看输出名,以为这个函数是比较参数2和参数3是否一致。
结果仔细看代码,好像是参数2和参数3不一致的话,才返回hal_ok,否则返回hal_timeout.
- /**
- * @brief This function handles SPI Communication Timeout.
- * @param hspi: pointer to a SPI_HandleTypeDef structure that contains
- * the configuration information for SPI module.
- * @param Flag: SPI flag to check
- * @param Status: Flag status to check: RESET or set
- * @param Timeout: 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;
- }
复制代码
|
评分
查看全部评分