RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
29extern "C" {
30#endif
31
40/*
41 * Wakeup callback data structure
42 */
43struct 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
59typedef enum {
60 TERMIOS_POLLED,
61 TERMIOS_IRQ_DRIVEN,
62 TERMIOS_TASK_DRIVEN,
63 TERMIOS_IRQ_SERVER_DRIVEN
64} rtems_termios_device_mode;
65
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
95void rtems_termios_device_lock_acquire_default(
98);
99
100void 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
141typedef 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
248typedef 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 */
283typedef 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 * Information for the tx task how many characters have been dequeued.
372 */
373 int txTaskCharsDequeued;
374
375 /*
376 * line discipline related stuff
377 */
378 int t_line; /* id of line discipline */
379 void *t_sc; /* hook for discipline-specific data structure */
380
381 /*
382 * Wakeup callback variables
383 */
384 struct ttywakeup tty_snd;
385 struct ttywakeup tty_rcv;
386 bool tty_rcvwakeup;
387
392
398
421 const char *device_file,
422 const rtems_termios_device_handler *handler,
423 const rtems_termios_device_flow *flow,
425);
426
433 const rtems_termios_tty *tty
434)
435{
436 return tty->device_context;
437}
438
448 rtems_interrupt_lock_context *lock_context
449)
450{
451 ( *context->lock_acquire )( context, lock_context );
452}
453
463 rtems_interrupt_lock_context *lock_context
464)
465{
466 ( *context->lock_release )( context, lock_context );
467}
468
479 struct termios *term,
480 uint32_t baud
481);
482
484 int (*l_open) (struct rtems_termios_tty *tp);
485 int (*l_close)(struct rtems_termios_tty *tp);
486 int (*l_read )(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
487 int (*l_write)(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
488 int (*l_rint )(int c,struct rtems_termios_tty *tp);
489 int (*l_start)(struct rtems_termios_tty *tp,int len);
490 int (*l_ioctl)(struct rtems_termios_tty *tp,rtems_libio_ioctl_args_t *args);
491 int (*l_modem)(struct rtems_termios_tty *tp,int flags);
492};
493
494/*
495 * FIXME: this should move to termios.h!
496 */
497void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty);
498
499/*
500 * FIXME: this should move to termios.h!
501 * put a string to output ring buffer
502 */
503void rtems_termios_puts (
504 const void *buf,
505 size_t len,
506 struct rtems_termios_tty *tty
507);
508
509/*
510 * global hooks for line disciplines
511 */
513extern int rtems_termios_nlinesw;
514
515#define TTYDISC 0 /* termios tty line discipline */
516#define TABLDISC 3 /* tablet discipline */
517#define SLIPDISC 4 /* serial IP discipline */
518#define PPPDISC 5 /* PPP discipline */
519#define MAXLDISC 8
520
521/* baudrate xxx integer type */
522typedef uint32_t rtems_termios_baud_t;
523
528
536speed_t rtems_termios_number_to_baud(rtems_termios_baud_t baud);
537
544rtems_termios_baud_t rtems_termios_baud_to_number(speed_t baud);
545
549int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud);
550
558 struct rtems_termios_tty *tty,
559 rtems_termios_baud_t baud
560);
561
568 rtems_libio_t *iop,
569 struct knote *kn
570);
571
578 rtems_libio_t *iop,
579 void **addr,
580 size_t len,
581 int prot,
582 off_t off
583);
584
591 rtems_libio_t *iop,
592 int events
593);
594
595#define RTEMS_IO_SNDWAKEUP _IOW('t', 11, struct ttywakeup ) /* send tty wakeup */
596#define RTEMS_IO_RCVWAKEUP _IOW('t', 12, struct ttywakeup ) /* recv tty wakeup */
597
598#define OLCUC 0x00000100 /* map lower case to upper case on output */
599#define IUCLC 0x00004000 /* map upper case to lower case on input */
600
601#define RTEMS_TERMIOS_NUMBER_BAUD_RATES 25
602
603extern rtems_mutex rtems_termios_ttyMutex;
604
605#ifdef __cplusplus
606}
607#endif
608
609#endif /* TERMIOSTYPES_H */
RTEMS Associativity Routines.
Chain API.
#define rtems_interrupt_lock_initialize(_lock, _name)
Initializes an interrupt lock.
Definition: intr.h:265
rtems_status_code
Classic API Status.
Definition: status.h:43
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
ssize_t write(int fd, const void *buffer, size_t count)
Definition: write.c:30
Basic IO API.
Definition: chain.h:68
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
ISR lock control.
Definition: isrlock.h:56
Definition: rtemscompat1.h:15
Definition: mutex.h:4
Definition: assoc.h:31
Definition: thread.h:221
Parameter block for ioctl.
Definition: libio.h:1355
Parameter block for open/close.
Definition: libio.h:1346
Paramameter block for read/write.
Definition: libio.h:1334
An open file data structure.
Definition: libio.h:1320
Definition: libio.h:1879
Termios device context.
Definition: termiostypes.h:75
Termios device flow control handler.
Definition: termiostypes.h:248
Termios device handler.
Definition: termiostypes.h:141
rtems_termios_device_mode mode
Termios device mode.
Definition: termiostypes.h:240
Termios device node for installed devices.
Definition: termiostypes.h:269
Definition: termiostypes.h:483
Definition: termiostypes.h:51
Definition: termiostypes.h:283
rtems_termios_device_handler handler
The device handler.
Definition: termiostypes.h:355
rtems_termios_device_context legacy_device_context
Context for legacy devices using the callbacks.
Definition: termiostypes.h:350
rtems_termios_device_node * device_node
Corresponding device node.
Definition: termiostypes.h:391
rtems_termios_device_context * device_context
Context for device driver.
Definition: termiostypes.h:396
rtems_termios_device_flow flow
The device flow control handler.
Definition: termiostypes.h:360
Definition: termiostypes.h:43
unsigned context
Definition: tlb.h:1
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:461
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:446
struct rtems_termios_device_context rtems_termios_device_context
Termios device context.
int rtems_termios_poll(rtems_libio_t *iop, int events)
Termios poll() filesystem node handler.
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
const rtems_assoc_t rtems_termios_baud_table[]
RTEMS Termios Baud Table.
Definition: termios_baudtable.c:23
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
int rtems_termios_mmap(rtems_libio_t *iop, void **addr, size_t len, int prot, off_t off)
Termios mmap() filter filesystem node handler.
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:432
int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud)
Convert Bxxx Constant to Index.
Definition: termios_baud2index.c:24
struct rtems_termios_device_node rtems_termios_device_node
Termios device node for installed devices.
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
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
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
int rtems_termios_kqfilter(rtems_libio_t *iop, struct knote *kn)
Termios kqueue() filter filesystem node handler.
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