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

Last change on this file since 884 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
RevLine 
[704]1/********************************************************************
2 * \file    reset_tty.c
3 * \date    5 mars 2014
[758]4 * \author  Cesar Fuguet
[704]5 *
[758]6 * Minimal driver for TTY controler
[704]7 *******************************************************************/
8
[586]9#include <reset_tty.h>
10#include <io.h>
[292]11#include <defs.h>
12
[758]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
[586]28///////////////////////
29int reset_getc(char *c)
[292]30{
[704]31    if (ioread32( &tty_address[TTY_STATUS] ) == 0) return 0;
32    *c = ioread32( &tty_address[TTY_READ] );
[348]33    return 1;
[292]34}
35
[586]36/////////////////////////////
37void reset_putc(const char c)
[292]38{
[704]39    iowrite32( &tty_address[TTY_WRITE], (unsigned int)c );
40    if (c == '\n') reset_putc( '\r' );
[292]41}
42
[586]43///////////////////////////////////
[758]44void reset_puts(const char *buffer)
[292]45{
46    unsigned int n;
47
48    for ( n=0; n<100; n++)
49    {
50        if (buffer[n] == 0) break;
[586]51        reset_putc(buffer[n]);
[292]52    }
[758]53}
[292]54
[586]55/////////////////////////////////
56void reset_putx(unsigned int val)
[292]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++ )
[758]67    {
[292]68        buf[9-c] = HexaTab[val&0xF];
69        val = val >> 4;
70    }
[586]71    reset_puts(buf);
[292]72}
73
[586]74/////////////////////////////////
75void reset_putd(unsigned int val)
[292]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    }
[586]97    reset_puts( &buf[first] );
[292]98}
99
[586]100/////////////////
101void reset_exit()
[292]102{
103    register int pid;
104    asm volatile( "mfc0 %0, $15, 1": "=r"(pid) );
105
[586]106    reset_puts("\n!!! Exit Processor ");
107    reset_putx(pid);
108    reset_puts(" !!!\n");
[292]109
110    while(1) asm volatile("nop");   // infinite loop...
111}
112
[586]113
114
Note: See TracBrowser for help on using the repository browser.