openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
aliro_lat.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2026 asxeem
9 * SPDX-License-Identifier: ISC
10 *
11 * aliro_lat — walk-up latency trace. One timestamp per phase boundary of the
12 * BLE connect -> credential auth -> UWB ranging -> bolt pipeline, stamped at
13 * first occurrence and printed as a single consolidated budget line so a bench
14 * trace ranks the levers before anything is optimized. Diagnostics only:
15 * nothing reads these marks on the protocol path. Compiled out entirely when
16 * CONFIG_ALIRO_LAT_TRACE is disabled (call sites stay unconditional).
17 */
18#ifndef ALIRO_LAT_H
19#define ALIRO_LAT_H
20
21#if defined(ESP_PLATFORM)
22#include "sdkconfig.h" /* CONFIG_ALIRO_LAT_TRACE (Zephyr injects autoconf.h itself) */
23#endif
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Phase boundaries, in pipeline order. Deltas in the budget line are relative
30 * to ALIRO_LAT_BLE_CONNECT (the walk-up's t=0). */
31enum aliro_lat_phase {
32 ALIRO_LAT_BLE_CONNECT = 0, /* GAP connect on the reader's advertisement */
33 ALIRO_LAT_GATT_SPSM_READ, /* phone read the SPSM/versions/features characteristic */
34 ALIRO_LAT_GATT_VER_WRITE, /* phone wrote its selected protocol version */
35 ALIRO_LAT_L2CAP_OPEN, /* L2CAP CoC connected on the Aliro SPSM */
36 ALIRO_LAT_OP05_RX, /* phone's Initiate-Access-Protocol received */
37 ALIRO_LAT_AUTH0_TX, /* AUTH0 command sent */
38 ALIRO_LAT_AUTH0_RSP, /* AUTH0Response received (fast/standard fork) */
39 ALIRO_LAT_AUTH1_DONE, /* AUTH1Response verified; EXCHANGE sent */
40 ALIRO_LAT_EXCHANGE_DONE, /* EXCHANGE response accepted (URSK armed) */
41 ALIRO_LAT_AP_COMPLETED, /* Reader-Status-AP-Completed sent */
42 ALIRO_LAT_IRS_RX, /* device's Initiate-Ranging-Session received */
43 ALIRO_LAT_M1_TX, /* M1 sent (engine's 1st ranging-setup TX) */
44 ALIRO_LAT_M2_RX, /* M2 received (2nd ranging-setup RX) */
45 ALIRO_LAT_M3_TX, /* M3 sent (engine's 2nd ranging-setup TX) */
46 ALIRO_LAT_M4_RX, /* M4 received (3rd ranging-setup RX) */
47 ALIRO_LAT_M4_DONE, /* UWB session ACTIVE (M4 handled, responder up) */
48 ALIRO_LAT_FIRST_RANGE, /* first DS-TWR range latched */
49 ALIRO_LAT_TRUSTED_RANGE, /* layer-4 consensus reached */
50 ALIRO_LAT_NEAR_DWELL, /* approach threshold met; unlock scheduled */
51 ALIRO_LAT_BOLT_DRIVEN, /* lock manager drove the unlock (Matter task) */
52 ALIRO_LAT_PHASE_COUNT
53};
54
55#if defined(CONFIG_ALIRO_LAT_TRACE)
56
57/* Start a fresh walk-up trace: clear every mark and stamp BLE_CONNECT. */
58void aliro_lat_begin(void);
59
60/* Stamp a phase at its first occurrence this walk-up; later calls are no-ops.
61 * Returns nonzero when this call stamped the phase, 0 otherwise. Cheap (one
62 * uptime read + store) — safe on the BLE-host and UWB RX paths. */
63int aliro_lat_mark(enum aliro_lat_phase phase);
64
65/* Print the consolidated budget line (one printf; call off the protocol path). */
66void aliro_lat_report(void);
67
68#else /* !CONFIG_ALIRO_LAT_TRACE */
69
74static inline void aliro_lat_begin(void)
75{
76}
81static inline int aliro_lat_mark(enum aliro_lat_phase phase)
82{
83 (void)phase;
84 return 0;
85}
90static inline void aliro_lat_report(void)
91{
92}
93
94#endif /* CONFIG_ALIRO_LAT_TRACE */
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* ALIRO_LAT_H */
static void aliro_lat_begin(void)
Initialize latency tracking; record the BLE_CONNECT epoch as the zero reference for all subsequent ph...
Definition aliro_lat.h:74
static int aliro_lat_mark(enum aliro_lat_phase phase)
Record the current uptime for a given Aliro protocol phase if not yet marked; return 1 if newly recor...
Definition aliro_lat.h:81
static void aliro_lat_report(void)
Emit a latency report showing all recorded phase timestamps and elapsed intervals; dump flight-record...
Definition aliro_lat.h:90