|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The KST wire on one RP2350 pin: a kst_driver_t made of one PIO (programmable input/output) state machine (kst_line.pio) and two DMA (direct memory access) channels, one for the words of a frame and one for the stamps of its reply window. More...
Go to the source code of this file.
Data Structures | |
| struct | kst_line_t |
| One line. More... | |
Macros | |
| #define | KST_LINE_GRACE_US 1000u |
| The driver ends a transaction whose state machine still runs this long after the end of the window. | |
Enumerations | |
| enum | kst_line_err_t { KST_LINE_OK = 0 , KST_LINE_ERR_ARG , KST_LINE_ERR_CLOCK , KST_LINE_ERR_PIO , KST_LINE_ERR_DMA } |
| Error codes of the KST line driver. More... | |
Functions | |
| void | kst_line_init (kst_line_t *line) |
Mark line closed. | |
| kst_line_err_t | kst_line_open (kst_line_t *line, unsigned pin) |
Claim the resources and take pin: from the return on the pad drives low. | |
| void | kst_line_close (kst_line_t *line) |
| Stop the state machine, give back what the open claimed and leave the pad an input with its pull-down on. | |
| bool | kst_line_is_open (const kst_line_t *line) |
| Check whether a line is open. | |
| bool | kst_line_busy (const kst_line_t *line) |
| A transaction runs: between a start() that returned true and the poll() that returns true. | |
| uint32_t | kst_line_half_cell_ns (const kst_line_t *line) |
| The transmit half-cell the system clock gives, in ns; 0 on a closed line. | |
| bool | kst_line_start (void *ctx, const kst_frame_t *frame, uint32_t window_ns) |
The three functions of kst_driver_t; ctx is the kst_line_t. | |
| bool | kst_line_poll (void *ctx, kst_capture_t *out) |
| Poll a transaction; the second of the three driver functions. | |
| uint32_t | kst_line_now_us (void *ctx) |
| Read the microsecond clock; the third of the three driver functions. | |
| kst_driver_t | kst_line_driver (kst_line_t *line) |
The driver for a session on line. | |
The KST wire on one RP2350 pin: a kst_driver_t made of one PIO (programmable input/output) state machine (kst_line.pio) and two DMA (direct memory access) channels, one for the words of a frame and one for the stamps of its reply window.
Implements the programming protocol of KST and Chaservo servos. KST and Chaservo are names or trademarks of their respective owners; they are used here only to say which servos this module works with (README.md, "Legal notice and disclaimer").
Resources. kst_line_open() claims 1 state machine, 24 words of program space in a PIO block that reaches the pin, and 2 DMA channels; kst_line_close() gives all of them back. A second line on a second pin claims its own and shares the program when its state machine is in the same block. No interrupt and no PIO interrupt flag is used.
Clock. The counts are computed from clock_get_hz(clk_sys) at the open. The open is refused when the half-cell that clock gives is more than 0.2% from 25.40us. At 150MHz the half-cell is 3810 cycles and a stamp resolves 26.7ns. The system clock must not change while the line is open.
Pad. While the line is open and no transaction runs, the pad drives low. In a transaction it is push-pull for the frame, driven low for 50us after the frame's last edge, then an input. It drives low again 165us after the last rising edge of a reply, or at the end of the window when no edge came. The pad's pull-down is on and its pull-up off from the open on, and the close leaves the pad an input with the pull-down on. A pull-down on the board is expected: the internal one is 50 to 80kOhm. A level change before the reply starts the 165us early, so the pad may drive low into a reply; the capture then holds the edges up to that point and the decoder refuses it.
Every function is called from one context. kst_line_poll() ends a transaction whose state machine still runs 1ms after the window: the state machine is restarted with the pad driven low and the capture is marked as overflowed.
Not measured: no frame of this driver has been on a pin.
SPDX-License-Identifier: MIT
| enum kst_line_err_t |
| bool kst_line_busy | ( | const kst_line_t * | line | ) |
A transaction runs: between a start() that returned true and the poll() that returns true.
| line | Line object. |
| void kst_line_close | ( | kst_line_t * | line | ) |
Stop the state machine, give back what the open claimed and leave the pad an input with its pull-down on.
A transaction on the wire is cut. Safe on a closed line.
| line | Line object. |
| kst_driver_t kst_line_driver | ( | kst_line_t * | line | ) |
The driver for a session on line.
| line | Line object. |
| uint32_t kst_line_half_cell_ns | ( | const kst_line_t * | line | ) |
The transmit half-cell the system clock gives, in ns; 0 on a closed line.
| line | Line object. |
| void kst_line_init | ( | kst_line_t * | line | ) |
Mark line closed.
Call once, before the first open.
| line | Line object to mark closed. |
| bool kst_line_is_open | ( | const kst_line_t * | line | ) |
Check whether a line is open.
| line | Line object. |
| uint32_t kst_line_now_us | ( | void * | ctx | ) |
Read the microsecond clock; the third of the three driver functions.
| ctx | The kst_line_t. |
| kst_line_err_t kst_line_open | ( | kst_line_t * | line, |
| unsigned | pin ) |
Claim the resources and take pin: from the return on the pad drives low.
The caller has stopped every other use of the pin. On an error nothing stays claimed and the pin is not touched. An open line is closed first.
| line | Line object. |
| pin | GPIO number. |
| bool kst_line_poll | ( | void * | ctx, |
| kst_capture_t * | out ) |
Poll a transaction; the second of the three driver functions.
| ctx | The kst_line_t. |
| out | Receives the capture when the transaction has ended. |
| bool kst_line_start | ( | void * | ctx, |
| const kst_frame_t * | frame, | ||
| uint32_t | window_ns ) |
The three functions of kst_driver_t; ctx is the kst_line_t.
| ctx | The kst_line_t. |
| frame | Frame to send. |
| window_ns | Capture end, in ns after the last edge. |