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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [testbench/] [kbdtest.c] - Blame information for rev 1782

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 664 markom
/* Simple keyboard test. Outputs scan codes. */
2
#include "support.h"
3
#include "spr_defs.h"
4 970 simons
#include "board.h"
5 664 markom
 
6
/* Whether this test should be run in interactive mode; scan codes are not check against real ones */
7
#define INTERACTIVE 0
8
 
9
/* fails if x is false */
10
#define ASSERT(x) ((x)?1: fail (__FUNCTION__, __LINE__))
11
/* Waits a few cycles that uart can prepare its data */
12
#define WAIT() {asm ("l.nop");asm ("l.nop");asm ("l.nop");asm ("l.nop");}
13 1024 simons
#define MARK() printf ("Passed line %i\n", __LINE__)
14 664 markom
 
15
#ifndef __LINE__
16
#define __LINE__  0
17
#endif
18
 
19
#if !INTERACTIVE
20
static const unsigned char incoming_scan[] = {
21 971 simons
  0x2a, 0x14, 0x94, 0xaa, 0x12, 0x92, 0x04, 0x84, 0x2a, 0x0d,
22
  0x8d, 0xaa, 0x0d, 0x8d, 0x0c, 0x8c, 0x2a, 0x33, 0xb3, 0xaa,
23
  0x35, 0xb5, 0x34, 0xb4, 0x2b, 0xab, 0x2a, 0x2b, 0xab, 0xaa,
24
  0x2a, 0x28, 0xa8, 0xaa, 0x28, 0xa8, 0x29, 0xa9, 0x2a, 0x1b,
25
  0x9b, 0xaa, 0x1b, 0x9b, 0x0f, 0x8f, 0x39, 0xb9, 0x2a, 0x02,
26
  0x82, 0xaa, 0x2a, 0x06, 0x86, 0xaa, 0x2a, 0x07, 0x87, 0xaa,
27
  0x2a, 0x08, 0x88, 0xaa, 0x2a, 0x0b, 0x8b, 0xaa, 0x2a, 0x09,
28
  0x89, 0xaa, 0x1c, 0x9c, 0x39, 0xb9, 0x00};
29 664 markom
static int current_scan = 0;
30
#endif
31
 
32
static volatile int done;
33
 
34
void fail (char *func, int line)
35
{
36
#ifndef __FUNCTION__
37
#define __FUNCTION__ "?"
38
#endif
39 1024 simons
  printf ("Test failed in %s:%i\n", func, line);
40 664 markom
  report(0xeeeeeeee);
41
  exit (1);
42
}
43
 
44
inline void setreg (unsigned long addr, unsigned char value)
45
{
46
  *((volatile unsigned char *)addr) = value;
47
}
48
 
49
inline unsigned long getreg (unsigned long addr)
50
{
51
  return *((volatile unsigned char *)addr);
52
}
53
 
54
void interrupt_handler ()
55
{
56
  unsigned x;
57 1024 simons
  printf ("Int\n");
58 664 markom
  do {
59 970 simons
    x = getreg (KBD_BASE_ADD);
60 1024 simons
    if (x) printf ("0x%02x, ", x);
61 664 markom
    report(x);
62
    if (x == 1) done = 1;
63
#if !INTERACTIVE
64 1024 simons
    printf ("expecting (0x%02x), ", incoming_scan[current_scan]);
65 971 simons
    if (x) {
66
      ASSERT (incoming_scan[current_scan++] == x);
67
    }
68
    if ((current_scan + 1) >= sizeof (incoming_scan) / sizeof (char)) done = 1;
69 664 markom
#endif
70
  } while (x);
71 1024 simons
  printf ("%i", done);
72 664 markom
  mtspr(SPR_PICSR, 0);
73
}
74
 
75
int main ()
76
{
77
  /* Use our low priority interrupt handler */
78
  excpt_int = (unsigned long)interrupt_handler;
79
 
80 1024 simons
  printf ("Reading from keyboard.\n");
81
  printf ("Enabling interrupts.\n");
82 664 markom
  done = 0;
83
 
84
  /* Enable interrupts */
85
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
86 970 simons
  mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << KBD_IRQ));
87 664 markom
 
88 1024 simons
  while (!done) printf ("[%i]", done);
89 664 markom
  report (0xdeaddead);
90
  return 0;
91
}

powered by: WebSVN 2.1.0

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