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

Gain, analog low-pass filter, burst and decimated capture (esp_sdr_rx.h). More...

Data Structures

struct  esp_sdr_rx_burst

Macros

#define ESP_SDR_RX_GAIN_AUTO   (-1)
#define ESP_SDR_RX_LPF_AUTO   (-1)
#define ESP_SDR_RX_LPF_MAX   63
#define ESP_SDR_RX_DECIM_MIN   2U
#define ESP_SDR_RX_DECIM_SETTLE   3U
#define ESP_SDR_RX_FOLD_MIN   2U

Typedefs

typedef void(* esp_sdr_rx_words_fn_t) (void *user, const uint32_t *words, size_t count)

Functions

int esp_sdr_rx_set_gain (int index)
 Select hardware AGC or a fixed receive gain.
int esp_sdr_rx_get_gain (void)
int esp_sdr_rx_gain_max (void)
int esp_sdr_rx_set_bandwidth (uint32_t mhz)
 Select the analog low-pass filter by approximate bandwidth.
void esp_sdr_rx_bandwidth_range (uint32_t *min, uint32_t *max)
 Supported bandwidth range in MHz.
int esp_sdr_rx_set_lpf (int code)
 Select a raw low-pass filter capacitor code.
int esp_sdr_rx_get_lpf (void)
int esp_sdr_rx_capture (enum esp_sdr_rate rate, size_t count, struct esp_sdr_rx_burst *burst)
 Capture one burst of complex samples.
int esp_sdr_rx_capture_iq (enum esp_sdr_rate rate, size_t count, struct esp_sdr_iq16 *out, uint64_t *first_ns)
 Capture one burst and convert it to I/Q (raw units, -512 to 511) under the radio lock.
int esp_sdr_rx_capture_with (enum esp_sdr_rate rate, size_t count, esp_sdr_rx_words_fn_t fn, void *user, uint64_t *first_ns)
 Capture one burst and hand its raw words to fn under the radio lock.
int esp_sdr_rx_capture_bank (enum esp_sdr_rate rate, size_t count, int bank, struct esp_sdr_rx_burst *burst)
 Capture one burst into a chosen bank, like esp_sdr_rx_capture().
void esp_sdr_rx_set_capture_hook (void(*fn)(void *user), void *user)
 Have work done while a capture runs.
int esp_sdr_rx_capture_decimated (enum esp_sdr_rate rate, size_t count, unsigned int m, struct esp_sdr_iq16 *out, size_t max_out, size_t *n_out, uint64_t *first_ns)
 Capture a burst and decimate it with a third order CIC filter.
int esp_sdr_rx_capture_folded (enum esp_sdr_rate rate, size_t count, unsigned int n, struct esp_sdr_iq16 *out, size_t max_out, size_t *n_out, uint64_t *first_ns)
 Capture a burst and fold its spectrum by n: a power estimation mode.
uint32_t esp_sdr_rx_rate_hz (enum esp_sdr_rate rate)
static int16_t esp_sdr_rx_i (uint32_t word)
static int16_t esp_sdr_rx_q (uint32_t word)
static uint32_t esp_sdr_rx_iq8 (uint32_t word)

Detailed Description

Gain, analog low-pass filter, burst and decimated capture (esp_sdr_rx.h).

Guides: Gain, Filters, Burst capture.

Macro Definition Documentation

◆ ESP_SDR_RX_DECIM_MIN

#define ESP_SDR_RX_DECIM_MIN   2U

Decimation factor limits for esp_sdr_rx_capture_decimated().

◆ ESP_SDR_RX_DECIM_SETTLE

#define ESP_SDR_RX_DECIM_SETTLE   3U

Outputs esp_sdr_rx_capture_decimated() drops while its filter settles: it gives count / m less these.

◆ ESP_SDR_RX_FOLD_MIN

#define ESP_SDR_RX_FOLD_MIN   2U

Fold factor limits for esp_sdr_rx_capture_folded().

◆ ESP_SDR_RX_GAIN_AUTO

#define ESP_SDR_RX_GAIN_AUTO   (-1)

Gain index that selects the hardware AGC.

◆ ESP_SDR_RX_LPF_AUTO

#define ESP_SDR_RX_LPF_AUTO   (-1)

Low-pass filter code that restores the PHY-calibrated setting.

◆ ESP_SDR_RX_LPF_MAX

#define ESP_SDR_RX_LPF_MAX   63

Largest raw low-pass filter capacitor code: seven bits on the ESP32, six on the others.

Typedef Documentation

◆ esp_sdr_rx_words_fn_t

typedef void(* esp_sdr_rx_words_fn_t) (void *user, const uint32_t *words, size_t count)

