From 8c34040d7413da1d3463344681ef19f9e97a3ea3 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Fri, 28 Feb 2020 13:31:36 -0300 Subject: [PATCH] [efr32] Radio: don't abort current operation on switching to idle (#4586) --- examples/platforms/efr32mg12/Makefile.am | 2 +- .../platforms/efr32mg12/Makefile.platform.am | 2 +- examples/platforms/efr32mg12/alarm.c | 2 +- .../efr32mg12/brd4161a/board_config.h | 1 + .../efr32mg12/brd4166a/board_config.h | 1 + .../efr32mg12/brd4304a/board_config.h | 1 + .../efr32mg12/crypto/efr32-mbedtls-config.h | 2 +- examples/platforms/efr32mg12/diag.c | 2 +- examples/platforms/efr32mg12/entropy.c | 2 +- examples/platforms/efr32mg12/fem-control.c | 2 +- examples/platforms/efr32mg12/flash.c | 2 +- examples/platforms/efr32mg12/misc.c | 2 +- .../openthread-core-efr32-config-check.h | 2 +- .../efr32mg12/openthread-core-efr32-config.h | 2 +- examples/platforms/efr32mg12/platform-band.h | 2 +- examples/platforms/efr32mg12/platform-efr32.h | 2 +- examples/platforms/efr32mg12/radio.c | 8 +- .../efr32mg12/sleepy-demo/Makefile.am | 2 +- .../sleepy-demo/sleepy-demo-ftd/Makefile.am | 2 +- .../sleepy-demo/sleepy-demo-ftd/main.c | 2 +- .../sleepy-demo/sleepy-demo-mtd/Makefile.am | 2 +- .../sleepy-demo/sleepy-demo-mtd/main.c | 2 +- examples/platforms/efr32mg12/startup-gcc.c | 2 +- examples/platforms/efr32mg12/system.c | 3 +- examples/platforms/efr32mg12/uart.c | 2 +- .../efr32mg13/brd4168a/board_config.h | 4 + .../efr32mg13/openthread-core-efr32-config.h | 24 +- examples/platforms/efr32mg13/radio.c | 222 +++++++++++++----- 28 files changed, 196 insertions(+), 108 deletions(-) diff --git a/examples/platforms/efr32mg12/Makefile.am b/examples/platforms/efr32mg12/Makefile.am index 62890aa2a..e1128aca0 100644 --- a/examples/platforms/efr32mg12/Makefile.am +++ b/examples/platforms/efr32mg12/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, The OpenThread Authors. +# Copyright (c) 2020, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/Makefile.platform.am b/examples/platforms/efr32mg12/Makefile.platform.am index 6ea500344..fe7f00672 100644 --- a/examples/platforms/efr32mg12/Makefile.platform.am +++ b/examples/platforms/efr32mg12/Makefile.platform.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, The OpenThread Authors. +# Copyright (c) 2020, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/alarm.c b/examples/platforms/efr32mg12/alarm.c index ab0a5c6bd..71a39c089 100644 --- a/examples/platforms/efr32mg12/alarm.c +++ b/examples/platforms/efr32mg12/alarm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/brd4161a/board_config.h b/examples/platforms/efr32mg12/brd4161a/board_config.h index fdcf413b2..82db41b1d 100644 --- a/examples/platforms/efr32mg12/brd4161a/board_config.h +++ b/examples/platforms/efr32mg12/brd4161a/board_config.h @@ -36,6 +36,7 @@ #define __BOARD_CONFIG_H__ #define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Dev board suppports OQPSK modulation in 2.4GHz band. +#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0 /// Dev board doesn't support OQPSK modulation in 915MHz band. #ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT #define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c diff --git a/examples/platforms/efr32mg12/brd4166a/board_config.h b/examples/platforms/efr32mg12/brd4166a/board_config.h index 3e5ff293e..fa5c9b27d 100644 --- a/examples/platforms/efr32mg12/brd4166a/board_config.h +++ b/examples/platforms/efr32mg12/brd4166a/board_config.h @@ -36,6 +36,7 @@ #define __BOARD_CONFIG_H__ #define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Dev board suppports OQPSK modulation in 2.4GHz band. +#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0 /// Dev board doesn't support OQPSK modulation in 915MHz band. #ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT #define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c diff --git a/examples/platforms/efr32mg12/brd4304a/board_config.h b/examples/platforms/efr32mg12/brd4304a/board_config.h index fdcf413b2..82db41b1d 100644 --- a/examples/platforms/efr32mg12/brd4304a/board_config.h +++ b/examples/platforms/efr32mg12/brd4304a/board_config.h @@ -36,6 +36,7 @@ #define __BOARD_CONFIG_H__ #define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Dev board suppports OQPSK modulation in 2.4GHz band. +#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0 /// Dev board doesn't support OQPSK modulation in 915MHz band. #ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT #define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c diff --git a/examples/platforms/efr32mg12/crypto/efr32-mbedtls-config.h b/examples/platforms/efr32mg12/crypto/efr32-mbedtls-config.h index 4a887904c..ba7058871 100644 --- a/examples/platforms/efr32mg12/crypto/efr32-mbedtls-config.h +++ b/examples/platforms/efr32mg12/crypto/efr32-mbedtls-config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/diag.c b/examples/platforms/efr32mg12/diag.c index f88ac7018..a7c335754 100644 --- a/examples/platforms/efr32mg12/diag.c +++ b/examples/platforms/efr32mg12/diag.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/entropy.c b/examples/platforms/efr32mg12/entropy.c index f085a590c..2b196bbba 100644 --- a/examples/platforms/efr32mg12/entropy.c +++ b/examples/platforms/efr32mg12/entropy.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/fem-control.c b/examples/platforms/efr32mg12/fem-control.c index 5ee527eab..f66415c19 100644 --- a/examples/platforms/efr32mg12/fem-control.c +++ b/examples/platforms/efr32mg12/fem-control.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/flash.c b/examples/platforms/efr32mg12/flash.c index 83ce5a46f..b3cafff06 100644 --- a/examples/platforms/efr32mg12/flash.c +++ b/examples/platforms/efr32mg12/flash.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/misc.c b/examples/platforms/efr32mg12/misc.c index 23c1510fb..4b2076fdc 100644 --- a/examples/platforms/efr32mg12/misc.c +++ b/examples/platforms/efr32mg12/misc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/openthread-core-efr32-config-check.h b/examples/platforms/efr32mg12/openthread-core-efr32-config-check.h index b1ed3923a..2c722a692 100644 --- a/examples/platforms/efr32mg12/openthread-core-efr32-config-check.h +++ b/examples/platforms/efr32mg12/openthread-core-efr32-config-check.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/openthread-core-efr32-config.h b/examples/platforms/efr32mg12/openthread-core-efr32-config.h index e34b16536..b9602c1ef 100644 --- a/examples/platforms/efr32mg12/openthread-core-efr32-config.h +++ b/examples/platforms/efr32mg12/openthread-core-efr32-config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/platform-band.h b/examples/platforms/efr32mg12/platform-band.h index cba0a64a4..7c4d91255 100644 --- a/examples/platforms/efr32mg12/platform-band.h +++ b/examples/platforms/efr32mg12/platform-band.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/platform-efr32.h b/examples/platforms/efr32mg12/platform-efr32.h index c956fb7ca..5ec48e216 100644 --- a/examples/platforms/efr32mg12/platform-efr32.h +++ b/examples/platforms/efr32mg12/platform-efr32.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/radio.c b/examples/platforms/efr32mg12/radio.c index 57a39d7e1..abc67e121 100644 --- a/examples/platforms/efr32mg12/radio.c +++ b/examples/platforms/efr32mg12/radio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -497,7 +497,7 @@ otError otPlatRadioSleep(otInstance *aInstance) otLogInfoPlat("State=OT_RADIO_STATE_SLEEP", NULL); - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); // abort packages under reception + RAIL_Idle(gRailHandle, RAIL_IDLE, true); sState = OT_RADIO_STATE_SLEEP; exit: @@ -518,7 +518,7 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) if (sCurrentBandConfig != config) { - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); + RAIL_Idle(gRailHandle, RAIL_IDLE, true); efr32RailConfigLoad(config); sCurrentBandConfig = config; } @@ -566,7 +566,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) if (sCurrentBandConfig != config) { - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); + RAIL_Idle(gRailHandle, RAIL_IDLE, true); efr32RailConfigLoad(config); sCurrentBandConfig = config; } diff --git a/examples/platforms/efr32mg12/sleepy-demo/Makefile.am b/examples/platforms/efr32mg12/sleepy-demo/Makefile.am index e9ff42f40..22cb72564 100644 --- a/examples/platforms/efr32mg12/sleepy-demo/Makefile.am +++ b/examples/platforms/efr32mg12/sleepy-demo/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, The OpenThread Authors. +# Copyright (c) 2020, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/Makefile.am b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/Makefile.am index 91df59148..2443898c7 100644 --- a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/Makefile.am +++ b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, The OpenThread Authors. +# Copyright (c) 2020, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/main.c b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/main.c index d6d775856..a6715b279 100644 --- a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/main.c +++ b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-ftd/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/Makefile.am b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/Makefile.am index a3b7585c0..c72759b1c 100644 --- a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/Makefile.am +++ b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, The OpenThread Authors. +# Copyright (c) 2020, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/main.c b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/main.c index 26ef87391..7037bc0ac 100644 --- a/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/main.c +++ b/examples/platforms/efr32mg12/sleepy-demo/sleepy-demo-mtd/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/startup-gcc.c b/examples/platforms/efr32mg12/startup-gcc.c index 611d44156..85c9e2aa5 100644 --- a/examples/platforms/efr32mg12/startup-gcc.c +++ b/examples/platforms/efr32mg12/startup-gcc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg12/system.c b/examples/platforms/efr32mg12/system.c index 73e4aca01..beac140d7 100644 --- a/examples/platforms/efr32mg12/system.c +++ b/examples/platforms/efr32mg12/system.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -91,7 +91,6 @@ void otSysInit(int argc, char *argv[]) CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO); CMU_ClockEnable(cmuClock_CORELE, true); CMU_ClockEnable(cmuClock_RTCC, true); - status = sl_sleeptimer_init(); assert(status == SL_STATUS_OK); diff --git a/examples/platforms/efr32mg12/uart.c b/examples/platforms/efr32mg12/uart.c index e81ebf052..f93f75fc6 100644 --- a/examples/platforms/efr32mg12/uart.c +++ b/examples/platforms/efr32mg12/uart.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The OpenThread Authors. + * Copyright (c) 2020, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/platforms/efr32mg13/brd4168a/board_config.h b/examples/platforms/efr32mg13/brd4168a/board_config.h index 6cac36d56..f3e7f837b 100644 --- a/examples/platforms/efr32mg13/brd4168a/board_config.h +++ b/examples/platforms/efr32mg13/brd4168a/board_config.h @@ -36,6 +36,7 @@ #define __BOARD_CONFIG_H__ #define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Dev board suppports OQPSK modulation in 2.4GHz band. +#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0 /// Dev board doesn't support OQPSK modulation in 915MHz band. #ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT #define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c @@ -43,6 +44,9 @@ #ifndef RADIO_CONFIG_DMP_SUPPORT #define RADIO_CONFIG_DMP_SUPPORT 0 /// Set to 1 to enable Dynamic Multi-Protocol support in radio.c + +#define RADIO_CONFIG_PA_USES_DCDC 0 /// The PA(s) is(are) fed from VBAT + #endif #endif // __BOARD_CONFIG_H__ diff --git a/examples/platforms/efr32mg13/openthread-core-efr32-config.h b/examples/platforms/efr32mg13/openthread-core-efr32-config.h index c7920f7ee..b9602c1ef 100644 --- a/examples/platforms/efr32mg13/openthread-core-efr32-config.h +++ b/examples/platforms/efr32mg13/openthread-core-efr32-config.h @@ -53,7 +53,7 @@ * Define to 1 if you want to enable physical layer to support OQPSK modulation in 915MHz band. * */ -#ifdef RADIO_CONFIG_915MHZ_OQPSK_SUPPORT +#if RADIO_CONFIG_915MHZ_OQPSK_SUPPORT #define OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT 1 #else #define OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT 0 @@ -65,7 +65,7 @@ * Define to 1 if you want to enable physical layer to support OQPSK modulation in 2.4GHz band. * */ -#ifdef RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT +#if RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT #define OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT 1 #else #define OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT 0 @@ -93,7 +93,7 @@ * Define to 1 if you want to enable software CSMA-CA backoff logic. * */ -#define OPENTHREAD_CONFIG_SOFTWARE_CSMA_BACKOFF_ENABLE 1 +#define OPENTHREAD_CONFIG_SOFTWARE_CSMA_BACKOFF_ENABLE 0 /** * @def OPENTHREAD_CONFIG_SOFTWARE_ENERGY_SCAN_ENABLE @@ -101,7 +101,7 @@ * Define to 1 if you want to enable software energy scanning logic. * */ -#define OPENTHREAD_CONFIG_SOFTWARE_ENERGY_SCAN_ENABLE 1 +#define OPENTHREAD_CONFIG_SOFTWARE_ENERGY_SCAN_ENABLE 0 /** * @def SETTINGS_CONFIG_BASE_ADDRESS @@ -127,22 +127,6 @@ */ #define SETTINGS_CONFIG_PAGE_NUM 4 -/** - * @def RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM - * - * The number of short source address table entries. - * - */ -#define RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM 6 - -/** - * @def RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM - * - * The number of extended source address table entries. - * - */ -#define RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM 6 - /** * @def OPENTHREAD_CONFIG_NCP_UART_ENABLE * diff --git a/examples/platforms/efr32mg13/radio.c b/examples/platforms/efr32mg13/radio.c index c1e6cc255..88dee1934 100644 --- a/examples/platforms/efr32mg13/radio.c +++ b/examples/platforms/efr32mg13/radio.c @@ -59,14 +59,19 @@ enum { - IEEE802154_MIN_LENGTH = 5, - IEEE802154_MAX_LENGTH = 127, - IEEE802154_ACK_LENGTH = 5, - IEEE802154_FRAME_TYPE_MASK = 0x7, - IEEE802154_FRAME_TYPE_ACK = 0x2, - IEEE802154_FRAME_PENDING = 1 << 4, - IEEE802154_ACK_REQUEST = 1 << 5, - IEEE802154_DSN_OFFSET = 2, + IEEE802154_MIN_LENGTH = 5, + IEEE802154_MAX_LENGTH = 127, + IEEE802154_ACK_LENGTH = 5, + + // FCF + DSN + dest PANID + dest addr + src PANID + src addr (without security header) + IEEE802154_MAX_MHR_LENGTH = 2 + 1 + 2 + 8 + 2 + 8, + + IEEE802154_FRAME_TYPE_MASK = 0x7, + IEEE802154_FRAME_TYPE_ACK = 0x2, + IEEE802154_FRAME_TYPE_MAC_COMMAND = 0x3, + IEEE802154_ACK_REQUEST = 1 << 5, + IEEE802154_DSN_OFFSET = 2, + IEEE802154_FCF_OFFSET = 0, }; enum @@ -106,10 +111,25 @@ typedef enum RAIL_Handle_t gRailHandle; -static volatile bool sTransmitBusy = false; -static bool sPromiscuous = false; -static bool sIsSrcMatchEnabled = false; -static otRadioState sState = OT_RADIO_STATE_DISABLED; +static volatile bool sTransmitBusy = false; +static bool sPromiscuous = false; +static otRadioState sState = OT_RADIO_STATE_DISABLED; + +enum +{ + ACKED_WITH_FP_MATCH_LENGTH = 1 + IEEE802154_MAX_MHR_LENGTH, // PHR and MHR + ACKED_WITH_FP_SLOTS = 16, // maximum number of Data Request packets in the RX FIFO. Length should be a power of 2. +}; + +typedef struct efr32AckedWithFP +{ + uint8_t mLength; + uint8_t mPacket[ACKED_WITH_FP_MATCH_LENGTH]; +} efr32AckedWithFP; +static bool sIsSrcMatchEnabled = false; +static efr32AckedWithFP sAckedWithFPFifo[ACKED_WITH_FP_SLOTS]; +static uint32_t sAckedWithFPReadIndex; +static volatile uint32_t sAckedWithFPWriteIndex; static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH]; static otRadioFrame sReceiveFrame; @@ -140,7 +160,7 @@ static const RAIL_IEEE802154_Config_t sRailIeee802154Config = { .ackConfig = { .enable = true, - .ackTimeout = 894, + .ackTimeout = 864, .rxTransitions = { .success = RAIL_RF_STATE_RX, @@ -166,10 +186,16 @@ static const RAIL_IEEE802154_Config_t sRailIeee802154Config = { .isPanCoordinator = false, }; +#if RADIO_CONFIG_PA_USES_DCDC +RAIL_DECLARE_TX_POWER_DCDC_CURVES(piecewiseSegments, curvesSg, curves24Hp, curves24Lp); +#else RAIL_DECLARE_TX_POWER_VBAT_CURVES(piecewiseSegments, curvesSg, curves24Hp, curves24Lp); +#endif static int8_t sTxPowerDbm = OPENTHREAD_CONFIG_DEFAULT_TRANSMIT_POWER; +static int8_t sCcaThresholdDbm = -75; // default -75dBm energy detect threshold + static efr32BandConfig *sCurrentBandConfig = NULL; static RAIL_Handle_t efr32RailInit(efr32CommonConfig *aCommonConfig) @@ -319,6 +345,10 @@ void efr32RadioInit(void) sCurrentBandConfig = efr32RadioGetBandConfig(OPENTHREAD_CONFIG_DEFAULT_CHANNEL); assert(sCurrentBandConfig != NULL); + memset(sAckedWithFPFifo, 0, sizeof(sAckedWithFPFifo)); + sAckedWithFPWriteIndex = 0; + sAckedWithFPReadIndex = 0; + efr32RadioSetTxPower(sTxPowerDbm); sEnergyScanStatus = ENERGY_SCAN_STATUS_IDLE; @@ -398,11 +428,8 @@ void otPlatRadioSetPanId(otInstance *aInstance, uint16_t aPanId) utilsSoftSrcMatchSetPanId(aPanId); - for (uint8_t i = 0; i < EFR32_NUM_BAND_CONFIGS; i++) - { - status = RAIL_IEEE802154_SetPanId(gRailHandle, aPanId, 0); - assert(status == RAIL_STATUS_NO_ERROR); - } + status = RAIL_IEEE802154_SetPanId(gRailHandle, aPanId, 0); + assert(status == RAIL_STATUS_NO_ERROR); } void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aAddress) @@ -414,11 +441,8 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aA otLogInfoPlat("ExtAddr=%X%X%X%X%X%X%X%X", aAddress->m8[7], aAddress->m8[6], aAddress->m8[5], aAddress->m8[4], aAddress->m8[3], aAddress->m8[2], aAddress->m8[1], aAddress->m8[0]); - for (uint8_t i = 0; i < EFR32_NUM_BAND_CONFIGS; i++) - { - status = RAIL_IEEE802154_SetLongAddress(gRailHandle, (uint8_t *)aAddress->m8, 0); - assert(status == RAIL_STATUS_NO_ERROR); - } + status = RAIL_IEEE802154_SetLongAddress(gRailHandle, (uint8_t *)aAddress->m8, 0); + assert(status == RAIL_STATUS_NO_ERROR); } void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aAddress) @@ -429,11 +453,8 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aAddress) otLogInfoPlat("ShortAddr=%X", aAddress); - for (uint8_t i = 0; i < EFR32_NUM_BAND_CONFIGS; i++) - { - status = RAIL_IEEE802154_SetShortAddress(gRailHandle, aAddress, 0); - assert(status == RAIL_STATUS_NO_ERROR); - } + status = RAIL_IEEE802154_SetShortAddress(gRailHandle, aAddress, 0); + assert(status == RAIL_STATUS_NO_ERROR); } bool otPlatRadioIsEnabled(otInstance *aInstance) @@ -476,7 +497,7 @@ otError otPlatRadioSleep(otInstance *aInstance) otLogInfoPlat("State=OT_RADIO_STATE_SLEEP", NULL); - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); // abort packages under reception + RAIL_Idle(gRailHandle, RAIL_IDLE, true); sState = OT_RADIO_STATE_SLEEP; exit: @@ -497,7 +518,7 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) if (sCurrentBandConfig != config) { - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); + RAIL_Idle(gRailHandle, RAIL_IDLE, true); efr32RailConfigLoad(config); sCurrentBandConfig = config; } @@ -545,7 +566,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) if (sCurrentBandConfig != config) { - RAIL_Idle(gRailHandle, RAIL_IDLE_ABORT, true); + RAIL_Idle(gRailHandle, RAIL_IDLE, true); efr32RailConfigLoad(config); sCurrentBandConfig = config; } @@ -596,6 +617,9 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) // time needed for CSMA/CA txSchedulerInfo.transactionTime += RADIO_TIMING_CSMA_OVERHEAD_US; #endif + csmaConfig.csmaTries = aFrame->mInfo.mTxInfo.mMaxCsmaBackoffs; + csmaConfig.ccaThreshold = sCcaThresholdDbm; + status = RAIL_StartCcaCsmaTx(gRailHandle, aFrame->mChannel, txOptions, &csmaConfig, &txSchedulerInfo); } else @@ -617,6 +641,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) #endif sTransmitError = OT_ERROR_CHANNEL_ACCESS_FAILURE; sTransmitBusy = false; + otSysEventSignalPending(); } exit: @@ -670,11 +695,8 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) sPromiscuous = aEnable; - for (uint8_t i = 0; i < EFR32_NUM_BAND_CONFIGS; i++) - { - status = RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, aEnable); - assert(status == RAIL_STATUS_NO_ERROR); - } + status = RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, aEnable); + assert(status == RAIL_STATUS_NO_ERROR); } void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) @@ -685,6 +707,74 @@ void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) sIsSrcMatchEnabled = aEnable; } +static bool sAckedWithFPFifoIsFull(void) +{ + return (uint32_t)(sAckedWithFPWriteIndex - sAckedWithFPReadIndex) == otARRAY_LENGTH(sAckedWithFPFifo); +} + +static bool sAckedWithFPFifoIsEmpty(void) +{ + return (uint32_t)(sAckedWithFPWriteIndex - sAckedWithFPReadIndex) == 0; +} + +static efr32AckedWithFP *sAckedWithFPFifoGetWriteSlot(void) +{ + uint32_t idx = sAckedWithFPWriteIndex & (otARRAY_LENGTH(sAckedWithFPFifo) - 1); + return &sAckedWithFPFifo[idx]; +} + +static const efr32AckedWithFP *sAckedWithFPFifoGetReadSlot(void) +{ + uint32_t idx = sAckedWithFPReadIndex & (otARRAY_LENGTH(sAckedWithFPFifo) - 1); + return &sAckedWithFPFifo[idx]; +} + +static void insertIeee802154DataRequestCommand(RAIL_Handle_t aRailHandle) +{ + assert(!sAckedWithFPFifoIsFull()); + efr32AckedWithFP *const slot = sAckedWithFPFifoGetWriteSlot(); + + RAIL_RxPacketInfo_t packetInfo; + + RAIL_GetRxIncomingPacketInfo(aRailHandle, &packetInfo); + assert(packetInfo.packetBytes >= 4); // PHR + FCF + DSN + + if (packetInfo.packetBytes > sizeof(slot->mPacket)) + { + packetInfo.packetBytes = sizeof(slot->mPacket); + if (packetInfo.firstPortionBytes >= sizeof(slot->mPacket)) + { + packetInfo.firstPortionBytes = sizeof(slot->mPacket); + packetInfo.lastPortionData = NULL; + } + } + slot->mLength = packetInfo.packetBytes; + RAIL_CopyRxPacket(slot->mPacket, &packetInfo); + + ++sAckedWithFPWriteIndex; +} + +static bool wasAckedWithFramePending(const uint8_t *aPsdu, uint8_t aPsduLength) +{ + bool ackedWithFramePending = false; + uint16_t fcf = aPsdu[IEEE802154_FCF_OFFSET] | (aPsdu[IEEE802154_FCF_OFFSET + 1] << 8); + + otEXPECT((fcf & IEEE802154_FRAME_TYPE_MASK) == IEEE802154_FRAME_TYPE_MAC_COMMAND); + + while (!(ackedWithFramePending || sAckedWithFPFifoIsEmpty())) + { + const efr32AckedWithFP *const slot = sAckedWithFPFifoGetReadSlot(); + if ((slot->mPacket[0] == aPsduLength) && (memcmp(slot->mPacket + 1, aPsdu, slot->mLength - 1) == 0)) + { + ackedWithFramePending = true; + } + ++sAckedWithFPReadIndex; + } + +exit: + return ackedWithFramePending; +} + static void processNextRxPacket(otInstance *aInstance) { RAIL_RxPacketHandle_t packetHandle = RAIL_RX_PACKET_HANDLE_INVALID; @@ -704,11 +794,11 @@ static void processNextRxPacket(otInstance *aInstance) length = packetInfo.packetBytes + 1; - // check the length in recv packet info structure - otEXPECT(length == packetInfo.firstPortionData[0]); + // check the length in recv packet info structure; RAIL should take care of this. + assert(length == packetInfo.firstPortionData[0]); - // check the length validity of recv packet - otEXPECT(length >= IEEE802154_MIN_LENGTH && length <= IEEE802154_MAX_LENGTH); + // check the length validity of recv packet; RAIL should take care of this. + assert(length >= IEEE802154_MIN_LENGTH && length <= IEEE802154_MAX_LENGTH); otLogInfoPlat("Received data:%d", length); @@ -719,9 +809,7 @@ static void processNextRxPacket(otInstance *aInstance) packetInfo.packetBytes--; // read packet - memcpy(sReceiveFrame.mPsdu, packetInfo.firstPortionData, packetInfo.firstPortionBytes); - memcpy(sReceiveFrame.mPsdu + packetInfo.firstPortionBytes, packetInfo.lastPortionData, - packetInfo.packetBytes - packetInfo.firstPortionBytes); + RAIL_CopyRxPacket(sReceiveFrame.mPsdu, &packetInfo); status = RAIL_ReleaseRxPacket(gRailHandle, packetHandle); if (status == RAIL_STATUS_NO_ERROR) @@ -750,20 +838,26 @@ static void processNextRxPacket(otInstance *aInstance) } else { - otEXPECT(length != IEEE802154_ACK_LENGTH); + // signal MAC layer for each received frame if promiscous is enabled + // otherwise only signal MAC layer for non-ACK frame + otEXPECT(sPromiscuous || (length != IEEE802154_ACK_LENGTH)); sReceiveError = OT_ERROR_NONE; sReceiveFrame.mInfo.mRxInfo.mRssi = packetDetails.rssi; sReceiveFrame.mInfo.mRxInfo.mLqi = packetDetails.lqi; - // TODO: grab timestamp and handle conversion to msec/usec and RAIL_GetRxTimeSyncWordEndAlt - // sReceiveFrame.mInfo.mRxInfo.mMsec = packetDetails.packetTime; - // sReceiveFrame.mInfo.mRxInfo.mUsec = packetDetails.packetTime; + // Get the timestamp when the SFD was received + assert(packetDetails.timeReceived.timePosition != RAIL_PACKET_TIME_INVALID); + packetDetails.timeReceived.totalPacketBytes = length + 1; - // TODO Set this flag only when the packet is really acknowledged with frame pending set. - // See https://github.com/openthread/openthread/pull/3785 - sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true; + status = RAIL_GetRxTimeSyncWordEndAlt(gRailHandle, &packetDetails); + assert(status == RAIL_STATUS_NO_ERROR); + sReceiveFrame.mInfo.mRxInfo.mTimestamp = packetDetails.timeReceived.packetTime; + + // Set this flag only when the packet is really acknowledged with frame pending set. + sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = + wasAckedWithFramePending(sReceiveFrame.mPsdu, sReceiveFrame.mLength); #if OPENTHREAD_CONFIG_DIAG_ENABLE @@ -774,16 +868,11 @@ static void processNextRxPacket(otInstance *aInstance) else #endif { - // signal MAC layer for each received frame if promiscous is enabled - // otherwise only signal MAC layer for non-ACK frame - if (sPromiscuous || sReceiveFrame.mLength > IEEE802154_ACK_LENGTH) - { - otLogInfoPlat("Received %d bytes", sReceiveFrame.mLength); - otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError); + otLogInfoPlat("Received %d bytes", sReceiveFrame.mLength); + otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError); #if RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT - sRailDebugCounters.mRailPlatRadioReceiveDoneCbCount++; + sRailDebugCounters.mRailPlatRadioReceiveDoneCbCount++; #endif - } } } @@ -815,12 +904,14 @@ static void ieee802154DataRequestCommand(RAIL_Handle_t aRailHandle) { status = RAIL_IEEE802154_SetFramePending(aRailHandle); assert(status == RAIL_STATUS_NO_ERROR); + insertIeee802154DataRequestCommand(aRailHandle); } } else { status = RAIL_IEEE802154_SetFramePending(aRailHandle); assert(status == RAIL_STATUS_NO_ERROR); + insertIeee802154DataRequestCommand(aRailHandle); } } @@ -840,6 +931,7 @@ static void RAILCb_Generic(RAIL_Handle_t aRailHandle, RAIL_Events_t aEvents) { ieee802154DataRequestCommand(aRailHandle); } + if (aEvents & RAIL_EVENTS_TX_COMPLETION) { if (aEvents & RAIL_EVENT_TX_PACKET_SENT) @@ -1041,17 +1133,23 @@ otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aThreshold) { OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aThreshold); - return OT_ERROR_NOT_IMPLEMENTED; + otError error = OT_ERROR_NONE; + otEXPECT_ACTION(aThreshold != NULL, error = OT_ERROR_INVALID_ARGS); + + *aThreshold = sCcaThresholdDbm; + +exit: + return error; } otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold) { OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aThreshold); - return OT_ERROR_NOT_IMPLEMENTED; + sCcaThresholdDbm = aThreshold; + + return OT_ERROR_NONE; } int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)