/* * @brief Windowed Watchdog Timer (WWDT) example * * @note * Copyright(C) NXP Semiconductors, 2013 * All rights reserved. * * @par * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * LPC products. This software is supplied "AS IS" without any warranties of * any kind, and NXP Semiconductors and its licensor disclaim any and * all warranties, express or implied, including all implied warranties of * merchantability, fitness for a particular purpose and non-infringement of * intellectual property rights. NXP Semiconductors assumes no responsibility * or liability for the use of the software, conveys no license or rights under any * patent, copyright, mask work right, or any other intellectual property rights in * or to any products. NXP Semiconductors reserves the right to make changes * in the software without notification. NXP Semiconductors also makes no * representation or warranty that such application will be suitable for the * specified use without further testing or modification. * * @par * Permission to use, copy, modify, and distribute this software and its * documentation is hereby granted, under NXP Semiconductors' and its * licensor's relevant copyrights in the software, without fee, provided that it * is used in conjunction with NXP Semiconductors microcontrollers. This * copyright, permission, and disclaimer notice must appear in all copies of * this code. */ #include "board.h" /***************************************************************************** * Private types/enumerations/variables ****************************************************************************/ /***************************************************************************** * Public types/enumerations/variables ****************************************************************************/ /***************************************************************************** * Private functions ****************************************************************************/ /***************************************************************************** * Public functions ****************************************************************************/ /** * @brief watchdog timer Interrupt Handler * @return Nothing * @note Handles watchdog timer warning and timeout events */ void WDT_IRQHandler(void) { uint32_t wdtStatus = Chip_WWDT_GetStatus(LPC_WWDT); Board_LED_Toggle(0); /* The chip will reset before this happens, but if the WDT doesn't have WWDT_WDMOD_WDRESET enabled, this will hit once */ if (wdtStatus & WWDT_WDMOD_WDTOF) { /* A watchdog feed didn't occur prior to window timeout */ Chip_WWDT_UnsetOption(LPC_WWDT, WWDT_WDMOD_WDEN); /* Stop WDT */ Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF); Chip_WWDT_Start(LPC_WWDT); /* Needs restart */ } /* Handle warning interrupt */ if (wdtStatus & WWDT_WDMOD_WDINT) { /* A watchdog feed didn't occur prior to warning timeout */ Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDINT); Chip_WWDT_Feed(LPC_WWDT); } } /** * @brief Application Main entry point * @return Nothing (This will not return) */ int main(void) { uint32_t wdtFreq; SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); /* Enable the WDT oscillator */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_WDTOSC_PD); /* The WDT divides the input frequency into it by 4 */ wdtFreq = Chip_Clock_GetWDTOSCRate() / 4; /* Initialize WWDT (also enables WWDT clock) */ Chip_WWDT_Init(LPC_WWDT); /* Set watchdog feed time constant to approximately 2s Set watchdog warning time to 512 ticks after feed time constant Set watchdog window time to 3s */ Chip_WWDT_SetTimeOut(LPC_WWDT, wdtFreq * 2); Chip_WWDT_SetWarning(LPC_WWDT, 512); Chip_WWDT_SetWindow(LPC_WWDT, wdtFreq * 3); /* Configure WWDT to reset on timeout */ Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET); /* Clear watchdog warning and timeout interrupts */ Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT); /* Power everything up except for ADC, USB and temp sensor on wake up from deep sleep. */ Chip_SYSCTL_SetWakeup(~(SYSCTL_SLPWAKE_IRCOUT_PD | SYSCTL_SLPWAKE_IRC_PD | SYSCTL_SLPWAKE_FLASH_PD | SYSCTL_SLPWAKE_SYSOSC_PD | SYSCTL_SLPWAKE_SYSPLL_PD | SYSCTL_SLPWAKE_WDTOSC_PD)); /* Allow WDT to wake from deep sleep. */ Chip_SYSCTL_EnableERP0PeriphWakeup(SYSCTL_ERP0_WAKEUP_WDTINT); /* Clear and enable watchdog interrupt */ NVIC_ClearPendingIRQ(WWDT_IRQn); NVIC_EnableIRQ(WWDT_IRQn); /* Start watchdog */ Chip_WWDT_Start(LPC_WWDT); /* Sleep until WDT needs servicing */ while (1) { LPC_PWRD_API->power_mode_configure(PMU_DEEP_SLEEP, ~PMU_PD_WDOSC); __WFI(); } return 0; }