reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Diff: Model/Application.cpp
- Revision:
- 7:1fe91b525d9a
- Parent:
- 6:b2c4687b421d
- Child:
- 8:3655e9a98f28
--- 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();