rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
sense_trace.h
Go to the documentation of this file.
1
176
177#pragma once
178
179#include <stdatomic.h>
180#include <stdbool.h>
181#include <stddef.h>
182#include <stdint.h>
183
184#include "sense_sched.h"
185
186#ifdef __cplusplus
187extern "C" {
188#endif
189
190#define SENSE_TRACE_FORMAT 3u
195#define SENSE_TRACE_LINE_MAX 64u
200#define SENSE_TRACE_PRE 64u
202#define SENSE_TRACE_EDGE_MS 4000u
204#define SENSE_TRACE_KEY_MS 10000u
209#define SENSE_TRACE_HOLD_MS 50u
215#define SENSE_TRACE_STALL_MS 100u
217#define SENSE_TRACE_SLOTS 8u
219#define SENSE_TRACE_MARKS 8u
221#define SENSE_TRACE_T_PER_MS 10u
223#define SENSE_TRACE_PERIOD_US 1000u
225#define SENSE_TRACE_LOST_MAX 0xFFFFFFu
231#define SENSE_TRACE_OWED_MAX_T (1u << 30)
232
243
245typedef enum {
246 SENSE_TRACE_TRIG_CMD = 0,
247 SENSE_TRACE_TRIG_EDGE,
248 SENSE_TRACE_TRIG_KEY,
253
255typedef enum {
256 SENSE_TRACE_END_NONE = 0,
257 SENSE_TRACE_END_TIME,
258 SENSE_TRACE_END_SETUP,
259 SENSE_TRACE_END_KEY,
261
263typedef struct {
264 uint32_t t;
269 int32_t v;
270 uint32_t meta;
273
275typedef struct {
276 bool have;
277 uint8_t head;
278 uint32_t t;
279 uint64_t win;
280 uint32_t gen;
282 uint16_t n_v;
283 uint16_t n_hi,
285 int64_t v_sum;
286 uint32_t lost;
287 uint32_t dropped;
289 uint32_t lost_after;
292 uint32_t cfg,
294 bool cfg_owed;
296 uint32_t cfg_t,
300 uint32_t kept_t;
302
304typedef struct {
305 uint8_t kind;
306 uint32_t t;
307 uint64_t at_us;
308 uint16_t ch,
310 uint32_t cmd_t;
312
314typedef struct {
315 bool have;
316 uint16_t ch;
317 bool changed;
320 bool slewed;
322 bool orphan;
324 uint16_t pulse;
325 uint32_t changed_t;
326 uint32_t cmd_t;
328
330typedef enum {
331 SENSE_TRACE_IDLE = 0,
334 SENSE_TRACE_BODY,
336
338typedef struct {
340 uint16_t id;
341 uint8_t trig;
342 uint32_t t0,
345 uint32_t end_t;
346 uint32_t last_t;
347 bool stopped;
348 bool stalled;
350 uint32_t cfg,
354 uint32_t drops_seen;
357 uint32_t ahead;
359 uint32_t n_s,
364 uint32_t mlost_t[2];
367 uint8_t q_n,
369 /* Triggers at or past the end of a trace still being written, and
370 * behind a slewed command among them its last change or its end. */
372 uint8_t wait_n;
373 uint32_t wait_lost;
374 uint32_t wait_lost_t[2];
375 uint32_t abandoned;
376 uint32_t scanned;
379
383typedef struct {
385 uint32_t mask;
386 atomic_uint_fast32_t head;
387 atomic_uint_fast32_t tail;
388 atomic_uint_fast32_t drops;
392 atomic_uint_fast32_t fed;
398
411 uint32_t size);
412
423 uint64_t tick_us);
424
436 uint64_t at_us, uint16_t ch, uint16_t us);
437
447uint16_t sense_trace_rendered(uint16_t pulse_us, uint32_t top);
448
466bool sense_trace_pulse(sense_trace_t *tr, unsigned slot, uint16_t ch,
467 uint16_t pulse_us, uint64_t now_us);
468
476void sense_trace_unwatch(sense_trace_t *tr, unsigned slot);
477
485void sense_trace_key(sense_trace_t *tr, int c, uint64_t now_us);
486
498size_t sense_trace_pump(sense_trace_t *tr, uint64_t now_us, bool connected,
499 char *out, size_t room);
500
507bool sense_trace_active(const sense_trace_t *tr);
508
515uint32_t sense_trace_held(const sense_trace_t *tr);
516
525int32_t sense_trace_code(int32_t ua, uint32_t shunt_uohm);
526
527#ifdef __cplusplus
528}
529#endif
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
The IOmcu's sampling schedule for the sensor bus: what is read on each 1ms tick, the 50ms windows mad...
sense_trace_stage_t
Where the header stands.
Definition sense_trace.h:330
@ SENSE_TRACE_HEAD_T
Definition sense_trace.h:332
@ SENSE_TRACE_HEAD_H
Definition sense_trace.h:333
void sense_trace_unwatch(sense_trace_t *tr, unsigned slot)
Core 0: slot slot renders no PWM pulse of its own – unbound, or another driver's: the next pulse seen...
Definition sense_trace.c:496
bool sense_trace_active(const sense_trace_t *tr)
Whether a trace is under way.
Definition sense_trace.c:80
sense_trace_trig_t
What started or extended a trace.
Definition sense_trace.h:245
@ SENSE_TRACE_MARK_STEP
Definition sense_trace.h:250
@ SENSE_TRACE_MARK_DEST
Definition sense_trace.h:249
void sense_trace_key(sense_trace_t *tr, int c, uint64_t now_us)
Core 0: a character from the console.
Definition sense_trace.c:503
sense_trace_kind_t
What a record holds.
Definition sense_trace.h:234
@ SENSE_TRACE_SHUNT
Definition sense_trace.h:241
@ SENSE_TRACE_CLIP_LO
Definition sense_trace.h:238
@ SENSE_TRACE_BUS
Definition sense_trace.h:236
@ SENSE_TRACE_CLIP_HI
Definition sense_trace.h:237
@ SENSE_TRACE_CFG
Definition sense_trace.h:239
@ SENSE_TRACE_CURRENT
Definition sense_trace.h:235
int32_t sense_trace_code(int32_t ua, uint32_t shunt_uohm)
The shunt code of ua on a shunt of shunt_uohm: the inverse of ina3221_current_ua(),...
Definition sense_trace.c:85
#define SENSE_TRACE_SLOTS
PWM slots watched for a changed pulse: OUT_MAX_SLOTS.
Definition sense_trace.h:217
sense_trace_end_t
Why a trace ended.
Definition sense_trace.h:255
#define SENSE_TRACE_MARKS
Trigger lines waiting for the console.
Definition sense_trace.h:219
bool sense_trace_pulse(sense_trace_t *tr, unsigned slot, uint16_t ch, uint16_t pulse_us, uint64_t now_us)
Core 0, every pass, for each PWM slot: the output channel ch it renders and the pulse,...
Definition sense_trace.c:442
void sense_trace_trigger(sense_trace_t *tr, sense_trace_trig_t kind, uint64_t at_us, uint16_t ch, uint16_t us)
Core 0: a trigger of kind at at_us on the clock the schedule reads; ch and us are a cmd trigger's cha...
Definition sense_trace.c:342
uint16_t sense_trace_rendered(uint16_t pulse_us, uint32_t top)
The pulse a PWM slice renders when asked for pulse_us with its counter wrapping at top: the frame's l...
Definition sense_trace.c:97
void sense_trace_feed(sense_trace_t *tr, const sense_sched_t *s, uint64_t tick_us)
Core 1, after each tick of s; NULL while no bus is open. tick_us is the time the caller read before t...
Definition sense_trace_feed.c:237
size_t sense_trace_pump(sense_trace_t *tr, uint64_t now_us, bool connected, char *out, size_t room)
Core 0, every pass: up to room bytes of whole lines into out; returns their length....
Definition sense_trace.c:1159
bool sense_trace_init(sense_trace_t *tr, sense_trace_rec_t *buf, uint32_t size)
A trace over buf of size records.
Definition sense_trace.c:17
uint32_t sense_trace_held(const sense_trace_t *tr)
Records the ring holds.
Definition sense_trace.c:75
The sampling schedule of the sensor bus: its parts, windows and captures.
Definition sense_sched.h:446
A trigger line waiting.
Definition sense_trace.h:304
uint8_t kind
Definition sense_trace.h:305
uint64_t at_us
Definition sense_trace.h:307
uint32_t cmd_t
Definition sense_trace.h:310
uint16_t ch
Definition sense_trace.h:308
uint32_t t
Definition sense_trace.h:306
uint16_t us
Definition sense_trace.h:309
Core 0's own.
Definition sense_trace.h:338
uint32_t last_t
Definition sense_trace.h:346
uint32_t drops_seen
Definition sense_trace.h:354
uint32_t n_s
Definition sense_trace.h:359
bool stopped
Definition sense_trace.h:347
uint32_t ms0
Definition sense_trace.h:343
uint32_t n_lost
Definition sense_trace.h:362
uint32_t scanned
Definition sense_trace.h:376
uint32_t n_mlost
Definition sense_trace.h:363
uint32_t cfg
Definition sense_trace.h:350
uint32_t end_t
Definition sense_trace.h:345
uint32_t shunt
Definition sense_trace.h:351
uint32_t len_ms
Definition sense_trace.h:344
bool stalled
Definition sense_trace.h:348
uint8_t q_n
Definition sense_trace.h:367
uint32_t t0
Definition sense_trace.h:342
uint32_t wait_lost
Definition sense_trace.h:373
bool lost_shown
Definition sense_trace.h:352
sense_trace_mark_t q[SENSE_TRACE_MARKS]
Definition sense_trace.h:366
uint32_t abandoned
Definition sense_trace.h:375
uint32_t n_v
Definition sense_trace.h:360
uint8_t q_head
Definition sense_trace.h:368
uint32_t mlost_t[2]
Definition sense_trace.h:364
uint32_t ahead
Definition sense_trace.h:357
uint8_t trig
Definition sense_trace.h:341
uint32_t n_m
Definition sense_trace.h:361
uint16_t id
Definition sense_trace.h:340
uint32_t wait_lost_t[2]
Definition sense_trace.h:374
One record: 12 bytes.
Definition sense_trace.h:263
uint32_t meta
Definition sense_trace.h:270
uint32_t t
Definition sense_trace.h:264
int32_t v
Definition sense_trace.h:269
Core 1's own.
Definition sense_trace.h:275
int64_t v_sum
Definition sense_trace.h:285
uint32_t cfg
Definition sense_trace.h:292
uint16_t n_hi
Definition sense_trace.h:283
uint8_t head
Definition sense_trace.h:277
uint16_t n_v
Definition sense_trace.h:282
uint16_t n_lo
Definition sense_trace.h:284
uint32_t lost_after
Definition sense_trace.h:289
uint32_t lost
Definition sense_trace.h:286
bool cfg_owed
Definition sense_trace.h:294
uint32_t gen
Definition sense_trace.h:280
uint32_t shunt
Definition sense_trace.h:293
uint32_t dropped
Definition sense_trace.h:287
bool shunt_newer
Definition sense_trace.h:299
bool cfg_newer
Definition sense_trace.h:298
uint32_t kept_t
Definition sense_trace.h:300
uint64_t win
Definition sense_trace.h:279
uint32_t cfg_t
Definition sense_trace.h:296
bool have
Definition sense_trace.h:276
uint32_t shunt_t
Definition sense_trace.h:297
uint32_t t
Definition sense_trace.h:278
bool shunt_owed
Definition sense_trace.h:295
A trace of the FAST channel's samples, shared between the two cores.
Definition sense_trace.h:383
uint32_t mask
Definition sense_trace.h:385
sense_trace_out_t out
Definition sense_trace.h:396
sense_trace_src_t src
Definition sense_trace.h:395
atomic_uint_fast32_t fed
Definition sense_trace.h:392
atomic_uint_fast32_t head
Definition sense_trace.h:386
atomic_uint_fast32_t drops
Definition sense_trace.h:388
atomic_uint_fast32_t tail
Definition sense_trace.h:387
One PWM slot's pulse as last seen.
Definition sense_trace.h:314
uint16_t pulse
Definition sense_trace.h:324
uint32_t cmd_t
Definition sense_trace.h:326
uint16_t ch
Definition sense_trace.h:316
bool changed
Definition sense_trace.h:317
bool slewed
Definition sense_trace.h:320
bool have
Definition sense_trace.h:315
uint32_t changed_t
Definition sense_trace.h:325
bool orphan
Definition sense_trace.h:322