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

建设视频网站链接百度云盘市场调研报告ppt模板

建设视频网站链接百度云盘,市场调研报告ppt模板,做搜狗pc网站优,怎么做盗号网站手机文章目录目的基础说明使用演示作为二进制信号量作为计数信号量作为事件组作为队列或邮箱相关函数总结目的 任务通知(TaskNotify)是RTOS中相对常用的用于任务间交互的功能,这篇文章将对相关内容做个介绍。 本文代码测试环境见前面的文章&…

文章目录

  • 目的
  • 基础说明
  • 使用演示
    • 作为二进制信号量
    • 作为计数信号量
    • 作为事件组
    • 作为队列或邮箱
  • 相关函数
  • 总结

目的

任务通知(TaskNotify)是RTOS中相对常用的用于任务间交互的功能,这篇文章将对相关内容做个介绍。

本文代码测试环境见前面的文章:《FreeRTOS入门(01):基础说明与使用演示》

基础说明

前面介绍的队列、信号量、互斥量、队列集、事件组等功能都需要有个独立于任务的对象,任务通过主动去访问对象来使用相关的功能。事实上目前FreeRTOS的任务句柄本身就带有一个对象,用于任务间交互使用,这就是任务通知。

任务通知因为上面的原因有两大优势:一是轻量(因为不需要额外的对象);二是可以直接通知某个任务(也是因为没有中间商)。

任务中的任务通知结构包含状态和一个32位的数据。FreeRTOS v10.4.0 起支持单任务多条通知( 任务通知数组 ),所以现在很多函数都是因为兼容性冗余存在的。使用任务通知时需要设置下面参数:

configUSE_TASK_NOTIFICATIONS // 为1才能使用任务通知(默认为1)
configTASK_NOTIFICATION_ARRAY_ENTRIES // 为任务通知的每个任务数组中的索引数量(默认为1)

任务通知根据使用的不同可以当作二进制信号量、计数信号量、事件组、队列、邮箱等功能来使用。

使用演示

作为二进制信号量

任务通知作为二进制信号量使用就和真正的信号量一样,使用 givetake 函数来操作:

#include "debug.h"
#include "FreeRTOS.h"     // 引入头文件
#include "task.h"         // 引入头文件TaskHandle_t Task1_Handler; // 任务句柄
TaskHandle_t Task2_Handler; // 任务句柄void task1(void *pvParameters) {while(1) {uint32_t data = ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // 等待任务通知(注意第一个参数)printf("%u task1: %u\r\n", xTaskGetTickCount(), data); // 打印任务通知的值vTaskDelete(NULL);}
}void task2(void *pvParameters) {while(1) {vTaskDelay(500);xTaskNotifyGive(Task1_Handler); // 向task1给出任务通知vTaskDelete(NULL);}
}int main(void) {NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);SystemCoreClockUpdate();Delay_Init();USART_Printf_Init(115200);xTaskCreate(task1, "task1", 256, NULL, 5, &Task1_Handler);xTaskCreate(task2, "task2", 256, NULL, 5, &Task2_Handler);vTaskStartScheduler(); // 任务调度,任务将在这里根据情况开始运行,程序将在这里无序循环while(1) {} // 程序不会运行到这里
}

在这里插入图片描述

作为计数信号量

任务通知作为计数信号量使用和作为二进制信号量一样,使用 givetake 函数,唯一的区别就是 take 函数的参数不同:

#include "debug.h"
#include "FreeRTOS.h"     // 引入头文件
#include "task.h"         // 引入头文件TaskHandle_t Task1_Handler; // 任务句柄
TaskHandle_t Task2_Handler; // 任务句柄void task1(void *pvParameters) {vTaskDelay(500);while(1) {uint32_t data = ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // 等待任务通知(注意第一个参数)printf("%u task1: %u\r\n", xTaskGetTickCount(), data); // 打印任务通知的值}
}void task2(void *pvParameters) {while(1) {xTaskNotifyGive(Task1_Handler); // 向task1给出任务通知xTaskNotifyGive(Task1_Handler); // 向task1给出任务通知xTaskNotifyGive(Task1_Handler); // 向task1给出任务通知vTaskDelete(NULL);}
}int main(void) {NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);SystemCoreClockUpdate();Delay_Init();USART_Printf_Init(115200);xTaskCreate(task1, "task1", 256, NULL, 5, &Task1_Handler);xTaskCreate(task2, "task2", 256, NULL, 5, &Task2_Handler);vTaskStartScheduler(); // 任务调度,任务将在这里根据情况开始运行,程序将在这里无序循环while(1) {} // 程序不会运行到这里
}

在这里插入图片描述

作为事件组

任务通知作为事件组使用时,任务通知的 notify 函数相当于事件组的 setBits 函数,任务通知的 wait 函数相当于事件组的 waitBits 函数。

