aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP/Lib/PDIProtocol.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-12-13 12:50:47 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-12-13 12:50:47 +0000
commit307ba254d5ef8bcdd9b9aa1bdb277041e79d6563 (patch)
treed4ee07f7d936e1211477060616bb6d1fd55de200 /Projects/AVRISP/Lib/PDIProtocol.c
parent33a46b243a0f204f3ade095f7b213d9d2598c450 (diff)
downloadlufa-307ba254d5ef8bcdd9b9aa1bdb277041e79d6563.tar.gz
lufa-307ba254d5ef8bcdd9b9aa1bdb277041e79d6563.tar.bz2
lufa-307ba254d5ef8bcdd9b9aa1bdb277041e79d6563.zip
The AVRISP project can now enter PDI mode under both bit-bang and hardware USART connection modes, tested against the XPLAIN board hardware. Still need to complete higher level NVM access code so that the device's memories can be read and written.
Diffstat (limited to 'Projects/AVRISP/Lib/PDIProtocol.c')
-rw-r--r--Projects/AVRISP/Lib/PDIProtocol.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/Projects/AVRISP/Lib/PDIProtocol.c b/Projects/AVRISP/Lib/PDIProtocol.c
index 2107e2b89..776934311 100644
--- a/Projects/AVRISP/Lib/PDIProtocol.c
+++ b/Projects/AVRISP/Lib/PDIProtocol.c
@@ -106,7 +106,7 @@ static void PDIProtocol_EnterXPROGMode(void)
PDITarget_EnableTargetPDI();
/* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */
- PDITarget_SendByte(PDI_CMD_STCS | PD_RESET_REG);
+ PDITarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);
PDITarget_SendByte(PDI_RESET_KEY);
/* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */
@@ -114,20 +114,12 @@ static void PDIProtocol_EnterXPROGMode(void)
for (uint8_t i = sizeof(PDI_NVMENABLE_KEY); i > 0; i--)
PDITarget_SendByte(PDI_NVMENABLE_KEY[i - 1]);
- /* Poll the STATUS register to check to see if NVM access has been enabled */
- uint8_t NVMAttemptsRemaining = 255;
- while (NVMAttemptsRemaining)
- {
- PDITarget_SendByte(PDI_CMD_LDCS | PD_STATUS_REG);
- if (PDITarget_ReceiveByte() & PDI_STATUS_NVM)
- break;
-
- NVMAttemptsRemaining--;
- }
+ /* Wait until the NVM bus becomes active */
+ bool NVMBusEnabled = PDITarget_WaitWhileNVMBusBusy();
Endpoint_Write_Byte(CMD_XPROG);
Endpoint_Write_Byte(XPRG_CMD_ENTER_PROGMODE);
- Endpoint_Write_Byte(NVMAttemptsRemaining ? XPRG_ERR_OK : XPRG_ERR_FAILED);
+ Endpoint_Write_Byte(NVMBusEnabled ? XPRG_ERR_OK : XPRG_ERR_FAILED);
Endpoint_ClearIN();
}
@@ -140,7 +132,7 @@ static void PDIProtocol_LeaveXPROGMode(void)
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
/* Clear the RESET key into the RESET PDI register to allow the XMEGA to run */
- PDITarget_SendByte(PDI_CMD_STCS | PD_RESET_REG);
+ PDITarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);
PDITarget_SendByte(0x00);
PDITarget_DisableTargetPDI();