SDSPI_Handler
Default mainpageat91libmemoriessdmmcSDSPI_Handler
Description Source Call Graph
Start Line: 534
void SDSPI_Handler(SdSpi *pSdSpi)
{
    SdSpiCmd *pCommand = pSdSpi->pCommand;
    AT91S_SPI *pSpiHw = pSdSpi->pSpiHw;
    volatile unsigned int spiSr;

    // Read the status register
    spiSr = pSpiHw->SPI_SR;
    if(spiSr & AT91C_SPI_RXBUFF) {

        if (pCommand->status == SDSPI_STATUS_PENDING) {
            pCommand->status = 0;
        }
        // Disable transmitter and receiver
        pSpiHw->SPI_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;

        // Disable the SPI clock
        AT91C_BASE_PMC->PMC_PCDR = (1 << pSdSpi->spiId);

        // Disable buffer complete interrupt
        pSpiHw->SPI_IDR = AT91C_SPI_RXBUFF | AT91C_SPI_ENDTX;

        // Release the SPI semaphore
        pSdSpi->semaphore++;
    }

    // Invoke the callback associated with the current command
    if (pCommand && pCommand->callback) {
        pCommand->callback(0, pCommand);
    }
}