- PDITarget_SendByte(AbsoluteAddress & 0xFF);\r
- PDITarget_SendByte(AbsoluteAddress >> 8);\r
- PDITarget_SendByte(AbsoluteAddress >> 16);\r
- PDITarget_SendByte(AbsoluteAddress >> 24);\r
+ XPROGTarget_SendByte(AbsoluteAddress & 0xFF);\r
+ XPROGTarget_SendByte(AbsoluteAddress >> 8);\r
+ XPROGTarget_SendByte(AbsoluteAddress >> 16);\r
+ XPROGTarget_SendByte(AbsoluteAddress >> 24);\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
+ * \return Boolean true if the NVM controller became ready within the timeout period, false otherwise\r
+ */\r
+bool XMEGANVM_WaitWhileNVMBusBusy(void)\r
+{\r
+ TCNT0 = 0;\r
+ TIFR0 = (1 << OCF1A);\r
+ \r
+ uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS;\r
+ \r
+ /* Poll the STATUS register to check to see if NVM access has been enabled */\r
+ while (TimeoutMS)\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
+ if (TIFR0 & (1 << OCF1A))\r
+ {\r
+ TIFR0 = (1 << OCF1A);\r
+ TimeoutMS--;\r
+ }\r
+ }\r
+ \r
+ return false;\r