From 8c4760050ef89683b5d6c4766256ced99a364498 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Fri, 8 Mar 2019 20:39:18 +0100 Subject: [PATCH 1/3] nrf802154: Change timer frequency to match symbols rate ieee802.15.4 specifies 40 symbols as LIFS value and 12 symbols as SIFS value. Furthermore, the 2.4Ghz DSSS mode has a symbol rate of 62.5Ksymbols/s. To have the LIFS and SIFS in the code match the timings from the specification, the TIMER_FREQ must match the symbol rate of 62.5Ksymbol/s such that one tick of the timer equals one symbol in time. --- cpu/nrf52/radio/nrf802154/nrf802154.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/nrf52/radio/nrf802154/nrf802154.c b/cpu/nrf52/radio/nrf802154/nrf802154.c index 297dae83de..c134c08676 100644 --- a/cpu/nrf52/radio/nrf802154/nrf802154.c +++ b/cpu/nrf52/radio/nrf802154/nrf802154.c @@ -68,7 +68,7 @@ static uint8_t txbuf[IEEE802154_FRAME_LEN_MAX + 3]; /* len PHR + PSDU + LQI */ #define LIFS (40U) #define SIFS (12U) #define SIFS_MAXPKTSIZE (18U) -#define TIMER_FREQ (250000UL) +#define TIMER_FREQ (62500UL) static volatile uint8_t _state; static mutex_t _txlock; From de2f193da345339d227338da533cb5e0449ead9d Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Fri, 8 Mar 2019 20:42:37 +0100 Subject: [PATCH 2/3] nrf802154: Fix timer behaviour of the IFS timer The timer_clear function doesn't clear the hardware timer counter, but is designed to clear the allocation of the channel. The consequence is that the IFS timer here is not set to zero in the callback, but only stopped at the current value. When the timer is started again, it has to count the full timer range until it matches the timeout value again. This commit fixes this issue by using timer_set instead of timer_set_absolute. This way the current timer value (when the timer is stopped) is read and the IFS timeout value is added to the current timer value. --- cpu/nrf52/radio/nrf802154/nrf802154.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/nrf52/radio/nrf802154/nrf802154.c b/cpu/nrf52/radio/nrf802154/nrf802154.c index c134c08676..ea2a1b2de1 100644 --- a/cpu/nrf52/radio/nrf802154/nrf802154.c +++ b/cpu/nrf52/radio/nrf802154/nrf802154.c @@ -189,7 +189,6 @@ static void _timer_cb(void *arg, int chan) (void)chan; mutex_unlock(&_txlock); timer_stop(NRF802154_TIMER); - timer_clear(NRF802154_TIMER, 0); } static int _init(netdev_t *dev) @@ -199,6 +198,7 @@ static int _init(netdev_t *dev) int result = timer_init(NRF802154_TIMER, TIMER_FREQ, _timer_cb, NULL); assert(result >= 0); (void)result; + timer_stop(NRF802154_TIMER); /* initialize local variables */ mutex_init(&_txlock); @@ -285,7 +285,7 @@ static int _send(netdev_t *dev, const iolist_t *iolist) /* set interframe spacing based on packet size */ unsigned int ifs = (len + IEEE802154_FCS_LEN > SIFS_MAXPKTSIZE) ? LIFS : SIFS; - timer_set_absolute(NRF802154_TIMER, 0, ifs); + timer_set(NRF802154_TIMER, 0, ifs); return len; } From 658fb0651ef60ed32a03fee0233f6b0e82600fb9 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Sun, 10 Mar 2019 22:24:19 +0100 Subject: [PATCH 3/3] nrf802154: Disable hardware IFS handling --- cpu/nrf52/radio/nrf802154/nrf802154.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/nrf52/radio/nrf802154/nrf802154.c b/cpu/nrf52/radio/nrf802154/nrf802154.c index ea2a1b2de1..d48f27e710 100644 --- a/cpu/nrf52/radio/nrf802154/nrf802154.c +++ b/cpu/nrf52/radio/nrf802154/nrf802154.c @@ -232,6 +232,9 @@ static int _init(netdev_t *dev) NRF_RADIO->CRCPOLY = 0x011021; NRF_RADIO->CRCINIT = 0; + /* Disable the hardware IFS handling */ + NRF_RADIO->MODECNF0 |= RADIO_MODECNF0_RU_Msk; + /* assign default addresses */ luid_get(nrf802154_dev.long_addr, IEEE802154_LONG_ADDRESS_LEN); memcpy(nrf802154_dev.short_addr, &nrf802154_dev.long_addr[6],