Example #1
0
static void add_thread_signal_map (osThreadId thread_id, EventGroupHandle_t signals)
{
    int dummy;
//    uint32_t i;
    ThreadSignalRec *prec_entity;

    if (inHandlerMode()) {
        dummy = portSET_INTERRUPT_MASK_FROM_ISR();
    }
    else {
        vPortEnterCritical();
    }

    prec_entity = (ThreadSignalRec*) malloc(sizeof(ThreadSignalRec));

    if (prec_entity != NULL) {
        prec_entity->thread_id = thread_id;
        prec_entity->signals = signals;
        prec_entity->pnext = NULL;
        if (pThreadSignalMapHead == NULL) {
            pThreadSignalMapHead = prec_entity;
            pThreadSignalMapTail = prec_entity;
        }
        else {
            pThreadSignalMapTail->pnext = prec_entity;
            pThreadSignalMapTail = prec_entity;
        }
    }
    else {
        CMSIS_OS_ERR("No Free Thread-Signal entity\n");
    }

#if 0    
    for (i=0;i<THREAD_SIGNAL_MAP_SIZE;i++)
    {
        if (!ThreadSignalMapTable[i].is_in_use) {
            ThreadSignalMapTable[i].is_in_use = 1;
            ThreadSignalMapTable[i].thread_id = thread_id;
            ThreadSignalMapTable[i].signals = signals;
            break;
        }
    }

    if (i >= THREAD_SIGNAL_MAP_SIZE) {
        // No free Thread-Signals map entity
        CMSIS_OS_ERR("No Free Thread-Signal entity\n");
    }

#endif

    if (inHandlerMode()) {
        portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
    }
    else {
        vPortExitCritical();
    }

}
Example #2
0
static EventGroupHandle_t find_signal_by_thread (osThreadId thread_id)
{
    EventGroupHandle_t signals_hdl=NULL;
//    uint32_t i;
    int dummy;
    ThreadSignalRec *prec_entity;
    
    if (inHandlerMode()) {
        dummy = portSET_INTERRUPT_MASK_FROM_ISR();
    }
    else {
        vPortEnterCritical();
    }

    prec_entity = pThreadSignalMapHead;
    while (prec_entity != NULL) {
        if (prec_entity->thread_id == thread_id) {
            signals_hdl = prec_entity->signals;
            break;
        }
        else {
            prec_entity = prec_entity->pnext;
        }
    }

#if 0    
    for (i=0;i<THREAD_SIGNAL_MAP_SIZE;i++)
    {
        if ((ThreadSignalMapTable[i].is_in_use)  && 
            (ThreadSignalMapTable[i].thread_id == thread_id)) {
            signals_hdl = ThreadSignalMapTable[i].signals;
            break;
        }
    }
#endif

    if (inHandlerMode()) {
        portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
    }
    else {
        vPortExitCritical();
    }

    if (NULL == signals_hdl) {
        CMSIS_OS_ERR("Cannot find the EventGroup Handle by thread_id\n");
    }

    return signals_hdl;
}
Example #3
0
/**
* @brief Put a mail to a queue
* @param  queue_id      mail queue ID obtained with \ref osMailCreate.
* @param  mail          memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
* @retval status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
*/
osStatus osMailPut (osMailQId queue_id, void *mail)
{
  portBASE_TYPE taskWoken;
  
  
  if (queue_id == NULL) {
    return osErrorParameter;
  }
  
  taskWoken = pdFALSE;
  
  if (inHandlerMode()) {
    if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) {
      return osErrorOS;
    }
    portEND_SWITCHING_ISR(taskWoken);
  }
  else {
    if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE) { 
      return osErrorOS;
    }
  }
  
  return osOK;
}
Example #4
0
/**
* @brief Wait until a Semaphore token becomes available
* @param  semaphore_id  semaphore object referenced with \ref osSemaphore.
* @param  millisec      timeout value or 0 in case of no time-out.
* @retval  number of available tokens, or -1 in case of incorrect parameters.
* @note   MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
*/
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;
}
Example #5
0
/// Start or restart a timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
/// \param[in]     millisec      time delay value of the timer.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec)
{
    portBASE_TYPE taskWoken = pdFALSE;
    osStatus result = osOK;
    portTickType ticks = millisec / portTICK_RATE_MS;
    if (ticks == 0) {
        ticks = 1;
    }

    if (inHandlerMode()) {
        if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) == pdPASS) {
            xTimerStartFromISR(timer_id, &taskWoken);
            portEND_SWITCHING_ISR(taskWoken);
        }
    }
    else {
        //TODO: add timeout support
        if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) {
            result = osErrorOS;
        }
        else {
            if (xTimerStart(timer_id, 0) != pdPASS) {
                result = osErrorOS;
            }
        }
    }

    return result;
}
Example #6
0
/// Put a mail to a queue
/// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
/// \param[in]     mail          memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
osStatus osMailPut (osMailQId queue_id, void *mail)
{
    portBASE_TYPE taskWoken;
    portTickType ticks=1000/portTICK_RATE_MS;   // No timeout is defined for this function, so we just wait 1 sec


    if (queue_id == NULL) {
        return osErrorParameter;
    }

    taskWoken = pdFALSE;

    if (inHandlerMode()) {
        if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) {
            return osErrorOS;
        }
        portEND_SWITCHING_ISR(taskWoken);
    }
    else {
        if (xQueueSend(queue_id->handle, &mail, ticks) != pdTRUE) {  //TODO where to get timeout value?
            return osErrorOS;
        }
    }

    return osOK;
}
Example #7
0
/// Get a Message or Wait for a Message from a Queue.
/// \param[in]     queue_id      message queue ID obtained with \ref osMessageCreate.
/// \param[in]     millisec      timeout value or 0 in case of no time-out.
/// \return event information that includes status code.
/// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
{
    portBASE_TYPE taskWoken = pdFALSE;
    portTickType ticks;
    osEvent   retEvent;

    retEvent.def.message_id = queue_id;
    if (inHandlerMode()) {
        if (xQueueReceiveFromISR(queue_id, (void *)retEvent.value.p, &taskWoken) != pdTRUE) {
            retEvent.status = osErrorOS;
            return retEvent;
        }
        portEND_SWITCHING_ISR(taskWoken);
    }
    else {
        ticks = millisec_to_ticks(millisec);
        
        if (xQueueReceive(queue_id, (void *)retEvent.value.p, ticks) != pdTRUE) {
            retEvent.status = osErrorOS;
            return retEvent;
        }
    }

    retEvent.status = osOK;
    
    return retEvent;
}
Example #8
0
/**
* @brief Wait until a Semaphore token becomes available
* @param  semaphore_id  semaphore object referenced with \ref osSemaphore.
* @param  millisec      timeout value or 0 in case of no time-out.
* @retval  number of available tokens, or -1 in case of incorrect parameters.
* @note   MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
*/
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
{
  portTickType ticks;
  
  
  if (semaphore_id == NULL) {
    return osErrorParameter;
  }
  
  ticks = 0;
  if (millisec == osWaitForever) {
    ticks = portMAX_DELAY;
  }
  else if (millisec != 0) {
    ticks = millisec / portTICK_RATE_MS;
    if (ticks == 0) {
      ticks = 1;
    }
  }
  
  if (inHandlerMode()) {
    return osErrorISR;
  }
  
  if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) {
    return osErrorOS;
  }
  
  return osOK;
}
Example #9
0
/**
* @brief  Get the value of the Kernel SysTick timer
* @param  None
* @retval None
* @note   MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.
*/
uint32_t osKernelSysTick(void)
{
  if (inHandlerMode()) {
    return xTaskGetTickCountFromISR();
  }
  else {
    return xTaskGetTickCount();
  }
}
Example #10
0
/// Return an allocated memory block back to a specific memory pool
/// \param[in]     pool_id       memory pool ID obtain referenced with \ref osPoolCreate.
/// \param[in]     block         address of the allocated memory block that is returned to the memory pool.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
osStatus osPoolFree (osPoolId pool_id, void *block)
{
    int dummy;
    uint32_t index;

    if (pool_id == NULL) {
        return osErrorParameter;
    }

    if (block == NULL) {
        return osErrorParameter;
    }

    if (block < pool_id->pool) {
        return osErrorParameter;
    }

    index = (uint32_t)block - (uint32_t)(pool_id->pool);
    if (index % pool_id->item_sz) {
        return osErrorParameter;
    }
    index = index / pool_id->item_sz;
    if (index >= pool_id->pool_sz) {
        return osErrorParameter;
    }

    if (inHandlerMode()) {
        dummy = portSET_INTERRUPT_MASK_FROM_ISR();
    }
    else {
        vPortEnterCritical();
    }

    pool_id->markers[index] = 0;

    if (inHandlerMode()) {
        portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
    }
    else {
        vPortExitCritical();
    }

    return osOK;
}
Example #11
0
/**
* @brief Delete a Mutex
* @param mutex_id  mutex ID obtained by \ref osMutexCreate.
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
*/
osStatus osMutexDelete (osMutexId mutex_id)
{
  if (inHandlerMode()) {
    return osErrorISR;
  }

  vQueueDelete(mutex_id);

  return osOK;
}
Example #12
0
/**
* @brief Delete a Semaphore
* @param  semaphore_id  semaphore object referenced with \ref osSemaphore.
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
*/
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id)
{
  if (inHandlerMode()) {
    return osErrorISR;
  }

  vSemaphoreDelete(semaphore_id);

  return osOK; 
}
Example #13
0
/**
* @brief Release a Mutex that was obtained by \ref osMutexWait
* @param mutex_id      mutex ID obtained by \ref osMutexCreate.
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
*/
osStatus osMutexRelease (osMutexId mutex_id)
{
  osStatus result = osOK;
  
  if (inHandlerMode()) {
    return osErrorISR;
  }
  
  if (xSemaphoreGive(mutex_id) != pdTRUE) 
  {
    result = osErrorOS;
  }
  return result;
}
Example #14
0
/**
* @brief Allocate a memory block from a memory pool
* @param pool_id       memory pool ID obtain referenced with \ref osPoolCreate.
* @retval  address of the allocated memory block or NULL in case of no memory available.
* @note   MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
*/
void *osPoolAlloc (osPoolId pool_id)
{
  int dummy = 0;
  void *p = NULL;
  uint32_t i;
  uint32_t index;
  
  if (inHandlerMode()) {
    dummy = portSET_INTERRUPT_MASK_FROM_ISR();
  }
  else {
    vPortEnterCritical();
  }
  
  for (i = 0; i < pool_id->pool_sz; i++) {
    index = pool_id->currentIndex + i;
    if (index >= pool_id->pool_sz) {
      index = 0;
    }
    
    if (pool_id->markers[index] == 0) {
      pool_id->markers[index] = 1;
      p = (void *)((uint32_t)(pool_id->pool) + (index * pool_id->item_sz));
      pool_id->currentIndex = index;
      break;
    }
  }
  
  if (inHandlerMode()) {
    portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
  }
  else {
    vPortExitCritical();
  }
  
  return p;
}
Example #15
0
/**
* @brief Get a Message or Wait for a Message from a Queue.
* @param  queue_id  message queue ID obtained with \ref osMessageCreate.
* @param  millisec  timeout value or 0 in case of no time-out.
* @retval event information that includes status code.
* @note   MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
*/
osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
{
  portBASE_TYPE taskWoken;
  TickType_t ticks;
  osEvent event;
  
  event.def.message_id = queue_id;
  event.value.v = 0;
  
  if (queue_id == NULL) {
    event.status = osErrorParameter;
    return event;
  }
  
  taskWoken = pdFALSE;
  
  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 (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) {
      /* We have mail */
      event.status = osEventMessage;
    }
    else {
      event.status = osOK;
    }
    portEND_SWITCHING_ISR(taskWoken);
  }
  else {
    if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) {
      /* We have mail */
      event.status = osEventMessage;
    }
    else {
      event.status = (ticks == 0) ? osOK : osEventTimeout;
    }
  }
  
  return event;
}
Example #16
0
/**
* @brief   Get current priority of an active thread.
* @param   thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
* @retval  current priority value of the thread function.
* @note   MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
*/
osPriority osThreadGetPriority (osThreadId thread_id)
{
#if (INCLUDE_uxTaskPriorityGet == 1)
  if (inHandlerMode())
  {
    return makeCmsisPriority(uxTaskPriorityGetFromISR(thread_id));  
  }
  else
  {  
    return makeCmsisPriority(uxTaskPriorityGet(thread_id));
  }
#else
  return osPriorityError;
#endif
}
Example #17
0
/**
* @brief  Resume execution of a suspended thread.
* @param   thread_id   thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
* @retval  status code that indicates the execution status of the function.
*/
osStatus osThreadResume (osThreadId thread_id)
{
#if (INCLUDE_vTaskSuspend == 1)
  if(inHandlerMode())
  {
    xTaskResumeFromISR(thread_id);
  }
  else
  {
    vTaskResume(thread_id);
  }
  return osOK;
#else
  return osErrorResource;
#endif
}
Example #18
0
/// Stop the timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
osStatus osTimerStop (osTimerId timer_id)
{
    portBASE_TYPE taskWoken = pdFALSE;
    osStatus result = osOK;

    if (inHandlerMode()) {
        xTimerStopFromISR(timer_id, &taskWoken);
        portEND_SWITCHING_ISR(taskWoken);
    }
    else {
        if (xTimerStop(timer_id, 0) != pdPASS) {    //TODO: add timeout support
            result = osErrorOS;
        }
    }

    return result;
}
Example #19
0
/**
* @brief Release a Mutex that was obtained by \ref osMutexWait
* @param mutex_id      mutex ID obtained by \ref osMutexCreate.
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
*/
osStatus osMutexRelease (osMutexId mutex_id)
{
  osStatus result = osOK;
  portBASE_TYPE taskWoken = pdFALSE;
  
  if (inHandlerMode()) {
    if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE) {
      return osErrorOS;
    }
    portEND_SWITCHING_ISR(taskWoken);
  }
  else if (xSemaphoreGive(mutex_id) != pdTRUE) 
  {
    result = osErrorOS;
  }
  return result;
}
Example #20
0
/**
* @brief  Set the specified Signal Flags of an active thread.
* @param  thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
* @param  signals       specifies the signal flags of the thread that should be set.
* @retval  osOK if successful, osErrorOS if failed .
* @note   MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
*/
int32_t osSignalSet (osThreadId thread_id, int32_t signal)
{
  BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  
  if (inHandlerMode())
  {
    if(xTaskNotifyFromISR( thread_id, (uint32_t)signal, eSetBits, &xHigherPriorityTaskWoken ) != pdPASS )
      return osErrorOS;

    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  }  
  else if(xTaskNotify( thread_id, (uint32_t)signal, eSetBits) != pdPASS )
  {
    return osErrorOS;
  }
  
  return osOK;
}
Example #21
0
/**
* @brief  Resume execution of a suspended thread.
* @param   thread_id   thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
* @retval  status code that indicates the execution status of the function.
*/
osStatus osThreadResume (osThreadId thread_id)
{
#if (INCLUDE_vTaskSuspend == 1)  
  if(inHandlerMode())
  {
    if (xTaskResumeFromISR(thread_id) == pdTRUE)
    {
      portYIELD_FROM_ISR(pdTRUE);
    }
  }
  else
  {
    vTaskResume(thread_id);
  }
  return osOK;
#else
  return osErrorResource;
#endif
}
/**
* @brief  Stop a timer.
* @param  timer_id      timer ID obtained by \ref osTimerCreate
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
*/
osStatus osTimerStop (osTimerId timer_id)
{
  osStatus result = osOK;
#if (configUSE_TIMERS == 1)  
  portBASE_TYPE taskWoken = pdFALSE;

  if (inHandlerMode()) {
    xTimerStopFromISR(timer_id, &taskWoken);
    portEND_SWITCHING_ISR(taskWoken);
  }
  else {
    if (xTimerStop(timer_id, 0) != pdPASS) {
      result = osErrorOS;
    }
  }
#else 
  result = osErrorOS;
#endif 
  return result;
}
Example #23
0
/// Put a Message to a Queue.
/// \param[in]     queue_id      message queue ID obtained with \ref osMessageCreate.
/// \param[in]     info          message information.
/// \param[in]     millisec      timeout value or 0 in case of no time-out.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
{
    portBASE_TYPE taskWoken = pdFALSE;
    portTickType ticks;

    if (inHandlerMode()) {
        if (xQueueSendFromISR(queue_id, (const void *)info, &taskWoken) != pdTRUE) {
            return osErrorOS;
        }
        portEND_SWITCHING_ISR(taskWoken);        
    }
    else {
        ticks = millisec_to_ticks(millisec);
        
        if (xQueueSend(queue_id, (const void *)info, ticks) != pdTRUE) {
            return osErrorOS;
        }
    }

    return osOK;
}
Example #24
0
/**
* @brief  Delete a timer.
* @param  timer_id      timer ID obtained by \ref osTimerCreate
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
*/
osStatus osTimerDelete (osTimerId timer_id)
{
osStatus result = osOK;

#if (configUSE_TIMERS == 1)

   if (inHandlerMode()) {
     return osErrorISR;
  }
  else { 
    if ((xTimerDelete(timer_id, osWaitForever )) != pdPASS) {
      result = osErrorOS;
    }
  } 
    
#else 
  result = osErrorOS;
#endif 
 
  return result;
}
Example #25
0
/// Wait until a Semaphore token becomes available
/// \param[in]     semaphore_id  semaphore object referenced with \ref osSemaphore.
/// \param[in]     millisec      timeout value or 0 in case of no time-out.
/// \return number of available tokens, or -1 in case of incorrect parameters.
/// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
{
    portTickType ticks;


    if (semaphore_id == NULL) {
        return osErrorParameter;
    }

    ticks = millisec_to_ticks(millisec);

    if (inHandlerMode()) {
        return osErrorISR;
    }

    if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) {
        return osErrorOS;
    }

    return osOK;
}
Example #26
0
/// Set the specified Signal Flags of an active thread.
/// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
/// \param[in]     signals       specifies the signal flags of the thread that should be set.
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
/// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
int32_t osSignalSet (osThreadId thread_id, int32_t signals)
{
    EventGroupHandle_t event_handle;
    portBASE_TYPE taskWoken = pdFALSE;
    portBASE_TYPE xResult;
    EventBits_t uxBits_ret=0x80000000;
#ifdef CHECK_VALUE_OF_EVENT_GROUP    
    EventBits_t uxBits;
#endif    

    if (signals & (0xFFFFFFFF << osFeature_Signals)) {
        return 0x80000000;
    }

    event_handle = find_signal_by_thread(thread_id);
    if (event_handle) {
        if (inHandlerMode()) {
            uxBits_ret = xEventGroupGetBitsFromISR(event_handle);
            xResult = xEventGroupSetBitsFromISR(
                            event_handle,    /* The event group being updated. */
                            signals,         /* The bits being set. */
                            &taskWoken );
            if( xResult != pdFAIL )
            {
                portYIELD_FROM_ISR(taskWoken);
            }
        }
        else {
            uxBits_ret = xEventGroupGetBits(event_handle);
#ifdef CHECK_VALUE_OF_EVENT_GROUP                
            uxBits = 
#endif              
                      xEventGroupSetBits(
                           event_handle,    /* The event group being updated. */
                           signals );/* The bits being set. */
        }
    }

    return uxBits_ret;
}
Example #27
0
/// Get a mail from a queue
/// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
/// \param[in]     millisec      timeout value or 0 in case of no time-out
/// \return event that contains mail information or error code.
/// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
osEvent osMailGet (osMailQId queue_id, uint32_t millisec)
{
    portBASE_TYPE taskWoken;
    portTickType ticks;
    osEvent event;

    event.def.mail_id = queue_id;

    if (queue_id == NULL) {
        event.status = osErrorParameter;
        return event;
    }

    taskWoken = pdFALSE;

    ticks = millisec_to_ticks(millisec);

    if (inHandlerMode()) {
        if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE) {
            /* We have mail */
            event.status = osEventMail;
        }
        else {
            event.status = osOK;
        }
        portEND_SWITCHING_ISR(taskWoken);
    }
    else {
        if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE) {
            /* We have mail */
            event.status = osEventMail;
        }
        else {
            event.status = (ticks == 0) ? osOK : osEventTimeout;
        }
    }

    return event;
}
Example #28
0
/// Clear the specified Signal Flags of an active thread.
/// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
/// \param[in]     signals       specifies the signal flags of the thread that shall be cleared.
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
/// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
int32_t osSignalClear (osThreadId thread_id, int32_t signals)
{
    EventGroupHandle_t event_handle;
    //portBASE_TYPE taskWoken = pdFALSE;
    EventBits_t uxBits_ret=0x80000000;
#ifdef CHECK_VALUE_OF_EVENT_GROUP     
    EventBits_t uxBits;
#endif    

    if (signals & (0xFFFFFFFF << osFeature_Signals)) {
        return 0x80000000;
    }

    event_handle = find_signal_by_thread(thread_id);
    if (event_handle) {
        if (inHandlerMode()) {
            uxBits_ret = xEventGroupGetBitsFromISR(event_handle);
#ifdef CHECK_VALUE_OF_EVENT_GROUP                
            uxBits = 
#endif              
                      xEventGroupClearBitsFromISR(
                         event_handle,    /* The event group being updated. */
                         signals);/* The bits being cleared. */
        }
        else {
            uxBits_ret = xEventGroupGetBits(event_handle);
#ifdef CHECK_VALUE_OF_EVENT_GROUP                
            uxBits = 
#endif              
                      xEventGroupClearBits(                                          
                         event_handle,    /* The event group being updated. */
                         signals);/* The bits being cleared. */
        }
    }

    return uxBits_ret;
}
Example #29
0
/**
* @brief Put a Message to a Queue.
* @param  queue_id  message queue ID obtained with \ref osMessageCreate.
* @param  info      message information.
* @param  millisec  timeout value or 0 in case of no time-out.
* @retval status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
*/
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
{
  portBASE_TYPE taskWoken = pdFALSE;
  TickType_t ticks;
  
  ticks = millisec / portTICK_PERIOD_MS;
  if (ticks == 0) {
    ticks = 1;
  }
  
  if (inHandlerMode()) {
    if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE) {
      return osErrorOS;
    }
    portEND_SWITCHING_ISR(taskWoken);
  }
  else {
    if (xQueueSend(queue_id, &info, ticks) != pdTRUE) {
      return osErrorOS;
    }
  }
  
  return osOK;
}
Example #30
0
/**
* @brief  Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
* @param  signals   wait until all specified signal flags set or 0 for any single signal flag.
* @param  millisec  timeout value or 0 in case of no time-out.
* @retval  event flag information or error code.
* @note   MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
*/
osEvent osSignalWait (int32_t signals, uint32_t millisec)
{
  osEvent ret;
  TickType_t ticks;

  ret.value.signals = 0;  
  ticks = 0;
  if (millisec == osWaitForever) {
    ticks = portMAX_DELAY;
  }
  else if (millisec != 0) {
    ticks = millisec / portTICK_PERIOD_MS;
    if (ticks == 0) {
      ticks = 1;
    }
  }  
  
  if (inHandlerMode())
  {
    ret.status = osErrorISR;  /*Not allowed in ISR*/
  }
  else
  {
    if(xTaskNotifyWait( 0,(uint32_t) signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE)
    {
      if(ticks == 0)  ret.status = osOK;
      else  ret.status = osEventTimeout;
    }
    else if(ret.value.signals >= 0x80000000)
    {
      ret.status =  osErrorValue;     
    }
    else  ret.status =  osEventSignal;
  }  
  return ret;
}