wiki:tty_driver

Version 3 (modified by alain, 10 years ago) (diff)

--

GIET-VM / TTY Driver

The tty_driver.c and tty_driver.h files define the TTY driver.

This vci_multi_tty component is a multi-terminals controller. It is an external peripheral.

The total number of terminals must be defined by the configuration parameter NB_TTY_CHANNELS in the hard_config.h file.

The kernel terminal is TTY[0]. The user TTYs are allocated to applications by the GIET-VM in the boot phase, as defined in the mapping. The corresponding global index is stored in the context of the task.

The SEG_TTY_BASE address must be defined in the hard_config.h file.

The virtual base address of the associated segment is vbase = SEG_TTY_BASE + cluster_io << 32

The addressable registers map are defined here.

unsigned int _tty_get_register( unsigned int channel, unsigned int index )

This low level function returns the value of register (channel / index).

void _tty_set_register( unsigned int channel, unsigned int index, unsigned int value )

This low level function set a new value in register (channel / index).

unsigned int _tty_write( const char* buffer, unsigned int length, unsigned int channel )

This non-blocking function writes a character string from a fixed-length buffer to a TTY terminal identified by the channel argument. This function is intended to be used to handle a system call, and should not be used by the kernel for log messages on TTY 0. If channel argument is 0xFFFFFFFF, the TTY index is found in the task context. It is non blocking: it tests the TTY_STATUS register, and stops the transfer as soon as the TTY_STATUS[WRITE] bit is set. Returns the number of characters that have been written.

unsigned int _tty_read( char* buffer, unsigned int length, unsigned int channel )

This non-blocking function fetches one character from the terminal identified by the channel argument. If the channel argument is 0xFFFFFFFF, the channel index is obtained from the current task context. It uses the TTY_GET_IRQ[tty_id] interrupt and the buffer must have been filled by the TTY_ISR. It test the _tty_rx_full[tty_id] variable, read the _tty_rx_buf[tty_id] buffer, writes this character to the target buffer, and resets the_tty_rx_full[tty_id] register. The length argument is not used. Returns the number of characters that have been read (0/1).

void _tty_get_lock( unsigned int channel, unsigned int* save_sr_ptr )

This blocking function try to take the lock protecting exclusive access to TTY terminal identified by the "channel" argument. It enters a critical section before taking the lock, and save the SR value at address defined by the save_sr_ptr argument. It returns only when the lock has been successfully taken.

void _tty_release_lock( unsigned int channel, unsigned int* save_sr_ptr )

This function releases the lock protecting exclusive access to TTY terminal identified by the channel argument. It exit the critical section after lock release, and restore SR value from address defined by the save_sr_ptr argument.

void _tty_rx_isr( unsigned int irq_type, unsigned int irq_id, unsigned int channel )

This Interrupt Service Routine handles the IRQ signaling that the RX buffer is not empty. IT can be an HWI or an SWI. There is one communication buffer _tty_rx_buf[i] and one synchronisation variable _tty_rx_full[i] per channel. It does nothing if the TTY_RX buffer is empty, or if the kernel buffer is full when the ISR is called.

void _tty_tx_isr( unsigned int irq_type, unsigned int irq_id, unsigned int channel )

This Interrupt Service Routine handles the IRQ signaling that the TX buffer is empty. IT can be an HWI or an SWI. There is one communication buffer _tty_rx_buf[i] and one synchronisation variable _tty_rx_full[i] per channel. A character is lost if the buffer is full when the ISR is executed. It is not implemented yet...