/******************************************************************************* * Function Name : FLASH_WaitForLastOperation * Description : Waits for a Flash operation to complete or a TIMEOUT to occur. * Input : - Timeout: FLASH progamming Timeout * Output : None * Return : FLASH Status: The returned value can be: FLASH_BUSY, * FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or * FLASH_TIMEOUT. *******************************************************************************/ FLASH_Status FLASH_WaitForLastOperation(u32 Timeout) { FLASH_Status status = FLASH_COMPLETE;
/* Check for the Flash Status */ status = FLASH_GetStatus();
/* Wait for a Flash operation to complete or a TIMEOUT to occur */ while((status == FLASH_BUSY) && (Timeout != 0x00)) { delay(); status = FLASH_GetStatus(); Timeout--; }
if(Timeout == 0x00 ) { status = FLASH_TIMEOUT; }
/* Return the operation status */ return status; }