rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_pio.h
Go to the documentation of this file.
1
52#ifndef KST_PIO_H
53#define KST_PIO_H
54
55#include <stdbool.h>
56#include <stdint.h>
57
58#include "kst_wire.h"
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
65#define KST_PIO_TICK_CYCLES 4u
67#define KST_PIO_BIT_OVERHEAD 4u
72#define KST_PIO_LOW_OVERHEAD 2u
74#define KST_PIO_SAMPLE_LEAD 3u
76#define KST_PIO_SYNC_CYCLES 2u
77
79#define KST_PIO_QUIET_NS 165000u
80
82#define KST_PIO_MAX_TICK_NS 500u
83
85#define KST_PIO_MAX_ERROR_PPM 2000u
86
91#define KST_PIO_TX_WORDS 9u
96#define KST_PIO_RX_WORDS (KST_CAP_MAX_EDGES + 2u)
97
99typedef struct {
100 uint32_t sys_hz;
101 uint32_t half_cycles;
102 uint32_t release_cycles;
103 uint32_t quiet_ticks;
105
107typedef struct {
108 uint32_t window_ns;
109 uint32_t window_ticks;
110 uint32_t lead_ns;
112
125bool kst_pio_clock(uint32_t sys_hz, kst_pio_clock_t *out);
126
133uint32_t kst_pio_half_cell_ns(const kst_pio_clock_t *clock);
134
141uint32_t kst_pio_tick_ns(const kst_pio_clock_t *clock);
142
158unsigned kst_pio_tx(const kst_pio_clock_t *clock, const kst_frame_t *frame,
159 uint32_t window_ns, uint32_t *words, kst_pio_run_t *run);
160
177void kst_pio_capture(const kst_pio_clock_t *clock, const kst_pio_run_t *run,
178 const uint32_t *stamps, unsigned n, bool lost,
179 kst_capture_t *out);
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* KST_PIO_H */
unsigned kst_pio_tx(const kst_pio_clock_t *clock, const kst_frame_t *frame, uint32_t window_ns, uint32_t *words, kst_pio_run_t *run)
The word stream for frame and a capture until window_ns after its last edge.
Definition kst_pio.c:75
uint32_t kst_pio_tick_ns(const kst_pio_clock_t *clock)
One tick of clock in ns, rounded up.
Definition kst_pio.c:60
void kst_pio_capture(const kst_pio_clock_t *clock, const kst_pio_run_t *run, const uint32_t *stamps, unsigned n, bool lost, kst_capture_t *out)
The capture from the n stamps of a transaction, in the order the program gave them.
Definition kst_pio.c:128
uint32_t kst_pio_half_cell_ns(const kst_pio_clock_t *clock)
The transmit half-cell of clock in ns, rounded to nearest.
Definition kst_pio.c:55
bool kst_pio_clock(uint32_t sys_hz, kst_pio_clock_t *out)
The counts for a system clock of sys_hz.
Definition kst_pio.c:25
KST servo programming protocol: frames and the reply decoder.
The reply window as the driver saw it.
Definition kst_wire.h:230
A master frame as line levels, one per half-cell.
Definition kst_wire.h:166
The counts a system clock gives.
Definition kst_pio.h:99
uint32_t half_cycles
Definition kst_pio.h:101
uint32_t release_cycles
Definition kst_pio.h:102
uint32_t quiet_ticks
Definition kst_pio.h:103
One transaction, as kst_pio_tx() laid it out.
Definition kst_pio.h:107
uint32_t window_ticks
Definition kst_pio.h:109
uint32_t window_ns
Definition kst_pio.h:108
uint32_t lead_ns
Definition kst_pio.h:110