summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-04-06 17:17:40 -0500
committerJesse Gilles <jgilles@multitech.com>2015-04-06 17:17:40 -0500
commit061f14802f86bdb41fe7dd0161461f8b8fa054cf (patch)
tree9327f5550d7927a9bb4f9cc14881635376da1ddc
parentbe5c8ac770bc5b142e2c6a47702d9ac653141371 (diff)
downloadlora_gateway-061f14802f86bdb41fe7dd0161461f8b8fa054cf.tar.gz
lora_gateway-061f14802f86bdb41fe7dd0161461f8b8fa054cf.tar.bz2
lora_gateway-061f14802f86bdb41fe7dd0161461f8b8fa054cf.zip
add configurable spidev path, fix CS behavior for MTCDT
-rw-r--r--libloragw/Makefile3
-rw-r--r--libloragw/inc/loragw_spi.h8
-rw-r--r--libloragw/src/loragw_spi.native.c29
3 files changed, 35 insertions, 5 deletions
diff --git a/libloragw/Makefile b/libloragw/Makefile
index 2b2090e..b9cad50 100644
--- a/libloragw/Makefile
+++ b/libloragw/Makefile
@@ -161,6 +161,7 @@ inc/config.h: ../VERSION library.cfg
# SPI interface
@echo "SPI interface : $(CFG_SPI_MSG)"
@echo " #define $(CFG_SPI_OPT) 1" >> $@
+ @echo ' #define CFG_SPI_DEV $(CFG_SPI_DEV)' >> $@
# Concentrator chip
@echo "Concentrator chip : $(CFG_CHIP_MSG)"
@echo " #define $(CFG_CHIP_OPT) 1" >> $@
@@ -227,4 +228,4 @@ test_loragw_hal: tst/test_loragw_hal.c libloragw.a
test_loragw_gps: tst/test_loragw_gps.c libloragw.a
$(CC) $(CFLAGS) -L. $< -o $@ $(LIBS)
-### EOF \ No newline at end of file
+### EOF
diff --git a/libloragw/inc/loragw_spi.h b/libloragw/inc/loragw_spi.h
index ae9ba68..845afdc 100644
--- a/libloragw/inc/loragw_spi.h
+++ b/libloragw/inc/loragw_spi.h
@@ -38,6 +38,14 @@ Maintainer: Sylvain Miermont
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
+/* set SPI device */
+/**
+@brief LoRa concentrator SPI path configuration for spidev
+@param path pointer to spidev device
+@return LGW_SPI_SUCCESS if path is valid, LGW_SPI_ERROR if not
+*/
+int lgw_spi_set_path(const char *path);
+
/**
@brief LoRa concentrator SPI setup (configure I/O and peripherals)
@param spi_target_ptr pointer on a generic pointer to SPI target (implementation dependant)
diff --git a/libloragw/src/loragw_spi.native.c b/libloragw/src/loragw_spi.native.c
index f963a59..5036eec 100644
--- a/libloragw/src/loragw_spi.native.c
+++ b/libloragw/src/loragw_spi.native.c
@@ -53,12 +53,23 @@ Maintainer: Sylvain Miermont
#define READ_ACCESS 0x00
#define WRITE_ACCESS 0x80
#define SPI_SPEED 8000000
-//#define SPI_DEV_PATH "/dev/spidev0.0"
-#define SPI_DEV_PATH "/dev/spidev32766.0"
+// use default device path from library.cfg
+char *spi_dev_path = CFG_SPI_DEV; /* path to spi device */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
+/* set SPI device */
+int lgw_spi_set_path(const char *path) {
+ if (path) {
+ spi_dev_path = path;
+ return LGW_SPI_SUCCESS;
+ }
+ else {
+ return LGW_SPI_ERROR;
+ }
+}
+
/* SPI initialization and configuration */
int lgw_spi_open(void **spi_target_ptr) {
int *spi_device = NULL;
@@ -75,9 +86,10 @@ int lgw_spi_open(void **spi_target_ptr) {
DEBUG_MSG("ERROR: MALLOC FAIL\n");
return LGW_SPI_ERROR;
}
-
+
/* open SPI device */
- dev = open(SPI_DEV_PATH, O_RDWR);
+ printf("Opening SPI %s\n", spi_dev_path);
+ dev = open(spi_dev_path, O_RDWR);
if (dev < 0) {
DEBUG_MSG("SPI port fail to open\n");
return LGW_SPI_ERROR;
@@ -95,6 +107,7 @@ int lgw_spi_open(void **spi_target_ptr) {
}
/* setting SPI max clk (in Hz) */
+ printf("Setting SPI speed %d Hz\n", SPI_SPEED);
i = SPI_SPEED;
a = ioctl(dev, SPI_IOC_WR_MAX_SPEED_HZ, &i);
b = ioctl(dev, SPI_IOC_RD_MAX_SPEED_HZ, &i);
@@ -183,7 +196,9 @@ int lgw_spi_w(void *spi_target, uint8_t address, uint8_t data) {
k.tx_buf = (unsigned long) out_buf;
k.len = ARRAY_SIZE(out_buf);
k.speed_hz = SPI_SPEED;
+ /* use default CS behavior
k.cs_change = 1;
+ */
k.bits_per_word = 8;
a = ioctl(spi_device, SPI_IOC_MESSAGE(1), &k);
@@ -225,7 +240,9 @@ int lgw_spi_r(void *spi_target, uint8_t address, uint8_t *data) {
k.tx_buf = (unsigned long) out_buf;
k.rx_buf = (unsigned long) in_buf;
k.len = ARRAY_SIZE(out_buf);
+ /* use default CS behavior
k.cs_change = 1;
+ */
a = ioctl(spi_device, SPI_IOC_MESSAGE(1), &k);
/* determine return code */
@@ -271,8 +288,10 @@ int lgw_spi_wb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size)
memset(&k, 0, sizeof(k)); /* clear k */
k[0].tx_buf = (unsigned long) &command;
k[0].len = 1;
+ /* use default CS behavior
k[0].cs_change = 0;
k[1].cs_change = 1;
+ */
for (i=0; size_to_do > 0; ++i) {
chunk_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK;
offset = i * LGW_BURST_CHUNK;
@@ -325,8 +344,10 @@ int lgw_spi_rb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size)
memset(&k, 0, sizeof(k)); /* clear k */
k[0].tx_buf = (unsigned long) &command;
k[0].len = 1;
+ /* use default CS behavior
k[0].cs_change = 0;
k[1].cs_change = 1;
+ */
for (i=0; size_to_do > 0; ++i) {
chunk_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK;
offset = i * LGW_BURST_CHUNK;