1 /* Copyright (C) 2013 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
13 * Power Output (12V, 2A, Push/Pull) RPP API implementation file.
17 * RPP API documentation.
22 #include "rpp/mutex.h"
24 RPP_MUTEX_DEFINE(mutex_mout);
26 #ifndef FREERTOS_POSIX
30 static boolean_t initialized = FALSE;
32 int8_t rpp_mout_init()
36 if (!RPP_MUTEX_INIT(mutex_mout))
39 #ifndef FREERTOS_POSIX
49 static uint8_t cache[] = {
50 LOW, LOW, LOW, LOW, LOW, LOW
53 int8_t rpp_mout_set(uint8_t pin, uint8_t val)
56 if ((pin < 1) || (pin > 6))
60 if ((val != HIGH) && (val != LOW))
63 uint8_t idx = pin - 1;
65 #ifndef FREERTOS_POSIX
66 // Set and store value
67 RPP_MUTEX_LOCK(mutex_mout);
68 if (drv_mout_set(idx, val) != SUCCESS)
71 RPP_MUTEX_UNLOCK(mutex_mout);
73 // FIXME Wait some time for synchronization
74 // Don't use vTaskDelay() here because the minimum time to wait is one tick,
75 // and depending of the configuration of the user model one tick can overrun
78 for (wait = 0; wait < 10; wait++) {
82 RPP_MUTEX_LOCK(mutex_mout);
83 // Get value back and compare
84 if (drv_mout_diag(idx) == FAILURE) {
85 RPP_MUTEX_UNLOCK(mutex_mout);
88 RPP_MUTEX_UNLOCK(mutex_mout);
91 RPP_MUTEX_LOCK(mutex_mout);
93 RPP_MUTEX_UNLOCK(mutex_mout);
100 int8_t rpp_mout_get(uint8_t pin)
103 if ((pin < 1) || (pin > 6))
106 RPP_MUTEX_LOCK(mutex_mout);
107 int8_t ret_val = cache[pin - 1];
108 RPP_MUTEX_UNLOCK(mutex_mout);
114 int8_t rpp_mout_diag(uint8_t pin)
117 if ((pin < 1) || (pin > 6))
120 #ifndef FREERTOS_POSIX
121 RPP_MUTEX_LOCK(mutex_mout);
122 if (drv_mout_diag(pin - 1) == 0) {
123 RPP_MUTEX_UNLOCK(mutex_mout);