rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
hitec_pio.h
Go to the documentation of this file.
1
63#ifndef HITEC_PIO_H
64#define HITEC_PIO_H
65
66#include <stdbool.h>
67#include <stdint.h>
68
69#include "hitec_wire.h"
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
76#define HITEC_PIO_CYCLES_PER_BIT 16u
78#define HITEC_PIO_TICK_CYCLES 2u
83#define HITEC_PIO_MIN_DIV 4u
85#define HITEC_PIO_MAX_DIV 65535u
89#define HITEC_PIO_SYNC_SYS_CYCLES 2u
96#define HITEC_PIO_MAX_ERROR_PPM 500u
97
99#define HITEC_PIO_LEAD_CYCLES 8u
104#define HITEC_PIO_BYTE_CYCLES 157u
109#define HITEC_PIO_ANSWER_CYCLES 165u
114#define HITEC_PIO_ANSWER_CYCLES_TO_EDGE 160u
116#define HITEC_PIO_ANSWER_BITS 10u
121#define HITEC_PIO_ANSWER_DROP_BITS 6u
123#define HITEC_PIO_DRAIN_CYCLES 2u
124
126#define HITEC_PIO_PROGRAM_WORDS 30u
135#define HITEC_PIO_IDLE_PC 1u
136#define HITEC_PIO_BIT_PC 8u
137#define HITEC_PIO_RELEASE_PC 11u
138#define HITEC_PIO_ASK_PC 22u
139#define HITEC_PIO_ANSWER_PC 24u
141#define HITEC_PIO_DRAIN_PC 28u
142
146#define HITEC_PIO_STAMP_BITS 23u
148#define HITEC_PIO_MAX_WINDOW_TICKS ((1u << HITEC_PIO_STAMP_BITS) - 1u)
150#define HITEC_PIO_MAX_LEAD ((1u << 30) - 1u)
151
157#define HITEC_PIO_TX_WORDS 11u
158
160typedef struct {
161 uint32_t sys_hz;
162 uint32_t div256;
164 uint32_t err_ppm;
165 uint8_t family;
167
169typedef struct {
170 uint32_t window_ns;
171 uint32_t window_ticks;
175 uint32_t lead_ns;
180 uint32_t span_us;
181 uint8_t family;
182 uint8_t max_rx;
183 uint8_t answer;
185
200bool hitec_pio_clock(uint32_t sys_hz, uint8_t family, hitec_pio_clock_t *out);
201
208uint32_t hitec_pio_bit_ns(const hitec_pio_clock_t *clock);
209
217uint32_t hitec_pio_cycles_ns(const hitec_pio_clock_t *clock, uint64_t cycles);
218
234unsigned hitec_pio_tx(const hitec_pio_clock_t *clock, uint8_t drive,
235 const hitec_xfer_t *xfer, uint32_t *words,
236 hitec_pio_run_t *run);
237
253bool hitec_pio_answer_due(const hitec_pio_run_t *run, unsigned n,
254 unsigned pc);
255
277void hitec_pio_capture(const hitec_pio_clock_t *clock,
278 const hitec_pio_run_t *run, const uint32_t *stamps,
279 unsigned n, bool full, bool lost, bool aborted,
280 bool cut, hitec_capture_t *out);
281
282#ifdef __cplusplus
283}
284#endif
285
286#endif /* HITEC_PIO_H */
void hitec_pio_capture(const hitec_pio_clock_t *clock, const hitec_pio_run_t *run, const uint32_t *stamps, unsigned n, bool full, bool lost, bool aborted, bool cut, hitec_capture_t *out)
The capture from the n words the program pushed, in their order.
Definition hitec_pio.c:299
unsigned hitec_pio_tx(const hitec_pio_clock_t *clock, uint8_t drive, const hitec_xfer_t *xfer, uint32_t *words, hitec_pio_run_t *run)
The word stream for xfer on a line with drive (hitec_drive_t).
Definition hitec_pio.c:178
bool hitec_pio_clock(uint32_t sys_hz, uint8_t family, hitec_pio_clock_t *out)
The divider for family at a system clock of sys_hz.
Definition hitec_pio.c:41
bool hitec_pio_answer_due(const hitec_pio_run_t *run, unsigned n, unsigned pc)
Whether the answer of run is still to go out with n bytes received and the state machine at pc,...
Definition hitec_pio.c:288
uint32_t hitec_pio_bit_ns(const hitec_pio_clock_t *clock)
The bit time clock gives, in ns, rounded to nearest.
Definition hitec_pio.c:75
uint32_t hitec_pio_cycles_ns(const hitec_pio_clock_t *clock, uint64_t cycles)
cycles state machine cycles of clock, in ns, rounded down.
Definition hitec_pio.c:83
Hitec servo programming protocols: frames, transactions, the reply decoders and the driver interface.
What the receiver took, in the order the bytes came.
Definition hitec_wire.h:398
The divider and the counts a system clock gives for one family.
Definition hitec_pio.h:160
uint32_t div256
Definition hitec_pio.h:162
uint32_t err_ppm
Definition hitec_pio.h:164
uint8_t family
Definition hitec_pio.h:165
uint32_t sys_hz
Definition hitec_pio.h:161
One transaction, as hitec_pio_tx() laid it out.
Definition hitec_pio.h:169
uint32_t window_ns
Definition hitec_pio.h:170
uint8_t family
Definition hitec_pio.h:181
uint32_t window_ticks
Definition hitec_pio.h:171
uint32_t lead_ns
From the lead's first change of direction to the release, in ns.
Definition hitec_pio.h:175
uint8_t max_rx
Definition hitec_pio.h:182
uint8_t answer
Definition hitec_pio.h:183
uint32_t span_us
An upper bound of the transaction's time from the hand-over of the stream: lead, bits,...
Definition hitec_pio.h:180
One transaction.
Definition hitec_wire.h:233