Skip to content

Commit

Permalink
[Silabs]Migrate some more freertos api to cmsisos (#35974)
Browse files Browse the repository at this point in the history
* Migrate some more freertos api to cmsisos

* Address comments
  • Loading branch information
jmartinez-silabs authored Oct 9, 2024
1 parent a629204 commit e02f0f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/SoftwareFaultReports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/

#include "SoftwareFaultReports.h"
#include "FreeRTOS.h"
#include "silabs_utils.h"
#include <app/clusters/software-diagnostics-server/software-diagnostics-server.h>
#include <app/util/attribute-storage.h>
#include <cmsis_os2.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>
Expand Down Expand Up @@ -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
}

Expand Down
30 changes: 12 additions & 18 deletions src/platform/silabs/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
#endif
#include "FreeRTOS.h"
#include "sl_memory_manager.h"
#include <cmsis_os2.h>
#include <inet/InetInterface.h>
#include <lib/support/CHIPMemString.h>
#include <sl_cmsis_os2_common.h>

using namespace ::chip::app::Clusters::GeneralDiagnostics;

Expand Down Expand Up @@ -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<osThreadId_t *>(chip::Platform::MemoryCalloc(threadCount, sizeof(osThreadId_t)));

taskStatusArray = static_cast<TaskStatus_t *>(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
Expand All @@ -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;
Expand Down
31 changes: 17 additions & 14 deletions src/test_driver/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#include <pw_unit_test/unit_test_service.h>

#include <AppConfig.h>
#include <FreeRTOS.h>
#include <PigweedLogger.h>
#include <PigweedLoggerMutex.h>
#include <ProvisionManager.h>
#include <cmsis_os2.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <cstring>
#include <lib/support/CHIPMem.h>
Expand All @@ -34,9 +34,9 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
#include <sl_cmsis_os2_common.h>
#include <sl_system_init.h>
#include <sl_system_kernel.h>
#include <task.h>

using namespace chip;
using namespace chip::DeviceLayer;
Expand Down Expand Up @@ -66,13 +66,17 @@ class NlTest : public pw_rpc::nanopb::NlTest::Service<NlTest>
} // 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;
Expand Down Expand Up @@ -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;
}

0 comments on commit e02f0f2

Please sign in to comment.