Skip to main content
soren2
Visitor II
December 17, 2015
Question

Return value from CMSIS osSemaphoreWait

  • December 17, 2015
  • 2 replies
  • 1371 views
Posted on December 17, 2015 at 10:40

According to the

http://www.keil.com/pack/doc/CMSIS/RTOS/html/group___c_m_s_i_s___r_t_o_s___semaphore_mgmt.html#gacc15b0fc8ce1167fe43da33042e62098

(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;
}

    This topic has been closed for replies.

    2 replies

    Nickname5522_O
    Visitor II
    December 23, 2015
    Posted on December 23, 2015 at 16:54

    Hi gjesse.soren,

    This incoherence is already detected and reported ([DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/Bug%20in%20CMSIS_OS%20for%20FreeRTOS%20V1.02&&currentviews=101]Bug in CMSIS_OS for FreeRTOS V1.02.

    Thank you for your feedback.

    -Shahrzad-

    Richard Lowe
    Senior II
    September 5, 2017
    Posted on September 05, 2017 at 22:09

    Found this bug too. Happy it was reported. Having to figure out how many tokens I have is a pain otherwise.