/* Receive an item from a queue without removing the item from the queue.  */
osEvent osMessagePeek(osMessageQId queue_id, uint32_t millisec)
/* Receive an item from a queue without removing the item from the queue.  */
osEvent osMessagePeek(osMessageQId queue_id, uint32_t millisec)
{
  TickType_t ticks;
  osEvent event;
  event.def.message_id = queue_id;
  if (queue_id == NULL) {
    event.status = osErrorParameter;
    return event;
  }
  ticks = 0;
  if (millisec == osWaitForever) {
    ticks = portMAX_DELAY;
  }
  else if (millisec != 0) {
    ticks = millisec / portTICK_PERIOD_MS;
    if (ticks == 0) {
      ticks = 1;
    }
  }
  if (xQueuePeek(queue_id, &event.value.v, ticks) == pdTRUE)
  {
    event.status = osEventMessage;
  }
  else
  {
    event.status = (ticks == 0) ? osOK : osEventTimeout;
  }
  return event;
}