AnsweredAssumed Answered

Return value from CMSIS osSemaphoreWait

Question asked by gjesse.soren on Dec 17, 2015
Latest reply on Sep 5, 2017 by Richard Lowe
According to the documentation of CMSIS osSemaphoreWait (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 STMCubeF7 looks 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;
}

Outcomes