rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
sense_link.h
Go to the documentation of this file.
1
87
88#pragma once
89
90#include <stdbool.h>
91#include <stdint.h>
92
93#include "bench_state.h"
94#include "link_pages.h"
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
101#define SENSE_LINK_MINOR 7u
103#define SENSE_LINK_ENC_MINOR 9u
105#define SENSE_LINK_WIN_MINOR LINK_MINOR_SERVO_WIN
106
112#define SENSE_LINK_SETTLE_MS 500u
113
121#define SENSE_LINK_READ_MS 40u
122
128#define SENSE_LINK_TOTALS_MS 100u
129
136#define SENSE_LINK_SERVO_MS 40u
137
143#define SENSE_LINK_WIN_MS 40u
144
146#define SENSE_LINK_WIN_HEAD ((unsigned)LINK_SW_ENTRY(2, 0))
147#define SENSE_LINK_WIN_HEAD_WINDOWS 2u
148
154#define SENSE_LINK_WIN_ALL_MS 100u
155
161#define SENSE_LINK_GRACE_MS 2500u
162
167#define SENSE_LINK_BUS_RETRY_MS 5000u
168
170#define SENSE_LINK_STALE_MS 500u
171
176#define SENSE_LINK_STATUS_COUNT ((unsigned)LINK_SN_COUNT - (unsigned)LINK_SN_FLAGS)
177#define SENSE_LINK_STATUS_COUNT_V48 \
178 ((unsigned)LINK_SN_COUNT_V48 - (unsigned)LINK_SN_FLAGS)
183#define SENSE_LINK_SERVO_COUNT ((unsigned)LINK_SS_CH_FLAGS + 1u)
184
186#define SENSE_LINK_NO_ANSWER (-1)
187#define SENSE_LINK_ACK 0
188
190typedef enum {
191 SENSE_LINK_INA228 = 0,
192 SENSE_LINK_INA3221 = 1,
194
196typedef struct {
197 bool i228, i3221;
198 bool as5600;
199 int8_t sda,
201 uint8_t i228_addr;
202 uint16_t i228_uohm;
203 uint16_t i228_max_da;
204 uint8_t i3221_addr;
205 uint16_t i3221_dmohm;
206 uint8_t i3221_ch;
213 uint8_t i3221_parts;
226
228enum {
243 SENSE_LINK_EV_I3221_SILENT = 0x0080,
248 SENSE_LINK_EV_I3221_WRONG = 0x0200,
280};
281
286#define SENSE_LINK_EV_SETUP ((uint32_t)(SENSE_LINK_EV_PINS_UNSET \
287 | SENSE_LINK_EV_SAME_ADDR \
288 | SENSE_LINK_EV_BUS_REFUSED \
289 | SENSE_LINK_EV_I228_REFUSED \
290 | SENSE_LINK_EV_I3221_REFUSED))
291
306
310typedef struct {
312 bool write;
313 uint8_t page;
314 uint8_t off,
316 uint16_t regs[4];
318
320#define SENSE_LINK_WINDOW_MS 50u
321
328typedef struct {
329 uint16_t number;
330 bool current;
331 bool voltage;
332 bool clip_hi;
333 bool clip_lo;
334 uint8_t clipped;
335 int16_t mean_ma;
336 int16_t max_ma;
337 int16_t min_ma;
338 uint16_t mean_mv;
339 uint16_t min_mv;
347 uint32_t taken_ms;
348 bool stamped;
350
355typedef struct {
356 bool page;
361 bool wanted;
366 bool held;
367 uint16_t setups;
369 bool status;
370 uint32_t status_ms;
371 uint16_t flags;
373 uint8_t resets;
378 bool win;
380 uint32_t win_ms;
382
386typedef struct {
387 bool up;
388 bool page;
389 bool enc_page;
390 bool win_page;
396 bool map;
402
403 /* What is asked, as the page is to hold it. */
404 bool want_set;
405 bool want_i228, want_i3221;
406 bool want_enc;
407 int8_t want_sda, want_scl;
408 uint8_t want_parts;
411 uint16_t want[LINK_SN_CONFIG_COUNT];
412 uint32_t want_ms;
413
414 /* What the page holds, as read or written since the link came up. */
415 bool known;
416 uint16_t held[LINK_SN_CONFIG_COUNT];
417 uint32_t setup_ms;
418 bool refused_bus, refused_i228, refused_i3221;
419 bool bus_told;
421 uint32_t bus_refused_ms;
423
424 /* The exchange in flight. */
425 sense_link_op_kind_t pending;
426 uint16_t out[4];
427
428 /* The reads. */
429 bool asked_status, asked_servo;
430 uint32_t status_asked_ms, servo_asked_ms;
431 bool have_status, have_servo;
432 uint16_t status[SENSE_LINK_STATUS_COUNT];
433 uint16_t servo[SENSE_LINK_SERVO_COUNT];
434 uint32_t status_ms;
435 uint32_t status_reads;
437 uint16_t window_last;
438
439 /* The window ring. */
440 bool asked_win;
441 uint32_t win_asked_ms;
442 bool win_all;
446 uint16_t win_next;
447 uint32_t win_sync_ms;
448 uint32_t win_lost;
449 bool win_have;
451 uint16_t win_newest;
452 uint32_t win_moved_ms;
455 uint8_t winq_n;
457 uint16_t setups;
458 bool caps_new;
459 uint16_t caps;
460
461 /* What has been said. */
462 uint16_t was_flags;
463 uint16_t was_clipped;
464 bool silent_told[2];
465 bool online_seen[2];
466 bool enc_silent_told, enc_online_seen;
468 uint16_t enc_magnet;
469 uint16_t was_faults;
470 uint8_t clipped_ch;
471 uint8_t clip_pending;
473 uint16_t ev_id[2];
474 uint8_t ev_found[2];
475 uint32_t events;
477 uint32_t event_ms;
479
486
494
505void sense_link_came_up(sense_link_t *s, uint16_t minor, uint32_t now_ms);
506
520 uint32_t now_ms);
521
534bool sense_link_next(sense_link_t *s, uint32_t now_ms, bool idle,
535 sense_link_op_t *op);
536
548void sense_link_done(sense_link_t *s, int result, const uint16_t *regs,
549 uint32_t now_ms);
550
557void sense_link_faults(sense_link_t *s, uint16_t faults);
558
566
571#define SENSE_LINK_EVENT_GAP_MS 5000u
572
586uint32_t sense_link_event(sense_link_t *s, uint32_t now_ms);
587
607bool sense_link_event_stands(const sense_link_t *s, uint32_t ev);
608
620void sense_link_event_back(sense_link_t *s, uint32_t ev);
621
630
632enum {
637 SENSE_LINK_ROW_I228_ADDR = 0x0010,
638 SENSE_LINK_ROW_I228_SHUNT = 0x0020,
639 SENSE_LINK_ROW_I228_MAX = 0x0040,
640 SENSE_LINK_ROW_I3221_ADDR = 0x0080,
641 SENSE_LINK_ROW_I3221_SHUNT = 0x0100,
642 SENSE_LINK_ROW_I3221_CH = 0x0200,
643};
644
661uint16_t sense_link_unheld(const sense_link_t *s);
662
671void sense_link_set_map(sense_link_t *s, bool map);
672
680void sense_link_set_map_held(sense_link_t *s, bool held);
681
689
698bool sense_link_take_caps(sense_link_t *s, uint16_t *caps);
699
706uint16_t sense_link_flags(const sense_link_t *s);
707
715bool sense_link_win_on(const sense_link_t *s);
716
726
738uint32_t sense_link_win_lost(const sense_link_t *s);
739
748unsigned sense_link_windows(const sense_link_t *s);
749
763 bench_state_t *b);
764
781
789
797uint32_t sense_link_reads(const sense_link_t *s);
798
813bool sense_link_esc(const sense_link_t *s, uint32_t now_ms, bool *v_ok,
814 float *volts, bool *i_ok, float *amps);
815
829bool sense_link_totals(const sense_link_t *s, uint32_t now_ms,
830 int32_t *charge_cmah, uint32_t *energy_cwh);
831
833typedef struct {
834 uint16_t raw;
835 uint16_t samples;
836 uint16_t still_ms;
837 uint32_t taken_ms;
838 bool weak,
841
857bool sense_link_enc(const sense_link_t *s, uint32_t now_ms,
858 sense_link_enc_t *out);
859
869bool sense_link_enc_no_magnet(const sense_link_t *s, uint32_t now_ms);
870
878uint16_t sense_link_enc_magnet(const sense_link_t *s);
879
886bool sense_link_enc_on(const sense_link_t *s);
887
895uint8_t sense_link_addr(const sense_link_t *s, sense_link_part_t part);
896
904uint16_t sense_link_id(const sense_link_t *s, sense_link_part_t part);
905
918
930
952
959uint16_t sense_link_i3221_dmohm(const sense_link_t *s);
960
968uint8_t sense_link_i3221_addr(const sense_link_t *s);
969
976int sense_link_sda(const sense_link_t *s);
983int sense_link_scl(const sense_link_t *s);
984
998bool sense_link_held_pins(const sense_link_t *s, int *sda, int *scl);
999
1000#ifdef __cplusplus
1001}
1002#endif
The bench readings, in the units a person reads: V, A, W, rpm (revolutions per minute),...
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
The bench readings in the units a person reads: V, A, W and rpm, with their peaks.
Definition bench_state.h:54
The set-up as SETUP INTERFACES has it.
Definition sense_link.h:196
uint8_t i3221_parts
Bit a: the INA3221 at 0x40 + a is fitted (SETUP > SENSORS); the INA228 on any of them is one address.
Definition sense_link.h:213
uint8_t i228_addr
Definition sense_link.h:201
uint16_t i228_max_da
Definition sense_link.h:203
bool i3221_unwatched
No fitted channel watches the servo tester's target (SENSORS' FAST is none): the INA3221 is not the s...
Definition sense_link.h:218
uint16_t i228_uohm
Definition sense_link.h:202
int8_t scl
Definition sense_link.h:200
bool as5600
Definition sense_link.h:198
bool i3221_fast_off_ch1
FAST is CH2 or CH3 of its part: without the map the INA3221 is not the servo rail's meter then,...
Definition sense_link.h:224
uint8_t i3221_ch
Definition sense_link.h:206
int8_t sda
Definition sense_link.h:199
bool i3221
Definition sense_link.h:197
uint16_t i3221_dmohm
Definition sense_link.h:205
uint8_t i3221_addr
Definition sense_link.h:204