Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
* Added support for SX1301AP2 reference design (with FPGA and additional
SX1272). When a FPGA is detected at startup, the HAL automatically adapt SPI
communication requests (using SPI header or not).

* Added util_spectral_scan diagnostic tool to scan the spectral band in
background, where the LoRa gateway operates. (can only be used with SX1301AP2
or similar design). By default it uses the same SPI device as the one used by
the HAL, but it can be changed depending on the hardware architecture on which
it is used.

* Removed SPI FTDI support due to lack of performances to properly handle heavy
packet traffic. Only native SPI suage is recommended.
* HAL: added a check that SX1301 firmwares have been properly loaded at startup.
  • Loading branch information
mcoracin committed Oct 8, 2015
1 parent ef01a45 commit a48215d
Show file tree
Hide file tree
Showing 26 changed files with 1,934 additions and 813 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -12,12 +12,14 @@ all:
$(MAKE) all -e -C util_spi_stress
$(MAKE) all -e -C util_tx_test
$(MAKE) all -e -C util_tx_continuous
$(MAKE) all -e -C util_spectral_scan

clean:
$(MAKE) clean -e -C libloragw
$(MAKE) clean -e -C util_pkt_logger
$(MAKE) clean -e -C util_spi_stress
$(MAKE) clean -e -C util_tx_test
$(MAKE) clean -e -C util_tx_continuous
$(MAKE) clean -e -C util_spectral_scan

### EOF
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.1.0
3.2.0
30 changes: 1 addition & 29 deletions libloragw/Makefile
Expand Up @@ -12,25 +12,9 @@ AR := $(CROSS_COMPILE)ar

CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I.

### library.cfg configuration file processing

ifeq ($(CFG_SPI),native)
CFG_SPI_MSG := Linux native SPI driver
CFG_SPI_OPT := CFG_SPI_NATIVE
else ifeq ($(CFG_SPI),ftdi)
CFG_SPI_MSG := FTDI SPI-over-USB bridge using libmpsse/libftdi/libusb
CFG_SPI_OPT := CFG_SPI_FTDI
else
$(error No SPI physical layer selected, check ../target.cfg file.)
endif

### linking options

ifeq ($(CFG_SPI),native)
LIBS := -lloragw -lrt -lm
else ifeq ($(CFG_SPI),ftdi)
LIBS := -lloragw -lrt -lmpsse -lm
endif
LIBS := -lloragw -lrt -lm

### general build targets

Expand All @@ -53,9 +37,6 @@ inc/config.h: ../VERSION library.cfg
# Release version
@echo "Release version : $(LIBLORAGW_VERSION)"
@echo " #define LIBLORAGW_VERSION "\"$(LIBLORAGW_VERSION)\""" >> $@
# SPI interface
@echo "SPI interface : $(CFG_SPI_MSG)"
@echo " #define $(CFG_SPI_OPT) 1" >> $@
# Debug options
@echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@
@echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@
Expand All @@ -72,13 +53,8 @@ inc/config.h: ../VERSION library.cfg
obj/loragw_aux.o: src/loragw_aux.c inc/loragw_aux.h inc/config.h
$(CC) -c $(CFLAGS) $< -o $@

ifeq ($(CFG_SPI),native)
obj/loragw_spi.o: src/loragw_spi.native.c inc/loragw_spi.h inc/config.h
$(CC) -c $(CFLAGS) $< -o $@
else ifeq ($(CFG_SPI),ftdi)
obj/loragw_spi.o: src/loragw_spi.ftdi.c inc/loragw_spi.h inc/config.h
$(CC) -c $(CFLAGS) $< -o $@
endif

obj/loragw_reg.o: src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h inc/config.h
$(CC) -c $(CFLAGS) $< -o $@
Expand All @@ -91,11 +67,7 @@ obj/loragw_gps.o: src/loragw_gps.c inc/loragw_gps.h inc/config.h

### static library

ifeq ($(CFG_SPI),native)
libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
else ifeq ($(CFG_SPI),ftdi)
libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
endif
$(AR) rcs $@ $^

