rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
hitec_port.h
Go to the documentation of this file.
1
104#ifndef RCBENCH_HITEC_PORT_H
105#define RCBENCH_HITEC_PORT_H
106
107#include <stdbool.h>
108#include <stdint.h>
109
110#include "hitec_wire.h"
111#include "link_pages.h"
112#include "outputs.h"
113#include "supply_page.h"
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
121#define HITEC_PORT_STOP_MS 50u
125#define HITEC_PORT_BUSY_MS 10000u
127#define HITEC_PORT_SUPPLY_MS LINK_HITEC_SUPPLY_MS
128
130typedef struct {
131 uint32_t lead_ns;
133 uint32_t span_us;
134 uint32_t bit_ns;
136
138typedef struct {
141 void *ctx;
143 uint8_t ports;
146 uint8_t (*pin)(void *ctx, uint8_t port);
151 bool (*take)(void *ctx, uint8_t port, uint8_t pin, uint8_t family,
152 uint8_t drive, uint8_t rx);
154 void (*give)(void *ctx);
158 void (*abort)(void *ctx);
160 void (*run)(void *ctx, hitec_port_run_t *out);
165 void (*supply)(void *ctx, supply_port_view_t *out);
168 bool (*supply_set)(void *ctx, bool on, uint16_t mv, uint16_t ma);
175
180typedef struct {
182 uint16_t staged[LINK_HT_W_STAGED];
183 uint16_t last_cmd[LINK_HT_W_CMD_FRAME];
188 uint32_t t0_ms;
189 uint32_t t1_ms;
190 uint32_t start_us;
191 uint32_t cap_us;
192 uint16_t seq;
193 uint16_t count;
194 uint16_t mv;
195 uint16_t ma;
196 uint16_t off_ms;
197 uint8_t state;
198 uint8_t port;
199 uint8_t pin;
200 uint8_t family;
201 uint8_t drive;
202 uint8_t op;
203 uint8_t result;
204 uint8_t refusal;
205 uint8_t rx;
206 uint8_t dec;
207 uint8_t dec_arg;
208 uint8_t view;
209 uint8_t safe;
210 uint8_t armed;
211 uint8_t other;
212 uint8_t has_pin;
213 uint8_t has_cap;
214 uint8_t stopped;
215 uint8_t keyed;
216 uint8_t cutting;
217 uint8_t off_seen;
218 uint8_t rx_mode;
219 uint8_t rx_line;
221 uint8_t supply_on;
222 uint8_t read_on;
225
238
256uint8_t hitec_port_write(hitec_port_t *p, uint8_t off, uint8_t n,
257 const uint16_t *in, uint32_t now_ms);
258
268void hitec_port_read(const hitec_port_t *p, uint8_t off, uint8_t n,
269 uint16_t *out);
270
283void hitec_port_step(hitec_port_t *p, bool safe, bool stop, uint32_t now_ms);
284
292
302uint8_t hitec_port_quiet_mask(const hitec_port_t *p);
303
313uint8_t hitec_port_pin_mask(const hitec_port_t *p);
314
321void hitec_port_bench_armed(hitec_port_t *p, bool armed);
322
329void hitec_port_other_mask(hitec_port_t *p, uint8_t mask);
330
340
351bool hitec_port_frame_out(const hitec_port_t *p, uint32_t now_ms);
352
353#ifdef __cplusplus
354}
355#endif
356
357#endif /* RCBENCH_HITEC_PORT_H */
bool hitec_port_supply_hold(const hitec_port_t *p)
The port holds the SUPPLY page (supply_page_hold()): every state but LINK_HITEC_FREE,...
Definition hitec_port.c:968
void hitec_port_bench_armed(hitec_port_t *p, bool armed)
Whether the bank is armed: OPEN is refused while it is.
Definition hitec_port.c:954
uint8_t hitec_port_quiet_mask(const hitec_port_t *p)
Bit n: programming port n renders no PWM pulse.
Definition hitec_port.c:943
uint8_t hitec_port_write(hitec_port_t *p, uint8_t off, uint8_t n, const uint16_t *in, uint32_t now_ms)
A write of the page: 0, or the LINK_NACK_* reason with nothing changed.
Definition hitec_port.c:645
bool hitec_port_frame_out(const hitec_port_t *p, uint32_t now_ms)
A byte may be on the wire: a SEND from its start until the lead and the bytes have had their time,...
Definition hitec_port.c:973
uint8_t hitec_port_pin_mask(const hitec_port_t *p)
Bit n: programming port n's pin is the wire driver's.
Definition hitec_port.c:949
void hitec_port_other_mask(hitec_port_t *p, uint8_t mask)
Bit n: the KST page holds programming port n (kst_port_quiet_mask()). OPEN on it is refused with LINK...
Definition hitec_port.c:961
void hitec_port_step(hitec_port_t *p, bool safe, bool stop, uint32_t now_ms)
One pass.
Definition hitec_port.c:881
link_hitec_state_t hitec_port_state(const hitec_port_t *p)
Where the port is.
Definition hitec_port.c:938
void hitec_port_read(const hitec_port_t *p, uint8_t off, uint8_t n, uint16_t *out)
A read of the page, LINK_HT_*.
Definition hitec_port.c:767
bool hitec_port_init(hitec_port_t *p, const hitec_port_hw_t *hw)
Prepare a free port.
Definition hitec_port.c:920
Hitec servo programming protocols: frames, transactions, the reply decoders and the driver interface.
The intermediary every output goes through: one set of rules for arming, clamping,...
What the receiver took, in the order the bytes came.
Definition hitec_wire.h:398
A pin driver.
Definition hitec_wire.h:544
What the port needs from the hardware.
Definition hitec_port.h:138
void(*) abort(void *ctx)
Cut the running transaction: the next poll() hands back what came, marked aborted.
Definition hitec_port.h:158
hitec_driver_t driver
The wire driver.
Definition hitec_port.h:173
void * ctx
The caller's context, passed as the first argument of each hook.
Definition hitec_port.h:141
uint8_t ports
Programming ports the build has, 1 to LINK_PG_PORTS_MAX.
Definition hitec_port.h:143
void(*) give(void *ctx)
Close the wire driver and give the pin back to the generator.
Definition hitec_port.h:154
uint8_t(*) pin(void *ctx, uint8_t port)
Definition hitec_port.h:146
bool(*) supply_set(void *ctx, bool on, uint16_t mv, uint16_t ma)
Definition hitec_port.h:168
void(*) run(void *ctx, hitec_port_run_t *out)
What the driver says about the line; NULL: nothing.
Definition hitec_port.h:160
bool(*) take(void *ctx, uint8_t port, uint8_t pin, uint8_t family, uint8_t drive, uint8_t rx)
Definition hitec_port.h:151
void(*) supply(void *ctx, supply_port_view_t *out)
What the supply says now (supply_page_port_view()).
Definition hitec_port.h:165
What the driver says about the line and the running transaction.
Definition hitec_port.h:130
uint32_t span_us
Definition hitec_port.h:133
uint32_t bit_ns
Definition hitec_port.h:134
uint32_t lead_ns
Definition hitec_port.h:131
The state of one Hitec port: the hardware, the staged registers, the running or last transaction and ...
Definition hitec_port.h:180
uint8_t drive
Definition hitec_port.h:201
uint8_t rx_mode
Definition hitec_port.h:218
uint8_t pin
Definition hitec_port.h:199
uint8_t read_on
Definition hitec_port.h:222
uint16_t off_ms
Definition hitec_port.h:196
uint8_t keyed
Definition hitec_port.h:215
uint8_t result
Definition hitec_port.h:203
uint16_t count
Definition hitec_port.h:193
uint8_t family
Definition hitec_port.h:200
uint8_t stopped
Definition hitec_port.h:214
uint8_t view
Definition hitec_port.h:208
uint8_t has_cap
Definition hitec_port.h:213
uint8_t state
Definition hitec_port.h:197
uint16_t mv
Definition hitec_port.h:194
uint8_t op
Definition hitec_port.h:202
uint8_t dec
Definition hitec_port.h:206
uint8_t rx_line
Definition hitec_port.h:219
uint8_t off_seen
Definition hitec_port.h:217
uint8_t other
Definition hitec_port.h:211
uint8_t has_pin
Definition hitec_port.h:212
uint8_t safe
Definition hitec_port.h:209
uint32_t t1_ms
Definition hitec_port.h:189
uint8_t armed
Definition hitec_port.h:210
hitec_port_run_t info
Definition hitec_port.h:187
uint8_t port
Definition hitec_port.h:198
uint8_t rx
Definition hitec_port.h:205
uint16_t ma
Definition hitec_port.h:195
uint32_t start_us
Definition hitec_port.h:190
uint32_t t0_ms
Definition hitec_port.h:188
hitec_reply_t reply
Definition hitec_port.h:186
uint8_t cutting
Definition hitec_port.h:216
hitec_xfer_t xfer
Definition hitec_port.h:184
uint8_t refusal
Definition hitec_port.h:204
uint8_t supply_on
Definition hitec_port.h:221
hitec_capture_t cap
Definition hitec_port.h:185
uint8_t dec_arg
Definition hitec_port.h:207
uint32_t cap_us
Definition hitec_port.h:191
uint16_t seq
Definition hitec_port.h:192
A decoded reply.
Definition hitec_wire.h:468
One transaction.
Definition hitec_wire.h:233
The supply as a programming port sees it (kst_port.h).
Definition supply_page.h:85
The SUPPLY link page at the IOmcu: a PD mini on a PIO UART, its wiring, what it is to do and what it ...