X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/dbb5f249bd057c7b292645463c52067c1da58efa..f9c0357b731e5ca4a5456056bbbe2e4a8a2dc9fe:/Projects/Incomplete/AVRISP/Lib/V2Protocol.c?ds=sidebyside diff --git a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c index 85e3a382d..7bb8f71ca 100644 --- a/Projects/Incomplete/AVRISP/Lib/V2Protocol.c +++ b/Projects/Incomplete/AVRISP/Lib/V2Protocol.c @@ -264,9 +264,36 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params)); Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); - for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++) + if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK) { - // TODO - Read in programming data, write to device + for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++) + { + if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) + 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()); + + // TODO - Correct Polling + + if (((V2Command == CMD_PROGRAM_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_PROGRAM_EEPROM_ISP)) + CurrentAddress++; + } + + /* If the current page must be committed, send the PROGRAM PAGE command to the target */ + if (Write_Memory_Params.ProgrammingMode & PROG_MODE_COMMIT_PAGE_MASK) + { + SPI_SendByte(Write_Memory_Params.ProgrammingCommands[1]); + SPI_SendByte(CurrentAddress >> 8); + SPI_SendByte(CurrentAddress & 0xFF); + SPI_SendByte(0x00); + } + } + else + { + // TODO - Read in programming data, write to device } Endpoint_ClearOUT(); @@ -294,7 +321,7 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command) Endpoint_Write_Byte(V2Command); Endpoint_Write_Byte(STATUS_CMD_OK); - + for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++) { if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) @@ -312,20 +339,12 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command) Endpoint_WaitUntilReady(); } - CurrentAddress++; + if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP)) + CurrentAddress++; } Endpoint_Write_Byte(STATUS_CMD_OK); - - bool EndpointBankFull = Endpoint_IsReadWriteAllowed(); Endpoint_ClearIN(); - - /* Ensure data transfer is terminated by a short packet if the last sent bank was completely full */ - if (EndpointBankFull) - { - Endpoint_WaitUntilReady(); - Endpoint_ClearIN(); - } } static void V2Protocol_Command_ChipErase(void) @@ -377,7 +396,7 @@ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command) Endpoint_Write_Byte(V2Command); Endpoint_Write_Byte(STATUS_CMD_OK); - Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte]); + Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte - 1]); Endpoint_Write_Byte(STATUS_CMD_OK); Endpoint_ClearIN(); }