source: trunk/softs/tsar_boot/drivers/reset_tty.c @ 1049

Last change on this file since 1049 was 1049, checked in by alain, 7 years ago

Cosmetic change in the hard_config.h file : XCU -> ICU , TTY -> TXT

File size: 2.3 KB
Line 
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_TXT_BASE
14#   error "SEG_TXT_BASE constant must be defined in the hard_config.h file"
15#endif
16
17static int* const tty_address = (int* const)SEG_TXT_BASE;
18
19enum 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///////////////////////
29int 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/////////////////////////////
37void 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///////////////////////////////////
47void 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/////////////////////////////////
59void 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/////////////////////////////////
78void 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/////////////////
104void 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
Note: See TracBrowser for help on using the repository browser.