FreeRTOS计数型信号量
API函数
//创建
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
#define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount )
xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
const UBaseType_t uxInitialCount )
#endif
//释放
#define xSemaphoreGive( xSemaphore )
xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )
BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue,
TickType_t xTicksToWait, const BaseType_t xCopyPosition )
//获取信号量值
#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
//等待
#define xSemaphoreTake( xSemaphore, xBlockTime )
xQueueGenericReceive( ( QueueHandle_t ) ( xSemaphore ), NULL, ( xBlockTime ), pdFALSE )
BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer,
TickType_t xTicksToWait, const BaseType_t xJustPeeking )
使用举例
SemaphoreHandle_t semaphore;
void start_task(void *pvParameters)
{
semaphore = xSemaphoreCreateCounting(10, 0);
}
void give_task(void *pvParameters)
{
UBaseType_t count;
while(1)
{
key = KEY_Scan(0);
if(key == WKUP_PRES)
{
err = xSemaphoreGive(semaphore);
count = uxSemaphoreGetCount(semaphore);
printf("give_task uxSemaphoreGetCount %d\r\n", count);
}
vTaskDelay(10);
}
}
void take_task(void *pvParameters)
{
while(1)
{
xSemaphoreTake(semaphore, portMAX_DELAY);
count = uxSemaphoreGetCount(semaphore);
printf("take_task uxSemaphoreGetCount %d\r\n", count);
vTaskDelay(1000);
}
}
实验现象
FreeRTOS计数型信号量的更多相关文章
- FreeRTOS 任务通知模拟计数型信号量
举例 //释放计数型信号量任务函数 void SemapGive_task(void *pvParameters) { u8 key; while(1) { key = KEY_Scan(0); // ...
- FreeRTOS 计数信号量
以下转载自安富莱电子: http://forum.armfly.com/forum.php 本章节开始讲解 FreeRTOS 任务间的同步和资源共享机制,计数信号量. FreeRTOS 中计数信号量的 ...
- FreeRTOS 二值信号量,互斥信号量,递归互斥信号量
以下转载自安富莱电子: http://forum.armfly.com/forum.php 本章节讲解 FreeRTOS 任务间的同步和资源共享机制,二值信号量. 二值信号量是计数信号量的一种特殊形式 ...
- 整型信号量和PV操作(计算机操作系统)
在整型信号量机制中,信号量被定义为一个整形变量.除初始化外,仅能通过两个标准的原子操作Wait(S)和Signal(S)来访问.其通常分别被称为P.V操作. 描述如下: P操作:S=S-1:如果S小于 ...
- Java 硬件同步机制 Swap 指令模拟 + 记录型信号量模拟
学校实验存档//.. 以经典的生产者消费者问题作为背景. 进程同步方式接口: package method; /** * P表示通过,V表示释放 */ public interface Method ...
- Java硬件同步机制Swap指令模拟+记录型信号量模拟
学校实验存档//.. 以经典的生产者消费者问题作为背景. 进程同步方式接口: package method; /** * P表示通过,V表示释放 */ public interface Method ...
- 「bzoj1925」「Sdoi2010」地精部落 (计数型dp)
「bzoj1925」「Sdoi2010」地精部落---------------------------------------------------------------------------- ...
- FreeRTOS二值信号量
API函数 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #define xSemaphoreCreateBinary() xQueueGenericCre ...
- 动态规划 计数型DP:dobra
令人愉快的单词(dobra)时间限制: 0.1 秒空间限制: 32 MB [问题描述]Lea 在她的一生中碰到过很多单词.其中的很大一部分都使她不愉快.作为补偿,她开始创造一些愉快的单词. Lea 通 ...
随机推荐
- 范仁义html+css课程---6、表格
范仁义html+css课程---6.表格 一.总结 一句话总结: 表格中最常用的元素就是table.tr.td.th,还有语义化的thead.tbody.tfoot标签 1.表格构成三个基本要素? t ...
- asp.net core 获取appsettings.json里的配置
public GoodsController(IConfiguration configuration) { Configuration = configuration; UpFileDir = Co ...
- ISO/IEC 9899:2011 条款5——环境
5.环境 1.一个实现在两个不同的数据处理系统环境下分别翻译C源文件与执行C程序,在本国际标准中分别称为翻译环境和执行环境.它们的特征定义并包含了根据顺从标准实现的语法及语义规则所构造的顺从标准的C程 ...
- Zookeeper 安装与简单使用
一.安装Zookeeper 其实Zookeeper的安装特别简单,也不能算安装了,只需要将Zookeeper下载后解压,就完成了安装操作. 下载地址:http://zookeeper.apache.o ...
- PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)
1079 Total Sales of Supply Chain (25 分) A supply chain is a network of retailers(零售商), distributor ...
- mybatis自动生成后无法获取主键id问题
使用mybatis的自动生成工具生成的主键id: <selectKey resultType="java.lang.Integer" keyProperty="id ...
- stylelint那些事儿
一.参考文档 - http://stylelint.cn/ - https://stylelint.io/ - https://stylelint.io/user-guide/exampl ...
- 【linux基础】Ubuntu16.04桌面突然卡住怎么办?
使用Ctrl+Alt+F1先进入命令行模式,然后根据问题进行相应的操作. re 1. Ubuntu16.04桌面突然卡住怎么办; 2. Ubuntu下图形界面卡死解决办法; end
- springboot-把web项目打成war包部署到外部tomcat
将打包方式修改为war <packaging>war</packaging> 移除tomcat依赖或者将tomcat依赖scope改为provide 移除tomcat依赖 &l ...
- Android接收RabbitMQ消息。
参考:https://blog.csdn.net/qq_36576738/article/details/83754621 我这android这边就不实现发布消息功能.因为我是在服务端那边推送消息. ...