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

Last change on this file since 1042 was 1042, checked in by meunier, 8 years ago
  • Passing BLOCK_SIZE as a Makefile parameter in tsar bootloader
  • Adding a 32-bit version for the bootloader
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}
41
42///////////////////////////////////
43void reset_puts(const char *buffer)
44{
45    unsigned int n;
46
47    for ( n=0; n<100; n++)
48    {
49        if (buffer[n] == 0) break;
50        reset_putc(buffer[n]);
51    }
52}
53
54/////////////////////////////////
55void reset_putx(unsigned int val)
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++ )
66    {
67        buf[9-c] = HexaTab[val&0xF];
68        val = val >> 4;
69    }
70    reset_puts(buf);
71}
72
73/////////////////////////////////
74void reset_putd(unsigned int val)
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    }
96    reset_puts( &buf[first] );
97}
98
99/////////////////
100void reset_exit()
101{
102    register int pid;
103    asm volatile( "mfc0 %0, $15, 1": "=r"(pid) );
104
105    reset_puts("\n!!! Exit Processor ");
106    reset_putx(pid & 0x3FF);
107    reset_puts(" !!!\n");
108
109    while(1) asm volatile("nop");   // infinite loop...
110}
111
112
113
Note: See TracBrowser for help on using the repository browser.