RTEMS  5.0.0
termiostypes.h
Go to the documentation of this file.
1 
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 <rtems/thread.h>
24 #include <sys/ioccom.h>
25 #include <stdint.h>
26 #include <termios.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
40 /*
41  * Wakeup callback data structure
42  */
43 struct ttywakeup {
44  void (*sw_pfn)(struct termios *tty, void *arg);
45  void *sw_arg;
46 };
47 
48 /*
49  * Variables associated with the character buffer
50  */
52  char *theBuf;
53  volatile unsigned int Head;
54  volatile unsigned int Tail;
55  volatile unsigned int Size;
56  rtems_binary_semaphore Semaphore;
57 };
58 
59 typedef enum {
60  TERMIOS_POLLED,
61  TERMIOS_IRQ_DRIVEN,
62  TERMIOS_TASK_DRIVEN,
63  TERMIOS_IRQ_SERVER_DRIVEN
64 } rtems_termios_device_mode;
65 
66 struct rtems_termios_tty;
67 
76  union {
77  /* Used for TERMIOS_POLLED and TERMIOS_IRQ_DRIVEN */
78  rtems_interrupt_lock interrupt;
79 
80  /* Used for TERMIOS_IRQ_SERVER_DRIVEN or TERMIOS_TASK_DRIVEN */
81  rtems_mutex mutex;
82  } lock;
83 
84  void ( *lock_acquire )(
87  );
88 
89  void ( *lock_release )(
92  );
94 
95 void rtems_termios_device_lock_acquire_default(
97  rtems_interrupt_lock_context *lock_context
98 );
99 
100 void rtems_termios_device_lock_release_default(
102  rtems_interrupt_lock_context *lock_context
103 );
104 
115  const char *name
116 )
117 {
118  rtems_interrupt_lock_initialize( &context->lock.interrupt, name );
119  context->lock_acquire = rtems_termios_device_lock_acquire_default;
120  context->lock_release = rtems_termios_device_lock_release_default;
121 }
122 
129 #define RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( name ) \
130  { \
131  { RTEMS_INTERRUPT_LOCK_INITIALIZER( name ) }, \
132  rtems_termios_device_lock_acquire_default, \
133  rtems_termios_device_lock_release_default \
134  }
135 
141 typedef struct {
159  bool (*first_open)(
160  struct rtems_termios_tty *tty,
162  struct termios *term,
164  );
165 
174  void (*last_close)(
175  struct rtems_termios_tty *tty,
178  );
179 
193 
202  void (*write)(
204  const char *buf,
205  size_t len
206  );
207 
217  bool (*set_attributes)(
219  const struct termios *term
220  );
221 
231  int (*ioctl)(
233  ioctl_command_t request,
234  void *buffer
235  );
236 
240  rtems_termios_device_mode mode;
242 
248 typedef struct {
254  void (*stop_remote_tx)(rtems_termios_device_context *context);
255 
261  void (*start_remote_tx)(rtems_termios_device_context *context);
263 
270  rtems_chain_node node;
271  rtems_device_major_number major;
272  rtems_device_minor_number minor;
273  const rtems_termios_device_handler *handler;
274  const rtems_termios_device_flow *flow;
276  struct rtems_termios_tty *tty;
278 
279 /*
280  * Variables associated with each termios instance.
281  * One structure for each hardware I/O device.
282  */
283 typedef struct rtems_termios_tty {
284  /*
285  * Linked-list of active TERMIOS devices
286  */
287  struct rtems_termios_tty *forw;
288  struct rtems_termios_tty *back;
289 
290  /*
291  * How many times has this device been opened
292  */
293  int refcount;
294 
295  /*
296  * This device
297  */
298  rtems_device_major_number major;
299  rtems_device_minor_number minor;
300 
301  /*
302  * Mutual-exclusion semaphores
303  */
304  rtems_mutex isem;
305  rtems_mutex osem;
306 
307  /*
308  * The canonical (cooked) character buffer
309  */
310  char *cbuf;
311  int ccount;
312  int cindex;
313 
314  /*
315  * Keep track of cursor (printhead) position
316  */
317  int column;
318  int read_start_column;
319 
320  /*
321  * The ioctl settings
322  */
323  struct termios termios;
324  rtems_interval vtimeTicks;
325 
326  /*
327  * Raw input character buffer
328  */
329  struct rtems_termios_rawbuf rawInBuf;
330  bool rawInBufSemaphoreWait;
331  rtems_interval rawInBufSemaphoreTimeout;
332  rtems_interval rawInBufSemaphoreFirstTimeout;
333  unsigned int rawInBufDropped; /* Statistics */
334 
335  /*
336  * Raw output character buffer
337  */
338  struct rtems_termios_rawbuf rawOutBuf;
339  int t_dqlen; /* count of characters dequeued from device */
340  enum {rob_idle, rob_busy, rob_wait } rawOutBufState;
341 
342  /*
343  * Callbacks to device-specific routines
344  */
346 
351 
356 
361 
362  volatile unsigned int flow_ctrl;
363  unsigned int lowwater,highwater;
364 
365  /*
366  * I/O task IDs (for task-driven drivers)
367  */
368  rtems_id rxTaskId;
369  rtems_id txTaskId;
370 
371  /*
372  * line discipline related stuff
373  */
374  int t_line; /* id of line discipline */
375  void *t_sc; /* hook for discipline-specific data structure */
376 
377  /*
378  * Wakeup callback variables
379  */
380  struct ttywakeup tty_snd;
381  struct ttywakeup tty_rcv;
382  bool tty_rcvwakeup;
383 
388 
394 
417  const char *device_file,
418  const rtems_termios_device_handler *handler,
419  const rtems_termios_device_flow *flow,
421 );
422 
429  const rtems_termios_tty *tty
430 )
431 {
432  return tty->device_context;
433 }
434 
444  rtems_interrupt_lock_context *lock_context
445 )
446 {
447  ( *context->lock_acquire )( context, lock_context );
448 }
449 
459  rtems_interrupt_lock_context *lock_context
460 )
461 {
462  ( *context->lock_release )( context, lock_context );
463 }
464 
475  struct termios *term,
476  uint32_t baud
477 );
478 
480  int (*l_open) (struct rtems_termios_tty *tp);
481  int (*l_close)(struct rtems_termios_tty *tp);
482  int (*l_read )(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
483  int (*l_write)(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
484  int (*l_rint )(int c,struct rtems_termios_tty *tp);
485  int (*l_start)(struct rtems_termios_tty *tp);
486  int (*l_ioctl)(struct rtems_termios_tty *tp,rtems_libio_ioctl_args_t *args);
487  int (*l_modem)(struct rtems_termios_tty *tp,int flags);
488 };
489 
490 /*
491  * FIXME: this should move to termios.h!
492  */
493 void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty);
494 
495 /*
496  * FIXME: this should move to termios.h!
497  * put a string to output ring buffer
498  */
499 void rtems_termios_puts (
500  const void *buf,
501  size_t len,
502  struct rtems_termios_tty *tty
503 );
504 
505 /*
506  * global hooks for line disciplines
507  */
508 extern struct rtems_termios_linesw rtems_termios_linesw[];
509 extern int rtems_termios_nlinesw;
510 
511 #define TTYDISC 0 /* termios tty line discipline */
512 #define TABLDISC 3 /* tablet discipline */
513 #define SLIPDISC 4 /* serial IP discipline */
514 #define PPPDISC 5 /* PPP discipline */
515 #define MAXLDISC 8
516 
517 /* baudrate xxx integer type */
518 typedef uint32_t rtems_termios_baud_t;
519 
524 
532 speed_t rtems_termios_number_to_baud(rtems_termios_baud_t baud);
533 
540 rtems_termios_baud_t rtems_termios_baud_to_number(speed_t baud);
541 
545 int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud);
546 
554  struct rtems_termios_tty *tty,
555  rtems_termios_baud_t baud
556 );
557 
564  rtems_libio_t *iop,
565  struct knote *kn
566 );
567 
574  rtems_libio_t *iop,
575  void **addr,
576  size_t len,
577  int prot,
578  off_t off
579 );
580 
587  rtems_libio_t *iop,
588  int events
589 );
590 
591 #define RTEMS_IO_SNDWAKEUP _IOW('t', 11, struct ttywakeup ) /* send tty wakeup */
592 #define RTEMS_IO_RCVWAKEUP _IOW('t', 12, struct ttywakeup ) /* recv tty wakeup */
593 
594 #define OLCUC 0x00000100 /* map lower case to upper case on output */
595 #define IUCLC 0x00004000 /* map upper case to lower case on input */
596 
597 #define RTEMS_TERMIOS_NUMBER_BAUD_RATES 25
598 
599 extern rtems_mutex rtems_termios_ttyMutex;
600 
601 #ifdef __cplusplus
602 }
603 #endif
604 
605 #endif /* TERMIOSTYPES_H */
RTEMS_INLINE_ROUTINE void rtems_termios_device_context_initialize(rtems_termios_device_context *context, const char *name)
Initializes a device context.
Definition: termiostypes.h:113
RTEMS Associativity Routines.
rtems_status_code rtems_termios_device_install(const char *device_file, const rtems_termios_device_handler *handler, const rtems_termios_device_flow *flow, rtems_termios_device_context *context)
Installs a Termios device.
Definition: termios.c:128
Parameter block for open/close.
Definition: libio.h:1346
rtems_termios_device_context * device_context
Context for device driver.
Definition: termiostypes.h:392
Definition: assoc.h:26
RTEMS_INLINE_ROUTINE void rtems_termios_device_lock_release(rtems_termios_device_context *context, rtems_interrupt_lock_context *lock_context)
Releases the device lock.
Definition: termiostypes.h:457
Definition: chain.h:65
rtems_termios_baud_t rtems_termios_baud_to_number(speed_t baud)
Converts the baud flags to an integral baud value.
Definition: termios_baud2num.c:23
Basic IO API.
int rtems_termios_kqfilter(rtems_libio_t *iop, struct knote *kn)
Termios kqueue() filter filesystem node handler.
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
Termios device context.
Definition: termiostypes.h:75
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Definition: thread.h:221
struct rtems_termios_device_node rtems_termios_device_node
Termios device node for installed devices.
int rtems_termios_set_initial_baud(struct rtems_termios_tty *tty, rtems_termios_baud_t baud)
Sets the initial baud in the Termios context tty.
Definition: termios_setinitialbaud.c:23
Termios device node for installed devices.
Definition: termiostypes.h:269
Parameter block for ioctl.
Definition: libio.h:1355
ssize_t write(int fd, const void *buffer, size_t count)
Definition: write.c:30
Paramameter block for read/write.
Definition: libio.h:1334
int rtems_termios_poll(rtems_libio_t *iop, int events)
Termios poll() filesystem node handler.
const rtems_assoc_t rtems_termios_baud_table[]
RTEMS Termios Baud Table.
Definition: termios_baudtable.c:23
Definition: termiostypes.h:479
speed_t rtems_termios_number_to_baud(rtems_termios_baud_t baud)
Converts the Integral Baud value baud to the Termios Control Flag Representation. ...
Definition: termios_num2baud.c:23
Definition: rtemscompat1.h:15
ISR lock control.
Definition: isrlock.h:56
Definition: libio.h:1883
rtems_termios_device_context legacy_device_context
Context for legacy devices using the callbacks.
Definition: termiostypes.h:350
rtems_status_code
Classic API Status.
Definition: status.h:43
Definition: termiostypes.h:283
rtems_termios_device_node * device_node
Corresponding device node.
Definition: termiostypes.h:387
#define rtems_interrupt_lock_initialize(_lock, _name)
Initializes an interrupt lock.
Definition: intr.h:265
RTEMS_INLINE_ROUTINE void rtems_termios_device_lock_acquire(rtems_termios_device_context *context, rtems_interrupt_lock_context *lock_context)
Acquires the device lock.
Definition: termiostypes.h:442
Definition: termiostypes.h:43
struct rtems_termios_device_context rtems_termios_device_context
Termios device context.
Chain API.
int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud)
Convert Bxxx Constant to Index.
Definition: termios_baud2index.c:24
RTEMS_INLINE_ROUTINE void * rtems_termios_get_device_context(const rtems_termios_tty *tty)
Returns the device context of an installed Termios device.
Definition: termiostypes.h:428
unsigned context
Definition: tlb.h:108
void rtems_termios_set_best_baud(struct termios *term, uint32_t baud)
Sets the best baud value in the Termios control.
Definition: termios_setbestbaud.c:21
An open file data structure.
Definition: libio.h:1320
int rtems_termios_mmap(rtems_libio_t *iop, void **addr, size_t len, int prot, off_t off)
Termios mmap() filter filesystem node handler.
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
Definition: termiostypes.h:51
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Termios device flow control handler.
Definition: termiostypes.h:248
rtems_termios_device_flow flow
The device flow control handler.
Definition: termiostypes.h:360
Definition: mutex.h:4
rtems_termios_device_mode mode
Termios device mode.
Definition: termiostypes.h:240
rtems_termios_device_handler handler
The device handler.
Definition: termiostypes.h:355
Termios device handler.
Definition: termiostypes.h:141