3.3 Se rial I/O Ex am ples
The COM8IO.C and COM8IO.H files are in tended to dem on strate the deep FIFO ca pa bil ity of the
EXAR 16C854 quad UARTs, the abili ty of soft ware to auto- configure for the I/O port and in ter rupt as -
sign ments and to dem on strate how shared in ter rupts should be han dled on a multi- port board such as
the COM8. These files do not com prise a com pre hen sive driver al though for a large number of us ers
util iz ing RS- 232, they proba bly could be used as- is. Cus tomer written pro grams could be linked di -
rectly to the COM8 I/O rou tines con tained in these files. Be cause of the deep 128 byte FIFO there is no
im ple men ta tion of any type of flow- control. There is also no sup port for al ter nate com mu n i ca tions
modes such as RS- 422 or RS-485. The main func tions in the COM8IO.C file will be briefly de scribed
and any spe cial fea tures or ca ve ats will be enu mer ated. This dis cus sion should be fol lowed with the
source code list ing in hand.
3.3.1 COM8IO.C
This file be gins with a number of data and struc ture defi ni tions. All of the COM port op er at ing pa -
rame ters, as well as buffer point ers, are stored in an ar ray of eight struc tures named comm_struct[].
Ref er to the struc ture defi ni tion in COM8IO.H for par ticu lars on this struc ture. If ad di tional fea -
tures such as RS- 422 or RS- 485 sup port were to be added, flags and pa rame ters, could be added to
comm_struct[].
To make the code more read able, rather than an ar ray of func tions for the pri mary ISRs ,since
there’s a fixed number (8) we just de clare 8 unique ISR func tions, all of which will then vec tor to com -
mon han dler code.
The first real func tion is com8_init() which has no re turn value and takes no ar gu ments. This would
be the first func tion that any pro gram de sir ing to use the other func tions MUST call. This func tion reads
the con figu ra tion reg is ters on the PCM- COM8 and fills in comm_struct[] with the I/O port and in ter -
rupt as sign ment val ues. It also de fines a de fault baud rate of 38400. There is no ac tual UART ini tiali za -
tion ef fected in this func tion.
An ap pli ca tion af ter call ing com8_init() would then need to fill in any of the other pa rame ters in
comm_struct[] that are de sired such as baud rate or trans mit or re ceive FIFO lev els.
The next func tion that an ap pli ca tion would need to call bef ore per form ing I/O on a COM port is
com_open(). This func tion takes as an ar gu ment the COM port number 0-7 and re turns 0 on suc cess or
sev eral non- zero val ues on fail ure. Once this func tion has been called, the port is ready for I/O. Note that
this func tion can ini tial ize and util ize the en tire 128 byte FI FO and will build an in ter rupt shar ing mask
to al low the IS Rs to de ter mine what other ports are shar ing this in ter rupt. This is one of the long est and
most com plex func tions in the ex am ple. Note that the ini tiali za tion is hard wired to an 8 bit word with 1
stop bit and no par ity.
Once an ap pli ca tion is fin ished us ing one of the ports, it is rec om mended to call com_close(). This
func tion take the port number as an ar gu ment and re turns 0 on suc cess. Ports closed prop erly will re in -
state any pre vious in ter rupt han dlers, and shut down the port from gen er at ing any more in ter rupts.
The next thing in the source code is the eight pri mary in ter rupt serv ice rou tines isr_1() to isr_8().
These eight ISRs simply call a com mon han dler, com mon_isr(), with the pri mary port number as signed
030604 OPERATIONS MANUAL PCM-COM8 Page 3 - 3
WinSystems - "The Embedded Systems Authority"