Esp32 的官方开发工具集成的是 FreeRTOS 系统,跟之前使用的 arduino freertos 系统一样,但是参数会有些微妙的区别。
示例:
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void say(void *argv) {
while(1) {
printf("Hello freertos.\n");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
void echo(void *argv) {
while(1) {
printf("echo word.\n");
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
xTaskCreate(&say, "Say", 1024 * 5, NULL, 2, NULL);
xTaskCreate(&echo, "Echo", 1024 * 5, NULL, 3, NULL);
}
xTaskCreate
函数中的第 4 个参数 usStackDepth
需要设置得大些,不然会 stack overflow 。