Skip to content

Commit

Permalink
Merge pull request #19668 from benpicco/ieee802154_symbol_time_on_demand
Browse files Browse the repository at this point in the history
ieee802154/submac: calculate symbol time on demand
  • Loading branch information
benpicco authored Feb 20, 2025
2 parents 88f2e45 + 73e45dd commit f67055c
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 42 deletions.
4 changes: 2 additions & 2 deletions drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ void ieee802154_submac_bh_request(ieee802154_submac_t *submac)
netdev->event_callback(netdev, NETDEV_EVENT_ISR);
}

void ieee802154_submac_ack_timer_set(ieee802154_submac_t *submac, uint16_t us)
void ieee802154_submac_ack_timer_set(ieee802154_submac_t *submac)
{
netdev_ieee802154_submac_t *netdev_submac = container_of(submac,
netdev_ieee802154_submac_t,
submac);

ztimer_set(ZTIMER_USEC, &netdev_submac->ack_timer, us);
ztimer_set(ZTIMER_USEC, &netdev_submac->ack_timer, submac->ack_timeout_us);
}

void ieee802154_submac_ack_timer_cancel(ieee802154_submac_t *submac)
Expand Down
127 changes: 123 additions & 4 deletions sys/include/net/ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include <stdlib.h>

#include "byteorder.h"
#include "net/eui64.h"
#include "modules.h"
#include "net/eui64.h"
#include "time_units.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -119,6 +120,18 @@ extern "C" {
*/
#define IEEE802154_ACK_TIMEOUT_SYMS (54)

/**
* @brief Symbol time for IEEE 802.15.4 MR-OFDM in µs
*/
#define IEEE802154_MR_OFDM_SYMBOL_TIME_US (120)

/**
* @brief Symbol time for IEEE 802.15.4 MR-FSK in µs
*
* symbol time is always 20 µs for MR-FSK (table 0, pg. 7)
*/
#define IEEE802154_MR_FSK_SYMBOL_TIME_US (20)

/**
* @brief value of measured power when RSSI is zero.
*
Expand Down Expand Up @@ -176,17 +189,67 @@ typedef enum {
IEEE802154_PHY_OQPSK, /**< Offset Quadrature Phase-Shift Keying */
IEEE802154_PHY_MR_OQPSK, /**< Multi-Rate Offset Quadrature Phase-Shift Keying */
IEEE802154_PHY_MR_OFDM, /**< Multi-Rate Orthogonal Frequency-Division Multiplexing */
IEEE802154_PHY_MR_FSK /**< Multi-Rate Frequency Shift Keying */
IEEE802154_PHY_MR_FSK, /**< Multi-Rate Frequency Shift Keying */

IEEE802154_PHY_NO_OP, /**< don't change PHY configuration */
} ieee802154_phy_mode_t;

/**
* @brief 802.15.4 forward error correction schemes
*/
enum {
typedef enum {
IEEE802154_FEC_NONE, /**< no forward error correction */
IEEE802154_FEC_NRNSC, /**< non-recursive and non-systematic code */
IEEE802154_FEC_RSC /**< recursive and systematic code */
};
} ieee802154_mr_fsk_fec_t;

/**
* @brief 802.15.4 MR-FSK symbol rates
*/
typedef enum {
IEEE802154_MR_FSK_SRATE_50K, /**< 50k Symbols/s */
IEEE802154_MR_FSK_SRATE_100K, /**< 100k Symbols/s */
IEEE802154_MR_FSK_SRATE_150K, /**< 150k Symbols/s */
IEEE802154_MR_FSK_SRATE_200K, /**< 200k Symbols/s */
IEEE802154_MR_FSK_SRATE_300K, /**< 300k Symbols/s */
IEEE802154_MR_FSK_SRATE_400K, /**< 400k Symbols/s */
} ieee802154_mr_fsk_srate_t;

/**
* @brief 802.15.4 MR-OQPSK chip rates
*/
typedef enum {
IEEE802154_MR_OQPSK_CHIPS_100, /**< 100 kChip/s */
IEEE802154_MR_OQPSK_CHIPS_200, /**< 200 kChip/s */
IEEE802154_MR_OQPSK_CHIPS_1000, /**< 1000 kChip/s */
IEEE802154_MR_OQPSK_CHIPS_2000, /**< 2000 kChip/s */
} ieee802154_mr_oqpsk_chips_t;

