feat(openthread): enable time sync feature

This commit is contained in:
Shu Chen 2023-09-21 20:31:38 +08:00 committed by zhangwenxu
parent 8a565641c2
commit 3f02e5e901
4 changed files with 51 additions and 5 deletions

View File

@ -329,4 +329,13 @@ menu "OpenThread"
default n default n
help help
Only used for Thread1.2 certification Only used for Thread1.2 certification
config OPENTHREAD_TIME_SYNC
bool "Enable the time synchronization service feature"
depends on OPENTHREAD_ENABLED
default n
help
Select this option to enable time synchronization feature, the devices in the same Thread network could
sync to the same network time.
endmenu endmenu

View File

@ -551,7 +551,6 @@
#define OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT 1 #define OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT 1
#endif #endif
/** /**
* *
* Define as 1 to enable support for allocating message pool buffer in PSRAM * Define as 1 to enable support for allocating message pool buffer in PSRAM
@ -570,4 +569,14 @@
#define OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT 1 #define OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT 1
#endif #endif
/**
* @def OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
*
* Define as 1 to enable the time synchronization service feature.
*
*/
#if CONFIG_OPENTHREAD_TIME_SYNC
#define OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 1
#endif
#define OPENTHREAD_FTD 1 #define OPENTHREAD_FTD 1

View File

@ -253,4 +253,14 @@
*/ */
#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE CONFIG_OPENTHREAD_DNS_CLIENT #define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE CONFIG_OPENTHREAD_DNS_CLIENT
/**
* @def OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
*
* Define as 1 to enable the time synchronization service feature.
*
*/
#if CONFIG_OPENTHREAD_TIME_SYNC
#define OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 1
#endif
#define OPENTHREAD_MTD 1 #define OPENTHREAD_MTD 1

View File

@ -713,15 +713,33 @@ void IRAM_ATTR esp_ieee802154_receive_sfd_done(void)
void IRAM_ATTR esp_ieee802154_transmit_sfd_done(uint8_t *frame) void IRAM_ATTR esp_ieee802154_transmit_sfd_done(uint8_t *frame)
{ {
assert(frame == (uint8_t *)&s_transmit_psdu || frame == s_enhack); assert(frame == (uint8_t *)&s_transmit_psdu || frame == s_enhack);
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
otRadioFrame ot_frame;
ot_frame.mPsdu = frame + 1;
ot_frame.mLength = frame[0];
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (s_csl_period > 0) { if (s_csl_period > 0) {
otRadioFrame ot_frame;
ot_frame.mPsdu = frame + 1;
ot_frame.mLength = frame[0];
otMacFrameSetCslIe(&ot_frame, s_csl_period, get_csl_phase()); otMacFrameSetCslIe(&ot_frame, s_csl_period, get_csl_phase());
} }
#endif #endif
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
if (frame == (uint8_t *)&s_transmit_psdu && s_transmit_frame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0)
{
uint8_t *p_time_ie = s_transmit_frame.mPsdu + s_transmit_frame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset;
uint64_t time = (uint64_t)((int64_t)otPlatTimeGet() + s_transmit_frame.mInfo.mTxInfo.mIeInfo->mNetworkTimeOffset);
*p_time_ie = s_transmit_frame.mInfo.mTxInfo.mIeInfo->mTimeSyncSeq;
*(++p_time_ie) = (uint8_t)(time & 0xff);
for (uint8_t i = 1; i < sizeof(uint64_t); i++)
{
time = time >> 8;
*(++p_time_ie) = (uint8_t)(time & 0xff);
}
}
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
} }
void IRAM_ATTR esp_ieee802154_energy_detect_done(int8_t power) void IRAM_ATTR esp_ieee802154_energy_detect_done(int8_t power)