\r
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
\r
-/** Sends the given NVM register address to the target.\r
- *\r
- * \param[in] Register NVM register whose absolute address is to be sent\r
- */\r
-void XMEGANVM_SendNVMRegAddress(const uint8_t Register)\r
-{\r
- /* Determine the absolute register address from the NVM base memory address and the NVM register address */\r
- uint32_t Address = XPROG_Param_NVMBase | Register;\r
-\r
- /* Send the calculated 32-bit address to the target, LSB first */\r
- XMEGANVM_SendAddress(Address);\r
-}\r
-\r
/** Sends the given 32-bit absolute address to the target.\r
*\r
* \param[in] AbsoluteAddress Absolute address to send to the target\r
*/\r
-void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)\r
+static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)\r
{\r
/* Send the given 32-bit address to the target, LSB first */\r
XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]);\r
XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[3]);\r
}\r
\r
+/** Sends the given NVM register address to the target.\r
+ *\r
+ * \param[in] Register NVM register whose absolute address is to be sent\r
+ */\r
+static void XMEGANVM_SendNVMRegAddress(const uint8_t Register)\r
+{\r
+ /* Determine the absolute register address from the NVM base memory address and the NVM register address */\r
+ uint32_t Address = XPROG_Param_NVMBase | Register;\r
+\r
+ /* Send the calculated 32-bit address to the target, LSB first */\r
+ XMEGANVM_SendAddress(Address);\r
+}\r
+\r
/** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC\r
* calculation.\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
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
+\r
+ /* Manage software timeout */\r
+ if (TIFR0 & (1 << OCF0A))\r
+ {\r
+ TIFR0 |= (1 << OCF0A);\r
+ TimeoutMSRemaining--;\r
+ }\r
}\r
\r
return false;\r
\r
/* Check to see if the BUSY flag is still set */\r
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
- return true;\r
+ {\r
+ TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+ return true;\r
+ }\r
+\r
+ /* Manage software timeout */\r
+ if (TIFR0 & (1 << OCF0A))\r
+ {\r
+ TIFR0 |= (1 << OCF0A);\r
+ TimeoutMSRemaining--;\r
+ }\r
}\r
\r
return false;\r
{\r
/* Other erase modes just need us to address a byte within the target memory space */\r
XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2));\r
- XMEGANVM_SendAddress(Address); \r
+ XMEGANVM_SendAddress(Address);\r
XPROGTarget_SendByte(0x00);\r
}\r
\r