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

Bring-up, tuning, front end turnaround and housekeeping (esp_sdr.h). More...

Data Structures

struct  esp_sdr_iq16
struct  esp_sdr_stats

Macros

#define ESP_SDR_FREQ_MIN_MHZ   100U
#define ESP_SDR_SAMPLES_MIN   256U
#define ESP_SDR_CPU_HZ   (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000U)
#define ESP_SDR_BANKS   2
#define ESP_SDR_HIGH_RAM   __attribute__((section(".esp_sdr_high")))
#define ESP_SDR_HIGH_BUF_DEFINE(type, name, dims, align)
#define ESP_SDR_PSRAM_BUF_DEFINE(type, name, dims, align)
#define ESP_SDR_HIGH_STACK_DEFINE(name, size)
#define ESP_SDR_FREQ_CORR_MAX_PPB   50000

Enumerations

enum  esp_sdr_rate

Functions

int esp_sdr_init (void)
 Bring the radio up and tune it to the default frequency.
int esp_sdr_set_freq (uint32_t mhz)
 Tune the LO, shared by receive and transmit.
bool esp_sdr_freq_window_checked (void)
uint32_t esp_sdr_get_freq (void)
int32_t esp_sdr_get_freq_offset (void)
int esp_sdr_set_freq_offset (int32_t khz)
 Set an offset in kHz from the whole MHz (esp_sdr_set_freq()) and retune.
int esp_sdr_set_freq_corr_ppb (int32_t ppb)
 Correct every tuning for the crystal's error and retune.
int32_t esp_sdr_get_freq_corr_ppb (void)
int32_t esp_sdr_get_lo_residual_hz (void)
 How far from the frequency asked for the correction leaves the LO.
int esp_sdr_get_temp_dc (int16_t *dc)
 Read the chip's die temperature (devicetree alias die-temp0).
int esp_sdr_set_channel_bw (unsigned int cbw)
 Set the channel bandwidth flag of the vendor tuning call (experimental).
int esp_sdr_reset_settings (void)
 Return the radio's settings to those esp_sdr_init() left.
void esp_sdr_get_stats (struct esp_sdr_stats *stats)
int esp_sdr_bbtop_read (unsigned int reg)
 Read or write a register of the analog baseband (I2C block 0x67), for characterization.
int esp_sdr_set_turnaround (uint32_t settle_us, bool retune)
 Set the front end turnaround between transmit and receive.

Detailed Description

Bring-up, tuning, front end turnaround and housekeeping (esp_sdr.h).

Guides: Transceiver, Tuning.

Macro Definition Documentation

◆ ESP_SDR_BANKS

#define ESP_SDR_BANKS   2

Dump banks available for capture and loop playback (CONFIG_ESP_SDR_BANK1 adds one).

◆ ESP_SDR_CPU_HZ

#define ESP_SDR_CPU_HZ   (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000U)

CPU clock in Hz (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ): the unit of esp_sdr_paced_cycles(), and the clock the CPU-paced rates must divide.

◆ ESP_SDR_FREQ_CORR_MAX_PPB

#define ESP_SDR_FREQ_CORR_MAX_PPB   50000

Largest crystal correction esp_sdr_set_freq_corr_ppb() takes, 50 ppm.

◆ ESP_SDR_FREQ_MIN_MHZ

#define ESP_SDR_FREQ_MIN_MHZ   100U

Software tuning limits in MHz. The PLL locks over a much narrower range that differs between chips; esp_sdr_set_freq() reports frequencies outside it with -ERANGE. Below 2210 MHz the LO goes through the 5/6 divider. Measured on one ESP32-S3: 1817 to 2793 MHz on air, 1828 to 2781 MHz without -ERANGE; on one ESP32-C6: 1774 MHz to at least 2856 MHz on air, 1784 to 2884 MHz without -ERANGE.

◆ ESP_SDR_HIGH_BUF_DEFINE

#define ESP_SDR_HIGH_BUF_DEFINE ( type,
name,
dims,
align )
Value:
static type name dims __aligned(align) ESP_SDR_HIGH_RAM
#define ESP_SDR_HIGH_RAM
Definition esp_sdr.h:65

static type name dims __aligned(align) ESP_SDR_HIGH_RAM: an app's buffer that must be internal RAM (DMA, ring threads). A multiapp extension gets it from the host's area instead.

