esp-sdr-zephyr
Raw I/Q receive and transmit on the ESP32-S3/C6 Wi-Fi radio, for Zephyr
Loading...
Searching...
No Matches
esp_sdr_paced.h File Reference

ESP-SDR CPU-paced streaming (ESP32-C6, ESP32-C5; transmit only on the ESP32-S31, which has no IQ estimator): continuous receive and transmit, one sample at a time from the caller's loop. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  esp_sdr_paced_stats

Macros

#define ESP_SDR_PACED_INPUT_HZ   80000000U

Typedefs

typedef bool(* esp_sdr_tx_paced_input_t) (void *user, int16_t *i, int16_t *q)

Functions

int esp_sdr_rx_paced_start (uint32_t rate_hz)
 Start receiving at rate_hz.
bool esp_sdr_rx_paced_poll (int32_t *i, int32_t *q)
 Produce the next receive sample if it is due.
uint32_t esp_sdr_rx_paced_fill_iq8 (int8_t *out, size_t n, unsigned int shift)
 Produce the next n receive samples as they fall due, as 8-bit I, Q pairs. The tight form of esp_sdr_rx_paced_poll() for MS/s rates: blocks until the last one.
void esp_sdr_rx_paced_stop (void)
 Stop receiving and release the radio; no-op when stopped.
int esp_sdr_tx_paced_start (uint32_t rate_hz, unsigned int interp, unsigned int power, esp_sdr_tx_paced_input_t input, void *user)
 Turn the transmit chain on at the current frequency and start playing input at rate_hz.
bool esp_sdr_tx_paced_poll (void)
 Write the next DAC value if it is due, then compute the one after.
void esp_sdr_tx_paced_stop (void)
 Turn the transmit chain off and release the radio; no-op when stopped.
unsigned int esp_sdr_tx_paced_power_max (void)
 Highest power step: 2 dB per step of the vendor tone's backoff (none on the C5, S31).
static uint32_t esp_sdr_paced_cycles (void)
 The CPU cycle counter the paced streams run on (inlined into IRAM loops).
static void esp_sdr_paced_cycles_enable (void)
 Make esp_sdr_paced_cycles() count CPU cycles (a stream's start does it too).
uint32_t esp_sdr_paced_deadline (void)
 When the running stream's next sample is due, on esp_sdr_paced_cycles().
void esp_sdr_paced_sync (void)
 Restart the running stream's clock: the next sample is due one period from now. Call once interrupts are locked, after the start.
void esp_sdr_paced_get_stats (struct esp_sdr_paced_stats *stats)
 Statistics of the running or last stream.

Detailed Description

ESP-SDR CPU-paced streaming (ESP32-C6, ESP32-C5; transmit only on the ESP32-S31, which has no IQ estimator): continuous receive and transmit, one sample at a time from the caller's loop.

The C6 has no dump path that runs gapless at a low rate and no DAC buffer the CPU can refill while it plays, so the CPU paces both directions:

  • Receive differences the running sums of the modem's IQ estimator, which adds up the 80 MHz baseband samples in hardware: each output is the sum of the 80 MHz / rate samples since the previous one (a boxcar decimator). Gapless up to about 4.7 MS/s with nothing else in the loop.
  • Transmit writes the TX DC value register, which drives the DAC directly once the vendor tone path has turned the transmit chain on, at the rate times an interpolation factor, through an 8-tap-per-phase FIR.

Between start and stop the caller polls in a tight loop with interrupts locked and serves its own I/O between polls. A poll that comes late moves that sample's instant (esp_sdr_rx_paced_fill_iq8() spreads a poll whole periods late over the samples it missed instead); the stats count it. One direction at a time.

On the ESP32-S31 the poll runs from IRAM and costs about 220 CPU cycles a write (a TX DC store alone 48): rate times factor up to 1 MHz, such as 250 kS/s x4 or 125 kS/s x8, keeps every write on time. Keep the input callback and the polling loop in IRAM with their data in internal RAM; code fetched through the flash cache stalls a write now and then by up to a few microseconds.