|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The KST programming session on a programming port: the way into and out of PWM. More...
Macros | |
| #define | NO_REG 0xFFu |
| The page carries the session's result as the core numbers it. | |
| #define | FRAMES_MAX 0x0FFFu |
| The frame count stops at this value (12 bits). | |
Enumerations | |
| enum | { SUP_NONE = 0 , SUP_OFF , SUP_ON , SUP_TIMED } |
| Where a wait for the supply is. | |
| enum | { LEAVE_NONE = 0 , LEAVE_ASKED , LEAVE_FORCED } |
| Why PROGRAMMING is left once the session has ended. | |
Functions | |
| static bool | drv_start (void *ctx, const kst_frame_t *frame, uint32_t window_ns) |
| A frame starts only on a channel in PROGRAMMING and while the bench is safe. The first one marks the servo as possibly in programming mode. | |
| static bool | drv_poll (void *ctx, kst_capture_t *out) |
| The session's poll, through the port's wire driver. | |
| static uint32_t | drv_now (void *ctx) |
| The session's clock, through the port's wire driver. | |
| static void | session_fresh (kst_port_t *p) |
| Start the session on a fresh model whose driver frames through this port. | |
| static void | image_to_regs (const kst_image_t *img, uint16_t *regs) |
| Pack an image into LINK_KS_IMAGE_REGS registers, low byte first. | |
| static void | image_from_regs (const uint16_t *regs, kst_image_t *img) |
| Unpack LINK_KS_IMAGE_REGS registers into an image, low byte first. | |
| static uint8_t | lowest_bit (uint32_t mask) |
| The index of the lowest set bit of a register mask. | |
| static bool | supply_view (const kst_port_t *p, supply_port_view_t *v) |
| What the supply says; false with no PD mini answering. | |
| static void | supply_off (kst_port_t *p) |
| Ask the supply off, when the build has one to switch. | |
| static uint16_t | supply_runs_at (const supply_port_view_t *v, uint16_t mv) |
The voltage a session asked for at mv runs at: an output that is on is lowered to it or left, never raised. | |
| static bool | supply_range_ok (const supply_port_view_t *v, uint16_t mv, uint16_t ma) |
Whether the PD mini gives a servo in programming mode mv and ma. | |
| static void | op_begin (kst_port_t *p, link_kst_op_t op) |
| Start an operation: record its code and set the result to BUSY. | |
| static void | op_end (kst_port_t *p, kst_ses_t result) |
| End the running operation with its result. | |
| static void | session_done (kst_port_t *p, kst_ses_t r) |
The session's operation ended with r. | |
| static void | session_started (kst_port_t *p, kst_ses_t r) |
| What a session function returned when asked to start. | |
| static void | go_pwm (kst_port_t *p) |
| Back to PWM: the driver closed, the pin the generator's. | |
| static void | back_out (kst_port_t *p, uint8_t result) |
| The way in ended before a frame went out: the supply as it was found. | |
| static void | cut (kst_port_t *p) |
| End the running operation. | |
| static void | on_stop (kst_port_t *p) |
| Apply a stop to the port, by its state. | |
| static link_kst_refusal_t | enter_from_pwm (kst_port_t *p, uint8_t port, uint32_t now_ms) |
| Start ENTER from PWM: check the port and its pin, then take the supply and the pin. | |
| static void | rail_off (kst_port_t *p, const supply_port_view_t *v, bool again, uint32_t now_ms) |
The supply switched off for RAIL_OFF; again: and on after it, at what it was set to. | |
| static link_kst_refusal_t | reboot (kst_port_t *p, uint8_t port, uint32_t now_ms) |
| Start REBOOT: a supply cycle, from PWM or from PROGRAMMING. | |
| static link_kst_refusal_t | plan_refusal (uint8_t plan_result) |
| Why the planner took a request without a search. | |
| static link_kst_refusal_t | start_plan (kst_port_t *p, link_kst_op_t op, bool confirm) |
| A write to the servo. | |
| static bool | writes_servo (link_kst_op_t op) |
| Whether an operation writes to the servo. | |
| static link_kst_refusal_t | dispatch (kst_port_t *p, link_kst_op_t op, uint8_t port, const uint16_t *in, uint32_t now_ms) |
| Route one command to its operation, judged against the port's state. | |
| static uint8_t | command (kst_port_t *p, const uint16_t *in, uint32_t now_ms) |
| Handle the command frame, registers 0 to 3. | |
| uint8_t | kst_port_write (kst_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. | |
| static uint16_t | clamp16 (uint32_t v) |
| Hold a 32-bit count to 16 bits. | |
| static uint16_t | state_reg (const kst_port_t *p) |
| The STATE register: the state, the port and the flags. | |
| static bool | plans (const kst_port_t *p) |
| The operation the page names is a write whose plan the session still builds: no frame of it has gone out. | |
| void | kst_port_read (const kst_port_t *p, uint8_t off, uint8_t n, uint16_t *out) |
| A read of the page, LINK_KS_*. | |
| static void | start_session (kst_port_t *p) |
| The servo is asked to enter programming mode. | |
| static void | low_begin (kst_port_t *p) |
| The pin is the driver's: what the supply has to do before the servo is spoken to. | |
| static void | step_low (kst_port_t *p, uint32_t now_ms) |
| The pass of a LOW port: hold the line low for KST_PORT_LOW_MS, then settle the supply. | |
| static void | step_programming (kst_port_t *p, uint32_t now_ms) |
| The pass of a PROGRAMMING port: step the session, or end the mode when the supply went off. | |
| static void | step_leaving (kst_port_t *p, uint32_t now_ms) |
| A LEAVE waits with the line low. | |
| static void | step_rail_off (kst_port_t *p, uint32_t now_ms) |
| The pass of RAIL_OFF: wait for the supply to read off and its off time, then the switch-on. | |
| static void | step_rail_wait (kst_port_t *p, uint32_t now_ms) |
| The pass of RAIL_WAIT: wait for the supply to read on, then the rail wait. | |
| void | kst_port_step (kst_port_t *p, bool safe, bool stop, uint32_t now_ms) |
| One pass. | |
| bool | kst_port_init (kst_port_t *p, const kst_port_hw_t *hw) |
| Prepare a port in LINK_KST_PWM. | |
| link_kst_state_t | kst_port_state (const kst_port_t *p) |
| Where the port is. | |
| uint8_t | kst_port_quiet_mask (const kst_port_t *p) |
| Bit n: programming port n renders no PWM pulse. | |
| bool | kst_port_frame_out (const kst_port_t *p) |
| An operation of the session runs: a frame may be on the wire. | |
| void | kst_port_bench_armed (kst_port_t *p, bool armed) |
| Whether the bank is armed. | |
| void | kst_port_other_mask (kst_port_t *p, uint8_t mask) |
| Bit n: the HITEC page holds programming port n (hitec_port_quiet_mask()). | |
| uint8_t | kst_port_pin_mask (const kst_port_t *p) |
| Bit n: programming port n's pin is the wire driver's, not the PWM generator's. | |
The KST programming session on a programming port: the way into and out of PWM.
SPDX-License-Identifier: MIT
| #define NO_REG 0xFFu |
The page carries the session's result as the core numbers it.
No register: the value of fail_reg when none failed.
|
static |
The way in ended before a frame went out: the supply as it was found.
| p | The port. |
| result | The result to report, a KST_SES_* value. |
|
static |
Hold a 32-bit count to 16 bits.
| v | The count. |
|
static |
Handle the command frame, registers 0 to 3.
| p | The port. |
| in | The command frame's four registers. |
| now_ms | Current time in milliseconds. |
|
static |
End the running operation.
A frame on the wire is finished first; the session ends at one of the next steps.
| p | The port. |
|
static |
Route one command to its operation, judged against the port's state.
| p | The port. |
| op | The operation. |
| port | Programming port index. |
| in | The command frame's registers. |
| now_ms | Current time in milliseconds. |
|
static |
The session's clock, through the port's wire driver.
| ctx | The port, as the driver's context. |
|
static |
The session's poll, through the port's wire driver.
| ctx | The port, as the driver's context. |
| out | Receives the capture. |
|
static |
A frame starts only on a channel in PROGRAMMING and while the bench is safe. The first one marks the servo as possibly in programming mode.
| ctx | The port, as the driver's context. |
| frame | The frame to send. |
| window_ns | The listen window in nanoseconds. |
|
static |
Start ENTER from PWM: check the port and its pin, then take the supply and the pin.
| p | The port. |
| port | Programming port index. |
| now_ms | Current time in milliseconds. |
|
static |
Back to PWM: the driver closed, the pin the generator's.
| p | The port. |
|
static |
Unpack LINK_KS_IMAGE_REGS registers into an image, low byte first.
| regs | The registers. |
| img | Receives the image. |
|
static |
Pack an image into LINK_KS_IMAGE_REGS registers, low byte first.
| img | The image. |
| regs | Receives the registers. |
| void kst_port_bench_armed | ( | kst_port_t * | p, |
| bool | armed ) |
Whether the bank is armed.
An ENTER is refused with LINK_KST_REF_BUSY while it is; the caller arms no output while kst_port_quiet_mask() is not 0.
| p | The port, or NULL; a NULL p is ignored. |
| armed | true when the bank is armed. |
| bool kst_port_frame_out | ( | const kst_port_t * | p | ) |
An operation of the session runs: a frame may be on the wire.
False from the pass in which an operation, or its cut, has ended.
| p | The port, or NULL. |
| bool kst_port_init | ( | kst_port_t * | p, |
| const kst_port_hw_t * | hw ) |
Prepare a port in LINK_KST_PWM.
False when hw names no port, lacks a function other than the supply's two, or has one of those two.
| p | The port to prepare. |
| hw | The hardware hooks, copied into the port. |
| void kst_port_other_mask | ( | kst_port_t * | p, |
| uint8_t | mask ) |
Bit n: the HITEC page holds programming port n (hitec_port_quiet_mask()).
An ENTER on it, and a REBOOT taken in PWM, are refused with LINK_KST_REF_BUSY.
| p | The port, or NULL; a NULL p is ignored. |
| mask | Bit n: the HITEC page holds programming port n. |
| uint8_t kst_port_pin_mask | ( | const kst_port_t * | p | ) |
Bit n: programming port n's pin is the wire driver's, not the PWM generator's.
The held port from LINK_KST_LOW until it is back in LINK_KST_PWM; never for a REBOOT taken in PWM.
| p | The port, or NULL. |
| uint8_t kst_port_quiet_mask | ( | const kst_port_t * | p | ) |
Bit n: programming port n renders no PWM pulse.
The held port in every state but LINK_KST_PWM.
| p | The port, or NULL. |
| void kst_port_read | ( | const kst_port_t * | p, |
| uint8_t | off, | ||
| uint8_t | n, | ||
| uint16_t * | out ) |
A read of the page, LINK_KS_*.
| p | The port. |
| off | First register of the window. |
| n | Number of registers to read. |
| out | Receives n register values; left unchanged for a NULL p or out, or a window past LINK_KS_COUNT. |
| link_kst_state_t kst_port_state | ( | const kst_port_t * | p | ) |
Where the port is.
| p | The port, or NULL. |
| void kst_port_step | ( | kst_port_t * | p, |
| bool | safe, | ||
| bool | stop, | ||
| uint32_t | now_ms ) |
One pass.
safe: the heartbeat is trusted and the link is not silent. stop: the bank was switched off or disarmed since the last pass. Steps the session and the port's timers; a pass every 1ms or faster keeps the session's pacing. A pass does one slice of planning at most and never a whole search.
| p | The port. |
| safe | true when the heartbeat is trusted and the link is not silent. |
| stop | true when the bank was switched off or disarmed since the last pass. |
| now_ms | Current time in milliseconds. |
| uint8_t kst_port_write | ( | kst_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.
A window that starts in registers 0 to 3 is a command and has to be exactly those 4. Registers 4 to 28 are taken in any windows; 29 and up are LINK_NACK_READ_ONLY.
| p | The port. |
| off | First register of the window. |
| n | Number of registers in the window. |
| in | The n register values to write. |
| now_ms | Current time in milliseconds. |
|
static |
The pin is the driver's: what the supply has to do before the servo is spoken to.
The voltage of an output that is on is lowered or left, never raised.
| p | The port. |
|
static |
The index of the lowest set bit of a register mask.
| mask | One bit per register. |
|
static |
Apply a stop to the port, by its state.
| p | The port. |
|
static |
Start an operation: record its code and set the result to BUSY.
| p | The port. |
| op | The operation. |
|
static |
End the running operation with its result.
| p | The port. |
| result | The session result. |
|
static |
Why the planner took a request without a search.
| plan_result | The planner's result, a kst_plan_result_t value. |
|
static |
The operation the page names is a write whose plan the session still builds: no frame of it has gone out.
| p | The port. |
|
static |
The supply switched off for RAIL_OFF; again: and on after it, at what it was set to.
| p | The port. |
| v | The supply's view. |
| again | true to switch the supply on again afterwards. |
| now_ms | Current time in milliseconds. |
|
static |
Start REBOOT: a supply cycle, from PWM or from PROGRAMMING.
| p | The port. |
| port | Programming port index. |
| now_ms | Current time in milliseconds. |
|
static |
The session's operation ended with r.
| p | The port. |
| r | The session's result. |
|
static |
Start the session on a fresh model whose driver frames through this port.
| p | The port. |
|
static |
What a session function returned when asked to start.
| p | The port. |
| r | What the session function returned. |
|
static |
A write to the servo.
The session plans it, from the image it read to what is staged, one slice of the planner in each pass, and runs its own plan. This call checks the request and prepares the job: no search runs in the command's frame.
| p | The port. |
| op | The write or restore operation. |
| confirm | true to confirm a restore. |
|
static |
The servo is asked to enter programming mode.
| p | The port. |
|
static |
The STATE register: the state, the port and the flags.
| p | The port. |
|
static |
A LEAVE waits with the line low.
The supply is read for one thing: a servo found without power ends as it does in PROGRAMMING.
| p | The port. |
| now_ms | Current time in milliseconds. |
|
static |
The pass of a LOW port: hold the line low for KST_PORT_LOW_MS, then settle the supply.
| p | The port. |
| now_ms | Current time in milliseconds. |
|
static |
The pass of a PROGRAMMING port: step the session, or end the mode when the supply went off.
| p | The port. |
| now_ms | Current time in milliseconds. |
|
static |
The pass of RAIL_OFF: wait for the supply to read off and its off time, then the switch-on.
| p | The port. |
| now_ms | Current time in milliseconds. |
|
static |
The pass of RAIL_WAIT: wait for the supply to read on, then the rail wait.
| p | The port. |
| now_ms | Current time in milliseconds. |
|
static |
Ask the supply off, when the build has one to switch.
| p | The port. |
|
static |
Whether the PD mini gives a servo in programming mode mv and ma.
The cap under the input holds for the voltage the output runs at.
| v | The supply's view. |
| mv | The voltage in mV. |
| ma | The current limit in mA. |
|
static |
The voltage a session asked for at mv runs at: an output that is on is lowered to it or left, never raised.
| v | The supply's view. |
| mv | The requested voltage in mV. |
|
static |
What the supply says; false with no PD mini answering.
| p | The port. |
| v | Receives the supply's view. |
|
static |
Whether an operation writes to the servo.
| op | The operation. |