/* Send (write) an item to the back of the queue.  */
OS_Status OS_QueueSend(OS_Queue_t *queue, const void *item, OS_Time_t waitMS)
/* Send (write) an item to the back of the queue.  */
OS_Status OS_QueueSend(OS_Queue_t *queue, const void *item, OS_Time_t waitMS)
{
    BaseType_t ret;
    BaseType_t taskWoken;
    OS_HANDLE_ASSERT(OS_QueueIsValid(queue), queue->handle);
    if (OS_IsISRContext()) {
        taskWoken = pdFALSE;
        ret = xQueueSendFromISR(queue->handle, item, &taskWoken);
        if (ret != pdPASS) {
            OS_DBG("%s() fail @ %d\n", __func__, __LINE__);
            return OS_FAIL;
        }
        portEND_SWITCHING_ISR(taskWoken);
    } else {
        ret = xQueueSend(queue->handle, item, OS_CalcWaitTicks(waitMS));
        if (ret != pdPASS) {
            OS_DBG("%s() fail @ %d, %"OS_TIME_F" ms\n", __func__, __LINE__, waitMS);
            return OS_FAIL;
        }
    }
    return OS_OK;
}