[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 | |
---|
[758] | 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 | |
---|
[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 | { |
---|
[704] | 39 | iowrite32( &tty_address[TTY_WRITE], (unsigned int)c ); |
---|
[292] | 40 | } |
---|
| 41 | |
---|
[586] | 42 | /////////////////////////////////// |
---|
[758] | 43 | void reset_puts(const char *buffer) |
---|
[292] | 44 | { |
---|
| 45 | unsigned int n; |
---|
| 46 | |
---|
| 47 | for ( n=0; n<100; n++) |
---|
| 48 | { |
---|
| 49 | if (buffer[n] == 0) break; |
---|
[586] | 50 | reset_putc(buffer[n]); |
---|
[292] | 51 | } |
---|
[758] | 52 | } |
---|
[292] | 53 | |
---|
[586] | 54 | ///////////////////////////////// |
---|
| 55 | void reset_putx(unsigned int val) |
---|
[292] | 56 | { |
---|
| 57 | static const char HexaTab[] = "0123456789ABCDEF"; |
---|
| 58 | char buf[11]; |
---|
| 59 | unsigned int c; |
---|
| 60 | |
---|
| 61 | buf[0] = '0'; |
---|
| 62 | buf[1] = 'x'; |
---|
| 63 | buf[10] = 0; |
---|
| 64 | |
---|
| 65 | for ( c = 0 ; c < 8 ; c++ ) |
---|
[758] | 66 | { |
---|
[292] | 67 | buf[9-c] = HexaTab[val&0xF]; |
---|
| 68 | val = val >> 4; |
---|
| 69 | } |
---|
[586] | 70 | reset_puts(buf); |
---|
[292] | 71 | } |
---|
| 72 | |
---|
[586] | 73 | ///////////////////////////////// |
---|
| 74 | void reset_putd(unsigned int val) |
---|
[292] | 75 | { |
---|
| 76 | static const char DecTab[] = "0123456789"; |
---|
| 77 | char buf[11]; |
---|
| 78 | unsigned int i; |
---|
| 79 | unsigned int first = 0; |
---|
| 80 | |
---|
| 81 | buf[10] = 0; |
---|
| 82 | |
---|
| 83 | for ( i = 0 ; i < 10 ; i++ ) |
---|
| 84 | { |
---|
| 85 | if ((val != 0) || (i == 0)) |
---|
| 86 | { |
---|
| 87 | buf[9-i] = DecTab[val % 10]; |
---|
| 88 | first = 9-i; |
---|
| 89 | } |
---|
| 90 | else |
---|
| 91 | { |
---|
| 92 | break; |
---|
| 93 | } |
---|
| 94 | val /= 10; |
---|
| 95 | } |
---|
[586] | 96 | reset_puts( &buf[first] ); |
---|
[292] | 97 | } |
---|
| 98 | |
---|
[586] | 99 | ///////////////// |
---|
| 100 | void reset_exit() |
---|
[292] | 101 | { |
---|
| 102 | register int pid; |
---|
| 103 | asm volatile( "mfc0 %0, $15, 1": "=r"(pid) ); |
---|
| 104 | |
---|
[586] | 105 | reset_puts("\n!!! Exit Processor "); |
---|
[992] | 106 | reset_putx(pid & 0x3FF); |
---|
[586] | 107 | reset_puts(" !!!\n"); |
---|
[292] | 108 | |
---|
| 109 | while(1) asm volatile("nop"); // infinite loop... |
---|
| 110 | } |
---|
| 111 | |
---|
[586] | 112 | |
---|
| 113 | |
---|