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 通 ...
随机推荐
- 007 SpringBoot的@EnableAutoConfiguration注解
一:原理 1. 首先Spring Boot项目中都会如下启动类: @SpringBootApplication public class Application { public static voi ...
- Maven构建报错问题解决
[ERROR] Failed to execute goal on project zepeto-admin: Could not resolve dependencies -SNAPSHOT: Fa ...
- MacOS Laravel 安装教程
一.到官网选择 Laravel 版本 根据个人的喜好选择安装的版本,我选择的是 5.8 https://laravel.com/docs/5.8/installation 以下是 Laravel 5. ...
- [转]白话HTTP短连接中的Session和Token
我经常想象并怀念三十年前那原始而美好的互联网旧时光, 工作很轻松, 生活很悠闲. 上班的时候偶尔有些HTTP的请求发到我这里, 我简单的看一下, 取出相对应的html文档,图片,发回去就可以了, 然后 ...
- vue-admin-template 切换回中文
使用vue-admin-template开发项目,使用的是element-ui的控件,但这个框架走的是国际化,是英文版,好吧!快速切换为中文版: 找到main.js 第七行: 替换为: import ...
- 【翻译】Flink Table Api & SQL —— 连接到外部系统
本文翻译自官网:Connect to External Systems https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev ...
- oracle导入及导出dmp文件
导出数据库步骤: exp 用户名/密码@实例名 file=导出的dmp文件存放路径(绝对路径) log=导出日志存放路径(建议记录log文件,方便后续核实数据是否完整导出和导入) 导入数据库步骤: 1 ...
- Quartz学习笔记:基础知识
Quartz学习笔记:基础知识 引入Quartz 关于任务调度 关于任务调度,Java.util.Timer是最简单的一种实现任务调度的方法,简单的使用如下: import java.util.Tim ...
- hihocoder 1566 皇室成员的名字
#1566 : 皇室成员的名字 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho正在学习世界历史.他发现历史上很多西方国家的皇室成员的名字都是由英文名字加罗马数字组 ...
- win10安装网络适配器
上面这个有些叫Microsoft Loopback Adapter