Sample Serial Port Driver

The serial port driver handles any I/O devices that behave like serial ports, including those based on 16450 and 16550 universal asynchronous receiver-transmitter (UART) chips and those that use direct memory access (DMA). Many Windows CE–based platforms have devices of this type, including ordinary nine-pin serial ports, infrared I/O ports, and PC Card serial devices, such as modems. If multiple types of serial port exist on a platform, you can either create several different serial drivers, one per serial port type, or create several different PDD layers and link them to a single MDD, thus creating one multipurpose serial driver. Either approach is equally acceptable. Creating separate drivers can simplify debugging and maintenance since each driver supports only one type of port. Creating a multipurpose driver, such as the sample serial port driver for the Windows CE reference platform, is more complex but gives a small memory savings.

The sample serial port MDD driver code appears under Public\Common\Oak\Drivers\Serial. The PDD code for various platforms is in Platform\CEPC\Drivers\Ser_Pdd and Platform\Odo\Drivers\Serial. There are sample serial port PDDs that support standard 16550, PC Card–based, and infrared serial ports. The sample MDD also supports linking multiple PDD layers, as described previously, by using a function pointer array that defines the types of supported serial port. If you add serial devices with unusual properties or functionality, you can add new serial port PDDs. In addition, Microsoft provides a library of functions appropriate for supporting serial ports that use 16550-compatible UARTs under Public\Common\Oak\Drivers\Ser16550. The COM_Open function in the serial port MDD does not support the fErrorChar, fNull, and fAbortOnChar members of the serial device control block (DCB) structure. You are expected to add support for this functionality in your PDD layer, if appropriate for your serial port hardware.

Because the functionality of serial ports maps easily to the functionality provided by standard stream interface functions, the serial port driver uses the stream interface functions as its DDI. Like other drivers that expose stream interface functions, it is loaded by the Device Manager.

Serial port devices make extensive use of I/O control codes to set and query various attributes of a serial port. For example, there are I/O control codes for setting and clearing the Data Terminal Ready (DTR) line, for purging any undelivered data, and for getting the status of a modem device. Therefore, you should support as many IOCTL_SERIAL I/O control codes as possible in your implementation of COM_IOControl.

The following table shows the DDI functions for the serial port driver.

COM_Close COM_PowerDown
COM_Deinit COM_PowerUp
COM_INIT COM_Read
COM_IOControl COM_Write
COM_Open  

The following table shows the DDSI functions for the sample serial port driver.

GetSerialObject HWGetIntrType HWPutBytes
HWClearBreak HWGetModemStatus HWReset
HWClearDTR HWGetRxBufferSize HWSetBreak
HWClearRTS HWGetRxStart HWSetCommTimeouts
HWClose HWGetStatus HWSetDCB
HWDeinit HWInit HWSetDTR
HWDisableIR HWOpen HWSetRTS
HWEnableIR HWPowerOff HWTxIntrHandler
HWGetBytes HWPowerOn HWXmitComChar
HWGetCommProperties HWPurgeComm  

These function names are listed as they are defined in the sample serial port code. You can change this set of functions or the function names by modifying the serial object table, which is a table of HWOBJ type objects, in the serial port PDD.