Commit 73801c73 authored by Dean Camera's avatar Dean Camera
Browse files

Finished preliminary AVRISP project - all V2 protocol commands now work...

Finished preliminary AVRISP project - all V2 protocol commands now work correctly for basic operations.
parent 4742e95a
...@@ -270,16 +270,22 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -270,16 +270,22 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
uint8_t ProgrammingCommands[3]; uint8_t ProgrammingCommands[3];
uint8_t PollValue1; uint8_t PollValue1;
uint8_t PollValue2; uint8_t PollValue2;
uint8_t ProgData[256];
} Write_Memory_Params; } 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); 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; uint8_t ProgrammingStatus = STATUS_CMD_OK;
uint16_t PollAddress = 0; uint16_t PollAddress = 0;
uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 : uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 :
Write_Memory_Params.PollValue2; Write_Memory_Params.PollValue2;
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK) if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)
{ {
uint16_t StartAddress = (CurrentAddress & 0xFFFF); uint16_t StartAddress = (CurrentAddress & 0xFFFF);
...@@ -287,15 +293,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -287,15 +293,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
/* Paged mode memory programming */ /* Paged mode memory programming */
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++) 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); bool IsOddByte = (CurrentByte & 0x01);
uint8_t ByteToWrite = Endpoint_Read_Byte(); uint8_t ByteToWrite = *(NextWriteByte++);
if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP)) 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;
...@@ -331,7 +330,7 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -331,7 +330,7 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
if (!(PollAddress)) if (!(PollAddress))
{ {
Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK; 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, ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,
...@@ -343,15 +342,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -343,15 +342,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
/* Word/byte mode memory programming */ /* Word/byte mode memory programming */
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++) 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); bool IsOddByte = (CurrentByte & 0x01);
uint8_t ByteToWrite = Endpoint_Read_Byte(); uint8_t ByteToWrite = *(NextWriteByte++);
if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP)) 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;
...@@ -382,9 +374,6 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -382,9 +374,6 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
} }
} }
Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
Endpoint_Write_Byte(V2Command); Endpoint_Write_Byte(V2Command);
Endpoint_Write_Byte(ProgrammingStatus); Endpoint_Write_Byte(ProgrammingStatus);
...@@ -532,8 +521,7 @@ static void V2Protocol_Command_SPIMulti(void) ...@@ -532,8 +521,7 @@ static void V2Protocol_Command_SPIMulti(void)
uint8_t TxData[255]; uint8_t TxData[255];
} SPI_Multi_Params; } SPI_Multi_Params;
Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData));
sizeof(SPI_Multi_Params.TxData));
Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes); Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment