source: branches/fault_tolerance/softs/tsar_boot/src/reset_tty.c @ 724

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

branches/fault_tolerance:

  • Recreating fault_tolerance branch with all new modifications from trunk.
  • Introducing distributed boot rom in the tsar_generic_iob platform
File size: 2.1 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///////////////////////
14int reset_getc(char *c)
15{
16    unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE;
17
18    if (ioread32( &tty_address[TTY_STATUS] ) == 0) return 0;
19    *c = ioread32( &tty_address[TTY_READ] );
20    return 1;
21}
22
23/////////////////////////////
24void reset_putc(const char c)
25{
26    unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE;
27
28    iowrite32( &tty_address[TTY_WRITE], (unsigned int)c );
29    if (c == '\n') reset_putc( '\r' );
30}
31
32///////////////////////////////////
33void reset_puts(const char *buffer) 
34{
35    unsigned int n;
36
37    for ( n=0; n<100; n++)
38    {
39        if (buffer[n] == 0) break;
40        reset_putc(buffer[n]);
41    }
42} 
43
44/////////////////////////////////
45void reset_putx(unsigned int val)
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    }
60    reset_puts(buf);
61}
62
63/////////////////////////////////
64void reset_putd(unsigned int val)
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    }
86    reset_puts( &buf[first] );
87}
88
89/////////////////
90void reset_exit()
91{
92    register int pid;
93    asm volatile( "mfc0 %0, $15, 1": "=r"(pid) );
94
95    reset_puts("\n!!! Exit Processor ");
96    reset_putx(pid);
97    reset_puts(" !!!\n");
98
99    while(1) asm volatile("nop");   // infinite loop...
100}
101
102
103
Note: See TracBrowser for help on using the repository browser.