rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
sense_svc.h
Go to the documentation of this file.
1
59
60#pragma once
61
62#include <stdbool.h>
63#include <stdint.h>
64
65#include "sense_bus.h"
66#include "sense_sched.h"
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
73#define SENSE_SCAN_FIRST 0x40u
74#define SENSE_SCAN_COUNT 16u
75
82typedef struct {
83 uint16_t cfg_gen;
84 uint8_t sda,
87 uint16_t run_gen;
88 uint16_t cap_gen;
89 bool cap_on;
91 bool edge_set;
92 uint64_t edge_us;
93 uint16_t limit_ma[SENSE_CHANNELS];
98
100typedef struct {
101 uint16_t cfg_gen, run_gen, cap_gen;
102 bool open;
103 bool stuck;
104 uint64_t held;
105 uint16_t errors;
106 uint16_t present;
109 uint16_t i228_maker,
113 uint8_t fast;
117 int32_t temp_mdegc;
118 uint16_t diag;
119 bool have_win;
120 sense_window_t win[SENSE_SRC_COUNT];
126 uint8_t i228_resets;
131 uint16_t cap_seq;
132 uint32_t cap_move_t;
133 uint32_t cap_arrive_t;
134 int32_t cap_peak_ua;
135 int32_t cap_mean_ua;
136 uint32_t cap_samples;
138 /* The output encoder (AS5600). */
139 sense_state_t enc;
141 uint8_t enc_status;
142 uint8_t enc_id;
143 uint16_t enc_raw;
144 uint16_t enc_samples;
145 uint16_t enc_still_ms;
146 bool enc_have_mag;
147 uint8_t enc_agc;
148 uint16_t enc_magnitude;
149 uint16_t over_n[SENSE_CHANNELS];
153
155typedef struct {
161 bool (*open)(void *ctx, uint8_t sda, uint8_t scl);
163 void (*close)(void *ctx);
168 sense_err_t (*ask)(void *ctx, uint8_t addr);
170
174typedef struct {
176 bool started;
177 uint16_t cfg_gen,
180 bool open;
181 uint8_t sda,
184 bool refused;
185 uint16_t refusals;
186 uint16_t seq_base;
187 bool scan_due;
188 uint64_t scan_at_us;
189 uint16_t present;
190 bool lim_have;
191 uint16_t lim_win;
192 uint16_t over_n[SENSE_CHANNELS];
193 uint32_t setups;
197
204void sense_svc_init(sense_svc_t *v, const sense_svc_io_t *io);
205
214void sense_svc_step(sense_svc_t *v, const sense_cmd_t *cmd, sense_snap_t *out);
215
231bool sense_window_over(const sense_window_t *w, int32_t clip_ua,
232 uint16_t limit_ma);
233
234#ifdef __cplusplus
235}
236#endif
The sensor bus: one I2C (Inter-Integrated Circuit) bus with current monitors on it,...
sense_err_t
What a transaction came to.
Definition sense_bus.h:62
sense_state_t
A part on the bus, as far as it is known.
Definition sense_bus.h:175
The IOmcu's sampling schedule for the sensor bus: what is read on each 1ms tick, the 50ms windows mad...
sense_cap_state_t
The move capture's state, in the order a capture passes through; the numbers are link_cap_state_t's.
Definition sense_sched.h:368
#define SENSE_WIN_RING
FAST windows the ring keeps: 200ms.
Definition sense_sched.h:196
#define SENSE_I3221_PARTS
INA3221 parts, at 0x40 to 0x43, and their channels.
Definition sense_sched.h:239
void sense_svc_init(sense_svc_t *v, const sense_svc_io_t *io)
A service with the bus closed; the first step takes its command whole.
Definition sense_svc.c:14
bool sense_window_over(const sense_window_t *w, int32_t clip_ua, uint16_t limit_ma)
Whether window w of a channel passed limit_ma: its highest current rounded to mA (as SENSE_WIN shows ...
Definition sense_svc.c:81
void sense_svc_step(sense_svc_t *v, const sense_cmd_t *cmd, sense_snap_t *out)
One tick, every 1ms: cmd acted on, the schedule ticked while the bus is open, and out filled.
Definition sense_svc.c:343
A capture's levels, µA.
Definition sense_sched.h:381
What core 0 asks for.
Definition sense_svc.h:82
uint8_t sda
Definition sense_svc.h:84
sense_cap_arm_t cap
Definition sense_svc.h:90
sense_sched_cfg_t parts
Definition sense_svc.h:86
uint16_t cfg_gen
Definition sense_svc.h:83
uint8_t scl
Definition sense_svc.h:85
uint16_t limit_ma[SENSE_CHANNELS]
Definition sense_svc.h:93
uint64_t edge_us
Definition sense_svc.h:92
bool cap_on
Definition sense_svc.h:89
uint16_t run_gen
Definition sense_svc.h:87
uint16_t cap_gen
Definition sense_svc.h:88
bool edge_set
Definition sense_svc.h:91
One FAST window as the ring keeps it.
Definition sense_sched.h:335
The run since sense_sched_arm(), from the INA228.
Definition sense_sched.h:350
What is fitted and how; a part not enabled is never addressed.
Definition sense_sched.h:282
The wire, the clock and the bus recovery.
Definition sense_sched.h:266
The sampling schedule of the sensor bus: its parts, windows and captures.
Definition sense_sched.h:446
What core 1 hands back after each step.
Definition sense_svc.h:100
uint8_t enc_id
Definition sense_svc.h:142
sense_run_t run
Definition sense_svc.h:129
uint16_t errors
Definition sense_svc.h:105
uint16_t i228_device
Definition sense_svc.h:110
sense_window_t win[SENSE_SRC_COUNT]
Definition sense_svc.h:120
int32_t cap_peak_ua
Definition sense_svc.h:134
uint32_t cap_move_t
Definition sense_svc.h:132
bool open
Definition sense_svc.h:102
uint8_t i228_resets
Definition sense_svc.h:126
uint16_t enc_samples
Definition sense_svc.h:144
uint16_t enc_still_ms
Definition sense_svc.h:145
sense_state_t i3221[SENSE_I3221_PARTS]
Definition sense_svc.h:108
bool stuck
Definition sense_svc.h:103
uint16_t cap_seq
Definition sense_svc.h:131
int32_t temp_mdegc
Definition sense_svc.h:117
bool cap_clipped
Definition sense_svc.h:137
uint16_t cap_gen
Definition sense_svc.h:101
uint16_t present
Definition sense_svc.h:106
uint16_t diag
Definition sense_svc.h:118
bool have_temp
Definition sense_svc.h:115
bool have_win
Definition sense_svc.h:119
uint8_t enc_status
Definition sense_svc.h:141
uint64_t held
Definition sense_svc.h:104
uint8_t fast
Definition sense_svc.h:113
uint16_t i3221_maker[SENSE_I3221_PARTS]
Definition sense_svc.h:111
bool enc_have_angle
Definition sense_svc.h:140
uint32_t cap_arrive_t
Definition sense_svc.h:133
bool have_diag
Definition sense_svc.h:116
uint16_t i3221_die[SENSE_I3221_PARTS]
Definition sense_svc.h:112
uint32_t cap_samples
Definition sense_svc.h:136
sense_ring_win_t ring[SENSE_WIN_RING]
FAST's last windows, newest first: entry k is the window numbered k before the number of win[].
Definition sense_svc.h:125
sense_state_t i228
Definition sense_svc.h:107
uint8_t i3221_resets[SENSE_I3221_PARTS]
Per INA3221: found reset under this set-up, modulo 256.
Definition sense_svc.h:128
uint16_t enc_raw
Definition sense_svc.h:143
uint16_t over_n[SENSE_CHANNELS]
Definition sense_svc.h:149
sense_cap_state_t cap_state
Definition sense_svc.h:130
uint16_t i228_maker
Definition sense_svc.h:109
int32_t cap_mean_ua
Definition sense_svc.h:135
The wire, the clock, the recovery and the pins.
Definition sense_svc.h:155
sense_sched_io_t sched
Definition sense_svc.h:156
bool(*) open(void *ctx, uint8_t sda, uint8_t scl)
The I2C block on sda and scl at 400kHz; false when those pins cannot carry it, and nothing is changed...
Definition sense_svc.h:161
void(*) close(void *ctx)
The block off and its pins let go.
Definition sense_svc.h:163
sense_err_t(*) ask(void *ctx, uint8_t addr)
The address byte and one byte read back: SENSE_OK when addr acknowledged, SENSE_NACK when it did not,...
Definition sense_svc.h:168
The sensor service: its schedule and the command state it acts on.
Definition sense_svc.h:174
uint16_t refusals
Definition sense_svc.h:185
uint16_t cap_gen
Definition sense_svc.h:179
uint16_t run_gen
Definition sense_svc.h:178
uint16_t cfg_gen
Definition sense_svc.h:177
uint16_t present
Definition sense_svc.h:189
uint16_t over_n[SENSE_CHANNELS]
Definition sense_svc.h:192
sense_sched_t sched
Definition sense_svc.h:195
uint8_t scl
Definition sense_svc.h:182
uint8_t sda
Definition sense_svc.h:181
bool scan_due
Definition sense_svc.h:187
bool started
Definition sense_svc.h:176
bool lim_have
Definition sense_svc.h:190
uint32_t setups
Definition sense_svc.h:193
bool edge_given
Definition sense_svc.h:183
bool refused
Definition sense_svc.h:184
uint64_t scan_at_us
Definition sense_svc.h:188
uint16_t seq_base
Definition sense_svc.h:186
bool open
Definition sense_svc.h:180
uint16_t lim_win
Definition sense_svc.h:191
One complete window of one source.
Definition sense_sched.h:309