void WDT_IRQHandler(void) { if(Chip_WWDT_GetStatus(LPC_WWDT) & WWDT_WDMOD_WDTOF) { NVIC_SystemReset(); } } void SysTick_Handler(void) { // If we feed Watch dog from here, reset happens 2 or 3 (or more) times // in a row (every time different). //Chip_WWDT_Feed(LPC_WWDT); if ( _g_IAPStarted ){ Chip_GPIO_SetPinToggle(LPC_GPIO, PIN_LED2_RED); } _g_BootloaderTimeout_100ms--; } int main(void) { uint16_t calculatedCRC; volatile unsigned int delay; /* Initialize board and chip */ BoardInitialization(); Reset_Signal(); // LED signals we are in bootloader. LedOn(); USBInit(); #ifndef DEBUG WatchdogInitialize(); #endif SysTick_Config(SystemCoreClock/10); // frequency of SysTick interrupt is 10 Hz (period = 100 ms) // Wait 5 seconds before attempting to start user-application while( _g_BootloaderTimeout_100ms ){ Chip_WWDT_Feed(LPC_WWDT); } .... } /* end main() */ void WatchdogInitialize(void) { #define WD_TIMEOUT_SEC ( 2 ) // Clear WD timeout flag Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF); /* Watchdog config */ Chip_WWDT_Init(LPC_WWDT); // WD clk source - IRC oscilator (12 MHz) // wd_clk_freq = 12 MHz / 4 = 3 MHz // Watchdog timeout set to WD_TIMEOUT_SEC second Chip_WWDT_SetTimeOut( LPC_WWDT, (3000000*WD_TIMEOUT_SEC) ); Chip_WWDT_SetWarning( LPC_WWDT, 0 ); // Don't reset MCU, only generate an interrupt Chip_WWDT_Start(LPC_WWDT); // (sets WD option WDEN) NVIC_ClearPendingIRQ(WDT_IRQn); NVIC_EnableIRQ(WDT_IRQn); } |