source: trunk/boot/tsar_mips32/boot_tty_driver.c @ 563

Last change on this file since 563 was 556, checked in by nicolas.van.phan@…, 3 years ago

Gather LETI-specific macros into hard_config.h

File size: 3.6 KB
Line 
1/*
2 * boot_tty_driver.c - TSAR bootloader TTY driver implementation.
3 *
4 * Authors :   Alain Greiner / Vu Son  (2016)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <boot_config.h>
25#include <boot_tty_driver.h>
26#include <hal_kernel_types.h>
27#include <boot_utils.h>
28
29#ifndef SEG_TXT_BASE
30# error "The SEG_TXT_BASE value should be defined in the 'hard_config.h' file"
31#endif
32
33#ifndef X_IO 
34# error "The X_IO value should be defined in the 'hard_config.h' file"
35#endif
36
37#ifndef Y_IO 
38# error "The Y_IO value should be defined in the 'hard_config.h' file"
39#endif
40
41#ifndef Y_WIDTH
42# error "The Y_WIDTH value should be defined in the 'hard_config.h' file"
43#endif
44
45#ifndef TXT_TGT_CLUSTER
46# error "The TXT_TGT_CLUSTER value should be defined in the 'hard_config.h' file"
47#endif
48
49/////////////////////////////////////////////////////////////////////////////
50// This function returns the value contained in a TTY0 register.
51// @ reg    : register to be read.
52// @ returns the value stored in 'reg'.
53/////////////////////////////////////////////////////////////////////////////
54static uint32_t boot_tty_get_register( uint32_t reg )
55{
56    cxy_t      cxy = TXT_TGT_CLUSTER;
57    uint32_t * ptr = (uint32_t *)SEG_TXT_BASE + reg;
58   
59    return boot_remote_lw( XPTR( cxy , ptr ) ); 
60   
61} // boot_tty_get_register()
62
63/////////////////////////////////////////////////////////////////////////////
64// This function sets a new value to a TTY0 register.
65// @ reg    : register to be configured.
66// @ val    : new value to be written to 'reg'.
67/////////////////////////////////////////////////////////////////////////////
68static void boot_tty_set_register( uint32_t reg, 
69                                   uint32_t val )
70{
71    cxy_t      cxy = TXT_TGT_CLUSTER;
72    uint32_t * ptr = (uint32_t *)SEG_TXT_BASE + reg;
73
74    boot_remote_sw( XPTR( cxy , ptr ) , val ); 
75
76} // boot_tty_set_register()
77
78//////////////////////////////////
79int boot_tty_write( const char * buf,
80                    uint32_t     nbytes )
81{
82    uint32_t nb_printed;
83    uint32_t nb_test;
84    uint32_t error; 
85
86    // Print nbytes to TTY0 terminal
87    for (nb_printed = 0; nb_printed < nbytes; nb_printed++)
88    {
89        // Poll the TTY0 status.
90        if ((boot_tty_get_register(TTY_STATUS_REG) & TTY_STATUS_TX_FULL))
91        {
92            error = 1;
93            for (nb_test = 0; nb_test < 10000; nb_test++)
94            {
95                if ((boot_tty_get_register(TTY_STATUS_REG) & TTY_STATUS_TX_FULL) == 0)
96                {
97                    error = 0;
98                    break;
99                }
100            }
101
102            // Report error after 10000 retries.
103            if (error) return -1;
104        }
105
106        // Write one character to TTY0 terminal.
107        // Special treatment for a newline: Carriage Return before Line Feed.
108        if (buf[nb_printed] == '\n') boot_tty_set_register(TTY_WRITE_REG , (uint32_t)'\r');
109        boot_tty_set_register(TTY_WRITE_REG , (uint32_t)buf[nb_printed]);
110    }
111
112    return 0;
113
114} // boot_tty_write()
Note: See TracBrowser for help on using the repository browser.