Skip to content

Commit

Permalink
[qpg] Use static alloc for lwip and FreeRTOS; Move LwIP to qpg_sdk (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-s-wrk authored and pull[bot] committed Jun 18, 2022
1 parent e3552c1 commit 5993285
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 343 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/qpg/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define APP_CONFIG_H

// ---- Lighting Example App Config ----

#define APP_TASK_NAME "APP"
#define APP_ON_OFF_BUTTON BTN_SW4
#define APP_FUNCTION_BUTTON BTN_SW5
#define APP_LEVEL_BUTTON BTN_SW1
Expand Down
31 changes: 23 additions & 8 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,39 @@ using namespace chip::DeviceLayer;
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10

static TaskHandle_t sAppTaskHandle;
static QueueHandle_t sAppEventQueue;
namespace {
TaskHandle_t sAppTaskHandle;
QueueHandle_t sAppEventQueue;

static bool sIsThreadProvisioned = false;
static bool sIsThreadEnabled = false;
static bool sHaveBLEConnections = false;
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;
bool sHaveServiceConnectivity = false;

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];

StaticQueue_t sAppEventQueueStruct;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;
} // namespace

AppTask AppTask::sAppTask;

CHIP_ERROR AppTask::StartAppTask()
{
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (sAppEventQueue == NULL)
{
ChipLogError(NotSpecified, "Failed to allocate app event queue");
return CHIP_ERROR_NO_MEMORY;
}

// Start App task.
if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, 1, &sAppTaskHandle) != pdPASS)
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (sAppTaskHandle != NULL)
{
return CHIP_ERROR_NO_MEMORY;
return CHIP_NO_ERROR;
}

return CHIP_NO_ERROR;
Expand Down Expand Up @@ -426,6 +437,10 @@ void AppTask::PostEvent(const AppEvent * aEvent)
ChipLogError(NotSpecified, "Failed to post event to app task event queue");
}
}
else
{
ChipLogError(NotSpecified, "Event Queue is NULL should never happen");
}
}

void AppTask::DispatchEvent(AppEvent * aEvent)
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/qpg/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define APP_CONFIG_H

// ---- Lock Example App Config ----

#define APP_TASK_NAME "APP"
#define APP_LOCK_BUTTON BTN_SW4
#define APP_FUNCTION_BUTTON BTN_SW5

Expand Down
27 changes: 18 additions & 9 deletions examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* Copyright (c) 2020-2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -55,26 +54,36 @@ using namespace chip::DeviceLayer;
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10

static TaskHandle_t sAppTaskHandle;
static QueueHandle_t sAppEventQueue;
namespace {
TaskHandle_t sAppTaskHandle;
QueueHandle_t sAppEventQueue;

static bool sIsThreadProvisioned = false;
static bool sIsThreadEnabled = false;
static bool sHaveBLEConnections = false;
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];

StaticQueue_t sAppEventQueueStruct;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;
} // namespace

AppTask AppTask::sAppTask;

CHIP_ERROR AppTask::StartAppTask()
{
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (sAppEventQueue == NULL)
{
ChipLogError(NotSpecified, "Failed to allocate app event queue");
return CHIP_ERROR_NO_MEMORY;
}

// Start App task.
if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, 1, &sAppTaskHandle) != pdPASS)
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (sAppTaskHandle == NULL)
{
return CHIP_ERROR_NO_MEMORY;
}
Expand Down
15 changes: 14 additions & 1 deletion examples/lock-app/qpg/src/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@
BoltLockManager BoltLockManager::sLock;

TimerHandle_t sLockTimer;
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_TASK) && CHIP_CONFIG_FREERTOS_USE_STATIC_TASK
StaticTimer_t sLockTimerBuffer;
#endif

CHIP_ERROR BoltLockManager::Init()
{
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_TASK) && CHIP_CONFIG_FREERTOS_USE_STATIC_TASK
sLockTimer = xTimerCreateStatic("lockTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
false, // no timer reload (==one-shot)
(void *) this, // init timer id = ble obj context
TimerEventHandler, // timer callback handler
&sLockTimerBuffer // static buffer for timer

);
#else
// Create FreeRTOS sw timer for lock timer.
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
false, // no timer reload (==one-shot)
(void *) this, // init timer id = lock obj context
TimerEventHandler // timer callback handler
);

