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

Last change on this file since 991 was 758, checked in by cfuguet, 10 years ago

tsar_boot: improving configuration infrastructure

  • Using hard_config.h which respects the same sintax that the hard_config.h file of all TSAR platforms. This file can be then generated by the GIET-VM genmap tool or written manually.
  • All peripheral drivers have been moved to a drivers directory and they are compiled as a static library. This allows GCC to only include in the final .ELF the object files of used peripherals and not all of them.
  • Example hard_config.h and ldscripts have been introduced in the conf directory.
  • Improving comments in all files
File size: 2.2 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_TTY_BASE
14#   error "SEG_TTY_BASE constant must be defined in the hard_config.h file"
15#endif
16
17static int* const tty_address = (int* const)SEG_TTY_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    iowrite32( &tty_address[TTY_WRITE], (unsigned int)c );
40    if (c == '\n') reset_putc( '\r' );
41}
42
43///////////////////////////////////
44void reset_puts(const char *buffer)
45{
46    unsigned int n;
47
48    for ( n=0; n<100; n++)
49    {
50        if (buffer[n] == 0) break;
51        reset_putc(buffer[n]);
52    }
53}
54
55/////////////////////////////////
56void reset_putx(unsigned int val)
57{
58    static const char HexaTab[] = "0123456789ABCDEF";
59    char              buf[11];
60    unsigned int      c;
61
62    buf[0]  = '0';
63    buf[1]  = 'x';
64    buf[10] = 0;
65
66    for ( c = 0 ; c < 8 ; c++ )
67    {
68        buf[9-c] = HexaTab[val&0xF];
69        val = val >> 4;
70    }
71    reset_puts(buf);
72}
73
74/////////////////////////////////
75void reset_putd(unsigned int val)
76{
77    static const char DecTab[] = "0123456789";
78    char              buf[11];
79    unsigned int      i;
80    unsigned int      first = 0;
81
82    buf[10] = 0;
83
84    for ( i = 0 ; i < 10 ; i++ )
85    {
86        if ((val != 0) || (i == 0))
87        {
88            buf[9-i] = DecTab[val % 10];
89            first    = 9-i;
90        }
91        else
92        {
93            break;
94        }
95        val /= 10;
96    }
97    reset_puts( &buf[first] );
98}
99
100/////////////////
101void reset_exit()
102{
103    register int pid;
104    asm volatile( "mfc0 %0, $15, 1": "=r"(pid) );
105
106    reset_puts("\n!!! Exit Processor ");
107    reset_putx(pid);
108    reset_puts(" !!!\n");
109
110    while(1) asm volatile("nop");   // infinite loop...
111}
112
113
114
Note: See TracBrowser for help on using the repository browser.