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

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

The global variables associated to TTY channels are not anymore
defined in the tty_driver.c file, but in the boot.c and kernel_init.c files.

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