source: rtems/cpukit/libcsupport/include/rtems/termiostypes.h @ 1c6926c1

Last change on this file since 1c6926c1 was 1c6926c1, checked in by Kevin Kirspel <kevin-kirspel@…>, on Mar 21, 2017 at 7:39:48 PM

termios: Synchronize with latest FreeBSD headers

Adding modified FreeBSD headers to synchronize RTEMS termios with
FreeBSD. Modify termios to support dedicated input and output baud for
termios structure. Updated BSPs to use dedicated input and output baud
in termios structure. Updated tools to use dedicated input and output
baud in termios structure. Updated termios testsuites to use dedicated
input and output baud in termios structure.

Close #2897.

  • Property mode set to 100644
File size: 15.0 KB
Line 
1/**
2 * @file rtems/termiostypes.h
3 *
4 * RTEMS termios device support internal data structures
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2011.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#ifndef  __TERMIOSTYPES_H
17#define  __TERMIOSTYPES_H
18
19#include <rtems.h>
20#include <rtems/libio.h>
21#include <rtems/assoc.h>
22#include <rtems/chain.h>
23#include <stdint.h>
24#include <termios.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 *  @defgroup TermiostypesSupport RTEMS Termios Device Support
32 *
33 *  @ingroup libcsupport
34 *
35 *  @brief RTEMS Termios Device Support Internal Data Structures
36 */
37
38/*
39 * Wakeup callback data structure
40 */
41struct ttywakeup {
42  void      (*sw_pfn)(struct termios *tty, void *arg);
43  void      *sw_arg;
44};
45
46/*
47 * Variables associated with the character buffer
48 */
49struct rtems_termios_rawbuf {
50  char *theBuf;
51  volatile unsigned int  Head;
52  volatile unsigned int  Tail;
53  volatile unsigned int  Size;
54  rtems_id    Semaphore;
55};
56
57typedef enum {
58  TERMIOS_POLLED,
59  TERMIOS_IRQ_DRIVEN,
60  TERMIOS_TASK_DRIVEN,
61  TERMIOS_IRQ_SERVER_DRIVEN
62} rtems_termios_device_mode;
63
64struct rtems_termios_tty;
65
66/**
67 * @brief Termios device context.
68 *
69 * @see RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER(),
70 * rtems_termios_device_context_initialize() and
71 * rtems_termios_device_install().
72 */
73typedef struct rtems_termios_device_context {
74  union {
75    /* Used for TERMIOS_POLLED and TERMIOS_IRQ_DRIVEN */
76    rtems_interrupt_lock interrupt;
77
78    /* Used for TERMIOS_IRQ_SERVER_DRIVEN or TERMIOS_TASK_DRIVEN */
79    rtems_id mutex;
80  } lock;
81
82  void ( *lock_acquire )(
83    struct rtems_termios_device_context *,
84    rtems_interrupt_lock_context *
85  );
86
87  void ( *lock_release )(
88    struct rtems_termios_device_context *,
89    rtems_interrupt_lock_context *
90  );
91} rtems_termios_device_context;
92
93void rtems_termios_device_lock_acquire_default(
94  rtems_termios_device_context *ctx,
95  rtems_interrupt_lock_context *lock_context
96);
97
98void rtems_termios_device_lock_release_default(
99  rtems_termios_device_context *ctx,
100  rtems_interrupt_lock_context *lock_context
101);
102
103/**
104 * @brief Initializes a device context.
105 *
106 * @param[in] context The Termios device context.
107 * @param[in] name The name for the interrupt lock.  This name must be a
108 *   string persistent throughout the life time of this lock.  The name is only
109 *   used if profiling is enabled.
110 */
111RTEMS_INLINE_ROUTINE void rtems_termios_device_context_initialize(
112  rtems_termios_device_context *context,
113  const char                   *name
114)
115{
116  rtems_interrupt_lock_initialize( &context->lock.interrupt, name );
117  context->lock_acquire = rtems_termios_device_lock_acquire_default;
118  context->lock_release = rtems_termios_device_lock_release_default;
119}
120
121/**
122 * @brief Initializer for static initialization of Termios device contexts.
123 *
124 * @param name The name for the interrupt lock.  It must be a string.  The name
125 *   is only used if profiling is enabled.
126 */
127#define RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( name ) \
128  { \
129    { RTEMS_INTERRUPT_LOCK_INITIALIZER( name ) }, \
130    rtems_termios_device_lock_acquire_default, \
131    rtems_termios_device_lock_release_default \
132  }
133
134/**
135 * @brief Termios device handler.
136 *
137 * @see rtems_termios_device_install().
138 */
139typedef struct {
140  /**
141   * @brief First open of this device.
142   *
143   * @param[in] tty The Termios control.  This parameter may be passed to
144   *   interrupt service routines since it must be provided for the
145   *   rtems_termios_enqueue_raw_characters() and
146   *   rtems_termios_dequeue_characters() functions.
147   * @param[in] context The Termios device context.
148   * @param[in] term The current Termios attributes.
149   * @param[in] args The open/close arguments.  This is parameter provided to
150   *   support legacy drivers.  It must not be used by new drivers.
151   *
152   * @retval true Successful operation.
153   * @retval false Cannot open device.
154   *
155   * @see rtems_termios_get_device_context() and rtems_termios_set_best_baud().
156   */
157  bool (*first_open)(
158    struct rtems_termios_tty      *tty,
159    rtems_termios_device_context  *context,
160    struct termios                *term,
161    rtems_libio_open_close_args_t *args
162  );
163
164  /**
165   * @brief Last close of this device.
166   *
167   * @param[in] tty The Termios control.
168   * @param[in] context The Termios device context.
169   * @param[in] args The open/close arguments.  This is parameter provided to
170   *   support legacy drivers.  It must not be used by new drivers.
171   */
172  void (*last_close)(
173    struct rtems_termios_tty      *tty,
174    rtems_termios_device_context  *context,
175    rtems_libio_open_close_args_t *args
176  );
177
178  /**
179   * @brief Polled read.
180   *
181   * In case mode is TERMIOS_IRQ_DRIVEN, TERMIOS_IRQ_SERVER_DRIVEN or
182   * TERMIOS_TASK_DRIVEN, then data is received via
183   * rtems_termios_enqueue_raw_characters().
184   *
185   * @param[in] context The Termios device context.
186   *
187   * @retval char The received data encoded as unsigned char.
188   * @retval -1 No data currently available.
189   */
190  int (*poll_read)(rtems_termios_device_context *context);
191
192  /**
193   * @brief Polled write in case mode is TERMIOS_POLLED or write support
194   * otherwise.
195   *
196   * @param[in] context The Termios device context.
197   * @param[in] buf The output buffer.
198   * @param[in] len The output buffer length in characters.
199   */
200  void (*write)(
201    rtems_termios_device_context *context,
202    const char *buf,
203    size_t len
204  );
205
206  /**
207   * @brief Set attributes after a Termios settings change.
208   *
209   * @param[in] context The Termios device context.
210   * @param[in] term The new Termios attributes.
211   *
212   * @retval true Successful operation.
213   * @retval false Invalid attributes.
214   */
215  bool (*set_attributes)(
216    rtems_termios_device_context *context,
217    const struct termios         *term
218  );
219
220  /**
221   * @brief IO control handler.
222   *
223   * Invoked in case the Termios layer cannot deal with the IO request.
224   *
225   * @param[in] context The Termios device context.
226   * @param[in] request The IO control request.
227   * @param[in] buffer The IO control buffer.
228   */
229  int (*ioctl)(
230    rtems_termios_device_context *context,
231    ioctl_command_t               request,
232    void                         *buffer
233  );
234
235  /**
236   * @brief Termios device mode.
237   */
238  rtems_termios_device_mode mode;
239} rtems_termios_device_handler;
240
241/**
242 * @brief Termios device flow control handler.
243 *
244 * @see rtems_termios_device_install().
245 */
246typedef struct {
247  /**
248   * @brief Indicate to stop remote transmitter.
249   *
250   * @param[in] context The Termios device context.
251   */
252  void (*stop_remote_tx)(rtems_termios_device_context *context);
253
254  /**
255   * @brief Indicate to start remote transmitter.
256   *
257   * @param[in] context The Termios device context.
258   */
259  void (*start_remote_tx)(rtems_termios_device_context *context);
260} rtems_termios_device_flow;
261
262/**
263 * @brief Termios device node for installed devices.
264 *
265 * @see rtems_termios_device_install().
266 */
267typedef struct rtems_termios_device_node {
268  rtems_chain_node                    node;
269  rtems_device_major_number           major;
270  rtems_device_minor_number           minor;
271  const rtems_termios_device_handler *handler;
272  const rtems_termios_device_flow    *flow;
273  rtems_termios_device_context       *context;
274  struct rtems_termios_tty           *tty;
275} rtems_termios_device_node;
276
277/*
278 * Variables associated with each termios instance.
279 * One structure for each hardware I/O device.
280 */
281typedef struct rtems_termios_tty {
282  /*
283   * Linked-list of active TERMIOS devices
284   */
285  struct rtems_termios_tty  *forw;
286  struct rtems_termios_tty  *back;
287
288  /*
289   * How many times has this device been opened
290   */
291  int    refcount;
292
293  /*
294   * This device
295   */
296  rtems_device_major_number  major;
297  rtems_device_minor_number  minor;
298
299  /*
300   * Mutual-exclusion semaphores
301   */
302  rtems_id  isem;
303  rtems_id  osem;
304
305  /*
306   * The canonical (cooked) character buffer
307   */
308  char    *cbuf;
309  int    ccount;
310  int    cindex;
311
312  /*
313   * Keep track of cursor (printhead) position
314   */
315  int    column;
316  int    read_start_column;
317
318  /*
319   * The ioctl settings
320   */
321  struct termios  termios;
322  rtems_interval  vtimeTicks;
323
324  /*
325   * Raw input character buffer
326   */
327  struct rtems_termios_rawbuf rawInBuf;
328  uint32_t                    rawInBufSemaphoreOptions;
329  rtems_interval              rawInBufSemaphoreTimeout;
330  rtems_interval              rawInBufSemaphoreFirstTimeout;
331  unsigned int                rawInBufDropped;  /* Statistics */
332
333  /*
334   * Raw output character buffer
335   */
336  struct rtems_termios_rawbuf rawOutBuf;
337  int  t_dqlen; /* count of characters dequeued from device */
338  enum {rob_idle, rob_busy, rob_wait }  rawOutBufState;
339
340  /*
341   * Callbacks to device-specific routines
342   */
343  rtems_termios_callbacks  device;
344
345  /**
346   * @brief Context for legacy devices using the callbacks.
347   */
348  rtems_termios_device_context legacy_device_context;
349
350  /**
351   * @brief The device handler.
352   */
353  rtems_termios_device_handler handler;
354
355  /**
356   * @brief The device flow control handler.
357   */
358  rtems_termios_device_flow flow;
359
360  volatile unsigned int    flow_ctrl;
361  unsigned int             lowwater,highwater;
362
363  /*
364   * I/O task IDs (for task-driven drivers)
365   */
366  rtems_id                rxTaskId;
367  rtems_id                txTaskId;
368
369  /*
370   * line discipline related stuff
371   */
372  int t_line;   /* id of line discipline                       */
373  void *t_sc;   /* hook for discipline-specific data structure */
374
375  /*
376   * Wakeup callback variables
377   */
378  struct ttywakeup tty_snd;
379  struct ttywakeup tty_rcv;
380  bool             tty_rcvwakeup;
381
382  /**
383   * @brief Corresponding device node.
384   */
385  rtems_termios_device_node *device_node;
386
387  /**
388   * @brief Context for device driver.
389   */
390  rtems_termios_device_context *device_context;
391} rtems_termios_tty;
392
393/**
394 * @brief Installs a Termios device.
395 *
396 * The installed Termios device may be removed via unlink().
397 *
398 * @param[in] device_file The device file path.
399 * @param[in] handler The device handler.  It must be persistent throughout the
400 *   installed time of the device.
401 * @param[in] flow The device flow control handler.  The device flow control
402 *   handler are optional and may be @c NULL.  If present must be persistent
403 *   throughout the installed time of the device.
404 * @param[in] context The device context.  It must be persistent throughout the
405 *   installed time of the device.
406 *
407 * @retval RTEMS_SUCCESSFUL Successful operation.
408 * @retval RTEMS_NO_MEMORY Not enough memory to create a device node.
409 * @retval RTEMS_UNSATISFIED Creation of the device file failed.
410 * @retval RTEMS_INCORRECT_STATE Termios is not initialized.
411 *
412 * @see rtems_termios_get_device_context().
413 */
414rtems_status_code rtems_termios_device_install(
415  const char                         *device_file,
416  const rtems_termios_device_handler *handler,
417  const rtems_termios_device_flow    *flow,
418  rtems_termios_device_context       *context
419);
420
421/**
422 * @brief Returns the device context of an installed Termios device.
423 *
424 * @param[in] tty The Termios control.
425 */
426RTEMS_INLINE_ROUTINE void *rtems_termios_get_device_context(
427  const rtems_termios_tty *tty
428)
429{
430  return tty->device_context;
431}
432
433/**
434 * @brief Acquires the device lock.
435 *
436 * @param[in] context The device context.
437 * @param[in] lock_context The local interrupt lock context for an acquire and
438 *   release pair.
439 */
440RTEMS_INLINE_ROUTINE void rtems_termios_device_lock_acquire(
441  rtems_termios_device_context *context,
442  rtems_interrupt_lock_context *lock_context
443)
444{
445  ( *context->lock_acquire )( context, lock_context );
446}
447
448/**
449 * @brief Releases the device lock.
450 *
451 * @param[in] context The device context.
452 * @param[in] lock_context The local interrupt lock context for an acquire and
453 *   release pair.
454 */
455RTEMS_INLINE_ROUTINE void rtems_termios_device_lock_release(
456  rtems_termios_device_context *context,
457  rtems_interrupt_lock_context *lock_context
458)
459{
460  ( *context->lock_release )( context, lock_context );
461}
462
463/**
464 * @brief Sets the best baud value in the Termios control.
465 *
466 * The valid Termios baud values are between 0 and 460800.  The Termios baud
467 * value is chosen which minimizes the difference to the value specified.
468 *
469 * @param[in] term The Termios attributes.
470 * @param[in] baud The current baud setting of the device.
471 */
472void rtems_termios_set_best_baud(
473  struct termios *term,
474  uint32_t        baud
475);
476
477struct rtems_termios_linesw {
478  int (*l_open) (struct rtems_termios_tty *tp);
479  int (*l_close)(struct rtems_termios_tty *tp);
480  int (*l_read )(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
481  int (*l_write)(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
482  int (*l_rint )(int c,struct rtems_termios_tty *tp);
483  int (*l_start)(struct rtems_termios_tty *tp);
484  int (*l_ioctl)(struct rtems_termios_tty *tp,rtems_libio_ioctl_args_t *args);
485  int (*l_modem)(struct rtems_termios_tty *tp,int flags);
486};
487
488/*
489 * FIXME: this should move to termios.h!
490 */
491void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty);
492
493/*
494 * FIXME: this should move to termios.h!
495 * put a string to output ring buffer
496 */
497void rtems_termios_puts (
498  const void               *buf,
499  size_t                    len,
500  struct rtems_termios_tty *tty
501);
502
503/*
504 * global hooks for line disciplines
505 */
506extern struct rtems_termios_linesw rtems_termios_linesw[];
507extern int   rtems_termios_nlinesw;
508
509#define TTYDISC   0    /* termios tty line discipline */
510#define TABLDISC  3    /* tablet discipline */
511#define SLIPDISC  4    /* serial IP discipline */
512#define PPPDISC   5    /* PPP discipline */
513#define MAXLDISC  8
514
515/* baudrate xxx integer type */
516typedef uint32_t rtems_termios_baud_t;
517
518/**
519 *  @brief RTEMS Termios Baud Table
520 */
521extern const rtems_assoc_t rtems_termios_baud_table [];
522
523/**
524 *  @brief Converts the Integral Baud value @a baud to the Termios Control Flag
525 *  Representation
526 *
527 *  @retval B0 Invalid baud value or a baud value of 0.
528 *  @retval other Baud constant according to @a baud.
529 */
530speed_t rtems_termios_number_to_baud(rtems_termios_baud_t baud);
531
532/**
533 *  @brief Convert Baud Part of Termios control flags to an integral Baud Value
534 *
535 *  There is no need to mask the @a c_cflag with @c CBAUD.
536 *
537 *  @retval 0 Invalid baud value or a baud value of @c B0.
538 *  @retval other Integral baud value.
539 */
540rtems_termios_baud_t rtems_termios_baud_to_number(speed_t c_cflag);
541
542/**
543 *  @brief Convert Bxxx Constant to Index
544 */
545int  rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud);
546
547/**
548 * @brief Sets the initial @a baud in the Termios context @a tty.
549 *
550 * @retval 0 Successful operation.
551 * @retval -1 Invalid baud value.
552 */
553int rtems_termios_set_initial_baud(
554  struct rtems_termios_tty *tty,
555  rtems_termios_baud_t baud
556);
557
558/**
559 * @brief Termios kqueue() filter filesystem node handler
560 *
561 * Real implementation is provided by libbsd.
562 */
563int rtems_termios_kqfilter(
564  rtems_libio_t *iop,
565  struct knote  *kn
566);
567
568/**
569 * @brief Termios poll() filesystem node handler.
570 *
571 * Real implementation is provided by libbsd.
572 */
573int rtems_termios_poll(
574  rtems_libio_t *iop,
575  int            events
576);
577
578#ifdef __cplusplus
579}
580#endif
581
582#endif  /* TERMIOSTYPES_H */
Note: See TracBrowser for help on using the repository browser.