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 通 ...
随机推荐
- 【postman】api开发必备神器
1.使用参考:https://blog.csdn.net/fxbin123/article/details/80428216 2.win 下载地址:Postman for windows X64 ...
- mysqldump: Got error: 1449: The user specified as a definer ('xxx'@'%') does not exist when using LOCK TABLES
开发同学说在测试环境使用mysqldump导出数据的时候遇到以下错误: # mysqldump -uroot -p --all-databases --routines --events --trig ...
- rabbitmq - 消息接收,解析xml格式数据时异常:ERROR not well-formed (invalid token): line 4, column 46
ERROR alsv odoo.addons.cus_alsv.utils.alsv_about_mq.get_data_from_mq: parse_xml_data_from_mq: not we ...
- vue---使用Class
在用vue-cli开发项目的时候,很多时候会用到类.具体的使用方法: config.js(使用类,还可以定义构造函数) class config { /** * 构造函数 * @param {stri ...
- java算法 -- 基数排序
基数排序(英语:Radix sort)是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较.由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排 ...
- SpringCloud中遇到的问题总结
1.如果数据库URL字符串中不加serverTimezone=GMT%2B8且数据库未设置时区,会报如下错误 Caused by: com.mysql.cj.exceptions.InvalidCon ...
- php中类的不定参数使用示例
在类的实例化过程中,可以带或不带参数,那么构造函数将如何处理这些参数呢?为了使构造函数具有通用性,在定义构造函数时,一般不带参数,然后在其内部对参数情况进行处理.下面代码显示了一个完整的通用Perso ...
- [LeetCode] 112. Path Sum 路径和
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展平为链表
Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 ...
- Neo4j CQL基本使用
Neo4j用CQL作为查询语言 CQL Neo4j图形数据库的查询语言 是一种声明性模式匹配语言 遵循SQL语法 语法是非常简单且人性化.可读的格式 1.启动服务,打开浏览器 在数据浏览器中的美元提 ...