Finished preliminary AVRISP project - all V2 protocol commands now work correctly...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 25 Aug 2009 11:24:45 +0000 (11:24 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 25 Aug 2009 11:24:45 +0000 (11:24 +0000)
Projects/Incomplete/AVRISP/Lib/V2Protocol.c

index f2089c6..08a54e2 100644 (file)
@@ -270,35 +270,34 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                uint8_t  ProgrammingCommands[3];\r
                uint8_t  PollValue1;\r
                uint8_t  PollValue2;\r
+               uint8_t  ProgData[256];\r
        } Write_Memory_Params;\r
        \r
-       Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));\r
+       uint8_t* NextWriteByte = Write_Memory_Params.ProgData;\r
+\r
+       Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
        Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
-       \r
+       Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
+\r
+       Endpoint_ClearOUT();\r
+       Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+\r
        uint8_t  ProgrammingStatus = STATUS_CMD_OK;     \r
        uint16_t PollAddress       = 0;\r
        uint8_t  PollValue         = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 :\r
                                                                            Write_Memory_Params.PollValue2;\r
-       \r
        if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)\r
        {\r
                uint16_t StartAddress = (CurrentAddress & 0xFFFF);\r
        \r
                /* Paged mode memory programming */\r
                for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
-               {                               \r
-                       /* Check if the endpoint bank is currently empty */\r
-                       if (!(Endpoint_IsReadWriteAllowed()))\r
-                       {\r
-                               Endpoint_ClearOUT();\r
-                               Endpoint_WaitUntilReady();\r
-                       }       \r
-\r
+               {\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
-                       uint8_t ByteToWrite = Endpoint_Read_Byte();\r
+                       uint8_t ByteToWrite = *(NextWriteByte++);\r
                \r
                        if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
-                         Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
+                         Write_Memory_Params.ProgrammingCommands[0] |=  READ_WRITE_HIGH_BYTE_MASK;\r
                        else\r
                          Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK;\r
                          \r
@@ -331,7 +330,7 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                        if (!(PollAddress))\r
                        {\r
                                Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK;\r
-                               Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_TIMEDELAY_MASK;                         \r
+                               Write_Memory_Params.ProgrammingMode |=  PROG_MODE_PAGED_TIMEDELAY_MASK;                         \r
                        }\r
 \r
                        ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
@@ -343,18 +342,11 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                /* Word/byte mode memory programming */\r
                for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
                {\r
-                       /* Check if the endpoint bank is currently empty */\r
-                       if (!(Endpoint_IsReadWriteAllowed()))\r
-                       {\r
-                               Endpoint_ClearOUT();\r
-                               Endpoint_WaitUntilReady();\r
-                       }       \r
-\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
-                       uint8_t ByteToWrite = Endpoint_Read_Byte();\r
+                       uint8_t ByteToWrite = *(NextWriteByte++);\r
                \r
                        if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
-                         Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
+                         Write_Memory_Params.ProgrammingCommands[0] |=  READ_WRITE_HIGH_BYTE_MASK;\r
                        else\r
                          Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK;                     \r
                          \r
@@ -381,9 +373,6 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                          break;\r
                }\r
        }\r
-       \r
-       Endpoint_ClearOUT();\r
-       Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
 \r
        Endpoint_Write_Byte(V2Command);\r
        Endpoint_Write_Byte(ProgrammingStatus);\r
@@ -413,7 +402,7 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
                bool IsOddByte = (CurrentByte & 0x01);\r
 \r
                if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
-                 Read_Memory_Params.ReadMemoryCommand |= READ_WRITE_HIGH_BYTE_MASK;\r
+                 Read_Memory_Params.ReadMemoryCommand |=  READ_WRITE_HIGH_BYTE_MASK;\r
                else\r
                  Read_Memory_Params.ReadMemoryCommand &= ~READ_WRITE_HIGH_BYTE_MASK;\r
 \r
@@ -532,8 +521,7 @@ static void V2Protocol_Command_SPIMulti(void)
                uint8_t TxData[255];\r
        } SPI_Multi_Params;\r
        \r
-       Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) -\r
-                                                  sizeof(SPI_Multi_Params.TxData));\r
+       Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData));\r
        Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes);\r
        \r
        Endpoint_ClearOUT();\r