Changes between Initial Version and Version 1 of txt_device_api


Ignore:
Timestamp:
Jan 22, 2020, 12:02:43 AM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • txt_device_api

    v1 v1  
     1= TXT device API =
     2
     3[[PageOutline]]
     4
     5== __A) General principles__ ==
     6
     7The TXT device allows the kernel to access a text terminal peripheral. It is a multi-channel device, and there is one chdev per terminal, and per direction (TX/RX). The TXT0 (channel 0) is the kernel terminal.
     8
     9The "user" API, contains the functions used  the user-level system calls, and by the kernel itself for debug. It defines three operation types :  '''TXT_READ''', '''TXT_WRITE''', and '''TXT_SYNC_WRITE'''. This API is detailed in section C below.
     10
     11* The '''asynchronous''' READ and WRITE operations are not directly executed by the client thread. The READ and WRITE requests are registered in the waiting queue rooted in the TXT chdev descriptor. These requests are actually handled by a dedicated server thread running in the cluster containing the chdev descriptor, that call the ''txt_driver_cmd()'' function.
     12A WRITE operation (TX direction) moves N characters from a kernel buffer to the TXT terminal. A READ operation moves one single character from the TXT terminal to a kernel buffer.
     13
     14* The '''synchronous''' SYNC_WRITE operation is used by the kernel to display debug messages on the TXT0. It does not use the waiting queue, and it does not use the server thread. The client thread calls directly the ''txt_driver_aux()'' function, without using the the txt_command_t structure to communicate with the driver.
     15
     16Most TXT device implementation use two (hardware or software) FIFOs for asynchronous READ and WRITE operations. These FIFOs are not controlled by the kernel, but are controlled by the ''txt_driver_cmd()'' and ''txt_cxd_isr()''. When they are used by the driver, the TXT_TX_IRQ and TXT_RX_IRQ are routed to the core executing the corresponding TXT server thread. (ISR stand for Interrupt Service Routine).
     17
     18To access the various drivers, the TXT device defines a lower-level "driver" API, that is detailed in section D below.
     19
     20All TXT device structures and access functions are defined in the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/devices/dev_txt.c  dev_txt.c] et [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/devices/dev_txt.h dev_txt.h] files.
     21
     22== __B) Initialisation__ ==
     23
     24The TXT device '''dev_txt_init( chdev_t * chdev )''' function makes the following initializations :
     25 * It selects a core in cluster containing the TXT chdev to execute the server thread.
     26 * it links the TXT channel IRQ to the core executing the server thread.
     27 * it initialises the TXT specific fields of the chdev descriptor.
     28 * it initialises the implementation specific TXT hardware device,
     29 * it initializes the specific software data structures required by the hardware implementation.
     30It must be called by a local thread.
     31
     32== __C) The "user" API__ ==
     33
     34These three I/O operations are blocking, and return only when the transfer is completed, but the blocking policy depends on the operation type.
     35
     36=== C.1) Asynchronous operations ===
     37
     38* The '''dev_txt_read( uint32_t channel , char * buffer  )''' function moves  one character from the terminal identified by the <channel> argument to the local  kernel buffer identified by the <buffer> pointer.
     39* The '''dev_txt_write( uint32_t channel , char * buffer , uint32_t count  )''' function moves  <count> characters from a local kernel buffer identified by the <buffer> pointer, to the terminal identified by the <channel> argument.
     40
     41The kernel buffer is allocated in the kernel stack of the client thread.
     42
     43Almos-mkh uses these '''asynchronous''' operations, for most data transfers required by the user processes.
     44
     45The scenario is the following :
     46
     47 1. When a client thread request an I/O operation, the request is registered in the ''ioc_command_t'' structure embedded in the client thread descriptor, and the client thread registers itself in the waiting queue rooted in the IOC chdev. Then the client thread blocks on the THREAD_BLOCKED_IO condition, and deschedules.
     48 1. The DEV server thread attached to the IOC device descriptor handles all commands registered in the IOC device waiting queue. For each pending request, it calls the IOC driver CMD (command) function to ask the hardware device to do the transfer. Then, the server thread blocks on the THREAD_BLOCKED_ISR condition, and deschedules. 
     49 1. When the I/O operation completed, the IOC driver ISR (Interrupt Service Routine) signaling completion reactivates the server thread.
     50 1. The server thread reactivates the client thread, and handle the next request in the IOC waiting queue, or reschedules if the queue is empty.
     51
     52Note : According to the scheduler policy, the DEV thread has an higher priority than any user thread, but it is not selected when the associated waiting queue is empty.
     53
     54=== C.2) Synchronous operations ===
     55
     56* The '''dev_txt_sync_write( char * buffer , uint32_t count  )''' function moves  <count> characters from the the kernel buffer identified by the <buffer> pointer, to the kernel TXT0 terminal.
     57
     58Almost-mkh uses this operation to synchronously display debug or log information on the kernel terminal using the print()
     59kernel function, and we want to avoid any interference with another TXT I/O operation. We don't want to use the TXT device waiting queue, the associated server thread, and the ''txt_command_t'' structures used by the ''txt_driver_cmd()'' function. Therefore, this function directly call the ''txt_driver_aux()'' function, and the txt_sync_args_s structure for the arguments.
     60 
     61These synchronous operations use neither the IOC device waiting queue, nor the DEV server thread, and the  IRQ. The client thread does not deschedules : it registers the arguments in the IOC command structure embedded in the client thread descriptor, and calls directly the blocking IOC driver CMD function,
     62
     63== __D) The "driver" API__ ==
     64
     65All TXT drivers must define four functions :
     66* void '''txt_driver_init( chdev_t *ioc_chdev )'''
     67* void '''txt_driver_cmd'''( xptr_t  thread_xp )'''
     68* void '''txt_driver_isr'''( chdev_t * ioc_chdev )'''
     69* void '''txt_driver_aux'''( char * buffer , uint32_t count )'''
     70
     71The '''txt_driver_cmd()''' function arguments are registered in the ''txt_command_t'' structure embedded in the client thread descriptor. One command contains four informations:
     72 - '''type''' : operation type (TXT_READ / TXT_WRITE)
     73 - '''buf_xp''' : extended pointer on kernel buffer.
     74 - '''count''' : number of characters (only for TXT_WRITE).
     75
     76For asynchronous operations the '''txt_driver_cmd()''' function is called by the server thread, that blocks and deschedules after launching the I/O transfer. When the TXT_IRQ is raised by the hardware, the '''ioc_driver_isr()''' function reports the I/O operation status, and re-activates the server thread.
     77
     78The '''txt_driver_aux()''' function doesn't use the ''txt_command_t'' structure embedded in the thread  descriptor. The two
     79arguments are the <buffer> pointer on the kernel buffer, and the number of characters <count>.