CS 452/652 Winter 2022 - Lecture 2
January 7, 2022
prev next
Timers
- Chapter 18 in EP93xx User Guide
- memory-mapped device registers
- configuration
- load start/reset value
- read current value
- timer counter width: 16 bit vs 32 bit
- timer mode: free-running vs. periodic
- periodic can be used for interrupt generation
- timer speed: 2 kHz vs. 508 kHz → 508 kHz is recommended
- time horizon = timer counter width / timer speed
- debug/watchdog timers: usage optional
- here: no time of day needed, no remote synchronization (very hard problem)
Serial Interface (UART)
- Chapter 14 in EP93xx User Guide
- in particular, read "UART Register Descriptions" in Section 14.1
- ignore "Modem Register Descriptions" starting on Page 14-25
- character device: 1 byte at a time
- timing: character in UART vs. character transmitted
- flow control: character transmission vs. reception & processing (later)
- memory-mapped device registers
- configuration
- RX/TX status
- data in/out
- UART1 = COM1, train control, 2400 baud, 8N2, flow control
- UART2 = COM2, terminal, 115200 baud, 8N1, no flow control
Track/Train Specifics
- train speed: 0-14; 15 for reverse (add 16 to turn on lights)
- model trains simulate real-world stopping by gradually slowing down
- we want to preserve this important characteristic
⇒ do not directly reverse rolling train!
- turnout commands: straight, curved
- NOTE: the middle turnouts should always be set to S/C or C/S → avoid C/C, S/S
- special command: turn off (last) solenoid
- IMPORTANT: After sending a turnout command, you must wait at least 100ms and at most 500ms. Then, either switch another turnout (which automatically turns off the previous solenoid) or explicitly turn off the last solenoid!
- sensors: query some/all, reset
- tracks have 5x16 sensors
- read reports after query
- IMPORTANT: operate half-duplex, i.e., do not send train commands while receiving sensor data
Polling Loop with Busy Wait?
for (;;) {
while (!c1);
a1();
while (!c2);
a2();
...
}
cannot handle c2 while waiting for c1, etc...