System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Sat Feb 07 08:54:51 2015 +0000
Revision:
38:8efacce315ae
Parent:
36:0afc0fc8f86b
Child:
39:ddf38df9699e
Updated with profiles, operating info, etc. Just like the other programs.  Awaiting test in car.

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 lastStat = 0;
pspatel321 38:8efacce315ae 7 startDelay = 0;
pspatel321 38:8efacce315ae 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 38:8efacce315ae 13 void LatchMonitor::delayStart()
pspatel321 38:8efacce315ae 14 {
pspatel321 38:8efacce315ae 15 lastStat = 0;
pspatel321 38:8efacce315ae 16 update();
pspatel321 38:8efacce315ae 17 if (startDelay == 0) return; // Not setup yet
pspatel321 38:8efacce315ae 18
pspatel321 30:91af74a299e1 19 // Power-on reset detected
pspatel321 30:91af74a299e1 20 if (LPC_SC->RSID & 1) {
pspatel321 38:8efacce315ae 21 LPC_SC->RSID = 1; // Clear POR flag
pspatel321 38:8efacce315ae 22 started = false; // Use the blocking startup timer
pspatel321 38:8efacce315ae 23 startup.attach(this, &LatchMonitor::startupDelay, *startDelay);
pspatel321 30:91af74a299e1 24 } else {
pspatel321 38:8efacce315ae 25 started = true; // Not a power-cycle, do not use the timer
pspatel321 30:91af74a299e1 26 }
pspatel321 30:91af74a299e1 27 }
pspatel321 30:91af74a299e1 28
pspatel321 38:8efacce315ae 29 void LatchMonitor::startupDelay()
pspatel321 38:8efacce315ae 30 {
pspatel321 38:8efacce315ae 31 started = true;
pspatel321 30:91af74a299e1 32 }
pspatel321 38:8efacce315ae 33 char LatchMonitor::update()
pspatel321 38:8efacce315ae 34 {
pspatel321 30:91af74a299e1 35 char ret = 0;
pspatel321 30:91af74a299e1 36 ret |= (!okPin << 0); // Mirror the ok pin
pspatel321 30:91af74a299e1 37 ret |= (faultPin << 1); // Copy the fault pin
pspatel321 38:8efacce315ae 38
pspatel321 30:91af74a299e1 39 if (started) {
pspatel321 30:91af74a299e1 40 ret |= !okPin << 2; // Mirror the ok pin when started only
pspatel321 30:91af74a299e1 41 if (!okPin && !faultPin) { // If started && okFault but not caught in hardware
pspatel321 38:8efacce315ae 42 ret |= HARD_FAULT;
pspatel321 30:91af74a299e1 43 }
pspatel321 30:91af74a299e1 44 }
pspatel321 38:8efacce315ae 45 lastStat = ret;
pspatel321 30:91af74a299e1 46 return ret;
pspatel321 30:91af74a299e1 47 }