CS452 - Real-Time Programming - Spring 2011

Lecture 14 - Serial I/O: Implementation

Pubilic Service Announcement

  1. CTS from train controller

Serial I/O


Easy way to use interrupts

Enable only combined; read UART registers to decide what to do.

Think of the receive and transmit parts of the UART as separate state machines


FIFO is assumed to be turned off; buffers are assumed to be in the server.

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

Providing I/O for the terminal


  1. Enable RcvRdy, XmitRdy interrupts in UART.
  2. Enable combined interrupt in ICU


Notifier RCV_BL on RcvRdy event

  1. Interrupt occurs, AwaitEvent returns with byte.
  2. Notifier sends byte to server
  3. Server replies, Notifier returns to initial state
  4. Server checks GetQ
  5. If ( ! GetQ_Empty )
  6. Else insert byte in RcvQ

When server receives Get request from client

  1. Server checks RcvQ
  2. If ( ! RcvQ_Empty )
  3. Else insert client in GetQ


Transmitting is a little more tricky because two conditions must be met.

  1. Byte available to transmit
  2. Transmit holding register empty

Assume we put conjunction detection in the server

When server receives Put request from client

  1. Is Notifier ready?
  2. If ( Ready ) Reply( notifier, byte ); Reply( client, ... )
  3. Else insert byte in XmitQ; Reply( client, ... )

When server receives Ready request from Notifier

  1. Is XmitQ empty?
  2. If ( Empty ) Mark notifier ready; Reply( client, ... )
  3. Else Reply( notifier, byte ); Reply( client )

The Notifier

  1. Enable XmitReady
  2. AwaitEvt( XmitRdy )
  3. Disable XmitRdy
  4. Send( server, ready, byte )
  5. Write byte on UART

This procedure assumes that the transmit bit never resets once it is set. Is this true?

Conjunction detection and buffer could just as easily be in the Notifier

Providing I/O for the train controller


As Above


For transmitting three conditions must be set

  1. Byte available to transmit
  2. Holding register empty
  3. CTS asserted

Task Structure

We are supposed to support

int Get( int port )


int Put( int port, char c )

These are wrappers for sends to one or more serial servers.

How many servers and notifiers?

one server two servers four servers


likely queue

congestion in


likely queue


in notifer



one per channel?

one per direction?

how should they

be paired?



certain queue


in server

likely queue

congestion in


best performance,

most tasks

How should we handle a terminal?


  1. Line editing
  2. Echo



Debugging Real-time Programs


The memory contents are not wiped by reset. Some of the most difficult errors can be detected only by using the contents of memory after a reset. Produce useful results by inserting

    str   pc, <magic location>

into your code, and with the assistance of a load map, finding out where you were in whose code when the problem occurred.

Stack Trace

In single-threaded programs this is often the most useful tool.

What is the equivalent of a stack trace in a real-time multi-tasking environment?


What does it do?

How do you get it started?

Breakpoint is a special case of a particular sort of tool that is very common.

Getting information closer to real-time.

Return to: