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