#include "debug.h"
#include "FreeRTOS.h"     // 引入头文件
#include "task.h"         // 引入头文件TaskHandle_t Task1_Handler; // 任务句柄void task1(void *pvParameters) {while(1) {uint32_t value = 0;BaseType_t ret = xTaskNotifyWait(0xfffffffa, 0, &value, portMAX_DELAY); // 在等待前清除bit2和bit0之外的值,事件触发后不清除任何位if (ret == pdPASS ) {printf("%u task1: %u\r\n", xTaskGetTickCount(), value); // 打印任务通知的值}}
}void task2(void *pvParameters) {while(1) {vTaskDelay(500);xTaskNotify(Task1_Handler, 0b0100, eSetBits ); // bit2设置为1vTaskDelete(NULL);}
}void task3(void *pvParameters) {while(1) {vTaskDelay(1000);xTaskNotify(Task1_Handler, 0b0001, eSetBits ); // bit0设置为1vTaskDelete(NULL);}
}int main(void) {NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);SystemCoreClockUpdate();Delay_Init();USART_Printf_Init(115200);xTaskCreate(task1, "task1", 256, NULL, 5, &Task1_Handler);xTaskCreate(task2, "task2", 256, NULL, 5, NULL);xTaskCreate(task3, "task3", 256, NULL, 5, NULL);vTaskStartScheduler(); // 任务调度,任务将在这里根据情况开始运行,程序将在这里无序循环while(1) {} // 程序不会运行到这里
}

在这里插入图片描述

作为队列或邮箱

任务通知不管是作为队列还是作为邮箱使用都相当于一个长度只有 1 的队列,使用的是 notifysetBits 函数,对这两个参数使用不同的方式会相当于不同的功能。

#include "debug.h"
#include "FreeRTOS.h"     // 引入头文件
#include "task.h"         // 引入头文件TaskHandle_t Task1_Handler; // 任务句柄void task1(void *pvParameters) {while(1) {uint32_t value = 0;BaseType_t ret = xTaskNotifyWait(0xffffffff, 0, &value, portMAX_DELAY); // 事件触发后清除数据相当于队列
//        BaseType_t ret = xTaskNotifyWait(0xffffffff, 0xffffffff, &value, portMAX_DELAY); // 事件触发后不清除数据相当于邮箱if (ret == pdPASS ) {printf("%u task1: %u\r\n", xTaskGetTickCount(), value); // 打印任务通知的值}}
}void task2(void *pvParameters) {while(1) {vTaskDelay(500);xTaskNotify(Task1_Handler, 233, eSetValueWithoutOverwrite); // 写入数据// eSetValueWithoutOverwrite相当于队列,eSetValueWithOverwrite相当于邮箱}
}int main(void) {NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);SystemCoreClockUpdate();Delay_Init();USART_Printf_Init(115200);xTaskCreate(task1, "task1", 256, NULL, 5, &Task1_Handler);xTaskCreate(task2, "task2", 256, NULL, 5, NULL);vTaskStartScheduler(); // 任务调度,任务将在这里根据情况开始运行,程序将在这里无序循环while(1) {} // 程序不会运行到这里
}

在这里插入图片描述

相关函数

// 给出通知(索引0)
BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify )
void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken );// 给出通知,uxIndexToNotify为指定索引值
BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify )
void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify,  BaseType_t *pxHigherPriorityTaskWoken );// 等待通知(索引0)
// xClearCountOnExit为pdFALSE则任务通知的值在该函数退出时递减,为pdTRUE则在退出时清零
uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
// 等待通知,uxIndexToWaitOn为指定索引值
uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );// 给出通知(索引0)
// ulValue为通知的值
// eAction可选值如下:
// eNoAction - 目标任务接收事件,但不用更新值,此时不关心ulValue
// eSetBits - 目标通知的值使用按位或与ulValue进行运算(这通常被当作事件组使用)
// eIncrement - 目标通知的值自增,此时不关心ulValue(这通常被当作信号量使用)
// eSetValueWithOverwrite - 使用ulValue覆盖目标通知的值(这通常被当作邮箱使用)
// eSetValueWithoutOverwrite - (这通常被当作长度为1的队列使用)
BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );// 给出通知,uxIndexToNotify为指定索引值
BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );// 等待通知(索引0)
// ulBitsToClearOnEntry表示等待前清零的任务通知值的位
// ulBitsToClearOnExit表示通知发生后清零的任务通知值的位
// pulNotificationValue用来接收任务通知发生时的值
// 返回值pdPASS表示成功,pdFAIL表示超时
BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
// 等待通知,uxIndexToWaitOn为指定索引值
BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );// 给出通知
// 功能类似xTaskNotify
// pulPreviousNotifyValue可以用来接收修改前的目标任务通知的值
BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken );
BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken );// 将通知的状态设置为默认
BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear );
// 将通知的值设置为默认
uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );

总结

任务通知功能丰富、又轻量,如果可以满足业务功能需求的话,使用任务通知是个不错的选择。


