rpp/src/drv/spi.c \
rpp/src/drv/spi_tms570.c \
rpp/src/drv/_$(TARGET)/spi_def.c \
+ rpp/src/rpp/spi.c \
rpp_lib_SOURCES_posix = \
os/$(rpp_lib_OS)/src/rpp/sci_posix.c
/mutex.h eaton
/rpp.h eaton
/sci.h eaton
+/spi.h eaton
#error No supported target specified!
#endif /* TARGET_TMS570_HDK */
+#if defined(TARGET_HAS_SPI)
+#include "rpp/spi.h"
+#endif
+
/* Library main functions */
/**
--- /dev/null
+/*
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ * - Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * 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.
+ *
+ */
+
+#ifndef RPP_SPI_H
+#define RPP_SPI_H
+
+#include "drv/spi_def.h"
+#include "types.h"
+
+/**
+ * Initizlize SPI subsystem
+ *
+ *
+ * @return SUCCESS or FAILURE
+ */
+int8_t rpp_spi_init();
+
+/**
+ * Transfer message to an SPI device and receive an answer.
+ *
+ * This function is thread safe.
+ *
+ * @param dev The device to communicate with.
+ * @param rq_len The lenght of data (in bytes) pointed by @a tx_buf and @a rx_buf.
+ * @param tx_buf Data to be sent to the device.
+ * @param rx_buf Data received from the device.
+ *
+ * @return SUCCESS or negative RPP error code.
+ */
+int8_t rpp_spi_transfer(enum spi_device dev, int rq_len, const void *tx_buf, void *rx_buf);
+
+/**
+ * Transfer 16-bit message to the device.
+ *
+ * This is a convenience wrapper function over rpp_spi_transfer().
+ *
+ * This function is thread safe.
+ *
+ * @param dev The device to communicate with.
+ * @param tx_val Value to send.
+ * @param rx_val Value to receive.
+ *
+ * @return SUCCESS or negative RPP error code.
+ */
+int8_t rpp_spi_transfer16(enum spi_device dev, uint16_t tx_val, uint16_t *rx_val);
+
+#endif
*
* @file types.h
*
- * @copyright Copyright (C) 2013, 2014 Czech Technical University in Prague
+ * @copyright Copyright (C) 2013, 2014, 2015 Czech Technical University in Prague
*
* @author Carlos Jenkins <carlos@jenkins.co.cr>
*/
#define RPP_EBUSY 3 /**< Hardware is busy */
#define RPP_ENOMEM 4 /**< Not enough memory */
#define RPP_ENODATA 5 /**< No data were reveived */
+#define RPP_ENODEV 6 /**< Specified device does not exist */
// Note: Sadly <stdint.h> is not available with CCS tools.
#ifdef __GNUC__
/gio.c eaton
/rpp.c eaton
/sci.c eaton
+/spi.c eaton
--- /dev/null
+/*
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ * - Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * 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.
+ *
+ */
+
+#include "rpp/spi.h"
+#include "drv/spi.h"
+#include "drv/endian.h"
+
+int8_t rpp_spi_init()
+{
+ return spi_init();
+}
+
+int8_t rpp_spi_transfer(enum spi_device dev, int rq_len, const void *tx_buf, void *rx_buf)
+{
+ if (dev >= _SPIDEV_COUNT)
+ return -RPP_ENODEV;
+ return spi_transfer(dev, rq_len, tx_buf, rx_buf) == rq_len ? SUCCESS : FAILURE;
+}
+
+
+int8_t rpp_spi_transfer16(enum spi_device dev, uint16_t tx_val, uint16_t *rx_val)
+{
+ uint16_t tx, rx;
+ int8_t ret;
+
+ tx = cpu_to_be16(tx_val);
+ ret = rpp_spi_transfer(dev, sizeof(tx), &tx, &rx);
+ if (rx_val)
+ *rx_val = be16_to_cpu(rx);
+ return ret;
+}