X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ce8d0424b1a59bb2b0bd3ab8f69f4e4cf8c9930b..fd96b288824caaa3ee4e5e03887f016de9df80cf:/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index 428469df7..c0f04c6bd 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -65,7 +65,7 @@ static void TINYNVM_SendReadNVMRegister(const uint8_t Address) */ static void TINYNVM_SendWriteNVMRegister(const uint8_t Address) { - /* The TPI command for writing to the I/O space uses weird addressing, where the I/O address's upper + /* The TPI command for reading from the I/O space uses strange addressing, where the I/O address's upper * two bits of the 6-bit address are shifted left once */ XPROGTarget_SendByte(TPI_CMD_SOUT | ((Address & 0x30) << 1) | (Address & 0x0F)); } @@ -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))