esp-sdr-zephyr
Raw I/Q receive and transmit on the ESP32-S3/C6 Wi-Fi radio, for Zephyr
Loading...
Searching...
No Matches
ieee154_phy.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-3.0-or-later
3 */
4
16
17#ifndef ESP_SDR_IEEE154_PHY_H_
18#define ESP_SDR_IEEE154_PHY_H_
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
32
34#define IEEE154_PHY_PSDU_MAX 127
35
37#define IEEE154_PHY_MOD_SAMPLES(len) ((6 + (size_t)(len)) * 128 + 4)
38
44#define IEEE154_PHY_FRAME_SAMPLES(len) ((6U + (uint32_t)(len)) * 128U)
45
51typedef void (*ieee154_phy_frame_cb_t)(const uint8_t *psdu, uint8_t len, int lqi, void *user);
52
67typedef void (*ieee154_phy_all_cb_t)(const uint8_t *psdu, uint8_t len, int lqi, bool fcs_ok,
68 void *user);
69
74#define IEEE154_PHY_DUP_SAMPLES 4
75
84typedef bool (*ieee154_phy_hdr_cb_t)(const uint8_t *psdu, uint8_t have, uint8_t len,
85 uint32_t end_pos, void *user);
86
92 /* Chip shift register, chips seen, the chip count of the last symbol boundary. */
93 uint32_t win, nchip, anchor;
94 /* Preamble hits in a row, state, nibble assembly, PSDU length and bytes so far. */
95 uint8_t run, st, nib_have, nib_lo, len, pos;
96 /* The header callback still wants bytes of this frame. */
97 uint8_t hdr_want;
98 /* Chip errors summed over the PHR and PSDU symbols, and their count. */
99 uint16_t err_sum, nsym;
100 /* Sample count at which the frame's last symbol will be decided. */
101 uint32_t end_pos;
102 uint8_t buf[IEEE154_PHY_PSDU_MAX];
103};
104
112 uint32_t preamble;
114 uint32_t sfd;
116 uint32_t psdu;
118 uint32_t drop_shr;
120 uint32_t drop_frame;
122 uint32_t short_phr;
124 uint32_t fcs_bad, fcs_good;
125};
126
133 struct ieee154_phy_trk trk[2];
135 void *user;
137 void *hdr_user;
139 void *all_user;
140 /* Samples fed before the block, or up to the sample being decided in it. */
141 uint32_t pos;
142 /* Samples fed over all blocks (wraps). */
143 uint32_t n_total;
144 /* DC removal state (Q8) and the discriminator's two previous samples. */
145 int32_t dc_i, dc_q, pi1, pq1, pi2, pq2;
146 /* The frame being delivered: the position of its first preamble sample. */
147 uint32_t frame_start;
148 /* The last frame delivered with a bad FCS: its end position, and whether there was one. */
149 uint32_t bad_end;
150 bool bad_seen;
151 /* The most preamble symbols in a row a tracker has found. */
152 uint8_t run_max;
153 /* Kept across ieee154_phy_rx_reset_i(). */
154 struct ieee154_phy_counts counts;
155};
156
159
166
175
184
194
202void ieee154_phy_rx_block_i(struct ieee154_phy_rx *rx, const int16_t *iq, size_t n);
203
211
221
230
233
244uint32_t ieee154_phy_rx_position_i(const struct ieee154_phy_rx *rx);
245
258
261
264
266void ieee154_phy_rx_block(const int16_t *iq, size_t n);
267
270
277
280
283
286
288uint32_t ieee154_phy_chips(int sym);
289
294size_t ieee154_phy_modulate(const uint8_t *psdu, uint8_t len, int16_t amp, int16_t *out,
295 size_t max_samples);
296
298size_t ieee154_phy_append_fcs(uint8_t *buf, size_t n);
299
301
302#ifdef __cplusplus
303}
304#endif
305
306#endif /* ESP_SDR_IEEE154_PHY_H_ */
uint32_t ieee154_phy_rx_frame_start_i(const struct ieee154_phy_rx *rx)
void ieee154_phy_rx_block(const int16_t *iq, size_t n)
void ieee154_phy_init(void)
void ieee154_phy_rx_counts_clear_i(struct ieee154_phy_rx *rx)
uint32_t ieee154_phy_rx_position(void)
uint32_t ieee154_phy_rx_position_i(const struct ieee154_phy_rx *rx)
void ieee154_phy_set_all_cb_i(struct ieee154_phy_rx *rx, ieee154_phy_all_cb_t cb, void *user)
void ieee154_phy_set_hdr_cb_i(struct ieee154_phy_rx *rx, ieee154_phy_hdr_cb_t cb, void *user)
uint32_t ieee154_phy_chips(int sym)
void ieee154_phy_rx_counts(struct ieee154_phy_counts *c)
void ieee154_phy_rx_init(struct ieee154_phy_rx *rx)
uint8_t ieee154_phy_rx_preamble_run_i(const struct ieee154_phy_rx *rx)
void(* ieee154_phy_frame_cb_t)(const uint8_t *psdu, uint8_t len, int lqi, void *user)
Definition ieee154_phy.h:51
void(* ieee154_phy_all_cb_t)(const uint8_t *psdu, uint8_t len, int lqi, bool fcs_ok, void *user)
Definition ieee154_phy.h:67
void ieee154_phy_rx_block_i(struct ieee154_phy_rx *rx, const int16_t *iq, size_t n)
void ieee154_phy_rx_counts_i(const struct ieee154_phy_rx *rx, struct ieee154_phy_counts *c)
void ieee154_phy_set_rx_cb_i(struct ieee154_phy_rx *rx, ieee154_phy_frame_cb_t cb, void *user)
bool(* ieee154_phy_hdr_cb_t)(const uint8_t *psdu, uint8_t have, uint8_t len, uint32_t end_pos, void *user)
Definition ieee154_phy.h:84
void ieee154_phy_rx_counts_clear(void)
void ieee154_phy_rx_reset(void)
size_t ieee154_phy_append_fcs(uint8_t *buf, size_t n)
#define IEEE154_PHY_PSDU_MAX
Definition ieee154_phy.h:34
void ieee154_phy_set_hdr_cb(ieee154_phy_hdr_cb_t cb, void *user)
uint32_t ieee154_phy_rx_frame_start(void)
void ieee154_phy_set_rx_cb(ieee154_phy_frame_cb_t cb, void *user)
void ieee154_phy_rx_reset_i(struct ieee154_phy_rx *rx)
size_t ieee154_phy_modulate(const uint8_t *psdu, uint8_t len, int16_t amp, int16_t *out, size_t max_samples)
Definition ieee154_phy.h:110
uint32_t drop_frame
Definition ieee154_phy.h:120
uint32_t psdu
Definition ieee154_phy.h:116
uint32_t short_phr
Definition ieee154_phy.h:122
uint32_t preamble
Definition ieee154_phy.h:112
uint32_t drop_shr
Definition ieee154_phy.h:118
uint32_t sfd
Definition ieee154_phy.h:114
uint32_t fcs_bad
Definition ieee154_phy.h:124
Definition ieee154_phy.h:132
Definition ieee154_phy.h:91