Skip to content

Commit 5993285

Browse files
nikita-s-wrkpull[bot]
nikita-s-wrk
authored andcommitted
[qpg] Use static alloc for lwip and FreeRTOS; Move LwIP to qpg_sdk (#11257)
1 parent e3552c1 commit 5993285

File tree

20 files changed

+142
-343
lines changed

20 files changed

+142
-343
lines changed

examples/lighting-app/qpg/include/AppConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define APP_CONFIG_H
2121

2222
// ---- Lighting Example App Config ----
23-
23+
#define APP_TASK_NAME "APP"
2424
#define APP_ON_OFF_BUTTON BTN_SW4
2525
#define APP_FUNCTION_BUTTON BTN_SW5
2626
#define APP_LEVEL_BUTTON BTN_SW1

examples/lighting-app/qpg/src/AppTask.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,39 @@ using namespace chip::DeviceLayer;
5454
#define APP_TASK_PRIORITY 2
5555
#define APP_EVENT_QUEUE_SIZE 10
5656

57-
static TaskHandle_t sAppTaskHandle;
58-
static QueueHandle_t sAppEventQueue;
57+
namespace {
58+
TaskHandle_t sAppTaskHandle;
59+
QueueHandle_t sAppEventQueue;
5960

60-
static bool sIsThreadProvisioned = false;
61-
static bool sIsThreadEnabled = false;
62-
static bool sHaveBLEConnections = false;
61+
bool sIsThreadProvisioned = false;
62+
bool sIsThreadEnabled = false;
63+
bool sHaveBLEConnections = false;
64+
bool sHaveServiceConnectivity = false;
65+
66+
uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];
67+
68+
StaticQueue_t sAppEventQueueStruct;
69+
70+
StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
71+
StaticTask_t appTaskStruct;
72+
} // namespace
6373

6474
AppTask AppTask::sAppTask;
6575

6676
CHIP_ERROR AppTask::StartAppTask()
6777
{
68-
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
78+
sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
6979
if (sAppEventQueue == NULL)
7080
{
7181
ChipLogError(NotSpecified, "Failed to allocate app event queue");
7282
return CHIP_ERROR_NO_MEMORY;
7383
}
7484

7585
// Start App task.
76-
if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, 1, &sAppTaskHandle) != pdPASS)
86+
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
87+
if (sAppTaskHandle != NULL)
7788
{
78-
return CHIP_ERROR_NO_MEMORY;
89+
return CHIP_NO_ERROR;
7990
}
8091

8192
return CHIP_NO_ERROR;
@@ -426,6 +437,10 @@ void AppTask::PostEvent(const AppEvent * aEvent)
426437
ChipLogError(NotSpecified, "Failed to post event to app task event queue");
427438
}
428439
}
440+
else
441+
{
442+
ChipLogError(NotSpecified, "Event Queue is NULL should never happen");
443+
}
429444
}
430445

431446
void AppTask::DispatchEvent(AppEvent * aEvent)

examples/lock-app/qpg/include/AppConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define APP_CONFIG_H
2121

2222
// ---- Lock Example App Config ----
23-
23+
#define APP_TASK_NAME "APP"
2424
#define APP_LOCK_BUTTON BTN_SW4
2525
#define APP_FUNCTION_BUTTON BTN_SW5
2626

examples/lock-app/qpg/src/AppTask.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2020 Project CHIP Authors
4-
* Copyright (c) 2019 Google LLC.
3+
* Copyright (c) 2020-2021 Project CHIP Authors
54
* All rights reserved.
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -55,26 +54,36 @@ using namespace chip::DeviceLayer;
5554
#define APP_TASK_PRIORITY 2
5655
#define APP_EVENT_QUEUE_SIZE 10
5756

58-
static TaskHandle_t sAppTaskHandle;
59-
static QueueHandle_t sAppEventQueue;
57+
namespace {
58+
TaskHandle_t sAppTaskHandle;
59+
QueueHandle_t sAppEventQueue;
6060

61-
static bool sIsThreadProvisioned = false;
62-
static bool sIsThreadEnabled = false;
63-
static bool sHaveBLEConnections = false;
61+
bool sIsThreadProvisioned = false;
62+
bool sIsThreadEnabled = false;
63+
bool sHaveBLEConnections = false;
64+
65+
uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];
66+
67+
StaticQueue_t sAppEventQueueStruct;
68+
69+
StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
70+
StaticTask_t appTaskStruct;
71+
} // namespace
6472

6573
AppTask AppTask::sAppTask;
6674

6775
CHIP_ERROR AppTask::StartAppTask()
6876
{
69-
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
77+
sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
7078
if (sAppEventQueue == NULL)
7179
{
7280
ChipLogError(NotSpecified, "Failed to allocate app event queue");
7381
return CHIP_ERROR_NO_MEMORY;
7482
}
7583

7684
// Start App task.
77-
if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, 1, &sAppTaskHandle) != pdPASS)
85+
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
86+
if (sAppTaskHandle == NULL)
7887
{
7988
return CHIP_ERROR_NO_MEMORY;
8089
}

examples/lock-app/qpg/src/BoltLockManager.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,30 @@
2626
BoltLockManager BoltLockManager::sLock;
2727

2828
TimerHandle_t sLockTimer;
29+
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_TASK) && CHIP_CONFIG_FREERTOS_USE_STATIC_TASK
30+
StaticTimer_t sLockTimerBuffer;
31+
#endif
2932

