From f991b0e35ad1bd3b999c70e68c518bae91bd36a6 Mon Sep 17 00:00:00 2001 From: Sylvain Miermont Date: Fri, 28 Mar 2014 16:58:48 +0100 Subject: v1.3.0 - Added TX power management. - Added full support for SX1301 reference board. - Changed build system with configuration for multiple chip/radio/band support. - SX125x bandwidth set to 1MHz by default (was 800 kHz). - Solved warnings with 64b integer printf when compiling on x86_64. - Renamed helper programs to reduce the concentrator vs. gateway confusion. --- LICENSE | 49 ++ Makefile | 22 + README | 76 -- VERSION | 1 + libloragw/99-libftdi.rules | 8 + libloragw/Makefile | 222 ++++-- libloragw/README | 32 - libloragw/VERSION | 20 - libloragw/doc/99-libftdi.rules | 8 - libloragw/doc/CHANGELOG.TXT | 80 --- libloragw/doc/INSTALL_FTDI.TXT | 46 -- libloragw/doc/LICENSE.TXT | 24 - libloragw/doc/MANUAL.TXT | 287 -------- libloragw/inc/loragw_aux.h | 9 +- libloragw/inc/loragw_gps.h | 12 +- libloragw/inc/loragw_hal.h | 168 +++-- libloragw/inc/loragw_reg.h | 26 +- libloragw/inc/loragw_spi.h | 22 +- libloragw/install_ftdi.txt | 46 ++ libloragw/library.cfg | 71 +- libloragw/readme.md | 379 ++++++++++ libloragw/src/agc_fw.var | 1028 +++++++++++++-------------- libloragw/src/arb_fw.var | 1028 +++++++++++++-------------- libloragw/src/loragw_aux.c | 11 +- libloragw/src/loragw_gps.c | 4 +- libloragw/src/loragw_hal.c | 569 +++++++++++---- libloragw/src/loragw_reg.c | 38 +- libloragw/src/loragw_spi.ftdi.c | 6 +- libloragw/src/loragw_spi.native.c | 6 +- libloragw/tst/test_loragw_gps.c | 2 +- libloragw/tst/test_loragw_hal.c | 89 ++- libloragw/tst/test_loragw_reg.c | 2 +- libloragw/tst/test_loragw_spi.c | 2 +- loragw_band_survey/LICENSE.TXT | 24 - loragw_band_survey/Makefile | 37 - loragw_band_survey/README | 57 -- loragw_band_survey/obj/.gitkeep | 0 loragw_band_survey/src/loragw_band_survey.c | 454 ------------ loragw_band_survey/src/rssi_fw.var | 529 -------------- loragw_pkt_logger/LICENSE.TXT | 49 -- loragw_pkt_logger/Makefile | 40 -- loragw_pkt_logger/README | 88 --- loragw_pkt_logger/global_conf.json | 46 -- loragw_pkt_logger/inc/parson.h | 100 --- loragw_pkt_logger/local_conf.json | 5 - loragw_pkt_logger/obj/.gitkeep | 0 loragw_pkt_logger/src/loragw_pkt_logger.c | 566 --------------- loragw_pkt_logger/src/parson.c | 649 ----------------- loragw_spi_stress/LICENSE.TXT | 24 - loragw_spi_stress/Makefile | 35 - loragw_spi_stress/README | 68 -- loragw_spi_stress/obj/.gitkeep | 0 loragw_spi_stress/src/loragw_spi_stress.c | 291 -------- loragw_tx_test/LICENSE.TXT | 24 - loragw_tx_test/Makefile | 35 - loragw_tx_test/README | 72 -- loragw_tx_test/obj/.gitkeep | 0 loragw_tx_test/src/loragw_tx_test.c | 293 -------- readme.md | 159 +++++ util_band_survey/Makefile | 59 ++ util_band_survey/obj/.gitkeep | 0 util_band_survey/readme.md | 82 +++ util_band_survey/src/rssi_fw.var | 529 ++++++++++++++ util_band_survey/src/util_band_survey.c | 468 ++++++++++++ util_pkt_logger/Makefile | 82 +++ util_pkt_logger/cfg/global_conf.cn470.json | 51 ++ util_pkt_logger/cfg/global_conf.empty.json | 66 ++ util_pkt_logger/cfg/global_conf.eu433.json | 35 + util_pkt_logger/cfg/global_conf.eu868.json | 45 ++ util_pkt_logger/cfg/global_conf.us915.json | 46 ++ util_pkt_logger/inc/parson.h | 111 +++ util_pkt_logger/local_conf.json | 5 + util_pkt_logger/obj/.gitkeep | 0 util_pkt_logger/readme.md | 143 ++++ util_pkt_logger/src/parson.c | 782 ++++++++++++++++++++ util_pkt_logger/src/util_pkt_logger.c | 570 +++++++++++++++ util_spi_stress/Makefile | 57 ++ util_spi_stress/obj/.gitkeep | 0 util_spi_stress/readme.md | 93 +++ util_spi_stress/src/util_spi_stress.c | 291 ++++++++ util_tx_test/Makefile | 58 ++ util_tx_test/obj/.gitkeep | 0 util_tx_test/readme.md | 98 +++ util_tx_test/src/util_tx_test.c | 335 +++++++++ 84 files changed, 6610 insertions(+), 5434 deletions(-) create mode 100644 LICENSE create mode 100644 Makefile delete mode 100644 README create mode 100644 VERSION create mode 100644 libloragw/99-libftdi.rules delete mode 100644 libloragw/README delete mode 100644 libloragw/VERSION delete mode 100644 libloragw/doc/99-libftdi.rules delete mode 100644 libloragw/doc/CHANGELOG.TXT delete mode 100644 libloragw/doc/INSTALL_FTDI.TXT delete mode 100644 libloragw/doc/LICENSE.TXT delete mode 100644 libloragw/doc/MANUAL.TXT create mode 100644 libloragw/install_ftdi.txt create mode 100644 libloragw/readme.md delete mode 100644 loragw_band_survey/LICENSE.TXT delete mode 100644 loragw_band_survey/Makefile delete mode 100644 loragw_band_survey/README delete mode 100644 loragw_band_survey/obj/.gitkeep delete mode 100644 loragw_band_survey/src/loragw_band_survey.c delete mode 100644 loragw_band_survey/src/rssi_fw.var delete mode 100644 loragw_pkt_logger/LICENSE.TXT delete mode 100644 loragw_pkt_logger/Makefile delete mode 100644 loragw_pkt_logger/README delete mode 100644 loragw_pkt_logger/global_conf.json delete mode 100644 loragw_pkt_logger/inc/parson.h delete mode 100644 loragw_pkt_logger/local_conf.json delete mode 100644 loragw_pkt_logger/obj/.gitkeep delete mode 100644 loragw_pkt_logger/src/loragw_pkt_logger.c delete mode 100644 loragw_pkt_logger/src/parson.c delete mode 100644 loragw_spi_stress/LICENSE.TXT delete mode 100644 loragw_spi_stress/Makefile delete mode 100644 loragw_spi_stress/README delete mode 100644 loragw_spi_stress/obj/.gitkeep delete mode 100644 loragw_spi_stress/src/loragw_spi_stress.c delete mode 100644 loragw_tx_test/LICENSE.TXT delete mode 100644 loragw_tx_test/Makefile delete mode 100644 loragw_tx_test/README delete mode 100644 loragw_tx_test/obj/.gitkeep delete mode 100644 loragw_tx_test/src/loragw_tx_test.c create mode 100644 readme.md create mode 100644 util_band_survey/Makefile create mode 100644 util_band_survey/obj/.gitkeep create mode 100644 util_band_survey/readme.md create mode 100644 util_band_survey/src/rssi_fw.var create mode 100644 util_band_survey/src/util_band_survey.c create mode 100644 util_pkt_logger/Makefile create mode 100644 util_pkt_logger/cfg/global_conf.cn470.json create mode 100644 util_pkt_logger/cfg/global_conf.empty.json create mode 100644 util_pkt_logger/cfg/global_conf.eu433.json create mode 100644 util_pkt_logger/cfg/global_conf.eu868.json create mode 100644 util_pkt_logger/cfg/global_conf.us915.json create mode 100644 util_pkt_logger/inc/parson.h create mode 100644 util_pkt_logger/local_conf.json create mode 100644 util_pkt_logger/obj/.gitkeep create mode 100644 util_pkt_logger/readme.md create mode 100644 util_pkt_logger/src/parson.c create mode 100644 util_pkt_logger/src/util_pkt_logger.c create mode 100644 util_spi_stress/Makefile create mode 100644 util_spi_stress/obj/.gitkeep create mode 100644 util_spi_stress/readme.md create mode 100644 util_spi_stress/src/util_spi_stress.c create mode 100644 util_tx_test/Makefile create mode 100644 util_tx_test/obj/.gitkeep create mode 100644 util_tx_test/readme.md create mode 100644 util_tx_test/src/util_tx_test.c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..62de0d4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,49 @@ +Copyright (c) 2013, SEMTECH S.A. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Semtech corporation nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +--- For the parson library used by the packet logger --- + +Parson ( http://kgabis.github.com/parson/ ) +Copyright (c) 2012 Krzysztof Gabis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5afee5d --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +### Environment constants + +CROSS_COMPILE := +export + +### general build targets + +all: + $(MAKE) all -e -C libloragw + $(MAKE) all -e -C util_band_survey + $(MAKE) all -e -C util_pkt_logger + $(MAKE) all -e -C util_spi_stress + $(MAKE) all -e -C util_tx_test + +clean: + $(MAKE) clean -e -C libloragw + $(MAKE) clean -e -C util_band_survey + $(MAKE) clean -e -C util_pkt_logger + $(MAKE) clean -e -C util_spi_stress + $(MAKE) clean -e -C util_tx_test + +### EOF \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index 7ab10c0..0000000 --- a/README +++ /dev/null @@ -1,76 +0,0 @@ - / _____) _ | | - ( (____ _____ ____ _| |_ _____ ____| |__ - \____ \| ___ | (_ _) ___ |/ ___) _ \ - _____) ) ____| | | || |_| ____( (___| | | | - (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo - -Lora Gateway HAL project -========================= - -1. Core library: libloragw ---------------------------- - -This directory contains the sources of the library to build a gateway based on -a Semtech Lora multi-channel RF receiver. -Once compiled all the code is contained in the libloragw.a file that will be -statically linked (ie. integrated in the final executable). - -The library also comes with a bunch of basic tests programs that are used to -test the different sub-modules of the library. - -2. Helper programs -------------------- - -Those programs are included in the project to provide examples on how to use -the HAL library, and to help the system builder test different parts of it. - -### 2.1. loragw_band_survey ### - -This software is used to scan the RF band and measure background RSSI and some -measurement of interferer pattern. - -### 2.2. loragw_pkt_logger ### - -This software is used to set up a Lora concentrator using a JSON configuration -file and then record all the packets received in a log file, indefinitely, until -the user stops the application. - -### 2.3. loragw_spi_stress ### - -This software is used to check the reliability of the link between the host -platform (on which the program is run) and the Lora concentrator register file -that is the interface through which all interaction with the Lora concentrator -happens. - -### 2.4. loragw_tx_test ### - -This software is used to send test packets with a Lora concentrator. The packets -contain little information, on no protocol (ie. MAC address) information but -can be used to assess the functionality of a gateway downlink using other -gateways as receivers. - -3. Legal notice ----------------- - -The information presented in this project documentation does not form part of -any quotation or contract, is believed to be accurate and reliable and may be -changed without notice. No liability will be accepted by the publisher for any -consequence of its use. Publication thereof does not convey nor imply any -license under patent or other industrial or intellectual property rights. -Semtech assumes no responsibility or liability whatsoever for any failure or -unexpected operation resulting from misuse, neglect improper installation, -repair or improper handling or unusual physical or electrical stress -including, but not limited to, exposure to parameters beyond the specified -maximum ratings or operation outside the specified range. - -SEMTECH PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED TO BE -SUITABLE FOR USE IN LIFE-SUPPORT APPLICATIONS, DEVICES OR SYSTEMS OR OTHER -CRITICAL APPLICATIONS. INCLUSION OF SEMTECH PRODUCTS IN SUCH APPLICATIONS IS -UNDERSTOOD TO BE UNDERTAKEN SOLELY AT THE CUSTOMER’S OWN RISK. Should a -customer purchase or use Semtech products for any such unauthorized -application, the customer shall indemnify and hold Semtech and its officers, -employees, subsidiaries, affiliates, and distributors harmless against all -claims, costs damages and attorney fees which could arise. - -*EOF* \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..589268e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.3.0 \ No newline at end of file diff --git a/libloragw/99-libftdi.rules b/libloragw/99-libftdi.rules new file mode 100644 index 0000000..8487413 --- /dev/null +++ b/libloragw/99-libftdi.rules @@ -0,0 +1,8 @@ +# FTDI Devices: FT232BM/L/Q, FT245BM/L/Q, FT232RL/Q, FT245RL/Q, VNC1L with VDPS Firmware +SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0664", GROUP="plugdev" + +# FTDI Devices: FT2232C/D/L, FT2232HL/Q +SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="0664", GROUP="plugdev" + +# FTDI Devices: FT4232HL/Q +SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", MODE="0664", GROUP="plugdev" diff --git a/libloragw/Makefile b/libloragw/Makefile index 2b91fa8..9d5660b 100644 --- a/libloragw/Makefile +++ b/libloragw/Makefile @@ -1,84 +1,190 @@ -# putting the configuration in a separate file +### get external defined data + +LIBLORAGW_VERSION := `cat ../VERSION` include library.cfg -# constant symbols -CROSS_COMPILE= -CC=gcc -CFLAGS=-O2 -Wall -Wextra -Iinc -I. -C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc -I. +### constant symbols -# configuration-dependant symbols -ifeq ($(LGW_PHY),native) -LDFLAGS=-lrt -endif -ifeq ($(LGW_PHY),ftdi) -LDFLAGS=-lrt -lmpsse -endif +CROSS_COMPILE := +CC := $(CROSS_COMPILE)gcc +AR := $(CROSS_COMPILE)ar -# general build targets +CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal test_loragw_gps +### library.cfg configuration file processing -clean: - rm -f *.a - rm -f test_* - rm -f obj/*.o - rm -f .conf_ok +ifeq ($(CFG_SPI),native) + CFG_SPI_MSG := Linux native SPI driver (/dev/spidev0.0) + 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 + +ifeq ($(CFG_CHIP),sx1301) + CFG_CHIP_MSG := Semtech SX1301 production chip + CFG_CHIP_OPT := CFG_CHIP_1301 +else ifeq ($(CFG_CHIP),fpga1301) + CFG_CHIP_MSG := FPGA containing the SX1301 IP + CFG_CHIP_OPT := CFG_CHIP_FPGA +else + $(error No concentrator chip selected, check library.cfg file.) +endif -.conf_ok: library.cfg - @echo "*** Checking Lora gateway HAL library config ***" - @rm -f .conf_ok -ifeq ($(LGW_PHY),native) - @echo "Selected SPI interface type: Linux native driver" +ifeq ($(CFG_RADIO),sx1257) + CFG_RADIO_MSG := Dual SX1257 transceivers, covering 860-1000 MHz + CFG_RADIO_OPT := CFG_RADIO_1257 +else ifeq ($(CFG_RADIO),sx1255) + CFG_RADIO_MSG := Dual SX1255 transceivers, covering 400-510 MHz + CFG_RADIO_OPT := CFG_RADIO_1255 else -ifeq ($(LGW_PHY),ftdi) - @echo "Selected SPI interface type: FTDI SPI-over-USB bridge" + $(error No radio chip selected, check library.cfg file.) +endif + +ifeq ($(CFG_BAND),full) + CFG_BAND_MSG := Full range supported by the radio(s) + CFG_BAND_OPT := CFG_BAND_FULL +else ifeq ($(CFG_BAND),eu868) + ifeq ($(CFG_RADIO),sx1257) + CFG_BAND_MSG := ETSI 868 (866) MHz band + CFG_BAND_OPT := CFG_BAND_868 + else + $(error The selected radio(s) cannot work in the selected band.) + endif +else ifeq ($(CFG_BAND),us915) + ifeq ($(CFG_RADIO),sx1257) + CFG_BAND_MSG := FCC 915 MHz band + CFG_BAND_OPT := CFG_BAND_915 + else + $(error The selected radio(s) cannot work in the selected band.) + endif +else ifeq ($(CFG_BAND),cn470) + ifeq ($(CFG_RADIO),sx1255) + CFG_BAND_MSG := China 470 MHz band + CFG_BAND_OPT := CFG_BAND_470 + else + $(error The selected radio(s) cannot work in the selected band.) + endif +else ifeq ($(CFG_BAND),eu433) + ifeq ($(CFG_RADIO),sx1255) + CFG_BAND_MSG := ETSI 433 MHz band + CFG_BAND_OPT := CFG_BAND_433 + else + $(error The selected radio(s) cannot work in the selected band.) + endif else - $(error No SPI physical layer selected) + $(warning [Warning] No frequency band selected, full radio capability assumed.) + CFG_BAND_MSG := Full range supported by the radio(s) + CFG_BAND_OPT := CFG_BAND_FULL endif + +ifeq ($(CFG_BRD),dev_nano_868) + CFG_BRD_MSG := FPGA-based nano-concentrator, with 868 MHz SAW filter + CFG_BRD_OPT := CFG_BRD_NANO868 +else ifeq ($(CFG_BRD),ref_1301_57nf) + CFG_BRD_MSG := SX1301 reference board with SX1257 radios, no filters + CFG_BRD_OPT := CFG_BRD_REF1301 +else + $(info [Info] No specific board selected.) + CFG_BRD_MSG := None + CFG_BRD_OPT := CFG_BRD_NONE endif - @echo "*** Config seems ok ***" - @echo "" - @touch .conf_ok -# static library +### linking options -libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o - $(CROSS_COMPILE)ar rcs libloragw.a obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o +ifeq ($(CFG_SPI),native) + LIBS := -lloragw -lrt +else ifeq ($(CFG_SPI),ftdi) + LIBS := -lloragw -lrt -lmpsse +endif -# library module target +### general build targets -obj/loragw_aux.o: .conf_ok src/loragw_aux.c inc/loragw_aux.h - $(CROSS_COMPILE)$(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX) +all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal test_loragw_gps -obj/loragw_spi.o: .conf_ok src/loragw_spi.native.c src/loragw_spi.ftdi.c inc/loragw_spi.h -ifeq ($(LGW_PHY),native) - $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI) -endif -ifeq ($(LGW_PHY),ftdi) - $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI) +clean: + rm -f libloragw.a + rm -f test_loragw_* + rm -f obj/*.o + rm -f inc/config.h + +### transpose library.cfg into a C header file : config.h + +inc/config.h: ../VERSION library.cfg + @echo "*** Checking libloragw library configuration ***" + @rm -f $@ + # File initialization + @echo "#ifndef _LORAGW_CONFIGURATION_H" >> $@ + @echo "#define _LORAGW_CONFIGURATION_H" >> $@ + # 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" >> $@ + # Concentrator chip + @echo "Concentrator chip : $(CFG_CHIP_MSG)" + @echo " #define $(CFG_CHIP_OPT) 1" >> $@ + # Radio chip(s) + @echo "Radio chip(s) : $(CFG_RADIO_MSG)" + @echo " #define $(CFG_RADIO_OPT) 1" >> $@ + # Frequency band + @echo "Frequency band : $(CFG_BAND_MSG)" + @echo " #define $(CFG_BAND_OPT) 1" >> $@ + # Board misc. parameters + @echo "Board misc. param : $(CFG_BRD_MSG)" + @echo " #define $(CFG_BRD_OPT) 1" >> $@ + # Debug options + @echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@ + @echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@ + @echo " #define DEBUG_REG $(DEBUG_REG)" >> $@ + @echo " #define DEBUG_HAL $(DEBUG_HAL)" >> $@ + @echo " #define DEBUG_GPS $(DEBUG_GPS)" >> $@ + # end of file + @echo "#endif" >> $@ + @echo "*** Configuration seems ok ***" + +### library module target + +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: .conf_ok src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h - $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG) +obj/loragw_reg.o: src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h inc/config.h + $(CC) -c $(CFLAGS) $< -o $@ -obj/loragw_hal.o: .conf_ok src/loragw_hal.c inc/loragw_hal.h inc/loragw_reg.h inc/loragw_aux.h VERSION src/arb_fw.var src/agc_fw.var - $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL) +obj/loragw_hal.o: src/loragw_hal.c inc/loragw_hal.h inc/loragw_reg.h inc/loragw_aux.h src/arb_fw.var src/agc_fw.var inc/config.h + $(CC) -c $(CFLAGS) $< -o $@ -obj/loragw_gps.o: .conf_ok src/loragw_gps.c inc/loragw_gps.h - $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_gps.c -o obj/loragw_gps.o $(FLAG_GPS) +obj/loragw_gps.o: src/loragw_gps.c inc/loragw_gps.h inc/config.h + $(CC) -c $(CFLAGS) $< -o $@ + +### static library + +libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o + $(AR) rcs $@ $^ -# test programs +### test programs -test_loragw_spi: tst/test_loragw_spi.c obj/loragw_spi.o - $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS) +test_loragw_spi: tst/test_loragw_spi.c libloragw.a + $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS) -test_loragw_reg: tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o - $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS) +test_loragw_reg: tst/test_loragw_reg.c libloragw.a + $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS) -test_loragw_hal: tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o - $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS) +test_loragw_hal: tst/test_loragw_hal.c libloragw.a + $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS) -test_loragw_gps: tst/test_loragw_gps.c obj/loragw_gps.o obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o - $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_gps.c obj/loragw_gps.o obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_gps $(LDFLAGS) +test_loragw_gps: tst/test_loragw_gps.c libloragw.a + $(CC) $(CFLAGS) -L. $< -o $@ $(LIBS) +### EOF \ No newline at end of file diff --git a/libloragw/README b/libloragw/README deleted file mode 100644 index 821eff6..0000000 --- a/libloragw/README +++ /dev/null @@ -1,32 +0,0 @@ -Lora Gateway HAL library -========================= - -1. Content of subdirectories ------------------------------ - -### 1.1. doc ### - -Contains the user manual, licensing informations, udev rules, etc. - -### 1.2. inc ### - -Contain C header files for the different sub-modules of the library. - -You *MUST* include loragw_hal.h in your application. -You *MAY* include loragw_reg.h in your application if you need direct registers -access. - -### 1.3. obj ### - -Contained the compiled intermediary objects. - -### 1.4. src ### - -Contain library C sources. - -### 1.5. tst ### - -Contain the C sources for test programs to validate SPI link, register access -and hardware functionality. - -*EOF* \ No newline at end of file diff --git a/libloragw/VERSION b/libloragw/VERSION deleted file mode 100644 index e7ee96c..0000000 --- a/libloragw/VERSION +++ /dev/null @@ -1,20 +0,0 @@ -/* Software library version: */ -#define VERSION_LIBRARY "1.2.2" - -/* API version */ -#define VERSION_API "1" - -/* Accepted value of CHIP_ID (SPI registers) must match reg default value in loragw_reg.c */ -#define ACCEPT_CHIP_ID "1" - -/* Accepted value of VERSION (SPI registers) must match reg default value in loragw_reg.c */ -#define ACCEPT_VERSION_REG "103" - -/* Accepted radio components */ -#define INFO_RADIO_CHIP "dual SX1257" - -/* Radio constants defined for the following bands */ -#define INFO_RF_PARAM "863-870 MHz TX&RX" - -/* Library validated on the following concentrator boards */ -#define INFO_REF_HARDWARE "Semtech Nano Concentrator v1 and v2" diff --git a/libloragw/doc/99-libftdi.rules b/libloragw/doc/99-libftdi.rules deleted file mode 100644 index 8487413..0000000 --- a/libloragw/doc/99-libftdi.rules +++ /dev/null @@ -1,8 +0,0 @@ -# FTDI Devices: FT232BM/L/Q, FT245BM/L/Q, FT232RL/Q, FT245RL/Q, VNC1L with VDPS Firmware -SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0664", GROUP="plugdev" - -# FTDI Devices: FT2232C/D/L, FT2232HL/Q -SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="0664", GROUP="plugdev" - -# FTDI Devices: FT4232HL/Q -SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", MODE="0664", GROUP="plugdev" diff --git a/libloragw/doc/CHANGELOG.TXT b/libloragw/doc/CHANGELOG.TXT deleted file mode 100644 index a03e7e0..0000000 --- a/libloragw/doc/CHANGELOG.TXT +++ /dev/null @@ -1,80 +0,0 @@ -Lora Gateway HAL changelog -========================== - - v1.2.2 ---------------------- - - * Added a GPIO toggle on the FTDI SPI module to reset the SX1301 board. - - v1.2.1 ---------------------- - - * Fixed 'floating point exception' crash when concentrator returned a packet with SF=0 (CRC error on Lora header) - * Fixed buggy timezone handling - - v1.2.0 ---------------------- - - * Added feature: new GPS module in the library for synchronization - * Removed feature: no more missed deadline detection in TX because of incompatibility with GPS - * Added documentation for GPS and legal notice - * Added flags in Makefiles for easier cross-compilation - - v1.1.0 ---------------------- - - * Fixed bug 'no TX on radio B' (rfch 1) - * Added feature: concentrator processing delay compensation in the receive() function for accurate 'end of packet' even timestamping - * Added feature: TX 'start delay' compensation in the send() function to emit packet exactly on target timestamp - * Added feature: timestamp counter verification in send() function, return an error if scheduling was too late - * Switched license to 'Revised BSD' - - v1.0.0 (from beta 8) ---------------------- - - * switched FTDI as default SPI phy layer in library.cfg - * fixed a bug in TX power control; still only two TW power available, 14 and 24 dBm - * changed library directory name from loragw_hal to libloragw to follow usual conventions - - Beta 8 (from beta 7) ---------------------- - - * API: lgw_receive now return info on RX frequency and RF path for each packet (no need to keep track of RF/IF settings) - * Unified some portion of the code with the 470 MHz variant of the HAL (use SX1255 radios instead of SX1257) - * Improved AGC and ARB firmwares - * Adding -Wall -Wextra for compilation, fixing all the new warnings for cleaner code - * Fixed bugs in handling of FSK datarate - * test_loragw_hal now dumps the content of all Lora registers after configuration in reg_dump.log - - Beta 7 (from beta 5) ---------------------- - - * Reduced number of SPI transactions to fetch a packet (improved number a packets par second that can be downloaded from gateway) - * Streamlined build process, main target is now a static library: libloragw.a - * Change memory allocation for payload: they are now part of the struct for TX/RX, no need to malloc/free - * All RX chains can use any of the two radios now - * FSK is available and working in TX and RX (variable length mode) - * Calibrated RSSI for FSK - * lgw_connect now check the CHIP_ID - * Added a license file and a changelog - * Added a function returning a version string to allow identification of the version/options once compiled - - Beta 6 -------- - -Not a mainline release, not taken into account in that changelog. - - Beta 5 (from beta 4) ---------------------- - - * Updated registers, firmware and configuration to align with r986 bitstream revision - * Calibrated RSSI for Lora "multi" and Lora "stand alone" modems - * Renamed some confusing TX status code - * Preliminary FSK support - - Beta 4 (from beta 3) ---------------------- - - * Unified build environment with selectable SPI layer (Linux native or FTDI SPI-over-USB bridge) - * Remove the 500 kHz limit on radio bandwith, back to the nominal 800 kHz - * Renamed debug flags diff --git a/libloragw/doc/INSTALL_FTDI.TXT b/libloragw/doc/INSTALL_FTDI.TXT deleted file mode 100644 index d26ad4b..0000000 --- a/libloragw/doc/INSTALL_FTDI.TXT +++ /dev/null @@ -1,46 +0,0 @@ -# / _____) _ | | -# ( (____ _____ ____ _| |_ _____ ____| |__ -# \____ \| ___ | (_ _) ___ |/ ___) _ \ -# _____) ) ____| | | || |_| ____( (___| | | | -# (______/|_____)_|_|_| \__)_____)\____)_| |_| -# ©2013 Semtech-Cycleo -# -# Description: -# Installation procedure for FTDI SPI-over-USB dependencies - -# [STEP 1] Install libftdi -sudo apt-get install libftdi-dev - -# this should install : -# - libftdi-dev 0.19-4 (armhf) -# - libftdil 0.19-4 (armhf) -# - libusb-dev 2:0.1.12-20 (armhf) - -# [STEP 2] Download and unpack the libMPSSE 1.3 -# File must match SHA1 Checksum: 1b994a23b118f83144261e3e786c43df74a81cd5 -wget http://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz -sha1sum libmpsse-1.3.tar.gz -tar -xzvf libmpsse-1.3.tar.gz - -# Go to the src directory and install the library -./configure --disable-python -make -sudo make install -# Static and dynamic libraries compiled code is put into /usr/local/lib -# Header file is put into /usr/local/include - -# On the Pcduino, you must regenerate the library cache (might some time). -sudo ldconfig - -# [STEP 3] to allow non-root applications to access the FTDI device on USB -# copy the provided 99-libftdi.rules file in /etc/udev/rules.d -# For the nano board, only the FT2232H line is required. -# Non-root users members of plugdev group will be able to access the device. - -# [STEP 4] Unpack the Lora Gateway HAL and go to its directory. -# Configure build options in library.cfg, then build the library and examples. -make all - -# [STEP 5] Connect a nanoconcentrator and run test_loragw_reg to test that -# you have access to Lora registers. -# Less than 50 registers of the ~300 registers should return a mismatch. diff --git a/libloragw/doc/LICENSE.TXT b/libloragw/doc/LICENSE.TXT deleted file mode 100644 index ff287f3..0000000 --- a/libloragw/doc/LICENSE.TXT +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2013, SEMTECH S.A. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the Semtech corporation nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/libloragw/doc/MANUAL.TXT b/libloragw/doc/MANUAL.TXT deleted file mode 100644 index 7fdefeb..0000000 --- a/libloragw/doc/MANUAL.TXT +++ /dev/null @@ -1,287 +0,0 @@ - / _____) _ | | - ( (____ _____ ____ _| |_ _____ ____| |__ - \____ \| ___ | (_ _) ___ |/ ___) _ \ - _____) ) ____| | | || |_| ____( (___| | | | - (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo - -Lora Gateway HAL user manual -============================ - -1. Introduction ---------------- - -The Lora Gateway Hardware Abstraction Layer is a C library that allow you to -use a Semtech Lora gateway hardware through a reduced number of high level C -functions to configure the hardware, send and receive packets. - -The Semtech Lora gateway is a digital multi-channel multi-standard packet radio -used to send and receive packets wirelessly using Lora or FSK modulations. - - -2. Components of the library ----------------------------- - -The library is composed of 5 modules: - -* loragw_hal -* loragw_reg -* loragw_spi -* loragw_aux -* loragw_gps - -The library also contains 4 test programs to demonstrate code use and check -functionality. - -### 2.1. loragw_hal ### - -This is the main module and contains the high level functions to configure and -use the Lora gateway: - -* lgw_rxrf_setconf, to set the configuration of the radio channels -* lgw_rxif_setconf, to set the configuration of the IF+modem channels -* lgw_start, to apply the set configuration to the hardware and start it -* lgw_stop, to stop the hardware -* lgw_receive, to fetch packets if any was received -* lgw_send, to send a single packet (non-blocking, see warning in usage section) -* lgw_status, to check when a packet has effectively been sent - -For an standard application, include only this module. -The use of this module is detailed on the usage section. - -### 2.2. loragw_reg ### - -This module is used to access to the Lora gateway registers by name instead of -by address: - -* lgw_connect, to initialise and check the connection with the hardware -* lgw_disconnect, to disconnect the hardware -* lgw_soft_reset, to reset the whole hardware by resetting the register array -* lgw_reg_check, to check all registers vs. their default value and output the -result to a file -* lgw_reg_r, read a named register -* lgw_reg_w, write a named register -* lgw_reg_rb, read a name register in burst -* lgw_reg_wb, write a named register in burst - -This module handles pagination, read-only registers protection, multi-byte -registers management, signed registers management, read-modify-write routines -for sub-byte registers and read/write burst fragmentation to respect SPI -maximum burst length constraints. - -It make the code much easier to read and to debug. -Moreover, if registers are relocated between different hardware revisions but -keep the same function, the code written using register names can be reused "as -is". - -If you need access to all the registers, include this module in your -application. - -**/!\ Warning** please be sure to have a good understanding of the Lora gateway -inner working before accessing the internal registers directly. - -### 2.3. loragw_spi ### - -This module contains the functions to access the Lora gateway register array -through the SPI interface: - -* lgw_spi_r to read one byte -* lgw_spi_w to write one byte -* lgw_spi_rb to read two bytes or more -* lgw_spi_wb to write two bytes or more - -Please *do not* include that module directly into your application. - -**/!\ Warning** Accessing the Lora gateway register array without the checks -and safety provided by the functions in loragw_reg is not recommended. - -### 2.4. loragw_aux ### - -This module contains a single host-dependant function wait_ms to pause for a -defined amount of milliseconds. - -The procedure to start and configure the Lora gateway hardware contained in the -loragw_hal module requires to wait for several milliseconds at certain steps, -typically to allow for supply voltages or clocks to stabilize after been -switched on. - -An accuracy of 1 ms or less is ideal. -If your system doesn't allow that level of accuracy, make sure that the actual -delay is *longer* that the time specified when the function is called (ie. -wait_ms(X) *MUST NOT* before X milliseconds under any circumstance). - -If the minimum delays are not guaranteed during the configuration and start -procedure, the hardware might not work at nominal performance. -Most likely, it will not work at all. - -### 2.5. loragw_gps ### - -This module contains functions to synchronize the concentrator internal -counter with an absolute time reference, in our case a GPS satellite receiver. - -The internal concentrator counter is used to timestamp incoming packets and to -triggers outgoing packets with a microsecond accuracy. -In some cases, it might be useful to be able to transform that internal -timestamp (that is independent for each concentrator running in a typical -networked system) into an absolute UTC time. - -In a typical implementation a GPS specific thread will be called, doing the -following things after opening the serial port: - -* blocking reads on the serial port (using system read() function) -* parse NMEA sentences (using lgw_parse_nmea) - -And each time an RMC sentence has been received: -* get the concentrator timestamp (using lgw_get_trigcnt, mutex needed to - protect access to the concentrator) -* get the UTC time contained in the NMEA sentence (using lgw_gps_get) -* call the lgw_gps_sync function (use mutex to protect the time reference that - should be a global shared variable). - -Then, in other threads, you can simply used that continuously adjusted time -reference to convert internal timestamps to UTC time (using lgw_cnt2utc) or -the other way around (using lgw_utc2cnt). - -3. Software dependencies ------------------------- - -The library is written following ANSI C conventions but using C99 explicit -length data type for all data exchanges with hardware and for parameters. - -The loragw_aux module contains POSIX dependant functions for millisecond -accuracy pause. -For embedded platforms, the function could be rewritten using hardware times. - -All modules use the fprintf(stderr,...) function to display debug diagnostic -messages if the DEBUG_xxx is set to 1 in library.cfg - -Depending on config, SPI module needs LibMPSSE to access the FTDI SPI-over-USB -bridge. Please go to that URL to download that library: -http://code.google.com/p/libmpsse/ - -The code was tested with version 1.3 of LibMPSSE: -http://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz -SHA1 Checksum: 1b994a23b118f83144261e3e786c43df74a81cd5 - -That library has some dependencies itself, please read the installation -instructions. - - -4. Hardware dependencies ------------------------- - -### 4.1. Hardware revision ### - -The loragw_reg and loragw_hal are written for a specific version on the Semtech -hardware (IP and/or silicon revision). -All relevant details are contained in the VERSION.TXT file. - -The library will not work if there is a mismatch between the hardware version -and the library version. You can use the test program test_loragw_reg to check -if the hardware registers match their software declaration. - -### 4.2. SPI communication ### - -loragw_spi contains 4 SPI functions (read, write, burst read, burst write) that -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) -* 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 - -### 4.3. GPS receiver (or other GNSS system) ### - -To use the GPS module of the library, the host must be connected to a GPS -receiver via a serial link (or an equivalent receiver using a different -satellite constellation). -The serial link must appear as a "tty" device in the /dev/ directory, and the -user launching the program must have the proper system rights to read and -write on that device. -Use `chmod a+rw` to allow all users to access that specific tty device, or use -sudo to run all your programs (eg. `sudo ./test_loragw_gps`). - -In the current revision, the library only reads data from the serial port, -expecting to receive NMEA frames that are generally sent by GPS receivers as -soon as they are powered up. - -The GPS receiver __MUST__ send RMC NMEA sentences (starting with "$GRMC") shortly after sending a PPS pulse on to allow internal -concentrator timestamps to be converted to absolute UTC time. -If the GPS receiver sends a GGA sentence, the gateway 3D position will also be -available. - -The PPS pulse must be sent to the pin 22 of connector CONN400 on the Semtech -FPGA-based nano-concentrator board. Ground is available on pins 2 and 12 of -the same connector. -The pin is loaded by an FPGA internal pull-down, and the signal level coming -in the FPGA must be 3.3V. -Timing is captured on the rising edge of the PPS signal. - -5. Usage --------- - -### 5.1. Setting the software environment ### - -For a typical application you need to: - -* include loragw_hal.h in your program source -* link to the libloragw.a static library during compilation -* link to the librt library due to loragw_aux dependencies (timing functions) -* link to the libmpsse library if you use a FTDI SPI-over-USB bridge - -For an application that will also access the concentrator configuration -registers directly (eg. for advanced configuration) you also need to: - -* include loragw_reg.h in your program source - -### 5.2. Using the software API ### - -To use the HAL in your application, you must follow some basic rules: - -* configure the radios path and IF+modem path before starting the radio -* the configuration is only transferred to hardware when you call the *start* -function -* you cannot receive packets until one (or +) radio is enabled AND one (or +) -IF+modem part is enabled AND the gateway is started -* you cannot send packets until one (or +) radio is enabled AND the gateway is -started -* you must stop the gateway before changing the configuration - -A typical application flow for using the HAL is the following: - - - - loop { - - - - } - - -**/!\ Warning** The lgw_send function is non-blocking and returns while the -Lora gateway is still sending the packet, or even before the packet has started -to be transmitted if the packet is triggered on a future event. -While a packet is emitted, no packet can be received (limitation intrinsic to -most radio frequency systems). - -Your application *must* take into account the time it takes to send a packet or -check the status (using lgw_status) before attempting to send another packet. - -Trying to send a packet while the previous packet has not finished being send -will result in the previous packet not being sent or being sent only partially -(resulting in a CRC error in the receiver). - -### 5.3. Debugging mode ### - -To debug your application, it might help to compile the loragw_hal function -with the debug messages activated (set DEBUG_HAL=1 in library.cfg). -It then send a lot of details, including detailed error messages to *stderr*. - - -*EOF* \ No newline at end of file diff --git a/libloragw/inc/loragw_aux.h b/libloragw/inc/loragw_aux.h index 8f485b4..feb0594 100644 --- a/libloragw/inc/loragw_aux.h +++ b/libloragw/inc/loragw_aux.h @@ -4,10 +4,10 @@ \____ \| ___ | (_ _) ___ |/ ___) _ \ _____) ) ____| | | || |_| ____( (___| | | | (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo + (C)2013 Semtech-Cycleo Description: - Lora gateway library common auxiliary functions + LoRa concentrator HAL common auxiliary functions License: Revised BSD License, see LICENSE.TXT file include in the project Maintainer: Sylvain Miermont @@ -17,6 +17,11 @@ Maintainer: Sylvain Miermont #ifndef _LORAGW_AUX_H #define _LORAGW_AUX_H +/* -------------------------------------------------------------------------- */ +/* --- DEPENDANCIES --------------------------------------------------------- */ + +#include "config.h" /* library configuration options (dynamically generated) */ + /* -------------------------------------------------------------------------- */ /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */ diff --git a/libloragw/inc/loragw_gps.h b/libloragw/inc/loragw_gps.h index 3884fd5..3f771e4 100644 --- a/libloragw/inc/loragw_gps.h +++ b/libloragw/inc/loragw_gps.h @@ -4,7 +4,7 @@ \____ \| ___ | (_ _) ___ |/ ___) _ \ _____) ) ____| | | || |_| ____( (___| | | | (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo + (C)2013 Semtech-Cycleo Description: Library of functions to manage a GNSS module (typically GPS) for accurate @@ -33,6 +33,8 @@ Maintainer: Sylvain Miermont #include /* time library */ #include /* speed_t */ +#include "config.h" /* library configuration options (dynamically generated) */ + /* -------------------------------------------------------------------------- */ /* --- PUBLIC TYPES --------------------------------------------------------- */ @@ -44,7 +46,7 @@ struct tref { time_t systime; /*!> system time when solution was calculated */ uint32_t count_us; /*!> reference concentrator internal timestamp */ struct timespec utc; /*!> reference UTC time (from GPS) */ - double xtal_err; /*!> clock error estimation (eg. <1 'slow' XTAL) */ + double xtal_err; /*!> raw clock error (eg. <1 'slow' XTAL) */ }; /** @@ -119,7 +121,7 @@ lock must be acquired before calling either function. enum gps_msg lgw_parse_nmea(char* serial_buff, int buff_size); /** -@brief Get the GPS solution (space & time) for the gateway +@brief Get the GPS solution (space & time) for the concentrator @param utc pointer to store UTC time, with ns precision (NULL to ignore) @param loc pointer to store coordinates (NULL to ignore) @@ -150,7 +152,7 @@ int lgw_gps_sync(struct tref* ref, uint32_t count_us, struct timespec utc); @brief Convert concentrator timestamp counter value to UTC time @param ref time reference structure required for time conversion -@param count_us internal timestamp counter of a Lora gateway +@param count_us internal timestamp counter of the LoRa concentrator @param utc pointer to store UTC time, with ns precision (leap seconds ignored) @return success if the function was able to convert timestamp to UTC @@ -165,7 +167,7 @@ int lgw_cnt2utc(struct tref ref, uint32_t count_us, struct timespec* utc); @param ref time reference structure required for time conversion @param utc UTC time, with ns precision (leap seconds are ignored) -@param count_us pointer to store internal timestamp counter of a Lora gateway +@param count_us pointer to store internal timestamp counter of LoRa concentrator @return success if the function was able to convert UTC to timestamp This function is typically used when a packet must be sent at an accurate time diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h index 022313f..27ca1a2 100644 --- a/libloragw/inc/loragw_hal.h +++ b/libloragw/inc/loragw_hal.h @@ -4,10 +4,10 @@ \____ \| ___ | (_ _) ___ |/ ___) _ \ _____) ) ____| | | || |_| ____( (___| | | | (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo + (C)2013 Semtech-Cycleo Description: - Lora gateway Hardware Abstraction Layer + LoRa concentrator Hardware Abstraction Layer License: Revised BSD License, see LICENSE.TXT file include in the project Maintainer: Sylvain Miermont @@ -23,12 +23,14 @@ Maintainer: Sylvain Miermont #include /* C99 types */ #include /* bool type */ +#include "config.h" /* library configuration options (dynamically generated) */ + /* -------------------------------------------------------------------------- */ /* --- PUBLIC MACROS -------------------------------------------------------- */ #define IS_LORA_BW(bw) ((bw == BW_125KHZ) || (bw == BW_250KHZ) || (bw == BW_500KHZ)) #define IS_LORA_STD_DR(dr) ((dr == DR_LORA_SF7) || (dr == DR_LORA_SF8) || (dr == DR_LORA_SF9) || (dr == DR_LORA_SF10) || (dr == DR_LORA_SF11) || (dr == DR_LORA_SF12)) -#define IS_LORA_MULTI_DR(dr) ((dr & ~DR_LORA_MULTI) == 0) /* ones outside of DR_LORA_MULTI bitmask -> not a combination of Lora datarates */ +#define IS_LORA_MULTI_DR(dr) ((dr & ~DR_LORA_MULTI) == 0) /* ones outside of DR_LORA_MULTI bitmask -> not a combination of LoRa datarates */ #define IS_LORA_CR(cr) ((cr == CR_LORA_4_5) || (cr == CR_LORA_4_6) || (cr == CR_LORA_4_7) || (cr == CR_LORA_4_8)) #define IS_FSK_BW(bw) ((bw >= 1) && (bw <= 7)) @@ -43,42 +45,104 @@ Maintainer: Sylvain Miermont #define LGW_HAL_SUCCESS 0 #define LGW_HAL_ERROR -1 -/* hardware characteristics */ -#define LGW_RF_CHAIN_NB 2 /* number of RF chains */ -#define LGW_IF_CHAIN_NB 10 /* number of IF+modem RX chains */ -#define LGW_MULTI_NB 4 /* number of Lora 'multi SF' chains */ - -#define LGW_PKT_FIFO_SIZE 8 /* depth of the RX packet FIFO */ -#define LGW_DATABUFF_SIZE 1024 /* size in bytes of the RX data buffer (contains payload & metadata) */ -#define LGW_REF_BW 125000 /* typical bandwidth of data channel */ -#define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */ +/* radio-specific parameters */ +#if ((CFG_RADIO_1257 == 1) || (CFG_RADIO_1255 == 1)) + #define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */ + #define LGW_RF_CHAIN_NB 2 /* number of RF chains */ + #define LGW_RF_RX_BANDWIDTH { 1000000, 1000000} /* bandwidth of the radios */ +#endif -/* to use those parameters, declare a local constant, and use 'rf_chain' as index */ -#define LGW_RF_RX_LOWFREQ {863000000, 863000000} /* lower limit of the usable band in RX for each radio */ -#define LGW_RF_RX_UPFREQ {870000000, 870000000} /* upper limit of the usable band in RX for each radio */ -#define LGW_RF_RX_BANDWIDTH {800000, 800000} /* bandwidth of the radios */ -#define LGW_RF_TX_LOWFREQ {863000000, 863000000} /* lower limit of the usable band in TX for each radio */ -#define LGW_RF_TX_UPFREQ {870000000, 870000000} /* upper limit of the usable band in TX for each radio */ +/* band-specific parameters */ +/* to use array parameters, declare a local const and use 'rf_chain' as index */ +#if (CFG_BAND_FULL == 1) + #if (CFG_RADIO_1257 == 1) + #define LGW_RF_RX_LOWFREQ { 862000000, 862000000} /* lower limit of the usable band in RX for each radio */ + #define LGW_RF_RX_UPFREQ {1020000000,1020000000} /* upper limit of the usable band in RX for each radio */ + #define LGW_RF_TX_LOWFREQ { 862000000, 862000000} /* lower limit of the usable band in TX for each radio */ + #define LGW_RF_TX_UPFREQ {1020000000,1020000000} /* upper limit of the usable band in TX for each radio */ + #elif (CFG_RADIO_1255 == 1) + #define LGW_RF_RX_LOWFREQ { 400000000, 400000000} + #define LGW_RF_RX_UPFREQ { 510000000, 510000000} + #define LGW_RF_TX_LOWFREQ { 400000000, 400000000} + #define LGW_RF_TX_UPFREQ { 510000000, 510000000} + #endif +#elif (CFG_BAND_868 == 1) + #define LGW_RF_RX_LOWFREQ { 863000000, 863000000} + #define LGW_RF_RX_UPFREQ { 870000000, 870000000} + #define LGW_RF_TX_LOWFREQ { 863000000, 863000000} + #define LGW_RF_TX_UPFREQ { 870000000, 870000000} +#elif (CFG_BAND_915 == 1) + #define LGW_RF_RX_LOWFREQ { 902000000, 902000000} + #define LGW_RF_RX_UPFREQ { 928000000, 928000000} + #define LGW_RF_TX_LOWFREQ { 902000000, 902000000} + #define LGW_RF_TX_UPFREQ { 928000000, 928000000} +#elif (CFG_BAND_470 == 1) + #define LGW_RF_RX_LOWFREQ { 470000000, 470000000} + #define LGW_RF_RX_UPFREQ { 510000000, 510000000} + #define LGW_RF_TX_LOWFREQ { 470000000, 470000000} + #define LGW_RF_TX_UPFREQ { 510000000, 510000000} +#elif (CFG_BAND_433 == 1) + #define LGW_RF_RX_LOWFREQ { 433050000, 433050000} + #define LGW_RF_RX_UPFREQ { 434790000, 434790000} + #define LGW_RF_TX_LOWFREQ { 433050000, 433050000} + #define LGW_RF_TX_UPFREQ { 434790000, 434790000} +#endif /* type of if_chain + modem */ #define IF_UNDEFINED 0 -#define IF_LORA_STD 0x10 /* if + standard single-SF Lora modem */ -#define IF_LORA_MULTI 0x11 /* if + Lora receiver with multi-SF capability */ +#define IF_LORA_STD 0x10 /* if + standard single-SF LoRa modem */ +#define IF_LORA_MULTI 0x11 /* if + LoRa receiver with multi-SF capability */ #define IF_FSK_STD 0x20 /* if + standard FSK modem */ -/* configuration of available IF chains and modems on the hardware */ -/* to use, declare a local constant, and use 'if_chain' as index */ -#define LGW_IFMODEM_CONFIG {\ - IF_LORA_MULTI, \ - IF_LORA_MULTI, \ - IF_LORA_MULTI, \ - IF_LORA_MULTI, \ - IF_UNDEFINED, \ - IF_UNDEFINED, \ - IF_UNDEFINED, \ - IF_UNDEFINED, \ - IF_LORA_STD, \ - IF_FSK_STD } +/* concentrator chipset-specific parameters */ +/* to use array parameters, declare a local const and use 'if_chain' as index */ +#if ((CFG_CHIP_1301 == 1) || (CFG_CHIP_FPGA == 1)) + #define LGW_IF_CHAIN_NB 10 /* number of IF+modem RX chains */ + #define LGW_PKT_FIFO_SIZE 8 /* depth of the RX packet FIFO */ + #define LGW_DATABUFF_SIZE 1024 /* size in bytes of the RX data buffer (contains payload & metadata) */ + #define LGW_REF_BW 125000 /* typical bandwidth of data channel */ +#endif + +#if (CFG_CHIP_1301 == 1) + #define LGW_MULTI_NB 8 /* number of LoRa 'multi SF' chains */ + #define LGW_IFMODEM_CONFIG {\ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_STD, \ + IF_FSK_STD } /* configuration of available IF chains and modems on the hardware */ +#elif (CFG_CHIP_FPGA == 1) + #define LGW_MULTI_NB 4 /* number of LoRa 'multi SF' chains */ + #define LGW_IFMODEM_CONFIG {\ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_LORA_MULTI, \ + IF_UNDEFINED, \ + IF_UNDEFINED, \ + IF_UNDEFINED, \ + IF_UNDEFINED, \ + IF_LORA_STD, \ + IF_FSK_STD } /* configuration of available IF chains and modems on the hardware */ +#endif + +/* board-specific parameters */ +/* to use array parameters, declare a local const and use 'rf_chain' as index */ +#if (CFG_BRD_NANO868 == 1) + #define LGW_RF_TX_ENABLE { true, true} /* both radio A and B are usable in TX */ + #define LGW_RF_CLKOUT { true, true} /* both radios have clkout enabled */ +#elif (CFG_BRD_REF1301 == 1) + #define LGW_RF_TX_ENABLE { true,false} /* radio B TX output is disconnected */ + #define LGW_RF_CLKOUT {false, true} /* radio A clkout disabled for spur optimization */ +#elif (CFG_BRD_NONE == 1) + #define LGW_RF_TX_ENABLE { true, true} /* both radio A and B are usable in TX */ + #define LGW_RF_CLKOUT { true, true} /* both radios have clkout enabled */ +#endif /* values available for the 'modulation' parameters */ /* NOTE: arbitrary values */ @@ -86,7 +150,7 @@ Maintainer: Sylvain Miermont #define MOD_LORA 0x10 #define MOD_FSK 0x20 -/* values available for the 'bandwidth' parameters (Lora & FSK) */ +/* values available for the 'bandwidth' parameters (LoRa & FSK) */ /* NOTE: directly encode FSK RX bandwidth, do not change */ #define BW_UNDEFINED 0 #define BW_500KHZ 0x01 @@ -98,7 +162,7 @@ Maintainer: Sylvain Miermont #define BW_7K8HZ 0x07 /* values available for the 'datarate' parameters */ -/* NOTE: Lora values used directly to code SF bitmask in 'multi' modem, do not change */ +/* NOTE: LoRa values used directly to code SF bitmask in 'multi' modem, do not change */ #define DR_UNDEFINED 0 #define DR_LORA_SF7 0x02 #define DR_LORA_SF8 0x04 @@ -111,7 +175,7 @@ Maintainer: Sylvain Miermont #define DR_FSK_MIN 500 #define DR_FSK_MAX 250000 -/* values available for the 'coderate' parameters (Lora only) */ +/* values available for the 'coderate' parameters (LoRa only) */ /* NOTE: arbitrary values */ #define CR_UNDEFINED 0 #define CR_LORA_4_5 0x01 @@ -185,16 +249,16 @@ struct lgw_pkt_rx_s { uint32_t freq_hz; /*!> central frequency of the IF chain */ uint8_t if_chain; /*!> by which IF chain was packet received */ uint8_t status; /*!> status of the received packet */ - uint32_t count_us; /*!> internal gateway counter for timestamping, 1 microsecond resolution */ + uint32_t count_us; /*!> internal concentrator counter for timestamping, 1 microsecond resolution */ uint8_t rf_chain; /*!> through which RF chain the packet was received */ uint8_t modulation; /*!> modulation used by the packet */ - uint8_t bandwidth; /*!> modulation bandwidth (Lora only) */ - uint32_t datarate; /*!> RX datarate of the packet (SF for Lora) */ - uint8_t coderate; /*!> error-correcting code of the packet (Lora only) */ + uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */ + uint32_t datarate; /*!> RX datarate of the packet (SF for LoRa) */ + uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */ float rssi; /*!> average packet RSSI in dB */ - float snr; /*!> average packet SNR, in dB (Lora only) */ - float snr_min; /*!> minimum packet SNR, in dB (Lora only) */ - float snr_max; /*!> maximum packet SNR, in dB (Lora only) */ + float snr; /*!> average packet SNR, in dB (LoRa only) */ + float snr_min; /*!> minimum packet SNR, in dB (LoRa only) */ + float snr_max; /*!> maximum packet SNR, in dB (LoRa only) */ uint16_t crc; /*!> CRC that was received in the payload */ uint16_t size; /*!> payload size in bytes */ uint8_t payload[256]; /*!> buffer containing the payload */ @@ -211,14 +275,14 @@ struct lgw_pkt_tx_s { uint8_t rf_chain; /*!> through which RF chain will the packet be sent */ int8_t rf_power; /*!> TX power, in dBm */ uint8_t modulation; /*!> modulation to use for the packet */ - uint8_t bandwidth; /*!> modulation bandwidth (Lora only) */ - uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for Lora) */ - uint8_t coderate; /*!> error-correcting code of the packet (Lora only) */ - bool invert_pol; /*!> invert signal polarity, for orthogonal downlinks (Lora only) */ + uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */ + uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for LoRa) */ + uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */ + bool invert_pol; /*!> invert signal polarity, for orthogonal downlinks (LoRa only) */ uint8_t f_dev; /*!> frequency deviation, in kHz (FSK only) */ uint16_t preamble; /*!> set the preamble length, 0 for default */ bool no_crc; /*!> if true, do not send a CRC in the packet */ - bool no_header; /*!> if true, enable implicit header mode (Lora), fixed length (FSK) */ + bool no_header; /*!> if true, enable implicit header mode (LoRa), fixed length (FSK) */ uint16_t size; /*!> payload size in bytes */ uint8_t payload[256]; /*!> buffer containing the payload */ }; @@ -243,19 +307,19 @@ int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s conf); int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s conf); /** -@brief Connect to the Lora gateway, reset it and configure it according to previously set parameters +@brief Connect to the LoRa concentrator, reset it and configure it according to previously set parameters @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else */ int lgw_start(void); /** -@brief Stop the Lora gateway and disconnect it +@brief Stop the LoRa concentrator and disconnect it @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else */ int lgw_stop(void); /** -@brief A non-blocking function that will fetch up to 'max_pkt' packets from the Lora gateway FIFO and data buffer +@brief A non-blocking function that will fetch up to 'max_pkt' packets from the LoRa concentrator FIFO and data buffer @param max_pkt maximum number of packet that must be retrieved (equal to the size of the array of struct) @param pkt_data pointer to an array of struct that will receive the packet metadata and payload pointers @return LGW_HAL_ERROR id the operation failed, else the number of packets retrieved @@ -270,7 +334,7 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data); int lgw_send(struct lgw_pkt_tx_s pkt_data); /** -@brief Give the the status of different part of the Lora gateway +@brief Give the the status of different part of the LoRa concentrator @param select is used to select what status we want to know @param code is used to return the status code @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else diff --git a/libloragw/inc/loragw_reg.h b/libloragw/inc/loragw_reg.h index 3b74bc3..1c6e9e7 100644 --- a/libloragw/inc/loragw_reg.h +++ b/libloragw/inc/loragw_reg.h @@ -4,10 +4,10 @@ \____ \| ___ | (_ _) ___ |/ ___) _ \ _____) ) ____| | | || |_| ____( (___| | | | (______/|_____)_|_|_| \__)_____)\____)_| |_| - ©2013 Semtech-Cycleo + (C)2013 Semtech-Cycleo Description: - Functions used to handle a single Lora gateway. + Functions used to handle a single LoRa concentrator. Registers are addressed by name. Multi-bytes registers are handled automatically. Read-modify-write is handled automatically. @@ -26,6 +26,8 @@ Maintainer: Sylvain Miermont #include /* C99 types */ #include /* bool type */ +#include "config.h" /* library configuration options (dynamically generated) */ + /* -------------------------------------------------------------------------- */ /* --- PUBLIC CONSTANTS ----------------------------------------------------- */ @@ -34,7 +36,7 @@ Maintainer: Sylvain Miermont /* auto generated register mapping for C code : 11-Jul-2013 13:20:40 -this file contains autogenerated C struct used to access the LORA register from the Primer firm