/**
* @brief Get the minimum preamble length for a given symbol rate
*
* From IEEE 802.15.4g Table 6-64
*
* @param[in] srate symbol rate
* @return preamble length in bytes
*/
static inline uint8_t ieee802154_mr_fsk_plen(ieee802154_mr_fsk_srate_t srate)
{
switch (srate) {
case IEEE802154_MR_FSK_SRATE_50K:
return 2;
case IEEE802154_MR_FSK_SRATE_100K:
return 3;
case IEEE802154_MR_FSK_SRATE_150K:
case IEEE802154_MR_FSK_SRATE_200K:
case IEEE802154_MR_FSK_SRATE_300K:
return 8;
case IEEE802154_MR_FSK_SRATE_400K:
return 10;
}

return 0;
}

/**
* @brief Special address definitions
Expand Down Expand Up @@ -256,6 +319,62 @@ extern const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN];
#define CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE (2U)
#endif

/**
* @brief IEEE802.15.4 MR-OQPSK default chip rate
*/
#ifndef CONFIG_IEEE802154_MR_OQPSK_DEFAULT_CHIPS
#define CONFIG_IEEE802154_MR_OQPSK_DEFAULT_CHIPS IEEE802154_MR_OQPSK_CHIPS_1000
#endif

/**
* @brief IEEE802.15.4 MR-OQPSK default rate mode
*/
#ifndef CONFIG_IEEE802154_MR_OQPSK_DEFAULT_RATE
#define CONFIG_IEEE802154_MR_OQPSK_DEFAULT_RATE (2U)
#endif

/**
* @brief IEEE802.15.4 MR-OFDM default modulation option
*/
#ifndef CONFIG_IEEE802154_MR_OFDM_DEFAULT_OPTION
#define CONFIG_IEEE802154_MR_OFDM_DEFAULT_OPTION (2U)
#endif

/**
* @brief IEEE802.15.4 MR-OFDM default Modulation & Coding Scheme
*/
#ifndef CONFIG_IEEE802154_MR_OFDM_DEFAULT_SCHEME
#define CONFIG_IEEE802154_MR_OFDM_DEFAULT_SCHEME (2U)
#endif

/**
* @brief IEEE802.15.4 MR-FSK default symbol rate
*/
#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_SRATE
#define CONFIG_IEEE802154_MR_FSK_DEFAULT_SRATE IEEE802154_MR_FSK_SRATE_200K
#endif

/**
* @brief IEEE802.15.4 MR-FSK default modulation index, fraction of 64
*/
#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_IDX
#define CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_IDX (64U)
#endif

/**
* @brief IEEE802.15.4 MR-FSK default modulation order
*/
#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_ORD
#define CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_ORD (2U)
#endif

/**
* @brief IEEE802.15.4 MR-FSK default error correction mode
*/
#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_FEC
#define CONFIG_IEEE802154_MR_FSK_DEFAULT_FEC IEEE802154_FEC_NONE
#endif

/**
* @brief IEEE802.15.4 default PANID
*/
Expand Down
29 changes: 29 additions & 0 deletions sys/include/net/ieee802154/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,35 @@ typedef struct {
int8_t pow; /**< TX power in dBm */
} ieee802154_phy_conf_t;

/**
* @brief extension for IEEE 802.15.4g MR-OQPSK PHY
*/
typedef struct {
ieee802154_phy_conf_t super; /**< common settings */
ieee802154_mr_oqpsk_chips_t chips; /**< chip rate */
uint8_t rate_mode; /**< rate mode */
} ieee802154_mr_oqpsk_conf_t;

/**
* @brief extension for IEEE 802.15.4g MR-ODFM PHY
*/
typedef struct {
ieee802154_phy_conf_t super; /**< common settings */
uint8_t option; /**< OFDM Option */
uint8_t scheme; /**< Modulation & Coding Scheme */
} ieee802154_mr_ofdm_conf_t;

/**
* @brief extension for IEEE 802.15.4g MR-FSK PHY
*/
typedef struct {
ieee802154_phy_conf_t super; /**< common settings */
ieee802154_mr_fsk_srate_t srate; /**< symbol rate */
uint8_t mod_ord; /**< modulation order, 2 or 4 */
uint8_t mod_idx; /**< modulation index */
ieee802154_mr_fsk_fec_t fec; /**< forward error correction */
} ieee802154_mr_fsk_conf_t;

