From 769eeefe6109cffd121e028251e2ba8aa652451a Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:39:44 -0400 Subject: [PATCH] [Silabs]Migrate some more freertos api to cmsisos (#35974) * Migrate some more freertos api to cmsisos * Address comments --- examples/platform/silabs/BaseApplication.cpp | 2 +- .../platform/silabs/SoftwareFaultReports.cpp | 4 +-- .../silabs/DiagnosticDataProviderImpl.cpp | 30 +++++++----------- src/test_driver/efr32/src/main.cpp | 31 ++++++++++--------- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 37efb09fe5c207..b7ce3e9fed8bdf 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -259,7 +259,7 @@ CHIP_ERROR BaseApplication::Init() ChipLogProgress(AppServer, "APP: Wait WiFi Init"); while (!wfx_hw_ready()) { - vTaskDelay(pdMS_TO_TICKS(10)); + osDelay(pdMS_TO_TICKS(10)); } ChipLogProgress(AppServer, "APP: Done WiFi Init"); /* We will init server when we get IP */ diff --git a/examples/platform/silabs/SoftwareFaultReports.cpp b/examples/platform/silabs/SoftwareFaultReports.cpp index 8245b1bf454307..37cbae17034f7f 100644 --- a/examples/platform/silabs/SoftwareFaultReports.cpp +++ b/examples/platform/silabs/SoftwareFaultReports.cpp @@ -17,10 +17,10 @@ */ #include "SoftwareFaultReports.h" -#include "FreeRTOS.h" #include "silabs_utils.h" #include #include +#include #include #include #include @@ -75,7 +75,7 @@ void OnSoftwareFaultEventHandler(const char * faultRecordString) // Allow some time for the Fault event to be sent as the next action after exiting this function // is typically an assert or reboot. // Depending on the task at fault, it is possible the event can't be transmitted. - vTaskDelay(pdMS_TO_TICKS(1000)); + osDelay(pdMS_TO_TICKS(1000)); #endif // MATTER_DM_PLUGIN_SOFTWARE_DIAGNOSTICS_SERVER } diff --git a/src/platform/silabs/DiagnosticDataProviderImpl.cpp b/src/platform/silabs/DiagnosticDataProviderImpl.cpp index 4be7113bb67b5b..0cb4c85d3dd10a 100644 --- a/src/platform/silabs/DiagnosticDataProviderImpl.cpp +++ b/src/platform/silabs/DiagnosticDataProviderImpl.cpp @@ -28,10 +28,11 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #endif -#include "FreeRTOS.h" #include "sl_memory_manager.h" +#include #include #include +#include using namespace ::chip::app::Clusters::GeneralDiagnostics; @@ -82,31 +83,24 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks() CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut) { - /* Obtain all available task information */ - TaskStatus_t * taskStatusArray; ThreadMetrics * head = nullptr; - uint32_t arraySize, x, dummy; - arraySize = uxTaskGetNumberOfTasks(); + uint32_t threadCount = osThreadGetCount(); + osThreadId_t * threadIdTable = static_cast(chip::Platform::MemoryCalloc(threadCount, sizeof(osThreadId_t))); - taskStatusArray = static_cast(chip::Platform::MemoryCalloc(arraySize, sizeof(TaskStatus_t))); - - if (taskStatusArray != NULL) + if (threadIdTable != nullptr) { - /* Generate raw status information about each task. */ - arraySize = uxTaskGetSystemState(taskStatusArray, arraySize, &dummy); - /* For each populated position in the taskStatusArray array, - format the raw data as human readable ASCII data. */ - - for (x = 0; x < arraySize; x++) + osThreadEnumerate(threadIdTable, threadCount); + for (uint8_t tIdIndex = 0; tIdIndex < threadCount; tIdIndex++) { + osThreadId_t tId = threadIdTable[tIdIndex]; ThreadMetrics * thread = new ThreadMetrics(); if (thread) { - Platform::CopyString(thread->NameBuf, taskStatusArray[x].pcTaskName); + thread->id = tIdIndex; + thread->stackFreeMinimum.Emplace(osThreadGetStackSpace(tId)); + Platform::CopyString(thread->NameBuf, osThreadGetName(tId)); thread->name.Emplace(CharSpan::fromCharString(thread->NameBuf)); - thread->id = taskStatusArray[x].xTaskNumber; - thread->stackFreeMinimum.Emplace(taskStatusArray[x].usStackHighWaterMark); /* Unsupported metrics */ // thread->stackSize @@ -119,7 +113,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadM *threadMetricsOut = head; /* The array is no longer needed, free the memory it consumes. */ - chip::Platform::MemoryFree(taskStatusArray); + chip::Platform::MemoryFree(threadIdTable); } return CHIP_NO_ERROR; diff --git a/src/test_driver/efr32/src/main.cpp b/src/test_driver/efr32/src/main.cpp index 088dc4e8703664..a2a078c4692271 100644 --- a/src/test_driver/efr32/src/main.cpp +++ b/src/test_driver/efr32/src/main.cpp @@ -19,10 +19,10 @@ #include #include -#include #include #include #include +#include #include #include #include @@ -34,9 +34,9 @@ #include #include #include +#include #include #include -#include using namespace chip; using namespace chip::DeviceLayer; @@ -66,13 +66,17 @@ class NlTest : public pw_rpc::nanopb::NlTest::Service } // namespace chip::rpc namespace { - -#define TEST_TASK_STACK_SIZE 16 * 1024 -#define TEST_TASK_PRIORITY 1 - -static TaskHandle_t sTestTaskHandle; -StaticTask_t sTestTaskBuffer; -StackType_t sTestTaskStack[TEST_TASK_STACK_SIZE]; +osThreadId_t sTestTaskHandle; +osThread_t testTaskControlBlock; +constexpr uint32_t kTestTaskStackSize = 16 * 1024; +uint8_t testTaskStack[kTestTaskStackSize]; +constexpr osThreadAttr_t kTestTaskAttr = { .name = "TestDriver", + .attr_bits = osThreadDetached, + .cb_mem = &testTaskControlBlock, + .cb_size = osThreadCbSize, + .stack_mem = testTaskStack, + .stack_size = kTestTaskStackSize, + .priority = osPriorityNormal }; chip::rpc::NlTest nl_test_service; pw::unit_test::UnitTestService unit_test_service; @@ -105,15 +109,14 @@ int main(void) SetDeviceInstanceInfoProvider(&provision.GetStorage()); SetCommissionableDataProvider(&provision.GetStorage()); - SILABS_LOG("***** CHIP EFR32 device tests *****\r\n"); + ChipLogProgress(AppServer, "***** CHIP EFR32 device tests *****\r\n"); // Start RPC service which runs the tests. - sTestTaskHandle = xTaskCreateStatic(RunRpcService, "RPC_TEST_TASK", ArraySize(sTestTaskStack), nullptr, TEST_TASK_PRIORITY, - sTestTaskStack, &sTestTaskBuffer); - SILABS_LOG("Starting FreeRTOS scheduler"); + sTestTaskHandle = osThreadNew(RunRpcService, nullptr, &kTestTaskAttr); + ChipLogProgress(AppServer, "Starting Kernel"); sl_system_kernel_start(); // Should never get here. - SILABS_LOG("vTaskStartScheduler() failed"); + ChipLogProgress(AppServer, "sl_system_kernel_start() failed"); return -1; }