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