]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Add SPI into RPP layer
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 29 Aug 2015 11:04:01 +0000 (13:04 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 3 Sep 2015 08:22:11 +0000 (10:22 +0200)
Makefile.var
rpp/include/rpp/.gitattributes
rpp/include/rpp/rpp.h
rpp/include/rpp/spi.h [new file with mode: 0644]
rpp/include/types.h
rpp/src/rpp/.gitattributes
rpp/src/rpp/spi.c [new file with mode: 0644]

index 30da060366203a1ce310559318e43f6d688114ad..3b34ead92b952bc11b478e9788b20e41dff1cbb2 100644 (file)
@@ -143,6 +143,7 @@ rpp_lib_SOURCES_$(TARGET_HAS_SPI) +=                        \
        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
index 44db08bfeda30f93015b541d213b7442f1f91282..62dc554d3a38429839b1775c79ccff03b4e23886 100644 (file)
@@ -4,3 +4,4 @@
 /mutex.h       eaton
 /rpp.h eaton
 /sci.h eaton
+/spi.h eaton
index 824d52a7750d6a81d81f96e25b4cee1067f80754..237c238a94289f91e2276788d2c65dc921469b5e 100644 (file)
 #error No supported target specified!
 #endif /* TARGET_TMS570_HDK */
 
+#if defined(TARGET_HAS_SPI)
+#include "rpp/spi.h"
+#endif
+
 /* Library main functions */
 
 /**
diff --git a/rpp/include/rpp/spi.h b/rpp/include/rpp/spi.h
new file mode 100644 (file)
index 0000000..c309eec
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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
index c9a2fd594f1f9edbfd81b04662fb612c1ada13e2..ab784abe98141ab99951398f9fed323fbcac8e7a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * @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>
  */
@@ -77,6 +77,7 @@
 #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__
index 23c96f30bb512378a1782f0894c3ec863ef144d3..b2413fa9fb0fc4c425b2b35fd51c048b9f80cbad 100644 (file)
@@ -3,3 +3,4 @@
 /gio.c eaton
 /rpp.c eaton
 /sci.c eaton
+/spi.c eaton
diff --git a/rpp/src/rpp/spi.c b/rpp/src/rpp/spi.c
new file mode 100644 (file)
index 0000000..496fa80
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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;
+}