### test programs
Expand Down
16 changes: 12 additions & 4 deletions libloragw/inc/loragw_spi.h
Expand Up @@ -35,6 +35,14 @@ Maintainer: Sylvain Miermont
#define LGW_SPI_ERROR -1
#define LGW_BURST_CHUNK 1024

#define LGW_SPI_MUX_MODE0 0x0 /* No FPGA */
#define LGW_SPI_MUX_MODE1 0x1 /* FPGA, with spi mux header */

#define LGW_SPI_MUX_TARGET_SX1301 0x0
#define LGW_SPI_MUX_TARGET_FPGA 0x1
#define LGW_SPI_MUX_TARGET_EEPROM 0x2
#define LGW_SPI_MUX_TARGET_SX1272 0x3

/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */

Expand All @@ -61,7 +69,7 @@ int lgw_spi_close(void *spi_target);
@param data data byte to write
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_w(void *spi_target, uint8_t address, uint8_t data);
int lgw_spi_w(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t data);

/**
@brief LoRa concentrator SPI single-byte read
Expand All @@ -70,7 +78,7 @@ int lgw_spi_w(void *spi_target, uint8_t address, uint8_t data);
@param data data byte to write
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_r(void *spi_target, uint8_t address, uint8_t *data);
int lgw_spi_r(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data);

/**
@brief LoRa concentrator SPI burst (multiple-byte) write
Expand All @@ -80,7 +88,7 @@ int lgw_spi_r(void *spi_target, uint8_t address, uint8_t *data);
@param size size of the transfer, in byte(s)
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_wb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
int lgw_spi_wb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size);

/**
@brief LoRa concentrator SPI burst (multiple-byte) read
Expand All @@ -90,7 +98,7 @@ int lgw_spi_wb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
@param size size of the transfer, in byte(s)
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_rb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
int lgw_spi_rb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size);

#endif

Expand Down
46 changes: 0 additions & 46 deletions libloragw/install_ftdi.txt

This file was deleted.

9 changes: 0 additions & 9 deletions libloragw/library.cfg
@@ -1,14 +1,5 @@
# That file will be included in the Makefile files that have hardware dependencies

### SPI interface to the concentrator ###
# Accepted values:
# native Linux native SPI driver (RECOMMENDED).
# Note: check the value of /dev/spidevX.X defined in source code
# to ensure the right device will be opened on your platform.
# ftdi FTDI SPI-over-USB bridge using libmpsse/libftdi/libusb

CFG_SPI= native

### Debug options ###
# Set the DEBUG_* to 1 to activate debug mode in individual modules.
# Warning: that makes the module *very verbose*, do not use for production
Expand Down
26 changes: 3 additions & 23 deletions libloragw/readme.md
Expand Up @@ -177,15 +177,6 @@ For embedded platforms, the function could be rewritten using hardware timers.
All modules use a fprintf(stderr,...) function to display debug diagnostic
messages if the DEBUG_xxx is set to 1 in library.cfg

The other settings available in library.cfg are:

* CFG_SPI configures how the link between the host and the concentrator chip
is done. It is highly recommended to use native SPI instead of FTDI when possible
for permormance reasons.
Note: when using native SPI on linux host, ensure that the /dev/spidevX.X
which is to be opened on your host is the same as the one defined in
libloragw/src/loragw_spi.native.c

### 3.3. Building procedures ###

For cross-compilation set the CROSS_COMPILE variable in the Makefile with the
Expand All @@ -199,16 +190,7 @@ and the *.c source files.
The library.cfg is also used directly to select the proper set of dynamic
libraries to be linked with.

### 3.4. Dynamic libraries requirements ###

Depending on config, SPI module needs LibMPSSE to access the FTDI SPI-over-USB
bridge. Please read install_ftdi.txt for installation instructions.

The code was tested with version 1.3 of LibMPSSE:
http://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz
SHA1 Checksum: 1b994a23b118f83144261e3e786c43df74a81cd5

### 3.5. Export ###
### 3.4. Export ###

Once build, to use that library on another system, you need to export the
following files :
Expand All @@ -232,7 +214,7 @@ hardware (IP and/or silicon revision).

This code has been written for:

* Semtech SX1301 chip (or FPGA equivalent)
* Semtech SX1301 chip
* Semtech SX1257 or SX1255 I/Q transceivers

The library will not work if there is a mismatch between the hardware version
Expand All @@ -246,11 +228,9 @@ are platform-dependant.
The functions must be rewritten depending on the SPI bridge you use:

* SPI master matched to the Linux SPI device driver (provided)
* SPI over USB using FTDI components (provided)
* SPI over USB using FTDI components (not provided)
* native SPI using a microcontroller peripheral (not provided)

Edit library.cfg to chose which SPI physical interface you want to use.

You can use the test program test_loragw_spi to check with a logic analyser
that the SPI communication is working

Expand Down
22 changes: 11 additions & 11 deletions libloragw/src/loragw_hal.c
Expand Up @@ -114,18 +114,8 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz)
const uint8_t ifmod_config[LGW_IF_CHAIN_NB] = LGW_IFMODEM_CONFIG;
const uint32_t rf_rx_bandwidth[LGW_RF_CHAIN_NB] = LGW_RF_RX_BANDWIDTH;

/* Strings for version (and options) identification */

