More fixes to the AVRISP command timeout system so that it should no longer lock...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / TINYNVM.c
index 428469d..a894793 100644 (file)
@@ -77,13 +77,15 @@ static void TINYNVM_SendWriteNVMRegister(const uint8_t Address)
 bool TINYNVM_WaitWhileNVMBusBusy(void)\r
 {\r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
 bool TINYNVM_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 SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)\r
        while (TimeoutMSRemaining)\r
        {\r
                /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_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
 \r
                /* Manage software timeout */\r
                if (TIFR0 & (1 << OCF0A))\r
@@ -104,7 +106,6 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
 bool TINYNVM_WaitWhileNVMControllerBusy(void)\r
 {\r
        /* Poll the STATUS register to check to see if NVM access has been enabled */\r
 bool TINYNVM_WaitWhileNVMControllerBusy(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 SIN command to read the TPI STATUS register to see the NVM bus is busy */\r
        while (TimeoutMSRemaining)\r
        {\r
                /* Send the SIN command to read the TPI STATUS register to see the NVM bus is busy */\r
@@ -112,7 +113,10 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
 \r
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
 \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
 \r
                /* Manage software timeout */\r
                if (TIFR0 & (1 << OCF0A))\r