From: Michal Horn Date: Tue, 11 Aug 2015 10:11:28 +0000 (+0200) Subject: Modify IRC enable code X-Git-Tag: eaton-0.6~29 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/commitdiff_plain/b98da5715a47ac1e8905356cbc7f15440679d0a9 Modify IRC enable code 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. --- diff --git a/rpp/include/rpp/irc.h b/rpp/include/rpp/irc.h index 7e1236b..0af0932 100644 --- a/rpp/include/rpp/irc.h +++ b/rpp/include/rpp/irc.h @@ -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. * diff --git a/rpp/src/rpp/din.c b/rpp/src/rpp/din.c index 0523905..1892faa 100644 --- a/rpp/src/rpp/din.c +++ b/rpp/src/rpp/din.c @@ -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; } diff --git a/rpp/src/rpp/irc.c b/rpp/src/rpp/irc.c index 96625b7..5002922 100644 --- a/rpp/src/rpp/irc.c +++ b/rpp/src/rpp/irc.c @@ -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; }