From 9e50a16a48066b544fc54e1e476b79abdc540fd3 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Tue, 19 Oct 2021 01:37:40 +0200 Subject: [PATCH] [examples] Add static memory FreeRTOS example --- .../main.cpp | 39 +++++++++++++------ .../project.xml | 5 +-- 2 files changed, 30 insertions(+), 14 deletions(-) rename examples/nucleo_f429zi/{freertos_plus_tcp => freertos_static}/main.cpp (70%) rename examples/nucleo_f429zi/{freertos_plus_tcp => freertos_static}/project.xml (65%) diff --git a/examples/nucleo_f429zi/freertos_plus_tcp/main.cpp b/examples/nucleo_f429zi/freertos_static/main.cpp similarity index 70% rename from examples/nucleo_f429zi/freertos_plus_tcp/main.cpp rename to examples/nucleo_f429zi/freertos_static/main.cpp index 140167e102..6b1354b4a9 100644 --- a/examples/nucleo_f429zi/freertos_plus_tcp/main.cpp +++ b/examples/nucleo_f429zi/freertos_static/main.cpp @@ -12,16 +12,15 @@ // ---------------------------------------------------------------------------- #include -#include +#include +#include +#include using namespace modm::platform; /** * This example uses four threads to check if task switching works correctly. * - * It also check if the FreeRTOS TCP stack can be compiled. - * No TCP functionality in this example (yet). - * * What to expect? * --------------- * - All our LEDs blinking at different rates, about 3 to 4 Hz @@ -38,27 +37,43 @@ using namespace modm::platform; */ // ---------------------------------------------------------------------------- +SemaphoreHandle_t semaphore = nullptr; +StaticSemaphore_t semaphoreBuffer; + template -class P: modm::rtos::Thread +class P { char c; uint8_t i = 0; volatile float a = 10.f; + TaskHandle_t task; + StaticTask_t taskBuffer; + StackType_t stack[1024/4]; public: - P(char c): Thread(2,1<<10), c(c) {} + P(char c): c(c) + { + xTaskCreateStatic( + [](void* obj) { reinterpret_cast(obj)->run(); }, + "anon", + (1024 / 4), + this, + 2, + stack, + &taskBuffer); + } void run() { Gpio::setOutput(); while (true) { - sleep(SleepTime * MILLISECONDS); + vTaskDelay(SleepTime * (configTICK_RATE_HZ / 1000.0)); Gpio::toggle(); { - static modm::rtos::Mutex lm; - modm::rtos::MutexGuard m(lm); + xSemaphoreTake(semaphore, portMAX_DELAY); MODM_LOG_INFO << char(i + c); + xSemaphoreGive(semaphore); } i = (i+1)%10; a *= 3.141f; @@ -70,12 +85,14 @@ P< Board::LedRed, 260 > p1('0'); P< Board::LedGreen, 260 + 10 > p2('a'); P< Board::LedBlue, 260 + 20 > p3('A'); - // ---------------------------------------------------------------------------- int main() { Board::initialize(); - modm::rtos::Scheduler::schedule(); + + semaphore = xSemaphoreCreateMutexStatic(&semaphoreBuffer); + vTaskStartScheduler(); + return 0; } diff --git a/examples/nucleo_f429zi/freertos_plus_tcp/project.xml b/examples/nucleo_f429zi/freertos_static/project.xml similarity index 65% rename from examples/nucleo_f429zi/freertos_plus_tcp/project.xml rename to examples/nucleo_f429zi/freertos_static/project.xml index 395d1497f3..1d82f7d8a5 100644 --- a/examples/nucleo_f429zi/freertos_plus_tcp/project.xml +++ b/examples/nucleo_f429zi/freertos_static/project.xml @@ -1,11 +1,10 @@ modm:nucleo-f429zi - + - modm:processing:rtos - modm:freertos:tcp + modm:freertos modm:build:scons