-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2015 Czech Technical University in Prague
*
* Authors:
* - Carlos Jenkins <carlos@jenkins.co.cr>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
*
* File : lout.c
* Abstract:
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
-#if rppCONFIG_INCLUDE_LOUT == 1
+RPP_MUTEX_DEFINE(mutex_lout);
-#if rppCONFIG_DRV == 1
-#include "drv_lout.h"
+#ifndef FREERTOS_POSIX
+#include "drv/lout.h"
+#include "drv/spi_tms570.h"
#endif
static boolean_t initialized = FALSE;
int8_t rpp_lout_init()
{
- if(initialized) {
- return FAIL;
- }
- initialized = TRUE;
+ if (initialized)
+ return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_lout))
+ return FAILURE;
+ initialized = TRUE;
+#ifndef FREERTOS_POSIX
+ spi_tms570_init();
+#endif
- // FIXME: Implement.
- return SUCCESS;
+ // FIXME: Implement.
+ return SUCCESS;
}
static uint8_t out_cache = 0x0;
-int8_t rpp_lout_set(uint8_t pin, int8_t val)
+int8_t rpp_lout_set(uint8_t pin, uint8_t val)
{
- if((pin < 1) || (pin > 8)) {
- return -1;
- }
- if(val) {
- set_bit(out_cache, pin - 1);
- } else {
- clear_bit(out_cache, pin - 1);
- }
- return SUCCESS;
+ if ((pin < 1) || (pin > 8))
+ return -1;
+
+ uint8_t index = pin - 1;
+ RPP_MUTEX_LOCK(mutex_lout);
+ if (val)
+ bit_set(out_cache, index);
+ else
+ bit_clear(out_cache, index);
+ RPP_MUTEX_UNLOCK(mutex_lout);
+ return SUCCESS;
}
int8_t rpp_lout_diag(uint8_t pin)
{
- if((pin < 1) || (pin > 8)) {
- return -1;
- }
-
- if(is_bit_set(pin - 1)) {
- return HIGH;
- }
- return LOW;
-}
+ if ((pin < 1) || (pin > 8))
+ return -1;
+ int8_t ret_val = LOW;
-int rpp_lout_update()
-{
- #if rppCONFIG_DRV == 1
- // Update output values
- lout_set_word(out_cache);
- // FIXME: Check which SPI transfer statuses could be considered errors
- lout_spi_transfer();
-
- // Read back diagnostic values
- // FIXME: Implement. Dummy asign for now.
- diag_cache = out_cache;
-
- if(diag_cache != out_cache) {
- return FAIL;
- }
- #endif
-
- return SUCCESS;
+ RPP_MUTEX_LOCK(mutex_lout);
+ if (is_bit_set(diag_cache, pin - 1))
+ ret_val = HIGH;
+ RPP_MUTEX_UNLOCK(mutex_lout);
+ return ret_val;
}
-#endif /* rppCONFIG_INCLUDE_LOUT */
+int8_t rpp_lout_update()
+{
+#ifndef FREERTOS_POSIX
+ RPP_MUTEX_LOCK(mutex_lout);
+ // Update output values
+ lout_set_word(out_cache);
+ // FIXME: Check which SPI transfer statuses could be considered errors
+ lout_spi_transfer();
+
+ // Read back diagnostic values
+ // FIXME: Implement. Dummy assign for now.
+ diag_cache = out_cache;
+
+ if (diag_cache != out_cache) {
+ RPP_MUTEX_UNLOCK(mutex_lout);
+ return FAILURE;
+ }
+ RPP_MUTEX_UNLOCK(mutex_lout);
+#endif
+ return SUCCESS;
+}