rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
supply_link.h
Go to the documentation of this file.
1
47
48#pragma once
49
50#include <stdbool.h>
51#include <stdint.h>
52
53#include "link_pages.h"
54#include "supply.h"
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
64#define SUPPLY_CAPS_PDMINI { 1.0f, 20.0f, 0.01f, 0.05f, 3.0f, 0.01f }
65
71#define SUPPLY_LINK_STALE_MS 1500u
77#define SUPPLY_LINK_BLIND_MS (2u * SUPPLY_LINK_STALE_MS)
79#define SUPPLY_LINK_READ_MS 100u
80
82#define SUPPLY_LINK_BAUD_AUTO 7u
83
85typedef struct {
86 bool en;
87 int8_t tx, rx;
88 uint8_t baud;
90
94#define SUPPLY_LINK_NO_ANSWER (-1)
95#define SUPPLY_LINK_ACK 0
96
98enum {
109};
110
114typedef enum {
115 SUPPLY_LINK_W_NONE = 0,
116 SUPPLY_LINK_W_OFF,
117 SUPPLY_LINK_W_WIRING,
118 SUPPLY_LINK_W_COMMAND,
119 SUPPLY_LINK_W_RESET,
121
125typedef struct {
126 /* What is asked. */
127 supply_wiring_t want;
128 bool on;
129 uint16_t mv, ma;
130
131 /* What the page holds, as written and acknowledged since the last
132 * time it was known. */
133 bool wired; /* page.wiring holds `want` as it was then */
134 bool wire_wait; /* page.wiring acknowledged, not yet read held */
135 supply_wiring_t page;
136 bool refused; /* `want` was refused; not written again */
137 bool commanded; /* the page holds page_on, page_mv, page_ma */
138 bool page_on;
139 uint16_t page_mv, page_ma;
140
141 /* The write in flight. */
142 supply_link_write_t pending;
143 uint16_t out[LINK_SP_FLAGS];
144
145 /* The last read. */
146 uint16_t regs[LINK_SP_COUNT];
147 bool read_any;
148 bool asked; /* a read was asked for since it was known */
149 uint32_t read_ms;
150 uint32_t asked_ms; /* when the last read was asked for */
151 /* The module's readings: SAMPLES as last read, and the page read that
152 * first showed it. A page read whose SAMPLES did not move brings no
153 * new reading -- a display read on the IOmcu that was slow or
154 * failed -- however fresh the page itself is. */
155 uint16_t samples_seen;
156 uint32_t sample_ms;
157
158 uint16_t events;
159 uint8_t found; /* the rate AUTO last reported, 7 none */
160 /* The input and the set point, in mV, on the read that first showed
161 * the output switched off for a sagging input (FLAGS bit 10). */
162 uint16_t sag_vin_mv, sag_set_mv;
163 bool reset_owed; /* a module restart asked, not yet written */
164 bool port_held; /* the last read had LINK_SP_PORT set */
165 bool judge; /* set points refused on an output that is
166 on: the next read says by whom */
167 bool adopted; /* on, mv, ma were taken from the page and
168 not yet handed out */
170
177
185
193
203void supply_link_command(supply_link_t *s, bool on, uint16_t mv, uint16_t ma);
204
212
227 uint8_t *n, uint16_t *regs);
228
237void supply_link_written(supply_link_t *s, int result);
238
247
261bool supply_link_event_stands(const supply_link_t *s, uint16_t ev);
262
270bool supply_link_read_due(const supply_link_t *s, uint32_t now_ms);
271
280void supply_link_read(supply_link_t *s, const uint16_t *regs,
281 uint32_t now_ms);
282
300void supply_link_state(const supply_link_t *s, uint32_t now_ms,
301 supply_state_t *st);
302
319bool supply_link_blind(const supply_link_t *s, uint32_t now_ms);
320
335bool supply_link_adopted(supply_link_t *s, bool *on, uint16_t *mv,
336 uint16_t *ma);
337
345
358void supply_link_sag(const supply_link_t *s, uint16_t *vin_mv,
359 uint16_t *set_mv);
360
369typedef struct {
370 bool seen;
371 unsigned edits, word;
373
383bool supply_link_wiring_moved(supply_link_follow_t *f, unsigned edits,
384 unsigned word);
385
400bool supply_link_held_pins(const supply_link_t *s, int *tx, int *rx);
401
415
416#ifdef __cplusplus
417}
418#endif
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
A supply's readings, set points, mode and trip state.
Definition supply.h:69
Where the PD mini is wired, as SETUP INTERFACES has it.
Definition supply_link.h:85
int8_t rx
Definition supply_link.h:87
uint8_t baud
Definition supply_link.h:88
A programmable supply: what it can be set to, what it was set to, and what it delivers.