CS452 - Real-Time Programming - Spring 2011

Lecture 14 - Serial I/O: Implementation

Pubilic Service Announcement

  1. CTS from train controller

Serial I/O

Interrupts

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


Implementation

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

Initialization

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

Receiving

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

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

Receiving

As Above

Transmitting

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 )

and

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
one

notifier

likely queue

congestion in

server

likely queue

congestion

in notifer

two

notifiers

one per channel?

one per direction?

how should they

be paired?

four

notifiers

certain queue

congestion

in server

likely queue

congestion in

server

best performance,

most tasks

How should we handle a terminal?

Issues

  1. Line editing
  2. Echo

    Either

    Or


Debugging Real-time Programs

RedBoot

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?

Breakpoint

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: