]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Modify IRC enable code
authorMichal Horn <hornmich@fel.cvut.cz>
Tue, 11 Aug 2015 10:11:28 +0000 (12:11 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 28 Aug 2015 14:17:01 +0000 (16:17 +0200)
The switch statements have been replaced by more effective lookup table,
The extern variables declaration has been removed as it would cause
problems with threadsave code later.

The lookup table array is not exported now and for getting the IRC status
the rpp_irc_status function is used instead of accessing the exported
variables.

There also was an error in rpp_irc_disable function, which was returning
FAILURE in case of success.

rpp/include/rpp/irc.h
rpp/src/rpp/din.c
rpp/src/rpp/irc.c

index 7e1236b9c97ab141ab9d2365cf27636f0c75ae94..0af093217b513c2208433d39d7b5a7655bfed8be 100644 (file)
@@ -21,9 +21,6 @@
  */
 #define RPP_IRC_2 2U
 
-extern boolean_t rpp_irc1_enabled;  /**< Flag for indicating the state of IRC1. */
-extern boolean_t rpp_irc2_enabled;  /**< Flag for indicating the state of IRC2. */
-
 /**
  * IRC module initialization.
  *
index 0523905759c612ff2b8e733d4630ee27186d2f71..1892faa440cdf8703139185c6f53f73fbf6bb2e6 100644 (file)
@@ -64,9 +64,9 @@ static uint16_t can_wake_cache = 0x0;
 
 static boolean_t check_pin_busy(uint8_t pin)
 {
-       if (rpp_irc1_enabled && (pin == 10 || pin == 11))
+       if (rpp_irc_status(RPP_IRC_1) == 1 && (pin == 10 || pin == 11))
                return TRUE;
-       if (rpp_irc2_enabled && (pin == 14 || pin == 15))
+       if (rpp_irc_status(RPP_IRC_2) == 1 && (pin == 14 || pin == 15))
                return TRUE;
        return FALSE;
 }
index 96625b7f6712826a2f996a7d0b8da2a08e54b311..5002922684f799ca392d4bbb2b51fab4cebe2aeb 100644 (file)
@@ -29,8 +29,7 @@
 
 static boolean_t initialized = FALSE;
 
-boolean_t rpp_irc1_enabled = FALSE;
-boolean_t rpp_irc2_enabled = FALSE;
+static boolean_t rpp_irc_enabled[2] = {FALSE, FALSE};
 
 int8_t rpp_irc_init()
 {
@@ -55,14 +54,7 @@ int8_t rpp_irc_enable(uint8_t irc)
        if (irc < 1 || irc > 2)
                return -RPP_EINVAL;
 
-       switch (irc) {
-       case 1:
-               rpp_irc1_enabled = TRUE;
-               break;
-       case 2:
-               rpp_irc2_enabled = TRUE;
-               break;
-       }
+       rpp_irc_enabled[irc-1] = TRUE;
 
        setMuxForIRC(irc, TRUE);
        ircEnable(irc);
@@ -79,13 +71,7 @@ int8_t rpp_irc_status(uint8_t irc)
        if (irc < 1 || irc > 2)
                return -RPP_EINVAL;
 
-       switch (irc) {
-       case 1:
-               return rpp_irc1_enabled ? 1 : 0;
-       case 2:
-               return rpp_irc2_enabled ? 1 : 0;
-       }
-       return FAILURE;
+       return rpp_irc_enabled[irc-1];
 }
 
 int32_t rpp_irc_get(uint8_t irc)
@@ -121,13 +107,6 @@ int8_t rpp_irc_disable(uint8_t irc)
 
        ircDisable(irc);
        setMuxForIRC(irc, FALSE);
-       switch (irc) {
-       case 1:
-               rpp_irc1_enabled = FALSE;
-               break;
-       case 2:
-               rpp_irc2_enabled = FALSE;
-               break;
-       }
-       return FAILURE;
+       rpp_irc_enabled[irc-1] = FALSE;
+       return SUCCESS;
 }