]> www.average.org Git - pulsecounter.git/commitdiff
pass its id to the handler
authorEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 20:27:26 +0000 (23:27 +0300)
committerEugene Crosser <crosser@average.org>
Thu, 10 Dec 2015 20:27:26 +0000 (23:27 +0300)
Hal/Hal.c
Hal/Hal.h

index ef498ba6f3d0b36a463b8b23e6666815b925b979..b4944e2c79090a97dcba17ea049e04377d85a231 100644 (file)
--- a/Hal/Hal.c
+++ b/Hal/Hal.c
 #define WAKEUP()                    (__bic_SR_register_on_exit(LPM3_bits))
 #endif
 
 #define WAKEUP()                    (__bic_SR_register_on_exit(LPM3_bits))
 #endif
 
-#define NUM_HANDLERS 3
+#define NUM_HANDLERS 5
 
 #define BUTTON_HANDLER_ID      0
 
 #define BUTTON_HANDLER_ID      0
-#define TICK_HANDLER_ID        1
-#define DISPATCH_HANDLER_ID    2
+#define EVENT4_HANDLER_ID      1
+#define EVENT5_HANDLER_ID      2
+#define TICK_HANDLER_ID        3
+#define DISPATCH_HANDLER_ID    4
 
 
-static void buttonHandler(void);
+static void buttonHandler(uint8_t id);
 static void postEvent(uint8_t handlerId);
 
 static void postEvent(uint8_t handlerId);
 
-static Hal_Handler appButtonHandler;
+static void (*appButtonHandler)(void);
 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];
@@ -103,7 +105,7 @@ static Hal_Handler handlerTab[NUM_HANDLERS];
 
 /* -------- APP-HAL INTERFACE -------- */
 
 
 /* -------- APP-HAL INTERFACE -------- */
 
-void Hal_buttonEnable(Hal_Handler handler) {
+void Hal_buttonEnable(void (*handler)(void)) {
     handlerTab[BUTTON_HANDLER_ID] = buttonHandler;
     appButtonHandler = handler;
     BUTTON_CONFIG();
     handlerTab[BUTTON_HANDLER_ID] = buttonHandler;
     appButtonHandler = handler;
     BUTTON_CONFIG();
@@ -226,7 +228,7 @@ void Hal_idleLoop(void) {
             uint8_t id;
             for (id = 0, mask = 0x1; id < NUM_HANDLERS; id++, mask <<= 1) {
                 if ((events & mask) && handlerTab[id]) {
             uint8_t id;
             for (id = 0, mask = 0x1; id < NUM_HANDLERS; id++, mask <<= 1) {
                 if ((events & mask) && handlerTab[id]) {
-                    handlerTab[id]();
+                    handlerTab[id](id);
                 }
             }
         }
                 }
             }
         }
@@ -326,7 +328,7 @@ void Em_Hal_watchOn(void) {
 
 /* -------- INTERNAL FUNCTIONS -------- */
 
 
 /* -------- INTERNAL FUNCTIONS -------- */
 
-static void buttonHandler(void) {
+static void buttonHandler(uint8_t id) {
     Hal_delay(BUTTON_DEBOUNCE_MSECS);
     if (BUTTON_PRESSED() && appButtonHandler) {
         appButtonHandler();
     Hal_delay(BUTTON_DEBOUNCE_MSECS);
     if (BUTTON_PRESSED() && appButtonHandler) {
         appButtonHandler();
index 8ec28c963db094252f39c2b99dff635bb49ad9ab..9af8ec811cc1745daca6aedcb13f449177cc4935 100644 (file)
--- a/Hal/Hal.h
+++ b/Hal/Hal.h
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
-typedef void (*Hal_Handler)(void);
+typedef void (*Hal_Handler)(uint8_t id);
 
 /**
  * --------- Hal_buttonEnable ---------
 
 /**
  * --------- Hal_buttonEnable ---------
@@ -47,7 +47,7 @@ typedef void (*Hal_Handler)(void);
  *   BUTTON interrupt enabled
  *
  **/
  *   BUTTON interrupt enabled
  *
  **/
-extern void Hal_buttonEnable(Hal_Handler handler);
+extern void Hal_buttonEnable(void (*handler)(void));
 /**
  * --------- Hal_connected ---------
  *
 /**
  * --------- Hal_connected ---------
  *