aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-04-30 08:27:21 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-04-30 08:27:21 +0000
commitceb16ee24f1e6add5e2ad0398369c24d2d868cd8 (patch)
treee8a588f50420aa51ac15e08f67eee1af23ea6ccf /Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
parent9cad677ebbd2fc4ea069f98335f8467b16dbb2cb (diff)
downloadlufa-ceb16ee24f1e6add5e2ad0398369c24d2d868cd8.tar.gz
lufa-ceb16ee24f1e6add5e2ad0398369c24d2d868cd8.tar.bz2
lufa-ceb16ee24f1e6add5e2ad0398369c24d2d868cd8.zip
Make sure that the NVM bus/controller busy waits in the AVRISP MKII clone project abort properly if a timeout occurs while waiting for a response.
Diffstat (limited to 'Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c')
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
index c0f04c6bd..7b9ff0914 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
+++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
@@ -81,7 +81,15 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
{
/* 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)
+
+ uint8_t StatusRegister = XPROGTarget_ReceiveByte();
+
+ /* We might have timed out waiting for the status register read response, check here */
+ if (!(TimeoutMSRemaining))
+ return false;
+
+ /* Check the status register read response to see if the NVM bus is enabled */
+ if (StatusRegister & TPI_STATUS_NVM)
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;
@@ -111,8 +119,14 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
/* Send the SIN command to read the TPI STATUS register to see the NVM bus is busy */
TINYNVM_SendReadNVMRegister(XPROG_Param_NVMCSRRegAddr);
+ uint8_t StatusRegister = XPROGTarget_ReceiveByte();
+
+ /* We might have timed out waiting for the status register read response, check here */
+ if (!(TimeoutMSRemaining))
+ return false;
+
/* Check to see if the BUSY flag is still set */
- if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
+ if (!(StatusRegister & (1 << 7)))
{
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
return true;