System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Wed Feb 11 23:09:57 2015 +0000
Revision:
39:ddf38df9699e
Parent:
38:8efacce315ae
Updated CAN IDs for datalogging.  Changed profile encoding.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pspatel321 30:91af74a299e1 1 #include "LatchMonitor.h"
pspatel321 30:91af74a299e1 2
pspatel321 38:8efacce315ae 3 LatchMonitor::LatchMonitor(PinName _ok, PinName _fault) : okPin(_ok, PullDown), faultPin(_fault, PullDown)
pspatel321 38:8efacce315ae 4 {
pspatel321 38:8efacce315ae 5 started = false;
pspatel321 38:8efacce315ae 6 startDelay = 0;
pspatel321 38:8efacce315ae 7 }
pspatel321 39:ddf38df9699e 8
pspatel321 38:8efacce315ae 9 void LatchMonitor::setup(float* _startDelay)
pspatel321 38:8efacce315ae 10 {
pspatel321 38:8efacce315ae 11 startDelay = _startDelay;
pspatel321 38:8efacce315ae 12 }
pspatel321 39:ddf38df9699e 13
pspatel321 38:8efacce315ae 14 void LatchMonitor::delayStart()
pspatel321 38:8efacce315ae 15 {
pspatel321 38:8efacce315ae 16 if (startDelay == 0) return; // Not setup yet
pspatel321 38:8efacce315ae 17
pspatel321 30:91af74a299e1 18 // Power-on reset detected
pspatel321 30:91af74a299e1 19 if (LPC_SC->RSID & 1) {
pspatel321 38:8efacce315ae 20 LPC_SC->RSID = 1; // Clear POR flag
pspatel321 38:8efacce315ae 21 started = false; // Use the blocking startup timer
pspatel321 38:8efacce315ae 22 startup.attach(this, &LatchMonitor::startupDelay, *startDelay);
pspatel321 30:91af74a299e1 23 } else {
pspatel321 38:8efacce315ae 24 started = true; // Not a power-cycle, do not use the timer
pspatel321 30:91af74a299e1 25 }
pspatel321 30:91af74a299e1 26 }
pspatel321 30:91af74a299e1 27
pspatel321 38:8efacce315ae 28 void LatchMonitor::startupDelay()
pspatel321 38:8efacce315ae 29 {
pspatel321 38:8efacce315ae 30 started = true;
pspatel321 30:91af74a299e1 31 }
pspatel321 38:8efacce315ae 32 char LatchMonitor::update()
pspatel321 38:8efacce315ae 33 {
pspatel321 30:91af74a299e1 34 char ret = 0;
pspatel321 30:91af74a299e1 35 ret |= (!okPin << 0); // Mirror the ok pin
pspatel321 30:91af74a299e1 36 ret |= (faultPin << 1); // Copy the fault pin
pspatel321 38:8efacce315ae 37
pspatel321 30:91af74a299e1 38 if (started) {
pspatel321 30:91af74a299e1 39 ret |= !okPin << 2; // Mirror the ok pin when started only
pspatel321 30:91af74a299e1 40 if (!okPin && !faultPin) { // If started && okFault but not caught in hardware
pspatel321 39:ddf38df9699e 41 //ret |= HARD_FAULT;
pspatel321 30:91af74a299e1 42 }
pspatel321 30:91af74a299e1 43 }
pspatel321 30:91af74a299e1 44 return ret;
pspatel321 30:91af74a299e1 45 }