使用静态栈内存的 FreeRTOS 任务 (xTaskCreateStatic) 示例
另请查看我们之前使用 xTaskCreate() 动态分配内存的文章:如何向任何 PlatformIO 项目添加 FreeRTOS 任务(线程)
freertos_xTaskCreateStatic_example.cpp
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
constexpr size_t MY_TASK_STACK_SIZE = 1024;
static StaticTask_t myTaskBuffer;
static StackType_t myTaskStack[ MY_TASK_STACK_SIZE ];
void MyTask(void * parameter)
{
while(true)
{
// TODO 你的代码放在这里
}
}
void setup()
{
xTaskCreateStatic(
MyTask, // 任务函数
"MyTask", // 名称
MY_TASK_STACK_SIZE, // 栈大小
nullptr, // 参数
tskIDLE_PRIORITY,
myTaskStack,
&myTaskBuffer);
}
void loop() {
}If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow