Description
This example program demonstrates reading from a serial terminal, as described in Text Output and Input.
It uses one core only, and the kernel. There are two threads:
- thread 0: heartbeat LED, to ensure our terminal reading is not blocking,
- thread 1: read strings and integers from the terminal.
Thread 1 runs two loops:
- read string: check buffer overflows,
- read integer: check syntax and out of limits inputs.
Entering an empty input switches between the two loops.
See modules
IO Terminal
See Set-up, one-terminal set-up. Note the limitations of certain terminal programs regarding line mode and local editing.
I have used YAT here.
Set the terminal program to:
- baudrate: 115,200
- text mode, Rx EOL sequence =
LF
Signal Traces
Note: for this test set-up, the interrupt handlers contain am artificial delay to make their signals better visible in the screenshot.
- green: UART receive
- yellow: interrupt handler for FIFO threshold level
- blue: interrupt handler for timeout
The FIFO threshold is set to four entries. Sending 14 characters plus EOL triggers the corresponding interrupt three times (yellow), and after the timeout period the timeout interrupt (blue).
Signals and setup a above.
Sending 15 characters plus EOL triggers the corresponding interrupt four times (yellow), but does not trigger the timeout interrupt, since the FIFO is empty. The situation is handled by detecting the EOL character as the last one transmitted.
Build and Run
Build module ReadTerminal
with Astrobe, and create and upload the UF2 file using abin2uf2
.
Set Astrobe’s memory options as listed, and the library search path as explained.