aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-24 11:04:05 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-24 11:04:05 +0000
commit92adb00f8eebab41853f95bbc0de8a2006c6df3d (patch)
treeb3ba0b1a7e1025edad8e0a48bb24eb3255e1a4d9 /Projects/Incomplete/AVRISP/Lib/V2Protocol.c
parentf9c0357b731e5ca4a5456056bbbe2e4a8a2dc9fe (diff)
downloadlufa-92adb00f8eebab41853f95bbc0de8a2006c6df3d.tar.gz
lufa-92adb00f8eebab41853f95bbc0de8a2006c6df3d.tar.bz2
lufa-92adb00f8eebab41853f95bbc0de8a2006c6df3d.zip
Added PROGRAM_FLASH_ISP and PROGRAM_EEPROM_ISP handler code to the V2 Protocol handler in the AVRISP project, programming complete checks not yet complete.
Diffstat (limited to 'Projects/Incomplete/AVRISP/Lib/V2Protocol.c')
-rw-r--r--Projects/Incomplete/AVRISP/Lib/V2Protocol.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
index 7bb8f71ca..16a1a0708 100644
--- a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
+++ b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c
@@ -259,26 +259,37 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
uint8_t PollValue2;
} Write_Memory_Params;
- uint8_t ProgrammingStatus = STATUS_CMD_OK;
-
Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);
+ uint8_t ProgrammingStatus = STATUS_CMD_OK;
+ uint16_t PollAddress = 0;
+
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)
{
+ /* Paged mode memory programming */
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)
{
- if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))
+ bool IsOddByte = (CurrentByte & 0x01);
+ uint8_t ByteToWrite = Endpoint_Read_Byte();
+
+ if ((V2Command == CMD_READ_FLASH_ISP) && IsOddByte)
Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);
SPI_SendByte(CurrentAddress >> 8);
SPI_SendByte(CurrentAddress & 0xFF);
- SPI_SendByte(Endpoint_Read_Byte());
+ SPI_SendByte(ByteToWrite);
- // TODO - Correct Polling
-
- if (((V2Command == CMD_PROGRAM_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_PROGRAM_EEPROM_ISP))
+ if (!(PollAddress))
+ {
+ if ((ByteToWrite != Write_Memory_Params.PollValue1) && (V2Command == CMD_PROGRAM_FLASH_ISP))
+ PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);
+ else if ((ByteToWrite != Write_Memory_Params.PollValue2) && (V2Command == CMD_PROGRAM_EEPROM_ISP))
+ PollAddress = (CurrentAddress & 0xFFFF);
+ }
+
+ if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))
CurrentAddress++;
}
@@ -289,11 +300,46 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
SPI_SendByte(CurrentAddress >> 8);
SPI_SendByte(CurrentAddress & 0xFF);
SPI_SendByte(0x00);
+
+ /* Check if polling is possible, if not switch to timed delay mode */
+ if (!(PollAddress))
+ {
+ Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK;
+ Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_TIMEDELAY_MASK;
+ }
}
+
+ ProgrammingStatus = V2Protocol_WaitForProgrammingComplete(PollAddress, Write_Memory_Params.ProgrammingMode);
}
else
- {
- // TODO - Read in programming data, write to device
+ {
+ /* Word/byte mode memory programming */
+ for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)
+ {
+ bool IsOddByte = (CurrentByte & 0x01);
+ uint8_t ByteToWrite = Endpoint_Read_Byte();
+
+ if ((V2Command == CMD_READ_FLASH_ISP) && IsOddByte)
+ Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;
+
+ SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);
+ SPI_SendByte(CurrentAddress >> 8);
+ SPI_SendByte(CurrentAddress & 0xFF);
+ SPI_SendByte(ByteToWrite);
+
+ if ((ByteToWrite != Write_Memory_Params.PollValue1) && (V2Command == CMD_PROGRAM_FLASH_ISP))
+ PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);
+ else if ((ByteToWrite != Write_Memory_Params.PollValue2) && (V2Command == CMD_PROGRAM_EEPROM_ISP))
+ PollAddress = (CurrentAddress & 0xFFFF);
+
+ ProgrammingStatus = V2Protocol_WaitForProgrammingComplete(PollAddress, Write_Memory_Params.ProgrammingMode);
+
+ if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))
+ CurrentAddress++;
+
+ if (ProgrammingStatus != STATUS_CMD_OK)
+ break;
+ }
}
Endpoint_ClearOUT();