Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_spi.c
/***************************************************************************/
/**
 *
 *  EtaCspSpiSlaveRxDataReceive - Receive bytes from the master. Function will
 *    return fewer than the requested number of bytes if the RX buffer becomes
 *    empty.
 *
 *  @param iNum the SPI number.
 *  @param pui8RxData pointer to RX Data Array
 *  @param ui32RxReadLen RX Data bytes to read from the interface
 *  @param pui32RxRecLen RX Data bytes actually received on return
 *  @return tEtaStatus will return eEtaSpiRxFifoOflow if the RX FIFO overflows
 *
 ******************************************************************************/
Receive bytes from the master. Function will
return fewer than the requested number of bytes if the RX buffer becomes
empty.

@param iNum the SPI number.
@param pui8RxData pointer to RX Data Array
@param ui32RxReadLen RX Data bytes to read from the interface
@param pui32RxRecLen RX Data bytes actually received on return
@return tEtaStatus will return eEtaSpiRxFifoOflow if the RX FIFO overflows
Receive bytes from the master . Function will return fewer than the requested number of bytes if the RX buffer becomes empty . @param iNum the SPI number . @param pui8RxData pointer to RX Data Array @param ui32RxReadLen RX Data bytes to read from the interface @param pui32RxRecLen RX Data bytes actually received on return @return tEtaStatus will return eEtaSpiRxFifoOflow if the RX FIFO overflows
tEtaStatus EtaCspSpiSlaveRxDataReceive(tSpiNum iNum, uint8_t * pui8RxData,
                        uint32_t ui32RxReadLen, uint32_t * pui32RxRecLen)
{
    tEtaStatus iStatus = eEtaSuccess;
    uint8_t ui8Debug = MEMIO8(REG_SPI_RX_FIFO_DEBUG_ADDR(iNum) );
    int32_t i32Entries = ui8Debug & BM_SPI_RX_FIFO_DEBUG_ENTRIES;
    *pui32RxRecLen = ui32RxReadLen;
    if (i32Entries < ui32RxReadLen) {
        *pui32RxRecLen = i32Entries;
    }
    else if (i32Entries > ui32RxReadLen) {
        i32Entries = ui32RxReadLen;
    }
    while (i32Entries > 0) {
        switch (i32Entries) {
            case 0:
                i32Entries -= 1;
                break;
            case 1:
                *pui8RxData = MEMIO8(REG_SPI_TXRX_1BYTE_FIFO_DATA_ADDR(iNum) );
                pui8RxData += 1;
                i32Entries -= 1;
                break;
            case 2:
            case 3:
                *((uint16_t*)pui8RxData) = 
                    MEMIO16(REG_SPI_TXRX_2BYTE_FIFO_DATA_ADDR(iNum) );
                pui8RxData += 2;
                i32Entries -= 2;
                break;
            default:
                *((uint32_t*)pui8RxData) = REG_SPI_RX_4BYTE_FIFO_DATA(iNum).V;
                pui8RxData += 4;
                i32Entries -= 4;
                break;
        }
    }
    ui8Debug = MEMIO8(REG_SPI_RX_FIFO_DEBUG_ADDR(iNum) );
    if (ui8Debug & BM_SPI_RX_FIFO_DEBUG_OFLOW) {
        iStatus = eEtaSpiRxFifoOflow;
    }
    return iStatus;
}
tEtaStatus EtaCspSpiSlaveRxDataReceive ( tSpiNum iNum , uint8_t * pui8RxData , uint32_t ui32RxReadLen , uint32_t * pui32RxRecLen ) { tEtaStatus iStatus = eEtaSuccess ; uint8_t ui8Debug = MEMIO8 ( REG_SPI_RX_FIFO_DEBUG_ADDR ( iNum ) ) ; int32_t i32Entries = ui8Debug & BM_SPI_RX_FIFO_DEBUG_ENTRIES ; * pui32RxRecLen = ui32RxReadLen ; if ( i32Entries < ui32RxReadLen ) { * pui32RxRecLen = i32Entries ; } else if ( i32Entries > ui32RxReadLen ) { i32Entries = ui32RxReadLen ; } while ( i32Entries > 0 ) { switch ( i32Entries ) { case 0 : i32Entries -= 1 ; break ; case 1 : * pui8RxData = MEMIO8 ( REG_SPI_TXRX_1BYTE_FIFO_DATA_ADDR ( iNum ) ) ; pui8RxData += 1 ; i32Entries -= 1 ; break ; case 2 : case 3 : * ( ( uint16_t * ) pui8RxData ) = MEMIO16 ( REG_SPI_TXRX_2BYTE_FIFO_DATA_ADDR ( iNum ) ) ; pui8RxData += 2 ; i32Entries -= 2 ; break ; default : * ( ( uint32_t * ) pui8RxData ) = REG_SPI_RX_4BYTE_FIFO_DATA ( iNum ) . V ; pui8RxData += 4 ; i32Entries -= 4 ; break ; } } ui8Debug = MEMIO8 ( REG_SPI_RX_FIFO_DEBUG_ADDR ( iNum ) ) ; if ( ui8Debug & BM_SPI_RX_FIFO_DEBUG_OFLOW ) { iStatus = eEtaSpiRxFifoOflow ; } return iStatus ; }
EtaCspSpiSlaveRxDataReceive - Receive bytes from the master.
EtaCspSpiSlaveRxDataReceive - Receive bytes from the master .
// Set the number of received bytes based on the number in the FIFO. // Get data from the FIFO