From e7d1d1347cd6c220af783972a064d782047e2c56 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Sat, 28 Dec 2013 23:24:23 +0100 Subject: firmware: code clean up, consolidated wait loops to save 4 bytes --- firmware/main.c | 65 ++++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'firmware/main.c') diff --git a/firmware/main.c b/firmware/main.c index 4ceb19e..8394e7e 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -239,7 +239,12 @@ static void initHardware (void) MCUSR=0; WDTCR = 1< 9ms before next usb request - if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); - if (isEvent(EVENT_WRITE_PAGE)) { - _delay_us(2000); // Wait for USB traffic to finish before halting CPU with write- - writeFlashPage(); - } - - LED_MACRO( ((uint8_t*)&idlePolls)[1] ); + idlePolls++; // Try to execute program if bootloader exit condition is met if (AUTO_EXIT_MS&&(idlePolls>AUTO_EXIT_MS*10L)) fireEvent(EVENT_EXECUTE); + LED_MACRO( ((uint8_t*)&idlePolls)[1] ); + + // Wait for USB traffic to finish before a blocking event is executed + // All events will render the MCU unresponsive to USB traffic for a while. + if (events) _delay_ms(2); + if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); + if (isEvent(EVENT_WRITE_PAGE)) writeFlashPage(); + /* main event loop runs as long as no problem is uploaded or existing program is not executed */ } while((!isEvent(EVENT_EXECUTE))||(pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_RESET_OFFSET + 1)==0xff)); + + LED_EXIT(); } - LED_EXIT(); - - #if OSCCAL_RESTORE - OSCCAL=osccal_default; - nop(); // NOP to avoid CPU hickup during oscillator stabilization - #endif - leaveBootloader(); } /* ------------------------------------------------------------------------ */ -- cgit v1.2.3