• FreeRTOS 任务+延迟处理
 1#include <stdio.h>
 2#include <stdlib.h>
 3#include "freertos/FreeRTOS.h"
 4#include "freertos/task.h"
 5#include "driver/gpio.h"
 6#include "esp_timer.h"
 7
 8
 9void log_task(void *pvParameters) {
10    long int time_current = 0;
11    printf("log task start.\n");
12    long int  times = 0;
13    while(1) {
14        time_current = esp_timer_get_time();
15        printf("%ld(s): esp timer time: %ld us\n", times, time_current);
16        vTaskDelay(1000/ portTICK_PERIOD_MS);
17        times++;
18        if (times > 30) {
19            printf("log task stop.\n");
20            break;
21        }
22    }
23    printf("log task exit.\n");
24    vTaskDelete(NULL);
25}
26
27void app_main(void)
28{
29    TaskHandle_t xHandle;
30    printf("start sample project\n");
31    xTaskCreate(log_task, "log_task", 1024*2, NULL, tskIDLE_PRIORITY, &xHandle);
32    printf("end project\n");
33
34}