More fixes to the AVRISP command timeout system so that it should no longer lock...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XMEGANVM.c
index 6ef59db..f63f13a 100644 (file)
@@ -72,13 +72,15 @@ static void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
 bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
 {\r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
-       uint8_t TimeoutMSRemaining = 100;\r
        while (TimeoutMSRemaining)\r
        {\r
                /* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
 \r
                /* Manage software timeout */\r
                if (TIFR0 & (1 << OCF0A))\r
@@ -99,7 +101,6 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
 bool XMEGANVM_WaitWhileNVMControllerBusy(void)\r
 {\r
        /* Poll the NVM STATUS register while the NVM controller is busy */\r
-       uint8_t TimeoutMSRemaining = 100;\r
        while (TimeoutMSRemaining)\r
        {\r
                /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */\r
@@ -108,7 +109,10 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
                \r
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
 \r
                /* Manage software timeout */\r
                if (TIFR0 & (1 << OCF0A))\r