@c @c COPYRIGHT (c) 1988-1998. @c On-Line Applications Research Corporation (OAR). @c All rights reserved. @c @c $Id$ @c @chapter Console Driver @section Introduction This chapter describes how to do a console driver using RTEMS Termios support. The serial driver is called as soon as printf/scanf or read/write kind of input/output are needed. There are two main functioning modes: @itemize @bullet @item console: formatted input/output, with special characters (end of line, tabulations, etc...) recognition and processing, @item raw: permits raw data processing. @end itemize We may think that one need two serial drivers to deal with those two types of data, but Termios permits having only one driver. @section Termios Termios is a standard for terminal management, included in several Unix versions. Termios is good because: @itemize @bullet @item from the user's side: primitives to access the terminal and change configuration settings are the same under Unix and Rtems. @item from the BSP developer's side: it frees you from dealing with buffer states and mutual exclusions on them. @end itemize Termios support includes: @itemize @bullet @item raw and console handling, @item blocking or non-blocking characters receive, with or without Timeout. @end itemize For more information on Termios, type man termios in your Unix box or go to http://www.freebsd.org/cgi/man.cgi. @section Driver Functioning Modes There are generally two main functioning modes for an UART (Universal Asynchronous Receiver-Transmitter, i.e. the serial chip): @itemize @bullet @item polling mode: the processor blocks on sending/receiving characters. This mode is not powerful, but is necessary when one wants to print an error message when the board hung. This is also the most simple mode to program, @item interrupt mode: the processor doesn't block on sending/receiving characters. Two buffers (one for the in-going characters, the others for the characters to be sent) are used. An interrupt is raised as soon as a character is in the UART. Then the int errupt subroutine insert the character at the input buffer queue. When a character is asked for input, this at the head of the buffer is returned. When characters have to be sent, one have to put the first characters (the number depends on the UART) in th e UART. Then an interrupt is raised when all the characters have been emitted. The interrupt subroutine has to send the characters remaining in the output buffer the same way. @end itemize @section Serial Driver Functioning Overview Figure 5 is an attempt of showing how a Termios driven serial driver works : @itemize @bullet @item the application programmer uses standard C library call (printf, scanf, read, write, etc.), @item C library (in fact that's Cygnus Newlib) calls RTEMS procedure: glue is made in newlib*.c files which can be found under $RTEMS_ROOT/c/src/lib/libc directory, @item Glue code calls your serial driver entry routines. @end itemize @subsection Termios and Polled I/O You have to point Termios out which functions are used for simple character input/output: Function Description @example int pollWrite (int minor, const char *buf, int len) for (i=0; i