Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 8

8250 Serial Driver

This chapter includes:

Creating a serial driver

The Character DDK currently includes the source code for the 8250 serial driver. You may not have to change much:


Note: On a modem disconnect, libio-char.a triggers an io_read for every client blocked on a read() call. The client's read() call returns with 0 (EOF). Make sure that your clients explicitly check for a return of EOF, instead of simply calling read() repeatedly if the number of bytes is less than expected.

Registers

You'll find the register addresses defined in ddk_working_dir/ddk-char/src/hardware/devc/public/hw/8250.h.

The <8250.h> file defines:

See the documentation for your hardware for information about its registers and bit definitions.

Source code

The source code for the 8250 serial driver is in ddk_working_dir/ddk-char/src/hardware/devc/ser8250. This directory includes:

externs.c
Defines the global data.
externs.h
Includes the required headers and declares the global data.
init.c
Initialization code.
intr.c
Interrupt handler routines.
main.c
The main part of the driver.
options.c
Parses the driver's command-line arguments.
proto.h
Prototypes for the driver's interface routines.
query_defdev.c
Queries the default devices. Note that there's a special version of this routine for x86 desktop systems in x86/query_defdev.c. For other platforms, there aren't any default devices.
tedit.c
The tiny edit-mode routine.
tto.c
A routine to transmit a byte, called by io-char. It also provides support to control and read hardware control lines status, and provides support for the stty utility. io-char down call that uses the stty command to send output such as line ctrl and line status to the hardware.

There are also platform-specific directories, each of which includes:

<sys_ttyinit.c>
Initialize the tty structure that the driver passes to io-char.

Note: Change as little of the given source code as possible, because it's easy to mess things up.

The most important parts of the code are those associated with output and interrupts.

Interrupts

Different chips use interrupts in different ways. Typically, interrupts occurs when:

Functions

The ser8250 driver includes the following functions, defined in proto.h:

The driver's main() routine (defined in main.c) calls:

create_device()

This function is defined in init.c. The prototype is:

void create_device( TTYINIT *dip,
                    unsigned unit )

This function gets a device entry and its input/output buffers and creates a new device based on options passed in.

options()

This function is defined in options.c. The prototype is:

unsigned options( int argc,
                  char *argv[] )

This function parses the driver's command-line arguments. For information about the arguments, see devc-ser8250 in the Utilities Reference.

Depending on the options specified, this function may call:

The options() function returns the number of ports.

query_default_device()

This function is defined in query_defdev.c. The prototype is:

void *query_default_device( TTYINIT *dip,
                            void *link )

This function returns a placeholder that's used for overwrites in the platform directory.

ser_intr()

This function is defined in intr.c. The prototype is:

const struct sigevent *ser_intr( void *area,
                                 int id )

The ser_attach_intr() function, which is called by create_device(), calls InterruptAttach() (see the QNX Library Reference) to attach ser_intr() to the first handler.

The ser_intr() function calls:

ser_stty()

This function is defined in tto.c. The prototype is:

void ser_stty( DEV_8250 *dev )

This function configures hardware registers and settings such as baud rate, parity, etc.

sys_ttyinit()

This function is defined in <sys_ttyinit.c> in the platform-specific directories under ddk_working_dir/ddk-char/src/hardware/devc/ser8250.

The prototype is:

void sys_ttyinit( TTYINIT *dip )

This function initializes the TTYINIT clock and divisor default as appropriate for the platform.

tto()

This function is defined in tto.c. The prototype is:

int tto( TTYDEV *ttydev,
         int action,
         int arg1 )

This function takes data from io-char's output buffer and gives it to the hardware. It also deals with stty commands, by calling ser_stty() and provides line ctrl and line status information.

The arguments are:

ttydev
A pointer to the driver's TTYDEV structure.
action
One of:
arg1
A data value which has different meanings for different actions. It's used to pass flags that modify the action.

Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 488

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/ddk_en/character/ser8250.html on line 488