1 | /******************************************************************** |
---|
2 | * \file reset_tty.c |
---|
3 | * \date 5 mars 2014 |
---|
4 | * \author Cesar Fuguet |
---|
5 | * |
---|
6 | * Minimal driver for TTY controler |
---|
7 | *******************************************************************/ |
---|
8 | |
---|
9 | #include <reset_tty.h> |
---|
10 | #include <io.h> |
---|
11 | #include <defs.h> |
---|
12 | |
---|
13 | #ifndef SEG_TTY_BASE |
---|
14 | # error "SEG_TTY_BASE constant must be defined in the hard_config.h file" |
---|
15 | #endif |
---|
16 | |
---|
17 | static int* const tty_address = (int* const)SEG_TTY_BASE; |
---|
18 | |
---|
19 | enum tty_registers { |
---|
20 | TTY_WRITE = 0, |
---|
21 | TTY_STATUS = 1, |
---|
22 | TTY_READ = 2, |
---|
23 | TTY_CONFIG = 3, |
---|
24 | |
---|
25 | TTY_SPAN = 4, |
---|
26 | }; |
---|
27 | |
---|
28 | /////////////////////// |
---|
29 | int reset_getc(char *c) |
---|
30 | { |
---|
31 | if (ioread32( &tty_address[TTY_STATUS] ) == 0) return 0; |
---|
32 | *c = ioread32( &tty_address[TTY_READ] ); |
---|
33 | return 1; |
---|
34 | } |
---|
35 | |
---|
36 | ///////////////////////////// |
---|
37 | void reset_putc(const char c) |
---|
38 | { |
---|
39 | if (c == '\n') |
---|
40 | { |
---|
41 | iowrite32(&tty_address[TTY_WRITE], (unsigned int) '\r'); |
---|
42 | } |
---|
43 | iowrite32(&tty_address[TTY_WRITE], (unsigned int) c); |
---|
44 | } |
---|
45 | |
---|
46 | /////////////////////////////////// |
---|
47 | void reset_puts(const char *buffer) |
---|
48 | { |
---|
49 | unsigned int n; |
---|
50 | |
---|
51 | for ( n=0; n<100; n++) |
---|
52 | { |
---|
53 | if (buffer[n] == 0) break; |
---|
54 | reset_putc(buffer[n]); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | ///////////////////////////////// |
---|
59 | void reset_putx(unsigned int val) |
---|
60 | { |
---|
61 | static const char HexaTab[] = "0123456789ABCDEF"; |
---|
62 | char buf[11]; |
---|
63 | unsigned int c; |
---|
64 | |
---|
65 | buf[0] = '0'; |
---|
66 | buf[1] = 'x'; |
---|
67 | buf[10] = 0; |
---|
68 | |
---|
69 | for ( c = 0 ; c < 8 ; c++ ) |
---|
70 | { |
---|
71 | buf[9-c] = HexaTab[val&0xF]; |
---|
72 | val = val >> 4; |
---|
73 | } |
---|
74 | reset_puts(buf); |
---|
75 | } |
---|
76 | |
---|
77 | ///////////////////////////////// |
---|
78 | void reset_putd(unsigned int val) |
---|
79 | { |
---|
80 | static const char DecTab[] = "0123456789"; |
---|
81 | char buf[11]; |
---|
82 | unsigned int i; |
---|
83 | unsigned int first = 0; |
---|
84 | |
---|
85 | buf[10] = 0; |
---|
86 | |
---|
87 | for ( i = 0 ; i < 10 ; i++ ) |
---|
88 | { |
---|
89 | if ((val != 0) || (i == 0)) |
---|
90 | { |
---|
91 | buf[9-i] = DecTab[val % 10]; |
---|
92 | first = 9-i; |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | break; |
---|
97 | } |
---|
98 | val /= 10; |
---|
99 | } |
---|
100 | reset_puts( &buf[first] ); |
---|
101 | } |
---|
102 | |
---|
103 | ///////////////// |
---|
104 | void reset_exit() |
---|
105 | { |
---|
106 | register int pid; |
---|
107 | asm volatile( "mfc0 %0, $15, 1": "=r"(pid) ); |
---|
108 | |
---|
109 | reset_puts("\n!!! Exit Processor "); |
---|
110 | reset_putx(pid & 0x3FF); |
---|
111 | reset_puts(" !!!\n"); |
---|
112 | |
---|
113 | while(1) asm volatile("nop"); // infinite loop... |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | |
---|