Standardized the naming scheme given to configuration descriptor sub-elements in...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XPROGProtocol.c
index a6a5767..07dce50 100644 (file)
@@ -119,14 +119,14 @@ static void XPROGProtocol_EnterXPROGMode(void)
        {\r
                /* Enable PDI programming mode with the attached target */\r
                XPROGTarget_EnableTargetPDI();\r
-               \r
+\r
                /* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */\r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);     \r
                XPROGTarget_SendByte(PDI_RESET_KEY);\r
 \r
-               /* Lower direction change guard time to 8 USART bits */\r
+               /* Lower direction change guard time to 0 USART bits */\r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG);      \r
-               XPROGTarget_SendByte(0x04);\r
+               XPROGTarget_SendByte(0x07);\r
 \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(PDI_CMD_KEY);      \r
@@ -141,9 +141,9 @@ static void XPROGProtocol_EnterXPROGMode(void)
                /* Enable TPI programming mode with the attached target */\r
                XPROGTarget_EnableTargetTPI();\r
                \r
-               /* Lower direction change guard time to 8 USART bits */\r
+               /* Lower direction change guard time to 0 USART bits */\r
                XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG);\r
-               XPROGTarget_SendByte(0x04);\r
+               XPROGTarget_SendByte(0x07);\r
                \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(TPI_CMD_SKEY);     \r
@@ -170,6 +170,8 @@ static void XPROGProtocol_LeaveXPROGMode(void)
        \r
        if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
        {\r
+               XMEGANVM_WaitWhileNVMBusBusy();\r
+\r
                /* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */\r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);     \r
                XPROGTarget_SendByte(0x00);\r
@@ -178,6 +180,8 @@ static void XPROGProtocol_LeaveXPROGMode(void)
        }\r
        else\r
        {\r
+               TINYNVM_WaitWhileNVMBusBusy();\r
+\r
                /* Clear the NVMEN bit in the TPI CONTROL register to disable TPI mode */\r
                XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG);     \r
                XPROGTarget_SendByte(0x00);\r