Platform/ECM3532/DSP/hw/csp/ecm3532/src/eta_csp_spi.c
/***************************************************************************/
/**
 *
 * EtaCspSpiTransferDma - Start the SPI using DMA
 *
 * @param ui16TxLen TX Data Length.
 * @param ui16RxLen RX Data Length.
 * @param spiChipSel is the chip select (0-3).
 * @param iSpiSequence is the SPI command sequence.
 *
 * >You cannot pass a non-zero uiTxLen and uiRxLen in a call. If you do,
 *  uiRxLen will be ignored. If you are setting up a TX DMA tranfer
 *  iSpiSequence has no effect. If you want to hold chip select active, do
 *  it explicitly. If you are setting up a RX DMA transfer, passing
 *  eSpiSequenceLastOnly will deassert the chip select signal.
 *
 ******************************************************************************/
Start the SPI using DMA
@param ui16TxLen TX Data Length.
@param ui16RxLen RX Data Length.
@param spiChipSel is the chip select (0-3).
@param iSpiSequence is the SPI command sequence.

>You cannot pass a non-zero uiTxLen and uiRxLen in a call. If you do,
uiRxLen will be ignored. If you are setting up a TX DMA tranfer
iSpiSequence has no effect. If you want to hold chip select active, do
it explicitly. If you are setting up a RX DMA transfer, passing
eSpiSequenceLastOnly will deassert the chip select signal.
Start the SPI using DMA @param ui16TxLen TX Data Length . @param ui16RxLen RX Data Length . @param spiChipSel is the chip select ( 0 - 3 ) . @param iSpiSequence is the SPI command sequence . > You cannot pass a non - zero uiTxLen and uiRxLen in a call . If you do uiRxLen will be ignored . If you are setting up a TX DMA tranfer iSpiSequence has no effect . If you want to hold chip select active do it explicitly . If you are setting up a RX DMA transfer passing eSpiSequenceLastOnly will deassert the chip select signal .
tEtaStatus
EtaCspSpiTransferDmaConfig(uint16_t ui16TxLen, uint16_t ui16RxLen,
                           tSpiChipSel spiChipSel, tSpiSequence iSpiSequence)
{
    tEtaStatus localStatus;
    uint32_t ui32Timeout;
    uint8_t lastcmd;
 if (ui32RxLen > (64*1024)-1)
 etaPrintf ("ERROR: EtaCspSpiTransferPoll exceeded max ui32RxLen of
 (64*1024)-1 with %d", ui32RxLen);
    if(ui16TxLen && REG_SPI2_RXDROP_CNT)
    {
        return eEtaSpiBusy;
    }
    else if(ui16RxLen && REG_SPI2_TX_DUMMY_BYTE_CNT)
    {
        return eEtaSpiBusy;
    }
     If it is first, start command
    if(iSpiSequence & eSpiSequenceFirstOnly)
    {
         Make sure previous command is done (optional)
        if(localStatus = EtaCspSpiDonePoll())
        {
            return(localStatus);
        }
        if((REG_SPI2_STATUS & BM_SPI2_STATUS_START_BUSY) ==
              BM_SPI2_STATUS_START_BUSY)
        {
            return eEtaSpiBusy;
        }
         Start command
        if(iSpiSequence & eSpiSequenceLastOnly)
        {
            REG_SPI2_STATUS = BM_SPI2_STATUS_START_BUSY |
                              (spiChipSel << BP_SPI2_STATUS_CS_SEL);
        }
        else
        {
            REG_SPI2_STATUS = BM_SPI2_STATUS_START_BUSY |
                              (spiChipSel << BP_SPI2_STATUS_CS_SEL) |
                              BM_SPI2_STATUS_HOLD_CS;
        }
    }
    if(ui16TxLen)  If we have TX, lets process it.
    {
         Deal with TX first
         We'll drop ui16TxLen of data (garbage receive data during TX)
        REG_SPI2_RXDROP_CNT = ui16TxLen;
        REG_SPI2_CONFIG = (REG_SPI2_CONFIG & ~BM_SPI2_CONFIG_FIFO_LEVEL_TRIG) |
                          (2 << BP_SPI2_CONFIG_FIFO_LEVEL_TRIG);
    }
    else if(ui16RxLen)  No TX, just RX
    {
        REG_SPI2_TX_DUMMY_BYTE_CNT = ui16RxLen;
         If it is Last, end command
        if(iSpiSequence & eSpiSequenceLastOnly)
        {
             At this point, all TX is in the queue. Remove hold
            REG_SPI2_STATUS = 0;
        }
        REG_SPI2_CONFIG = (REG_SPI2_CONFIG & ~BM_SPI2_CONFIG_FIFO_LEVEL_TRIG) |
                          (2 << BP_SPI2_CONFIG_FIFO_LEVEL_TRIG);
    }
    else  No TX, No RX
    {
         If it is Last, end command
        if(iSpiSequence & eSpiSequenceLastOnly)
        {
             At this point, all TX is in the queue. Remove hold
            REG_SPI2_STATUS = 0;
        }
    }
     Setup next expected interrupt
    REG_SPI2_INT_EN =
        ((ui16TxLen != 0) ? BM_SPI2_INT_EN_TXFIFO_HAS_LEVEL_SPACE_EN2 : 0)    |
        ((ui16RxLen != 0) ? BM_SPI2_INT_EN_RX_FIFO_HIT_LEVEL_EN1 : 0);
    return(eEtaSuccess);
}
tEtaStatus EtaCspSpiTransferDmaConfig ( uint16_t ui16TxLen , uint16_t ui16RxLen , tSpiChipSel spiChipSel , tSpiSequence iSpiSequence ) { tEtaStatus localStatus ; uint32_t ui32Timeout ; uint8_t lastcmd ; if ( ui16TxLen && REG_SPI2_RXDROP_CNT ) { return eEtaSpiBusy ; } else if ( ui16RxLen && REG_SPI2_TX_DUMMY_BYTE_CNT ) { return eEtaSpiBusy ; } if ( iSpiSequence & eSpiSequenceFirstOnly ) { if ( ( REG_SPI2_STATUS & BM_SPI2_STATUS_START_BUSY ) == BM_SPI2_STATUS_START_BUSY ) { return eEtaSpiBusy ; } if ( iSpiSequence & eSpiSequenceLastOnly ) { REG_SPI2_STATUS = BM_SPI2_STATUS_START_BUSY | ( spiChipSel << BP_SPI2_STATUS_CS_SEL ) ; } else { REG_SPI2_STATUS = BM_SPI2_STATUS_START_BUSY | ( spiChipSel << BP_SPI2_STATUS_CS_SEL ) | BM_SPI2_STATUS_HOLD_CS ; } } if ( ui16TxLen ) { REG_SPI2_RXDROP_CNT = ui16TxLen ; REG_SPI2_CONFIG = ( REG_SPI2_CONFIG & ~ BM_SPI2_CONFIG_FIFO_LEVEL_TRIG ) | ( 2 << BP_SPI2_CONFIG_FIFO_LEVEL_TRIG ) ; } else if ( ui16RxLen ) { REG_SPI2_TX_DUMMY_BYTE_CNT = ui16RxLen ; if ( iSpiSequence & eSpiSequenceLastOnly ) { REG_SPI2_STATUS = 0 ; } REG_SPI2_CONFIG = ( REG_SPI2_CONFIG & ~ BM_SPI2_CONFIG_FIFO_LEVEL_TRIG ) | ( 2 << BP_SPI2_CONFIG_FIFO_LEVEL_TRIG ) ; } else { if ( iSpiSequence & eSpiSequenceLastOnly ) { REG_SPI2_STATUS = 0 ; } } REG_SPI2_INT_EN = ( ( ui16TxLen != 0 ) ? BM_SPI2_INT_EN_TXFIFO_HAS_LEVEL_SPACE_EN2 : 0 ) | ( ( ui16RxLen != 0 ) ? BM_SPI2_INT_EN_RX_FIFO_HIT_LEVEL_EN1 : 0 ) ; return ( eEtaSuccess ) ; }
EtaCspSpiTransferDma - Start the SPI using DMA
 @param ui16TxLen TX Data Length.
EtaCspSpiTransferDma - Start the SPI using DMA @param ui16TxLen TX Data Length .
// Impossible if we use 16 bit lengths... // but keep incase we standardize to 32 bit lengths. // if (ui32TxLen > (64*1024)-1) // { // #ifdef ETA_CSP_SPI_DEBUG // etaPrintf ("ERROR: EtaCspSpiTransferPoll exceeded max ui32TxLen of // (64*1024)-1 with %d", ui32TxLen); // #endif // return eEtaSpiInvalidConfig; // } // // if (ui32RxLen > (64*1024)-1) // { // #ifdef ETA_CSP_SPI_DEBUG // etaPrintf ("ERROR: EtaCspSpiTransferPoll exceeded max ui32RxLen of // (64*1024)-1 with %d", ui32RxLen); // #endif // return eEtaSpiInvalidConfig; // } // If it is first, start command // Make sure previous command is done (optional) //if(localStatus = EtaCspSpiDonePoll()) //{ //    return(localStatus); //} // Start command // If we have TX, lets process it. // Deal with TX first // We'll drop ui16TxLen of data (garbage receive data during TX) // No TX, just RX // If it is Last, end command // At this point, all TX is in the queue. Remove hold // No TX, No RX // If it is Last, end command // At this point, all TX is in the queue. Remove hold // Setup next expected interrupt