diff --git a/examples/lighting-app/nrf5/Makefile b/examples/lighting-app/nrf5/Makefile index 56fa0a6fc30766..4509512e962cd4 100644 --- a/examples/lighting-app/nrf5/Makefile +++ b/examples/lighting-app/nrf5/Makefile @@ -113,10 +113,12 @@ INC_DIRS = \ $(PROJECT_ROOT)/main/traits/include \ $(PROJECT_ROOT)/main/schema/include \ $(PROJECT_ROOT)/third_party/printf \ + $(CHIP_OUTPUT_DIR)/third_party/openthread/include \ $(CHIP_ROOT)/src/include/ \ $(CHIP_ROOT)/src/lib \ $(CHIP_ROOT)/src/ \ $(CHIP_ROOT)/src/system \ + $(CHIP_ROOT)/third_party/openthread/repo/include \ $(NRF5_PLATFORM_DIR)/app/include \ $(NRF5_PLATFORM_DIR)/app/project_include \ $(NRF5_PLATFORM_DIR)/util/include \ @@ -210,6 +212,7 @@ LIBS = \ -lopenthread-nrf52840-transport \ -lopenthread-nrf52840-softdevice-sdk \ -lnordicsemi-nrf52840-radio-driver-softdevice \ + -lSetupPayload \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ diff --git a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h index b9b5b098d2fd98..4b1fbc5dae7a00 100644 --- a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h +++ b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h @@ -30,10 +30,12 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/task.h" +#include "timers.h" #else #include "FreeRTOS.h" #include "semphr.h" #include "task.h" +#include "timers.h" #endif namespace chip { @@ -77,6 +79,9 @@ class GenericThreadStackManagerImpl_FreeRTOS inline ImplClass * Impl() { return static_cast(this); } static void ThreadTaskMain(void * arg); + static void OnJoinerTimer(TimerHandle_t xTimer); + + portTickType mJoinerExpire; }; // Instruct the compiler to instantiate the template only when explicitly told to do so. diff --git a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp index 6a2276583ad454..e8d14e0923caa1 100644 --- a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp +++ b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp @@ -27,6 +27,7 @@ #define GENERIC_THREAD_STACK_MANAGER_IMPL_FREERTOS_IPP #include +#include #include #include #include @@ -114,6 +115,26 @@ BaseType_t GenericThreadStackManagerImpl_FreeRTOS::SignalThreadActivi return yieldRequired; } +template +void GenericThreadStackManagerImpl_FreeRTOS::OnJoinerTimer(TimerHandle_t xTimer) +{ + GenericThreadStackManagerImpl_FreeRTOS * self = + static_cast *>(pvTimerGetTimerID(xTimer)); + + if (xTaskGetTickCount() > self->mJoinerExpire || self->Impl()->IsThreadProvisioned()) + { + ChipLogDetail(DeviceLayer, "Thread joiner timer stopped"); + + VerifyOrDie(pdPASS == xTimerStop(xTimer, portMAX_DELAY) && pdPASS == xTimerDelete(xTimer, portMAX_DELAY)); + } + else + { + CHIP_ERROR error = self->Impl()->JoinerStart(); + + ChipLogDetail(DeviceLayer, "Thread joiner timer triggered: %s", chip::ErrorStr(error)); + } +} + template void GenericThreadStackManagerImpl_FreeRTOS::ThreadTaskMain(void * arg) { @@ -127,6 +148,13 @@ void GenericThreadStackManagerImpl_FreeRTOS::ThreadTaskMain(void * ar // Capture the Thread task handle. self->mThreadTask = xTaskGetCurrentTaskHandle(); + // Try starting joiner within 15m. + self->mJoinerExpire = xTaskGetTickCount() + pdMS_TO_TICKS(15 * 60 * 1000); + + TimerHandle_t joinerTimer = xTimerCreate("JoinerTimer", pdMS_TO_TICKS(10000), pdTRUE, self, &OnJoinerTimer); + VerifyOrDie(joinerTimer != NULL); + VerifyOrDie(pdPASS == xTimerStart(joinerTimer, portMAX_DELAY)); + while (true) { // Lock the Thread stack.