introduce new feature: BOOTLOADER_ADDITIONALMSDEVICEWAIT
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Mon, 16 Dec 2013 11:36:54 +0000 (12:36 +0100)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Mon, 16 Dec 2013 12:38:41 +0000 (12:38 +0000)
Configure "BOOTLOADER_ADDITIONALMSDEVICEWAIT" to the number of
milliseconds the bootloader should delay its bootup, so
the pullups have time to charge up.

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
firmware/bootloaderconfig.h
firmware/main.c

index 29a5a74..8c969bd 100644 (file)
@@ -399,6 +399,18 @@ these macros are defined, the boot loader usees them.
  * can be soldered otherwise.
  */
 
+#ifdef CONFIG_NO__BOOTLOADER_ADDITIONALDEVICEWAIT
+#      define HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT 0
+#else
+#      define HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT 50
+#endif
+/* 
+ * When enabling "HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT", then
+ * the bootloader will alway delay its bootup by the configured
+ * number of milliseconds.
+ * This gives the pullups additional time to charge up.
+ */
+
 //#define SIGNATURE_BYTES             0x1e, 0x93, 0x07, 0     /* ATMega8 */
 /* This macro defines the signature bytes returned by the emulated USBasp to
  * the programmer software. They should match the actual device at least in
index 9558089..c378d0f 100644 (file)
@@ -691,32 +691,35 @@ uchar   i;
 
 /* ------------------------------------------------------------------------ */
 
-static void initForUsbConnectivity(void)
-{
-#if HAVE_UNPRECISEWAIT
-    /* (0.25s*F_CPU)/(4 cycles per loop) ~ (65536*waitloopcnt)
-     * F_CPU/(16*65536) ~ waitloopcnt
-     * F_CPU / 1048576 ~ waitloopcnt
-     */
-    uint8_t waitloopcnt = 1 + (F_CPU/1048576);
-#endif
-    usbInit();
-    /* enforce USB re-enumerate: */
-    usbDeviceDisconnect();  /* do this while interrupts are disabled */
 #if HAVE_UNPRECISEWAIT
+static void _mywait(uint8_t waitloopcnt) {
     asm volatile (
       /*we really don't care what value Z has...
        * ...if we loop 65536/F_CPU more or less...
        * ...unimportant - just save some opcodes
        */
-"initForUsbConnectivity_sleeploop:                     \n\t"
+"_mywait_sleeploop:                                    \n\t"
       "sbiw    r30,    1                               \n\t"
       "sbci    %0,     0                               \n\t"
-      "brne    initForUsbConnectivity_sleeploop        \n\t"
+      "brne    _mywait_sleeploop                       \n\t"
       : "+d" (waitloopcnt)
       :
       : "r30","r31"
     );
+}
+#endif
+
+static void initForUsbConnectivity(void)
+{
+    usbInit();
+    /* enforce USB re-enumerate: */
+    usbDeviceDisconnect();  /* do this while interrupts are disabled */
+#if HAVE_UNPRECISEWAIT
+    /* (0.25s*F_CPU)/(4 cycles per loop) ~ (65536*waitloopcnt)
+     * F_CPU/(16*65536) ~ waitloopcnt
+     * F_CPU / 1048576 ~ waitloopcnt
+     */
+    _mywait(1 + (F_CPU/1048576));
 #else
     _delay_ms(260);         /* fake USB disconnect for > 250 ms */
 #endif
@@ -738,6 +741,13 @@ int __attribute__((__noreturn__)) main(void)
     GICR = (1 << IVCE);  /* enable change of interrupt vectors */
     GICR = (1 << IVSEL); /* move interrupts to boot flash section */
 #endif
+#if (HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT>0)    
+#      if HAVE_UNPRECISEWAIT
+    _mywait(1+((HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT*F_CPU)/262144000));
+#      else
+    _delay_ms(HAVE_BOOTLOADER_ADDITIONALMSDEVICEWAIT);
+#      endif
+#endif
     if(bootLoaderCondition()){
 #if (BOOTLOADER_CAN_EXIT)
 #      if (USE_EXCESSIVE_ASSEMBLER)