说明
因为要使用CMSIS-RTOS的信号量,所以需要了解以下几点功能:
1.接收信号量时,返回值的意思
2.接收信号量时,如果信号量容器不只为一,那么是否可以再次接收到
3.发送信号量是否有限制
带着以上问题做了一个测试程序:
例一
程序代码
static void sema_send_test(void const *arg);
static void sema_rec_test(void const *arg);
static osThreadId send_seam_task_id;
osThreadDef(sema_send_test,osPriorityNormal,1,1024);
static osThreadId rec_seam_task_id;
osThreadDef(sema_rec_test,osPriorityNormal,1,1024);
static osSemaphoreId m_test_sema;
osSemaphoreDef(m_test_sema);
static osStatus status;
//用于发送信号量的任务,每300ms发送一次
static void sema_send_test(void const *arg)
{
m_test_sema = osSemaphoreCreate(osSemaphore(m_test_sema),0);
while(1)
{
status = osSemaphoreRelease(m_test_sema);
LOG(2,"send sema result : %x",status);
osDelay(300);
}
}
//用于接收信号量的任务,循环接收
static s16 count = 0;
static void sema_rec_test(void const *arg)
{
while(1)
{
count = osSemaphoreWait(m_test_sema,50);
LOG(2,"rec sema co

本文通过三个实例详细探讨了CMSIS-RTOS信号量的使用,包括接收信号量的返回值含义、信号量接收限制及信号量容器的性质。测试结果显示,信号量容器最大容量为15,超过则值归零;信号量释放和等待会相应增加或减少容器值,返回值反映接收状态。
最低0.47元/天 解锁文章
1497





