X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9decc2bc595bb15ccf275ae2d3854bb862c92881..022035839e62c52299b7191f6967ac57ccf1bd94:/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c diff --git a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c index d91941307..bccb96c2c 100644 --- a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c @@ -38,14 +38,13 @@ #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) /** Base absolute address for the target's NVM controller */ -uint32_t XPROG_Param_NVMBase = 0x010001C0; +uint32_t XPROG_Param_NVMBase = 0x010001C0; /** Size in bytes of the target's EEPROM page */ uint32_t XPROG_Param_EEPageSize; /** Currently selected XPROG programming protocol */ -uint8_t XPROG_SelectedProtocol; - +uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI; /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI * programming. @@ -113,23 +112,32 @@ static void XPROGProtocol_EnterXPROGMode(void) if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { /* Enable PDI programming mode with the attached target */ - PDITarget_EnableTargetPDI(); + XPROGTarget_EnableTargetPDI(); /* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */ - PDITarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); - PDITarget_SendByte(PDI_RESET_KEY); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(PDI_RESET_KEY); /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ - PDITarget_SendByte(PDI_CMD_KEY); + XPROGTarget_SendByte(PDI_CMD_KEY); for (uint8_t i = sizeof(PDI_NVMENABLE_KEY); i > 0; i--) - PDITarget_SendByte(PDI_NVMENABLE_KEY[i - 1]); + XPROGTarget_SendByte(PDI_NVMENABLE_KEY[i - 1]); /* Wait until the NVM bus becomes active */ - NVMBusEnabled = PDITarget_WaitWhileNVMBusBusy(); + NVMBusEnabled = XMEGANVM_WaitWhileNVMBusBusy(); } else { - // TODO + /* Enable TPI programming mode with the attached target */ + XPROGTarget_EnableTargetTPI(); + + /* 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--) + XPROGTarget_SendByte(TPI_NVMENABLE_KEY[i - 1]); + + /* Wait until the NVM bus becomes active */ + NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy(); } Endpoint_Write_Byte(CMD_XPROG); @@ -149,14 +157,18 @@ static void XPROGProtocol_LeaveXPROGMode(void) if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { /* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */ - PDITarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); - PDITarget_SendByte(0x00); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(0x00); - PDITarget_DisableTargetPDI(); + XPROGTarget_DisableTargetPDI(); } else { - // TODO + /* Clear the NVMEN bit in the TPI CONTROL register to disable TPI mode */ + XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); + XPROGTarget_SendByte(0x00); + + XPROGTarget_DisableTargetTPI(); } Endpoint_Write_Byte(CMD_XPROG); @@ -381,7 +393,8 @@ static void XPROGProtocol_ReadCRC(void) } else { - // TODO + /* TPI does not support memory CRC */ + ReturnStatus = XPRG_ERR_FAILED; } Endpoint_Write_Byte(CMD_XPROG);