Skip to content

Commit

Permalink
Increase heap size for examples using thread as srp host setup was so…
Browse files Browse the repository at this point in the history
…metime 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
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Aug 11, 2021
1 parent 65b0007 commit 1539770
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 43 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
]
}

Expand Down
24 changes: 24 additions & 0 deletions examples/platform/efr32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>
#include <string.h>
Expand All @@ -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);

Expand Down Expand Up @@ -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
}

/*
Expand All @@ -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
}

/*
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/efr32/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
]
}

Expand Down
36 changes: 0 additions & 36 deletions src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,6 @@ BaseType_t GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::SignalThreadActivi
return yieldRequired;
}

template <class ImplClass>
void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::OnJoinerTimer(TimerHandle_t xTimer)
{
GenericThreadStackManagerImpl_FreeRTOS<ImplClass> * self =
static_cast<GenericThreadStackManagerImpl_FreeRTOS<ImplClass> *>(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 <class ImplClass>
void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::ThreadTaskMain(void * arg)
{
Expand All @@ -153,26 +130,13 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::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();
self->Impl()->ProcessThreadActivity();
self->Impl()->UnlockThreadStack();

ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (self->mJoinerStartPending)
{
self->mJoinerStartPending = false;
self->Impl()->JoinerStart();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ class GenericThreadStackManagerImpl_FreeRTOS
inline ImplClass * Impl() { return static_cast<ImplClass *>(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)];
Expand Down

0 comments on commit 1539770

Please sign in to comment.