reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Model/Application.cpp@10:372c882b5533, 2014-03-02 (annotated)
- Committer:
- wyunreal
- Date:
- Sun Mar 02 18:15:47 2014 +0000
- Revision:
- 10:372c882b5533
- Parent:
- 8:3655e9a98f28
- Child:
- 11:9366140ebe5f
integrating microchip io expander
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wyunreal | 4:a19825caaf41 | 1 | #include "Application.h" |
wyunreal | 4:a19825caaf41 | 2 | |
wyunreal | 7:1fe91b525d9a | 3 | #define WATCH_DOG_TIMER_TRIGGER_TIME 5 //seconds |
wyunreal | 7:1fe91b525d9a | 4 | |
wyunreal | 4:a19825caaf41 | 5 | extern "C" void mbed_reset(); |
wyunreal | 4:a19825caaf41 | 6 | |
wyunreal | 4:a19825caaf41 | 7 | Application::Application() { |
wyunreal | 4:a19825caaf41 | 8 | } |
wyunreal | 4:a19825caaf41 | 9 | |
wyunreal | 7:1fe91b525d9a | 10 | void Application::setup() { |
wyunreal | 7:1fe91b525d9a | 11 | |
wyunreal | 7:1fe91b525d9a | 12 | // WatchDog reset ? |
wyunreal | 7:1fe91b525d9a | 13 | if (WatchDogTimer::systemResetReason() == SYSTEM_RESET_WATCH_DOG) { |
wyunreal | 7:1fe91b525d9a | 14 | handleFaultyResetRecovery(); |
wyunreal | 4:a19825caaf41 | 15 | } |
wyunreal | 7:1fe91b525d9a | 16 | |
wyunreal | 5:df012c2caf40 | 17 | // setup ethernet |
wyunreal | 4:a19825caaf41 | 18 | ethernetService = new EthernetService(); |
wyunreal | 4:a19825caaf41 | 19 | if(!ethernetService->setup()) { |
wyunreal | 4:a19825caaf41 | 20 | applicationReset(); |
wyunreal | 4:a19825caaf41 | 21 | } |
wyunreal | 5:df012c2caf40 | 22 | // set the system time from NTP |
wyunreal | 4:a19825caaf41 | 23 | ethernetService->setRtcTime(); |
wyunreal | 5:df012c2caf40 | 24 | |
wyunreal | 10:372c882b5533 | 25 | // start spi |
wyunreal | 10:372c882b5533 | 26 | spiHandler = new SPI(p5, p6, p7); |
wyunreal | 10:372c882b5533 | 27 | spiHandler->frequency(100000); // 100 khz for slow periperals intialization |
wyunreal | 10:372c882b5533 | 28 | |
wyunreal | 10:372c882b5533 | 29 | // starting the file systems |
wyunreal | 6:b2c4687b421d | 30 | localFileSystem = new LocalFileSystem("local"); |
wyunreal | 10:372c882b5533 | 31 | sdFileSystem = new SDFileSystem(spiHandler, p8, "sd"); |
wyunreal | 10:372c882b5533 | 32 | |
wyunreal | 10:372c882b5533 | 33 | // starting the external actuators control group |
wyunreal | 10:372c882b5533 | 34 | actuatorsController = new ActuatorsController(spiHandler); |
wyunreal | 10:372c882b5533 | 35 | |
wyunreal | 10:372c882b5533 | 36 | spiHandler->frequency(4000000); // 4 Mhz spi normal operation frequency |
wyunreal | 5:df012c2caf40 | 37 | |
wyunreal | 5:df012c2caf40 | 38 | // start the rest api server |
wyunreal | 8:3655e9a98f28 | 39 | restServer = new RestServer(localFileSystem, sdFileSystem); |
wyunreal | 5:df012c2caf40 | 40 | restServer->bind(); |
wyunreal | 7:1fe91b525d9a | 41 | |
wyunreal | 7:1fe91b525d9a | 42 | // enable watchdog timer |
wyunreal | 7:1fe91b525d9a | 43 | watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME); |
wyunreal | 7:1fe91b525d9a | 44 | } |
wyunreal | 7:1fe91b525d9a | 45 | |
wyunreal | 7:1fe91b525d9a | 46 | void Application::handleFaultyResetRecovery() { |
wyunreal | 7:1fe91b525d9a | 47 | |
wyunreal | 4:a19825caaf41 | 48 | } |
wyunreal | 4:a19825caaf41 | 49 | |
wyunreal | 4:a19825caaf41 | 50 | void Application::loop() { |
wyunreal | 4:a19825caaf41 | 51 | |
wyunreal | 4:a19825caaf41 | 52 | } |
wyunreal | 4:a19825caaf41 | 53 | |
wyunreal | 7:1fe91b525d9a | 54 | void Application::run() { |
wyunreal | 7:1fe91b525d9a | 55 | setup(); |
wyunreal | 7:1fe91b525d9a | 56 | while(1) { |
wyunreal | 7:1fe91b525d9a | 57 | loop(); |
wyunreal | 7:1fe91b525d9a | 58 | watchDog->feed(); |
wyunreal | 7:1fe91b525d9a | 59 | ethernetService->poll(); |
wyunreal | 7:1fe91b525d9a | 60 | if (ethernetService->isLinkRestored()) { |
wyunreal | 7:1fe91b525d9a | 61 | // if ethernet link is restored, application needs to be restarted |
wyunreal | 7:1fe91b525d9a | 62 | applicationReset(); |
wyunreal | 7:1fe91b525d9a | 63 | } |
wyunreal | 7:1fe91b525d9a | 64 | watchDog->feed(); |
wyunreal | 7:1fe91b525d9a | 65 | } |
wyunreal | 7:1fe91b525d9a | 66 | } |
wyunreal | 7:1fe91b525d9a | 67 | |
wyunreal | 4:a19825caaf41 | 68 | void Application::applicationReset() { |
wyunreal | 4:a19825caaf41 | 69 | wait(5); |
wyunreal | 4:a19825caaf41 | 70 | mbed_reset(); |
wyunreal | 4:a19825caaf41 | 71 | } |
wyunreal | 4:a19825caaf41 | 72 | |
wyunreal | 4:a19825caaf41 | 73 | Application::~Application() { |
wyunreal | 4:a19825caaf41 | 74 | delete ethernetService; |
wyunreal | 4:a19825caaf41 | 75 | } |