说明
因为要使用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)
{