/**
* @brief IEEE 802.15.4 radio operations
*/
Expand Down
43 changes: 29 additions & 14 deletions sys/include/net/ieee802154/submac.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ struct ieee802154_submac {
const ieee802154_submac_cb_t *cb; /**< pointer to the SubMAC callbacks */
ieee802154_csma_be_t be; /**< CSMA-CA backoff exponent params */
bool wait_for_ack; /**< SubMAC is waiting for an ACK frame */
uint16_t ack_timeout_us; /**< ACK timeout in µs */
uint16_t csma_backoff_us; /**< CSMA sender backoff period in µs */
uint16_t panid; /**< IEEE 802.15.4 PAN ID */
uint16_t channel_num; /**< IEEE 802.15.4 channel number */
uint8_t channel_page; /**< IEEE 802.15.4 channel page */
Expand Down Expand Up @@ -310,9 +312,7 @@ static inline ieee802154_phy_mode_t ieee802154_get_phy_mode(
* @brief Set IEEE 802.15.4 PHY configuration (channel, TX power)
*
* @param[in] submac pointer to the SubMAC descriptor
* @param[in] channel_num channel number
* @param[in] channel_page channel page
* @param[in] tx_pow transmission power (in dBm)
* @param[in] conf pointer to the PHY configuration
*
* @return 0 on success
* @return -ENOTSUP if the PHY settings are not supported
Expand All @@ -321,8 +321,7 @@ static inline ieee802154_phy_mode_t ieee802154_get_phy_mode(
* @ref ieee802154_submac_cb_t::tx_done
* @return negative errno on error
*/
int ieee802154_set_phy_conf(ieee802154_submac_t *submac, uint16_t channel_num,
uint8_t channel_page, int8_t tx_pow);
int ieee802154_set_phy_conf(ieee802154_submac_t *submac, const ieee802154_phy_conf_t *conf);

/**
* @brief Set IEEE 802.15.4 channel number
Expand All @@ -342,8 +341,14 @@ int ieee802154_set_phy_conf(ieee802154_submac_t *submac, uint16_t channel_num,
static inline int ieee802154_set_channel_number(ieee802154_submac_t *submac,
uint16_t channel_num)
{
return ieee802154_set_phy_conf(submac, channel_num, submac->channel_page,
submac->tx_pow);
const ieee802154_phy_conf_t conf = {
.phy_mode = IEEE802154_PHY_NO_OP,
.channel = channel_num,
.page = submac->channel_page,
.pow = submac->tx_pow,
};

return ieee802154_set_phy_conf(submac, &conf);
}

/**
Expand All @@ -364,8 +369,14 @@ static inline int ieee802154_set_channel_number(ieee802154_submac_t *submac,
static inline int ieee802154_set_channel_page(ieee802154_submac_t *submac,
uint16_t channel_page)
{
return ieee802154_set_phy_conf(submac, submac->channel_num, channel_page,
submac->tx_pow);
const ieee802154_phy_conf_t conf = {
.phy_mode = IEEE802154_PHY_NO_OP,
.channel = submac->channel_num,
.page = channel_page,
.pow = submac->tx_pow,
};

return ieee802154_set_phy_conf(submac, &conf);
}

/**
Expand All @@ -386,8 +397,14 @@ static inline int ieee802154_set_channel_page(ieee802154_submac_t *submac,
static inline int ieee802154_set_tx_power(ieee802154_submac_t *submac,
int8_t tx_pow)
{
return ieee802154_set_phy_conf(submac, submac->channel_num,
submac->channel_page, tx_pow);
const ieee802154_phy_conf_t conf = {
.phy_mode = IEEE802154_PHY_NO_OP,
.channel = submac->channel_num,
.page = submac->channel_page,
.pow = tx_pow,
};

return ieee802154_set_phy_conf(submac, &conf);
}

/**
Expand Down Expand Up @@ -501,10 +518,8 @@ int ieee802154_submac_init(ieee802154_submac_t *submac, const network_uint16_t *
* @note This function should be implemented by the user of the SubMAC.
*
* @param[in] submac pointer to the SubMAC descriptor
* @param[in] us microseconds until the ACK timeout timer is fired
*/
extern void ieee802154_submac_ack_timer_set(ieee802154_submac_t *submac,
uint16_t us);
extern void ieee802154_submac_ack_timer_set(ieee802154_submac_t *submac);

/**
* @brief Cancel the ACK timeout timer
Expand Down
Loading

0 comments on commit f67055c

Please sign in to comment.