/* kbdtest.c. Test of Or1ksim keyboard
|
/* kbdtest.c. Test of Or1ksim keyboard
|
|
|
Copyright (C) 1999-2006 OpenCores
|
Copyright (C) 1999-2006 OpenCores
|
Copyright (C) 2010 Embecosm Limited
|
Copyright (C) 2010 Embecosm Limited
|
|
|
Contributors various OpenCores participants
|
Contributors various OpenCores participants
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
under the terms of the GNU General Public License as published by the Free
|
under the terms of the GNU General Public License as published by the Free
|
Software Foundation; either version 3 of the License, or (at your option)
|
Software Foundation; either version 3 of the License, or (at your option)
|
any later version.
|
any later version.
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
more details.
|
more details.
|
|
|
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along
|
with this program. If not, see <http: www.gnu.org/licenses/>. */
|
with this program. If not, see <http: www.gnu.org/licenses/>. */
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
This code is commented throughout for use with Doxygen.
|
This code is commented throughout for use with Doxygen.
|
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
|
|
#include "support.h"
|
#include "support.h"
|
#include "spr-defs.h"
|
#include "spr-defs.h"
|
#include "board.h"
|
#include "board.h"
|
|
|
|
|
/*! Maximum number of characters to read before giving up. */
|
/*! Maximum number of characters to read before giving up. */
|
#define MAX_CHARS_TO_READ 25
|
#define MAX_CHARS_TO_READ 25
|
|
|
/*! A character used to indicate shift */
|
/*! A character used to indicate shift */
|
#define SHIFT_CHAR 0xfe
|
#define SHIFT_CHAR 0xfe
|
|
|
/*! An invalid character */
|
/*! An invalid character */
|
#define INVALID_CHAR 0xff
|
#define INVALID_CHAR 0xff
|
|
|
/*! Enumeration of state machine for processing scan codes */
|
/*! Enumeration of state machine for processing scan codes */
|
enum scan_state {
|
enum scan_state {
|
STATE_START,
|
STATE_START,
|
STATE_SHIFT_MADE,
|
STATE_SHIFT_MADE,
|
STATE_SHIFT_CHAR_MADE,
|
STATE_SHIFT_CHAR_MADE,
|
STATE_SHIFT_CHAR_BROKEN,
|
STATE_SHIFT_CHAR_BROKEN,
|
STATE_CHAR_MADE
|
STATE_CHAR_MADE
|
};
|
};
|
|
|
/*! Shared volatile flag counting how many chars have been done. */
|
/*! Shared volatile flag counting how many chars have been done. */
|
static volatile int num_chars_done;
|
static volatile int num_chars_done;
|
|
|
|
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
/*!Report failure
|
/*!Report failure
|
|
|
Terminate execution.
|
Terminate execution.
|
|
|
@param[in] msg Description of test which failed. */
|
@param[in] msg Description of test which failed. */
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
void fail (char *msg)
|
void fail (char *msg)
|
{
|
{
|
printf ("Test failed: %s\n", msg);
|
printf ("Test failed: %s\n", msg);
|
report (0xeeeeeeee);
|
report (0xeeeeeeee);
|
exit (1);
|
exit (1);
|
|
|
} /* fail () */
|
} /* fail () */
|
|
|
|
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
|
/*!Print an escaped character
|
|
Non-printable characters use their name:
|
|
'\n' - ENTER
|
|
' ' - SPACE
|
|
'\t' - TAB
|
|
|
|
Any char > 127 (0x7f) is an error.
|
|
|
|
Any other char less than 0x20 appears as ^<char>. */
|
|
/* --------------------------------------------------------------------------*/
|
|
static void
|
|
print_escaped_char (unsigned char c)
|
|
{
|
|
switch (c)
|
|
{
|
|
case '\n': printf ("Received: ENTER.\n"); return;
|
|
case ' ': printf ("Received: SPACE.\n"); return;
|
|
case '\t': printf ("Received: TAB.\n"); return;
|
|
|
|
default:
|
|
if (c > 0x7f)
|
|
{
|
|
printf ("\nWarning: received erroneous character 0x%02x.\n",
|
|
(unsigned int) c);
|
|
}
|
|
else if (c < 0x20)
|
|
{
|
|
printf ("Received '^%c'.\n", '@' + c);
|
|
}
|
|
else
|
|
{
|
|
printf ("Received '%c'.\n", c);
|
|
}
|
|
}
|
|
} /* print_escaped_char () */
|
|
|
|
|
|
/* --------------------------------------------------------------------------*/
|
/*!Utility to read a 32 bit memory mapped register
|
/*!Utility to read a 32 bit memory mapped register
|
|
|
@param[in] addr The address to read from
|
@param[in] addr The address to read from
|
|
|
@return The result of the read */
|
@return The result of the read */
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
static unsigned long
|
static unsigned long
|
getreg (unsigned long addr)
|
getreg (unsigned long addr)
|
{
|
{
|
return *((volatile unsigned char *)addr);
|
return *((volatile unsigned char *)addr);
|
|
|
} /* getreg () */
|
} /* getreg () */
|
|
|
|
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
/*!Keyboard interrupt handler
|
/*!Keyboard interrupt handler
|
|
|
Receives codes in the keyboard base register. Reports the first specified
|
Receives codes in the keyboard base register. Reports the first specified
|
number of them.
|
number of them.
|
|
|
@todo We only deal with shift keys here. Control, Alt and other funnies are
|
@todo We only deal with shift keys here. Control, Alt and other funnies are
|
left for the future. We also don't do extended sequences.
|
left for the future. We also don't do extended sequences.
|
|
|
If there is a zero in the register that is interpreted as meaning "No data
|
If there is a zero in the register that is interpreted as meaning "No data
|
more available" and the interrupt routine completes.
|
more available" and the interrupt routine completes.
|
|
|
Map the codes back to their characters. Fail on any bad chars. */
|
Map the codes back to their characters. Fail on any bad chars. */
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
static void
|
static void
|
interrupt_handler ()
|
interrupt_handler ()
|
{
|
{
|
/* String mapping 256 make codes to chars. 0xff means "invalid", 0xfe means
|
/* String mapping 256 make codes to chars. 0xff means "invalid", 0xfe means
|
"shift key". */
|
"shift key". */
|
static const unsigned char *make_codes = (unsigned char *)
|
static const unsigned char *make_codes = (unsigned char *)
|
"\xff\xff" "1234567890-=\xff\t"
|
"\xff\xff" "1234567890-=\xff\t"
|
"qwertyuiop[]\n\xff" "as"
|
"qwertyuiop[]\n\xff" "as"
|
"dfghjkl;'`\xfe\\zxcv"
|
"dfghjkl;'`\xfe\\zxcv"
|
"bnm,./\xfe\xff\xff \xff\xff\xff\xff\xff\xff"
|
"bnm,./\xfe\xff\xff \xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
|
|
/* String mapping 256 make codes to chars in a shift context. 0xff means
|
/* String mapping 256 make codes to chars in a shift context. 0xff means
|
"invalid". */
|
"invalid". */
|
static const unsigned char *make_shift_codes = (unsigned char *)
|
static const unsigned char *make_shift_codes = (unsigned char *)
|
"\xff\xff!@#$%^&*()_+\xff\t"
|
"\xff\xff!@#$%^&*()_+\xff\t"
|
"QWERTYUIOP{}\n\xff" "AS"
|
"QWERTYUIOP{}\n\xff" "AS"
|
"DFGHJKL:\"~\xff|ZXCV"
|
"DFGHJKL:\"~\xff|ZXCV"
|
"BNM<>?\xff\xff\xff \xff\xff\xff\xff\xff\xff"
|
"BNM<>?\xff\xff\xff \xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
|
|
/* The break codes expected to correspond to a make code. 00 indicates an
|
/* The break codes expected to correspond to a make code. 00 indicates an
|
invalid code (should never be requested) */
|
invalid code (should never be requested) */
|
static const unsigned char *break_codes = (unsigned char *)
|
static const unsigned char *break_codes = (unsigned char *)
|
"\x00\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x00\x8f"
|
"\x00\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x00\x8f"
|
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x00\x9e\x9f"
|
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x00\x9e\x9f"
|
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
|
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
|
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\x00\x00\xb9\x00\x00\x00\x00\x00\x00"
|
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\x00\x00\xb9\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
|
|
/* State machine */
|
/* State machine */
|
static enum scan_state state = STATE_START;
|
static enum scan_state state = STATE_START;
|
|
|
/* Stuff to remember between states */
|
/* Stuff to remember between states */
|
static char shift_scan_made;
|
static char shift_scan_made;
|
static char char_scan_made;
|
static char char_scan_made;
|
|
|
/* Get all the chars currently available */
|
/* Get all the chars currently available */
|
while (1)
|
while (1)
|
{
|
{
|
unsigned char x = getreg (KBD_BASE_ADD); /* Scan code */
|
unsigned char x = getreg (KBD_BASE_ADD); /* Scan code */
|
unsigned char c;
|
unsigned char c;
|
|
|
/* Give up if nothing more in the buffer */
|
/* Give up if nothing more in the buffer */
|
if (0 == x)
|
if (0 == x)
|
{
|
{
|
mtspr(SPR_PICSR, 0); /* Mark interrupt complete */
|
mtspr(SPR_PICSR, 0); /* Mark interrupt complete */
|
return;
|
return;
|
}
|
}
|
|
|
/* Handle the scan code */
|
/* Handle the scan code */
|
switch (state)
|
switch (state)
|
{
|
{
|
case STATE_START:
|
case STATE_START:
|
|
|
c = make_codes[(int) x];
|
c = make_codes[(int) x];
|
|
|
if (SHIFT_CHAR == c)
|
if (SHIFT_CHAR == c)
|
{
|
{
|
/* We had a shift key pressed */
|
/* We had a shift key pressed */
|
state = STATE_SHIFT_MADE;
|
state = STATE_SHIFT_MADE;
|
shift_scan_made = x;
|
shift_scan_made = x;
|
}
|
}
|
else
|
else
|
{
|
{
|
/* We had another key pressed. If it's valid record it,
|
/* We had another key pressed. If it's valid record it,
|
otherwise blow up. */
|
otherwise blow up. */
|
state = STATE_CHAR_MADE;
|
state = STATE_CHAR_MADE;
|
|
|
if (INVALID_CHAR == c)
|
if (INVALID_CHAR == c)
|
{
|
{
|
fail ("Unrecognized make scan code");
|
fail ("Unrecognized make scan code");
|
}
|
}
|
else
|
else
|
{
|
{
|
printf ("%c", c);
|
print_escaped_char (c);
|
char_scan_made = x;
|
char_scan_made = x;
|
}
|
}
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case STATE_SHIFT_MADE:
|
case STATE_SHIFT_MADE:
|
|
|
c = make_shift_codes[(int) x];
|
c = make_shift_codes[(int) x];
|
state = STATE_SHIFT_CHAR_MADE;
|
state = STATE_SHIFT_CHAR_MADE;
|
|
|
/* We had a key pressed after SHIFT. If it's valid, record it,
|
/* We had a key pressed after SHIFT. If it's valid, record it,
|
otherwise blow up. */
|
otherwise blow up. */
|
if (INVALID_CHAR == c)
|
if (INVALID_CHAR == c)
|
{
|
{
|
fail ("Unrecognized make scan code");
|
fail ("Unrecognized make scan code");
|
}
|
}
|
else
|
else
|
{
|
{
|
printf ("%c", c);
|
print_escaped_char (c);
|
char_scan_made = x;
|
char_scan_made = x;
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case STATE_SHIFT_CHAR_MADE:
|
case STATE_SHIFT_CHAR_MADE:
|
|
|
/* Check the break matches the char scan made */
|
/* Check the break matches the char scan made */
|
if (x == break_codes[(int) char_scan_made])
|
if (x == break_codes[(int) char_scan_made])
|
{
|
{
|
state = STATE_SHIFT_CHAR_BROKEN;
|
state = STATE_SHIFT_CHAR_BROKEN;
|
}
|
}
|
else
|
else
|
{
|
{
|
fail ("Unrecognized break scan code");
|
fail ("Unrecognized break scan code");
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case STATE_SHIFT_CHAR_BROKEN:
|
case STATE_SHIFT_CHAR_BROKEN:
|
|
|
/* Check the break matches the shift scan made */
|
/* Check the break matches the shift scan made */
|
if (x == break_codes[(int) shift_scan_made])
|
if (x == break_codes[(int) shift_scan_made])
|
{
|
{
|
state = STATE_START;
|
state = STATE_START;
|
num_chars_done++;
|
num_chars_done++;
|
}
|
}
|
else
|
else
|
{
|
{
|
fail ("Unrecognized break scan code");
|
fail ("Unrecognized break scan code");
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case STATE_CHAR_MADE:
|
case STATE_CHAR_MADE:
|
|
|
/* Check the break matches the char scan made */
|
/* Check the break matches the char scan made */
|
if (x == break_codes[(int) char_scan_made])
|
if (x == break_codes[(int) char_scan_made])
|
{
|
{
|
state = STATE_START;
|
state = STATE_START;
|
num_chars_done++;
|
num_chars_done++;
|
}
|
}
|
else
|
else
|
{
|
{
|
fail ("Unrecognized break scan code");
|
fail ("Unrecognized break scan code");
|
}
|
}
|
|
|
break;
|
break;
|
|
|
default:
|
default:
|
fail ("*** ABORT ***: Unknown scan state");
|
fail ("*** ABORT ***: Unknown scan state");
|
}
|
}
|
}
|
}
|
} /* interrupt_handler () */
|
} /* interrupt_handler () */
|
|
|
|
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
/*!Simple keyboard test main program
|
/*!Simple keyboard test main program
|
|
|
This appears to use the original XT scan code set, while the keyboard
|
This appears to use the original XT scan code set, while the keyboard
|
handler in Or1ksim generates codes appropriate to a US keyboard layout.
|
handler in Or1ksim generates codes appropriate to a US keyboard layout.
|
|
|
Set up the interrupt handler and wait until the shared variable shows it
|
Set up the interrupt handler and wait until the shared variable shows it
|
has done enough chars
|
has done enough chars
|
|
|
@return The return code from the program (always zero). */
|
@return The return code from the program (always zero). */
|
/* --------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------*/
|
int
|
int
|
main ()
|
main ()
|
{
|
{
|
printf ("Reading from keyboard.\n");
|
printf ("Reading from keyboard.\n");
|
|
|
/* Use our low priority interrupt handler. Clear the shared completed flag. */
|
/* Use our low priority interrupt handler. Clear the shared completed flag. */
|
excpt_int = (unsigned long)interrupt_handler;
|
excpt_int = (unsigned long)interrupt_handler;
|
|
|
/* Enable interrupts */
|
/* Enable interrupts */
|
printf ("Enabling interrupts.\n");
|
printf ("Enabling interrupts.\n");
|
|
|
mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << KBD_IRQ));
|
mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << KBD_IRQ));
|
|
|
/* Wait until the interrupt handler is finished */
|
/* Wait until the interrupt handler is finished. */
|
while (num_chars_done < MAX_CHARS_TO_READ)
|
while (num_chars_done < MAX_CHARS_TO_READ)
|
{
|
{
|
}
|
}
|
|
|
/* Usual end report */
|
/* Usual end report */
|
report (0xdeaddead);
|
report (0xdeaddead);
|
return 0;
|
return 0;
|
|
|
} /* main () */
|
} /* main () */
|
|
|