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

Last change on this file since 457 was 456, checked in by alain, 10 years ago

Defining the NIC and CMA drivers (validated by the classif application).
Updating other drivers to comply with the new tty0 common file.

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