Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sys/net/link_layer/ieee802154/submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "net/ieee802154.h"
#include "net/ieee802154/submac.h"
#include "ztimer.h"
#include "random.h"
#include "atomic_utils.h"
#include "compiler_hints.h"
#include "kernel_defines.h"
#include "errno.h"

Check warning on line 24 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -15,10 +15,11 @@ #include <string.h> -#include "net/ieee802154.h" -#include "net/ieee802154/submac.h" -#include "ztimer.h" -#include "random.h" + #include "atomic_utils.h" #include "compiler_hints.h" -#include "kernel_defines.h" #include "errno.h" +#include "kernel_defines.h" +#include "net/ieee802154.h" +#include "net/ieee802154/submac.h" +#include "random.h" +#include "ztimer.h"
#define ENABLE_DEBUG 0
#include "debug.h"

Expand Down Expand Up @@ -102,27 +102,27 @@
const char *name;
} ieee802154_fsm_state_mapping_t;

static const ieee802154_fsm_state_mapping_t states_mapping[] = {
{ _fsm_state_invalid, "INVALID" },
{ _fsm_state_rx, "RX" },
{ _fsm_state_idle, "IDLE" },
{ _fsm_state_prepare, "PREPARE" },
{ _fsm_state_tx, "TX" },
{ _fsm_state_wait_for_ack, "WAIT_FOR_ACK" },
{ _fsm_state_tx_ack, "TX_ACK" },

Check warning on line 112 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -105,8 +106,5 @@ static const ieee802154_fsm_state_mapping_t states_mapping[] = { - { _fsm_state_invalid, "INVALID" }, - { _fsm_state_rx, "RX" }, - { _fsm_state_idle, "IDLE" }, - { _fsm_state_prepare, "PREPARE" }, - { _fsm_state_tx, "TX" }, - { _fsm_state_wait_for_ack, "WAIT_FOR_ACK" }, + { _fsm_state_invalid, "INVALID" }, { _fsm_state_rx, "RX" }, + { _fsm_state_idle, "IDLE" }, { _fsm_state_prepare, "PREPARE" }, + { _fsm_state_tx, "TX" }, { _fsm_state_wait_for_ack, "WAIT_FOR_ACK" }, { _fsm_state_tx_ack, "TX_ACK" },
};

static const char *str_ev[] = {
"ENTRY",
"EXIT",
"TX_DONE",
"RX_DONE",
"CRC_ERROR",
"ACK_TIMEOUT",
"REQUEST_TX",
"REQUEST_SET_RX_ON",
"REQUEST_SET_IDLE",
};

Check warning on line 125 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -115,11 +113,4 @@ static const char *str_ev[] = { - "ENTRY", - "EXIT", - "TX_DONE", - "RX_DONE", - "CRC_ERROR", - "ACK_TIMEOUT", - "REQUEST_TX", - "REQUEST_SET_RX_ON", - "REQUEST_SET_IDLE", + "ENTRY", "EXIT", "TX_DONE", "RX_DONE", "CRC_ERROR", + "ACK_TIMEOUT", "REQUEST_TX", "REQUEST_SET_RX_ON", "REQUEST_SET_IDLE", };

MAYBE_UNUSED
static const char *get_state_name(ieee802154_fsm_state_cb_t state)
Expand Down Expand Up @@ -154,10 +154,10 @@
{
if (!IS_USED(MODULE_IEEE802154_SUBMAC_SOFT_FRAME_RETRANS)) {
return true;
}
return ieee802154_radio_has_frame_retrans(dev) ||
ieee802154_radio_has_irq_ack_timeout(dev);
}

Check warning on line 160 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -157,4 +148,3 @@ } - return ieee802154_radio_has_frame_retrans(dev) || - ieee802154_radio_has_irq_ack_timeout(dev); + return ieee802154_radio_has_frame_retrans(dev) || ieee802154_radio_has_irq_ack_timeout(dev); }

/**
* @brief If softack module is used, we will check if submac should really send ack
Expand All @@ -183,14 +183,25 @@
!IS_USED(MODULE_IEEE802154_SUBMAC_SOFT_FRAME_RETRANS)) {
return true;
}

return ieee802154_radio_has_frame_retrans(dev) ||
ieee802154_radio_has_auto_csma(dev);
}

Check warning on line 189 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -186,4 +176,3 @@ - return ieee802154_radio_has_frame_retrans(dev) || - ieee802154_radio_has_auto_csma(dev); + return ieee802154_radio_has_frame_retrans(dev) || ieee802154_radio_has_auto_csma(dev); }

/**
* @brief Enable/disable CCA before the next transmission.
*/
static inline void _set_cca_before_tx(ieee802154_dev_t *dev, bool enable)
{
if (!_does_handle_csma(dev)) {
/* retries == 0: single CCA, retries < 0: no CCA (see set_csma_params) */
ieee802154_radio_set_csma_params(dev, NULL, enable ? 0 : -1);
}
}

