[1] | 1 | /* |
---|
| 2 | * dev_txt.h - TXT (Text Terminal) generic device API definition. |
---|
[49] | 3 | * |
---|
[1] | 4 | * Author Alain Greiner (2016) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _DEV_TXT_H_ |
---|
| 25 | #define _DEV_TXT_H_ |
---|
| 26 | |
---|
[14] | 27 | #include <kernel_config.h> |
---|
[1] | 28 | #include <hal_types.h> |
---|
[422] | 29 | #include <xlist.h> |
---|
| 30 | #include <remote_spinlock.h> |
---|
[1] | 31 | |
---|
| 32 | /**** Forward declarations ****/ |
---|
| 33 | |
---|
[3] | 34 | struct chdev_s ; |
---|
[1] | 35 | |
---|
| 36 | /****************************************************************************************** |
---|
| 37 | * Generic Text Terminal device definition. |
---|
| 38 | * |
---|
[49] | 39 | * This multi-channels generic TXT device provides access to a text terminal. |
---|
[407] | 40 | * |
---|
| 41 | * It supports two operations that must be implemented by the driver cmd() function: |
---|
[1] | 42 | * - TXT_READ : read a single character from the text terminal identified by its channel |
---|
| 43 | * index, using a descheduling strategy for the calling thread. |
---|
| 44 | * - TXT_WRITE : write a character string to the text terminal identified by its channel |
---|
| 45 | * index, using a descheduling strategy for the calling thread. |
---|
[407] | 46 | * |
---|
| 47 | * It supports one operation, that must be implemented by the driver aux() function |
---|
| 48 | * - TXT_SYNC_WRITE write a character string to the TXT0 kernel terminal, using a busy |
---|
| 49 | * waiting strategy for the calling thread. |
---|
[1] | 50 | *****************************************************************************************/ |
---|
| 51 | |
---|
| 52 | /****************************************************************************************** |
---|
[422] | 53 | * This defines the (implementation independant) extension for the generic TXT device. |
---|
| 54 | *****************************************************************************************/ |
---|
| 55 | |
---|
| 56 | typedef struct txt_extend_s |
---|
| 57 | { |
---|
| 58 | xptr_t owner_xp; /*! ext. pointer on current process owner (reference) */ |
---|
| 59 | xlist_entry_t root; /*! root of list of processes attached to same TXT */ |
---|
| 60 | remote_spinlock_t lock; /*! lock protecting this list */ |
---|
| 61 | } |
---|
| 62 | txt_extend_t; |
---|
| 63 | |
---|
| 64 | /****************************************************************************************** |
---|
[1] | 65 | * This enum defines the various implementations of the generic TXT peripheral. |
---|
| 66 | * This array must be kept consistent with the define in arch_info.h file |
---|
| 67 | *****************************************************************************************/ |
---|
| 68 | |
---|
| 69 | enum txt_impl_e |
---|
| 70 | { |
---|
[49] | 71 | IMPL_TXT_TTY = 0, |
---|
[254] | 72 | IMPL_TXT_RS2 = 1, |
---|
[1] | 73 | } |
---|
| 74 | txt_impl_t; |
---|
| 75 | |
---|
| 76 | /****************************************************************************************** |
---|
[407] | 77 | * This defines the arguments passed to the driver CMD function. |
---|
[1] | 78 | *****************************************************************************************/ |
---|
| 79 | |
---|
| 80 | enum |
---|
| 81 | { |
---|
| 82 | TXT_READ = 0, |
---|
| 83 | TXT_WRITE = 1, |
---|
[435] | 84 | TXT_SYNC_WRITE = 2, |
---|
[1] | 85 | }; |
---|
| 86 | |
---|
| 87 | typedef struct txt_command_s |
---|
| 88 | { |
---|
| 89 | xptr_t dev_xp; /*! extended pointer on the relevant TXT device descriptor */ |
---|
[435] | 90 | uint32_t type; /*! TXT_READ / TXT_WRITE */ |
---|
[1] | 91 | xptr_t buf_xp; /*! extended pointer on characters array */ |
---|
| 92 | uint32_t count; /*! number of characters in buffer (must be 1 if to_mem) */ |
---|
| 93 | uint32_t error; /*! operation status (0 if success) */ |
---|
| 94 | } |
---|
| 95 | txt_command_t; |
---|
| 96 | |
---|
| 97 | /****************************************************************************************** |
---|
[407] | 98 | * This defines the arguments passed to the driver AUX function. |
---|
| 99 | * This function implement the TXT_SYNC_WRITE operation. |
---|
| 100 | *****************************************************************************************/ |
---|
| 101 | |
---|
[435] | 102 | typedef struct txt_sync_args_s |
---|
[407] | 103 | { |
---|
[435] | 104 | xptr_t dev_xp; /*! extended pointer on the TXT0_TX device descriptor */ |
---|
[407] | 105 | char * buffer; /*! local pointer on characters array */ |
---|
| 106 | uint32_t count; /*! number of characters in buffer */ |
---|
| 107 | } |
---|
[435] | 108 | txt_sync_args_t; |
---|
[407] | 109 | |
---|
| 110 | /****************************************************************************************** |
---|
[435] | 111 | * This function returns a printable string for the comman type. |
---|
| 112 | ****************************************************************************************** |
---|
| 113 | * @ type : command type (TXT_READ / TXT_WRITE / TXT_SYNC_WRITE) |
---|
| 114 | *****************************************************************************************/ |
---|
| 115 | char * dev_txt_type_str( uint32_t type ); |
---|
| 116 | |
---|
| 117 | /****************************************************************************************** |
---|
[3] | 118 | * This function completes the TXT chdev descriptor initialisation, |
---|
[49] | 119 | * namely the link with the implementation specific driver. |
---|
[3] | 120 | * The func, impl, channel, is_rxt, base fields have been previously initialised. |
---|
[1] | 121 | * It calls the specific driver initialisation function, to initialise the hardware |
---|
| 122 | * device and the driver specific data structures when required. |
---|
[3] | 123 | * It creates the associated server thread and allocates a WTI from local ICU. |
---|
| 124 | * It must de executed by a local thread. |
---|
[1] | 125 | ****************************************************************************************** |
---|
[3] | 126 | * @ chdev : local pointer on TXT device descriptor. |
---|
[1] | 127 | *****************************************************************************************/ |
---|
[3] | 128 | void dev_txt_init( struct chdev_s * chdev ); |
---|
[1] | 129 | |
---|
| 130 | /****************************************************************************************** |
---|
[49] | 131 | * This blocking function reads a single character from the terminal identified |
---|
[1] | 132 | * by the "channel" argument. The corresponding request is actually registered in the |
---|
[3] | 133 | * chdev requests queue, and the calling thread is descheduled, blocked until |
---|
[1] | 134 | * transfer completion. |
---|
| 135 | * It must be called in the client cluster. |
---|
| 136 | ****************************************************************************************** |
---|
| 137 | * @ channel : TXT channel index. |
---|
| 138 | * @ buffer : local pointer on destination buffer for the character. |
---|
| 139 | * @ returns 0 if success / returns EINVAL if error. |
---|
| 140 | *****************************************************************************************/ |
---|
| 141 | error_t dev_txt_read( uint32_t channel, |
---|
| 142 | char * buffer ); |
---|
| 143 | |
---|
| 144 | /****************************************************************************************** |
---|
[49] | 145 | * This blocking function writes characters on the terminal identified |
---|
[1] | 146 | * by the "channel" argument. The corresponding request is actually registered in the |
---|
[3] | 147 | * chdev requests queue, and the calling thread is descheduled, blocked until |
---|
[1] | 148 | * transfer completion. |
---|
| 149 | * It must be called in the client cluster. |
---|
| 150 | ****************************************************************************************** |
---|
| 151 | * @ channel : TXT channel index. |
---|
| 152 | * @ buffer : local pointer on source buffer containing the string. |
---|
| 153 | * @ count : number of characters. |
---|
| 154 | * @ returns 0 if success / returns EINVAL if error. |
---|
| 155 | ****************************************************************************************/ |
---|
| 156 | error_t dev_txt_write( uint32_t channel, |
---|
| 157 | char * buffer, |
---|
| 158 | uint32_t count ); |
---|
| 159 | |
---|
[49] | 160 | /*************************************************************************************** |
---|
[407] | 161 | * This blocking function is used by the kernel to display a string on the TXT0 |
---|
| 162 | * terminal, without descheduling the calling thread, without registering it |
---|
| 163 | * in the TXT0 device waiting queue, without using the TXT0 irq, and without |
---|
| 164 | * interfering with another possible TXT access to another terminal. |
---|
| 165 | * As it is used for debug, the command arguments <buffer> and <count> are registerd |
---|
| 166 | * in a specific "dbg_cmd" field of the calling thread. |
---|
[1] | 167 | **************************************************************************************** |
---|
| 168 | * @ buffer : local pointer on source buffer containing the string. |
---|
| 169 | * @ count : number of characters. |
---|
| 170 | * @ returns 0 if success / returns EINVAL if error. |
---|
| 171 | ***************************************************************************************/ |
---|
[407] | 172 | error_t dev_txt_sync_write( char * buffer, |
---|
[1] | 173 | uint32_t count ); |
---|
| 174 | |
---|
| 175 | #endif /* _DEV_TXT_H_ */ |
---|