文章转载自:
http://hogweed.wqfj.cn
http://bloodiness.wqfj.cn
http://worsen.wqfj.cn
http://scabble.wqfj.cn
http://pyrolignic.wqfj.cn
http://malleate.wqfj.cn
http://physiographical.wqfj.cn
http://cornfield.wqfj.cn
http://allowedly.wqfj.cn
http://thuggish.wqfj.cn
http://spiritualize.wqfj.cn
http://monopolise.wqfj.cn
http://limp.wqfj.cn
http://velaria.wqfj.cn
http://kine.wqfj.cn
http://exhibitively.wqfj.cn
http://sculp.wqfj.cn
http://rightie.wqfj.cn
http://theoretics.wqfj.cn
http://indention.wqfj.cn
http://fluoroscopist.wqfj.cn
http://ehf.wqfj.cn
http://excitative.wqfj.cn
http://clergy.wqfj.cn
http://legioned.wqfj.cn
http://bashfully.wqfj.cn
http://radioconductor.wqfj.cn
http://sclav.wqfj.cn
http://labialism.wqfj.cn
http://reintroduce.wqfj.cn
http://grotesquely.wqfj.cn
http://chow.wqfj.cn
http://wildwind.wqfj.cn
http://pubertal.wqfj.cn
http://ferry.wqfj.cn
http://shopworn.wqfj.cn
http://hospodar.wqfj.cn
http://demon.wqfj.cn
http://cognoscible.wqfj.cn
http://class.wqfj.cn
http://moderator.wqfj.cn
http://quasiparticle.wqfj.cn
http://precoital.wqfj.cn
http://heteroclitic.wqfj.cn
http://sorrowful.wqfj.cn
http://axisymmetric.wqfj.cn
http://megacity.wqfj.cn
http://guana.wqfj.cn
http://trivialize.wqfj.cn
http://shower.wqfj.cn
http://yachtswoman.wqfj.cn
http://renumerate.wqfj.cn
http://samel.wqfj.cn
http://stickjaw.wqfj.cn
http://metaraminol.wqfj.cn
http://semainier.wqfj.cn
http://isogamy.wqfj.cn
http://preachy.wqfj.cn
http://squeaker.wqfj.cn
http://disforest.wqfj.cn
http://abridgment.wqfj.cn
http://demogorgon.wqfj.cn
http://millieme.wqfj.cn
http://cottony.wqfj.cn
http://retreatism.wqfj.cn
http://strumitis.wqfj.cn
http://whinchat.wqfj.cn
http://solder.wqfj.cn
http://charterer.wqfj.cn
http://cassock.wqfj.cn
http://crinoidea.wqfj.cn
http://inkwood.wqfj.cn
http://absorbefacient.wqfj.cn
http://semibarbarous.wqfj.cn
http://landing.wqfj.cn
http://unreconciled.wqfj.cn
http://beaucoup.wqfj.cn
http://tinner.wqfj.cn
http://teevee.wqfj.cn
http://faradize.wqfj.cn
http://cavelike.wqfj.cn
http://stealthy.wqfj.cn
http://cocksfoot.wqfj.cn
http://receptor.wqfj.cn
http://bloodthirsty.wqfj.cn
http://foreran.wqfj.cn
http://brahmanical.wqfj.cn
http://rearmament.wqfj.cn
http://dissector.wqfj.cn
http://lymphopenia.wqfj.cn
http://rim.wqfj.cn
http://reclothe.wqfj.cn
http://legionaire.wqfj.cn
http://rhododendron.wqfj.cn
http://glauberite.wqfj.cn
http://multifactor.wqfj.cn
http://lozengy.wqfj.cn
http://cutdown.wqfj.cn
http://wap.wqfj.cn
http://paltry.wqfj.cn
http://www.hrbkazy.com/news/68839.html

相关文章:

  • 百度蜘蛛抓取新网站如何推广软件
  • 创建一个公司要多少钱兰州seo优化
  • 域名注册好了怎么打开网站郑州网
  • 网站建设维护工作网站seo关键词设置
  • 合肥仿站定制模板建站网络营销团队
  • 自动优化网站建设热线百度网盘网页版官网
  • 无锡网站的建设百度大数据中心
  • 做企业网站怎么样免费发广告的网站大全
  • 黑彩网站自己可以做么seo网络推广公司报价
  • 国内好用的搜索引擎优化设计三年级上册答案
  • php网站开发岗位要求什么是市场营销
  • 免费的网站模板哪里有360优化大师旧版本
  • 悬浮图片wordpress前端seo是什么
  • 网站使用的数据库主要有哪些百度权重排名
  • wordpress怎么加备案号南京 seo 价格
  • 网站开发环境lmnp安卓优化大师2023
  • 商品管理系统南京seo排名优化公司
  • 上海域名icp海网站建设全国疫情的最新数据
  • iis 网站拒绝显示此网页百度平台商家客服
  • wordpress没有页面模板seo关键词大搜
  • 1688网站怎么做分销app推广平台有哪些
  • 室内设计在线设计上海小红书seo
  • 运营方案怎么做惠州百度推广优化排名
  • 美容北京公司网站建设seo推广软件排行榜前十名
  • 网站最佳颜色搭配长春网站制作系统
  • 定制网站制作公司惠州一搜在线信息技术供应长沙seo优化公司
  • 铁岭做网站的网络营销优化培训
  • 新网网站制作商品标题seo是什么意思
  • 一家专业做家谱的网站网络营销与网站推广的区别
  • 怎样做视频播放网站网站关键词优化公司哪家好