summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåvard Espeland <gus@ping.uio.no>2011-08-27 20:46:15 +0200
committerHåvard Espeland <gus@ping.uio.no>2011-08-27 20:46:15 +0200
commit89fdad6ba6ca5a2093e71861913415252f585bb0 (patch)
tree401d7a2ca2247dc6c846eb83be7f9a16c6eb4848
parent15e2e2160a108a3324a5640dbdf4a6b19a72060c (diff)
downloadat90usb-bootloader-89fdad6ba6ca5a2093e71861913415252f585bb0.tar.gz
at90usb-bootloader-89fdad6ba6ca5a2093e71861913415252f585bb0.tar.bz2
at90usb-bootloader-89fdad6ba6ca5a2093e71861913415252f585bb0.tar.xz
at90usb-bootloader-89fdad6ba6ca5a2093e71861913415252f585bb0.zip
Jump from bootloader to main program if not used within 10s
-rw-r--r--BootloaderCDC.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/BootloaderCDC.c b/BootloaderCDC.c
index 0d7a529..64ef61c 100644
--- a/BootloaderCDC.c
+++ b/BootloaderCDC.c
@@ -56,6 +56,13 @@ uint32_t CurrAddress;
*/
bool RunBootloader = true;
+volatile uint32_t time_since_boot = 0;
+bool command_sent = false;
+
+ISR(TIMER0_OVF_vect)
+{
+ ++time_since_boot;
+}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
* runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
@@ -63,33 +70,34 @@ bool RunBootloader = true;
*/
int main(void)
{
- /* Check if we should run the bootloader. */
- DDRD &= ~(1 << PD7);
- RunBootloader = !(PIND & (1 << PD7));
-
- if (!RunBootloader)
- {
- cli();
- __asm("jmp 0x0000");
- }
-
/* Setup hardware required for the bootloader */
SetupHardware();
/* Enable global interrupts so that the USB stack can function */
sei();
+ /* Timer init */
+ TCCR0B = 1 << CS02 | 1 << CS00; // prescaler = / 1024, i.e. 15625 Hz
+ TCCR0A = 0; // 8-bit normal mode
+ TIMSK0 = 1 << TOIE0; // Enable Timer0
+ TIFR0 = 1 << TOV0; // Clear TOV0 / clear
+
while (RunBootloader)
{
CDC_Task();
USB_USBTask();
+
+ /* Jump to main program if not used within 10 seconds. */
+ if (time_since_boot >= (uint16_t) (10 * 61) && !command_sent)
+ break;
}
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();
- /* Enable the watchdog and force a timeout to reset the AVR */
- wdt_enable(WDTO_250MS);
+ /* Jump to main program. */
+ cli();
+ __asm("jmp 0x0000");
for (;;);
}
@@ -345,6 +353,8 @@ void CDC_Task(void)
if (!(Endpoint_IsOUTReceived()))
return;
+ command_sent = true;
+
/* Read in the bootloader command (first byte sent from host) */
uint8_t Command = FetchNextCommandByte();