|
ELEC-C7222
Libraries for ELEC C7222 Course Work
|
C++ FreeRTOS LED test for Pico 2 W using std::thread.
More...
#include <assert.h>#include <chrono>#include <new>#include <stdio.h>#include <iostream>#include <thread>#include <functional>#include "pico/stdlib.h"
Classes | |
| class | BaseClass |
| Singleton startup coordinator. More... | |
Macros | |
| #define | LED_DELAY_MS 100 |
Functions | |
| int | pico_led_init () |
| void | pico_set_led (bool led_on) |
| Set the onboard LED state. | |
| static void | led_task () |
LED blink worker executed by std::thread. | |
| static void | log_task () |
Low-priority periodic logger executed by std::thread. | |
| int | main () |
| Application entry point. | |
Variables | |
| std::thread | led_thread |
| Global LED worker thread handle. | |
| std::thread | log_thread |
| Global logger worker thread handle. | |
C++ FreeRTOS LED test for Pico 2 W using std::thread.
This source tests a Pico 2 W board by blinking the onboard LED while running a low-priority logger task. It uses the Pico C SDK for board/LED access and FreeRTOS as the scheduler, but the application task model is C++-oriented.
Difference from main_freertos.c:
main_freertos.c creates tasks directly with xTaskCreate() and uses vTaskDelay().main_freertos.cpp creates std::thread tasks and uses std::this_thread::sleep_for(), with priorities assigned from inside the running task via vTaskPrioritySet().Dependency on FreeRTOS-cpp11:
std::thread/chrono behavior in this file depends on the FreeRTOS-cpp11 integration (FREERTOS_CPP11_SOURCES and FREERTOS_CPP11_INCLUDE_DIRS in CMake).| #define LED_DELAY_MS 100 |
|
static |
LED blink worker executed by std::thread.
Behavior:
tskIDLE_PRIORITY + 1.LED_DELAY_MS period.Usage:
std::thread{led_task} after FreeRTOS scheduler is running. 

|
static |
Low-priority periodic logger executed by std::thread.
Behavior:
tskIDLE_PRIORITY.Usage:
std::thread{log_task} after scheduler start. 
| int main | ( | void | ) |
Application entry point.
Startup sequence:
BaseClass::startup()) creates detached std::thread workers.vTaskStartScheduler().How this is used:

| int pico_led_init | ( | void | ) |

| void pico_set_led | ( | bool | led_on | ) |
Set the onboard LED state.
Usage:
pico_led_init() returns PICO_OK.true to switch LED on, false to switch LED off.| led_on | Desired LED state. |

| std::thread led_thread |
Global LED worker thread handle.
Created in BaseClass::startup() and detached immediately.
| std::thread log_thread |
Global logger worker thread handle.
Created in BaseClass::startup() and detached immediately.