From 636e87f5106faa195235f6fa76b728c183804a65 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Tue, 16 Mar 2021 19:28:53 +0100 Subject: [PATCH] [nrf528xx] improve CSL phase calculation (#6287) Fill a CSL Phase IE with a value for the CSL transmitter to aim at the center of the receive window, instead of aiming at the beginning. --- examples/platforms/nrf528xx/src/radio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/platforms/nrf528xx/src/radio.c b/examples/platforms/nrf528xx/src/radio.c index 7e5337fcd..c3c78ac71 100644 --- a/examples/platforms/nrf528xx/src/radio.c +++ b/examples/platforms/nrf528xx/src/radio.c @@ -51,7 +51,6 @@ #include #include #include -#include #include #include @@ -119,9 +118,10 @@ static uint8_t sEnergyDetectionChannel; static int8_t sEnergyDetected; #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE -static uint32_t sCslPeriod; -static uint32_t sCslSampleTime; -static const uint8_t sCslIeHeader[OT_IE_HEADER_SIZE] = {CSL_IE_HEADER_BYTES_LO, CSL_IE_HEADER_BYTES_HI}; +static uint32_t sCslPeriod; +static uint32_t sCslSampleTime; +static const uint32_t sCslSampleDur = OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW * OT_US_PER_TEN_SYMBOLS; +static const uint8_t sCslIeHeader[OT_IE_HEADER_SIZE] = {CSL_IE_HEADER_BYTES_LO, CSL_IE_HEADER_BYTES_HI}; #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE typedef enum @@ -1068,8 +1068,9 @@ static uint16_t getCslPhase() { uint32_t curTime = otPlatAlarmMicroGetNow(); uint32_t cslPeriodInUs = sCslPeriod * OT_US_PER_TEN_SYMBOLS; - uint32_t diff = (cslPeriodInUs - (curTime % cslPeriodInUs) + (sCslSampleTime % cslPeriodInUs)) % cslPeriodInUs; - + uint32_t diff = + (cslPeriodInUs - (curTime % cslPeriodInUs) + (sCslSampleTime % cslPeriodInUs) + (sCslSampleDur / 2)) % + cslPeriodInUs; return (uint16_t)(diff / OT_US_PER_TEN_SYMBOLS + 1); } #endif