From 8b491b314406fbcf6e9ad3d0e39bd3c75a0c106c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 25 May 2023 15:23:38 +0200 Subject: [PATCH] ieee802154/submac: let ieee802154_submac_config_phy() take whole struct --- sys/include/net/ieee802154.h | 4 +- sys/include/net/ieee802154/submac.h | 37 ++++++++++++------ sys/net/link_layer/ieee802154/submac.c | 52 ++++++++++++++++---------- 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/sys/include/net/ieee802154.h b/sys/include/net/ieee802154.h index 65dd7f75e3229..c9799ee713baf 100644 --- a/sys/include/net/ieee802154.h +++ b/sys/include/net/ieee802154.h @@ -176,7 +176,9 @@ 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; /** diff --git a/sys/include/net/ieee802154/submac.h b/sys/include/net/ieee802154/submac.h index d8923fa22822e..a41de6cc15405 100644 --- a/sys/include/net/ieee802154/submac.h +++ b/sys/include/net/ieee802154/submac.h @@ -312,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 @@ -323,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 @@ -344,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); } /** @@ -366,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); } /** @@ -388,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); } /** diff --git a/sys/net/link_layer/ieee802154/submac.c b/sys/net/link_layer/ieee802154/submac.c index 57a15634993ed..a6e98921f9640 100644 --- a/sys/net/link_layer/ieee802154/submac.c +++ b/sys/net/link_layer/ieee802154/submac.c @@ -496,7 +496,7 @@ static inline uint8_t _mr_oqpsk_ack_psdu_duration_syms(uint8_t chips, uint8_t mo return (Npsdu + Ns/2) / Ns + (Npsdu + 8 * Ns) / (16 * Ns); } -static uint16_t _mr_oqpsk_ack_timeout_us(const ieee802154_mr_oqpks_conf_t *conf) +static inline uint16_t _mr_oqpsk_ack_timeout_us(const ieee802154_mr_oqpks_conf_t *conf) { /* see 802.15.4g-2012, p. 30 */ uint16_t symbols = _mr_oqpsk_cca_duration_syms(conf->chips) @@ -508,7 +508,7 @@ static uint16_t _mr_oqpsk_ack_timeout_us(const ieee802154_mr_oqpks_conf_t *conf) + IEEE802154G_ATURNAROUNDTIME_US; } -static uint16_t _mr_oqpsk_csma_backoff_period_us(const ieee802154_mr_oqpks_conf_t *conf) +static inline uint16_t _mr_oqpsk_csma_backoff_period_us(const ieee802154_mr_oqpks_conf_t *conf) { return _mr_oqpsk_cca_duration_syms(conf->chips) * _mr_oqpsk_symbol_duration_us(conf->chips) + IEEE802154G_ATURNAROUNDTIME_US; @@ -522,10 +522,14 @@ static int ieee802154_submac_config_phy(ieee802154_submac_t *submac, submac->ack_timeout_us = ACK_TIMEOUT_US; submac->csma_backoff_us = CSMA_SENDER_BACKOFF_PERIOD_UNIT_US; break; +#ifdef MODULE_NETDEV_IEEE802154_MR_OQPSK case IEEE802154_PHY_MR_OQPSK: submac->ack_timeout_us = _mr_oqpsk_ack_timeout_us((void *)conf); submac->csma_backoff_us = _mr_oqpsk_csma_backoff_period_us((void *)conf); break; +#endif + case IEEE802154_PHY_NO_OP: + break; default: return -EINVAL; } @@ -601,13 +605,26 @@ int ieee802154_submac_init(ieee802154_submac_t *submac, const network_uint16_t * ieee802154_radio_config_addr_filter(dev, IEEE802154_AF_PANID, &submac->panid); /* Configure PHY settings (mode, channel, TX power) */ - ieee802154_phy_conf_t conf = - { .phy_mode = submac->phy_mode, - .channel = submac->channel_num, - .page = submac->channel_page, - .pow = submac->tx_pow }; + union { + ieee802154_phy_conf_t super; +#ifdef MODULE_NETDEV_IEEE802154_MR_OQPSK + ieee802154_mr_oqpks_conf_t mr_oqpsk; +#endif + } conf; + +#ifdef MODULE_NETDEV_IEEE802154_MR_OQPSK + if (submac->phy_mode == IEEE802154_PHY_MR_OQPSK) { + conf.mr_oqpsk.chips = CONFIG_IEEE802154_MR_OQPSK_DEFAULT_CHIPS; + conf.mr_oqpsk.rate_mode = CONFIG_IEEE802154_MR_OQPSK_DEFAULT_RATE; + } +#endif - ieee802154_submac_config_phy(submac, &conf); + conf.super.phy_mode = submac->phy_mode; + conf.super.channel = submac->channel_num; + conf.super.page = submac->channel_page; + conf.super.pow = submac->tx_pow; + + ieee802154_submac_config_phy(submac, &conf.super); ieee802154_radio_set_cca_threshold(dev, CONFIG_IEEE802154_CCA_THRESH_DEFAULT); assert(res >= 0); @@ -617,15 +634,9 @@ int ieee802154_submac_init(ieee802154_submac_t *submac, const network_uint16_t * return res; } -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) { ieee802154_dev_t *dev = &submac->dev; - const ieee802154_phy_conf_t conf = - { .phy_mode = submac->phy_mode, - .channel = channel_num, - .page = channel_page, - .pow = tx_pow }; int res; ieee802154_fsm_state_t current_state = submac->fsm_state; @@ -641,12 +652,15 @@ int ieee802154_set_phy_conf(ieee802154_submac_t *submac, uint16_t channel_num, } } - res = ieee802154_submac_config_phy(submac, &conf); + res = ieee802154_submac_config_phy(submac, conf); if (res >= 0) { - submac->channel_num = channel_num; - submac->channel_page = channel_page; - submac->tx_pow = tx_pow; + submac->channel_num = conf->channel; + submac->channel_page = conf->page; + submac->tx_pow = conf->pow; + if (conf->phy_mode != IEEE802154_PHY_NO_OP) { + submac->phy_mode = conf->phy_mode; + } } while (ieee802154_radio_confirm_set_idle(dev) == -EAGAIN) {}