RX/TX hold registers: 64-bytes FIFOs for send/receive
RX/TX level registers: FIFO status
Timer
here: no time of day needed, no remote synchronization (very hard problem)
ARM timer: dynamic frequency
SYSTEM timer: fixed frequency (better) - see BCM Chapter 10
64-bit counter running at 54 MHz (CLO / CHI)
query timer and/or wait for interrupt via "compare" registers
Track/Train Interface
USEFUL: turn on the headlights! (verify communication and direction)
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 (0x21), curved (0x22)
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 0x020
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; tracks have 5x16 sensors
set reset mode (single command byte 0xC0)
read reports after query
IMPORTANT: track communication is half-duplex, i.e., no contro
can use extra serial cable to connect gtkterm to RPi Channel 2 for debugging
Build Environment
linking with libc
without MMU and/or other magic: SIMD/FP instructions require strict alignment
not a problem, since kernels typically don't do FP
but: precompiled libc routines don't care
options:
do not use libc!
do not use those routines (see test in Makefile)
recompile libc?
linking and loading for C++: might need constructors, etc.
Design
polling loop
for (;;) {
if (c1) a1();
if (c2) a2();
...
}
vs. busy wait
for (;;) {
while (!c1);
a1();
while (!c2);
a2();
...
}