#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#define CONFIG_LOG_MAXIMUM_LEVEL 5
static const char *TAG = "NOTIFY_APP";
static TaskHandle_t b_handle = NULL; // 任務B的指標
static void task_a(void *arg) {
while(1) {
xTaskNotifyGive(b_handle); // 先向任務B發出通知
vTaskDelay(pdMS_TO_TICKS(500)); // 等待500ms
}
}
static void task_b(void *arg) {
while(1) {
vTaskDelay(pdMS_TO_TICKS(1000)); // 先延遲1000ms
uint32_t count = ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
ESP_LOGI(TAG, "收到通知~計數值:%lu", count);
}
}
void app_main(void) {
esp_log_level_set(TAG, ESP_LOG_VERBOSE);
xTaskCreate(task_b, "Task B", 3000, NULL, 3, &b_handle);
xTaskCreate(task_a, "Task A", 2000, NULL, 5, NULL);
}