CS452 - Real-Time Programming - Spring 2012

Lecture 14 - Serial I/O, Debugging

Public Service Annoucements

  1. Assignment 4
  2. Performance measurements

Serial I/O

See pdf.

FIFO

Why do FIFOs exist in UARTS?

The Big Blunder

To use the FIFO effectively you must be able to turn off the transmitter & receiver independently.

But look at UARTE in UARTxCtrl

The Little Blunder

`It is assumed that various configuration registers for the UART are not written more than once in quick succession, in order to insure proper synchronization of configuration information across the implementation. Such registers include UART1Ctrl and UART1LinCtrlHigh. ... In between the two writes, at least two UARTCLK periods must occur. Under worst case conditions, at least 55 HCLK periods must separate the two writes. The simplest way to due [sic] this is to separate the two writes by 55 NOPs.'

Why does this occur?

Why doesn't anybody care?

Interrupts

Five interrupts in the device

These interrupts are separately enabled and disabled.

  1. Transmit
  2. Receive
  3. Modem status
  4. Receive timeout
  5. Combined

Three inputs to the ICU

  1. Transmit
  2. Receive
  3. Combined

These are adequate for interacting with the terminal, but not for interacting with the train controller.

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

Practical Advice

Until now you have been using busy-wait I/O for getting debugging output. You would like to continue to have debugging output while you are implementing interrupt-mediated I/O.

  1. There are two UART ports on the ARM board.
  2. Connect each one to a different terminal window on the terminal.
  3. Do busy-wait I/O to one for debugging while getting interrupt-mediated I/O working on the other.
  4. Then do debugging I/O on the working serial server while you create and debig the other server.

Hint. The serial server for the terminal must be a lot more complex than the esrial server for the train controller.


Debugging Real-time Programs

The most common set of debugging tools used by experienced programmers is the oldest: printf, grep & stack trace.

Debugging real-time programs, at its base, is just the same as any other debugging, and just the same as empirical science.

  1. Gather data.
  2. Create a model that explains the data
  3. Test the model
  4. If the model is not correct, go to 1.
  5. Remember that the model is ALWAYS provisional: data collected later may invalidate it, no matter how much data has confirmed it.

But real-time programs are harder to debug. Very few programs are entirely free of critical races, which are the worst type of bug, lurking for weeks months or years in seemingly correct code, then appearing when innocuous, unconnected changes occur.

Critical Races

There is no known method for eliminating critical races.

It is, in principle, impossible to test away critical races. Why?

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>

many places in your code. Then, with the assistance of a load map, you can find out where you were in which code when the problem occurred.

In RedBoot you can, in principle, trace any of the kernel

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: