case CMD_LOAD_ADDRESS:\r
V2Protocol_Command_LoadAddress();\r
break;\r
+ case CMD_RESET_PROTECTION:\r
+ V2Protocol_Command_ResetProtection();\r
+ break;\r
case CMD_ENTER_PROGMODE_ISP:\r
V2Protocol_Command_EnterISPMode();\r
break;\r
Endpoint_ClearIN();\r
}\r
\r
+static void V2Protocol_Command_ResetProtection(void)\r
+{\r
+ Endpoint_ClearOUT();\r
+ Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+ \r
+ Endpoint_Write_Byte(CMD_RESET_PROTECTION);\r
+ Endpoint_Write_Byte(STATUS_CMD_OK);\r
+ Endpoint_ClearIN(); \r
+}\r
+\r
static void V2Protocol_Command_EnterISPMode(void)\r
{\r
struct\r
}\r
\r
/* Check if polling disabled, or if the polled value matches the expected value */\r
- if (!Enter_ISP_Params.PollIndex || (ResponseBytes[Enter_ISP_Params.PollIndex - 1] == Enter_ISP_Params.PollValue))\r
+ if (!(Enter_ISP_Params.PollIndex) || (ResponseBytes[Enter_ISP_Params.PollIndex - 1] == Enter_ISP_Params.PollValue))\r
{\r
ResponseStatus = STATUS_CMD_OK;\r
}\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
SPI_SendByte(CurrentAddress & 0xFF);\r
SPI_SendByte(ByteToWrite);\r
\r
- if (!(PollAddress))\r
+ if (!(PollAddress) && (ByteToWrite != PollValue))\r
{\r
- if ((ByteToWrite != Write_Memory_Params.PollValue1) && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
+ if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
- else if ((ByteToWrite != Write_Memory_Params.PollValue2) && (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
+ else\r
PollAddress = (CurrentAddress & 0xFFFF); \r
}\r
\r
}\r
}\r
\r
- ProgrammingStatus = V2Protocol_WaitForProgrammingComplete(PollAddress, Write_Memory_Params.ProgrammingMode);\r
+ ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
+ Write_Memory_Params.DelayMS, (V2Command == CMD_READ_FLASH_ISP),\r
+ Write_Memory_Params.ProgrammingCommands[2]);\r
}\r
else\r
{\r
SPI_SendByte(CurrentAddress & 0xFF);\r
SPI_SendByte(ByteToWrite);\r
\r
- if ((ByteToWrite != Write_Memory_Params.PollValue1) && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
- PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
- else if ((ByteToWrite != Write_Memory_Params.PollValue2) && (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
- PollAddress = (CurrentAddress & 0xFFFF);\r
-\r
- ProgrammingStatus = V2Protocol_WaitForProgrammingComplete(PollAddress, Write_Memory_Params.ProgrammingMode);\r
-\r
+ if (ByteToWrite != PollValue)\r
+ {\r
+ if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
+ PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
+ else\r
+ PollAddress = (CurrentAddress & 0xFFFF);\r
+ }\r
+ \r
if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
CurrentAddress++;\r
+ \r
+ ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
+ Write_Memory_Params.DelayMS, (V2Command == CMD_READ_FLASH_ISP),\r
+ Write_Memory_Params.ProgrammingCommands[2]);\r
\r
if (ProgrammingStatus != STATUS_CMD_OK)\r
break;\r
}\r
\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
+\r
+ bool IsEndpointFull = !(Endpoint_IsReadWriteAllowed());\r
Endpoint_ClearIN();\r
+ \r
+ /* Ensure last packet is a short packet to terminate the transfer */\r
+ if (IsEndpointFull)\r
+ {\r
+ Endpoint_WaitUntilReady(); \r
+ Endpoint_ClearIN();\r
+ Endpoint_WaitUntilReady(); \r
+ }\r
}\r
\r
static void V2Protocol_Command_ChipErase(void)\r
for (uint8_t SByte = 0; SByte < sizeof(Erase_Chip_Params.EraseCommandBytes); SByte++)\r
SPI_SendByte(Erase_Chip_Params.EraseCommandBytes[SByte]);\r
\r
- if (Erase_Chip_Params.PollMethod == 0)\r
+ if (!(Erase_Chip_Params.PollMethod))\r
V2Protocol_DelayMS(Erase_Chip_Params.EraseDelayMS);\r
else\r
ResponseStatus = V2Protocol_WaitWhileTargetBusy();\r