你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

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

[复制链接]
any012 提问时间:2017-7-5 16:19 /
看输出名,以为这个函数是比较参数2和参数3是否一致。
结果仔细看代码,好像是参数2和参数3不一致的话,才返回hal_ok,否则返回hal_timeout.
  1. /**
  2. * @brief  This function handles SPI Communication Timeout.
  3. * @param  hspi: pointer to a SPI_HandleTypeDef structure that contains
  4. *                the configuration information for SPI module.
  5. * @param  Flag: SPI flag to check
  6. * @param  Status: Flag status to check: RESET or set
  7. * @param  Timeout: Timeout duration
  8. * @retval HAL status
  9. */
  10. static HAL_StatusTypeDef SPI_WaitOnFlagUntilTimeout(SPI_HandleTypeDef *hspi,
  11.         uint32_t Flag, FlagStatus Status, uint32_t Timeout)
  12. {
  13.     uint32_t tickstart = 0;

  14.     /* Get tick */
  15.     tickstart = HAL_GetTick();

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

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

  31.                     /* Disable SPI peripheral */
  32.                     __HAL_SPI_DISABLE(hspi);

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

  38.                     hspi->State = HAL_SPI_STATE_READY;

  39.                     /* Process Unlocked */
  40.                     __HAL_UNLOCK(hspi);

  41.                     return HAL_TIMEOUT;
  42.                 }
  43.             }
  44.         }
  45.     }
  46.     else
  47.     {
  48.         while (__HAL_SPI_GET_FLAG(hspi, Flag) != RESET)
  49.         {
  50.             if (Timeout != HAL_MAX_DELAY)
  51.             {
  52.                 if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
  53.                 {
  54.                     /* Disable the SPI and reset the CRC: the CRC value should be cleared
  55.                      on both master and slave sides in order to resynchronize the master
  56.                      and slave for their respective CRC calculation */

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

  60.                     /* Disable SPI peripheral */
  61.                     __HAL_SPI_DISABLE(hspi);

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

  67.                     hspi->State = HAL_SPI_STATE_READY;

  68.                     /* Process Unlocked */
  69.                     __HAL_UNLOCK(hspi);

  70.                     return HAL_TIMEOUT;
  71.                 }
  72.             }
  73.         }
  74.     }
  75.     return HAL_OK;
  76. }
复制代码

收藏 1 评论1 发布时间:2017-7-5 16:19

举报

1个回答
bargagebaobei 回答时间:2018-3-27 09:37:45
就是一个等待超时的判断 如果等待的状态在指定的时间内到了就ok

评分

参与人数 1蝴蝶豆 +2 收起 理由
zero99 + 2

查看全部评分

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版