m b / Mbed 2 deprecated 4180Lab1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wdt.h Source File

wdt.h

00001 #include "mbed.h"
00002 
00003 //----------------------------
00004 //Watchdog class
00005 class Watchdog {
00006 public:
00007 
00008     //Directions on how to use this stuff can be found in the lpc1768 user manual. 
00009     //LPC_WDT is the "Register set", -> is the register, 0x is the hex value to write
00010     //Can also use 0B to write binary, or just base 10 by =
00011     //Chip has multiple clock sources, critical to understand for low power modes. This WDT uses the main system clock
00012 
00013     void kick(float timeToReset) {
00014         LPC_WDT->WDCLKSEL = 0x1;                
00015         uint32_t clk = SystemCoreClock / 16;    
00016         LPC_WDT->WDTC = timeToReset * (float)clk;
00017         LPC_WDT->WDMOD = 0x3;                  
00018         kick();
00019     }
00020     void kick() {
00021         LPC_WDT->WDFEED = 0xAA;
00022         LPC_WDT->WDFEED = 0x55;
00023     }
00024 };
00025 
00026 //--------------------------------------
00027 /*Insert in code
00028 Watchdog wdt; //Create object
00029 
00030 
00031 
00032 byte lockUpCounter = 0; //Simulate a lockup, use a byte because ti consumes less memory
00033 
00034 
00035 if (lockUpCounter > 100){ //Simulated lockup
00036     while(1);
00037     }
00038 lockUpCounter++;
00039 
00040 wdt.kick; //Reset WDT
00041 
00042 //------------------------------------
00043 // Assembly stuff
00044 
00045 //Attach file
00046 //extern "C" int my_asm(int value);
00047 //my_asm(value);
00048 //----------------
00049 //Thisw goes in separate ASM file
00050 
00051 */