CS452 - Real-Time Programming - Spring 2009
Lecture 17 - Serial IO: Programmer's Model
Practical Details
Split serial I/O channels
- One BW, the other interrupts
Serial Hardware
DMA
Direct Memory Access
HDLC
High-level Data Link Control
- Derived from IBM SLDC
- Synchronous, with synchronized clocks at each end of a connection
- Many stages, many modes
- Supports ABM (Asynchronous Balanced Mode)
Serial Interrupts
The simplest way to handle the interrupts is to turn on only the combined
interrupt and then look at the registers of the device.
To identify the current interrupt
Read UARTxIntIDIntClr at 0x800[bc]001c
- Four bits, one for each interrupt
- (Write anything to this register to clear the modem status
interrupt)
What service is required
Transmitting
- Getting started
- Enable modem status interrupt
- Bytes arrive to transmit
If transmitter is busy (UARTxFlag at
0x800[bc]0018)
- enable transmit interrupt in
UARTxCtrl at
0x800[bc]0014
If transmitter is not busy & fewer than 16 bytes to transmit
If transmitter is not busy & more than 16 bytes to transmit
- write 16 bytes to FIFO
- enable transmit interrupt
- Modem status interrupt
EITHER
- Clear interrupt
- Disable transmitter
- Enter stalled state: accumulate bytes in buffer
OR
- Clear interrupt
- Enable transmitter
- Enter transmit state
- Transmit interrupt
If there are more than 8 bytes to transmit
- Write 8 bytes to FIFO
- Leave interrupt enabled
If there are fewer than 8 bytes to transmit
- Write remaining bytes to FIFO
- Disable transmit interrupt in UARTxCtrl at 0x800[bc]0014
- Start again when more bytes to transmit
Receiving
- Getting started
- Clear any junk from FIFO
- Turn on receiver
- Enable Receive and Receive Time Out interrupts
- Receive interrupt
- Receive Time Out interrupt
- Read from FIFO until empty
Typical Task Structure
Most simple
- Separate server/notifier pair for Receive and for Transmit
- Reparate Receive/Transmit quartet for each channel
Receive
- Server provides
- Notifier provides
- Initialization of device
- Sending characters to server in blocks as they arrive
- Managing a buffer that creates blocks for the server
- Questions.
- What if server buffer gets full?
- What if notifier buffer gets full?
Transmitter
- Server provides
- Putc for clients,
- Putc is non-blocking, server replies immediately
- Fill buffer from Notifier
- Fill buffer must not be non-blocking. Why?
- Notifier provides
- Management of stalled/transmit state
- Managing an output buffer to hold characters when transmission is
stalled
- Emptying buffer into UART when transmission is not stalled
- Questions
- What if server buffer gets full?
- What if notifier buffer gets full?
Issues
- Should it be possible to allocate a server?
- What should transmit/receive granularity be?
- Should servers be specialized to match devices on the end of their
channel?
- How should echo be handled?
Return to: