X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/664a2921816069483604f5e05a2a02b6ddf8727a..57fe6b4fb97668eb15c4fa56095c0abd746d6c99:/Bootloaders/CDC/BootloaderCDC.c diff --git a/Bootloaders/CDC/BootloaderCDC.c b/Bootloaders/CDC/BootloaderCDC.c index 925385d8c..9f7878617 100644 --- a/Bootloaders/CDC/BootloaderCDC.c +++ b/Bootloaders/CDC/BootloaderCDC.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -54,8 +54,8 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600, uint32_t CurrAddress; /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run - * via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application - * jumped to via an indirect jump to location 0x0000. + * via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite + * loop until the AVR restarts and the application runs. */ bool RunBootloader = true; @@ -69,18 +69,22 @@ int main(void) /* Setup hardware required for the bootloader */ SetupHardware(); + /* Enable global interrupts so that the USB stack can function */ + sei(); + while (RunBootloader) { CDC_Task(); USB_USBTask(); } - /* Reset all configured hardware to their default states for the user app */ - ResetHardware(); + /* 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); - /* Start the user application */ - AppPtr_t AppStartPtr = (AppPtr_t)0x0000; - AppStartPtr(); + for (;;); } /** Configures all hardware required for the bootloader. */ @@ -101,20 +105,6 @@ void SetupHardware(void) USB_Init(); } -/** Resets all configured hardware required for the bootloader back to their original states. */ -void ResetHardware(void) -{ - /* Shut down the USB subsystem */ - USB_ShutDown(); - - /* Relocate the interrupt vector table back to the application section */ - MCUCR = (1 << IVCE); - MCUCR = 0; - - /* Re-enable RWW section */ - boot_rww_enable(); -} - /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready * to relay data to and from the attached USB host. */ @@ -343,7 +333,7 @@ static void WriteNextResponseByte(const uint8_t Response) /* Select the IN endpoint so that the next data byte can be written */ Endpoint_SelectEndpoint(CDC_TX_EPNUM); - /* If IN endpoint full, clear it and wait util ready for the next packet to the host */ + /* If IN endpoint full, clear it and wait until ready for the next packet to the host */ if (!(Endpoint_IsReadWriteAllowed())) { Endpoint_ClearIN();