Luth Haroon / SD_modified
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers watchdog.cpp Source File

watchdog.cpp

00001 #include "mbed.h"
00002 
00003 // Loads watchdog timer with TC value
00004 void feed() {
00005     LPC_WWDT->FEED = 0xAA;
00006     LPC_WWDT->FEED = 0x55;
00007 }
00008 
00009 // Ref. UM10462.pdf chapter 17
00010 void WDTInit() {
00011     // Power on interface...
00012     LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 15);
00013 
00014     // Power on watchdog oscillator
00015     LPC_SYSCON->PDRUNCFG &= 0x3F;
00016 
00017     // Select watchdog oscillator for WWDT clock source
00018     LPC_WWDT->CLKSEL = 0x1;
00019 
00020     uint32_t clk = SystemCoreClock / 16;
00021     LPC_WWDT->TC = 0xfff;//10 * clk;
00022 
00023     // Enable WWDT. The timer will not begin until the
00024     // proper feed sequence is loaded.
00025     LPC_WWDT->MOD = 0x3;
00026 
00027     feed();
00028 #if 0
00029     printf("CLKSEL->0x%x TC->0x%x MOD->0x%x FEED->0x%x\n", LPC_WWDT->CLKSEL, LPC_WWDT->TC, LPC_WWDT->MOD, LPC_WWDT->FEED);
00030     printf("clk->%d\n", clk);
00031 #endif
00032 }