[704] | 1 | /******************************************************************** |
---|
| 2 | * \file reset_tty.c |
---|
| 3 | * \date 5 mars 2014 |
---|
[758] | 4 | * \author Cesar Fuguet |
---|
[704] | 5 | * |
---|
[758] | 6 | * Minimal driver for TTY controler |
---|
[704] | 7 | *******************************************************************/ |
---|
| 8 | |
---|
[586] | 9 | #include <reset_tty.h> |
---|
| 10 | #include <io.h> |
---|
[292] | 11 | #include <defs.h> |
---|
| 12 | |
---|
[1049] | 13 | #ifndef SEG_TXT_BASE |
---|
| 14 | # error "SEG_TXT_BASE constant must be defined in the hard_config.h file" |
---|
[758] | 15 | #endif |
---|
| 16 | |
---|
[1049] | 17 | static int* const tty_address = (int* const)SEG_TXT_BASE; |
---|
[758] | 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 | |
---|
[586] | 28 | /////////////////////// |
---|
| 29 | int reset_getc(char *c) |
---|
[292] | 30 | { |
---|
[704] | 31 | if (ioread32( &tty_address[TTY_STATUS] ) == 0) return 0; |
---|
| 32 | *c = ioread32( &tty_address[TTY_READ] ); |
---|
[348] | 33 | return 1; |
---|
[292] | 34 | } |
---|
| 35 | |
---|
[586] | 36 | ///////////////////////////// |
---|
| 37 | void reset_putc(const char c) |
---|
[292] | 38 | { |
---|
[1043] | 39 | if (c == '\n') |
---|
| 40 | { |
---|
| 41 | iowrite32(&tty_address[TTY_WRITE], (unsigned int) '\r'); |
---|
| 42 | } |
---|
| 43 | iowrite32(&tty_address[TTY_WRITE], (unsigned int) c); |
---|
[292] | 44 | } |
---|
| 45 | |
---|
[586] | 46 | /////////////////////////////////// |
---|
[758] | 47 | void reset_puts(const char *buffer) |
---|
[292] | 48 | { |
---|
| 49 | unsigned int n; |
---|
| 50 | |
---|
| 51 | for ( n=0; n<100; n++) |
---|
| 52 | { |
---|
| 53 | if (buffer[n] == 0) break; |
---|
[586] | 54 | reset_putc(buffer[n]); |
---|
[292] | 55 | } |
---|
[758] | 56 | } |
---|
[292] | 57 | |
---|
[586] | 58 | ///////////////////////////////// |
---|
| 59 | void reset_putx(unsigned int val) |
---|
[292] | 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++ ) |
---|
[758] | 70 | { |
---|
[292] | 71 | buf[9-c] = HexaTab[val&0xF]; |
---|
| 72 | val = val >> 4; |
---|
| 73 | } |
---|
[586] | 74 | reset_puts(buf); |
---|
[292] | 75 | } |
---|
| 76 | |
---|
[586] | 77 | ///////////////////////////////// |
---|
| 78 | void reset_putd(unsigned int val) |
---|
[292] | 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 | } |
---|
[586] | 100 | reset_puts( &buf[first] ); |
---|
[292] | 101 | } |
---|
| 102 | |
---|
[586] | 103 | ///////////////// |
---|
| 104 | void reset_exit() |
---|
[292] | 105 | { |
---|
| 106 | register int pid; |
---|
| 107 | asm volatile( "mfc0 %0, $15, 1": "=r"(pid) ); |
---|
| 108 | |
---|
[586] | 109 | reset_puts("\n!!! Exit Processor "); |
---|
[992] | 110 | reset_putx(pid & 0x3FF); |
---|
[586] | 111 | reset_puts(" !!!\n"); |
---|
[292] | 112 | |
---|
| 113 | while(1) asm volatile("nop"); // infinite loop... |
---|
| 114 | } |
---|
| 115 | |
---|
[586] | 116 | |
---|
| 117 | |
---|