rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_session.h
Go to the documentation of this file.
1
44
45#ifndef KST_SESSION_H
46#define KST_SESSION_H
47
48#include <stdbool.h>
49#include <stdint.h>
50
51#include "kst_plan.h"
52#include "kst_reg.h"
53#include "kst_wire.h"
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
60#define KST_ENTRY_LOW_US 100000u
62#define KST_GAP_US 3000u
69#define KST_GAP_AFTER_FAULT_US 20000u
74#define KST_DRIVER_SLACK_US 5000u
75
80#define KST_READ_PASSES 3u
83#define KST_READ_PASSES_MAX 5u
85#define KST_READ_EQUAL 3u
87#define KST_WRITE_ATTEMPTS 3u
88
106typedef struct {
107 void *ctx;
117 bool (*start)(void *ctx, const kst_frame_t *frame, uint32_t window_ns);
126 bool (*poll)(void *ctx, kst_capture_t *out);
127 uint32_t (*now_us)(void *ctx);
129
159
165typedef struct {
166 uint32_t replies;
167 uint32_t faults;
168 uint32_t delay_min_ns;
169 uint32_t delay_max_ns;
170 uint32_t half_min_ns;
171 uint32_t half_max_ns;
173
175typedef struct {
176 /* --- for the caller to read ------------------------------------------- */
184 kst_stats_t stats;
186 uint32_t bad_regs;
187 uint32_t wrote_regs;
194 uint32_t diff_regs;
196 uint8_t result;
197 uint8_t in_mode;
199 uint8_t has_image;
200 uint8_t has_backup;
202 uint8_t locked;
203 uint8_t step_index;
204 uint8_t planning;
205 uint8_t plan_result;
211 uint32_t plan_cap;
214
215 /* --- private ----------------------------------------------------------- */
216 kst_driver_t drv;
222 kst_frame_t frame;
223 uint8_t vals[KST_READ_PASSES_MAX][KST_REG_COUNT];
224 uint32_t vals_ok[KST_READ_PASSES_MAX];
225 uint32_t t_mark;
226 uint32_t t_gap;
227 uint32_t t_start;
228 uint32_t t_limit;
229 int16_t undo;
230 int16_t undo_stop;
231 uint8_t op;
232 uint8_t phase;
233 uint8_t t_state;
234 uint8_t t_expect;
235 uint8_t t_frame;
236 uint8_t t_reg;
237 uint8_t fault;
238 uint8_t abort;
239 uint8_t reading;
240 uint8_t read_result;
241 uint8_t pass;
242 uint8_t passes;
243 uint8_t reg;
244 uint8_t attempt;
245 uint8_t first_ok;
246 uint8_t dirty;
247 uint8_t unseen; /* a write ended with the servo not read */
248 uint8_t cycled; /* the supply was off under the running
249 operation */
250 uint8_t undone;
251 uint8_t confirm;
253
263bool kst_session_init(kst_session_t *s, const kst_driver_t *driver);
264
281
297
331 kst_field_set_t unlocked);
332
357kst_ses_t kst_session_restore(kst_session_t *s, bool confirm_unchecked);
358
369
382
434 bool confirm_unchecked);
435
445
457
467
480
481#ifdef __cplusplus
482}
483#endif
484
485#endif /* KST_SESSION_H */
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
uint64_t kst_rules_t
A set of rules, bit n for rule n.
Definition kst_limits.h:141
KST servo programming protocol: the order of the writes for a change.
KST servo programming protocol: the register image and its fields.
uint64_t kst_field_set_t
A set of fields, bit n for field n.
Definition kst_reg.h:110
kst_ses_t kst_session_write(kst_session_t *s, const kst_plan_t *plan, bool confirm_unchecked)
Run a plan the caller built.
Definition kst_session.c:941
kst_ses_t kst_session_edit(kst_session_t *s, const kst_image_t *target, kst_field_set_t unlocked)
Change the servo from image to target, which is copied before the session's plan is cleared: it may b...
Definition kst_session.c:1017
kst_ses_t kst_session_verify(kst_session_t *s, const kst_image_t *expected)
Read all and compare with expected, which is copied. diff_regs names the registers that differ.
Definition kst_session.c:832
bool kst_session_init(kst_session_t *s, const kst_driver_t *driver)
Prepare a session.
Definition kst_session.c:744
kst_ses_t kst_session_step(kst_session_t *s)
Advance the running operation.
Definition kst_session.c:726
kst_ses_t kst_session_release_pairing(kst_session_t *s)
Write 0x00 to register 0x1D, as kst_plan_release_pairing() plans it.
Definition kst_session.c:1045
kst_ses_t kst_session_enter(kst_session_t *s)
Enter programming mode.
Definition kst_session.c:805
void kst_session_abort(kst_session_t *s)
End the running operation with KST_SES_ERR_ABORTED.
Definition kst_session.c:1067
const kst_plan_t * kst_session_plan(const kst_session_t *s)
The plan of the last kst_session_edit(), kst_session_restore() or kst_session_release_pairing(),...
Definition kst_session.c:1062
kst_ses_t kst_session_restore(kst_session_t *s, bool confirm_unchecked)
Take the servo from image back to the backup, planned as kst_session_edit() plans.
Definition kst_session.c:1032
kst_ses_t
Result of a session operation.
Definition kst_session.h:131
@ KST_SES_ERR_DRIVER
Definition kst_session.h:154
@ KST_SES_ERR_TORN
Definition kst_session.h:151
@ KST_SES_ERR_ARG
Definition kst_session.h:136
@ KST_SES_ERR_ROLLED_BACK
Definition kst_session.h:149
@ KST_SES_ERR_ABORTED
Definition kst_session.h:155
@ KST_SES_ERR_WRITE_FAILED
Definition kst_session.h:147
@ KST_SES_ERR_NO_PLAN
Definition kst_session.h:156
@ KST_SES_ERR_NO_SERVO
Definition kst_session.h:137
@ KST_SES_ERR_LOCKED
Definition kst_session.h:142
@ KST_SES_BUSY
Definition kst_session.h:133
@ KST_SES_ERR_NO_BACKUP
Definition kst_session.h:140
@ KST_SES_ERR_FINGERPRINT
Definition kst_session.h:141
@ KST_SES_ERR_UNINTENDED
Definition kst_session.h:152
@ KST_SES_ERR_NOT_IN_MODE
Definition kst_session.h:138
@ KST_SES_ERR_BUSY
Definition kst_session.h:135
@ KST_SES_ERR_VERIFY
Definition kst_session.h:153
@ KST_SES_ERR_READ
Definition kst_session.h:139
@ KST_SES_ERR_CHANGED
Definition kst_session.h:145
@ KST_SES_OK
Definition kst_session.h:132
@ KST_SES_ERR_UNCONFIRMED
Definition kst_session.h:144
@ KST_SES_ERR_BAD_PLAN
Definition kst_session.h:143
#define KST_READ_PASSES_MAX
Most passes one read takes: the 3 passes and 2 after a disagreement.
Definition kst_session.h:83
kst_ses_t kst_session_read_all(kst_session_t *s)
Read all 32 registers: 3 passes, all 3 equal for every register.
Definition kst_session.c:817
void kst_session_power_cycled(kst_session_t *s)
The servo's supply was off: it has left programming mode, and the servo on the line may be another on...
Definition kst_session.c:1074
KST servo programming protocol: frames and the reply decoder.
#define KST_REG_COUNT
The servo decodes 5 address bits: registers 0x00 to 0x1F.
Definition kst_wire.h:55
The reply window as the driver saw it.
Definition kst_wire.h:230
The driver: the only way to the wire.
Definition kst_session.h:106
bool(*) start(void *ctx, const kst_frame_t *frame, uint32_t window_ns)
Clocks out frame and records the line up to window_ns; false when it cannot start.
Definition kst_session.h:117
uint32_t(*) now_us(void *ctx)
Definition kst_session.h:127
bool(*) poll(void *ctx, kst_capture_t *out)
Reports the window's end: false while the transaction runs; true once, with out filled.
Definition kst_session.h:126
void * ctx
Definition kst_session.h:107
Broken rules and deviating registers of an image.
Definition kst_reg.h:314
A master frame as line levels, one per half-cell.
Definition kst_wire.h:166
The 32 registers, by address.
Definition kst_reg.h:47
The state of one planning job: 176 bytes.
Definition kst_plan.h:160
A plan: the writes that take the servo from start to target.
Definition kst_plan.h:141
A decoded reply window.
Definition kst_wire.h:271
The session with one servo: results and state of its operation.
Definition kst_session.h:175
uint8_t fingerprint_ok
Definition kst_session.h:201
uint8_t has_image
Definition kst_session.h:199
uint8_t locked
Definition kst_session.h:202
uint8_t has_backup
Definition kst_session.h:200
kst_image_t backup
Definition kst_session.h:179
kst_plan_job_t job
Definition kst_session.h:219
kst_rules_t plan_rules
Definition kst_session.h:209
kst_image_t expect
Definition kst_session.h:220
kst_reply_t last_reply
Definition kst_session.h:185
uint8_t plan_result
Definition kst_session.h:205
kst_image_t image
Definition kst_session.h:177
uint8_t confirm
Definition kst_session.h:251
uint8_t t_reg
Definition kst_session.h:236
uint8_t planning
Definition kst_session.h:204
kst_image_t read
Definition kst_session.h:221
uint32_t t_mark
Definition kst_session.h:225
uint8_t step_index
Definition kst_session.h:203
uint32_t wrote_regs
Definition kst_session.h:187
int16_t undo
Definition kst_session.h:229
uint32_t t_gap
Definition kst_session.h:226
uint32_t diff_regs
Definition kst_session.h:194
kst_fingerprint_t fingerprint
Definition kst_session.h:183
uint8_t in_mode
Definition kst_session.h:197
uint32_t bad_regs
Definition kst_session.h:186
uint8_t result
Definition kst_session.h:196
uint32_t plan_cap
Definition kst_session.h:211
kst_plan_t plan
Definition kst_session.h:217
Reply timing of the read frames since kst_session_init().
Definition kst_session.h:165
uint32_t half_max_ns
Definition kst_session.h:171
uint32_t replies
Definition kst_session.h:166
uint32_t delay_min_ns
Definition kst_session.h:168
uint32_t faults
Definition kst_session.h:167
uint32_t delay_max_ns
Definition kst_session.h:169
uint32_t half_min_ns
Definition kst_session.h:170