Enhance USB Interrupt responsibility
[pub/lufa.git] / Bootloaders / DFU / BootloaderDFU.c
index ec8f0fa..ce76abe 100644 (file)
@@ -225,16 +225,6 @@ int main(void)
        GlobalInterruptEnable();
 
        /* Run the USB management task while the bootloader is supposed to be running */
        GlobalInterruptEnable();
 
        /* Run the USB management task while the bootloader is supposed to be running */
-       /*if bit_is_clear(PINB,PB5)     // PB5 is Digital 9 on Arduino Pro Micro
-       {
-               loop_until_bit_is_set(PINB,PB5);
-
-               while ((RunBootloader || WaitForExit) && bit_is_set(PINB,PB5))
-                       USB_USBTask();
-
-               loop_until_bit_is_clear(PINB,PB5);
-       }*/
-
        stayinbootloader = false;
 
        uint16_t i = 0;
        stayinbootloader = false;
 
        uint16_t i = 0;
@@ -244,10 +234,13 @@ int main(void)
 
                if (!stayinbootloader)
                {
 
                if (!stayinbootloader)
                {
-                       _delay_ms(1);
+                       Delay_MS(1);
                        if (i++ > 5000)
                        {
                        if (i++ > 5000)
                        {
-                               break;
+                               if (pgm_read_word_near(0) != 0xFFFF)
+                                       break;
+                               else
+                                       i = 0;
                        }
                }
                else
                        }
                }
                else
@@ -846,7 +839,7 @@ static void ProcessWriteCommand(void)
                        else                                                               // Start via jump
                        {
                                /* Set the flag to terminate the bootloader at next opportunity if a valid application has been loaded */
                        else                                                               // Start via jump
                        {
                                /* Set the flag to terminate the bootloader at next opportunity if a valid application has been loaded */
-                               if (pgm_read_word_near(0) == 0xFFFF)
+                               if (pgm_read_word_near(0) != 0xFFFF)
                                  RunBootloader = false;
                        }
                }
                                  RunBootloader = false;
                        }
                }