From 9de00e5fe8e4a292819706c1adca66c1ae9a6275 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Fri, 20 Jan 2023 08:22:23 -0500 Subject: [PATCH] Add Threshold timer as active consumer (#24523) --- ...nericThreadStackManagerImpl_OpenThread.cpp | 25 ++++++++++++++----- ...GenericThreadStackManagerImpl_OpenThread.h | 5 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index c2b9370eec2f3b..7b42c24e3840f8 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -1896,20 +1896,25 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RequestSEDActiv if (!onOff && delayIdle && CHIP_DEVICE_CONFIG_SED_ACTIVE_THRESHOLD.count() != 0) { - err = DeviceLayer::SystemLayer().StartTimer(CHIP_DEVICE_CONFIG_SED_ACTIVE_THRESHOLD, RequestSEDModeChange, this); + err = DeviceLayer::SystemLayer().StartTimer(CHIP_DEVICE_CONFIG_SED_ACTIVE_THRESHOLD, RequestSEDModeUpdate, this); if (CHIP_NO_ERROR == err) { + if (!mDelayIdleTimerRunning) + { + mDelayIdleTimerRunning = true; + mActiveModeConsumers++; + } return err; } - ChipLogError(DeviceLayer, "Failed to postponed Idle Mode with error %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(DeviceLayer, "Failed to postpone Idle Mode with error %" CHIP_ERROR_FORMAT, err.Format()); } - return SEDChangeMode(); + return SEDUpdateMode(); } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::SEDChangeMode() +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::SEDUpdateMode() { CHIP_ERROR err = CHIP_NO_ERROR; ConnectivityManager::SEDIntervalMode mode; @@ -1923,12 +1928,20 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::SEDChangeMode() } template -void GenericThreadStackManagerImpl_OpenThread::RequestSEDModeChange(chip::System::Layer * apSystemLayer, +void GenericThreadStackManagerImpl_OpenThread::RequestSEDModeUpdate(chip::System::Layer * apSystemLayer, void * apAppState) { if (apAppState != nullptr) { - static_cast(apAppState)->SEDChangeMode(); + GenericThreadStackManagerImpl_OpenThread * obj = static_cast(apAppState); + if (obj->mActiveModeConsumers > 0) + { + obj->mActiveModeConsumers--; + } + + obj->mDelayIdleTimerRunning = false; + + obj->SEDUpdateMode(); } } #endif diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 0a08466c06b587..79d8f7385d780f 100755 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -104,8 +104,8 @@ class GenericThreadStackManagerImpl_OpenThread CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle); - CHIP_ERROR SEDChangeMode(void); - static void RequestSEDModeChange(chip::System::Layer * apSystemLayer, void * apAppState); + CHIP_ERROR SEDUpdateMode(); + static void RequestSEDModeUpdate(chip::System::Layer * apSystemLayer, void * apAppState); #endif bool _HaveMeshConnectivity(void); @@ -164,6 +164,7 @@ class GenericThreadStackManagerImpl_OpenThread ConnectivityManager::SEDIntervalsConfig mIntervalsConfig; ConnectivityManager::SEDIntervalMode mIntervalsMode = ConnectivityManager::SEDIntervalMode::Idle; uint32_t mActiveModeConsumers = 0; + bool mDelayIdleTimerRunning = false; #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT