当前位置: 首页 > news >正文

B站Michale_ee——ESP32_IDF SDK——FreeRTOS_6 任务通知同步、任务通知值

一、任务通知同步

1.API简介

(1)释放任务通知

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

(2)获取任务通知

在这里插入图片描述
在这里插入图片描述

2.示例代码及运行结果

#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"static TaskHandle_t xTask1 = NULL, xTask2 = NULL;void Task1(void *pvparam)
{while(1){printf("Task1 wait notificaiton!\n");ulTaskNotifyTake( pdTRUE, portMAX_DELAY );printf("Task1 got notificaiton!\n");vTaskDelay(pdMS_TO_TICKS(3000));}
}void Task2(void *pvparam)
{while(1){vTaskDelay(pdMS_TO_TICKS(5000));printf("Task2 notify Task1\n");xTaskNotifyGive( xTask1 );}
}void app_main(void)
{vTaskSuspendAll();xTaskCreatePinnedToCore(Task1, "Task1", 1024*5, NULL, 1, &xTask1, 1);  //! ESP32-S3为双核,CPU0主要运行WiFi和蓝牙;CPU1用于运行应用程序;xTaskCreatePinnedToCore(Task2, "Task2", 1024*5, NULL, 1, &xTask2, 1);xTaskResumeAll();}

在这里插入图片描述

二、任务通知值

1.API简介

(1)等待任务通知

在这里插入图片描述
在这里插入图片描述

(2)发送任务通知

在这里插入图片描述
在这里插入图片描述

2.示例代码及运行结果

#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"static TaskHandle_t xTask1 = NULL, xTask2 = NULL;void Task1(void *pvparam)
{uint32_t ulNotifiedValue;while(1){printf("Task1 wait notificaiton!\n");xTaskNotifyWait( 0x00, /* Don't clear any notification bits on entry. */ULONG_MAX, /* Reset the notification value to 0 on exit. */&ulNotifiedValue, /* Notified value pass out in ulNotifiedValue. */portMAX_DELAY ); /* Block indefinitely. */if( ( ulNotifiedValue & 0x01 ) != 0 ){/* Bit 0 was set - process whichever event is represented by bit 0. */printf("Task1 process bit0 event!\n");}if( ( ulNotifiedValue & 0x02 ) != 0 ){/* Bit 1 was set - process whichever event is represented by bit 1. */printf("Task1 process bit1 event!\n");}if( ( ulNotifiedValue & 0x04 ) != 0 ){/* Bit 2 was set - process whichever event is represented by bit 2. */printf("Task1 process bit2 event!\n");}}
}void Task2(void *pvparam)
{while(1){printf("Task2 notify Bit0\n");xTaskNotify( xTask1, 0x01, eSetValueWithOverwrite);vTaskDelay(pdMS_TO_TICKS(5000));printf("Task2 notify Bit1\n");xTaskNotify( xTask1, 0x02, eSetValueWithOverwrite);vTaskDelay(pdMS_TO_TICKS(5000));printf("Task2 notify Bit2\n");xTaskNotify( xTask1, 0x04, eSetValueWithOverwrite);vTaskDelay(pdMS_TO_TICKS(5000));}
}void app_main(void)
{vTaskSuspendAll();xTaskCreatePinnedToCore(Task1, "Task1", 1024*5, NULL, 1, &xTask1, 1);  //! ESP32-S3为双核,CPU0主要运行WiFi和蓝牙;CPU1用于运行应用程序;xTaskCreatePinnedToCore(Task2, "Task2", 1024*5, NULL, 1, &xTask2, 1);xTaskResumeAll();}

在这里插入图片描述

相关文章:

  • Qt QGraphicsScene 的用法
  • 分享国产AI工作流集成数据库完成业务处理
  • 常见工业汽车行业通讯接口一览表
  • 珠江桥牌闪耀第137届广交会,展现中国味道与创新活力
  • 【Redis】Hash哈希
  • YOLO旋转目标检测之ONNX模型推理
  • 基于SpringBoot+Vue实现的电影推荐平台功能一
  • 通过组策略使能长路径
  • re题(52)BUUCTF-[FlareOn5]Minesweeper Championship Registration
  • 数据结构学习笔记
  • 【Linux】PetaLinux开发
  • Python虚假新闻检测识别
  • 用定时器做微妙延时注意事项
  • 第N8周:使用Word2vec实现文本分类
  • cPanel 的 Let’s Encrypt™ 插件
  • 【AI论文】WebThinker:赋予大型推理模型深度研究能力
  • 走进AI的奇妙世界:探索历史、革命与未来机遇
  • DeepSeek实战--AI技术架构(持续更新)
  • 数字智慧方案6187丨智慧应急指挥平台体系建设方案(78页PPT)(文末有下载方式)
  • 单词规律(简单)
  • 首日5金!中国队夺得跳水世界杯总决赛混合团体冠军
  • 特朗普宣布提名迈克·沃尔兹为下一任美国驻联合国大使
  • 年轻人的事业!6家上海人工智能企业畅想“模范生”新征程
  • 游客曝九寨沟打网约车被出租车围堵,官方:前者违规,后者做法不对
  • 现场聆听总书记讲话,“00后”博士和大模型CEO都“热血沸腾”
  • 人民日报评论员:汇聚起工人阶级和广大劳动群众的磅礴力量