/* This function handles SPI communication timeout in interrupt function.  */
static ald_status_t spi_wait_flag_irq(ald_spi_handle_t *hperh, ald_spi_flag_t flag, flag_status_t status, uint32_t timeout)
/* This function handles SPI communication timeout in interrupt function.  */
static ald_status_t spi_wait_flag_irq(ald_spi_handle_t *hperh, ald_spi_flag_t flag, flag_status_t status, uint32_t timeout)
{
    assert_param(timeout > 0);
    while (((ald_spi_get_flag_status(hperh, flag)) != status) && (--timeout));
    if (timeout)
        return ALD_OK;
    ald_spi_interrupt_config(hperh, ALD_SPI_IT_TXE, DISABLE);
    ald_spi_interrupt_config(hperh, ALD_SPI_IT_RXTH, DISABLE);
    ald_spi_interrupt_config(hperh, ALD_SPI_IT_CRCERR, DISABLE);
    ald_spi_interrupt_config(hperh, ALD_SPI_IT_MODF, DISABLE);
    return ALD_TIMEOUT;
}