Takes a burst's raw words (esp_sdr_rx_burst.words) for esp_sdr_rx_capture_with().

Function Documentation

◆ esp_sdr_rx_bandwidth_range()

void esp_sdr_rx_bandwidth_range ( uint32_t * min,
uint32_t * max )

Supported bandwidth range in MHz.

Parameters
minSet to the narrowest setting.
maxSet to the widest setting.

◆ esp_sdr_rx_capture()

int esp_sdr_rx_capture ( enum esp_sdr_rate rate,
size_t count,
struct esp_sdr_rx_burst * burst )

Capture one burst of complex samples.

The samples live in a reserved SRAM bank and stay valid until the next capture or transmit session by any thread: with other radio users, copy them with esp_sdr_rx_capture_iq() instead. The caller may rewrite them in place, for example to pack them.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
burstFilled with the result.
Return values
0on success.
-EINVALfor an unsupported rate or count.
-EAGAINif esp_sdr_init() has not run.
-ETIMEDOUTif the capture engine did not finish.

◆ esp_sdr_rx_capture_bank()

int esp_sdr_rx_capture_bank ( enum esp_sdr_rate rate,
size_t count,
int bank,
struct esp_sdr_rx_burst * burst )

Capture one burst into a chosen bank, like esp_sdr_rx_capture().

With two banks (CONFIG_ESP_SDR_BANK1), one burst can be processed while the next is captured into the other bank. Bank 0 is the one esp_sdr_rx_capture() uses.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
bank0 to ESP_SDR_BANKS - 1.
burstFilled with the result.
Returns
Like esp_sdr_rx_capture(); -EINVAL also for a bank that does not exist.

◆ esp_sdr_rx_capture_decimated()

int esp_sdr_rx_capture_decimated ( enum esp_sdr_rate rate,
size_t count,
unsigned int m,
struct esp_sdr_iq16 * out,
size_t max_out,
size_t * n_out,
uint64_t * first_ns )

Capture a burst and decimate it with a third order CIC filter.

Captures count samples like esp_sdr_rx_capture(), then (still holding the radio lock) decimates by m into out, I and Q in the usual order. The first 3 outputs (filter settling) are dropped, so up to count / m - 3 samples come out. The CIC needs no multiplies per input sample but droops towards the band edge: -2.7 dB at a quarter of the output rate, -9.3 dB at 0.45 of it. Needs CONFIG_ESP_SDR_RX_DECIM.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
mDecimation factor, ESP_SDR_RX_DECIM_MIN to ESP_SDR_RX_DECIM_MAX.
outOutput samples, full scale +-32767.
max_outCapacity of out.
n_outSet to the number of samples written.
first_nsSet to the time of the first output sample (k_cycle_get_64() clock, ns).
Return values
0on success.
-EINVALfor an unsupported rate, count or factor.
-EAGAINif esp_sdr_init() has not run.
-ETIMEDOUTif the capture engine did not finish.

◆ esp_sdr_rx_capture_folded()

int esp_sdr_rx_capture_folded ( enum esp_sdr_rate rate,
size_t count,
unsigned int n,
struct esp_sdr_iq16 * out,
size_t max_out,
size_t * n_out,
uint64_t * first_ns )

Capture a burst and fold its spectrum by n: a power estimation mode.

Captures count samples like esp_sdr_rx_capture(), then (still holding the radio lock) sums n time-shifted blocks of count / n samples each, averaged back to the raw 10-bit scale, into out. This is decimation in frequency rather than in time: a tone originally at offset f reappears at f mod (rate / n), summed with every other tone an integer multiple of rate / n away, instead of being low-pass filtered out. The whole original band's power is represented at 1/n the data rate, so it suits a wideband power/occupancy survey; it does not suit recovering an individual signal, since two sources that land in the same fold group add instead of one of them surviving cleanly. Needs CONFIG_ESP_SDR_RX_DECIM.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
nFold factor, ESP_SDR_RX_FOLD_MIN to ESP_SDR_RX_FOLD_MAX.
outOutput samples, full scale +-511 (raw 10-bit, averaged not summed).
max_outCapacity of out.
n_outSet to the number of samples written (count / n).
first_nsSet to the time of the first input sample in the burst.
Return values
0on success.
-EINVALfor an unsupported rate, count or factor.
-EAGAINif esp_sdr_init() has not run.
-ETIMEDOUTif the capture engine did not finish.

◆ esp_sdr_rx_capture_iq()

int esp_sdr_rx_capture_iq ( enum esp_sdr_rate rate,
size_t count,
struct esp_sdr_iq16 * out,
uint64_t * first_ns )

