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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [kbdtest.c] - Blame information for rev 664

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

powered by: WebSVN 2.1.0

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