source: soft/giet_vm/giet_drivers/tty_driver.c @ 496

Last change on this file since 496 was 496, checked in by alain, 9 years ago

1) Introduce access functions to MMC intrumentation registers.
2) Use _printf for error or debug messages.

File size: 3.7 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : tty_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <giet_config.h>
9#include <hard_config.h>
10#include <tty_driver.h>
11#include <xcu_driver.h>
12#include <ctx_handler.h>
13#include <utils.h>
14#include <tty0.h>
15
16#if !defined(SEG_TTY_BASE)
17# error: You must define SEG_TTY_BASE in the hard_config.h file
18#endif
19
20////////////////////////////////////////////////////////////////////////////////////
21//               global variables
22////////////////////////////////////////////////////////////////////////////////////
23
24__attribute__((section(".kdata")))
25unsigned int   _tty_rx_buf[NB_TTY_CHANNELS];
26
27__attribute__((section(".kdata")))
28unsigned int   _tty_rx_full[NB_TTY_CHANNELS]; 
29
30////////////////////////////////////////////////////////////////////////////////////
31//               access functions
32////////////////////////////////////////////////////////////////////////////////////
33
34/////////////////////////////////////////////////////
35unsigned int _tty_get_register( unsigned int channel,
36                                unsigned int index )
37{
38    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
39    return _io_extended_read( vaddr );
40}
41
42/////////////////////////////////////////////
43void _tty_set_register( unsigned int channel,
44                        unsigned int index,
45                        unsigned int value )
46{
47    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
48    _io_extended_write( vaddr, value );
49}
50
51//////////////////////////////////////
52void _tty_init( unsigned int channel )
53{
54    _tty_rx_full[channel] = 0;
55}
56
57////////////////////////////////////////
58void _tty_rx_isr( unsigned int irq_type,   // HWI / WTI
59                  unsigned int irq_id,     // index returned by XCU
60                  unsigned int channel )   // TTY channel
61{
62    unsigned int gpid       = _get_procid();
63    unsigned int cluster_xy = gpid >> P_WIDTH;
64
65    // get TTY status
66    unsigned int status = _tty_get_register( channel, TTY_STATUS );
67
68    // check both TTY status and kernel buffer status:
69    // does nothing if kernel buffer full or tty_buffer empty
70    if ( ((status & 0x1) == 0) || 
71         (_tty_rx_full[channel] != 0) )  return;
72 
73    // reset WTI in XCU if WTI type
74    if ( irq_type == IRQ_TYPE_WTI ) 
75    {
76        unsigned int value;
77        _xcu_get_wti_value( cluster_xy, irq_id, &value );
78    }
79
80    // transfer character to kernel buffer and acknowledge TTY IRQ
81    _tty_rx_buf[channel]  = _tty_get_register( channel, TTY_READ ); 
82
83    // set kernel buffer status
84    asm volatile( "sync" );
85    _tty_rx_full[channel] = 1;
86
87#if GIET_DEBUG_IRQS  // we don't take the TTY lock to avoid deadlock
88unsigned int x              = cluster_xy >> Y_WIDTH;
89unsigned int y              = cluster_xy & ((1<<Y_WIDTH)-1);
90unsigned int lpid           = gpid & ((1<<P_WIDTH)-1);
91_puts("\n[IRQS DEBUG] Processor[");
92_putd(x );
93_puts(",");
94_putd(y );
95_puts(",");
96_putd(lpid );
97_puts("] enters _tty_rx_isr() at cycle ");
98_putd(_get_proctime() );
99_puts("\n  read byte = ");
100_putx(_tty_rx_buf[channel] );
101_puts("\n");
102#endif
103
104}
105
106/////////////////////////////////////////
107void _tty_tx_isr( unsigned int irq_type,   // HWI / WTI
108                  unsigned int irq_id,     // index returned by XCU
109                  unsigned int channel )   // TTY channel
110{
111    _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
112    _exit();
113}
114
115// Local Variables:
116// tab-width: 4
117// c-basic-offset: 4
118// c-file-offsets:((innamespace . 0)(inline-open . 0))
119// indent-tabs-mode: nil
120// End:
121// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
122
Note: See TracBrowser for help on using the repository browser.