1 /* Copyright (C) 2013, 2016 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)
57 if ((pin < 1) || (pin > 6))
61 if ((val != HIGH) && (val != LOW))
64 uint8_t idx = pin - 1;
66 #ifndef FREERTOS_POSIX
67 // Set and store value
68 RPP_MUTEX_LOCK(mutex_mout);
69 ret = drv_mout_set(idx, val);
72 RPP_MUTEX_UNLOCK(mutex_mout);
76 // FIXME Wait some time for synchronization
77 // Don't use vTaskDelay() here because the minimum time to wait is one tick,
78 // and depending of the configuration of the user model one tick can overrun
81 for (wait = 0; wait < 10; wait++) {
85 RPP_MUTEX_LOCK(mutex_mout);
86 // Get value back and compare
87 ret = drv_mout_diag(idx);
88 RPP_MUTEX_UNLOCK(mutex_mout);
94 RPP_MUTEX_LOCK(mutex_mout);
96 RPP_MUTEX_UNLOCK(mutex_mout);
103 int8_t rpp_mout_get(uint8_t pin)
106 if ((pin < 1) || (pin > 6))
109 RPP_MUTEX_LOCK(mutex_mout);
110 int8_t ret_val = cache[pin - 1];
111 RPP_MUTEX_UNLOCK(mutex_mout);
117 int8_t rpp_mout_diag(uint8_t pin)
121 if ((pin < 1) || (pin > 6))
124 #ifndef FREERTOS_POSIX
125 RPP_MUTEX_LOCK(mutex_mout);
126 ret = drv_mout_diag(pin - 1);
127 RPP_MUTEX_UNLOCK(mutex_mout);