From ce8d0424b1a59bb2b0bd3ab8f69f4e4cf8c9930b Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Fri, 19 Feb 2010 05:17:41 +0000 Subject: AVRISP programmer project now has a more robust timeout system, allowing for a doubling of the software USART speed for PDI and TPI programming. --- Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c') diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index fc98cfceb9..6ef59db377 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -72,14 +72,19 @@ 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; + + /* Manage software timeout */ + if (TIFR0 & (1 << OCF0A)) { - TimeoutMSRemaining = COMMAND_TIMEOUT_MS; - return true; + TIFR0 |= (1 << OCF0A); + TimeoutMSRemaining--; } } @@ -94,6 +99,7 @@ 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 */ @@ -102,9 +108,13 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void) /* Check to see if the BUSY flag is still set */ if (!(XPROGTarget_ReceiveByte() & (1 << 7))) + return true; + + /* Manage software timeout */ + if (TIFR0 & (1 << OCF0A)) { - TimeoutMSRemaining = COMMAND_TIMEOUT_MS; - return true; + TIFR0 |= (1 << OCF0A); + TimeoutMSRemaining--; } } -- cgit v1.2.3