Decode STmin
Turn the STmin byte of a flow control frame into microseconds, reserved values included. An easy embedded C problem (ISO-TP: flow control and timing), run…
easy · ISO-TP: flow control and timing · isotp · can · automotive · timing
The third byte of an ISO-TP flow control frame is STmin, the least time the sender must leave between consecutive frames. Its coding is not linear:
| Byte | Meaning |
|---|---|
0x00 to 0x7F | 0 to 127 milliseconds |
0xF1 to 0xF9 | 100 to 900 microseconds |
| anything else | reserved: use the longest valid time, 127 ms |
Write stmin_us(raw), the time in microseconds, and stmin_ticks(raw), the number of 1 ms ticks a sender must wait. A sender may wait longer than STmin, never shorter, so round up.
Starter code
uint32_t stmin_us(uint8_t raw) {
return raw * 1000u;
}
uint32_t stmin_ticks(uint8_t raw) {
return stmin_us(raw) / 1000u;
}Example tests
Milliseconds
show(0x00);
show(0x14);
show(0x7F);Expected output:
0x00: 0 us, 0 tick(s)
0x14: 20000 us, 20 tick(s)
0x7F: 127000 us, 127 tick(s)Microseconds round up to a tick
show(0xF1);
show(0xF9);Expected output:
0xF1: 100 us, 1 tick(s)
0xF9: 900 us, 1 tick(s)Learn it first
- ISO-TP: flow control and timing · Block size, STmin, the N_ timers, wait and overflow, and a receiver that survives a bad sender.
More ISO-TP: flow control and timing problems
- Reassemble a segmented message · An ISO-TP receiver: first and consecutive frames in, a complete message or nothing out.