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);

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-10
  • 2021-11-18
  • 2021-11-19
  • 2021-11-19
  • 2021-04-15
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-09-14
  • 2021-05-03
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案