当前位置: 首页 > 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();}

在这里插入图片描述

http://www.dtcms.com/a/169133.html

相关文章:

  • 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)(文末有下载方式)
  • 单词规律(简单)
  • B站Michale_ee——ESP32_IDF SDK——FreeRTOS_4信号量、互斥量
  • 情境领导理论——AI与思维模型【89】
  • c/c++开发调试工具之gdb
  • AI 驱动的智能交通系统:从拥堵到流畅的未来出行
  • Allegro23.1新功能之如何使用文件预览功能操作指导
  • FormCalc 支持的编程语言和软件
  • 流水线相关计算【计算机组成与体系结构】
  • 数字智慧方案5873丨智慧交通设计方案(57页PPT)(文末有下载方式)
  • Linux_sudo命令的使用与机制
  • 力扣刷题 -- 206.反转链表