X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/8b7565956380c558bb309732c1d7d2cb58b193ea..37c9ba7fa980472406625973f0ee32719b5a8997:/Projects/AVRISP/Lib/NVMTarget.c?ds=inline diff --git a/Projects/AVRISP/Lib/NVMTarget.c b/Projects/AVRISP/Lib/NVMTarget.c index 00312d513..adf213bb4 100644 --- a/Projects/AVRISP/Lib/NVMTarget.c +++ b/Projects/AVRISP/Lib/NVMTarget.c @@ -72,9 +72,12 @@ void NVMTarget_SendAddress(const uint32_t AbsoluteAddress) bool NVMTarget_WaitWhileNVMControllerBusy(void) { TCNT0 = 0; - + TIFR0 = (1 << OCF1A); + + uint8_t TimeoutMS = PDI_NVM_TIMEOUT_MS; + /* Poll the NVM STATUS register while the NVM controller is busy */ - while (TCNT0 < NVM_BUSY_TIMEOUT_MS) + while (TimeoutMS) { /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */ PDITarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); @@ -83,6 +86,12 @@ bool NVMTarget_WaitWhileNVMControllerBusy(void) /* Check to see if the BUSY flag is still set */ if (!(PDITarget_ReceiveByte() & (1 << 7))) return true; + + if (TIFR0 & (1 << OCF1A)) + { + TIFR0 = (1 << OCF1A); + TimeoutMS--; + } } return false;