From 153977029271c116a27f759751a12f322387bebc Mon Sep 17 00:00:00 2001 From: jmartinez-silabs <67972863+jmartinez-silabs@users.noreply.github.com> Date: Wed, 5 May 2021 08:55:00 -0400 Subject: [PATCH] Increase heap size for examples using thread as srp host setup was sometime failing with error insuffisant buffers available. (#6471) Remove The joiner start on a periodic timer. This isn't used Add a UART IRQ to wakeup the thread process on CLI inputs --- examples/lighting-app/efr32/BUILD.gn | 2 +- examples/lock-app/efr32/BUILD.gn | 2 +- examples/platform/efr32/uart.c | 24 +++++++++++++ examples/platform/efr32/uart.h | 3 ++ examples/window-app/efr32/BUILD.gn | 2 +- ...GenericThreadStackManagerImpl_FreeRTOS.cpp | 36 ------------------- .../GenericThreadStackManagerImpl_FreeRTOS.h | 4 --- 7 files changed, 30 insertions(+), 43 deletions(-) diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 06168e0b67103a..4a4f29f25e9d91 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -66,7 +66,7 @@ efr32_sdk("sdk") { defines = [ "BOARD_ID=${efr32_board}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", - "SL_HEAP_SIZE=(10 * 1024)", + "SL_HEAP_SIZE=(12 * 1024)", ] if (chip_enable_pw_rpc) { diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index dadbda26665433..5f1b81e69ceda3 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -59,7 +59,7 @@ efr32_sdk("sdk") { defines = [ "BOARD_ID=${efr32_board}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", - "SL_HEAP_SIZE=(10 * 1024)", + "SL_HEAP_SIZE=(12 * 1024)", ] } diff --git a/examples/platform/efr32/uart.c b/examples/platform/efr32/uart.c index 5dae1cf562e307..7915291e4aa95e 100644 --- a/examples/platform/efr32/uart.c +++ b/examples/platform/efr32/uart.c @@ -21,6 +21,7 @@ #include "em_core.h" #include "em_usart.h" #include "hal-config.h" +#include "sl_uartdrv_usart_vcom_config.h" #include "uartdrv.h" #include #include @@ -29,6 +30,14 @@ #define MIN(A, B) ((A) < (B) ? (A) : (B)) #endif +#define HELPER1(x) USART##x##_RX_IRQn +#define HELPER2(x) HELPER1(x) +#define USART_IRQ HELPER2(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO) + +#define HELPER3(x) USART##x##_RX_IRQHandler +#define HELPER4(x) HELPER3(x) +#define USART_IRQHandler HELPER4(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO) + DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_RX_BUFS, sUartRxQueue); DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_TX_BUFS, sUartTxQueue); @@ -213,6 +222,18 @@ void uartConsoleInit(void) // Activate 2 dma queues to always have one active UARTDRV_Receive(sUartHandle, sRxDmaBuffer, MAX_DMA_BUFFER_SIZE, UART_rx_callback); UARTDRV_Receive(sUartHandle, sRxDmaBuffer2, MAX_DMA_BUFFER_SIZE, UART_rx_callback); + + // Enable USART0 interrupt to wake OT task when data arrives + NVIC_ClearPendingIRQ(USART_IRQ); + NVIC_EnableIRQ(USART_IRQ); + USART_IntEnable(SL_UARTDRV_USART_VCOM_PERIPHERAL, USART_IF_RXDATAV); +} + +void USART_IRQHandler(void) +{ +#ifndef PW_RPC_ENABLED + otSysEventSignalPending(); +#endif } /* @@ -230,6 +251,9 @@ static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, ui } UARTDRV_Receive(sUartHandle, data, transferCount, UART_rx_callback); +#ifndef PW_RPC_ENABLED + otSysEventSignalPending(); +#endif } /* diff --git a/examples/platform/efr32/uart.h b/examples/platform/efr32/uart.h index 3ff3062dc1747d..f708030223b2f7 100644 --- a/examples/platform/efr32/uart.h +++ b/examples/platform/efr32/uart.h @@ -29,8 +29,11 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength); int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead); // Implemented by in openthread code +#ifndef PW_RPC_ENABLED extern void otPlatUartReceived(const uint8_t * aBuf, uint16_t aBufLength); extern void otPlatUartSendDone(void); +extern void otSysEventSignalPending(void); +#endif #ifdef __cplusplus } // extern "C" diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 26004a6b2c2520..ea7f9c29d1f034 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -60,7 +60,7 @@ efr32_sdk("sdk") { defines = [ "BOARD_ID=${efr32_board}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", - "SL_HEAP_SIZE=(10 * 1024)", + "SL_HEAP_SIZE=(12 * 1024)", ] } diff --git a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp index b7eff5105e1c8a..5e66049c0f6273 100644 --- a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp +++ b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp @@ -122,29 +122,6 @@ BaseType_t GenericThreadStackManagerImpl_FreeRTOS::SignalThreadActivi return yieldRequired; } -template -void GenericThreadStackManagerImpl_FreeRTOS::OnJoinerTimer(TimerHandle_t xTimer) -{ - GenericThreadStackManagerImpl_FreeRTOS * self = - static_cast *>(pvTimerGetTimerID(xTimer)); - - ChipLogDetail(DeviceLayer, "Thread joiner timer running"); - - 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 if (!self->mJoinerStartPending) - { - ChipLogDetail(DeviceLayer, "Request Thread joiner start"); - - self->mJoinerStartPending = true; - self->Impl()->SignalThreadActivityPending(); - } -} - template void GenericThreadStackManagerImpl_FreeRTOS::ThreadTaskMain(void * arg) { @@ -153,13 +130,6 @@ void GenericThreadStackManagerImpl_FreeRTOS::ThreadTaskMain(void * ar ChipLogDetail(DeviceLayer, "Thread task running"); - // 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) { self->Impl()->LockThreadStack(); @@ -167,12 +137,6 @@ void GenericThreadStackManagerImpl_FreeRTOS::ThreadTaskMain(void * ar self->Impl()->UnlockThreadStack(); ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - - if (self->mJoinerStartPending) - { - self->mJoinerStartPending = false; - self->Impl()->JoinerStart(); - } } } diff --git a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h index b23b06d8fbd998..2df83e28fb0ab4 100644 --- a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h +++ b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h @@ -79,10 +79,6 @@ class GenericThreadStackManagerImpl_FreeRTOS inline ImplClass * Impl() { return static_cast(this); } static void ThreadTaskMain(void * arg); - static void OnJoinerTimer(TimerHandle_t xTimer); - - portTickType mJoinerExpire; - bool mJoinerStartPending = false; #if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_TASK) && CHIP_CONFIG_FREERTOS_USE_STATIC_TASK StackType_t mThreadStack[CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE / sizeof(StackType_t)];