X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a7880ac1cdbfe8ddaf957173bc08f334aad8bca7..79efd8c79e723adb3392367ae62356c5c3a835d0:/Projects/AVRISP/Lib/PDIProtocol.c diff --git a/Projects/AVRISP/Lib/PDIProtocol.c b/Projects/AVRISP/Lib/PDIProtocol.c index 46d6dd417..aa03fc494 100644 --- a/Projects/AVRISP/Lib/PDIProtocol.c +++ b/Projects/AVRISP/Lib/PDIProtocol.c @@ -162,7 +162,7 @@ static void PDIProtocol_Erase(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - uint8_t EraseCommand; + uint8_t EraseCommand = NVM_CMD_NOOP; if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_CHIP) EraseCommand = NVM_CMD_CHIPERASE; @@ -198,6 +198,7 @@ static void PDIProtocol_WriteMemory(void) struct { uint8_t MemoryType; + uint8_t PageMode; uint32_t Address; uint16_t Length; uint8_t ProgData[256]; @@ -211,11 +212,70 @@ static void PDIProtocol_WriteMemory(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); + + + uint8_t WriteCommand = NVM_CMD_NOOP; + uint8_t WriteBuffCommand = NVM_CMD_NOOP; + uint8_t EraseBuffCommand = NVM_CMD_NOOP; + bool PagedMemory = false; - // TODO: Send program command here via PDI protocol + if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_APPL) + { + WriteCommand = NVM_CMD_ERASEWRITEFLASH; + WriteBuffCommand = NVM_CMD_LOADFLASHPAGEBUFF; + EraseBuffCommand = NVM_CMD_ERASEFLASHPAGEBUFF; + PagedMemory = true; + } + else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_BOOT) + { + WriteCommand = NVM_CMD_ERASEWRITEFLASH; + WriteBuffCommand = NVM_CMD_LOADFLASHPAGEBUFF; + EraseBuffCommand = NVM_CMD_ERASEFLASHPAGEBUFF; + PagedMemory = true; + } + else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_EEPROM) + { + WriteCommand = NVM_CMD_ERASEWRITEEEPROMPAGE; + WriteBuffCommand = NVM_CMD_LOADEEPROMPAGEBUFF; + EraseBuffCommand = NVM_CMD_ERASEEEPROMPAGEBUFF; + PagedMemory = true; + } + else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_USERSIG) + { + WriteCommand = NVM_CMD_WRITEUSERSIG; + WriteBuffCommand = NVM_CMD_LOADFLASHPAGEBUFF; + EraseBuffCommand = NVM_CMD_ERASEFLASHPAGEBUFF; + PagedMemory = true; + } + else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_FUSE) + { + WriteCommand = NVM_CMD_WRITEFUSE; + } + else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_LOCKBITS) + { + WriteCommand = NVM_CMD_WRITELOCK; + } + + if (PagedMemory) + { + if (!(NVMTarget_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, + WriteMemory_XPROG_Params.PageMode, WriteMemory_XPROG_Params.Address, + WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length))) + { + ReturnStatus = XPRG_ERR_TIMEOUT; + } + } + else + { + if (!(NVMTarget_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData, + WriteMemory_XPROG_Params.Length))) + { + ReturnStatus = XPRG_ERR_TIMEOUT; + } + } Endpoint_Write_Byte(CMD_XPROG); - Endpoint_Write_Byte(XPRG_CMD_READ_MEM); + Endpoint_Write_Byte(XPRG_CMD_WRITE_MEM); Endpoint_Write_Byte(ReturnStatus); Endpoint_ClearIN(); } @@ -272,8 +332,8 @@ static void PDIProtocol_ReadCRC(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); + uint8_t CRCCommand = NVM_CMD_NOOP; uint32_t MemoryCRC; - uint8_t CRCCommand; if (ReadCRC_XPROG_Params.CRCType == XPRG_CRC_APP) CRCCommand = NVM_CMD_APPCRC;