/* Sends the contents of buffer through a SPI peripheral, using the PDC to take care of the transfer.  */
unsigned char SPI_WriteBuffer(AT91S_SPI *spi, void *buffer, unsigned int length)
/* Sends the contents of buffer through a SPI peripheral, using the PDC to take care of the transfer.  */
unsigned char SPI_WriteBuffer(AT91S_SPI *spi, void *buffer, unsigned int length)
{
    if (spi->SPI_TCR == 0) {
        spi->SPI_TPR = (unsigned int) buffer;
        spi->SPI_TCR = length;
        spi->SPI_PTCR = AT91C_PDC_TXTEN;
        return 1;
    }
    else if (spi->SPI_TNCR == 0) {
        spi->SPI_TNPR = (unsigned int) buffer;
        spi->SPI_TNCR = length;
        return 1;
    }
    return 0;
}