System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
36:0afc0fc8f86b
Parent:
30:91af74a299e1
Child:
38:8efacce315ae
--- a/Libs/IMD/IMD.cpp	Wed Jan 07 03:36:43 2015 +0000
+++ b/Libs/IMD/IMD.cpp	Thu Jan 22 07:58:51 2015 +0000
@@ -1,5 +1,6 @@
 #include "IMD.h"
 #include <math.h>
+#include "pinmap.h"
 
 static IMD* instance[4] = { 0 };    // Access member from static frame, one IMD permitted per timer module (4 total IMD objects)
 
@@ -29,42 +30,37 @@
     LPC_TIM3->IR=0x3F;        // Clear interrupt flags
 }
 
-bool cmpPin(LPC_pin p1, LPC_pin p2) {
-    if (p1.gpio_addr == p2.gpio_addr && p1.gpio_num == p2.gpio_num) return true;
-    else return false;
-}
-
-IMD::IMD(LPC_pin _pin) {
+IMD::IMD(PinName _pin) {
     // Setup the timer/pin access variables
-    if (cmpPin(_pin, p1_26)) {          // CAP0.0
+    if (_pin == P1_26) {          // CAP0.0
         timer=0;
         pin=0;
         timerBase=LPC_TIM0;
-    } else if (cmpPin(_pin, p1_27)) {   // CAP0.1
+    } else if (_pin == P1_27) {   // CAP0.1
         timer=0;
         pin=1;
         timerBase=LPC_TIM0;
-    } else if (cmpPin(_pin, p1_18)) {   // CAP1.0
+    } else if (_pin == P1_18) {   // CAP1.0
         timer=1;
         pin=0;
         timerBase=LPC_TIM1;
-    } else if (cmpPin(_pin, p1_19)) {   // CAP1.1
+    } else if (_pin == P1_19) {   // CAP1.1
         timer=1;
         pin=1;
         timerBase=LPC_TIM1;
-    } else if (cmpPin(_pin, p0_4)) {    // CAP2.0
+    } else if (_pin == P0_4) {    // CAP2.0
         timer=2;
         pin=0;
         timerBase=LPC_TIM2;
-    } else if (cmpPin(_pin, p0_5)) {    // CAP2.1
+    } else if (_pin == P0_5) {    // CAP2.1
         timer=2;
         pin=1;
         timerBase=LPC_TIM2;
-    } else if (cmpPin(_pin, p0_23)) {   // CAP3.0
+    } else if (_pin == P0_23) {   // CAP3.0
         timer=3;
         pin=0;
         timerBase=LPC_TIM3;
-    } else if (cmpPin(_pin, p0_24)) {   // CAP3.1
+    } else if (_pin == P0_24) {   // CAP3.1
         timer=3;
         pin=1;
         timerBase=LPC_TIM3;
@@ -97,9 +93,9 @@
         LPC_SC->PCLKSEL1 &= ~(3<<14);
     }
     
-    *(_pin.pinsel_addr)  |= 3 << _pin.selmode_num;     // Set pin as capture pin
-    *(_pin.pinmode_addr) |= 3 << _pin.selmode_num;     // Pull down
-    
+    pin_function(_pin, 3);      // Capture input
+    pin_mode(_pin, PullDown);   // Pull-down
+
     timerBase->TCR=2;       // Stop counter and hold at 0, for configuration
     timerBase->IR=0x3F;     // Clear any interrupt flags
     timerBase->CTCR=0;      // Use pclk, not external pin
@@ -125,7 +121,7 @@
     uint32_t capTime = pin?timerBase->CR1:timerBase->CR0;   // Get the time of the capture event
     timerBase->MR0 = capTime + TIMEOUT_TICKS;               // Move the zero timeout ahead
     
-    // Special case - on first pulse after a timeout or on startup, period cannot be calculated
+    // Special case - on first pulse after a timeout or on startup == Period cannot be calculated
     //    so set startTime such that periodTicks remains unchanged from its zero state (periodTicks=1)
     if (first) {
         first = false;