X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8ecdc2b1441417bf97661a3d3edd17a5afd707bf..7c8f4a716f01f6598234fd60cd53345da4903fde:/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index bccb96c2c..39f82a0df 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -9,13 +9,13 @@ /* Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -37,11 +37,17 @@ #include "XPROGProtocol.h" #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) -/** Base absolute address for the target's NVM controller */ +/** Base absolute address for the target's NVM controller for PDI programming */ uint32_t XPROG_Param_NVMBase = 0x010001C0; /** Size in bytes of the target's EEPROM page */ -uint32_t XPROG_Param_EEPageSize; +uint16_t XPROG_Param_EEPageSize; + +/** Address of the TPI device's NVMCMD register for TPI programming */ +uint8_t XPROG_Param_NVMCMDRegAddr; + +/** Address of the TPI device's NVMCSR register for TPI programming */ +uint8_t XPROG_Param_NVMCSRRegAddr; /** Currently selected XPROG programming protocol */ uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI; @@ -74,7 +80,7 @@ void XPROGProtocol_SetMode(void) void XPROGProtocol_Command(void) { uint8_t XPROGCommand = Endpoint_Read_Byte(); - + switch (XPROGCommand) { case XPRG_CMD_ENTER_PROGMODE: @@ -222,7 +228,9 @@ static void XPROGProtocol_Erase(void) } else { - // TODO + /* Erase the target memory, indicate timeout if ocurred */ + if (!(TINYNVM_EraseMemory())) + ReturnStatus = XPRG_ERR_TIMEOUT; } Endpoint_Write_Byte(CMD_XPROG); @@ -294,18 +302,20 @@ static void XPROGProtocol_WriteMemory(void) } /* Send the appropriate memory write commands to the device, indicate timeout if occurred */ - if ((PagedMemory && !XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, + if ((PagedMemory && !(XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, WriteMemory_XPROG_Params.PageMode, WriteMemory_XPROG_Params.Address, - WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length)) || - (!PagedMemory && !XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address, - WriteMemory_XPROG_Params.ProgData))) + WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length))) || + (!PagedMemory && !(XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address, + WriteMemory_XPROG_Params.ProgData[0])))) { ReturnStatus = XPRG_ERR_TIMEOUT; } } else { - // TODO + /* Send write command to the TPI device, indicate timeout if occurred */ + if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData[0]))) + ReturnStatus = XPRG_ERR_TIMEOUT; } Endpoint_Write_Byte(CMD_XPROG); @@ -339,13 +349,15 @@ static void XPROGProtocol_ReadMemory(void) if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { - /* Read the target's memory, indicate timeout if occurred */ + /* Read the PDI target's memory, indicate timeout if occurred */ if (!(XMEGANVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) ReturnStatus = XPRG_ERR_TIMEOUT; } else { - // TODO + /* Read the TPI target's memory, indicate timeout if occurred */ + if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) + ReturnStatus = XPRG_ERR_TIMEOUT; } Endpoint_Write_Byte(CMD_XPROG); @@ -420,13 +432,25 @@ static void XPROGProtocol_SetParam(void) uint8_t XPROGParam = Endpoint_Read_Byte(); /* Determine which parameter is being set, store the new parameter value */ - if (XPROGParam == XPRG_PARAM_NVMBASE) - XPROG_Param_NVMBase = Endpoint_Read_DWord_BE(); - else if (XPROGParam == XPRG_PARAM_EEPPAGESIZE) - XPROG_Param_EEPageSize = Endpoint_Read_Word_BE(); - else - ReturnStatus = XPRG_ERR_FAILED; - + switch (XPROGParam) + { + case XPRG_PARAM_NVMBASE: + XPROG_Param_NVMBase = Endpoint_Read_DWord_BE(); + break; + case XPRG_PARAM_EEPPAGESIZE: + XPROG_Param_EEPageSize = Endpoint_Read_Word_BE(); + break; + case XPRG_PARAM_NVMCMD: + XPROG_Param_NVMCMDRegAddr = Endpoint_Read_Byte(); + break; + case XPRG_PARAM_NVMCSR: + XPROG_Param_NVMCSRRegAddr = Endpoint_Read_Byte(); + break; + default: + ReturnStatus = XPRG_ERR_FAILED; + break; + } + Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);