]> www.average.org Git - pulsecounter.git/commitdiff
two counters work
authorEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 21:38:47 +0000 (00:38 +0300)
committerEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 21:38:47 +0000 (00:38 +0300)
Hal/Hal.c
Hal/Hal.h
Pulsecounter-Prog.c

index f7b801c4aed7174759f08fc616f26a4ade4f54d9..be668cb02c9f2e7b4fa5c3208e42e1645a22fef7 100644 (file)
--- a/Hal/Hal.c
+++ b/Hal/Hal.c
 #define RED_LED_READ()                    (P1OUT & BIT0)
 #define RED_LED_TOGGLE()                  (P1OUT ^= BIT0)
 
 #define RED_LED_READ()                    (P1OUT & BIT0)
 #define RED_LED_TOGGLE()                  (P1OUT ^= BIT0)
 
-#define BUTTON_CONFIG()             (P1DIR &= ~BIT3, P1REN |= BIT3, P1OUT |= BIT3, P1IES |= BIT3);
-#define BUTTON_ENABLE()             (P1IFG &= ~BIT3, P1IE |= BIT3)
-#define BUTTON_DISABLE()            (P1IE &= ~BIT3, P1IFG &= ~BIT3)
-#define BUTTON_FIRED()              (P1IFG & BIT3)
-#define BUTTON_PRESSED()            (!(P1IN & BIT3))
-#define BUTTON_DEBOUNCE_MSECS       100
+#define GPIO_CONFIG(mask)           (P1DIR &= ~mask, P1REN |= mask, P1OUT |= mask, P1IES |= mask);
+#define GPIO_ENABLE(mask)           (P1IFG &= ~mask, P1IE |= mask)
+#define GPIO_DISABLE(mask)          (P1IE &= ~mask, P1IFG &= ~mask)
+#define GPIO_FIRED(mask)            (P1IFG & mask)
+#define GPIO_LOW(mask)              (!(P1IN & mask))
+#define GPIO_DEBOUNCE_MSECS         100
 
 #define DEBUG1_CONFIG()             (P2DIR |= BIT3)
 #define DEBUG1_ON()                 (P2OUT |= BIT3)
 
 #define DEBUG1_CONFIG()             (P2DIR |= BIT3)
 #define DEBUG1_ON()                 (P2OUT |= BIT3)
 
 #define NUM_HANDLERS 5
 
 
 #define NUM_HANDLERS 5
 
-#define BUTTON_HANDLER_ID      0
+#define EVENT3_HANDLER_ID      0
 #define EVENT4_HANDLER_ID      1
 #define EVENT5_HANDLER_ID      2
 #define TICK_HANDLER_ID        3
 #define DISPATCH_HANDLER_ID    4
 
 #define EVENT4_HANDLER_ID      1
 #define EVENT5_HANDLER_ID      2
 #define TICK_HANDLER_ID        3
 #define DISPATCH_HANDLER_ID    4
 
-static void buttonHandler(uint8_t id);
+static void gpioHandler(uint8_t id);
 static void postEvent(uint8_t handlerId);
 
 static void postEvent(uint8_t handlerId);
 
-static Hal_Handler appButtonHandler;
+static Hal_Handler appGpioHandler;
 static volatile uint16_t handlerEvents = 0;
 static uint16_t clockTick = 0;
 static Hal_Handler handlerTab[NUM_HANDLERS];
 static volatile uint16_t handlerEvents = 0;
 static uint16_t clockTick = 0;
 static Hal_Handler handlerTab[NUM_HANDLERS];
@@ -105,12 +105,17 @@ static Hal_Handler handlerTab[NUM_HANDLERS];
 
 /* -------- APP-HAL INTERFACE -------- */
 
 
 /* -------- APP-HAL INTERFACE -------- */
 
