AnsweredAssumed Answered

CPAL Spin Waits in Interupt

Question asked by sotack.john.001 on May 11, 2013
Latest reply on May 15, 2013 by sotack.john
I noticed the CPAL uses spin type waits including at least one in an interrupt (see code below).  These are used via the MACRO __CPAL_I2C_TIMEOUT. I have some concern with the one in the interrupt handler below because it appears to spin for 302 us = 20,536 cyles.  The wait is on the BTF flag which there is an interrupt for (see table from STMf4XX reference manual.

Is there are reason a spin wait is done on the BTF rather than using the interrupt?  I may want to optimize my code to recover the cyles.  Were I to take a guess is would be that BTF is usually not used in DMA transfers and is this not specially turned on in this case.  For my cause it looks like the wait occurs in the last two transmitted bytesIf switching from DMA to interrupt mode saves 20,536 cycles on a single write I may be better off using interrupt mode.

Does ST have any opinion of the relative  efficiency of Interrupt vs DMA in CPAL?


From cpal_i2c.c:

uint32_t CPAL_I2C_DMA_TX_IRQHandler(CPAL_InitTypeDef* pDevInitStruct)
  /* Reinitialize Timeout Value to default (no timeout initiated) */
  pDevInitStruct->wCPAL_Timeout = CPAL_I2C_TIMEOUT_DEFAULT;
  CPAL_LOG("\n\r\n\rLOG <CPAL_I2C_DMA_TX_IRQHandler> : I2C Device TX DMA ");
  /*------------- If TC interrupt ------------*/
  if((__CPAL_I2C_HAL_GET_DMATX_TCIT(pDevInitStruct->CPAL_Dev)) != 0)
    CPAL_LOG("\n\rLOG : I2C Device TX Complete");
    /* Update remaining number of data */
    pDevInitStruct->pCPAL_TransferTx->wNumData = 0;
    /* Call DMA TX TC UserCallback */
    /* If DMA Normal mode */
    if ((pDevInitStruct->wCPAL_Options & CPAL_OPT_DMATX_CIRCULAR) == 0)
      /* If Master Mode selected */
      if (pDevInitStruct->CPAL_Mode == CPAL_MODE_MASTER)
 #ifdef CPAL_I2C_MASTER_MODE         
        /* Disable DMA Request */
        /* Wait until BTF flag is set */
        /* No Stop Condition Generation option bit not selected */   
        if ((pDevInitStruct->wCPAL_Options & CPAL_OPT_I2C_NOSTOP) == 0)