![]() |
|
|||
File indexing completed on 2025-05-11 08:24:14
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup TermiostypesSupport 0007 * 0008 * @brief This header file provides the interfaces of the 0009 * @ref TermiostypesSupport. 0010 */ 0011 0012 /* 0013 * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG 0014 * 0015 * Redistribution and use in source and binary forms, with or without 0016 * modification, are permitted provided that the following conditions 0017 * are met: 0018 * 1. Redistributions of source code must retain the above copyright 0019 * notice, this list of conditions and the following disclaimer. 0020 * 2. Redistributions in binary form must reproduce the above copyright 0021 * notice, this list of conditions and the following disclaimer in the 0022 * documentation and/or other materials provided with the distribution. 0023 * 0024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0034 * POSSIBILITY OF SUCH DAMAGE. 0035 */ 0036 0037 #ifndef _RTEMS_TERMIOSDEVICE_H 0038 #define _RTEMS_TERMIOSDEVICE_H 0039 0040 #include <rtems/thread.h> 0041 #include <rtems/rtems/intr.h> 0042 0043 #include <sys/ioccom.h> 0044 0045 #ifdef __cplusplus 0046 extern "C" { 0047 #endif /* __cplusplus */ 0048 0049 struct rtems_libio_open_close_args; 0050 struct rtems_termios_tty; 0051 struct termios; 0052 0053 /** 0054 * @defgroup TermiostypesSupport RTEMS Termios Device Support 0055 * 0056 * @ingroup libcsupport 0057 * 0058 * @brief This group contains the Termios Device Support provided by RTEMS. 0059 */ 0060 0061 /** 0062 * @brief Termios device context. 0063 * 0064 * @see RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER(), 0065 * rtems_termios_device_context_initialize() and 0066 * rtems_termios_device_install(). 0067 */ 0068 typedef struct rtems_termios_device_context { 0069 union { 0070 /* Used for TERMIOS_POLLED and TERMIOS_IRQ_DRIVEN */ 0071 rtems_interrupt_lock interrupt; 0072 0073 /* Used for TERMIOS_IRQ_SERVER_DRIVEN and TERMIOS_TASK_DRIVEN */ 0074 rtems_mutex mutex; 0075 } lock; 0076 0077 void ( *lock_acquire )( 0078 struct rtems_termios_device_context *, 0079 rtems_interrupt_lock_context * 0080 ); 0081 0082 void ( *lock_release )( 0083 struct rtems_termios_device_context *, 0084 rtems_interrupt_lock_context * 0085 ); 0086 } rtems_termios_device_context; 0087 0088 typedef enum { 0089 TERMIOS_POLLED, 0090 TERMIOS_IRQ_DRIVEN, 0091 TERMIOS_TASK_DRIVEN, 0092 TERMIOS_IRQ_SERVER_DRIVEN 0093 } rtems_termios_device_mode; 0094 0095 /** 0096 * @brief Termios device handler. 0097 * 0098 * @see rtems_termios_device_install(). 0099 */ 0100 typedef struct { 0101 /** 0102 * @brief First open of this device. 0103 * 0104 * @param[in] tty The Termios control. This parameter may be passed to 0105 * interrupt service routines since it must be provided for the 0106 * rtems_termios_enqueue_raw_characters() and 0107 * rtems_termios_dequeue_characters() functions. 0108 * @param[in] context The Termios device context. 0109 * @param[in] term The current Termios attributes. 0110 * @param[in] args The open/close arguments. This is parameter provided to 0111 * support legacy drivers. It must not be used by new drivers. 0112 * 0113 * @retval true Successful operation. 0114 * @retval false Cannot open device. 0115 * 0116 * @see rtems_termios_get_device_context() and rtems_termios_set_best_baud(). 0117 */ 0118 bool (*first_open)( 0119 struct rtems_termios_tty *tty, 0120 rtems_termios_device_context *context, 0121 struct termios *term, 0122 struct rtems_libio_open_close_args *args 0123 ); 0124 0125 /** 0126 * @brief Last close of this device. 0127 * 0128 * @param[in] tty The Termios control. 0129 * @param[in] context The Termios device context. 0130 * @param[in] args The open/close arguments. This is parameter provided to 0131 * support legacy drivers. It must not be used by new drivers. 0132 */ 0133 void (*last_close)( 0134 struct rtems_termios_tty *tty, 0135 rtems_termios_device_context *context, 0136 struct rtems_libio_open_close_args *args 0137 ); 0138 0139 /** 0140 * @brief Polled read. 0141 * 0142 * In case mode is TERMIOS_IRQ_DRIVEN, TERMIOS_IRQ_SERVER_DRIVEN or 0143 * TERMIOS_TASK_DRIVEN, then data is received via 0144 * rtems_termios_enqueue_raw_characters(). 0145 * 0146 * @param[in] context The Termios device context. 0147 * 0148 * @retval char The received data encoded as unsigned char. 0149 * @retval -1 No data currently available. 0150 */ 0151 int (*poll_read)(rtems_termios_device_context *context); 0152 0153 /** 0154 * @brief Polled write in case mode is TERMIOS_POLLED or write support 0155 * otherwise. 0156 * 0157 * @param[in] context The Termios device context. 0158 * @param[in] buf The output buffer. 0159 * @param[in] len The output buffer length in characters. 0160 */ 0161 void (*write)( 0162 rtems_termios_device_context *context, 0163 const char *buf, 0164 size_t len 0165 ); 0166 0167 /** 0168 * @brief Set attributes after a Termios settings change. 0169 * 0170 * @param[in] context The Termios device context. 0171 * @param[in] term The new Termios attributes. 0172 * 0173 * @retval true Successful operation. 0174 * @retval false Invalid attributes. 0175 */ 0176 bool (*set_attributes)( 0177 rtems_termios_device_context *context, 0178 const struct termios *term 0179 ); 0180 0181 /** 0182 * @brief IO control handler. 0183 * 0184 * Invoked in case the Termios layer cannot deal with the IO request. 0185 * 0186 * @param[in] context The Termios device context. 0187 * @param[in] request The IO control request. 0188 * @param[in] buffer The IO control buffer. 0189 */ 0190 int (*ioctl)( 0191 rtems_termios_device_context *context, 0192 ioctl_command_t request, 0193 void *buffer 0194 ); 0195 0196 /** 0197 * @brief Termios device mode. 0198 */ 0199 rtems_termios_device_mode mode; 0200 } rtems_termios_device_handler; 0201 0202 /** 0203 * @brief Termios device flow control handler. 0204 * 0205 * @see rtems_termios_device_install(). 0206 */ 0207 typedef struct { 0208 /** 0209 * @brief Indicate to stop remote transmitter. 0210 * 0211 * @param[in] context The Termios device context. 0212 */ 0213 void (*stop_remote_tx)(rtems_termios_device_context *context); 0214 0215 /** 0216 * @brief Indicate to start remote transmitter. 0217 * 0218 * @param[in] context The Termios device context. 0219 */ 0220 void (*start_remote_tx)(rtems_termios_device_context *context); 0221 } rtems_termios_device_flow; 0222 0223 void rtems_termios_device_lock_acquire_default( 0224 rtems_termios_device_context *ctx, 0225 rtems_interrupt_lock_context *lock_context 0226 ); 0227 0228 void rtems_termios_device_lock_release_default( 0229 rtems_termios_device_context *ctx, 0230 rtems_interrupt_lock_context *lock_context 0231 ); 0232 0233 /** 0234 * @brief Initializes a device context. 0235 * 0236 * @param[in] context The Termios device context. 0237 * @param[in] name The name for the interrupt lock. This name must be a 0238 * string persistent throughout the life time of this lock. The name is only 0239 * used if profiling is enabled. 0240 */ 0241 static inline void rtems_termios_device_context_initialize( 0242 rtems_termios_device_context *context, 0243 const char *name 0244 ) 0245 { 0246 rtems_interrupt_lock_initialize( &context->lock.interrupt, name ); 0247 context->lock_acquire = rtems_termios_device_lock_acquire_default; 0248 context->lock_release = rtems_termios_device_lock_release_default; 0249 } 0250 0251 /** 0252 * @brief Initializer for static initialization of Termios device contexts. 0253 * 0254 * @param name The name for the interrupt lock. It must be a string. The name 0255 * is only used if profiling is enabled. 0256 */ 0257 #define RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( name ) \ 0258 { \ 0259 { RTEMS_INTERRUPT_LOCK_INITIALIZER( name ) }, \ 0260 rtems_termios_device_lock_acquire_default, \ 0261 rtems_termios_device_lock_release_default \ 0262 } 0263 0264 /** 0265 * @brief Acquires the device lock. 0266 * 0267 * @param[in] context The device context. 0268 * @param[in] lock_context The local interrupt lock context for an acquire and 0269 * release pair. 0270 */ 0271 static inline void rtems_termios_device_lock_acquire( 0272 rtems_termios_device_context *context, 0273 rtems_interrupt_lock_context *lock_context 0274 ) 0275 { 0276 ( *context->lock_acquire )( context, lock_context ); 0277 } 0278 0279 /** 0280 * @brief Releases the device lock. 0281 * 0282 * @param[in] context The device context. 0283 * @param[in] lock_context The local interrupt lock context for an acquire and 0284 * release pair. 0285 */ 0286 static inline void rtems_termios_device_lock_release( 0287 rtems_termios_device_context *context, 0288 rtems_interrupt_lock_context *lock_context 0289 ) 0290 { 0291 ( *context->lock_release )( context, lock_context ); 0292 } 0293 0294 /** @} */ 0295 0296 #ifdef __cplusplus 0297 } 0298 #endif /* __cplusplus */ 0299 0300 #endif /* _RTEMS_TERMIOSDEVICE_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |