introduce new feature: BOOTLOADER_LOOPCYCLES_TIMEOUT
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Wed, 11 Sep 2013 19:07:20 +0000 (21:07 +0200)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Wed, 11 Sep 2013 22:00:20 +0000 (22:00 +0000)
This feature must be explicitly defined (Makefile.inc)

When greater than "0", "BOOTLOADER_LOOPCYCLES_TIMEOUT" defines how
many 16bit loopcycles can be cycled, before bootloader times out
and starts user firmware. Of course "BOOTLOADER_CAN_EXIT" must be
enabled.

Even if this value is too small, bootloader  will not exit as
long as bootLoaderConditionSimple() stays true.

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

index 7d173d5..072aa81 100644 (file)
@@ -334,6 +334,19 @@ these macros are defined, the boot loader usees them.
  * as soon as the programming software disconnects.
  */
 
  * as soon as the programming software disconnects.
  */
 
+#ifndef BOOTLOADER_LOOPCYCLES_TIMEOUT
+#      define BOOTLOADER_LOOPCYCLES_TIMEOUT    0
+#endif
+/* 
+ * When greater than "0", "BOOTLOADER_LOOPCYCLES_TIMEOUT"
+ * defines how many 16bit loopcycles can be cycled,
+ * before bootloader times out and starts user
+ * firmware.
+ * Of course "BOOTLOADER_CAN_EXIT" must be enabled.
+ * If value is even too small, bootloader  will not
+ * exit as long as bootLoaderConditionSimple stays on.
+ */
+
 //#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
 //#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 8eb785b..98703f9 100644 (file)
@@ -112,7 +112,18 @@ typedef union longConverter{
 }longConverter_t;
 
 
 }longConverter_t;
 
 
-#if BOOTLOADER_CAN_EXIT
+#if (BOOTLOADER_CAN_EXIT)
+#      if (BOOTLOADER_LOOPCYCLES_TIMEOUT)
+#              if (BOOTLOADER_LOOPCYCLES_TIMEOUT < 256)
+#                      if ((HAVE_UNPRECISEWAIT))
+volatile register uint8_t timeout_remaining __asm__("r2");
+#                      else
+static volatile uint8_t timeout_remaining;
+#                      endif
+#              else
+static volatile uint16_t timeout_remaining;
+#              endif
+#      endif
 #      if ((HAVE_UNPRECISEWAIT))
 /* here we have to assume we need to optimize for every byte */
 #define __REGISTER_stayinloader_initialValue 0xfe
 #      if ((HAVE_UNPRECISEWAIT))
 /* here we have to assume we need to optimize for every byte */
 #define __REGISTER_stayinloader_initialValue 0xfe
@@ -482,7 +493,12 @@ static uchar    replyBuffer[4];
     }else if(rq->bRequest == USBASP_FUNC_DISCONNECT){
 
 #if BOOTLOADER_CAN_EXIT
     }else if(rq->bRequest == USBASP_FUNC_DISCONNECT){
 
 #if BOOTLOADER_CAN_EXIT
+#      if (BOOTLOADER_LOOPCYCLES_TIMEOUT)
+      timeout_remaining = BOOTLOADER_LOOPCYCLES_TIMEOUT;
+      stayinloader         = (0xfe);
+#      else
       stayinloader        &= (0xfe);
       stayinloader        &= (0xfe);
+#      endif
 #endif
     }else{
         /* ignore: others, but could be USBASP_FUNC_CONNECT */
 #endif
     }else{
         /* ignore: others, but could be USBASP_FUNC_CONNECT */
@@ -721,6 +737,10 @@ static void initForUsbConnectivity(void)
 
 int __attribute__((__noreturn__)) main(void)
 {
 
 int __attribute__((__noreturn__)) main(void)
 {
+#if ((BOOTLOADER_LOOPCYCLES_TIMEOUT) && (BOOTLOADER_CAN_EXIT))
+    uint16_t __loopscycles;
+    timeout_remaining = BOOTLOADER_LOOPCYCLES_TIMEOUT;
+#endif
     /* initialize  */
     bootLoaderInit();
     odDebugInit();
     /* initialize  */
     bootLoaderInit();
     odDebugInit();
@@ -745,6 +765,13 @@ int __attribute__((__noreturn__)) main(void)
        MCUCSR = 0;       /* clear all reset flags for next time */
         initForUsbConnectivity();
         do{
        MCUCSR = 0;       /* clear all reset flags for next time */
         initForUsbConnectivity();
         do{
+#if ((BOOTLOADER_LOOPCYCLES_TIMEOUT) && (BOOTLOADER_CAN_EXIT))
+       __loopscycles++;
+       if (!(__loopscycles)) {
+         if(timeout_remaining) timeout_remaining--;
+         else                  stayinloader&=0xf1;
+       }
+#endif
             usbPoll();
 #if BOOTLOADER_CAN_EXIT
 #if USE_EXCESSIVE_ASSEMBLER
             usbPoll();
 #if BOOTLOADER_CAN_EXIT
 #if USE_EXCESSIVE_ASSEMBLER