diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/bootloaderconfig.h | 14 | ||||
-rw-r--r-- | firmware/main.c | 63 |
2 files changed, 39 insertions, 38 deletions
diff --git a/firmware/bootloaderconfig.h b/firmware/bootloaderconfig.h index 479d268..a5b1f7d 100644 --- a/firmware/bootloaderconfig.h +++ b/firmware/bootloaderconfig.h @@ -208,6 +208,7 @@ these macros are defined, the boot loader uses them. * (This will wait for an USB SE0 reset from the host) * AUTO_EXIT_MS The bootloader will exit after this delay if no USB communication * from the host tool was received. + * Set to 0 to disable * * All values are approx. in milliseconds */ @@ -258,10 +259,15 @@ these macros are defined, the boot loader uses them. #define LED_PORT PORTB #define LED_PIN PB1 -#define LED_INIT(x) LED_PORT &=~_BV(LED_PIN); -#define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN); -#define LED_MACRO(x) if ( x & 0xd ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);} - +#if LED_PRESENT + #define LED_INIT(x) LED_PORT &=~_BV(LED_PIN); + #define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN); + #define LED_MACRO(x) if ( x & 0xd ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);} +#else + #define LED_INIT(x) + #define LED_EXIT(x) + #define LED_MACRO(x) +#endif /* ------------------------------------------------------------------------- */ #endif /* __bootloader_h_included__ */ diff --git a/firmware/main.c b/firmware/main.c index 0723c3e..88753a8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -300,40 +300,37 @@ int main(void) { #if AUTO_EXIT_NO_USB_MS ((uint8_t*)&idlePolls)[1]=((AUTO_EXIT_MS-AUTO_EXIT_NO_USB_MS) * 10UL)>>8; // write only high byte to save 6 bytes #endif - - if (bootLoaderStartCondition()) { +// if (bootLoaderStartCondition()||(pgm_read_byte(BOOTLOADER_ADDRESS - TINYVECTOR_RESET_OFFSET + 1)==0xff)) { + if (bootLoaderStartCondition()) { + + initHardware(); + LED_INIT(); - initHardware(); - -# if LED_PRESENT - LED_INIT(); -# endif - do { - clearEvents(); - usbPoll(); - _delay_us(100); - - // these next two freeze the chip for ~ 4.5ms, breaking usb protocol - // and usually both of these will activate in the same loop, so host - // needs to wait > 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(); - } - - #if LED_PRESENT - LED_MACRO( ((uint8_t*)&idlePolls)[1] ) - #endif + do { + clearEvents(); + usbPoll(); - idlePolls++; - // Try to execute program if bootloader exit condition is met - if (!bootLoaderCondition()) fireEvent(EVENT_EXECUTE); - - /* 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)); - } + _delay_us(100); + + // these next two freeze the chip for ~ 4.5ms, breaking usb protocol + // and usually both of these will activate in the same loop, so host + // needs to wait > 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*10)) fireEvent(EVENT_EXECUTE); + + /* 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)); + } // set clock prescaler to desired clock speed (changing from clkdiv8, or no division, depending on fuses) #if LOW_POWER_MODE @@ -346,9 +343,7 @@ int main(void) { #endif #endif - #if LED_PRESENT - LED_EXIT(); - #endif + LED_EXIT(); #if OSCCAL_RESTORE OSCCAL=osccal_default; |