Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_spi.c
/***************************************************************************/
/**
 *
 *  EtaCspSpiProcessIntRxData - Process SPI Interrupt for RX Data Available
 *
 *  @param iNum the SPI number.
 *
 ******************************************************************************/
Process SPI Interrupt for RX Data Available
@param iNum the SPI number.
Process SPI Interrupt for RX Data Available @param iNum the SPI number .
tEtaStatus EtaCspSpiProcessIntRxData (tSpiNum iNum)
{
  uint8_t ui8SpaceInFifo;
  uint32_t ui32RxWord;
  if ((g_pEtaCspSpiCmd[iNum]->bCmdActive == 0) || (g_pEtaCspSpiCmd[iNum]->ui32RxLen == 0))
  {
#ifdef ETA_CSP_SPI_DEBUG
    ETA_DIAGS_PRINTF("ERROR: received spi_int_rx but command is done. bCmdActive=%x  ui32RxLen=%x\r\n", g_pEtaCspSpiCmd[iNum]->bCmdActive, g_pEtaCspSpiCmd[iNum]->ui32RxLen);
#endif
    return eEtaSpiCmdSequenceErr;
  }
  if (ETA_CSP_SPI_EN_GREEDY_INT) 
  {
    ui8SpaceInFifo = (MEMIO8(REG_SPI_RX_FIFO_DEBUG_ADDR (iNum)) & BM_SPI_RX_FIFO_DEBUG_ENTRIES);
  }
  else
  {
    ui8SpaceInFifo = g_pEtaCspSpiCmd[iNum]->ui8RxIntSize; 
  }
#ifdef ETA_CSP_SPI_DETAILED_DEBUG
  ETA_DIAGS_PRINTF("DETAILED_SPI:SPI RX data interrupt. entries:%d\r\n", ui8SpaceInFifo);
#endif
  do
  {
    if (ui8SpaceInFifo >= 4)
    {
      ui32RxWord = REG_SPI_RX_4BYTE_FIFO_DATA(iNum).V;
#ifdef ETA_CSP_SPI_DETAILED_DEBUG
      ETA_DIAGS_PRINTF("DETAILED_SPI:SPI RX 4data interrupt. rx:%x rxlen:%d space:%d\r\n", ui32RxWord, g_pEtaCspSpiCmd[iNum]->ui32RxLen, ui8SpaceInFifo);
#endif
      *g_pEtaCspSpiCmd[iNum]->pui8RxData++ = ((ui32RxWord >> 0) & 0xff);
      *g_pEtaCspSpiCmd[iNum]->pui8RxData++ = ((ui32RxWord >> 8) & 0xff);
      *g_pEtaCspSpiCmd[iNum]->pui8RxData++ = ((ui32RxWord >> 16) & 0xff);
      *g_pEtaCspSpiCmd[iNum]->pui8RxData++ = ((ui32RxWord >> 24) & 0xff);
      g_pEtaCspSpiCmd[iNum]->ui32RxLen -= 4;
      ui8SpaceInFifo -= 4;
    }
    else if (ui8SpaceInFifo >= 1)
    {
      ui32RxWord = MEMIO8(REG_SPI_TXRX_1BYTE_FIFO_DATA_ADDR (iNum));
#ifdef ETA_CSP_SPI_DETAILED_DEBUG
      ETA_DIAGS_PRINTF("DETAILED_SPI:SPI RX 1data interrupt. rx:%x rxlen:%d space:%d\r\n", ui32RxWord, g_pEtaCspSpiCmd[iNum]->ui32RxLen, ui8SpaceInFifo);
#endif
      *g_pEtaCspSpiCmd[iNum]->pui8RxData++ = ((ui32RxWord >> 0) & 0xff);
      g_pEtaCspSpiCmd[iNum]->ui32RxLen --;
      ui8SpaceInFifo --;
    }
    if ((ui8SpaceInFifo < 4) & (g_pEtaCspSpiCmd[iNum]->ui32RxLen >= 4))
    {
      break; 
    }
    if (g_pEtaCspSpiCmd[iNum]->ui32RxLen == 0)
    {
      break; 
    }
  }
  while (ui8SpaceInFifo);
  if (g_pEtaCspSpiCmd[iNum]->ui32RxLen == 0) 
  {
    REGN_M1(0, SPI_INT_EN, RX_FIFO_HIT_LEVEL_EN0, 0);
#ifdef ETA_CSP_SPI_DETAILED_DEBUG
    ETA_DIAGS_PRINTF("DETAILED_SPI:Last SPI RX data interrupt\r\n");
#endif
  }
  else if (g_pEtaCspSpiCmd[iNum]->ui32RxLen < g_pEtaCspSpiCmd[iNum]->ui8RxIntSize) 
  {
    REG_SPI_CONFIG(iNum).BF.FIFO_LEVEL_TRIG = g_pEtaCspSpiCmd[iNum]->ui32RxLen;
#ifdef ETA_CSP_SPI_DETAILED_DEBUG
    ETA_DIAGS_PRINTF("DETAILED_SPI:SPI RX dropped below level, set to %d\r\n", g_pEtaCspSpiCmd[iNum]->ui32RxLen);
#endif
  }
  return eEtaSuccess;
}
tEtaStatus EtaCspSpiProcessIntRxData ( tSpiNum iNum ) { uint8_t ui8SpaceInFifo ; uint32_t ui32RxWord ; if ( ( g_pEtaCspSpiCmd [ iNum ] -> bCmdActive == 0 ) || ( g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen == 0 ) ) { #ifdef ETA_CSP_SPI_DEBUG ETA_DIAGS_PRINTF ( " \r \n " , g_pEtaCspSpiCmd [ iNum ] -> bCmdActive , g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen ) ; #endif return eEtaSpiCmdSequenceErr ; } if ( ETA_CSP_SPI_EN_GREEDY_INT ) { ui8SpaceInFifo = ( MEMIO8 ( REG_SPI_RX_FIFO_DEBUG_ADDR ( iNum ) ) & BM_SPI_RX_FIFO_DEBUG_ENTRIES ) ; } else { ui8SpaceInFifo = g_pEtaCspSpiCmd [ iNum ] -> ui8RxIntSize ; } #ifdef ETA_CSP_SPI_DETAILED_DEBUG ETA_DIAGS_PRINTF ( " \r \n " , ui8SpaceInFifo ) ; #endif do { if ( ui8SpaceInFifo >= 4 ) { ui32RxWord = REG_SPI_RX_4BYTE_FIFO_DATA ( iNum ) . V ; #ifdef ETA_CSP_SPI_DETAILED_DEBUG ETA_DIAGS_PRINTF ( " \r \n " , ui32RxWord , g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen , ui8SpaceInFifo ) ; #endif * g_pEtaCspSpiCmd [ iNum ] -> pui8RxData ++ = ( ( ui32RxWord >> 0 ) & 0xff ) ; * g_pEtaCspSpiCmd [ iNum ] -> pui8RxData ++ = ( ( ui32RxWord >> 8 ) & 0xff ) ; * g_pEtaCspSpiCmd [ iNum ] -> pui8RxData ++ = ( ( ui32RxWord >> 16 ) & 0xff ) ; * g_pEtaCspSpiCmd [ iNum ] -> pui8RxData ++ = ( ( ui32RxWord >> 24 ) & 0xff ) ; g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen -= 4 ; ui8SpaceInFifo -= 4 ; } else if ( ui8SpaceInFifo >= 1 ) { ui32RxWord = MEMIO8 ( REG_SPI_TXRX_1BYTE_FIFO_DATA_ADDR ( iNum ) ) ; #ifdef ETA_CSP_SPI_DETAILED_DEBUG ETA_DIAGS_PRINTF ( " \r \n " , ui32RxWord , g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen , ui8SpaceInFifo ) ; #endif * g_pEtaCspSpiCmd [ iNum ] -> pui8RxData ++ = ( ( ui32RxWord >> 0 ) & 0xff ) ; g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen -- ; ui8SpaceInFifo -- ; } if ( ( ui8SpaceInFifo < 4 ) & ( g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen >= 4 ) ) { break ; } if ( g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen == 0 ) { break ; } } while ( ui8SpaceInFifo ) ; if ( g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen == 0 ) { REGN_M1 ( 0 , SPI_INT_EN , RX_FIFO_HIT_LEVEL_EN0 , 0 ) ; #ifdef ETA_CSP_SPI_DETAILED_DEBUG ETA_DIAGS_PRINTF ( " \r \n " ) ; #endif } else if ( g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen < g_pEtaCspSpiCmd [ iNum ] -> ui8RxIntSize ) { REG_SPI_CONFIG ( iNum ) . BF . FIFO_LEVEL_TRIG = g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen ; #ifdef ETA_CSP_SPI_DETAILED_DEBUG ETA_DIAGS_PRINTF ( " \r \n " , g_pEtaCspSpiCmd [ iNum ] -> ui32RxLen ) ; #endif } return eEtaSuccess ; }
EtaCspSpiProcessIntRxData - Process SPI Interrupt for RX Data Available
  @param iNum the SPI number.
EtaCspSpiProcessIntRxData - Process SPI Interrupt for RX Data Available @param iNum the SPI number .
// This allows for burst writes, which is more efficient, but not requires an extra read. // Do work that interrupt said we have space for // If we drop low enough that we cannot bulk transfer, exit loop, wait for next int. // Exit loop, we're done. // Just sent last byte. Lets turn off TX has space interrupt and send dummy bytes // RX Length less than interrupt size.