summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/main.c')
-rw-r--r--firmware/main.c63
1 files changed, 29 insertions, 34 deletions
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;