X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/85aaaf84ce14568580a35c31e22062ba529b49fe..9a1560dc050f79fd189838a87ce623e79ff48677:/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c index bd269edd7..e75adbe10 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c @@ -338,6 +338,9 @@ uint8_t XPROGTarget_ReceiveByte(void) } } + if (TimeoutMSRemaining) + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + return UDR1; #else /* Wait until a byte has been received before reading */ @@ -453,22 +456,33 @@ static void XPROGTarget_SetRxMode(void) { BITBANG_PDIDATA_DDR &= ~BITBANG_PDIDATA_MASK; BITBANG_PDIDATA_PORT &= ~BITBANG_PDIDATA_MASK; + + /* Wait until DATA line has been pulled up to idle by the target */ + while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining) + { + /* Manage software timeout */ + if (TIFR0 & (1 << OCF0A)) + { + TIFR0 |= (1 << OCF0A); + TimeoutMSRemaining--; + } + } } else { BITBANG_TPIDATA_DDR &= ~BITBANG_TPIDATA_MASK; - BITBANG_TPIDATA_PORT &= ~BITBANG_TPIDATA_MASK; - } - - /* Wait until DATA line has been pulled up to idle by the target */ - while (!(BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK) && TimeoutMSRemaining) - { - /* Manage software timeout */ - if (TIFR0 & (1 << OCF0A)) + BITBANG_TPIDATA_PORT &= ~BITBANG_TPIDATA_MASK; + + /* Wait until DATA line has been pulled up to idle by the target */ + while (!(BITBANG_TPIDATA_PIN & BITBANG_TPIDATA_MASK) && TimeoutMSRemaining) { - TIFR0 |= (1 << OCF0A); - TimeoutMSRemaining--; - } + /* Manage software timeout */ + if (TIFR0 & (1 << OCF0A)) + { + TIFR0 |= (1 << OCF0A); + TimeoutMSRemaining--; + } + } } #endif