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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc2/] [or1ksim/] [testbench/] [kbdtest.c] - Blame information for rev 970

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
#define MARK() printf ("Passed line %i\n", __LINE__)
14
 
15
#ifndef __LINE__
16
#define __LINE__  0
17
#endif
18
 
19
#if !INTERACTIVE
20
static const unsigned char incoming_scan[] = {
21
  0x2a, 0x14, 0x94, 0xaa, 0x12, 0x92, 0x1f, 0x9f, 0x14, 0x94, 0x02, 0x82, 0x03, 0x83, 0x04, 0x84,
22
  0x2a, 0x0d, 0x8d, 0xaa, 0x0b, 0x8b, 0x0d, 0x8d, 0x0c, 0x8c, 0x2a, 0x33, 0xb3, 0xaa, 0x35, 0xb5,
23
  0x33, 0xb3, 0x2a, 0x34, 0xb4, 0xaa, 0x34, 0xb4, 0x2b, 0xab, 0x2a, 0x2b, 0xab, 0xaa, 0x2a, 0x28,
24
  0xa8, 0xaa, 0x28, 0xa8, 0x29, 0xa9, 0x2a, 0x1b, 0x9b, 0xaa, 0x2a, 0x1a, 0x9a, 0xaa, 0x1a, 0x9a,
25
  0x1b, 0x9b, 0x0f, 0x8f, 0x39, 0xb9, 0x1c, 0x9c, 0x2a, 0x02, 0x82, 0xaa, 0x2a, 0x03, 0x83, 0xaa,
26
  0x2a, 0x04, 0x84, 0xaa, 0x2a, 0x05, 0x85, 0xaa, 0x2a, 0x06, 0x86, 0xaa, 0x2a, 0x07, 0x87, 0xaa,
27
  0x2a, 0x08, 0x88, 0xaa, 0x2a, 0x09, 0x89, 0xaa, 0x2a, 0x0a, 0x8a, 0xaa, 0x2a, 0x0b, 0x8b, 0xaa,
28
  0x1c, 0x9c, 0x2a, 0x09, 0x89, 0xaa, 0x1c, 0x9c, 0x39, 0xb9, 0x00};
29
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
  printf ("Test failed in %s:%i\n", func, line);
40
  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
  printf ("Int\n");
58
  do {
59 970 simons
    x = getreg (KBD_BASE_ADD);
60 664 markom
    if (x) printf ("0x%02x, ", x);
61
    report(x);
62
    if (x == 1) done = 1;
63
#if !INTERACTIVE
64
    printf ("expecting (0x%02x), ", incoming_scan[current_scan]);
65
    ASSERT (incoming_scan[current_scan++] == x);
66
    if (x == 0) done = 1;
67
#endif
68
  } while (x);
69
  printf ("%i", done);
70
  mtspr(SPR_PICSR, 0);
71
}
72
 
73
int main ()
74
{
75
  /* Use our low priority interrupt handler */
76
  excpt_int = (unsigned long)interrupt_handler;
77
 
78
  printf ("Reading from keyboard.\n");
79
  printf ("Enabling interrupts.\n");
80
  done = 0;
81
 
82
  /* Enable interrupts */
83
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
84 970 simons
  mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << KBD_IRQ));
85 664 markom
 
86
  while (!done) printf ("[%i]", done);
87
  report (0xdeaddead);
88
  return 0;
89
}

powered by: WebSVN 2.1.0

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