- more improvements on PS2 stuff
Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@635 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -20,8 +20,8 @@ typedef struct _sps2_if_t
|
|||||||
|
|
||||||
static ps2_if_t ps2_if[2] =
|
static ps2_if_t ps2_if[2] =
|
||||||
{
|
{
|
||||||
{(UINT32*)sys_ps2_0_stat, (UINT32*)sys_ps2_0_data},
|
{(UINT32*)SYS_PS2_0_STAT, (UINT32*)SYS_PS2_0_DATA},
|
||||||
{(UINT32*)sys_ps2_1_stat, (UINT32*)sys_ps2_1_data}
|
{(UINT32*)SYS_PS2_1_STAT, (UINT32*)SYS_PS2_1_DATA}
|
||||||
};
|
};
|
||||||
|
|
||||||
void handler0(void)
|
void handler0(void)
|
||||||
@@ -43,10 +43,10 @@ void handler2(void)
|
|||||||
|
|
||||||
void handler3(void)
|
void handler3(void)
|
||||||
{
|
{
|
||||||
volatile UINT32 *pUART0_stat = (UINT32*)sys_uart0_stat;
|
volatile UINT32 *pUART0_stat = (UINT32*)SYS_UART0_STAT;
|
||||||
volatile UINT32 *pUART0_data = (UINT32*)sys_uart0_data;
|
volatile UINT32 *pUART0_data = (UINT32*)SYS_UART0_DATA;
|
||||||
volatile UINT32 *pUART1_stat = (UINT32*)sys_uart1_stat;
|
volatile UINT32 *pUART1_stat = (UINT32*)SYS_UART1_STAT;
|
||||||
volatile UINT32 *pUART1_data = (UINT32*)sys_uart1_data;
|
volatile UINT32 *pUART1_data = (UINT32*)SYS_UART1_DATA;
|
||||||
|
|
||||||
while(0x200 & *pUART0_stat)
|
while(0x200 & *pUART0_stat)
|
||||||
{
|
{
|
||||||
@@ -90,9 +90,12 @@ void handler6(void)
|
|||||||
for (p=0; p < sizeof(ps2_if)/sizeof(ps2_if_t); p++)
|
for (p=0; p < sizeof(ps2_if)/sizeof(ps2_if_t); p++)
|
||||||
{
|
{
|
||||||
pIF = &ps2_if[p];
|
pIF = &ps2_if[p];
|
||||||
|
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
||||||
|
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *(pIF->pCTRL));
|
||||||
|
|
||||||
if (p==0)
|
if (p==0)
|
||||||
{
|
{
|
||||||
while(sys_ps2_bit_rx_irq & *pIF->pCTRL)
|
while(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL)
|
||||||
{
|
{
|
||||||
key = *pIF->pDATA;
|
key = *pIF->pDATA;
|
||||||
printf("Keyboard scan code = 0x%02X\n", key);
|
printf("Keyboard scan code = 0x%02X\n", key);
|
||||||
@@ -100,13 +103,13 @@ void handler6(void)
|
|||||||
}
|
}
|
||||||
if (p==1)
|
if (p==1)
|
||||||
{
|
{
|
||||||
if(!(sys_ps2_bit_rx_irq & *pIF->pCTRL))
|
if(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
timeout_count = 100;
|
timeout_count = 100;
|
||||||
while(!(sys_ps2_bit_rx_irq & *pIF->pCTRL))
|
while(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
|
||||||
{
|
{
|
||||||
timeout_count--;
|
timeout_count--;
|
||||||
if (!timeout_count)
|
if (!timeout_count)
|
||||||
@@ -135,9 +138,24 @@ void handler6(void)
|
|||||||
// printf("dx = %5d, dy = %5d\n", dx, dy);
|
// printf("dx = %5d, dy = %5d\n", dx, dy);
|
||||||
|
|
||||||
mouse_x += dx;
|
mouse_x += dx;
|
||||||
mouse_y += dy;
|
mouse_y -= dy;
|
||||||
|
if ((mouse_rsp[0] & 0x03) == 0x03)
|
||||||
|
{
|
||||||
|
mouse_x = 0;
|
||||||
|
mouse_y = 0;
|
||||||
|
}
|
||||||
|
if ((mouse_rsp[0] & 0x03) == 0x01)
|
||||||
|
{
|
||||||
|
mouse_x = 0;
|
||||||
|
Screen_line_clr();
|
||||||
|
}
|
||||||
|
if ((mouse_rsp[0] & 0x03) == 0x02)
|
||||||
|
mouse_y = 0;
|
||||||
|
|
||||||
printf("x = %5d, y = %5d\n", mouse_x, mouse_y);
|
Screen_csr_set_x(mouse_x);
|
||||||
|
Screen_csr_set_y(mouse_y);
|
||||||
|
|
||||||
|
// printf("x = %5d, y = %5d\n", mouse_x, mouse_y);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,13 +166,19 @@ void handler7(void)
|
|||||||
printf("Interrupt 7\n");
|
printf("Interrupt 7\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PS2_MODULE_PREFIX 0x1000000
|
||||||
|
#define PS2_SUCCESS LSYS_SUCCESS
|
||||||
|
#define PS2_ERROR (LSYS_ERR_BASE | PS2_MODULE_PREFIX)
|
||||||
|
#define PS2_ERR_TIMEOUT (PS2_ERROR | 0x0000001)
|
||||||
|
#define PS2_ERR_PS2_PREFIX (PS2_ERROR | 0x0010000)
|
||||||
|
|
||||||
void PS2_byte_write(UINT32 port, UINT8 byte)
|
void PS2_byte_write(UINT32 port, UINT8 byte)
|
||||||
{
|
{
|
||||||
ps2_if_t *pIF;
|
ps2_if_t *pIF;
|
||||||
|
|
||||||
pIF = &ps2_if[port];
|
pIF = &ps2_if[port];
|
||||||
|
|
||||||
while(!(*pIF->pCTRL & sys_ps2_bit_tx_empty));
|
while(!(*pIF->pCTRL & SYS_PS2_BIT_TX_EMPTY));
|
||||||
|
|
||||||
*pIF->pDATA = (UINT32)byte;
|
*pIF->pDATA = (UINT32)byte;
|
||||||
}
|
}
|
||||||
@@ -165,11 +189,11 @@ UINT32 PS2_byte_read(UINT32 port, UINT32 timeout_ms)
|
|||||||
|
|
||||||
pIF = &ps2_if[port];
|
pIF = &ps2_if[port];
|
||||||
|
|
||||||
while(!(*pIF->pCTRL & sys_ps2_bit_rx_avail))
|
while(!(*pIF->pCTRL & SYS_PS2_BIT_RX_AVAIL))
|
||||||
{
|
{
|
||||||
timeout_ms--;
|
timeout_ms--;
|
||||||
if (!timeout_ms)
|
if (!timeout_ms)
|
||||||
return ERROR;
|
return PS2_ERR_TIMEOUT;
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
@@ -185,26 +209,28 @@ UINT32 PS2_cmd(UINT32 port, UINT8 cmd, UINT32 ack_timeout_ms)
|
|||||||
if (0xFA != result)
|
if (0xFA != result)
|
||||||
{
|
{
|
||||||
printf ("PS2_cmd(%d): no ACK received. Result = %08X\n", port, result);
|
printf ("PS2_cmd(%d): no ACK received. Result = %08X\n", port, result);
|
||||||
return ERROR;
|
return PS2_ERR_PS2_PREFIX | result;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS2_flush(UINT32 port)
|
void PS2_flush(UINT32 port)
|
||||||
{
|
{
|
||||||
while (ERROR != PS2_byte_read(port, 10));
|
while (!IS_ERROR(PS2_byte_read(port, 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS2_init(UINT32 port)
|
UINT32 PS2_init(UINT32 port)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
ps2_if_t *pIF;
|
ps2_if_t *pIF;
|
||||||
|
UINT8 id[2];
|
||||||
|
|
||||||
pIF = &ps2_if[port];
|
pIF = &ps2_if[port];
|
||||||
|
|
||||||
UINT32 result;
|
UINT32 result;
|
||||||
|
|
||||||
// Disable RX-interrupt
|
// Disable RX-interrupt
|
||||||
*pIF->pCTRL &= ~sys_ps2_bit_rx_inten;
|
*pIF->pCTRL &= ~SYS_PS2_BIT_RX_INTEN;
|
||||||
|
|
||||||
printf ("PS2_init(%d) - Initialize... ", port);
|
printf ("PS2_init(%d) - Initialize... ", port);
|
||||||
|
|
||||||
@@ -216,7 +242,7 @@ void PS2_init(UINT32 port)
|
|||||||
if (IS_ERROR(result))
|
if (IS_ERROR(result))
|
||||||
{
|
{
|
||||||
printf ("Reset error %08X\n", result);
|
printf ("Reset error %08X\n", result);
|
||||||
return;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read BAT
|
// Read BAT
|
||||||
@@ -224,56 +250,176 @@ void PS2_init(UINT32 port)
|
|||||||
if (0xAA != result)
|
if (0xAA != result)
|
||||||
{
|
{
|
||||||
printf ("BAT error %08X\n", result);
|
printf ("BAT error %08X\n", result);
|
||||||
return;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("Success\n");
|
printf ("Success\n");
|
||||||
|
|
||||||
// Read ID
|
while(1)
|
||||||
result = PS2_byte_read(port, 10);
|
|
||||||
if (IS_ERROR(result))
|
|
||||||
{
|
{
|
||||||
// No ID => keyboard
|
// Read ID
|
||||||
printf ("PS2_init(%d) - Keyboard detected\n", port);
|
result = PS2_byte_read(port, 10);
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 0)
|
|
||||||
{
|
|
||||||
printf ("PS2_init(%d) - Mouse device detected\n", port);
|
|
||||||
printf ("PS2_init(%d) - Enable stream mode...", port);
|
|
||||||
result = PS2_cmd(port, 0xF4, 1000);
|
|
||||||
if (IS_ERROR(result))
|
if (IS_ERROR(result))
|
||||||
{
|
{
|
||||||
printf ("error %08X\n", result);
|
// No ID => keyboard
|
||||||
return;
|
printf ("PS2_init(%d) - Keyboard detected\n", port);
|
||||||
}
|
|
||||||
printf ("Success\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// send Get Device-ID
|
// send Get Device-ID
|
||||||
result = PS2_cmd(port, 0xF2, 1000);
|
result = PS2_cmd(port, 0xF2, 1000);
|
||||||
if (IS_ERROR(result))
|
if (IS_ERROR(result))
|
||||||
{
|
{
|
||||||
printf ("Get Device-ID error %08X\n", result);
|
printf ("Get Device-ID error %08X\n", result);
|
||||||
return;
|
break;
|
||||||
|
}
|
||||||
|
id[0] = PS2_byte_read(port, 1000);
|
||||||
|
id[1] = PS2_byte_read(port, 1000);
|
||||||
|
printf ("PS2_init(%d) - Device-ID: %02X%02X\n", port, id[0], id[1]);
|
||||||
|
|
||||||
|
// Get Scan code set (phase 1)
|
||||||
|
result = PS2_cmd(port, 0xF0, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. Get Scan code error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Get Scan code set (phase 2)
|
||||||
|
result = PS2_cmd(port, 0x00, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. Get Scan code error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = PS2_byte_read(port, 1000);
|
||||||
|
printf ("PS2_init(%d) - Current scan code set = %d\n", port, result);
|
||||||
|
|
||||||
|
// if Scan code SET != 2
|
||||||
|
if (result != 2)
|
||||||
|
{
|
||||||
|
printf ("PS2_init(%d) - Set scan code set = 2\n", port);
|
||||||
|
// Set Scan code set (phase 1)
|
||||||
|
result = PS2_cmd(port, 0xF0, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. Set Scan code error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Set Scan code set (phase 2)
|
||||||
|
result = PS2_cmd(port, 0x02, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. Set Scan code error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test LEDs
|
||||||
|
for (i=0; i < 4; i++)
|
||||||
|
{
|
||||||
|
result = PS2_cmd(port, 0xED, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = PS2_cmd(port, 0x02, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(100);
|
||||||
|
result = PS2_cmd(port, 0xED, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = PS2_cmd(port, 0x04, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(100);
|
||||||
|
result = PS2_cmd(port, 0xED, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = PS2_cmd(port, 0x01, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(100);
|
||||||
|
}
|
||||||
|
result = PS2_cmd(port, 0xED, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("1. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result = PS2_cmd(port, 0x00, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("2. LED error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We got a byte => maybe mouse
|
||||||
|
if (result == 0)
|
||||||
|
{
|
||||||
|
// We got zero => yes, it's a mouse
|
||||||
|
printf ("PS2_init(%d) - Mouse device detected\n", port);
|
||||||
|
|
||||||
|
// send Get Device-ID
|
||||||
|
result = PS2_cmd(port, 0xF2, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("Get Device-ID error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
id[0] = PS2_byte_read(port, 1000);
|
||||||
|
printf ("PS2_init(%d) - Device-ID: %02X\n", port, id[0]);
|
||||||
|
printf ("PS2_init(%d) - Enable stream mode...", port);
|
||||||
|
result = PS2_cmd(port, 0xF4, 1000);
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
{
|
||||||
|
printf ("error %08X\n", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf ("Success\n");
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf ("PS2_init(%d) - Device-ID: %08X\n", port, result);
|
|
||||||
|
|
||||||
// Flush buffer
|
// Flush buffer
|
||||||
while (ERROR != PS2_byte_read(port, 10));
|
PS2_flush(port);
|
||||||
|
|
||||||
|
if (IS_ERROR(result))
|
||||||
|
return result;
|
||||||
|
|
||||||
// Enable RX-interrupt
|
// Enable RX-interrupt
|
||||||
*pIF->pCTRL |= sys_ps2_bit_rx_inten;
|
*pIF->pCTRL |= SYS_PS2_BIT_RX_INTEN;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
volatile UINT32 *pUART0_stat = (UINT32*)sys_uart0_stat;
|
volatile UINT32 *pUART0_stat = (UINT32*)SYS_UART0_STAT;
|
||||||
volatile UINT32 *pUART1_stat = (UINT32*)sys_uart1_stat;
|
volatile UINT32 *pUART1_stat = (UINT32*)SYS_UART1_STAT;
|
||||||
volatile UINT32 *pUART0_baud = (UINT32*)sys_uart0_baud;
|
volatile UINT32 *pUART0_baud = (UINT32*)SYS_UART0_BAUD;
|
||||||
volatile UINT32 *pUART1_baud = (UINT32*)sys_uart1_baud;
|
volatile UINT32 *pUART1_baud = (UINT32*)SYS_UART1_BAUD;
|
||||||
|
|
||||||
char string[65];
|
char string[65];
|
||||||
|
|
||||||
@@ -288,8 +434,8 @@ int main(void)
|
|||||||
interrupt_register(1, (void*)handler1);
|
interrupt_register(1, (void*)handler1);
|
||||||
interrupt_enable(1);
|
interrupt_enable(1);
|
||||||
|
|
||||||
interrupt_register(2, (void*)handler2);
|
// interrupt_register(2, (void*)handler2);
|
||||||
interrupt_enable(2);
|
// interrupt_enable(2);
|
||||||
|
|
||||||
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
||||||
printf("UART0 Baud = 0x%8.8X\n", *pUART0_baud);
|
printf("UART0 Baud = 0x%8.8X\n", *pUART0_baud);
|
||||||
@@ -349,6 +495,14 @@ int main(void)
|
|||||||
PS2_flush(0);
|
PS2_flush(0);
|
||||||
PS2_flush(1);
|
PS2_flush(1);
|
||||||
|
|
||||||
|
|
||||||
|
// while(1)
|
||||||
|
// {
|
||||||
|
// printf("PS2-Status : 0x%08X\n", *(ps2_if[0].pCTRL));
|
||||||
|
// printf("PS2-Data : 0x%08X\n", *(ps2_if[0].pDATA));
|
||||||
|
// sleep(1000);
|
||||||
|
// }
|
||||||
|
|
||||||
interrupt_enable(6);
|
interrupt_enable(6);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user