static inline void _set_csma_backoff_period(ieee802154_submac_t *submac,
uint16_t period_us)
{

Check warning on line 204 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -201,4 +190,3 @@ -static inline void _set_csma_backoff_period(ieee802154_submac_t *submac, - uint16_t period_us) +static inline void _set_csma_backoff_period(ieee802154_submac_t *submac, uint16_t period_us) {
#if IS_USED(MODULE_IEEE802154_SUBMAC_SOFT_CSMA_CA)
submac->csma_backoff_us = period_us;
#else
Expand Down Expand Up @@ -347,7 +358,7 @@
return _state_transition(&submac->fsm, _fsm_state_idle);
}

static inline void _print_state_transition(ieee802154_fsm_state_cb_t old, ieee802154_fsm_state_cb_t new,

Check warning on line 361 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
ieee802154_fsm_ev_t ev)
{
DEBUG("IEEE802154 submac: %s--(%s)->%s\n", get_state_name(old), str_ev[ev], get_state_name(new));
Expand Down Expand Up @@ -571,6 +582,7 @@
else if (submac->tx_ftype == IEEE802154_FCF_TYPE_ACK && !_does_send_ack(dev)) {
/* no backoff for ACK frames but wait for SIFSPeriod */
ztimer_sleep(ZTIMER_USEC, SIFS_PERIOD_US);
_set_cca_before_tx(dev, false);
tx_state = _fsm_state_tx_ack;
}
while (ieee802154_radio_request_transmit(dev) == -EBUSY) {}
Expand Down Expand Up @@ -747,6 +759,7 @@
DEBUG("IEEE802154 submac: ACK sent, status %d\n", (int)info.status);
res = ieee802154_radio_set_idle(dev, true);
assert(res >= 0);
_set_cca_before_tx(dev, true);
submac->cb->rx_done(submac);
return _state_transition(&submac->fsm, _fsm_state_idle);
}
Expand Down Expand Up @@ -991,12 +1004,12 @@
if (conf->fec) {
ack_len *= 2;
}

return _mr_fsk_csma_backoff_period_us(conf)
+ IEEE802154G_ATURNAROUNDTIME_US
/* long Preamble + SFD; SFD=2 */
+ ((fsk_pl * 8 + 2) + ack_len) * 8 * IEEE802154_MR_FSK_SYMBOL_TIME_US;
}

Check warning on line 1012 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -1007,6 +977,6 @@ - return _mr_fsk_csma_backoff_period_us(conf) - + IEEE802154G_ATURNAROUNDTIME_US - /* long Preamble + SFD; SFD=2 */ - + ((fsk_pl * 8 + 2) + ack_len) * 8 * IEEE802154_MR_FSK_SYMBOL_TIME_US; + return _mr_fsk_csma_backoff_period_us(conf) + + IEEE802154G_ATURNAROUNDTIME_US + /* long Preamble + SFD; SFD=2 */ + + ((fsk_pl * 8 + 2) + ack_len) * 8 * IEEE802154_MR_FSK_SYMBOL_TIME_US; }

static int ieee802154_submac_config_phy(ieee802154_submac_t *submac,
const ieee802154_phy_conf_t *conf)
Expand Down Expand Up @@ -1133,14 +1146,14 @@
conf.super.channel = submac->channel_num;
conf.super.pow = submac->tx_pow;

ieee802154_submac_config_phy(submac, &conf.super);
ieee802154_radio_set_cca_threshold(dev,
CONFIG_IEEE802154_CCA_THRESH_DEFAULT);

Check warning on line 1152 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -1149,4 +1119,3 @@ ieee802154_submac_config_phy(submac, &conf.super); - ieee802154_radio_set_cca_threshold(dev, - CONFIG_IEEE802154_CCA_THRESH_DEFAULT); + ieee802154_radio_set_cca_threshold(dev, CONFIG_IEEE802154_CCA_THRESH_DEFAULT);
if (ieee802154_radio_has_frame_retrans(&submac->dev)) {
ieee802154_radio_set_frame_retrans(&submac->dev,
CONFIG_IEEE802154_DEFAULT_MAX_FRAME_RETRANS);
}

Check warning on line 1156 in sys/net/link_layer/ieee802154/submac.c

View workflow job for this annotation

GitHub Actions / static-tests

clang-format proposes the following patch

@@ -1154,3 +1123,3 @@ ieee802154_radio_set_frame_retrans(&submac->dev, - CONFIG_IEEE802154_DEFAULT_MAX_FRAME_RETRANS); + CONFIG_IEEE802154_DEFAULT_MAX_FRAME_RETRANS); }

_init_csma(submac);

Expand Down
Loading