Fix TPI NVM Write handler -- AVRStudio sends out writes in page sized chunks, not...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 28 Dec 2009 07:50:20 +0000 (07:50 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 28 Dec 2009 07:50:20 +0000 (07:50 +0000)
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c
Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h

index 4d879bd..41e6852 100644 (file)
@@ -119,14 +119,13 @@ bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_
 \r
 /** Writes byte addressed memory to the target's memory spaces.\r
  *\r
- *  \param[in]  WriteCommand  Command to send to the device to write each memory byte\r
  *  \param[in]  WriteAddress  Start address to write to within the target's address space\r
  *  \param[in]  WriteBuffer   Buffer to source data from\r
- *\r
+ *  \param[in]  WriteLength   Total number of bytes to write to the device\r
  *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
-bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte)\r
+bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer, uint16_t WriteLength)\r
 {\r
        /* Wait until the NVM controller is no longer busy */\r
        if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
@@ -139,9 +138,12 @@ bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte)
        /* Send the address of the location to write to */\r
        TINYNVM_SendPointerAddress(WriteAddress);\r
        \r
-       /* Write the byte of data to the target */\r
-       XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT);\r
-       XPROGTarget_SendByte(Byte);\r
+       while (WriteLength--)\r
+       {\r
+               /* Write the byte of data to the target */\r
+               XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
+               XPROGTarget_SendByte(*(WriteBuffer++));\r
+       }\r
        \r
        return true;\r
 }\r
index 2d98c0d..e7d8dad 100644 (file)
@@ -65,7 +65,7 @@
                void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress);\r
                bool TINYNVM_WaitWhileNVMBusBusy(void);\r
                bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength);\r
-               bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte);\r
+               bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer, uint16_t WriteLength);\r
                bool TINYNVM_EraseMemory(void);\r
 \r
 #endif\r
index 39f82a0..5275cca 100644 (file)
@@ -134,6 +134,7 @@ static void XPROGProtocol_EnterXPROGMode(void)
        }\r
        else\r
        {\r
+       #if 0\r
                /* Enable TPI programming mode with the attached target */\r
                XPROGTarget_EnableTargetTPI();\r
                \r
@@ -144,6 +145,8 @@ static void XPROGProtocol_EnterXPROGMode(void)
 \r
                /* Wait until the NVM bus becomes active */\r
                NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy();\r
+       #endif\r
+               NVMBusEnabled = true;\r
        }\r
        \r
        Endpoint_Write_Byte(CMD_XPROG);\r
@@ -313,9 +316,14 @@ static void XPROGProtocol_WriteMemory(void)
        }\r
        else\r
        {\r
+               Serial_TxByte((uint8_t)WriteMemory_XPROG_Params.Length);\r
+       \r
                /* Send write command to the TPI device, indicate timeout if occurred */\r
-               if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData[0])))\r
-                 ReturnStatus = XPRG_ERR_TIMEOUT;\r
+               if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData,\r
+                     WriteMemory_XPROG_Params.Length)))\r
+               {\r
+                       ReturnStatus = XPRG_ERR_TIMEOUT;\r
+               }\r
        }\r
        \r
        Endpoint_Write_Byte(CMD_XPROG);\r
@@ -355,6 +363,8 @@ static void XPROGProtocol_ReadMemory(void)
        }\r
        else\r
        {\r
+               Serial_TxByte((uint8_t)ReadMemory_XPROG_Params.Length);\r
+\r
                /* Read the TPI target's memory, indicate timeout if occurred */\r
                if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))\r
                  ReturnStatus = XPRG_ERR_TIMEOUT;\r
index a95e5b8..4bb6009 100644 (file)
@@ -42,6 +42,7 @@
                #include <stdio.h>\r
                \r
                #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
        \r
                #include "../V2Protocol.h"\r
                #include "XPROGTarget.h"\r