From e322f14620a1064efc4b3a98cf701efc48da81cc Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sun, 21 Feb 2010 06:26:33 +0000 Subject: More fixes to the AVRISP command timeout system so that it should no longer lock up while processing command no matter what the conditions. --- Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c | 12 ++++++++---- Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c | 12 ++++++++---- Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c | 9 ++++++--- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'Projects/AVRISP-MKII/Lib/XPROG') diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index 428469df74..a894793c7b 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -77,13 +77,15 @@ static void TINYNVM_SendWriteNVMRegister(const uint8_t Address) bool TINYNVM_WaitWhileNVMBusBusy(void) { /* Poll the STATUS register to check to see if NVM access has been enabled */ - uint8_t TimeoutMSRemaining = 100; while (TimeoutMSRemaining) { /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */ XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG); if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM) - return true; + { + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + return true; + } /* Manage software timeout */ if (TIFR0 & (1 << OCF0A)) @@ -104,7 +106,6 @@ bool TINYNVM_WaitWhileNVMBusBusy(void) bool TINYNVM_WaitWhileNVMControllerBusy(void) { /* Poll the STATUS register to check to see if NVM access has been enabled */ - uint8_t TimeoutMSRemaining = 100; while (TimeoutMSRemaining) { /* Send the SIN command to read the TPI STATUS register to see the NVM bus is busy */ @@ -112,7 +113,10 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void) /* Check to see if the BUSY flag is still set */ if (!(XPROGTarget_ReceiveByte() & (1 << 7))) - return true; + { + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + return true; + } /* Manage software timeout */ if (TIFR0 & (1 << OCF0A)) diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index 6ef59db377..f63f13a97a 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -72,13 +72,15 @@ static void XMEGANVM_SendNVMRegAddress(const uint8_t Register) bool XMEGANVM_WaitWhileNVMBusBusy(void) { /* Poll the STATUS register to check to see if NVM access has been enabled */ - uint8_t TimeoutMSRemaining = 100; while (TimeoutMSRemaining) { /* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */ XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG); if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM) - return true; + { + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + return true; + } /* Manage software timeout */ if (TIFR0 & (1 << OCF0A)) @@ -99,7 +101,6 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void) bool XMEGANVM_WaitWhileNVMControllerBusy(void) { /* Poll the NVM STATUS register while the NVM controller is busy */ - uint8_t TimeoutMSRemaining = 100; while (TimeoutMSRemaining) { /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */ @@ -108,7 +109,10 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void) /* Check to see if the BUSY flag is still set */ if (!(XPROGTarget_ReceiveByte() & (1 << 7))) - return true; + { + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + return true; + } /* Manage software timeout */ if (TIFR0 & (1 << OCF0A)) diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c index 45c1d225de..7bef25e6e0 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c @@ -350,7 +350,6 @@ uint8_t XPROGTarget_ReceiveByte(void) #if defined(XPROG_VIA_HARDWARE_USART) /* Wait until a byte has been received before reading */ - uint8_t TimeoutMSRemaining = 100; while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining) { /* Manage software timeout */ @@ -365,7 +364,6 @@ uint8_t XPROGTarget_ReceiveByte(void) #else /* Wait until a byte has been received before reading */ SoftUSART_BitCount = BITS_IN_USART_FRAME; - uint8_t TimeoutMSRemaining = 100; while (SoftUSART_BitCount && TimeoutMSRemaining) { /* Manage software timeout */ @@ -376,6 +374,9 @@ uint8_t XPROGTarget_ReceiveByte(void) } } + if (TimeoutMSRemaining) + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */ return (uint8_t)SoftUSART_Data; #endif @@ -468,7 +469,6 @@ static void XPROGTarget_SetRxMode(void) } /* Wait until DATA line has been pulled up to idle by the target */ - uint8_t TimeoutMSRemaining = 100; while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining) { /* Manage software timeout */ @@ -480,6 +480,9 @@ static void XPROGTarget_SetRxMode(void) } #endif + if (TimeoutMSRemaining) + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + IsSending = false; } -- cgit v1.2.3