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

Last change on this file since 722 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
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////////////////////////////////////////////////////////////////////////////////////
[709]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////////////////////////////////////////////////////////////////////////////////////
[496]28//               global variables
29////////////////////////////////////////////////////////////////////////////////////
30
31__attribute__((section(".kdata")))
[709]32tty_fifo_t  _tty_rx_fifo[NB_TTY_CHANNELS];
33
34/*
35__attribute__((section(".kdata")))
[496]36unsigned int   _tty_rx_buf[NB_TTY_CHANNELS];
37
38__attribute__((section(".kdata")))
39unsigned int   _tty_rx_full[NB_TTY_CHANNELS];
40
[709]41__attribute__((section(".kdata")))
42unsigned int   _tty_rx_trdid[NB_TTY_CHANNELS];
43*/
44
[496]45////////////////////////////////////////////////////////////////////////////////////
[437]46//               access functions
[456]47////////////////////////////////////////////////////////////////////////////////////
[437]48
49/////////////////////////////////////////////////////
[295]50unsigned int _tty_get_register( unsigned int channel,
51                                unsigned int index )
52{
[320]53    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]54    return _io_extended_read( vaddr );
55}
56
[437]57/////////////////////////////////////////////
[295]58void _tty_set_register( unsigned int channel,
59                        unsigned int index,
60                        unsigned int value )
61{
[320]62    unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index;
[295]63    _io_extended_write( vaddr, value );
64}
65
[456]66//////////////////////////////////////
67void _tty_init( unsigned int channel )
68{
[709]69    _tty_rx_fifo[channel].sts = 0;
70    _tty_rx_fifo[channel].ptr = 0;
71    _tty_rx_fifo[channel].ptw = 0;
[456]72}
[258]73
[437]74////////////////////////////////////////
[295]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
[258]78{
[709]79    // get pointer on TTY_RX FIFO
80    tty_fifo_t*   fifo = &_tty_rx_fifo[channel];
[297]81
[709]82    // get character from TTY_RX channel and acknowledge IRQ
83    unsigned int data = _tty_get_register( channel, TTY_READ ); 
[604]84
[709]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; 
[297]91
[709]92        // avoid race
93        asm volatile( "sync" );
[258]94
[709]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 );
[258]111}
112
[437]113/////////////////////////////////////////
[295]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
[258]117{
[709]118    _printf("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");
[295]119    _exit();
[258]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.