X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/9ebcc693fb87247af18d94ba3c65229187f73a94..573021795371f41a23ed0fe0b5171f38bb96d86e:/rpp/src/rpp/din.c diff --git a/rpp/src/rpp/din.c b/rpp/src/rpp/din.c index 1892faa..e65380a 100644 --- a/rpp/src/rpp/din.c +++ b/rpp/src/rpp/din.c @@ -19,18 +19,23 @@ #include "rpp/rpp.h" +#include "rpp/mutex.h" #ifndef FREERTOS_POSIX #include "drv/din.h" #include "drv/spi_tms570.h" #endif +RPP_MUTEX_DEFINE(mutex_din); + static boolean_t initialized = FALSE; int8_t rpp_din_init() { if (initialized) return FAILURE; + if (!RPP_MUTEX_INIT(mutex_din)) + return FAILURE; initialized = TRUE; #ifndef FREERTOS_POSIX dmmInit(); @@ -48,7 +53,9 @@ int8_t rpp_din_ref(uint16_t ref_a, uint16_t ref_b) return -1; #ifndef FREERTOS_POSIX + RPP_MUTEX_LOCK(mutex_din); drv_din_ref(ref_a, ref_b); + RPP_MUTEX_UNLOCK(mutex_din); #endif return SUCCESS; } @@ -82,9 +89,12 @@ int8_t rpp_din_setup(uint8_t pin, boolean_t pull_up, if (!pull_up && (pin > 7)) return -2; + RPP_MUTEX_LOCK(mutex_din); // Check blockade of specific pins - if (check_pin_busy(pin)) + if (check_pin_busy(pin)) { + RPP_MUTEX_UNLOCK(mutex_din); return -RPP_EBUSY; + } // Set bits if (pull_up) @@ -103,6 +113,7 @@ int8_t rpp_din_setup(uint8_t pin, boolean_t pull_up, bit_clear(can_wake_cache, pin); config_changed = TRUE; + RPP_MUTEX_UNLOCK(mutex_din); return SUCCESS; } @@ -119,10 +130,7 @@ int8_t rpp_din_get(uint8_t pin) if (check_pin_busy(pin)) return -RPP_EBUSY; - - if (is_bit_set(in_cache, pin)) - return RPP_CLOSED; - return RPP_OPEN; + return is_bit_set(in_cache, pin) ? RPP_CLOSED : RPP_OPEN; } int8_t rpp_din_get_tr(uint8_t pin) @@ -135,11 +143,9 @@ int8_t rpp_din_get_tr(uint8_t pin) if (check_pin_busy(pin)) return -RPP_EBUSY; - #ifndef FREERTOS_POSIX if (drv_din_get_varthr(pin) == 1) return HIGH; - #endif return LOW; } @@ -158,10 +164,7 @@ int8_t rpp_din_diag(uint8_t pin) if (check_pin_busy(pin)) return -RPP_EBUSY; - - if (is_bit_set(diag_cache, pin)) - return HIGH; - return LOW; + return is_bit_set(diag_cache, pin) ? HIGH : LOW; } /* @@ -169,6 +172,7 @@ int8_t rpp_din_diag(uint8_t pin) */ int8_t rpp_din_update() { + RPP_MUTEX_LOCK(mutex_din); #ifndef FREERTOS_POSIX /// Setup pins if (config_changed) { @@ -219,12 +223,15 @@ int8_t rpp_din_update() // FIXME: Implement. Dummy assign for now. diag_cache = in_cache; - if (diag_cache != in_cache) + if (diag_cache != in_cache) { + RPP_MUTEX_UNLOCK(mutex_din); return FAILURE; + } #else /* ifndef FREERTOS_POSIX */ UNUSED(config_changed); #endif /* ifndef FREERTOS_POSIX */ + RPP_MUTEX_UNLOCK(mutex_din); return SUCCESS; }