#include "XPROGProtocol.h"\r
\r
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)\r
-/** Base absolute address for the target's NVM controller */\r
+/** Base absolute address for the target's NVM controller for PDI programming */\r
uint32_t XPROG_Param_NVMBase = 0x010001C0;\r
\r
/** Size in bytes of the target's EEPROM page */\r
-uint32_t XPROG_Param_EEPageSize;\r
+uint16_t XPROG_Param_EEPageSize;\r
+\r
+/** Address of the TPI device's NVMCMD register for TPI programming */\r
+uint8_t XPROG_Param_NVMCMDRegAddr;\r
+\r
+/** Address of the TPI device's NVMCSR register for TPI programming */\r
+uint8_t XPROG_Param_NVMCSRRegAddr;\r
\r
/** Currently selected XPROG programming protocol */\r
uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI;\r
}\r
else\r
{\r
- // TODO\r
+ /* Erase the target memory, indicate timeout if ocurred */\r
+ if (!(TINYNVM_EraseMemory()))\r
+ ReturnStatus = XPRG_ERR_TIMEOUT;\r
}\r
\r
Endpoint_Write_Byte(CMD_XPROG);\r
}\r
\r
/* Send the appropriate memory write commands to the device, indicate timeout if occurred */\r
- if ((PagedMemory && !XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, \r
+ if ((PagedMemory && !(XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, \r
WriteMemory_XPROG_Params.PageMode, WriteMemory_XPROG_Params.Address,\r
- WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length)) ||\r
- (!PagedMemory && !XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address,\r
- WriteMemory_XPROG_Params.ProgData)))\r
+ WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length))) ||\r
+ (!PagedMemory && !(XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address,\r
+ WriteMemory_XPROG_Params.ProgData[0]))))\r
{\r
ReturnStatus = XPRG_ERR_TIMEOUT;\r
}\r
}\r
else\r
{\r
- // TODO\r
+ /* Send write command to the TPI device, indicate timeout if occurred */\r
+ if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData[0])))\r
+ ReturnStatus = XPRG_ERR_TIMEOUT;\r
}\r
\r
Endpoint_Write_Byte(CMD_XPROG);\r
\r
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
{\r
- /* Read the target's memory, indicate timeout if occurred */\r
+ /* Read the PDI target's memory, indicate timeout if occurred */\r
if (!(XMEGANVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))\r
ReturnStatus = XPRG_ERR_TIMEOUT;\r
}\r
else\r
{\r
- // TODO\r
+ /* Read the TPI target's memory, indicate timeout if occurred */\r
+ if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))\r
+ ReturnStatus = XPRG_ERR_TIMEOUT;\r
}\r
\r
Endpoint_Write_Byte(CMD_XPROG);\r
case XPRG_PARAM_EEPPAGESIZE:\r
XPROG_Param_EEPageSize = Endpoint_Read_Word_BE();\r
break;\r
- case XPRG_PARAM_UNDOC_1:\r
- case XPRG_PARAM_UNDOC_2:\r
- break; // Undocumented TPI parameter, just accept and discard\r
+ case XPRG_PARAM_NVMCMD:\r
+ XPROG_Param_NVMCMDRegAddr = Endpoint_Read_Byte();\r
+ break;\r
+ case XPRG_PARAM_NVMCSR:\r
+ XPROG_Param_NVMCSRRegAddr = Endpoint_Read_Byte();\r
+ break;\r
default:\r
ReturnStatus = XPRG_ERR_FAILED;\r
break;\r