From 42cfd157936571c70b6ba0be48fbda1ab7b450a1 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Fri, 11 Dec 2009 00:03:10 +0000 Subject: Change over AVRISP project to have both hardware USART and software USART modes for the PDI protocol, when enabled. Fix up PDI initialisation routines. --- Projects/AVRISP/Lib/PDIProtocol.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'Projects/AVRISP/Lib/PDIProtocol.c') diff --git a/Projects/AVRISP/Lib/PDIProtocol.c b/Projects/AVRISP/Lib/PDIProtocol.c index 864d4e9c3..c1e7bf2ee 100644 --- a/Projects/AVRISP/Lib/PDIProtocol.c +++ b/Projects/AVRISP/Lib/PDIProtocol.c @@ -104,18 +104,13 @@ static void PDIProtocol_EnterXPROGMode(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - PDIDATA_LINE_DDR |= PDIDATA_LINE_MASK; - PDICLOCK_LINE_DDR |= PDICLOCK_LINE_MASK; - - /* Must hold DATA line high for at least 90nS to enable PDI interface */ - PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK; - asm volatile ("NOP"::); - asm volatile ("NOP"::); - - /* Toggle CLOCK line 16 times within 100uS of the original 90nS timeout to keep PDI interface enabled */ - for (uint8_t i = 0; i < 16; i++) - TOGGLE_PDI_CLOCK; + /* Enable PDI programming mode with the attached target */ + PDITarget_EnableTargetPDI(); + /* Store the RESET ket into the RESET PDI register to complete the handshake */ + PDITarget_SendByte(PDI_CMD_STCS | PD_RESET_REG); + PDITarget_SendByte(PDI_RESET_KEY); + /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ PDITarget_SendByte(PDI_CMD_KEY); for (uint8_t i = 0; i < sizeof(PDI_NVMENABLE_KEY); i++) @@ -140,14 +135,8 @@ static void PDIProtocol_LeaveXPROGMode(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - /* Set DATA and CLOCK lines to inputs */ - PDIDATA_LINE_DDR &= ~PDIDATA_LINE_MASK; - PDICLOCK_LINE_DDR &= ~PDICLOCK_LINE_MASK; - - /* Tristate DATA and CLOCK lines */ - PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK; - PDICLOCK_LINE_PORT &= ~PDICLOCK_LINE_MASK; - + PDITarget_DisableTargetPDI(); + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_LEAVE_PROGMODE); Endpoint_Write_Byte(XPRG_ERR_OK); -- cgit v1.2.3