]> www.average.org Git - pulsecounter.git/commitdiff
count interrupts, disable for 100ms
authorEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 19:39:01 +0000 (22:39 +0300)
committerEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 19:39:01 +0000 (22:39 +0300)
Hal/Hal.c
Hal/Hal.h
Pulsecounter-Prog.c

index 00b8c6b07202727f6cc402d3f9aed6e9da7a5cf5..ef498ba6f3d0b36a463b8b23e6666815b925b979 100644 (file)
--- a/Hal/Hal.c
+++ b/Hal/Hal.c
@@ -24,6 +24,8 @@
 
 #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
 
@@ -90,8 +92,6 @@
 #define TICK_HANDLER_ID        1
 #define DISPATCH_HANDLER_ID    2
 
-int32_t buttonCnt = 0;
-
 static void buttonHandler(void);
 static void postEvent(uint8_t handlerId);
 
@@ -327,10 +327,11 @@ void Em_Hal_watchOn(void) {
 /* -------- INTERNAL FUNCTIONS -------- */
 
 static void buttonHandler(void) {
-    Hal_delay(100);
+    Hal_delay(BUTTON_DEBOUNCE_MSECS);
     if (BUTTON_PRESSED() && appButtonHandler) {
         appButtonHandler();
     }
+    BUTTON_ENABLE();
 }
 
 static void postEvent(uint8_t handlerId) {
@@ -348,9 +349,9 @@ static void postEvent(uint8_t handlerId) {
     #pragma vector=PORT1_VECTOR
 #endif
 INTERRUPT void buttonIsr(void) {
-    buttonCnt++;
-    postEvent(BUTTON_HANDLER_ID);
-    BUTTON_ENABLE();
+    if (BUTTON_FIRED())
+        postEvent(BUTTON_HANDLER_ID);
+    BUTTON_DISABLE();
     WAKEUP();
 }
 
index 374daf5f9e37b56d745240b3d5b2a5e4e2bb098b..8ec28c963db094252f39c2b99dff635bb49ad9ab 100644 (file)
--- a/Hal/Hal.h
+++ b/Hal/Hal.h
@@ -26,8 +26,6 @@
 extern "C" {
 #endif
 
-extern int32_t buttonCnt;
-
 typedef void (*Hal_Handler)(void);
 
 /**
index 2c3256d849ee1eabac4e03815f8e3f0743585246..f5071784b56c41126d9d58559242d7bf0ea0b090 100644 (file)
@@ -4,6 +4,7 @@
 static void buttonHandler(void);
 static void tickHandler(void);
 static bool connected = false;
+static int32_t buttonCnt = 0;
 
 void main() {
     Hal_init();
@@ -16,6 +17,7 @@ void main() {
 static void buttonHandler(void) {
     uint8_t i;
 
+    buttonCnt++;
     if (connected)
         Pulsecounter_event3_indicate();
     else
@@ -23,7 +25,7 @@ static void buttonHandler(void) {
     for (i = 0; i < 3; i++) {
         Hal_greenLedOn();
         Hal_redLedOn();
-        Hal_delay(100);
+        Hal_delay(10);
         Hal_greenLedOff();
         Hal_redLedOff();
     }