aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-25 11:24:45 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-25 11:24:45 +0000
commit73801c73a1684a88bff33aefe3c5aa89bc66c414 (patch)
tree41a3e32a93e79c73b55b3ee2140d3bcde8fa1bc2
parent4742e95a3f8ef01715c6d5e740c4aab59d2c2b58 (diff)
downloadlufa-73801c73a1684a88bff33aefe3c5aa89bc66c414.tar.gz
lufa-73801c73a1684a88bff33aefe3c5aa89bc66c414.tar.bz2
lufa-73801c73a1684a88bff33aefe3c5aa89bc66c414.zip
Finished preliminary AVRISP project - all V2 protocol commands now work correctly for basic operations.
-rw-r--r--Projects/Incomplete/AVRISP/Lib/V2Protocol.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
index f2089c67a..08a54e2f1 100644
--- a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
+++ b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
@@ -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();