|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The phase tap's capture. More...
#include "tone_cap.h"#include <string.h>#include "hardware/clocks.h"#include "hardware/dma.h"#include "hardware/gpio.h"#include "hardware/pio.h"#include "pico/stdlib.h"#include "tone_cap.pio.h"#include "tone_svc.h"Macros | |
| #define | RING_BYTES (TONE_RING_WORDS * 4u) |
| 16kB, on a 16kB boundary: the DMA wraps its write address on it. | |
| #define | RING_BITS 14u |
Functions | |
| void | tone_cap_rest (uint8_t pin) |
| The pin as an input with its pull-down on, driven by nothing: a tap that is off. | |
| bool | tone_cap_start (uint8_t pin) |
Claim a state machine and a DMA channel, load the program, start the capture on pin. | |
| bool | tone_cap_pause (void) |
| Mark the capture not running, so the next order tells core 1 to read nothing from it; the state machine and the channel stay, and tone_cap_wr() and tone_cap_stalled() still read them for a pass already under way. | |
| void | tone_cap_resume (void) |
| Mark a paused capture running again, when core 1 did not acknowledge the pause and nothing was taken down. | |
| void | tone_cap_stop (void) |
| Stop the capture and give back what it claimed; the pin is left an input with its pull-down on. | |
| bool | tone_cap_running (void) |
| Whether the capture runs. | |
| uint64_t | tone_cap_start_us (void) |
| The microsecond timer when the counter began. | |
| const uint32_t * | tone_cap_ring (void) |
| The ring. | |
| uint32_t | tone_cap_wr (void) |
| The slot the DMA writes next; 0 when the capture does not run. | |
| bool | tone_cap_stalled (void) |
| Whether the state machine dropped a word (its FIFO was full) since the last call; clears the flag. | |
Variables | |
| static uint32_t | s_ring [TONE_RING_WORDS] |
| static volatile bool | s_running |
| Written by core 0 while the capture is stopped or starting, read by core 1: running is set last and cleared first. | |
| static PIO | s_pio |
| static uint | s_sm |
| static uint | s_offset |
| static int | s_dma = -1 |
| static volatile uint32_t | s_wr_base |
| static uint8_t | s_pin |
| static uint64_t | s_start_us |
| bool tone_cap_pause | ( | void | ) |
Mark the capture not running, so the next order tells core 1 to read nothing from it; the state machine and the channel stay, and tone_cap_wr() and tone_cap_stalled() still read them for a pass already under way.
True when it was running. The first step of taking the capture down: tell core 1, wait for it to acknowledge, then tone_cap_stop().
| void tone_cap_rest | ( | uint8_t | pin | ) |
The pin as an input with its pull-down on, driven by nothing: a tap that is off.
Not while the capture runs.
| pin | GPIO number of the phase input. |
| const uint32_t * tone_cap_ring | ( | void | ) |
The ring.
| bool tone_cap_running | ( | void | ) |
Whether the capture runs.
| bool tone_cap_stalled | ( | void | ) |
Whether the state machine dropped a word (its FIFO was full) since the last call; clears the flag.
Called from core 1 only.
| bool tone_cap_start | ( | uint8_t | pin | ) |
Claim a state machine and a DMA channel, load the program, start the capture on pin.
False, with nothing claimed, when no PIO block that reaches the pin has room for the program and a state machine, no DMA channel is free, or the system clock is not 150MHz.
| pin | GPIO number of the phase input. |
| uint64_t tone_cap_start_us | ( | void | ) |
The microsecond timer when the counter began.
| void tone_cap_stop | ( | void | ) |
Stop the capture and give back what it claimed; the pin is left an input with its pull-down on.
Safe when it is not running. Core 1 is not reading the ring or the channel at that moment (tone_cap_pause()).
| uint32_t tone_cap_wr | ( | void | ) |
The slot the DMA writes next; 0 when the capture does not run.
|
static |
the capture pin, GPIO
|
static |
the capture's start, µs
|
static |
the ring's address