![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Complete
wdt.h@3:ecfa4fa0b5a7, 2016-01-30 (annotated)
- Committer:
- mikeb
- Date:
- Sat Jan 30 03:22:41 2016 +0000
- Revision:
- 3:ecfa4fa0b5a7
- Parent:
- 0:8f5b2af5e1d5
Complete;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mikeb | 0:8f5b2af5e1d5 | 1 | #include "mbed.h" |
mikeb | 0:8f5b2af5e1d5 | 2 | |
mikeb | 0:8f5b2af5e1d5 | 3 | //---------------------------- |
mikeb | 0:8f5b2af5e1d5 | 4 | //Watchdog class |
mikeb | 0:8f5b2af5e1d5 | 5 | class Watchdog { |
mikeb | 0:8f5b2af5e1d5 | 6 | public: |
mikeb | 0:8f5b2af5e1d5 | 7 | |
mikeb | 0:8f5b2af5e1d5 | 8 | //Directions on how to use this stuff can be found in the lpc1768 user manual. |
mikeb | 0:8f5b2af5e1d5 | 9 | //LPC_WDT is the "Register set", -> is the register, 0x is the hex value to write |
mikeb | 0:8f5b2af5e1d5 | 10 | //Can also use 0B to write binary, or just base 10 by = |
mikeb | 0:8f5b2af5e1d5 | 11 | //Chip has multiple clock sources, critical to understand for low power modes. This WDT uses the main system clock |
mikeb | 0:8f5b2af5e1d5 | 12 | |
mikeb | 0:8f5b2af5e1d5 | 13 | void kick(float timeToReset) { |
mikeb | 0:8f5b2af5e1d5 | 14 | LPC_WDT->WDCLKSEL = 0x1; |
mikeb | 0:8f5b2af5e1d5 | 15 | uint32_t clk = SystemCoreClock / 16; |
mikeb | 0:8f5b2af5e1d5 | 16 | LPC_WDT->WDTC = timeToReset * (float)clk; |
mikeb | 0:8f5b2af5e1d5 | 17 | LPC_WDT->WDMOD = 0x3; |
mikeb | 0:8f5b2af5e1d5 | 18 | kick(); |
mikeb | 0:8f5b2af5e1d5 | 19 | } |
mikeb | 0:8f5b2af5e1d5 | 20 | void kick() { |
mikeb | 0:8f5b2af5e1d5 | 21 | LPC_WDT->WDFEED = 0xAA; |
mikeb | 0:8f5b2af5e1d5 | 22 | LPC_WDT->WDFEED = 0x55; |
mikeb | 0:8f5b2af5e1d5 | 23 | } |
mikeb | 0:8f5b2af5e1d5 | 24 | }; |
mikeb | 0:8f5b2af5e1d5 | 25 | |
mikeb | 0:8f5b2af5e1d5 | 26 | //-------------------------------------- |
mikeb | 0:8f5b2af5e1d5 | 27 | /*Insert in code |
mikeb | 0:8f5b2af5e1d5 | 28 | Watchdog wdt; //Create object |
mikeb | 0:8f5b2af5e1d5 | 29 | |
mikeb | 0:8f5b2af5e1d5 | 30 | |
mikeb | 0:8f5b2af5e1d5 | 31 | |
mikeb | 0:8f5b2af5e1d5 | 32 | byte lockUpCounter = 0; //Simulate a lockup, use a byte because ti consumes less memory |
mikeb | 0:8f5b2af5e1d5 | 33 | |
mikeb | 0:8f5b2af5e1d5 | 34 | |
mikeb | 0:8f5b2af5e1d5 | 35 | if (lockUpCounter > 100){ //Simulated lockup |
mikeb | 0:8f5b2af5e1d5 | 36 | while(1); |
mikeb | 0:8f5b2af5e1d5 | 37 | } |
mikeb | 0:8f5b2af5e1d5 | 38 | lockUpCounter++; |
mikeb | 0:8f5b2af5e1d5 | 39 | |
mikeb | 0:8f5b2af5e1d5 | 40 | wdt.kick; //Reset WDT |
mikeb | 0:8f5b2af5e1d5 | 41 | |
mikeb | 0:8f5b2af5e1d5 | 42 | //------------------------------------ |
mikeb | 0:8f5b2af5e1d5 | 43 | // Assembly stuff |
mikeb | 0:8f5b2af5e1d5 | 44 | |
mikeb | 0:8f5b2af5e1d5 | 45 | //Attach file |
mikeb | 0:8f5b2af5e1d5 | 46 | //extern "C" int my_asm(int value); |
mikeb | 0:8f5b2af5e1d5 | 47 | //my_asm(value); |
mikeb | 0:8f5b2af5e1d5 | 48 | //---------------- |
mikeb | 0:8f5b2af5e1d5 | 49 | //Thisw goes in separate ASM file |
mikeb | 0:8f5b2af5e1d5 | 50 | |
mikeb | 0:8f5b2af5e1d5 | 51 | */ |