Added ENABLE_TELNET_SERVER compile time option to the Webserver project to disable...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / TINYNVM.c
index f327a47..a894793 100644 (file)
@@ -37,7 +37,6 @@
 #include "TINYNVM.h"\r
 \r
 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
-#warning TPI Protocol support is currently incomplete and is not suitable for general use.\r
 \r
 /** Sends the given pointer address to the target's TPI pointer register */\r
 static void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress)\r
@@ -83,9 +82,19 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
                /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_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
+\r
        return false;\r
 }\r
 \r
@@ -104,9 +113,19 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
 \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
+\r
        return false;\r
 }\r
 \r
@@ -204,13 +223,13 @@ bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address)
        TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
        XPROGTarget_SendByte(EraseCommand);\r
 \r
-       /* Write to a location within the target address space to start the erase process */\r
-       TINYNVM_SendPointerAddress(Address);\r
+       /* Write to a high byte location within the target address space to start the erase process */\r
+       TINYNVM_SendPointerAddress(Address | 0x0001);\r
        XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT);\r
        XPROGTarget_SendByte(0x00);\r
 \r
-       /* Wait until the NVM bus is ready again */\r
-       if (!(TINYNVM_WaitWhileNVMBusBusy()))\r
+       /* Wait until the NVM controller is no longer busy */\r
+       if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
        \r
        return true;\r