X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/b1dbd92c32022c2ec1601f6a6e51c5714a69c56c..03ee87b35abdb8b92e8b55ec040fa943f9a6786c:/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c?ds=inline diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c index c1f1a6316..2b733d363 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -159,7 +159,7 @@ void XPROGTarget_EnableTargetPDI(void) /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */ - UBRR1 = (F_CPU / 1000000UL); + UBRR1 = (F_CPU / 500000UL); UCSR1B = (1 << TXEN1); UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1); #else @@ -201,7 +201,7 @@ void XPROGTarget_EnableTargetTPI(void) /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */ - UBRR1 = (F_CPU / 1000000UL); + UBRR1 = (F_CPU / 500000UL); UCSR1B = (1 << TXEN1); UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1); #else @@ -226,6 +226,9 @@ void XPROGTarget_EnableTargetTPI(void) /** Disables the target's PDI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetPDI(void) { + /* Switch to Rx mode to ensure that all pending transmissions are complete */ + XPROGTarget_SetRxMode(); + #if defined(XPROG_VIA_HARDWARE_USART) /* Turn off receiver and transmitter of the USART, clear settings */ UCSR1A |= (1 << TXC1) | (1 << RXC1); @@ -249,6 +252,9 @@ void XPROGTarget_DisableTargetPDI(void) /** Disables the target's TPI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetTPI(void) { + /* Switch to Rx mode to ensure that all pending transmissions are complete */ + XPROGTarget_SetRxMode(); + #if defined(XPROG_VIA_HARDWARE_USART) /* Turn off receiver and transmitter of the USART, clear settings */ UCSR1A |= (1 << TXC1) | (1 << RXC1); @@ -420,7 +426,7 @@ static void XPROGTarget_SetRxMode(void) } /* Wait until DATA line has been pulled up to idle by the target */ - while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK)); + while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining); #endif IsSending = false;