/* Reads and return a packet of data on the specified USART peripheral. This function operates asynchronously, so it waits until some data has been received.  */
unsigned short USART_Read(AT91S_USART *usart, volatile unsigned int timeOut)
/* Reads and return a packet of data on the specified USART peripheral. This function operates asynchronously, so it waits until some data has been received.  */
unsigned short USART_Read(AT91S_USART *usart, volatile unsigned int timeOut)
{
    if (timeOut == 0) {
        while ((usart->US_CSR & AT91C_US_RXRDY) == 0);
    }
    else {
        while ((usart->US_CSR & AT91C_US_RXRDY) == 0) {
            if (timeOut == 0) {
                trace_LOG(trace_ERROR, "-E- USART_Read: Timed out.\n\r");
                return 0;
            }
            timeOut--;
        }
    }
    return usart->US_RHR;
}