Question
Return value from CMSIS osSemaphoreWait
Posted on December 17, 2015 at 10:40
According to the
(CMSIS version 1.02) the return value should be the number of tokens available. This is a citation from the documentation: ''The return value indicates the number of available tokens (the semaphore count value). If 0 is returned, then no semaphore was available.'' However, the implementation in STM32CubeF7 returns osOK (which is 0) when the semaphore is acquired. Is this the intended behaviour? Is the documentation wrong? The implementation in STMCubeF7looks like this:int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
{
TickType_t ticks;
portBASE_TYPE taskWoken = pdFALSE;
if (semaphore_id == NULL) {
return osErrorParameter;
}
ticks = 0;
if (millisec == osWaitForever) {
ticks = portMAX_DELAY;
}
else if (millisec != 0) {
ticks = millisec / portTICK_PERIOD_MS;
if (ticks == 0) {
ticks = 1;
}
}
if (inHandlerMode()) {
if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE) {
return osErrorOS;
}
portEND_SWITCHING_ISR(taskWoken);
}
else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) {
return osErrorOS;
}
return osOK;
}