Version of Watchdog timer for LPC4088 that uses the Singleton design pattern for easy access throughout a program.

Fork of WDT4088 by Kevin Braun

Committer:
tbronez
Date:
Sat Jan 23 19:01:31 2016 +0000
Revision:
1:06813ae93fea
Parent:
0:fc62d045ca0c
Revised using Singleton design pattern to ease use throughout a program.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tbronez 1:06813ae93fea 1 // T. Bronez. rev. 2016-01-23
tbronez 1:06813ae93fea 2 // Based on https://developer.mbed.org/users/loopsva/code/WDT4088/
tbronez 1:06813ae93fea 3 // Put into Singleton design pattern for easy use throughout a program
tbronez 1:06813ae93fea 4
loopsva 0:fc62d045ca0c 5 #include "mbed.h"
loopsva 0:fc62d045ca0c 6 #include "Watchdog.h"
loopsva 0:fc62d045ca0c 7
tbronez 1:06813ae93fea 8 // Global static point to singleton instance
tbronez 1:06813ae93fea 9 Watchdog* Watchdog::_pInstance = NULL;
tbronez 1:06813ae93fea 10
tbronez 1:06813ae93fea 11 bool Watchdog::isWatchdogReset() {
tbronez 1:06813ae93fea 12 return ((LPC_WDT->MOD >> 2) & 1);
tbronez 1:06813ae93fea 13 }
tbronez 1:06813ae93fea 14
tbronez 1:06813ae93fea 15 Watchdog::Watchdog() {
tbronez 1:06813ae93fea 16 }
tbronez 1:06813ae93fea 17
tbronez 1:06813ae93fea 18 Watchdog* Watchdog::getInstance() {
tbronez 1:06813ae93fea 19 if(!_pInstance) { _pInstance = new Watchdog(); }
tbronez 1:06813ae93fea 20 return _pInstance;
tbronez 1:06813ae93fea 21 }
tbronez 1:06813ae93fea 22
tbronez 1:06813ae93fea 23 void Watchdog::enable(int WDTseconds) {
loopsva 0:fc62d045ca0c 24 if(WDTseconds < 1) WDTseconds = 1; //minimum watchdog time is 1 sec
loopsva 0:fc62d045ca0c 25 if(WDTseconds > 134) WDTseconds = 134; //maximum watchdog time is 134 sec
loopsva 0:fc62d045ca0c 26 LPC_WDT->TC = 125000 * WDTseconds; //125000 * 8uS = 1.0 second tics
loopsva 0:fc62d045ca0c 27 LPC_WDT->MOD = 0x3; //enable and restart watchdog
tbronez 1:06813ae93fea 28 Watchdog::feed();
loopsva 0:fc62d045ca0c 29 }
loopsva 0:fc62d045ca0c 30
tbronez 1:06813ae93fea 31 void Watchdog::feed() {
tbronez 1:06813ae93fea 32 LPC_WDT->FEED = 0xaa; //put sequence into FEED register
loopsva 0:fc62d045ca0c 33 LPC_WDT->FEED = 0x55;
loopsva 0:fc62d045ca0c 34 }