From dda3e71306415ec5fd744d0daa2fafeddec99961 Mon Sep 17 00:00:00 2001 From: Stephan Baerwolf Date: Wed, 11 Sep 2013 23:34:33 +0200 Subject: [PATCH] BUGfix: fix race condition between TIMEOUT and HIDDENEXIT Signed-off-by: Stephan Baerwolf --- firmware/main.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 98703f9..c609439 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -493,12 +493,7 @@ static uchar replyBuffer[4]; }else if(rq->bRequest == USBASP_FUNC_DISCONNECT){ #if BOOTLOADER_CAN_EXIT -# if (BOOTLOADER_LOOPCYCLES_TIMEOUT) - timeout_remaining = BOOTLOADER_LOOPCYCLES_TIMEOUT; - stayinloader = (0xfe); -# else stayinloader &= (0xfe); -# endif #endif }else{ /* ignore: others, but could be USBASP_FUNC_CONNECT */ @@ -766,10 +761,14 @@ int __attribute__((__noreturn__)) main(void) initForUsbConnectivity(); do{ #if ((BOOTLOADER_LOOPCYCLES_TIMEOUT) && (BOOTLOADER_CAN_EXIT)) - __loopscycles++; - if (!(__loopscycles)) { - if(timeout_remaining) timeout_remaining--; - else stayinloader&=0xf1; + if (stayinloader & 0x1) { + timeout_remaining = BOOTLOADER_LOOPCYCLES_TIMEOUT; + } else { + __loopscycles++; + if (!(__loopscycles)) { + if(timeout_remaining) timeout_remaining--; + else stayinloader&=0xf1; + } } #endif usbPoll(); -- 2.11.0