reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Revision 7:1fe91b525d9a, committed 2014-02-08
- Comitter:
- wyunreal
- Date:
- Sat Feb 08 17:33:41 2014 +0000
- Parent:
- 6:b2c4687b421d
- Child:
- 8:3655e9a98f28
- Commit message:
- add watchdog timer support
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HardwareDrivers/WatchDogTimer/WatchDogTimer.cpp Sat Feb 08 17:33:41 2014 +0000 @@ -0,0 +1,18 @@ +#include "WatchDogTimer.h" + +int WatchDogTimer::systemResetReason() { + return ((LPC_WDT->WDMOD >> 2) & 1) ? SYSTEM_RESET_WATCH_DOG : SYSTEM_RESET_NORMAL; +} + +WatchDogTimer::WatchDogTimer(float seconds) { + LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK + uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 + LPC_WDT->WDTC = seconds * (float)clk; // Load WD Timer Constant with value determined by float s + LPC_WDT->WDMOD = 0x3; // Enabled and Reset + feed(); +} + +void WatchDogTimer::feed() { + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HardwareDrivers/WatchDogTimer/WatchDogTimer.h Sat Feb 08 17:33:41 2014 +0000 @@ -0,0 +1,16 @@ +#ifndef WATCH_DOG_TIMER_H +#define WATCH_DOG_TIMER_H + +#include "mbed.h" + +#define SYSTEM_RESET_NORMAL 1 +#define SYSTEM_RESET_WATCH_DOG 2 + +class WatchDogTimer { +public: + WatchDogTimer(float seconds); + void feed(); + static int systemResetReason(); +}; + +#endif \ No newline at end of file
--- a/Model/Application.cpp Sun Feb 02 16:57:24 2014 +0000 +++ b/Model/Application.cpp Sat Feb 08 17:33:41 2014 +0000 @@ -1,23 +1,19 @@ #include "Application.h" +#define WATCH_DOG_TIMER_TRIGGER_TIME 5 //seconds + extern "C" void mbed_reset(); Application::Application() { } -void Application::run() { - setup(); - while(1) { - loop(); - ethernetService->poll(); - if (ethernetService->isLinkRestored()) { - // if ethernet link is restored, application needs to be restarted - applicationReset(); - } +void Application::setup() { + + // WatchDog reset ? + if (WatchDogTimer::systemResetReason() == SYSTEM_RESET_WATCH_DOG) { + handleFaultyResetRecovery(); } -} - -void Application::setup() { + // setup ethernet ethernetService = new EthernetService(); if(!ethernetService->setup()) { @@ -33,12 +29,33 @@ // start the rest api server restServer = new RestServer(localFileSystem, mscFileSystem); restServer->bind(); + + // enable watchdog timer + watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME); +} + +void Application::handleFaultyResetRecovery() { + } void Application::loop() { } +void Application::run() { + setup(); + while(1) { + loop(); + watchDog->feed(); + ethernetService->poll(); + if (ethernetService->isLinkRestored()) { + // if ethernet link is restored, application needs to be restarted + applicationReset(); + } + watchDog->feed(); + } +} + void Application::applicationReset() { wait(5); mbed_reset();
--- a/Model/Application.h Sun Feb 02 16:57:24 2014 +0000 +++ b/Model/Application.h Sat Feb 08 17:33:41 2014 +0000 @@ -4,9 +4,11 @@ #include "EthernetService.h" #include "RestServer.h" #include "MSCFileSystem.h" +#include "WatchDogTimer.h" class Application { private: + WatchDogTimer* watchDog; EthernetService* ethernetService; RestServer* restServer; FileSystemLike* localFileSystem; @@ -15,6 +17,7 @@ void setup(); void loop(); void applicationReset(); + void handleFaultyResetRecovery(); public: Application(); ~Application();