Capture one burst and convert it to I/Q (raw units, -512 to 511) under the radio lock.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
outOutput samples, count of them.
first_nsSet to the time of the first sample returned (k_cycle_get_64() clock, ns): the arming time, but on the ESP32-S31 256 settling words after it.
Returns
Like esp_sdr_rx_capture().

◆ esp_sdr_rx_capture_with()

int esp_sdr_rx_capture_with ( enum esp_sdr_rate rate,
size_t count,
esp_sdr_rx_words_fn_t fn,
void * user,
uint64_t * first_ns )

Capture one burst and hand its raw words to fn under the radio lock.

For work straight on the bank's words that other radio users must not overwrite meanwhile, as esp_sdr_rx_capture_iq() converts them. fn runs in the calling thread, after the capture; it must not call into esp_sdr, and every other thread that wants the radio waits for it.

Parameters
rateNative sample rate.
countComplex samples, ESP_SDR_SAMPLES_MIN to ESP_SDR_SAMPLES_MAX.
fnCalled once with \p user, the words and count; the words are good for the call.
userPassed to fn.
first_nsAs for esp_sdr_rx_capture_iq().
Returns
Like esp_sdr_rx_capture(); fn runs only on success.

◆ esp_sdr_rx_gain_max()

int esp_sdr_rx_gain_max ( void )
Returns
Largest calibrated gain index, 0 if the PHY reports none.

◆ esp_sdr_rx_get_gain()

int esp_sdr_rx_get_gain ( void )
Returns
Selected gain index, or ESP_SDR_RX_GAIN_AUTO.

◆ esp_sdr_rx_get_lpf()

int esp_sdr_rx_get_lpf ( void )
Returns
Selected low-pass filter code, or ESP_SDR_RX_LPF_AUTO.

◆ esp_sdr_rx_i()

int16_t esp_sdr_rx_i ( uint32_t word)
inlinestatic
Returns
In-phase component of a raw receive word, -512 to 511.

◆ esp_sdr_rx_iq8()

uint32_t esp_sdr_rx_iq8 ( uint32_t word)
inlinestatic
Returns
The top 8 bits of each component of a raw receive word as an int8 I/Q pair: I (bits 19:12) in the low byte, Q (bits 9:2) in the high one.

◆ esp_sdr_rx_q()

int16_t esp_sdr_rx_q ( uint32_t word)
inlinestatic
Returns
Quadrature component of a raw receive word, -512 to 511.

◆ esp_sdr_rx_rate_hz()

uint32_t esp_sdr_rx_rate_hz ( enum esp_sdr_rate rate)
Returns
Capture sample rate in Hz, or 0 for an unknown rate.

◆ esp_sdr_rx_set_bandwidth()

int esp_sdr_rx_set_bandwidth ( uint32_t mhz)

Select the analog low-pass filter by approximate bandwidth.

Parameters
mhzTwo-sided bandwidth in MHz, 0 selects the widest setting.
Return values
0on success.
-EINVALif outside the characterized range.

◆ esp_sdr_rx_set_capture_hook()

void esp_sdr_rx_set_capture_hook ( void(* fn )(void *user),
void * user )

Have work done while a capture runs.

The engine needs no CPU while it fills the bank, so fn is called once in each capture from its start, in the capturing thread, instead of spinning all that time. It must not start a capture or read the bank. It may take longer than the capture, which then only ends late.

On the ESP32-S31 the burst lands in TCM group 2 where the image leaves it free (CONFIG_ESP_SDR_S31_GROUP2): fn runs during it, interrupts on, and the engine runs on past the burst until fn returns. It must return before the engine reaches the group's end, some 16000 words after the burst's (0.8 ms at 20 MS/s, 0.2 ms at 80), or the capture fails with -EOVERFLOW. Without group 2 nothing can run while the engine has the memory: it is called just before the burst, which then starts late.

Parameters
fnCalled with user; NULL for none.
userPassed to fn.

◆ esp_sdr_rx_set_gain()

int esp_sdr_rx_set_gain ( int index)

Select hardware AGC or a fixed receive gain.

Indices are PHY gain table entries, not dB; higher is more gain.

Parameters
indexESP_SDR_RX_GAIN_AUTO, or 0 to esp_sdr_rx_gain_max().
Return values
0on success.
-EINVALif out of range.
-ENOTSUPfor a fixed gain without CONFIG_ESP_SDR_RFTEST.
-EAGAINif esp_sdr_init() has not run.

◆ esp_sdr_rx_set_lpf()

int esp_sdr_rx_set_lpf ( int code)

Select a raw low-pass filter capacitor code.

Parameters
code0 (widest) to ESP_SDR_RX_LPF_MAX, or ESP_SDR_RX_LPF_AUTO.
Return values
0on success.
-EINVALif out of range.