RTOS计数型信号量的使用流程

1.初始化计数型信号量句柄

SemaphoreHandle_t CountSemaphore;

2.创建计数型信号量

CountSemaphore=xSemaphoreCreateCounting(255,0);//255是最大计数值,0为开始计数值

3.计数型信号量的释放

BaseType_t err;

err=xSemaphoreGive(CountSemaphore);

if(err==pdFALSE)//表示计数值为0,计数型信号量释放失败

 

4.获取计数型信号量

xSemaphoreTake(CountSemaphore,portMAX_DELAY);//死等阻塞

5.获取计数值

u8 semavalue;

semavalue=uxSemaphoreGetCount(CountSemaphore);

 

猜你喜欢

转载自www.cnblogs.com/qingyunboke/p/12807366.html
今日推荐