RTEMS CPU Kit with SuperCore  4.11.3
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 <stdint.h>
24 #include <termios.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
38 /*
39  * Wakeup callback data structure
40  */
41 struct 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  */
50  char *theBuf;
51  volatile unsigned int Head;
52  volatile unsigned int Tail;
53  volatile unsigned int Size;
54  rtems_id Semaphore;
55 };
56 
57 typedef enum {
58  TERMIOS_POLLED,
59  TERMIOS_IRQ_DRIVEN,
60  TERMIOS_TASK_DRIVEN
61 } rtems_termios_device_mode;
62 
63 struct rtems_termios_tty;
64 
73  rtems_interrupt_lock interrupt_lock;
75 
86  const char *name
87 )
88 {
89  rtems_interrupt_lock_initialize( &context->interrupt_lock, name );
90 }
91 
98 #define RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( name ) \
99  { RTEMS_INTERRUPT_LOCK_INITIALIZER( name ) }
100 
106 typedef struct {
124  bool (*first_open)(
125  struct rtems_termios_tty *tty,
127  struct termios *term,
129  );
130 
139  void (*last_close)(
140  struct rtems_termios_tty *tty,
143  );
144 
156  int (*poll_read)(rtems_termios_device_context *context);
157 
166  void (*write)(
168  const char *buf,
169  size_t len
170  );
171 
181  bool (*set_attributes)(
183  const struct termios *term
184  );
185 
189  rtems_termios_device_mode mode;
191 
197 typedef struct {
203  void (*stop_remote_tx)(rtems_termios_device_context *context);
204 
210  void (*start_remote_tx)(rtems_termios_device_context *context);
212 
219  rtems_chain_node node;
220  rtems_device_major_number major;
221  rtems_device_minor_number minor;
222  const rtems_termios_device_handler *handler;
223  const rtems_termios_device_flow *flow;
225  struct rtems_termios_tty *tty;
227 
228 /*
229  * Variables associated with each termios instance.
230  * One structure for each hardware I/O device.
231  */
232 typedef struct rtems_termios_tty {
233  /*
234  * Linked-list of active TERMIOS devices
235  */
236  struct rtems_termios_tty *forw;
237  struct rtems_termios_tty *back;
238 
239  /*
240  * How many times has this device been opened
241  */
242  int refcount;
243 
244  /*
245  * This device
246  */
247  rtems_device_major_number major;
248  rtems_device_minor_number minor;
249 
250  /*
251  * Mutual-exclusion semaphores
252  */
253  rtems_id isem;
254  rtems_id osem;
255 
256  /*
257  * The canonical (cooked) character buffer
258  */
259  char *cbuf;
260  int ccount;
261  int cindex;
262 
263  /*
264  * Keep track of cursor (printhead) position
265  */
266  int column;
267  int read_start_column;
268 
269  /*
270  * The ioctl settings
271  */
272  struct termios termios;
273  rtems_interval vtimeTicks;
274 
275  /*
276  * Raw input character buffer
277  */
278  struct rtems_termios_rawbuf rawInBuf;
279  uint32_t rawInBufSemaphoreOptions;
280  rtems_interval rawInBufSemaphoreTimeout;
281  rtems_interval rawInBufSemaphoreFirstTimeout;
282  unsigned int rawInBufDropped; /* Statistics */
283 
284  /*
285  * Raw output character buffer
286  */
287  struct rtems_termios_rawbuf rawOutBuf;
288  int t_dqlen; /* count of characters dequeued from device */
289  enum {rob_idle, rob_busy, rob_wait } rawOutBufState;
290 
291  /*
292  * Callbacks to device-specific routines
293  */
295 
300 
305 
310 
311  volatile unsigned int flow_ctrl;
312  unsigned int lowwater,highwater;
313 
314  /*
315  * I/O task IDs (for task-driven drivers)
316  */
317  rtems_id rxTaskId;
318  rtems_id txTaskId;
319 
320  /*
321  * line discipline related stuff
322  */
323  int t_line; /* id of line discipline */
324  void *t_sc; /* hook for discipline-specific data structure */
325 
326  /*
327  * Wakeup callback variables
328  */
329  struct ttywakeup tty_snd;
330  struct ttywakeup tty_rcv;
331  int tty_rcvwakeup;
332 
337 
343 
370  const char *device_file,
371  rtems_device_major_number major,
372  rtems_device_minor_number minor,
373  const rtems_termios_device_handler *handler,
374  const rtems_termios_device_flow *flow,
376 );
377 
395  const char *device_file,
396  rtems_device_major_number major,
397  rtems_device_minor_number minor
398 );
399 
406  rtems_device_major_number major,
407  rtems_device_minor_number minor,
408  void *arg
409 );
410 
419 
426  const rtems_termios_tty *tty
427 )
428 {
429  return tty->device_context;
430 }
431 
441  rtems_interrupt_lock_context *lock_context
442 )
443 {
444  rtems_interrupt_lock_acquire( &context->interrupt_lock, lock_context );
445 }
446 
456  rtems_interrupt_lock_context *lock_context
457 )
458 {
459  rtems_interrupt_lock_release( &context->interrupt_lock, lock_context );
460 }
461 
472  struct termios *term,
473  uint32_t baud
474 );
475 
477  int (*l_open) (struct rtems_termios_tty *tp);
478  int (*l_close)(struct rtems_termios_tty *tp);
479  int (*l_read )(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
480  int (*l_write)(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
481  int (*l_rint )(int c,struct rtems_termios_tty *tp);
482  int (*l_start)(struct rtems_termios_tty *tp);
483  int (*l_ioctl)(struct rtems_termios_tty *tp,rtems_libio_ioctl_args_t *args);
484  int (*l_modem)(struct rtems_termios_tty *tp,int flags);
485 };
486 
487 /*
488  * FIXME: this should move to termios.h!
489  */
490 void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty);
491 
492 /*
493  * FIXME: this should move to termios.h!
494  * put a string to output ring buffer
495  */
496 void rtems_termios_puts (
497  const void *buf,
498  size_t len,
499  struct rtems_termios_tty *tty
500 );
501 
502 /*
503  * global hooks for line disciplines
504  */
505 extern struct rtems_termios_linesw rtems_termios_linesw[];
506 extern int rtems_termios_nlinesw;
507 
508 #define TTYDISC 0 /* termios tty line discipline */
509 #define TABLDISC 3 /* tablet discipline */
510 #define SLIPDISC 4 /* serial IP discipline */
511 #define PPPDISC 5 /* PPP discipline */
512 #define MAXLDISC 8
513 
514 /* baudrate xxx integer type */
515 typedef uint32_t rtems_termios_baud_t;
516 
521 
529 tcflag_t rtems_termios_number_to_baud(rtems_termios_baud_t baud);
530 
539 rtems_termios_baud_t rtems_termios_baud_to_number(tcflag_t c_cflag);
540 
544 int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud);
545 
553  struct rtems_termios_tty *tty,
554  rtems_termios_baud_t baud
555 );
556 
557 #ifdef __cplusplus
558 }
559 #endif
560 
561 #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:84
RTEMS Associativity Routines.
Parameter block for open/close.
Definition: libio.h:1308
rtems_termios_device_context * device_context
Context for device driver.
Definition: termiostypes.h:341
Definition: assoc.h:25
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:454
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
Definition: termios.h:42
Basic IO API.
tcflag_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_status_code rtems_termios_device_install(const char *device_file, rtems_device_major_number major, rtems_device_minor_number minor, const rtems_termios_device_handler *handler, const rtems_termios_device_flow *flow, rtems_termios_device_context *context)
Installs a Termios device.
Definition: termios.c:134
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:80
Termios device context.
Definition: termiostypes.h:72
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
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:218
Parameter block for ioctl.
Definition: libio.h:1317
ssize_t write(int fd, const void *buffer, size_t count)
POSIX 1003.1b 6.4.2 - Write to a File.
Definition: write.c:30
Paramameter block for read/write.
Definition: libio.h:1296
const rtems_assoc_t rtems_termios_baud_table[]
RTEMS Termios Baud Table.
Definition: termios_baudtable.c:23
Definition: termiostypes.h:476
ISR lock control.
Definition: isrlock.h:56
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:119
rtems_status_code rtems_termios_device_remove(const char *device_file, rtems_device_major_number major, rtems_device_minor_number minor)
Removes a Termios device.
Definition: termios.c:190
POSIX Termios Implementation for RTEMS Console Device Driver.
Definition: libio.h:1819
rtems_termios_device_context legacy_device_context
Context for legacy devices using the callbacks.
Definition: termiostypes.h:299
rtems_status_code
Classic API Status.
Definition: status.h:46
Definition: termiostypes.h:232
rtems_termios_device_node * device_node
Corresponding device node.
Definition: termiostypes.h:336
#define rtems_interrupt_lock_initialize(_lock, _name)
Initializes an interrupt lock.
Definition: intr.h:268
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:439
rtems_status_code rtems_termios_device_open(rtems_device_major_number major, rtems_device_minor_number minor, void *arg)
Opens an installed Termios device.
Definition: termios.c:632
Definition: termiostypes.h:41
struct rtems_termios_device_context rtems_termios_device_context
Termios device context.
int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud)
Convert Bxxx Constant to Index.
Definition: termios_baud2index.c:24
#define rtems_interrupt_lock_release(_lock, _lock_context)
Releases an interrupt lock.
Definition: intr.h:312
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:425
Chain API.
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:22
rtems_status_code rtems_termios_device_close(void *arg)
Closes an installed Termios device.
Definition: termios.c:790
Definition: termiostypes.h:49
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Termios device flow control handler.
Definition: termiostypes.h:197
rtems_termios_device_flow flow
The device flow control handler.
Definition: termiostypes.h:309
#define rtems_interrupt_lock_acquire(_lock, _lock_context)
Acquires an interrupt lock.
Definition: intr.h:295
rtems_termios_device_mode mode
Termios device mode.
Definition: termiostypes.h:189
rtems_termios_device_handler handler
The device handler.
Definition: termiostypes.h:304
Termios device handler.
Definition: termiostypes.h:106
rtems_termios_baud_t rtems_termios_baud_to_number(tcflag_t c_cflag)
Convert Baud Part of Termios control flags to an integral Baud Value.
Definition: termios_baud2num.c:23