/* Reads data from an USART peripheral, filling the provided buffer until it becomes full. This function returns immediately with 1 if the buffer has been queued for transmission; otherwise 0.  */
unsigned char USART_ReadBuffer(AT91S_USART *usart, void *buffer, unsigned int size)
/* Reads data from an USART peripheral, filling the provided buffer until it becomes full. This function returns immediately with 1 if the buffer has been queued for transmission; otherwise 0.  */
unsigned char USART_ReadBuffer(AT91S_USART *usart, void *buffer, unsigned int size)
{
    if ((usart->US_RCR == 0) && (usart->US_RNCR == 0)) {
        usart->US_RPR = (unsigned int) buffer;
        usart->US_RCR = size;
        usart->US_PTCR = AT91C_PDC_RXTEN;
        return 1;
    }
    else if (usart->US_RNCR == 0) {
        usart->US_RNPR = (unsigned int) buffer;
        usart->US_RNCR = size;
        return 1;
    }
    else {
        return 0;
    }
}