Modulator and receiver, portable C (ieee154_phy.h).
More...
|
| typedef void(* | ieee154_phy_frame_cb_t) (const uint8_t *psdu, uint8_t len, int lqi, void *user) |
| typedef void(* | ieee154_phy_all_cb_t) (const uint8_t *psdu, uint8_t len, int lqi, bool fcs_ok, void *user) |
| typedef bool(* | ieee154_phy_hdr_cb_t) (const uint8_t *psdu, uint8_t have, uint8_t len, uint32_t end_pos, void *user) |
|
| void | ieee154_phy_init (void) |
| void | ieee154_phy_rx_init (struct ieee154_phy_rx *rx) |
| void | ieee154_phy_set_rx_cb_i (struct ieee154_phy_rx *rx, ieee154_phy_frame_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) |
| void | ieee154_phy_set_all_cb_i (struct ieee154_phy_rx *rx, ieee154_phy_all_cb_t cb, void *user) |
| void | ieee154_phy_rx_block_i (struct ieee154_phy_rx *rx, const int16_t *iq, size_t n) |
| void | ieee154_phy_rx_reset_i (struct ieee154_phy_rx *rx) |
| uint8_t | ieee154_phy_rx_preamble_run_i (const struct ieee154_phy_rx *rx) |
| void | ieee154_phy_rx_counts_i (const struct ieee154_phy_rx *rx, struct ieee154_phy_counts *c) |
| void | ieee154_phy_rx_counts_clear_i (struct ieee154_phy_rx *rx) |
| uint32_t | ieee154_phy_rx_position_i (const struct ieee154_phy_rx *rx) |
| uint32_t | ieee154_phy_rx_frame_start_i (const struct ieee154_phy_rx *rx) |
| void | ieee154_phy_set_rx_cb (ieee154_phy_frame_cb_t cb, void *user) |
| void | ieee154_phy_set_hdr_cb (ieee154_phy_hdr_cb_t cb, void *user) |
| void | ieee154_phy_rx_block (const int16_t *iq, size_t n) |
| void | ieee154_phy_rx_reset (void) |
| uint32_t | ieee154_phy_rx_position (void) |
| uint32_t | ieee154_phy_rx_frame_start (void) |
| void | ieee154_phy_rx_counts (struct ieee154_phy_counts *c) |
| void | ieee154_phy_rx_counts_clear (void) |
| uint32_t | ieee154_phy_chips (int sym) |
| size_t | ieee154_phy_modulate (const uint8_t *psdu, uint8_t len, int16_t amp, int16_t *out, size_t max_samples) |
| size_t | ieee154_phy_append_fcs (uint8_t *buf, size_t n) |
Modulator and receiver, portable C (ieee154_phy.h).
◆ IEEE154_PHY_DUP_SAMPLES
| #define IEEE154_PHY_DUP_SAMPLES 4 |
End positions this close, in samples, belong to the same frame completed by both phase trackers (ieee154_phy_all_cb_t).
◆ IEEE154_PHY_FRAME_SAMPLES
| #define IEEE154_PHY_FRAME_SAMPLES |
( |
| len | ) |
|
Value:((6U + (uint32_t)(len)) * 128U)
Samples a frame of a PSDU of len bytes takes on the air at 2 samples a chip: 4 preamble bytes, the SFD, the PHR and the PSDU, 2 symbols a byte, 64 samples a symbol.
◆ IEEE154_PHY_MOD_SAMPLES
| #define IEEE154_PHY_MOD_SAMPLES |
( |
| len | ) |
|
◆ IEEE154_PHY_PSDU_MAX
| #define IEEE154_PHY_PSDU_MAX 127 |
Longest PSDU, FCS included.
◆ ieee154_phy_all_cb_t
| typedef void(* ieee154_phy_all_cb_t) (const uint8_t *psdu, uint8_t len, int lqi, bool fcs_ok, void *user) |
Called for every complete frame, whether its FCS matched or not: psdu includes the 2-byte FCS, lqi is 0 to 255 from the mean chip-error count, fcs_ok says whether the FCS matched, user is the pointer given to ieee154_phy_set_all_cb_i(). A frame with a good FCS also goes to the ieee154_phy_frame_cb_t callback and stops the other phase tracker delivering it again. Both trackers may complete a frame whose FCS fails, a sample or two apart: the first is delivered, a second bad one of the same end position (within IEEE154_PHY_DUP_SAMPLES) is not, but a good one is. So a frame may come as a bad copy and then as a good one: a consumer that wants every frame once holds a bad frame back until the position has moved more than IEEE154_PHY_DUP_SAMPLES past its end, or a good copy has replaced it.
◆ ieee154_phy_frame_cb_t
| typedef void(* ieee154_phy_frame_cb_t) (const uint8_t *psdu, uint8_t len, int lqi, void *user) |
Called for each CRC-valid frame: psdu includes the 2-byte FCS, lqi is 0 to 255 from the mean chip-error count, user is the pointer given to ieee154_phy_set_rx_cb().
◆ ieee154_phy_hdr_cb_t
| typedef bool(* ieee154_phy_hdr_cb_t) (const uint8_t *psdu, uint8_t have, uint8_t len, uint32_t end_pos, void *user) |
Called while a frame comes in, from the PHR on: len is the PSDU length (FCS included), have the PSDU bytes received so far (0 at the PHR, at most len - 1), end_pos the receiver's position (ieee154_phy_rx_position_i(), ieee154_phy_rx_position() for the static receiver) at which the frame's last symbol will be decided. Called again with each further byte while it returns true. Both phase trackers may report the same frame.
◆ ieee154_phy_append_fcs()
| size_t ieee154_phy_append_fcs |
( |
uint8_t * | buf, |
|
|
size_t | n ) |
Append the little-endian CRC-16 FCS to buf[0..n-1]; returns n + 2.
◆ ieee154_phy_chips()
| uint32_t ieee154_phy_chips |
( |
int | sym | ) |
|
The 32 chips of symbol sym (0..15), chip c0 in the MSB.
◆ ieee154_phy_init()
| void ieee154_phy_init |
( |
void | | ) |
|
Build the chip tables. Call once before anything else.
◆ ieee154_phy_modulate()
| size_t ieee154_phy_modulate |
( |
const uint8_t * | psdu, |
|
|
uint8_t | len, |
|
|
int16_t | amp, |
|
|
int16_t * | out, |
|
|
size_t | max_samples ) |
Modulate SHR + PHR + psdu (FCS already appended) into out. Returns the complex samples written, 0 if max_samples is too small.
◆ ieee154_phy_rx_block()
| void ieee154_phy_rx_block |
( |
const int16_t * | iq, |
|
|
size_t | n ) |
Feed the static receiver the next n complex samples; blocks must be consecutive.
◆ ieee154_phy_rx_block_i()
| void ieee154_phy_rx_block_i |
( |
struct ieee154_phy_rx * | rx, |
|
|
const int16_t * | iq, |
|
|
size_t | n ) |
Feed a receiver the next n complex samples; blocks must be consecutive.
- Parameters
-
| rx | The receiver. |
| iq | Interleaved int16 I/Q at 4 MS/s. |
| n | Complex samples in iq. |
◆ ieee154_phy_rx_counts()
◆ ieee154_phy_rx_counts_clear()
| void ieee154_phy_rx_counts_clear |
( |
void | | ) |
|
◆ ieee154_phy_rx_counts_clear_i()
Zero a receiver's counts.
◆ ieee154_phy_rx_counts_i()
◆ ieee154_phy_rx_frame_start()
| uint32_t ieee154_phy_rx_frame_start |
( |
void | | ) |
|
◆ ieee154_phy_rx_frame_start_i()
| uint32_t ieee154_phy_rx_frame_start_i |
( |
const struct ieee154_phy_rx * | rx | ) |
|
In the frame callbacks: the position of the frame's first preamble sample, its end position (ieee154_phy_rx_position_i()) less IEEE154_PHY_FRAME_SAMPLES() of its length, on the same wrapping count (so it may stand for a sample before the first one fed: subtract the position the stream of interest started at and read the difference as signed).
- Parameters
-
- Returns
- The frame's first sample's position.
◆ ieee154_phy_rx_init()
Set up a receiver: idle trackers, no history, position 0, no callbacks.
- Parameters
-
◆ ieee154_phy_rx_position()
| uint32_t ieee154_phy_rx_position |
( |
void | | ) |
|
ieee154_phy_rx_position_i() of the static receiver: in the frame callback, the samples fed up to and including the frame's last sample, which completed its last symbol.
◆ ieee154_phy_rx_position_i()
| uint32_t ieee154_phy_rx_position_i |
( |
const struct ieee154_phy_rx * | rx | ) |
|
A receiver's sample count, over all blocks (wraps). In the callbacks: the samples fed up to and including the one that completed the symbol just decided (for a frame, its last symbol). Between blocks it keeps what the last block left: the samples fed before that block, or the position of its last symbol decision (not the samples fed so far).
- Parameters
-
- Returns
- The sample count.
◆ ieee154_phy_rx_preamble_run_i()
| uint8_t ieee154_phy_rx_preamble_run_i |
( |
const struct ieee154_phy_rx * | rx | ) |
|
The most preamble symbols in a row a tracker has found since the receiver was set up or reset: a stream cut before its frame's end still shows what it was. Each takes 16 us; the count stops at 4, where the receiver goes on to look for the frame's start.
- Parameters
-
- Returns
- 0 to 4.
◆ ieee154_phy_rx_reset()
| void ieee154_phy_rx_reset |
( |
void | | ) |
|
Drop any frame in progress, before a block that does not follow the last one.
◆ ieee154_phy_rx_reset_i()
Drop any frame in progress, before a block that does not follow the last one. The sample count goes on.
- Parameters
-
◆ ieee154_phy_set_all_cb_i()
Set a receiver's callback for every complete frame, bad FCS included (NULL: none, frames with a bad FCS are dropped).
- Parameters
-
| rx | The receiver. |
| cb | Called for each complete frame with its FCS verdict. |
| user | Passed to cb. |
◆ ieee154_phy_set_hdr_cb()
Set the static receiver's header callback (NULL: none).
◆ ieee154_phy_set_hdr_cb_i()
Set a receiver's header callback (NULL: none).
- Parameters
-
| rx | The receiver. |
| cb | Called from the PHR on while a frame comes in. |
| user | Passed to cb. |
◆ ieee154_phy_set_rx_cb()
Set the static receiver's frame callback (NULL: frames are dropped).
◆ ieee154_phy_set_rx_cb_i()
Set a receiver's frame callback (NULL: good frames are dropped).
- Parameters
-
| rx | The receiver. |
| cb | Called for each CRC-valid frame. |
| user | Passed to cb. |