OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 683 to Rev 684
    Reverse comparison

Rev 683 → Rev 684

/trunk/or1ksim/peripheral/ps2kbd.c
67,7 → 67,19
 
/* Input stream */
static FILE *kbd_rxfs = NULL;
 
 
/* Controller Command (write into 0x64) */
static int kbd_ccmd;
 
/* Keyboard Command (write into 0x60) */
static unsigned char kbd_kcmd;
 
/* Controller Command Byte */
static unsigned char kbd_ccmdbyte;
 
/* Keyboard response pending */
static unsigned long kbd_kresp;
 
static void kbd_put (unsigned char c)
{
if (kbd_buf_count >= KBD_MAX_BUF) {
101,8 → 113,36
{
int a = (addr - config.kbd.baseaddr);
switch (a) {
case KBD_CTRL: break;
case KBD_DATA: break;
case KBD_CTRL:
kbd_ccmd = value & 0xff;
if (kbd_ccmd == KBD_CCMD_RCB)
kbd_kresp = 0x1;
if (kbd_ccmd == KBD_CCMD_ST1)
kbd_kresp = 0x1;
if (kbd_ccmd == KBD_CCMD_ST2)
kbd_kresp = 0x1;
if (kbd_ccmd == KBD_CCMD_DKI)
kbd_ccmdbyte |= KBD_CCMDBYTE_EN;
if (kbd_ccmd == KBD_CCMD_EKI)
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
if (config.sim.verbose)
printf("kbd_write8(%x) %x\n", addr, value);
break;
case KBD_DATA:
if (kbd_ccmd == KBD_CCMD_WCB) {
kbd_ccmdbyte = value & 0xff;
kbd_ccmd = 0x00;
} else
kbd_kcmd = value & 0xff;
if (kbd_kcmd == KBD_KCMD_DK)
kbd_ccmdbyte |= KBD_CCMDBYTE_EN;
if (kbd_kcmd == KBD_KCMD_EK)
kbd_ccmdbyte &= ~KBD_CCMDBYTE_EN;
kbd_kresp = 0x1;
kbd_ccmd = 0x00;
if (config.sim.verbose)
printf("kbd_write8(%x) %x\n", addr, value);
break;
default:
fprintf (stderr, "Write out of keyboard space (0x%08x)!\n", addr);
cont_run = 0;
115,14 → 155,62
{
int a = (addr - config.kbd.baseaddr);
switch (a) {
case KBD_CTRL: return 0; break;
case KBD_DATA:
if (kbd_buf_count) {
case KBD_CTRL: {
unsigned long c = 0x0;
if (kbd_kresp || kbd_buf_count)
c |= KBD_STATUS_OBF;
c |= kbd_ccmdbyte & KBD_CCMDBYTE_SYS;
c |= KBD_STATUS_INH;
if (config.sim.verbose)
printf("kbd_read8(%x) %x\n", addr, c);
return c;
}
case KBD_DATA:
if (kbd_ccmd) {
unsigned long rc;
if (kbd_ccmd == KBD_CCMD_RCB)
rc = kbd_ccmdbyte;
if (kbd_ccmd == KBD_CCMD_ST1)
rc = 0x55;
if (kbd_ccmd == KBD_CCMD_ST2)
rc = 0x00;
kbd_ccmd = 0x00;
kbd_kresp = 0x0;
if (config.sim.verbose)
printf("kbd_read8(%x) %x\n", addr, rc);
return rc;
}
else if (kbd_kresp) {
unsigned long rc;
if (kbd_kresp == 0x2) {
kbd_kresp = 0x0;
rc = KBD_KRESP_RSTOK;
} else if (kbd_kcmd == KBD_KCMD_RST) {
kbd_kresp = 0x2;
rc = KBD_KRESP_ACK;
} else if (kbd_kcmd == KBD_KCMD_ECHO) {
kbd_kresp = 0x0;
rc = KBD_KRESP_ECHO;
} else {
kbd_kresp = 0x0;
rc = KBD_KRESP_ACK;
}
kbd_kcmd = 0x00;
if (config.sim.verbose)
printf("kbd_read8(%x) %x\n", addr, rc);
return rc;
} else if (kbd_buf_count) {
unsigned long c = kbd_buf[kbd_buf_tail];
kbd_buf_tail = (kbd_buf_tail + 1) % KBD_MAX_BUF;
kbd_buf_count--;
kbd_kresp = 0x0;
if (config.sim.verbose)
printf("kbd_read8(%x) %x\n", addr, c);
return c;
}
kbd_kresp = 0x0;
if (config.sim.verbose)
printf("kbd_read8(%x) fifo empty\n", addr);
return 0;
default:
fprintf (stderr, "Read out of keyboard space (0x%08x)!\n", addr);
138,6 → 226,8
kbd_buf_count = 0;
kbd_buf_head = 0;
kbd_buf_tail = 0;
kbd_kresp = 0x0;
kbd_ccmdbyte = 0x65; /* We reset into default normal operation. */
register_memoryarea(config.kbd.baseaddr, KBD_SPACE, 1, kbd_read8, kbd_write8);
if (!(kbd_rxfs = fopen(config.kbd.rxfile, "r"))
147,13 → 237,28
}
}
 
 
void kbd_info()
{
printf("kbd_kcmd: %x\n", kbd_kcmd);
printf("kbd_ccmd: %x\n", kbd_ccmd);
printf("kbd_ccmdbyte: %x\n", kbd_ccmdbyte);
printf("kbd_kresp: %x\n", kbd_kresp);
printf("kbd_buf_count: %x\n", kbd_buf_count);
}
 
/* Simulation hook. Must be called every clock cycle to simulate incomming data. */
void kbd_clock()
{
int c;
int kbd_int = 0;
/* Check if there is something waiting, and decode it into kdb_buf */
if((c = fgetc(kbd_rxfs)) != EOF) {
scan_decode (c);
}
if (kbd_buf_count) report_interrupt(config.kbd.irq);
kbd_int = kbd_kresp || kbd_buf_count;
kbd_int = kbd_kresp || kbd_buf_count ? kbd_ccmdbyte & KBD_CCMDBYTE_INT : 0;
if (config.sim.verbose && kbd_int)
printf("Keyboard Interrupt.... kbd_kresp %x kbd_buf_count %x \n", kbd_kresp, kbd_buf_count);
if (kbd_int) report_interrupt(config.kbd.irq);
}
/trunk/or1ksim/peripheral/ps2kbd.h
24,7 → 24,45
#define KBD_CTRL 4
#define KBD_DATA 0
#define KBD_SPACE 8
 
 
/* Keyboard commands */
#define KBD_KCMD_RST 0xFF
#define KBD_KCMD_DK 0xF5
#define KBD_KCMD_EK 0xF4
#define KBD_KCMD_ECHO 0xFF
#define KBD_KCMD_SRL 0xED
 
/* Keyboard responses */
#define KBD_KRESP_RSTOK 0xAA
#define KBD_KRESP_ECHO 0xEE
#define KBD_KRESP_ACK 0xFA
 
/* Controller commands */
#define KBD_CCMD_RCB 0x20
#define KBD_CCMD_WCB 0x60
#define KBD_CCMD_ST1 0xAA
#define KBD_CCMD_ST2 0xAB
#define KBD_CCMD_DKI 0xAD
#define KBD_CCMD_EKI 0xAE
 
/* Status register bits */
#define KBD_STATUS_OBF 0x01
#define KBD_STATUS_IBF 0x02
#define KBD_STATUS_SYS 0x04
#define KBD_STATUS_A2 0x08
#define KBD_STATUS_INH 0x10
#define KBD_STATUS_MOBF 0x20
#define KBD_STATUS_TO 0x40
#define KBD_STATUS_PERR 0x80
 
/* Command byte register bits */
#define KBD_CCMDBYTE_INT 0x01
#define KBD_CCMDBYTE_INT2 0x02
#define KBD_CCMDBYTE_SYS 0x04
#define KBD_CCMDBYTE_EN 0x10
#define KBD_CCMDBYTE_EN2 0x20
#define KBD_CCMDBYTE_XLAT 0x40
 
/* Length of internal scan code fifo */
#define KBD_MAX_BUF 0x100
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.