#endif
if (sLockTimer == NULL)
{
ChipLogProgress(NotSpecified, "sLockTimer timer create failed");
Expand Down
7 changes: 6 additions & 1 deletion examples/persistent-storage/qpg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
#include <platform/KeyValueStoreManager.h>

#define APP_NAME "KVS-Test"
#define APP_TASK_STACK_SIZE (3 * 1024)

#define LOG_MODULE_ID 1

static TaskHandle_t sTestTaskHandle;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;

void TestTask(void * pvParameter)
{
while (1)
Expand Down Expand Up @@ -62,7 +67,7 @@ int main(void)
qvCHIP_Printf(LOG_MODULE_ID, "============================");

// Run tests
xTaskCreate(TestTask, "Test", 2048, NULL, 1, &sTestTaskHandle);
xTaskCreateStatic(TestTask, APP_NAME, 2048, NULL, 1, appStack, &appTaskStruct);
qvCHIP_Printf(LOG_MODULE_ID, "Starting FreeRTOS scheduler");
vTaskStartScheduler();

Expand Down
11 changes: 8 additions & 3 deletions examples/platform/qpg/project_include/OpenThreadConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 384
#define OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE 512

// Enable specific features
#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1

#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1
#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1

// Disable unneeded features
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 0
#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0
#define OPENTHREAD_CONFIG_DIAG_ENABLE 0

#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 0
#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0

#define OPENTHREAD_CONFIG_COAP_API_ENABLE 0
#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0
#define OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE 0
#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_InitChipStack(void)
mEventLoopTask = NULL;
mChipTimerActive = false;

mChipStackLock = xSemaphoreCreateMutex();
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE) && CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE
mChipStackLock = xSemaphoreCreateMutexStatic(&mChipStackLockMutex);
#else
mChipStackLock = xSemaphoreCreateMutex();
#endif // CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE

if (mChipStackLock == NULL)
{
ChipLogError(DeviceLayer, "Failed to create CHIP stack lock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class GenericPlatformManagerImpl_FreeRTOS : public GenericPlatformManagerImpl<Im
StackType_t mEventLoopStack[CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t mventLoopTaskStruct;
#endif

#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE) && CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE
StaticSemaphore_t mChipStackLockMutex;
#endif
};

// Instruct the compiler to instantiate the template only when explicitly told to do so.
Expand Down
26 changes: 24 additions & 2 deletions src/lwip/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if (lwip_platform == "cc13x2_26x2") {
import("//build_overrides/efr32_sdk.gni")
} else if (lwip_platform == "qpg") {
import("//build_overrides/qpg_sdk.gni")
import("${qpg_sdk_build_root}/qpg_sdk.gni")
} else if (lwip_platform == "k32w0") {
import("//build_overrides/k32w0_sdk.gni")
} else if (lwip_platform == "p6") {
Expand Down Expand Up @@ -91,6 +92,29 @@ if (current_os == "zephyr" || current_os == "mbed") {
group("all") {
deps = [ ":lwip" ]
}
} else if (lwip_platform == "qpg") {
config("lwip_config") {
include_dirs = [ "freertos" ]
}

lwip_target("lwip") {
public = [
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/arch/cc.h",
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/arch/perf.h",
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/lwipopts.h",
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/lwippools.h",
"freertos/arch/sys_arch.h",
]
sources =
[ "${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/sys_arch.c" ]

public_deps = [ ":lwip_buildconfig" ]
public_deps += [ "${qpg_sdk_build_root}:qpg_sdk" ]
public_configs = [
":lwip_config",
"${chip_root}/src:includes",
]
}
} else {
config("lwip_config") {
include_dirs = [ lwip_platform ]
Expand Down Expand Up @@ -125,8 +149,6 @@ if (current_os == "zephyr" || current_os == "mbed") {
public_deps += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" ]
} else if (lwip_platform == "efr32") {
public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ]
} else if (lwip_platform == "qpg") {
public_deps += [ "${qpg_sdk_build_root}:qpg_sdk" ]
} else if (lwip_platform == "standalone") {
public_deps += [ "${chip_root}/src/lib/support" ]
} else if (lwip_platform == "k32w0") {
Expand Down
97 changes: 0 additions & 97 deletions src/lwip/qpg/arch/cc.h

This file was deleted.

Loading

0 comments on commit 5993285

Please sign in to comment.