Change over AVRISP project to have both hardware USART and software USART modes for...
[pub/USBasp.git] / Projects / AVRISP / Lib / PDIProtocol.c
index 864d4e9..c1e7bf2 100644 (file)
@@ -104,18 +104,13 @@ static void PDIProtocol_EnterXPROGMode(void)
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \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
-       asm volatile ("NOP"::);\r
-       asm volatile ("NOP"::);\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
-         TOGGLE_PDI_CLOCK;\r
+       /* Enable PDI programming mode with the attached target */\r
+       PDITarget_EnableTargetPDI();\r
        \r
+       /* Store the RESET ket into the RESET PDI register to complete the handshake */\r
+       PDITarget_SendByte(PDI_CMD_STCS | PD_RESET_REG);        \r
+       PDITarget_SendByte(PDI_RESET_KEY);\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 < sizeof(PDI_NVMENABLE_KEY); i++)\r
@@ -140,14 +135,8 @@ static void PDIProtocol_LeaveXPROGMode(void)
        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
-       /* Tristate DATA and CLOCK lines */\r
-       PDIDATA_LINE_PORT  &= ~PDIDATA_LINE_MASK;\r
-       PDICLOCK_LINE_PORT &= ~PDICLOCK_LINE_MASK;\r
-       \r
+       PDITarget_DisableTargetPDI();\r
+\r
        Endpoint_Write_Byte(CMD_XPROG);\r
        Endpoint_Write_Byte(XPRG_CMD_LEAVE_PROGMODE);\r
        Endpoint_Write_Byte(XPRG_ERR_OK);\r