默认配置创建的FreeRTOS 工程,手动在任务中创建信号量,没有配置configUSE_COUNTING_SEMAPHORES
?所以创建的都是二值量
osSemaphoreDef(Log_rx_Sem);
log_rx_SemHandle = osSemaphoreCreate(osSemaphore(Log_rx_Sem), 1);
使用中发现,信号量有初值,创建完即可收到信号量。
在线调试发现创建过程中,创建函数判断semaphore_def->controlblock == NULL,故而调用的函数为老版本函数vSemaphoreCreateBinary(sema);已知老版本函数是有初值的,新版本函数xSemaphoreCreateBinary()没有初值,无奈只能直接使用xSemaphoreCreateBinary()来创建。
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count)
{
#if (configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
osSemaphoreId sema;
if (semaphore_def->controlblock != NULL){
if (count == 1) {
return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock );
}
else {
#if (configUSE_COUNTING_SEMAPHORES == 1 )
return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock );
#else
return NULL;
#endif
}
}
else {
if (count == 1) {
vSemaphoreCreateBinary(sema);
return sema;
}
else {
#if (configUSE_COUNTING_SEMAPHORES == 1 )
return xSemaphoreCreateCounting(count, count);
#else
return NULL;
#endif
}
}
#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) // configSUPPORT_DYNAMIC_ALLOCATION == 0
if(count == 1) {
return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock );
}
else
{
#if (configUSE_COUNTING_SEMAPHORES == 1 )
return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock );
#else
return NULL;
#endif
}
#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1
osSemaphoreId sema;
if (count == 1) {
vSemaphoreCreateBinary(sema);
return sema;
}
else {
#if (configUSE_COUNTING_SEMAPHORES == 1 )
return xSemaphoreCreateCounting(count, count);
#else
return NULL;
#endif
}
#endif
}
|