bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
{\r
/* Poll the STATUS register to check to see if NVM access has been enabled */\r
+ uint8_t TimeoutMSRemaining = 100;\r
while (TimeoutMSRemaining)\r
{\r
/* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */\r
XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);\r
if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)\r
+ return true;\r
+\r
+ /* Manage software timeout */\r
+ if (TIFR0 & (1 << OCF0A))\r
{\r
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
- return true;\r
+ TIFR0 |= (1 << OCF0A);\r
+ TimeoutMSRemaining--;\r
}\r
}\r
\r
bool XMEGANVM_WaitWhileNVMControllerBusy(void)\r
{\r
/* Poll the NVM STATUS register while the NVM controller is busy */\r
+ uint8_t TimeoutMSRemaining = 100;\r
while (TimeoutMSRemaining)\r
{\r
/* Send a LDS command to read the NVM STATUS register to check the BUSY flag */\r
\r
/* Check to see if the BUSY flag is still set */\r
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
+ return true;\r
+\r
+ /* Manage software timeout */\r
+ if (TIFR0 & (1 << OCF0A))\r
{\r
- TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
- return true;\r
+ TIFR0 |= (1 << OCF0A);\r
+ TimeoutMSRemaining--;\r
}\r
}\r
\r