From 661d2b4f5f2c81a45df1c6f2a4f6397e8722d863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ku=C5=BAnia?= Date: Tue, 17 Mar 2020 21:02:15 +0100 Subject: [PATCH] [mac] add capability to transition from Sleep to Transmit during data request (#4697) --- examples/platforms/nrf528xx/src/radio.c | 3 ++- include/openthread/platform/radio.h | 9 ++++++++- src/core/mac/sub_mac.cpp | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/platforms/nrf528xx/src/radio.c b/examples/platforms/nrf528xx/src/radio.c index e85f8fa07..a9cec0cd5 100644 --- a/examples/platforms/nrf528xx/src/radio.c +++ b/examples/platforms/nrf528xx/src/radio.c @@ -428,7 +428,8 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return (otRadioCaps)(OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF); + return (otRadioCaps)(OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF | + OT_RADIO_CAPS_SLEEP_TO_TX); } bool otPlatRadioGetPromiscuous(otInstance *aInstance) diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index f5c74c78f..7e4724810 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -123,6 +123,7 @@ enum OT_RADIO_CAPS_ENERGY_SCAN = 1 << 1, ///< Radio supports Energy Scans. OT_RADIO_CAPS_TRANSMIT_RETRIES = 1 << 2, ///< Radio supports tx retry logic with collision avoidance (CSMA). OT_RADIO_CAPS_CSMA_BACKOFF = 1 << 3, ///< Radio supports CSMA backoff for frame transmission (but no retry). + OT_RADIO_CAPS_SLEEP_TO_TX = 1 << 4, ///< Radio supports direct transition from sleep to TX with CSMA. }; #define OT_PANID_BROADCAST 0xffff ///< IEEE 802.15.4 Broadcast PAN ID @@ -244,6 +245,10 @@ typedef enum otRadioState * +----------+ Disable() +-------+ Sleep() +---------+ Receive() +----------+ * (Radio OFF) or * signal TransmitDone + * + * During the IEEE 802.15.4 data request command the transition Sleep->Receive->Transmit + * can be shortened to direct transition from Sleep to Transmit if the platform supports + * the OT_RADIO_CAPS_SLEEP_TO_TX capability. */ /** @@ -558,7 +563,9 @@ otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance); * requesting transmission. The channel and transmit power are also included in the otRadioFrame structure. * * The transmit sequence consists of: - * 1. Transitioning the radio to Transmit from Receive. + * 1. Transitioning the radio to Transmit from one of the following states: + * - Receive if RX is on when the device is idle or OT_RADIO_CAPS_SLEEP_TO_TX is not supported + * - Sleep if RX is off when the device is idle and OT_RADIO_CAPS_SLEEP_TO_TX is supported. * 2. Transmits the psdu on the given channel and at the given transmit power. * * @param[in] aInstance The OpenThread instance structure. diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index 1e5cc8f2e..e84fc4f8b 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -285,8 +285,11 @@ void SubMac::BeginTransmit(void) mTransmitFrame.SetCsmaCaEnabled(true); } - error = Get().Receive(mTransmitFrame.GetChannel()); - OT_ASSERT(error == OT_ERROR_NONE); + if ((mRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX) == 0) + { + error = Get().Receive(mTransmitFrame.GetChannel()); + OT_ASSERT(error == OT_ERROR_NONE); + } SetState(kStateTransmit);