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

Last change on this file since 448 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
RevLine 
[258]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>
[437]9#include <hard_config.h>
[258]10#include <tty_driver.h>
[295]11#include <xcu_driver.h>
[258]12#include <ctx_handler.h>
13#include <utils.h>
14
[320]15#if !defined(SEG_TTY_BASE)
16# error: You must define SEG_TTY_BASE in the hard_config.h file
17#endif
18
[258]19#if !defined(NB_TTY_CHANNELS)
20# error: You must define NB_TTY_CHANNELS in the hard_config.h file
21#endif
22
[350]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
[258]27#if (NB_TTY_CHANNELS < 1)
28# error: NB_TTY_CHANNELS cannot be smaller than 1!
29#endif
30
[295]31//////////////////////////////////////////////////////////////////////////////
[437]32//                global variables
[295]33//////////////////////////////////////////////////////////////////////////////
34
[350]35#define in_unckdata __attribute__((section (".unckdata")))
36#define in_kdata    __attribute__((section (".kdata")))
37
38#if GIET_NO_HARD_CC
[295]39in_unckdata volatile unsigned int _tty_rx_buf[NB_TTY_CHANNELS];
[350]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
[313]47
[295]48//////////////////////////////////////////////////////////////////////////////
[437]49//               access functions
[295]50//////////////////////////////////////////////////////////////////////////////
[437]51
52/////////////////////////////////////////////////////
[295]53unsigned int _tty_get_register( unsigned int channel,
54                                unsigned int index )
55{
[320]56    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]57    return _io_extended_read( vaddr );
58}
59
[437]60/////////////////////////////////////////////
[295]61void _tty_set_register( unsigned int channel,
62                        unsigned int index,
63                        unsigned int value )
64{
[320]65    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]66    _io_extended_write( vaddr, value );
67}
68
[258]69
[437]70////////////////////////////////////////
[295]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
[258]74{
[426]75    unsigned int gpid       = _get_procid();
76    unsigned int cluster_xy = gpid >> P_WIDTH;
[258]77
[297]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 ) 
[258]88    {
[295]89        unsigned int value;
90        _xcu_get_wti_value( cluster_xy, irq_id, &value );
[258]91    }
92
[297]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
[295]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);
[426]103unsigned int lpid           = gpid & ((1<<P_WIDTH)-1);
[295]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
[258]116
117}
118
[437]119/////////////////////////////////////////
[295]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
[258]123{
[295]124    _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
125    _exit();
[258]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.