More fixes to the AVRISP command timeout system so that it should no longer lock...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XPROGTarget.c
index 45c1d22..7bef25e 100644 (file)
@@ -350,7 +350,6 @@ uint8_t XPROGTarget_ReceiveByte(void)
 \r
 #if defined(XPROG_VIA_HARDWARE_USART)\r
        /* Wait until a byte has been received before reading */\r
-       uint8_t TimeoutMSRemaining = 100;\r
        while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining)\r
        {\r
                /* Manage software timeout */\r
@@ -365,7 +364,6 @@ uint8_t XPROGTarget_ReceiveByte(void)
 #else\r
        /* Wait until a byte has been received before reading */\r
        SoftUSART_BitCount = BITS_IN_USART_FRAME;\r
-       uint8_t TimeoutMSRemaining = 100;\r
        while (SoftUSART_BitCount && TimeoutMSRemaining)\r
        {\r
                /* Manage software timeout */\r
@@ -376,6 +374,9 @@ uint8_t XPROGTarget_ReceiveByte(void)
                }\r
        }\r
 \r
+       if (TimeoutMSRemaining)\r
+         TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+\r
        /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */\r
        return (uint8_t)SoftUSART_Data;\r
 #endif\r
@@ -468,7 +469,6 @@ static void XPROGTarget_SetRxMode(void)
        }\r
        \r
        /* Wait until DATA line has been pulled up to idle by the target */\r
-       uint8_t TimeoutMSRemaining = 100;\r
        while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining)\r
        {\r
                /* Manage software timeout */\r
@@ -480,6 +480,9 @@ static void XPROGTarget_SetRxMode(void)
        }       \r
 #endif\r
 \r
+    if (TimeoutMSRemaining)\r
+         TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+\r
        IsSending = false;\r
 }\r
 \r