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

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

Introducing dynamic allocation of peripheral channel(TTY, NIC, TIM, CMA)
Removint the ICU driver : ICU component not supported anymore.
Removing the FBF driver.

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