\r
#if defined(ENABLE_XPROG_PROTOCOL)\r
\r
+#warning PDI Programming Protocol support is incomplete and not currently suitable for use.\r
+\r
/** \file\r
*\r
* PDI Protocol handler, to process V2 Protocol wrapped PDI commands used in Atmel programmer devices.\r
Endpoint_ClearIN(); \r
}\r
\r
+/** Handler for the CMD_XPROG command, which wraps up XPROG commands in a V2 wrapper which need to be\r
+ * removed and processed so that the underlying XPROG command can be handled.\r
+ */\r
void PDIProtocol_XPROG_Command(void)\r
{\r
uint8_t XPROGCommand = Endpoint_Read_Byte();\r
PDIProtocol_LeaveXPROGMode();\r
break;\r
case XPRG_CMD_ERASE:\r
- PDIProtocol_EraseChip();\r
+ PDIProtocol_Erase();\r
break;\r
case XPRG_CMD_WRITE_MEM:\r
PDIProtocol_WriteMemory();\r
}\r
}\r
\r
+/** Handler for the XPROG ENTER_PROGMODE command to establish a PDI connection with the attached device. */\r
static void PDIProtocol_EnterXPROGMode(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r
PDIDATA_LINE_DDR |= PDIDATA_LINE_MASK;\r
PDICLOCK_LINE_DDR |= PDICLOCK_LINE_MASK;\r
\r
+ /* Must hold DATA line high for at least 90nS to enable PDI interface */\r
PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;\r
-\r
_delay_us(1);\r
\r
+ /* Toggle CLOCK line 16 times within 100uS of the original 90nS timeout to keep PDI interface enabled */\r
for (uint8_t i = 0; i < 16; i++)\r
- {\r
- PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
- PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
- }\r
- \r
- static const uint8_t NVMKey[8] = {0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF};\r
+ TOGGLE_PDI_CLOCK;\r
\r
+ /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
PDITarget_SendByte(PDI_CMD_KEY); \r
for (uint8_t i = 0; i < 8; i++)\r
- PDITarget_SendByte(NVMKey[i]);\r
+ PDITarget_SendByte(PDI_NVMENABLE_KEY[i]);\r
\r
+ /* Read out the STATUS register to check that NVM access was successfully enabled */\r
PDITarget_SendByte(PDI_CMD_LDCS | PD_STATUS_REG); \r
if (!(PDITarget_ReceiveByte() & PDI_STATUS_NVM))\r
ReturnStatus = XPRG_ERR_FAILED;\r
Endpoint_ClearIN();\r
}\r
\r
+/** Handler for the XPROG LEAVE_PROGMODE command to terminate the PDI programming connection with\r
+ * the attached device.\r
+ */\r
static void PDIProtocol_LeaveXPROGMode(void)\r
{\r
Endpoint_ClearOUT();\r
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
\r
+ /* Set DATA and CLOCK lines to inputs */\r
PDIDATA_LINE_DDR &= ~PDIDATA_LINE_MASK;\r
PDICLOCK_LINE_DDR &= ~PDICLOCK_LINE_MASK;\r
-\r
+ \r
+ /* Tristate DATA and CLOCK lines */\r
PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;\r
PDICLOCK_LINE_PORT &= ~PDICLOCK_LINE_MASK;\r
\r
Endpoint_ClearIN();\r
}\r
\r
-static void PDIProtocol_EraseChip(void)\r
+/** Handler for the XPRG ERASE command to erase a specific memory address space in the attached device. */\r
+static void PDIProtocol_Erase(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r
\r
Endpoint_ClearIN(); \r
}\r
\r
+/** Handler for the XPROG WRITE_MEMORY command to write to a specific memory space within the attached device. */\r
static void PDIProtocol_WriteMemory(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r
Endpoint_ClearIN();\r
}\r
\r
+/** Handler for the XPROG READ_MEMORY command to read data from a specific address space within the\r
+ * attached device.\r
+ */\r
static void PDIProtocol_ReadMemory(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r
Endpoint_Write_Byte(CMD_XPROG);\r
Endpoint_Write_Byte(XPRG_CMD_READ_MEM);\r
Endpoint_Write_Byte(ReturnStatus);\r
-\r
- // START TEMP\r
- uint8_t ProgData[256];\r
- for (uint16_t i = 0; i < ReadMemory_XPROG_Params.Length; i++)\r
- ProgData[i] = i;\r
- Endpoint_Write_Stream_LE(ProgData, ReadMemory_XPROG_Params.Length);\r
-\r
- if (!Endpoint_IsReadWriteAllowed())\r
- {\r
- Endpoint_ClearIN(); \r
- while(!(Endpoint_IsReadWriteAllowed()));\r
- }\r
- // END TEMP\r
\r
Endpoint_ClearIN();\r
}\r
\r
+/** Handler for the XPROG CRC command to read a specific memory space's CRC value for comparison between the\r
+ * attached device's memory and a data set on the host.\r
+ */\r
static void PDIProtocol_ReadCRC(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r
Endpoint_ClearIN(); \r
}\r
\r
+/** Handler for the XPROG SET_PARAM command to set a PDI parameter for use when communicating with the\r
+ * attached device.\r
+ */\r
static void PDIProtocol_SetParam(void)\r
{\r
uint8_t ReturnStatus = XPRG_ERR_OK;\r