-
-
Save lonelybinary/eab79c894ac021893107fbc407d55055 to your computer and use it in GitHub Desktop.
Bilibili ESP-IDF WIFI Event Group Day3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
通过Event Group 来实现,任务之间的Event通知。 | |
Task2 执行完自己的秘密任务后,通知Task1,然后Task1执行自己的任务 | |
Task3 是用来验证,在通过xEventGroupWaitBits的时候CPU进入阻塞状态是不消耗CPU的。 | |
*/ | |
#include <stdio.h> | |
#include "esp_log.h" | |
#include "freertos/FreeRTOS.h" | |
#include "freertos/task.h" | |
#include "freertos/event_groups.h" | |
static EventGroupHandle_t s_wifi_event_group; | |
#define SECRET_TASK BIT23 | |
void task1(void *pt) | |
{ | |
ESP_LOGE("TASK1", "TASK1 创建完毕"); | |
while (1) | |
{ | |
ESP_LOGE("TASK1", "等待task2的把重要的事情做完"); | |
xEventGroupWaitBits(s_wifi_event_group, | |
SECRET_TASK, | |
pdFALSE, | |
pdFALSE, | |
portMAX_DELAY); | |
ESP_LOGE("TASK1", "终于轮到我了。。。。"); | |
vTaskDelete(NULL); | |
} | |
} | |
void task2(void *pt) | |
{ | |
ESP_LOGI("TASK2", "TASK2 创建完毕"); | |
while (1) | |
{ | |
ESP_LOGI("TASK2", "TASK2 假装在做很重要的事情,大约需要5秒"); | |
vTaskDelay(5000 / portTICK_PERIOD_MS); | |
xEventGroupSetBits(s_wifi_event_group, SECRET_TASK); | |
vTaskDelete(NULL); | |
} | |
} | |
void task3(void *pt) | |
{ | |
ESP_LOGI("TASK3", "TASK3 创建完毕"); | |
while (1) | |
{ | |
ESP_LOGI("TASK3", "其他任务阻塞,CPU归我了~"); | |
vTaskDelay(500 / portTICK_PERIOD_MS); | |
} | |
} | |
void app_main(void) | |
{ | |
ESP_LOGW("MAIN", "Event Group Bits : %d bits", configUSE_16_BIT_TICKS ? 8 : 24); | |
s_wifi_event_group = xEventGroupCreate(); | |
xTaskCreate(task1, "task1", 1024 * 12, NULL, 1, NULL); | |
xTaskCreate(task2, "task2", 1024 * 12, NULL, 1, NULL); | |
//xTaskCreate(task3, "task3", 1024 * 12, NULL, 1, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment