1 /* Copyright (C) 2013, 2015 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 * Logic Output RPP API implementation file.
17 * RPP API documentation.
22 #include "rpp/mutex.h"
24 RPP_MUTEX_DEFINE(mutex_lout);
26 #ifndef FREERTOS_POSIX
28 #include "drv/spi_def.h"
31 static boolean_t initialized = FALSE;
33 int8_t rpp_lout_init()
37 if (!RPP_MUTEX_INIT(mutex_lout))
40 #ifndef FREERTOS_POSIX
49 static uint8_t out_cache = 0x0;
51 int8_t rpp_lout_set(uint8_t pin, uint8_t val)
53 if ((pin < 1) || (pin > 8))
56 uint8_t index = pin - 1;
57 RPP_MUTEX_LOCK(mutex_lout);
59 bit_set(out_cache, index);
61 bit_clear(out_cache, index);
62 RPP_MUTEX_UNLOCK(mutex_lout);
67 static uint8_t diag_cache = 0x0;
69 int8_t rpp_lout_diag(uint8_t pin)
71 if ((pin < 1) || (pin > 8))
76 RPP_MUTEX_LOCK(mutex_lout);
77 if (is_bit_set(diag_cache, pin - 1))
79 RPP_MUTEX_UNLOCK(mutex_lout);
84 int8_t rpp_lout_update()
86 #ifndef FREERTOS_POSIX
87 RPP_MUTEX_LOCK(mutex_lout);
88 // Update output values
89 lout_set_word(out_cache);
90 // FIXME: Check which SPI transfer statuses could be considered errors
93 // Read back diagnostic values
94 // FIXME: Implement. Dummy assign for now.
95 diag_cache = out_cache;
97 if (diag_cache != out_cache) {
98 RPP_MUTEX_UNLOCK(mutex_lout);
101 RPP_MUTEX_UNLOCK(mutex_lout);