X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d4ca7fb44c7d326b96cf391f0275dc323dbe24de..f3d370a7778dc8e374efc3b76e26f8ecefc27e84:/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 b8c435efa..1be159c38 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -37,11 +37,17 @@ #include "XPROGProtocol.h" #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) -/** Base absolute address for the target's NVM controller */ -uint32_t XPROG_Param_NVMBase = 0x010001C0; +/** 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: @@ -118,6 +124,10 @@ static void XPROGProtocol_EnterXPROGMode(void) XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(PDI_RESET_KEY); + /* Lower direction change guard time to 8 USART bits */ + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG); + XPROGTarget_SendByte(0x04); + /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ XPROGTarget_SendByte(PDI_CMD_KEY); for (uint8_t i = sizeof(PDI_NVMENABLE_KEY); i > 0; i--) @@ -131,6 +141,10 @@ static void XPROGProtocol_EnterXPROGMode(void) /* Enable TPI programming mode with the attached target */ XPROGTarget_EnableTargetTPI(); + /* Lower direction change guard time to 8 USART bits */ + XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); + XPROGTarget_SendByte(0x04); + /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ XPROGTarget_SendByte(TPI_CMD_SKEY); for (uint8_t i = sizeof(TPI_NVMENABLE_KEY); i > 0; i--) @@ -222,7 +236,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 +310,25 @@ 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 + Serial_TxByte((uint8_t)WriteMemory_XPROG_Params.Length); + + /* Send write command to the TPI device, indicate timeout if occurred */ + if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData, + WriteMemory_XPROG_Params.Length))) + { + ReturnStatus = XPRG_ERR_TIMEOUT; + } } Endpoint_Write_Byte(CMD_XPROG); @@ -339,13 +362,17 @@ 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 + Serial_TxByte((uint8_t)ReadMemory_XPROG_Params.Length); + + /* 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 +447,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_REG: + XPROG_Param_NVMCMDRegAddr = Endpoint_Read_Byte(); + break; + case XPRG_PARAM_NVMCSR_REG: + XPROG_Param_NVMCSRRegAddr = Endpoint_Read_Byte(); + break; + default: + ReturnStatus = XPRG_ERR_FAILED; + break; + } + Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);