/* This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_ReadMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller.  */
SD_Error SD_WaitReadOperation(void)
/* This function waits until the SDIO DMA data transfer is finished. This function should be called after SDIO_ReadMultiBlocks() function to insure that all data sent by the card are already transferred by the DMA controller.  */
SD_Error SD_WaitReadOperation(void)
{
	SD_Error errorstatus = SD_OK;
	volatile uint32_t timeout;
	timeout = SD_DATATIMEOUT;
	while ((DMAEndOfTransfer == 0x00) && (TransferEnd == 0) && (TransferError == SD_OK) && (timeout > 0)) {
		timeout--;
	}
	DMAEndOfTransfer = 0x00;
	timeout = SD_DATATIMEOUT;
	while (((SDIO ->STA & SDIO_FLAG_RXACT)) && (timeout > 0)) {
		timeout--;
	}
	if (StopCondition == 1) {
		errorstatus = SD_StopTransfer ();
		StopCondition = 0;
	}
	if ((timeout == 0) && (errorstatus == SD_OK)) {
		errorstatus = SD_DATA_TIMEOUT;
	}
	SDIO->ICR = (SDIO_STATIC_FLAGS);
	if (TransferError != SD_OK) {
		return (TransferError);
	}
	return (errorstatus);
}