/******************************************************************************* * 函数名称: SPI_I2S_GetITStatus * 功能描述: SPI_IT:检查指定的的SPI/I2S中断是否发生了。 * 输入参数: (1) SPIx: x可以是 : * - 1, 2 或 3 在 SPI 模式 * - 2 或 3 在 I2S 模式 * (2) SPI_I2S_IT:检查的指定的SPI/I2S中断源。 * 这个参数可以是下面的值之一: * - SPI_I2S_IT_TXE: 传输缓冲为空中断 * - SPI_I2S_IT_RXNE: 接收缓冲不空中断 * - SPI_I2S_IT_OVR: 溢出中断. * - SPI_IT_MODF: 模式错误中断 * - SPI_IT_CRCERR: CRC校验错误中断. * - I2S_IT_UDR: 空栈读错误中断. * 输出参数: 无 * 返回参数: SPI_I2S_IT的新状态 (SET or RESET). *******************************************************************************/ ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, u8 SPI_I2S_IT) { ITStatus bitstatus = RESET; u16 itpos = 0, itmask = 0, enablestatus = 0; /* Check the parameters [检查参数]*/ assert_param(IS_SPI_ALL_PERIPH(SPIx)); assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT)); /* Get the SPI/I2S IT index [取得SPI/I2S IT引索]*/ itpos = (u16)((u16)0x01 << (SPI_I2S_IT & (u8)0x0F)); /* Get the SPI/I2S IT mask [取得SPI/I2S IT标志]*/ itmask = SPI_I2S_IT >> 4; /* Set the IT mask [置位IT标志]*/ itmask = (u16)((u16)0x01 << itmask); /* Get the SPI_I2S_IT enable bit status [取得SPI_I2S_IT使能状态位]*/ enablestatus = (SPIx->CR2 & itmask) ; /* Check the status of the specified SPI/I2S interrupt [检查指定的SPI/I2S中断状态]*/ if (((SPIx->SR & itpos) != (u16)RESET) && enablestatus) { /* SPI_I2S_IT is set [置位SPI_I2S_IT]*/ bitstatus = SET; } else { /* SPI_I2S_IT is reset [复位SPI_I2S_IT]*/ bitstatus = RESET; } /* Return the SPI_I2S_IT status [返回SPI_I2S_IT状态]*/ return bitstatus; }
/** * @brief Checks whether the specified SPI/I2S interrupt has occurred or not. * @param SPIx: where x can be 1 or 2 in SPI mode or 1 in I2S mode to select * the SPI peripheral. * @param SPI_I2S_IT: specifies the SPI interrupt source to check. * This parameter can be one of the following values: * @arg SPI_I2S_IT_TXE: Transmit buffer empty interrupt. * @arg SPI_I2S_IT_RXNE: Receive buffer not empty interrupt. * @arg SPI_IT_MODF: Mode Fault interrupt. * @arg SPI_I2S_IT_OVR: Overrun interrupt. * @arg I2S_IT_UDR: Underrun interrupt. * @arg SPI_I2S_IT_FRE: Format Error interrupt. * @retval The new state of SPI_I2S_IT (SET or RESET). */ ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT) { ITStatus bitstatus = RESET; uint16_t itpos = 0, itmask = 0, enablestatus = 0; /* Check the parameters */ assert_param(IS_SPI_ALL_PERIPH(SPIx)); assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT)); /* Get the SPI_I2S_IT index */ itpos = 0x01 << (SPI_I2S_IT & 0x0F); /* Get the SPI_I2S_IT IT mask */ itmask = SPI_I2S_IT >> 4; /* Set the IT mask */ itmask = 0x01 << itmask; /* Get the SPI_I2S_IT enable bit status */ enablestatus = (SPIx->CR2 & itmask) ; /* Check the status of the specified SPI interrupt */ if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus) { /* SPI_I2S_IT is set */ bitstatus = SET; } else { /* SPI_I2S_IT is reset */ bitstatus = RESET; } /* Return the SPI_I2S_IT status */ return bitstatus; }