Fixed AVRISP V2 Protocol handler for the READ_FLASH_ISP and READ_EEPROM_ISP handler...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 25 Aug 2009 08:58:48 +0000 (08:58 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 25 Aug 2009 08:58:48 +0000 (08:58 +0000)
LUFA/ManPages/ChangeLog.txt
Projects/Incomplete/AVRISP/Lib/V2Protocol.c

index da4c007..6c4fea5 100644 (file)
@@ -14,7 +14,7 @@
   *  - Added new EVENT_USB_Device_StartOfFrame() event, controlled by the new USB_Device_EnableSOFEvents() and\r
   *    USB_Device_DisableSOFEvents() macros to give bus-synchronised millisecond interrupts when in USB device mode\r
   *  - Added new Endpoint_SetEndpointDirection() macro for bi-directional endpoints\r
   *  - Added new EVENT_USB_Device_StartOfFrame() event, controlled by the new USB_Device_EnableSOFEvents() and\r
   *    USB_Device_DisableSOFEvents() macros to give bus-synchronised millisecond interrupts when in USB device mode\r
   *  - Added new Endpoint_SetEndpointDirection() macro for bi-directional endpoints\r
-  *  - Added new AVRISP project, a LUFA clone of the Atmel AVRISP-MKII programmer\r
+  *  - Added new AVRISP project, a LUFA powered clone of the Atmel AVRISP-MKII programmer\r
   *  - Added ShutDown functions for all hardware peripheral drivers, so that peripherals can be turned off after use\r
   *  \r
   *  <b>Changed:</b>\r
   *  - Added ShutDown functions for all hardware peripheral drivers, so that peripherals can be turned off after use\r
   *  \r
   *  <b>Changed:</b>\r
@@ -35,6 +35,8 @@
   *    causing continuous USART receive interrupts\r
   *  - Fixed misspelt event name in the Class driver USBtoSerial demo, preventing correct operation\r
   *  - Fixed invalid data being returned when a GetStatus request is issued in Device mode with an unhandled data recipient\r
   *    causing continuous USART receive interrupts\r
   *  - Fixed misspelt event name in the Class driver USBtoSerial demo, preventing correct operation\r
   *  - Fixed invalid data being returned when a GetStatus request is issued in Device mode with an unhandled data recipient\r
+  *  - Added hardware USART receive interrupt and software buffering to the Benito project to ensure received data is not\r
+  *    missed or corrupted\r
   *\r
   *\r
   *  \section Sec_ChangeLog090810 Version 090810\r
   *\r
   *\r
   *  \section Sec_ChangeLog090810 Version 090810\r
index 8d14802..f2089c6 100644 (file)
@@ -286,12 +286,21 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
        \r
                /* Paged mode memory programming */\r
                for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
        \r
                /* Paged mode memory programming */\r
                for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
-               {\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
                \r
                        if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
                        uint8_t ByteToWrite = Endpoint_Read_Byte();\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
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
                          \r
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
@@ -304,14 +313,7 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                                  Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
                                  \r
                                PollAddress = (CurrentAddress & 0xFFFF);                                \r
                                  Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
                                  \r
                                PollAddress = (CurrentAddress & 0xFFFF);                                \r
-                       }\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
                        if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
                          CurrentAddress++;\r
 \r
                        if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
                          CurrentAddress++;\r
@@ -341,11 +343,20 @@ 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
                /* 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
                \r
                        if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
                        uint8_t ByteToWrite = Endpoint_Read_Byte();\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
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
                          \r
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
@@ -359,13 +370,6 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
                                  \r
                                PollAddress = (CurrentAddress & 0xFFFF);\r
                        }\r
                                  \r
                                PollAddress = (CurrentAddress & 0xFFFF);\r
                        }\r
-                       \r
-                       /* Check if the endpoint bank is currently empty */\r
-                       if (!(Endpoint_IsReadWriteAllowed()))\r
-                       {\r
-                               Endpoint_ClearOUT();\r
-                               Endpoint_WaitUntilReady();\r
-                       }       \r
 \r
                        if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
                          CurrentAddress++;\r
 \r
                        if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
                          CurrentAddress++;\r
@@ -406,8 +410,12 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
        \r
        for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
        {\r
        \r
        for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
        {\r
-               if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
-                 Read_Memory_Params.ReadMemoryCommand ^= READ_WRITE_HIGH_BYTE_MASK;\r
+               bool IsOddByte = (CurrentByte & 0x01);\r
+\r
+               if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
+                 Read_Memory_Params.ReadMemoryCommand |= READ_WRITE_HIGH_BYTE_MASK;\r
+               else\r
+                 Read_Memory_Params.ReadMemoryCommand &= ~READ_WRITE_HIGH_BYTE_MASK;\r
 \r
                SPI_SendByte(Read_Memory_Params.ReadMemoryCommand);\r
                SPI_SendByte(CurrentAddress >> 8);\r
 \r
                SPI_SendByte(Read_Memory_Params.ReadMemoryCommand);\r
                SPI_SendByte(CurrentAddress >> 8);\r
@@ -421,7 +429,7 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
                        Endpoint_WaitUntilReady();\r
                }\r
                \r
                        Endpoint_WaitUntilReady();\r
                }\r
                \r
-               if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP))\r
+               if ((IsOddByte && (V2Command == CMD_READ_FLASH_ISP)) || (V2Command == CMD_READ_EEPROM_ISP))\r
                  CurrentAddress++;\r
        }\r
 \r
                  CurrentAddress++;\r
        }\r
 \r