Ignore:
Timestamp:
Nov 3, 2014, 10:53:00 AM (10 years ago)
Author:
alain
Message:

Introducing dynamic allocation of peripheral channel(TTY, NIC, TIM, CMA)
Removint the ICU driver : ICU component not supported anymore.
Removing the FBF driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_drivers/tty_driver.c

    r426 r437  
    55// Copyright (c) UPMC-LIP6
    66///////////////////////////////////////////////////////////////////////////////////
    7 // The tty_driver.c and tty_drivers.h files are part ot the GIET-VM kernel.
    8 // This driver supports the SocLib vci_multi_tty component.
    9 //
    10 // The total number of TTY terminals must be defined by the configuration
    11 // parameter NB_TTY_CHANNELS in the hard_config.h file.
    12 //
    13 // The "system" terminal is TTY[0].
    14 // The "user" TTYs are allocated to applications by the GIET in the boot phase,
    15 // as defined in the mapping_info data structure. The corresponding tty_id must
    16 // be stored in the context of the task by the boot code.
    17 //
    18 // The SEG_TTY_BASE address must be defined in the hard_config.h file.
    19 ///////////////////////////////////////////////////////////////////////////////////
    20 // Implementation note:
    21 //
    22 // All physical accesses to device registers are done by the two
    23 // _tty_get_register(), _tty_set_register() low-level functions,
    24 // that are handling virtual / physical addressing.
    25 ///////////////////////////////////////////////////////////////////////////////////
    267
    278#include <giet_config.h>
     9#include <hard_config.h>
    2810#include <tty_driver.h>
    2911#include <xcu_driver.h>
     
    4830
    4931//////////////////////////////////////////////////////////////////////////////
    50 //   TTY global variables
     32//               global variables
    5133//////////////////////////////////////////////////////////////////////////////
    5234
     
    6547
    6648//////////////////////////////////////////////////////////////////////////////
    67 // This low level function returns the value of register (channel / index)
     49//               access functions
    6850//////////////////////////////////////////////////////////////////////////////
     51
     52/////////////////////////////////////////////////////
    6953unsigned int _tty_get_register( unsigned int channel,
    7054                                unsigned int index )
     
    7458}
    7559
    76 //////////////////////////////////////////////////////////////////////////////
    77 // This low level function set a new value in register (channel / index) 
    78 //////////////////////////////////////////////////////////////////////////////
     60/////////////////////////////////////////////
    7961void _tty_set_register( unsigned int channel,
    8062                        unsigned int index,
     
    8567}
    8668
    87 /////////////////////////////////////////////////////////////////////////////////
    88 // This non-blocking function writes a character string from a fixed-length
    89 // buffer to a TTY terminal identified by the channel argument.
    90 // This function is intended to be used to handle a system call, and should
    91 // not be used by the kernel for log messages on TTY 0.
    92 // protecting exclusive access to the selected terminal.
    93 // If channel argument is 0xFFFFFFFF, the TTY index is found in the task context.
    94 // This is a non blocking call: it tests the TTY_STATUS register, and stops
    95 // the transfer as soon as the TTY_STATUS[WRITE] bit is set.
    96 /////////////////////////////////////////////////////////////////////////////////
    97 // Returns  the number of characters that have been written.
    98 /////////////////////////////////////////////////////////////////////////////////
    99 unsigned int _tty_write( const char*  buffer,   
    100                          unsigned int length,    // number of characters
    101                          unsigned int channel)   // channel index
    102 {
    103     unsigned int  nwritten;
    10469
    105     // compute and check tty channel
    106     if( channel == 0xFFFFFFFF )  channel = _get_context_slot(CTX_TTY_ID);
    107     if( channel >= NB_TTY_CHANNELS ) return -1;
    108 
    109     // write string to TTY channel
    110     for (nwritten = 0; nwritten < length; nwritten++)
    111     {
    112         // check tty's status
    113         if ( _tty_get_register( channel, TTY_STATUS ) & 0x2 )  break;
    114 
    115         // write one byte
    116         if (buffer[nwritten] == '\n') {
    117             _tty_set_register( channel, TTY_WRITE, (unsigned int)'\r' );
    118         }
    119         _tty_set_register( channel, TTY_WRITE, (unsigned int)buffer[nwritten] );
    120     }
    121    
    122     return nwritten;
    123 }
    124 
    125 //////////////////////////////////////////////////////////////////////////////
    126 // This non-blocking function fetches one character from the
    127 // terminal identified by the channel argument. If the channel argument
    128 // is 0xFFFFFFFF, the channel index is obtained from the current task context.
    129 // It uses the TTY_GET_IRQ[tty_id] interrupt and the buffer must have been
    130 // filled by the TTY_ISR.
    131 // It test the _tty_rx_full[tty_id] variable, read the _tty_rx_buf[tty_id]
    132 // buffer, writes this character to the target buffer, and resets the
    133 // _tty_rx_full[tty_id] register.
    134 // The length argument is not used.
    135 //////////////////////////////////////////////////////////////////////////////
    136 // Returns  the number of characters that have been read (0/1).
    137 //////////////////////////////////////////////////////////////////////////////
    138 unsigned int _tty_read( char*        buffer,
    139                         unsigned int length,    // unused
    140                         unsigned int channel)   // channel index
    141 {
    142     // compute and check tty channel
    143     if( channel == 0xFFFFFFFF )  channel = _get_context_slot(CTX_TTY_ID);
    144     if( channel >= NB_TTY_CHANNELS ) return -1;
    145 
    146     // read one character from TTY channel
    147     if (_tty_rx_full[channel] == 0)
    148     {
    149         return 0;
    150     }
    151     else
    152     {
    153         *buffer = _tty_rx_buf[channel];
    154         _tty_rx_full[channel] = 0;
    155         return 1;
    156     }
    157 }
    158 
    159 //////////////////////////////////////////////////////////////////////////////
    160 // This function try to take the lock protecting
    161 // exclusive access to TTY terminal identified by the "channel" argument.
    162 // It enters a critical section before taking the lock, and save the SR value
    163 // at address defined by the "save_sr_ptr" argument.
    164 // It returns only when the lock has been successfully taken.
    165 //////////////////////////////////////////////////////////////////////////////
    166 void _tty_get_lock( unsigned int   channel,
    167                     unsigned int * save_sr_ptr )
    168 {
    169     if( channel >= NB_TTY_CHANNELS ) _exit();
    170     _it_disable( save_sr_ptr );
    171     _get_lock( &_tty_lock[channel] );
    172 }
    173 
    174 //////////////////////////////////////////////////////////////////////////////
    175 // This function releases the hardwired lock protecting
    176 // exclusive access to TTY terminal identified by the channel argument.
    177 // It exit the critical section after lock release, and restore SR value
    178 // from address defined by the "save_sr_ptr" argument.
    179 //////////////////////////////////////////////////////////////////////////////
    180 void _tty_release_lock( unsigned int   channel,
    181                         unsigned int * save_sr_ptr )
    182 {
    183     if( channel >= NB_TTY_CHANNELS ) _exit();
    184     _release_lock( &_tty_lock[channel] );
    185     _it_restore( save_sr_ptr );
    186 }
    187 
    188 ///////////////////////////////////////////////////////////////////////////////////
    189 // This ISR handles the IRQ signaling that the RX buffer is not empty.
    190 // IT can be an HWI or an SWI.
    191 // There is one communication buffer _tty_rx_buf[i] and one synchronisation
    192 // variable _tty_rx_full[i] per channel.
    193 // Does nothing if the TTY_RX buffer is empty, or if the kernel buffer is full
    194 // when the ISR is called.
    195 ///////////////////////////////////////////////////////////////////////////////////
     70////////////////////////////////////////
    19671void _tty_rx_isr( unsigned int irq_type,   // HWI / WTI
    19772                  unsigned int irq_id,     // index returned by XCU
     
    242117}
    243118
    244 ///////////////////////////////////////////////////////////////////////////////////
    245 // This ISR handles the IRQ signaling that the TX buffer is empty.
    246 // IT can be an HWI or an SWI.
    247 // There is one single multi_tty component controling all channels.
    248 // There is one communication buffer _tty_rx_buf[i] and one synchronisation
    249 // variable _tty_rx_full[i] per channel.
    250 // A character is lost if the buffer is full when the ISR is executed.
    251 ///////////////////////////////////////////////////////////////////////////////////
     119/////////////////////////////////////////
    252120void _tty_tx_isr( unsigned int irq_type,   // HWI / WTI
    253121                  unsigned int irq_id,     // index returned by XCU
Note: See TracChangeset for help on using the changeset viewer.