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

Last change on this file since 605 was 605, checked in by guerin, 9 years ago

tty: don't manually reset WTI

It is already done in hardware, and can cause hardlocks.

File size: 3.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>
[456]14#include <tty0.h>
[258]15
[320]16#if !defined(SEG_TTY_BASE)
17# error: You must define SEG_TTY_BASE in the hard_config.h file
18#endif
19
[456]20////////////////////////////////////////////////////////////////////////////////////
[496]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////////////////////////////////////////////////////////////////////////////////////
[437]31//               access functions
[456]32////////////////////////////////////////////////////////////////////////////////////
[437]33
34/////////////////////////////////////////////////////
[295]35unsigned int _tty_get_register( unsigned int channel,
36                                unsigned int index )
37{
[320]38    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]39    return _io_extended_read( vaddr );
40}
41
[437]42/////////////////////////////////////////////
[295]43void _tty_set_register( unsigned int channel,
44                        unsigned int index,
45                        unsigned int value )
46{
[320]47    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]48    _io_extended_write( vaddr, value );
49}
50
[456]51//////////////////////////////////////
52void _tty_init( unsigned int channel )
53{
54    _tty_rx_full[channel] = 0;
55}
[258]56
[437]57////////////////////////////////////////
[295]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
[258]61{
[604]62    // transfer character to kernel buffer and acknowledge TTY IRQ
[297]63    _tty_rx_buf[channel]  = _tty_get_register( channel, TTY_READ ); 
64
[604]65    // flush pending memory writes
66    asm volatile( "sync" );
67
[297]68    // set kernel buffer status
69    _tty_rx_full[channel] = 1;
70
[295]71#if GIET_DEBUG_IRQS  // we don't take the TTY lock to avoid deadlock
[605]72unsigned int gpid           = _get_procid();
73unsigned int cluster_xy     = gpid >> P_WIDTH;
[295]74unsigned int x              = cluster_xy >> Y_WIDTH;
75unsigned int y              = cluster_xy & ((1<<Y_WIDTH)-1);
[426]76unsigned int lpid           = gpid & ((1<<P_WIDTH)-1);
[295]77_puts("\n[IRQS DEBUG] Processor[");
78_putd(x );
79_puts(",");
80_putd(y );
81_puts(",");
82_putd(lpid );
83_puts("] enters _tty_rx_isr() at cycle ");
84_putd(_get_proctime() );
85_puts("\n  read byte = ");
86_putx(_tty_rx_buf[channel] );
87_puts("\n");
88#endif
[258]89
90}
91
[437]92/////////////////////////////////////////
[295]93void _tty_tx_isr( unsigned int irq_type,   // HWI / WTI
94                  unsigned int irq_id,     // index returned by XCU
95                  unsigned int channel )   // TTY channel
[258]96{
[295]97    _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
98    _exit();
[258]99}
100
101// Local Variables:
102// tab-width: 4
103// c-basic-offset: 4
104// c-file-offsets:((innamespace . 0)(inline-open . 0))
105// indent-tabs-mode: nil
106// End:
107// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
108
Note: See TracBrowser for help on using the repository browser.