Skip to content

Commit

Permalink
ieee802154/submac: let ieee802154_submac_config_phy() take whole struct
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 25, 2023
1 parent 83b6c30 commit 8b491b3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 31 deletions.
4 changes: 3 additions & 1 deletion sys/include/net/ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
37 changes: 26 additions & 11 deletions sys/include/net/ieee802154/submac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
52 changes: 33 additions & 19 deletions sys/net/link_layer/ieee802154/submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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) {}

Expand Down

0 comments on commit 8b491b3

Please sign in to comment.