[low-power] add csl feature for Thread 1.2 (#4557)

This commit implements the CSL feature in Thread 1.2.

- Add macro definitions for low power to control the compiling of
  source code.

- Add data and methods for running CSL in Mac and SubMac. This mainly
  includes setting CSL parameters, starting/stopping CSL, and the
  timer handling process.

- Add otPlatTimeGetAPI and implementation.

- Add CSL transmission implementation. CSL transmission is a new kind
  of transmission, the related definition and implementaion for the
  whole transmitting process is added.

- Add calling of start/stop CSL in certain cases.

- Implement CSL synchronization maintainence. If a CSL cordinator
  didn't get a frame containing CSL IE for CSLTimeout, the CSL
  receiver is regarded as de-synchronized.

- Add Cli interface for using CSL.

- Implement enhanced Ack with IE. The original code can only generate
  auto ack for Imm-Ack. As CSL requires CSL IE included in enhanced
  ack. This PR implements it.

- Add basic functional test for CSL transmission. More tests
  corresponding to test plan would be added later.
This commit is contained in:
Li Cao
2020-08-18 10:55:33 -07:00
committed by GitHub
parent 5b7f3b9acf
commit 7db8c6815c
41 changed files with 2012 additions and 50 deletions
-2
View File
@@ -310,11 +310,9 @@ uint64_t otPlatTimeGet(void)
return platformGetNow();
}
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
uint16_t otPlatTimeGetXtalAccuracy(void)
{
return 0;
}
#endif
#endif // OPENTHREAD_SIMULATION_VIRTUAL_TIME == 0
@@ -145,6 +145,16 @@
*/
#define CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER 1
/**
* @def OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW
*
* The CSL sample window in units of 10 symbols.
*
*/
#ifndef OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW
#define OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW 5
#endif
/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
*
+93 -5
View File
@@ -31,6 +31,7 @@
#include <errno.h>
#include <openthread/dataset.h>
#include <openthread/link.h>
#include <openthread/random_noncrypto.h>
#include <openthread/platform/alarm-micro.h>
#include <openthread/platform/alarm-milli.h>
@@ -113,6 +114,17 @@ static int8_t sCcaEdThresh = -74;
static bool sSrcMatchEnabled = false;
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
static uint8_t sAckIeData[OT_ACK_IE_MAX_SIZE];
static uint8_t sAckIeDataLength = 0;
#endif
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
static const uint8_t sCslIeHeader[OT_IE_HEADER_IE_SIZE] = {0x04, 0x0d};
static uint32_t sCslSampleTime;
static uint32_t sCslPeriod;
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
static bool sRadioCoexEnabled = true;
#endif
@@ -138,7 +150,7 @@ static void ReverseExtAddress(otExtAddress *aReversed, const otExtAddress *aOrig
}
}
static bool HasFramePending(const otRadioFrame *aFrame)
static bool hasFramePending(const otRadioFrame *aFrame)
{
bool rval = false;
otMacAddress src;
@@ -348,6 +360,17 @@ void platformRadioInit(void)
#endif
}
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
static uint16_t getCslPhase(void)
{
uint32_t curTime = otPlatAlarmMicroGetNow();
uint32_t cslPeriodInUs = sCslPeriod * OT_US_PER_TEN_SYMBOLS;
uint32_t diff = ((sCslSampleTime % cslPeriodInUs) - (curTime % cslPeriodInUs) + cslPeriodInUs) % cslPeriodInUs;
return (uint16_t)(diff / OT_US_PER_TEN_SYMBOLS);
}
#endif
bool otPlatRadioIsEnabled(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
@@ -630,6 +653,13 @@ void radioSendMessage(otInstance *aInstance)
}
#endif // OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT && OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (sCslPeriod > 0)
{
otMacFrameSetCslIe(&sTransmitFrame, (uint16_t)sCslPeriod, getCslPhase());
}
#endif
sTransmitMessage.mChannel = sTransmitFrame.mChannel;
otEXPECT(radioProcessTransmitSecurity(&sTransmitFrame) == OT_ERROR_NONE);
@@ -803,7 +833,7 @@ void radioSendAck(void)
#else
otMacFrameIsDataRequest(&sReceiveFrame)
#endif
&& HasFramePending(&sReceiveFrame))
&& hasFramePending(&sReceiveFrame))
{
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;
}
@@ -812,9 +842,18 @@ void radioSendAck(void)
// Use enh-ack for 802.15.4-2015 frames
if (otMacFrameIsVersion2015(&sReceiveFrame))
{
otEXPECT(otMacFrameGenerateEnhAck(&sReceiveFrame, sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending, NULL, 0,
&sAckFrame) == OT_ERROR_NONE);
otEXPECT(radioProcessTransmitSecurity(&sAckFrame) == OT_ERROR_NONE);
otEXPECT(otMacFrameGenerateEnhAck(&sReceiveFrame, sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending,
sAckIeData, sAckIeDataLength, &sAckFrame) == OT_ERROR_NONE);
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (sCslPeriod > 0)
{
otMacFrameSetCslIe(&sAckFrame, (uint16_t)sCslPeriod, getCslPhase());
}
#endif
if (otMacFrameIsSecurityEnabled(&sAckFrame))
{
otEXPECT(radioProcessTransmitSecurity(&sAckFrame) == OT_ERROR_NONE);
}
}
else
#endif
@@ -1016,6 +1055,55 @@ exit:
}
#endif
uint64_t otPlatRadioGetNow(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
return otPlatTimeGet();
}
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
static otError updateIeData(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
otError error = OT_ERROR_NONE;
uint8_t offset = 0;
if (sCslPeriod > 0)
{
memcpy(sAckIeData, sCslIeHeader, OT_IE_HEADER_IE_SIZE);
offset += OT_IE_HEADER_IE_SIZE + OT_CSL_IE_SIZE; // reserve space for CSL IE
}
sAckIeDataLength = offset;
return error;
}
otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, const otExtAddress *aExtAddr)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aExtAddr);
otError error = OT_ERROR_NONE;
sCslPeriod = aCslPeriod;
error = updateIeData(aInstance);
return error;
}
void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTime)
{
OT_UNUSED_VARIABLE(aInstance);
sCslSampleTime = aCslSampleTime;
}
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
void otPlatRadioSetMacKey(otInstance * aInstance,
uint8_t aKeyIdMode,
uint8_t aKeyId,