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

Last change on this file since 807 was 709, checked in by alain, 9 years ago

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
File size: 4.2 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//               extern variables
22////////////////////////////////////////////////////////////////////////////////////
23
24// This variable is allocated in kernel_init.c file
25extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
26
27////////////////////////////////////////////////////////////////////////////////////
28//               global variables
29////////////////////////////////////////////////////////////////////////////////////
30
31__attribute__((section(".kdata")))
32tty_fifo_t  _tty_rx_fifo[NB_TTY_CHANNELS];
33
34/*
35__attribute__((section(".kdata")))
36unsigned int   _tty_rx_buf[NB_TTY_CHANNELS];
37
38__attribute__((section(".kdata")))
39unsigned int   _tty_rx_full[NB_TTY_CHANNELS];
40
41__attribute__((section(".kdata")))
42unsigned int   _tty_rx_trdid[NB_TTY_CHANNELS];
43*/
44
45////////////////////////////////////////////////////////////////////////////////////
46//               access functions
47////////////////////////////////////////////////////////////////////////////////////
48
49/////////////////////////////////////////////////////
50unsigned int _tty_get_register( unsigned int channel,
51                                unsigned int index )
52{
53    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
54    return _io_extended_read( vaddr );
55}
56
57/////////////////////////////////////////////
58void _tty_set_register( unsigned int channel,
59                        unsigned int index,
60                        unsigned int value )
61{
62    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
63    _io_extended_write( vaddr, value );
64}
65
66//////////////////////////////////////
67void _tty_init( unsigned int channel )
68{
69    _tty_rx_fifo[channel].sts = 0;
70    _tty_rx_fifo[channel].ptr = 0;
71    _tty_rx_fifo[channel].ptw = 0;
72}
73
74////////////////////////////////////////
75void _tty_rx_isr( unsigned int irq_type,   // HWI / WTI
76                  unsigned int irq_id,     // index returned by XCU
77                  unsigned int channel )   // TTY channel
78{
79    // get pointer on TTY_RX FIFO
80    tty_fifo_t*   fifo = &_tty_rx_fifo[channel];
81
82    // get character from TTY_RX channel and acknowledge IRQ
83    unsigned int data = _tty_get_register( channel, TTY_READ ); 
84
85    // transfer character to FIFO if not full
86    // discard incoming character if full
87    if ( fifo->sts < TTY_FIFO_DEPTH )
88    {
89        // store data into FIFO
90        fifo->data[fifo->ptw] = (char)data; 
91
92        // avoid race
93        asm volatile( "sync" );
94
95        // update FIFO state
96        fifo->ptw = (fifo->ptw + 1) % TTY_FIFO_DEPTH;
97        fifo->sts = fifo->sts + 1;
98    }
99
100    // get owner thread indexes
101    unsigned int trdid          = fifo->trdid;
102    unsigned int x              = (trdid >> 24) & 0xFF;
103    unsigned int y              = (trdid >> 16) & 0xFF;
104    unsigned int p              = (trdid >>  8) & 0xFF;
105    unsigned int ltid           = (trdid      ) & 0xFF;
106
107    // Reset NORUN_MASK_TTY bit
108    static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
109    unsigned int*       ptr     = &psched->context[ltid].slot[CTX_NORUN_ID];
110    _atomic_and( ptr , ~NORUN_MASK_TTY );
111}
112
113/////////////////////////////////////////
114void _tty_tx_isr( unsigned int irq_type,   // HWI / WTI
115                  unsigned int irq_id,     // index returned by XCU
116                  unsigned int channel )   // TTY channel
117{
118    _printf("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
119    _exit();
120}
121
122// Local Variables:
123// tab-width: 4
124// c-basic-offset: 4
125// c-file-offsets:((innamespace . 0)(inline-open . 0))
126// indent-tabs-mode: nil
127// End:
128// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
129
Note: See TracBrowser for help on using the repository browser.