#if (CFG_SPI_NATIVE == 1)
#define CFG_SPI_STR "native"
#elif (CFG_SPI_FTDI == 1)
#define CFG_SPI_STR "ftdi"
#else
#define CFG_SPI_STR "spi?"
#endif

/* Version string, used to identify the library version/options once compiled */
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION "; Options: " CFG_SPI_STR ";";
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION ";";

/* -------------------------------------------------------------------------- */
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
Expand Down Expand Up @@ -212,6 +202,8 @@ void lgw_constant_adjust(void);
int load_firmware(uint8_t target, uint8_t *firmware, uint16_t size) {
int reg_rst;
int reg_sel;
uint8_t fw_check[8192];
int32_t dummy;

/* check parameters */
CHECK_NULL(firmware);
Expand Down Expand Up @@ -244,6 +236,14 @@ int load_firmware(uint8_t target, uint8_t *firmware, uint16_t size) {
/* write the program in one burst */
lgw_reg_wb(LGW_MCU_PROM_DATA, firmware, size);

/* Read back firmware code for check */
lgw_reg_r( LGW_MCU_PROM_DATA, &dummy ); /* bug workaround */
lgw_reg_rb( LGW_MCU_PROM_DATA, fw_check, size );
if (memcmp(firmware, fw_check, size) != 0) {
printf ("ERROR: Failed to load fw %d\n", (int)target);
return -1;
}

/* give back control of the MCU program ram to the MCU */
lgw_reg_w(reg_sel, 1);

Expand Down

6 comments on commit a48215d

@PetteriAimonen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that Semtech SX1301 Reference Board (usb-connected) can no longer be used with lora_gateway library?

@mcoracin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or at least, we don't support it anymore because it was unreliable in term of performances.
We generally use a raspberry pi as host (but any other similar host can do), connected with the reference board through their native SPI connectors.

@PetteriAimonen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Is more information available on in what way it is unreliable? We have seen a few cases were packets get lost or are never transmitted. However our packet load is not particularly heavy, there is 5 seconds or more between packets.

@mcoracin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the transfer rate between the SX1301 board and the host is too slow, the SX1301 FIFO can get full, and from there packet loss happens. If a gateway receives packets from many nodes, the traffic may be too heavy.

Also we are planning to perform some scheduling of downlink transfers, handled by the host, and this need a low latency connection between the host and the SX1301 board which cannot be expected through a USB connexion.

@jmalangoni
Copy link

@jmalangoni jmalangoni commented on a48215d Oct 9, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcoracin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) I don't have a number. But it could be a problem if you have lots of them emitting very frequently (corner case).

But the main (and concrete) issue with USB/FTDI is the latency issue. As I said before, if we want to optimize downlink programming, we need to have a low latency (order of 10ms) between host and sx1301. Which is not verified at all when using FTDI.

Please sign in to comment.