/* Sends the contents of a data buffer through the specified USART peripheral. This function returns immediately (1 if the buffer has been queued, 0 otherwise); poll the ENDTX and TXBUFE bits of the USART status register to check for the transfer completion.  */
unsigned char USART_WriteBuffer(AT91S_USART *usart, void *buffer, unsigned int size)
/* Sends the contents of a data buffer through the specified USART peripheral. This function returns immediately (1 if the buffer has been queued, 0 otherwise); poll the ENDTX and TXBUFE bits of the USART status register to check for the transfer completion.  */
unsigned char USART_WriteBuffer(AT91S_USART *usart, void *buffer, unsigned int size)
{
    if ((usart->US_TCR == 0) && (usart->US_TNCR == 0)) {
        usart->US_TPR = (unsigned int) buffer;
        usart->US_TCR = size;
        usart->US_PTCR = AT91C_PDC_TXTEN;
        return 1;
    }
    else if (usart->US_TNCR == 0) {
        usart->US_TNPR = (unsigned int) buffer;
        usart->US_TNCR = size;
        return 1;
    }
    else {
        return 0;
    }
}