3033
CHIP_ERROR BoltLockManager::Init()
3134
{
35+
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_TASK) && CHIP_CONFIG_FREERTOS_USE_STATIC_TASK
36+
sLockTimer = xTimerCreateStatic("lockTmr", // Just a text name, not used by the RTOS kernel
37+
1, // == default timer period (mS)
38+
false, // no timer reload (==one-shot)
39+
(void *) this, // init timer id = ble obj context
40+
TimerEventHandler, // timer callback handler
41+
&sLockTimerBuffer // static buffer for timer
42+
43+
);
44+
#else
3245
// Create FreeRTOS sw timer for lock timer.
3346
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
3447
1, // == default timer period (mS)
3548
false, // no timer reload (==one-shot)
3649
(void *) this, // init timer id = lock obj context
3750
TimerEventHandler // timer callback handler
3851
);
39-
52+
#endif
4053
if (sLockTimer == NULL)
4154
{
4255
ChipLogProgress(NotSpecified, "sLockTimer timer create failed");

examples/persistent-storage/qpg/main.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@
3030
#include <platform/KeyValueStoreManager.h>
3131

3232
#define APP_NAME "KVS-Test"
33+
#define APP_TASK_STACK_SIZE (3 * 1024)
3334

3435
#define LOG_MODULE_ID 1
3536

3637
static TaskHandle_t sTestTaskHandle;
38+
39+
StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
40+
StaticTask_t appTaskStruct;
41+
3742
void TestTask(void * pvParameter)
3843
{
3944
while (1)
@@ -62,7 +67,7 @@ int main(void)
6267
qvCHIP_Printf(LOG_MODULE_ID, "============================");
6368

6469
// Run tests
65-
xTaskCreate(TestTask, "Test", 2048, NULL, 1, &sTestTaskHandle);
70+
xTaskCreateStatic(TestTask, APP_NAME, 2048, NULL, 1, appStack, &appTaskStruct);
6671
qvCHIP_Printf(LOG_MODULE_ID, "Starting FreeRTOS scheduler");
6772
vTaskStartScheduler();
6873

examples/platform/qpg/project_include/OpenThreadConfig.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@
5858
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 384
5959
#define OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE 512
6060

61-
// Enable specific features
62-
#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
6361
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
6462
#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1
6563

6664
#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1
6765
#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1
6866

69-
// Disable unneeded features
67+
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 0
68+
#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0
69+
#define OPENTHREAD_CONFIG_DIAG_ENABLE 0
70+
71+
#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 0
72+
#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0
73+
7074
#define OPENTHREAD_CONFIG_COAP_API_ENABLE 0
75+
#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
7176
#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0
7277
#define OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE 0
7378
#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0

src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_InitChipStack(void)
5252
mEventLoopTask = NULL;
5353
mChipTimerActive = false;
5454

55-
mChipStackLock = xSemaphoreCreateMutex();
55+
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE) && CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE
56+
mChipStackLock = xSemaphoreCreateMutexStatic(&mChipStackLockMutex);
57+
#else
58+
mChipStackLock = xSemaphoreCreateMutex();
59+
#endif // CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE
60+
5661
if (mChipStackLock == NULL)
5762
{
5863
ChipLogError(DeviceLayer, "Failed to create CHIP stack lock");

src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class GenericPlatformManagerImpl_FreeRTOS : public GenericPlatformManagerImpl<Im
9999
StackType_t mEventLoopStack[CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE / sizeof(StackType_t)];
100100
StaticTask_t mventLoopTaskStruct;
101101
#endif
102+
103+
#if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE) && CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE
104+
StaticSemaphore_t mChipStackLockMutex;
105+
#endif
102106
};
103107

104108
// Instruct the compiler to instantiate the template only when explicitly told to do so.

src/lwip/BUILD.gn

+24-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if (lwip_platform == "cc13x2_26x2") {
4747
import("//build_overrides/efr32_sdk.gni")
4848
} else if (lwip_platform == "qpg") {
4949
import("//build_overrides/qpg_sdk.gni")
50+
import("${qpg_sdk_build_root}/qpg_sdk.gni")
5051
} else if (lwip_platform == "k32w0") {
5152
import("//build_overrides/k32w0_sdk.gni")
5253
} else if (lwip_platform == "p6") {
@@ -91,6 +92,29 @@ if (current_os == "zephyr" || current_os == "mbed") {
9192
group("all") {
9293
deps = [ ":lwip" ]
9394
}
95+
} else if (lwip_platform == "qpg") {
96+
config("lwip_config") {
97+
include_dirs = [ "freertos" ]
98+
}
99+
100+
lwip_target("lwip") {
101+
public = [
102+
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/arch/cc.h",
103+
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/arch/perf.h",
104+
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/lwipopts.h",
105+
"${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/lwippools.h",
106+
"freertos/arch/sys_arch.h",
107+
]
108+
sources =
109+
[ "${qpg_sdk_build_root}/repo/${qpg_target_ic}/comps/lwip/sys_arch.c" ]
110+
111+
public_deps = [ ":lwip_buildconfig" ]
112+
public_deps += [ "${qpg_sdk_build_root}:qpg_sdk" ]
113+
public_configs = [
114+
":lwip_config",
115+
"${chip_root}/src:includes",
116+
]
117+
}
94118
} else {
95119
config("lwip_config") {
96120
include_dirs = [ lwip_platform ]
@@ -125,8 +149,6 @@ if (current_os == "zephyr" || current_os == "mbed") {
125149
public_deps += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" ]
126150
} else if (lwip_platform == "efr32") {
127151
public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ]
128-
} else if (lwip_platform == "qpg") {
129-
public_deps += [ "${qpg_sdk_build_root}:qpg_sdk" ]
130152
} else if (lwip_platform == "standalone") {
131153
public_deps += [ "${chip_root}/src/lib/support" ]
132154
} else if (lwip_platform == "k32w0") {

src/lwip/qpg/arch/cc.h

-97
This file was deleted.

0 commit comments

Comments
 (0)