rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_line.c File Reference

The KST wire on one RP2350 pin. More...

#include "kst_line.h"
#include <string.h>
#include "hardware/clocks.h"
#include "hardware/dma.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"
#include "hardware/timer.h"
#include "pico.h"
#include "kst_line.pio.h"

Macros

#define IDLE_PC   1u
 The instruction the state machine stalls on between transactions.
#define DMA_COUNT_MASK   0x0FFFFFFFu
 A transfer count's low 28 bits are the count; the rest is the mode.

Functions

static PIO line_pio (const kst_line_t *l)
 Get the PIO block of a line.
static bool line_idle (const kst_line_t *l)
 The state machine waits for a stream: it stalls on the first out, the FIFO is empty and the channel has handed over every word.
static void line_restart (kst_line_t *l)
 Put the state machine at the start of the program with the pad driven low, whatever it was doing.
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.

Detailed Description

The KST wire on one RP2350 pin.

See kst_line.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ kst_line_busy()

bool kst_line_busy ( const kst_line_t * line)

A transaction runs: between a start() that returned true and the poll() that returns true.

Parameters
lineLine object.
Returns
true between a start that returned true and the poll that returns true.

◆ kst_line_close()

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.

Parameters
lineLine object.

◆ kst_line_driver()

kst_driver_t kst_line_driver ( kst_line_t * line)

The driver for a session on line.

Parameters
lineLine object.
Returns
The driver for a session on the line.

◆ kst_line_half_cell_ns()

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.

Parameters
lineLine object.
Returns
The transmit half-cell in ns; 0 on a closed line.

◆ kst_line_init()

void kst_line_init ( kst_line_t * line)

Mark line closed.

Call once, before the first open.

Parameters
lineLine object to mark closed.

◆ kst_line_is_open()

bool kst_line_is_open ( const kst_line_t * line)

Check whether a line is open.

Parameters
lineLine object.
Returns
true when the line is open.

◆ kst_line_now_us()

uint32_t kst_line_now_us ( void * ctx)

Read the microsecond clock; the third of the three driver functions.

Parameters
ctxThe kst_line_t.
Returns
The microsecond clock.

◆ kst_line_open()

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.

Parameters
lineLine object.
pinGPIO number.
Returns
KST_LINE_OK, or the error that refused the open.

◆ kst_line_poll()

bool kst_line_poll ( void * ctx,
kst_capture_t * out )

Poll a transaction; the second of the three driver functions.

Parameters
ctxThe kst_line_t.
outReceives the capture when the transaction has ended.
Returns
true once, when the transaction has ended.

◆ kst_line_start()

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.

Parameters
ctxThe kst_line_t.
frameFrame to send.
window_nsCapture end, in ns after the last edge.
Returns
true when the transaction started.

◆ line_idle()

bool line_idle ( const kst_line_t * l)
static

The state machine waits for a stream: it stalls on the first out, the FIFO is empty and the channel has handed over every word.

A stream is 6 words or more and the FIFO and the shift register hold 5, so this is false from the start of a transfer to the end of the capture.