◆ ESP_SDR_HIGH_RAM

#define ESP_SDR_HIGH_RAM   __attribute__((section(".esp_sdr_high")))

Place a static buffer in the internal SRAM above the capture bank (on the ESP32-S3 about 38 KiB, DMA capable). It is not zeroed at boot: buffers only. A multiapp extension defines it beforehand: it has no fixed addresses.

◆ ESP_SDR_HIGH_STACK_DEFINE

#define ESP_SDR_HIGH_STACK_DEFINE ( name,
size )
Value:
static Z_KERNEL_STACK_DEFINE_IN(name, size, ESP_SDR_HIGH_RAM)

A kernel thread stack of an app in the high region, as ESP_SDR_HIGH_BUF_DEFINE().

◆ ESP_SDR_PSRAM_BUF_DEFINE

#define ESP_SDR_PSRAM_BUF_DEFINE ( type,
name,
dims,
align )
Value:
static type name dims __aligned(align) EXT_RAM_BSS_ATTR

static type name dims __aligned(align) in PSRAM. An extension's bss may be in internal RAM, so that an image loading the library as one defines it elsewhere (apps/multiapp).

◆ ESP_SDR_SAMPLES_MIN

#define ESP_SDR_SAMPLES_MIN   256U

Limits of one capture or playback burst in complex samples (one dump bank).

Enumeration Type Documentation

◆ esp_sdr_rate

Native dump engine rates; values are the upstream protocol rate indices. The S3 and the ESP32 receive at 80, 40 and 16 MS/s (esp_sdr_rx_rate_hz()), the C5 and the S31 at 80, 40, 20, 10, 8 and 4 MS/s, the C6 at 80 MS/s only (the others return 0); the DAC runs at 80 and 40 MS/s (esp_sdr_tx_rate_hz(), S3 only).

Function Documentation

◆ esp_sdr_bbtop_read()

int esp_sdr_bbtop_read ( unsigned int reg)

Read or write a register of the analog baseband (I2C block 0x67), for characterization.

Unchecked: wrong values can detune or disable the radio until the next retune or reset.

◆ esp_sdr_freq_window_checked()

bool esp_sdr_freq_window_checked ( void )
Returns
Whether the tuning calls check the VCO's window on this chip (and return -ERANGE outside it); false on the ESP32-C5 and the classic ESP32, whose PLL status is not mapped: there they return 0 wherever the PLL ends up.

◆ esp_sdr_get_freq()

uint32_t esp_sdr_get_freq ( void )
Returns
Current LO frequency in MHz.

◆ esp_sdr_get_freq_corr_ppb()

