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
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//               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////////////////////////////////////////////////////////////////////////////////////
31//               access functions
32////////////////////////////////////////////////////////////////////////////////////
33
34/////////////////////////////////////////////////////
35unsigned int _tty_get_register( unsigned int channel,
36                                unsigned int index )
37{
38    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
39    return _io_extended_read( vaddr );
40}
41
42/////////////////////////////////////////////
43void _tty_set_register( unsigned int channel,
44                        unsigned int index,
45                        unsigned int value )
46{
47    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
48    _io_extended_write( vaddr, value );
49}
50
51//////////////////////////////////////
52void _tty_init( unsigned int channel )
53{
54    _tty_rx_full[channel] = 0;
55}
56
57////////////////////////////////////////
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
61{
62    // transfer character to kernel buffer and acknowledge TTY IRQ
63    _tty_rx_buf[channel]  = _tty_get_register( channel, TTY_READ ); 
64
65    // flush pending memory writes
66    asm volatile( "sync" );
67
68    // set kernel buffer status
69    _tty_rx_full[channel] = 1;
70
71#if GIET_DEBUG_IRQS  // we don't take the TTY lock to avoid deadlock
72unsigned int gpid           = _get_procid();
73unsigned int cluster_xy     = gpid >> P_WIDTH;
74unsigned int x              = cluster_xy >> Y_WIDTH;
75unsigned int y              = cluster_xy & ((1<<Y_WIDTH)-1);
76unsigned int lpid           = gpid & ((1<<P_WIDTH)-1);
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
89
90}
91
92/////////////////////////////////////////
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
96{
97    _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
98    _exit();
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.