rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
hitec_pre.h
Go to the documentation of this file.
1
61#ifndef HITEC_PRE_H
62#define HITEC_PRE_H
63
64#include <stdbool.h>
65#include <stdint.h>
66
67#include "hitec_wire.h"
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
81
86#define HITEC_PRE_SAMPLES_PER_BIT 8u
93#define HITEC_PRE_CHARGE_NS 100u
94#define HITEC_PRE_SAMPLE_NS 113u
100#define HITEC_PRE_CHARGE_MIN_NS 7u
101#define HITEC_PRE_CHARGE_MAX_NS 200u
102#define HITEC_PRE_SAMPLE_MIN_NS 40u
103#define HITEC_PRE_SAMPLE_MAX_NS 187u
111#define HITEC_PRE_MIN_HZ 48000000u
112#define HITEC_PRE_MAX_HZ 250000000u
114#define HITEC_PRE_WINDOW_MAX_US 30000u
119#define HITEC_PRE_WORDS 928u
121#define HITEC_PRE_PROGRAM_MAX 12u
123#define HITEC_PRE_FRAME_BITS 10u
124
126typedef struct {
127 uint32_t sys_hz;
128 uint32_t period;
129 uint32_t charge;
130 uint32_t wait;
131 uint32_t spb_q16;
138
153bool hitec_pre_timing(uint32_t sys_hz, hitec_pre_timing_t *out);
154
162uint32_t hitec_pre_cycles_ns(const hitec_pre_timing_t *t, uint64_t cycles);
163
179unsigned hitec_pre_program(const hitec_pre_timing_t *t, uint16_t *words,
180 unsigned max);
181
190 uint32_t window_us);
191
206uint32_t hitec_pre_words(const hitec_pre_timing_t *t, uint32_t window_us,
207 uint8_t max_rx);
208
219static inline unsigned hitec_pre_sample(const uint32_t *words, uint32_t k)
220{
221 return (unsigned)((words[k >> 5] >> (31u - (k & 31u))) & 1u);
222}
223
224/* --- the decoder ---------------------------------------------------------- */
225
233
241
243typedef struct {
244 uint32_t window;
245 uint32_t at;
246 uint32_t waited;
247 uint32_t start[HITEC_RX_MAX];
249 uint16_t framing;
250 uint8_t n;
251 uint8_t max_rx;
252 uint8_t phase;
253 uint8_t end;
255
266 uint32_t window_us, uint8_t max_rx);
267
284 const uint32_t *words, uint32_t n_words);
285
293
294/* --- the run -------------------------------------------------------------- */
295
312
320
322typedef struct {
324 uint32_t words;
325 uint32_t window_ns;
326 uint8_t phase;
327 uint8_t aborted;
328 uint8_t lost;
330
343 const hitec_pre_timing_t *t,
344 const hitec_xfer_t *x);
345
353void hitec_pre_tx_xfer(const hitec_xfer_t *x, hitec_xfer_t *out);
354
363
379 const uint32_t *words, uint32_t n_words, bool all_in);
380
393 const uint32_t *words, uint32_t n_words);
394
405
421 int32_t offset_ns, hitec_capture_t *out);
422
423#ifdef __cplusplus
424}
425#endif
426
427#endif /* HITEC_PRE_H */
uint32_t hitec_pre_window_samples(const hitec_pre_timing_t *t, uint32_t window_us)
Samples a window of window_us waits, rounded to nearest.
Definition hitec_pre.c:116
void hitec_pre_tx_done(hitec_pre_run_t *r)
The request has ended: HITEC_PRE_TX to HITEC_PRE_SAMPLE.
Definition hitec_pre.c:309
uint32_t hitec_pre_cycles_ns(const hitec_pre_timing_t *t, uint64_t cycles)
cycles system clock cycles of t in ns, rounded to nearest.
Definition hitec_pre.c:38
uint32_t hitec_pre_words(const hitec_pre_timing_t *t, uint32_t window_us, uint8_t max_rx)
Sample words a run with a window of window_us and max_rx bytes takes: the window, every byte from its...
Definition hitec_pre.c:124
bool hitec_pre_dec_feed(hitec_pre_dec_t *d, const hitec_pre_timing_t *t, const uint32_t *words, uint32_t n_words)
Decode the samples of the first n_words words of words that it has not seen.
Definition hitec_pre.c:203
void hitec_pre_abort(hitec_pre_run_t *r, const hitec_pre_timing_t *t, const uint32_t *words, uint32_t n_words)
Cut the run in any phase but idle: what n_words words hold is decoded, a byte not whole is dropped,...
Definition hitec_pre.c:336
void hitec_pre_tx_xfer(const hitec_xfer_t *x, hitec_xfer_t *out)
The transaction the line sends for a HITEC_PRE_PLAN_SEND: x with no window and no byte to receive.
Definition hitec_pre.c:298
void hitec_pre_dec_init(hitec_pre_dec_t *d, const hitec_pre_timing_t *t, uint32_t window_us, uint8_t max_rx)
Prepare d for a window of window_us and up to max_rx bytes (1 to HITEC_RX_MAX).
Definition hitec_pre.c:141
bool hitec_pre_step(hitec_pre_run_t *r, const hitec_pre_timing_t *t, const uint32_t *words, uint32_t n_words, bool all_in)
Feed the first n_words sample words.
Definition hitec_pre.c:316
void hitec_pre_dec_close(hitec_pre_dec_t *d)
No more samples come: a decoder that has not ended ends with HITEC_PRE_END_SHORT, dropping a byte who...
Definition hitec_pre.c:257
void hitec_pre_capture(const hitec_pre_run_t *r, const hitec_pre_timing_t *t, int32_t offset_ns, hitec_capture_t *out)
The capture of a done run.
Definition hitec_pre.c:364
unsigned hitec_pre_program(const hitec_pre_timing_t *t, uint16_t *words, unsigned max)
The sampler's program: precharge, release, wait, sample, then the rest of the period,...
Definition hitec_pre.c:84
hitec_pre_plan_t hitec_pre_begin(hitec_pre_run_t *r, const hitec_pre_timing_t *t, const hitec_xfer_t *x)
Plan x on a PRECHARGE line.
Definition hitec_pre.c:266
void hitec_pre_lost(hitec_pre_run_t *r)
Samples went missing (the sampler stalled) or the sampler ran past its time: the capture is marked ov...
Definition hitec_pre.c:354
bool hitec_pre_timing(uint32_t sys_hz, hitec_pre_timing_t *out)
The counts for a system clock of sys_hz.
Definition hitec_pre.c:45
hitec_pre_phase_t
Phase of a run.
Definition hitec_pre.h:314
@ HITEC_PRE_SAMPLE
Definition hitec_pre.h:317
@ HITEC_PRE_DONE
Definition hitec_pre.h:318
@ HITEC_PRE_IDLE
Definition hitec_pre.h:315
@ HITEC_PRE_TX
Definition hitec_pre.h:316
hitec_pre_dec_phase_t
Phase of the decoder.
Definition hitec_pre.h:227
@ HITEC_PRE_WAIT_START
Definition hitec_pre.h:229
@ HITEC_PRE_IN_BYTE
Definition hitec_pre.h:230
@ HITEC_PRE_DEC_DONE
Definition hitec_pre.h:231
@ HITEC_PRE_WAIT_REST
Definition hitec_pre.h:228
#define HITEC_PRE_FRAME_BITS
Bits of a frame the decoder samples: start, 8 data, stop.
Definition hitec_pre.h:123
hitec_pre_end_t
Why the decoder ended.
Definition hitec_pre.h:235
@ HITEC_PRE_END_SHORT
Definition hitec_pre.h:239
@ HITEC_PRE_END_FULL
Definition hitec_pre.h:237
@ HITEC_PRE_END_NONE
Definition hitec_pre.h:236
@ HITEC_PRE_END_WINDOW
Definition hitec_pre.h:238
static unsigned hitec_pre_sample(const uint32_t *words, uint32_t k)
The level of sample k of words: 1 high.
Definition hitec_pre.h:219
hitec_pre_plan_t
What a transaction asks of the sampler, hitec_pre_begin().
Definition hitec_pre.h:297
@ HITEC_PRE_PLAN_REFUSE
Not one the sampler runs: a LISTEN that answers, a window above HITEC_PRE_WINDOW_MAX_US,...
Definition hitec_pre.h:310
@ HITEC_PRE_PLAN_LISTEN
A LISTEN: the sampler from the start.
Definition hitec_pre.h:305
@ HITEC_PRE_PLAN_SEND
A SEND with a window: the request on the line, then the sampler.
Definition hitec_pre.h:303
@ HITEC_PRE_PLAN_LINE
No receive window, or a LEVEL: the line runs it as in PULL-UP.
Definition hitec_pre.h:299
hitec_rx_mode_t
How a D series line receives.
Definition hitec_pre.h:74
@ HITEC_RX_PULL_UP
Released for the answer; a pull-up on the board makes the high level (2.2kOhm to the servo supply on ...
Definition hitec_pre.h:77
@ HITEC_RX_PRECHARGE
No pull-up: precharge and sample, this module.
Definition hitec_pre.h:79
Hitec servo programming protocols: frames, transactions, the reply decoders and the driver interface.
#define HITEC_RX_MAX
Definition hitec_wire.h:204
#define k
Short name for kst_panel_k inside the overlay's seven files.
Definition kst_panel_int.h:238
What the receiver took, in the order the bytes came.
Definition hitec_wire.h:398
Decoder state for one receive.
Definition hitec_pre.h:243
uint8_t n
Definition hitec_pre.h:250
uint32_t window
Definition hitec_pre.h:244
uint8_t end
Definition hitec_pre.h:253
uint8_t phase
Definition hitec_pre.h:252
uint32_t waited
Definition hitec_pre.h:246
uint32_t start[HITEC_RX_MAX]
Definition hitec_pre.h:247
uint32_t at
Definition hitec_pre.h:245
uint8_t value[HITEC_RX_MAX]
Definition hitec_pre.h:248
uint8_t max_rx
Definition hitec_pre.h:251
uint16_t framing
Definition hitec_pre.h:249
State of one transaction on the sampler.
Definition hitec_pre.h:322
uint8_t phase
Definition hitec_pre.h:326
uint8_t lost
Definition hitec_pre.h:328
hitec_pre_dec_t dec
Definition hitec_pre.h:323
uint32_t window_ns
Definition hitec_pre.h:325
uint32_t words
Definition hitec_pre.h:324
uint8_t aborted
Definition hitec_pre.h:327
The cycle counts a system clock gives.
Definition hitec_pre.h:126
uint32_t charge
Definition hitec_pre.h:129
uint32_t wait
Definition hitec_pre.h:130
uint32_t sys_hz
Definition hitec_pre.h:127
uint32_t spb_q16
Definition hitec_pre.h:131
uint16_t mid[HITEC_PRE_FRAME_BITS]
Samples from a start bit's first high sample to the middle of bit j: 0 the start bit,...
Definition hitec_pre.h:136
uint32_t period
Definition hitec_pre.h:128
One transaction.
Definition hitec_wire.h:233