Stub out more of the TPI programming protocol routines in the AVRISP project.
[pub/USBasp.git] / Projects / AVRISP / Lib / TPITarget.c
index 8b47006..464d403 100644 (file)
@@ -312,8 +312,26 @@ void TPITarget_SendBreak(void)
  */\r
 bool TPITarget_WaitWhileNVMBusBusy(void)\r
 {\r
-       // TODO\r
-\r
+       TCNT0 = 0;\r
+       TIFR0 = (1 << OCF1A);\r
+                       \r
+       uint8_t TimeoutMS = TPI_NVM_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 TPI STATUS register to see the NVM bus is active */\r
+               TPITarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
+               if (TPITarget_ReceiveByte() & TPI_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
 }\r
 \r