any012 发表于 2017-7-5 16:19:17

对WaitOnFlagUntilTimeout()这个函数名不理解

看输出名,以为这个函数是比较参数2和参数3是否一致。
结果仔细看代码,好像是参数2和参数3不一致的话,才返回hal_ok,否则返回hal_timeout.
/**
* @briefThis function handles SPI Communication Timeout.
* @paramhspi: pointer to a SPI_HandleTypeDef structure that contains
*                the configuration information for SPI module.
* @paramFlag: SPI flag to check
* @paramStatus: Flag status to check: RESET or set
* @paramTimeout: Timeout duration
* @retval HAL status
*/
static HAL_StatusTypeDef SPI_WaitOnFlagUntilTimeout(SPI_HandleTypeDef *hspi,
      uint32_t Flag, FlagStatus Status, uint32_t Timeout)
{
    uint32_t tickstart = 0;

    /* Get tick */
    tickstart = HAL_GetTick();

    /* Wait until flag is set */
    if (Status == RESET)
    {
      while (__HAL_SPI_GET_FLAG(hspi, Flag) == RESET)
      {
            if (Timeout != HAL_MAX_DELAY)
            {
                if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
                {
                  /* Disable the SPI and reset the CRC: the CRC value should be cleared
                     on both master and slave sides in order to resynchronize the master
                     and slave for their respective CRC calculation */

                  /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
                  __HAL_SPI_DISABLE_IT(hspi,
                            (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));

                  /* Disable SPI peripheral */
                  __HAL_SPI_DISABLE(hspi);

                  /* Reset CRC Calculation */
                  if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)
                  {
                        SPI_RESET_CRC(hspi);
                  }

                  hspi->State = HAL_SPI_STATE_READY;

                  /* Process Unlocked */
                  __HAL_UNLOCK(hspi);

                  return HAL_TIMEOUT;
                }
            }
      }
    }
    else
    {
      while (__HAL_SPI_GET_FLAG(hspi, Flag) != RESET)
      {
            if (Timeout != HAL_MAX_DELAY)
            {
                if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
                {
                  /* Disable the SPI and reset the CRC: the CRC value should be cleared
                     on both master and slave sides in order to resynchronize the master
                     and slave for their respective CRC calculation */

                  /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
                  __HAL_SPI_DISABLE_IT(hspi,
                            (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));

                  /* Disable SPI peripheral */
                  __HAL_SPI_DISABLE(hspi);

                  /* Reset CRC Calculation */
                  if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)
                  {
                        SPI_RESET_CRC(hspi);
                  }

                  hspi->State = HAL_SPI_STATE_READY;

                  /* Process Unlocked */
                  __HAL_UNLOCK(hspi);

                  return HAL_TIMEOUT;
                }
            }
      }
    }
    return HAL_OK;
}

bargagebaobei 发表于 2018-3-27 09:37:45

就是一个等待超时的判断 如果等待的状态在指定的时间内到了就ok
页: [1]
查看完整版本: 对WaitOnFlagUntilTimeout()这个函数名不理解