-void Hal_buttonEnable(Hal_Handler handler) {
-    handlerTab[BUTTON_HANDLER_ID] = buttonHandler;
-    appButtonHandler = handler;
-    BUTTON_CONFIG();
-    Hal_delay(100);
-    BUTTON_ENABLE();
+void Hal_gpioEnable(Hal_Handler handler) {
+    uint8_t id;
+    uint16_t mask;
+
+    for (id = 0, mask = BIT3; id < 3; id++, mask <<= 1) {
+        handlerTab[id] = gpioHandler;
+        appGpioHandler = handler;
+        (P1DIR &= ~mask, P1REN |= mask, P1OUT |= mask, P1IES |= mask);
+        Hal_delay(100);
+        (P1IFG &= ~mask, P1IE |= mask);
+    }
 }
 
 void Hal_connected(void) {
 }
 
 void Hal_connected(void) {
@@ -328,12 +333,13 @@ void Em_Hal_watchOn(void) {
 
 /* -------- INTERNAL FUNCTIONS -------- */
 
 
 /* -------- INTERNAL FUNCTIONS -------- */
 
-static void buttonHandler(uint8_t id) {
-    Hal_delay(BUTTON_DEBOUNCE_MSECS);
-    if (BUTTON_PRESSED() && appButtonHandler) {
-        appButtonHandler(id);
-    }
-    BUTTON_ENABLE();
+static void gpioHandler(uint8_t id) {
+    uint16_t mask = BIT3 << id;
+
+    Hal_delay(GPIO_DEBOUNCE_MSECS);
+    if (GPIO_LOW(mask) && appGpioHandler)
+        appGpioHandler(id);
+    GPIO_ENABLE(mask);
 }
 
 static void postEvent(uint8_t handlerId) {
 }
 
 static void postEvent(uint8_t handlerId) {
@@ -350,10 +356,15 @@ static void postEvent(uint8_t handlerId) {
 #ifdef __TI_COMPILER_VERSION__
     #pragma vector=PORT1_VECTOR
 #endif
 #ifdef __TI_COMPILER_VERSION__
     #pragma vector=PORT1_VECTOR
 #endif
-INTERRUPT void buttonIsr(void) {
-    if (BUTTON_FIRED())
-        postEvent(BUTTON_HANDLER_ID);
-    BUTTON_DISABLE();
+INTERRUPT void gpioIsr(void) {
+    uint8_t id;
+    uint16_t mask;
+
+    for (id = 0, mask = BIT3; id < 3; id++, mask <<= 1)
+        if (GPIO_FIRED(mask)) {
+            postEvent(id);
+            GPIO_DISABLE(mask);
+        }
     WAKEUP();
 }
 
     WAKEUP();
 }
 
index aa5f7c2db816c31b6addefbe00e6093449b61527..0d57348ab855a824c58594da29d7cd02dcb5eb84 100644 (file)
--- a/Hal/Hal.h
+++ b/Hal/Hal.h
@@ -47,7 +47,7 @@ typedef void (*Hal_Handler)(uint8_t id);
  *   BUTTON interrupt enabled
  *
  **/
  *   BUTTON interrupt enabled
  *
  **/
-extern void Hal_buttonEnable(Hal_Handler handler);
+extern void Hal_gpioEnable(Hal_Handler handler);
 /**
  * --------- Hal_connected ---------
  *
 /**
  * --------- Hal_connected ---------
  *
index 5b9beab300232c87ff693167fecdb4a040ad3b49..331dbf5366af78b29b9d5f79612c5b24d8132704 100644 (file)
@@ -1,48 +1,61 @@
 #include "Pulsecounter.h"
 #include "Hal.h"
 
 #include "Pulsecounter.h"
 #include "Hal.h"
 
-static void buttonHandler(uint8_t id);
+static void gpioHandler(uint8_t id);
 static void tickHandler(void);
 static bool connected = false;
 static int32_t base4 = 0;
 static void tickHandler(void);
 static bool connected = false;
 static int32_t base4 = 0;
-static int32_t base5 = 1000;
+static int32_t base5 = 0;
 static int32_t event4 = 0;
 static int32_t event5 = 0;
 
 static int32_t event4 = 0;
 static int32_t event5 = 0;
 
-static bool cold = true;
-
 void main() {
     Hal_init();
 void main() {
     Hal_init();
-    Hal_buttonEnable(buttonHandler);
+    Hal_gpioEnable(gpioHandler);
     Pulsecounter_setDeviceName("PULS-CNTR");
     Pulsecounter_start();
     Hal_idleLoop();
 }
 
     Pulsecounter_setDeviceName("PULS-CNTR");
     Pulsecounter_start();
     Hal_idleLoop();
 }
 
-static void buttonHandler(uint8_t id) {
+static void gpioHandler(uint8_t id) {
     uint8_t i;
 
     uint8_t i;
 
-    cold = !cold;
-    if (cold)
+    switch (id) {
+    case 0:
+        Pulsecounter_accept(true);
+            Hal_greenLedOn();
+            Hal_redLedOn();
+            Hal_delay(10);
+            Hal_greenLedOff();
+            Hal_redLedOff();
+        Hal_tickStart(5000, tickHandler);
+        break;
+    case 1:
         event4++;
         event4++;
-    else
-        event5++;
-    if (connected) {
-        if (cold)
+        if (connected)
             Pulsecounter_event4_indicate();
             Pulsecounter_event4_indicate();
-        else
-            Pulsecounter_event5_indicate();
-    }
-    else
-        Pulsecounter_accept(true);
-    for (i = 0; i < 3; i++) {
         Hal_greenLedOn();
         Hal_greenLedOn();
-        Hal_redLedOn();
         Hal_delay(10);
         Hal_greenLedOff();
         Hal_delay(10);
         Hal_greenLedOff();
+        break;
+    case 2:
+        event5++;
+        if (connected)
+            Pulsecounter_event5_indicate();
+        Hal_redLedOn();
+        Hal_delay(10);
         Hal_redLedOff();
         Hal_redLedOff();
+        break;
+    default:
+        for (i = 0; i < 5; i++) {
+            Hal_greenLedOn();
+            Hal_redLedOn();
+            Hal_delay(10);
+            Hal_greenLedOff();
+            Hal_redLedOff();
+            Hal_delay(10);
+        }
     }
     }
-    Hal_tickStart(5000, tickHandler);
 }
 
 static void tickHandler(void) {
 }
 
 static void tickHandler(void) {