int32_t esp_sdr_get_freq_corr_ppb ( void )
Returns
The crystal correction in force in ppb (the model's at the last retune, if any).

◆ esp_sdr_get_freq_offset()

int32_t esp_sdr_get_freq_offset ( void )
Returns
The LO's offset in kHz (esp_sdr_set_freq_offset()), which esp_sdr_set_freq() keeps: a caller that tunes to a new MHz with the same offset needs no second retune.

◆ esp_sdr_get_lo_residual_hz()

int32_t esp_sdr_get_lo_residual_hz ( void )

How far from the frequency asked for the correction leaves the LO.

The vendor tuning calls take whole kHz at the PLL (the classic ESP32's ROM 1/1024 MHz after that), so a correction lands up to 500 Hz there (417 Hz at the RF below 2210 MHz, through the 5/6 divider) from where it should, even when it is right. This is that remainder for the current tuning, by the correction in force: an app can shift its samples by it, or report the centre it gives.

Returns
The LO's offset from the frequency asked for, in Hz at the RF, positive when above.

◆ esp_sdr_get_stats()

void esp_sdr_get_stats ( struct esp_sdr_stats * stats)

Copy the radio housekeeping counters into stats.

◆ esp_sdr_get_temp_dc()

int esp_sdr_get_temp_dc ( int16_t * dc)

Read the chip's die temperature (devicetree alias die-temp0).

A reading is kept for a second, so frequent callers (every retune) cost nothing.

Parameters
dcSet to the temperature in 0.1 degC.
Return values
0on success.
-ENOTSUPwithout CONFIG_ESP_SDR_TEMP.
-ENODEVif the sensor is not ready.
othernegative errno from the sensor.

◆ esp_sdr_init()

int esp_sdr_init ( void )

Bring the radio up and tune it to the default frequency.

Needs the Wi-Fi driver started; safe to call more than once. The radio rests in the receive state between transmissions.

Return values
0on success.
-ENODEVif the Wi-Fi driver is not ready.
-EIOif a Wi-Fi call failed.

◆ esp_sdr_reset_settings()

int esp_sdr_reset_settings ( void )

Return the radio's settings to those esp_sdr_init() left.

The LO at the calibration channel (2412 MHz) without an offset, the 20 MHz channel bandwidth flag, the hardware AGC, the automatic analog low-pass and the default turnaround, for the next user to start from (an app that ends). Nothing that streams is stopped: stop it first.

Return values
0on success.
-EAGAINif esp_sdr_init() has not run.
-ERANGEas for esp_sdr_set_freq().

◆ esp_sdr_set_channel_bw()

int esp_sdr_set_channel_bw ( unsigned int cbw)

Set the channel bandwidth flag of the vendor tuning call (experimental).

Passed as the bandwidth argument of the PHY's channel setup; 0 (default) is the 20 MHz configuration the receiver was characterized with.

Return values
0on success.
-EINVALabove 2.
-EAGAINif esp_sdr_init() has not run.

◆ esp_sdr_set_freq()

int esp_sdr_set_freq ( uint32_t mhz)

Tune the LO, shared by receive and transmit.

Below 2210 MHz the PLL runs at 6/5 of mhz behind the 5/6 LO divider. After tuning, the PLL calibration's VCO window check decides the return value. It errs on the safe side: on the chips measured, the PLL still locked about 12 MHz beyond either end of the window.

Parameters
mhzFrequency in MHz, ESP_SDR_FREQ_MIN_MHZ to ESP_SDR_FREQ_MAX_MHZ.
Return values
0on success.
-EINVALif out of range.
-ERANGEif the VCO ended outside its tuning window: tuned, but the PLL may not lock there.
-EAGAINif esp_sdr_init() has not run.

◆ esp_sdr_set_freq_corr_ppb()

int esp_sdr_set_freq_corr_ppb ( int32_t ppb)

Correct every tuning for the crystal's error and retune.

The LO and the sample clock come from one crystal; the correction scales what the PLL is asked for by 1 / (1 + ppb * 1e-9), in the whole kHz the vendor calls take (some 0.2 to 0.4 ppm of rounding left at 2.4 GHz). A correction other than 0 forces direct PLL tuning. esp_sdr_reset_settings() keeps it. With CONFIG_ESP_SDR_CALSTORE, esp_sdr_init() loads the stored one. A constant: it drops a temperature model (esp_sdr_set_freq_corr_model()).

Parameters
ppbThe crystal's error in ppb, positive when the LO runs high, as esp_sdr_lte_calibrate() measures it.
Return values
0on success, also before esp_sdr_init() (applied by it).
-EINVALbeyond ESP_SDR_FREQ_CORR_MAX_PPB.
-ERANGEas for esp_sdr_set_freq().

◆ esp_sdr_set_freq_offset()

int esp_sdr_set_freq_offset ( int32_t khz)

Set an offset in kHz from the whole MHz (esp_sdr_set_freq()) and retune.

An offset at the RF: below 2210 MHz, where the LO is the PLL through a 5/6 divider, the PLL moves 6/5 of it, to the nearest kHz together with the crystal correction (esp_sdr_get_lo_residual_hz() tells the rest). A non-zero offset forces direct PLL tuning, also on Wi-Fi channel frequencies.

Return values
0on success.
-ERANGEas for esp_sdr_set_freq().
-EAGAINif esp_sdr_init() has not run.

◆ esp_sdr_set_turnaround()

int esp_sdr_set_turnaround ( uint32_t settle_us,
bool retune )

Set the front end turnaround between transmit and receive.

Every switch to TX (playback, loop sessions) and back to RX waits settle_us, and with retune also reprograms the LO first. Defaults: 3000 us with retune, as after a frequency change (which always retunes and waits the full 3000 us). Shorter turnarounds suit packet links; check the signal quality at the chosen setting.

Return values
0on success.
-EINVALfor more than 3000 us.