Files
heltec-repeater/docs/TIMING.md
T

100 lines
4.3 KiB
Markdown

# Timing Instrumentation
All values measured on the DUT with `esp_timer_get_time()` (monotonic
microseconds), from `captures/2026-09-01T10-34-24-hil` (1200 s run, 72
repeats, 214 RX candidates, repeat delay set to 200 ms).
## Measured
| Quantity | min | median | max | n |
|---|---|---|---|---|
| RxDone -> reconstructed end of frame ("deaf tail") | 9 360 us | 12 240 us | 17 120 us | 214 |
| TX operation latency (routine entry -> observed TxDone) | 10 421 us | 13 422 us | 14 560 us | 72 |
| Scheduled frame end -> TX-routine entry | 200 001 us | 200 001 us | 200 008 us | 72 |
| Repeated frame length (over-the-air bytes) | 63 | 100 | 113 | 72 |
Independent confirmation from the SDR side (raw IQ, same run): observed
burst duration differs from the computed airtime by 0.2-1.5 ms
(median 1.2 ms), and firmware TX-operation events align to observed RF
within 0-3.1 ms (median 2.4 ms).
## Derived
```
repeat scheduling accuracy : +1 us to +8 us against a 200 ms setting
(at TX-routine entry, not RF onset)
RX deaf time per repeat : ~225.7 ms historical median
= 12.2 ms deaf tail
+ 200.0 ms programmed delay
+ 13.4 ms TX operation latency
```
The programmed delay dominates by design; it exists to make SDR
correlation possible during development.
## The 12 ms deaf tail
The SX1262's GFSK packet engine cannot express Wireless M-Bus length
semantics (format A carries per-block CRCs that the L-field excludes), so
RX uses a fixed 255-byte capture and the firmware truncates in software
using the L-field formulas. Consequences:
- RxDone fires `(255 - frame_bytes) * 80 us` after the frame really ended;
the firmware subtracts this to recover the true end-of-frame timestamp,
which is what the repeat delay is measured from.
- During that tail the receiver is not re-armed for sync search, costing
9.4-17.1 ms of receive availability per detected frame -- including for
false syncs from the deliberately short 8-bit preamble detector.
Optimisation candidate (not implemented): poll `GetRxBufferStatus` after
`SyncWordValid`, read the L-field as soon as it lands, then stop RX early
once the computed frame length has been received. That would cut the tail
to roughly the frame's own airtime and materially raise the duty cycle of
a production repeater.
## Relevance to the production gateway
- A production repeater using randomized 5-25 s delays will have a very
different deaf-time profile; the 200 ms figure here is a development
artefact, not a design target (see docs/STANDARDS_GAPS.md).
- The fixed-255 tail is an SX1262 packet-engine limitation, so it applies
to any SX126x-based design. Budget for it, or implement early-stop RX.
- TX-routine scheduling jitter is only a few microseconds. Actual RF starts
after packet setup and buffer transfer, so it must be measured at RF when
exact over-the-air delay matters.
## Computed airtime vs TX operation latency
Current `airtime_us`, cumulative `stats.tx_airtime_us`, and the duty ledger
all use computed channel occupancy:
```
airtime = 48-bit preamble + 16-bit sync + payload at 100 kbps
= (radio_payload_bytes * 80 us) + 640 us
102-byte radio payload : 8.8 ms
26-byte beacon payload : 2.72 ms
```
`wmbus_tx.tx_operation_us` separately records the longer interval from
entry into the TX routine through observed TxDone. It includes standby,
packet-parameter and buffer SPI transactions, the actual transmission, and
polling/notification latency. Historical firmware mislabeled this interval
as `airtime_us`; its 102-byte median was 13.4 ms.
The distinction matters:
- Computed occupancy is independent of task scheduling and SPI speed, so
the duty guard no longer consumes roughly 50% extra budget.
- Operation latency remains useful for diagnosing stalls and TxDone timing,
but is not a regulatory airtime measurement.
- Raw-IQ burst duration remains the independent check. In the historical
102-byte run it differed from computed airtime by 0.2-1.5 ms (median
1.2 ms).
The rolling-hour ledger uses 61 keyed one-minute buckets rather than a
fixed event ring. It therefore cannot forget high-rate events merely
because an event count was exceeded. The oldest overlapping minute is
counted in full, making the result conservatively high by at most one
minute's included traffic at the window boundary.