diff options
| author | Sylvain Miermont <smiermont@semtech.com> | 2013-09-19 15:46:06 +0200 |
|---|---|---|
| committer | Sylvain Miermont <smiermont@semtech.com> | 2013-10-23 14:03:05 +0200 |
| commit | b922932d1c9869d82042b600db2382d8c15f63dc (patch) | |
| tree | b97b83a74f5b3faadb674867f6cc004b8426a8a9 | |
| parent | 68b8b7a70d9104888997174506fbbaa0abb12a4c (diff) | |
| download | lora_gateway-b922932d1c9869d82042b600db2382d8c15f63dc.tar.gz lora_gateway-b922932d1c9869d82042b600db2382d8c15f63dc.tar.bz2 lora_gateway-b922932d1c9869d82042b600db2382d8c15f63dc.zip | |
Beta 7 (beta6 skipped)v1.b7
- API: change memory allocation for payload, they are now part of the struct for TX/RX, no need to malloc/free
- 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
- 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
| -rw-r--r-- | libloragw/Makefile (renamed from loragw_hal/Makefile) | 37 | ||||
| -rw-r--r-- | libloragw/README.TXT | 30 | ||||
| -rw-r--r-- | libloragw/VERSION | 20 | ||||
| -rw-r--r-- | libloragw/doc/99-libftdi.rules (renamed from loragw_hal/99-libftdi.rules) | 0 | ||||
| -rw-r--r-- | libloragw/doc/CHANGELOG.TXT | 35 | ||||
| -rw-r--r-- | libloragw/doc/INSTALL_FTDI.TXT (renamed from loragw_hal/INSTALL_FTDI.TXT) | 0 | ||||
| -rw-r--r-- | libloragw/doc/LICENSE.TXT | 8 | ||||
| -rw-r--r-- | libloragw/doc/MANUAL.TXT (renamed from loragw_hal/README.txt) | 67 | ||||
| -rw-r--r-- | libloragw/inc/loragw_aux.h (renamed from loragw_hal/inc/loragw_aux.h) | 0 | ||||
| -rw-r--r-- | libloragw/inc/loragw_hal.h (renamed from loragw_hal/inc/loragw_hal.h) | 101 | ||||
| -rw-r--r-- | libloragw/inc/loragw_reg.h (renamed from loragw_hal/inc/loragw_reg.h) | 0 | ||||
| -rw-r--r-- | libloragw/inc/loragw_spi.h (renamed from loragw_hal/inc/loragw_spi.h) | 0 | ||||
| -rw-r--r-- | libloragw/library.cfg (renamed from loragw_hal/library.cfg) | 0 | ||||
| -rw-r--r-- | libloragw/obj/.gitkeep (renamed from loragw_hal/obj/.gitkeep) | 0 | ||||
| -rw-r--r-- | libloragw/src/agc_fw.var (renamed from loragw_hal/src/agc_fw.var) | 0 | ||||
| -rw-r--r-- | libloragw/src/arb_fw.var (renamed from loragw_hal/src/arb_fw.var) | 0 | ||||
| -rw-r--r-- | libloragw/src/loragw_aux.c (renamed from loragw_hal/src/loragw_aux.c) | 0 | ||||
| -rw-r--r-- | libloragw/src/loragw_hal.c (renamed from loragw_hal/src/loragw_hal.c) | 278 | ||||
| -rw-r--r-- | libloragw/src/loragw_reg.c (renamed from loragw_hal/src/loragw_reg.c) | 14 | ||||
| -rw-r--r-- | libloragw/src/loragw_spi.ftdi.c (renamed from loragw_hal/src/loragw_spi.ftdi.c) | 0 | ||||
| -rw-r--r-- | libloragw/src/loragw_spi.native.c (renamed from loragw_hal/src/loragw_spi.native.c) | 0 | ||||
| -rw-r--r-- | libloragw/tst/test_loragw_hal.c (renamed from loragw_hal/test/test_loragw_hal.c) | 90 | ||||
| -rw-r--r-- | libloragw/tst/test_loragw_reg.c (renamed from loragw_hal/test/test_loragw_reg.c) | 0 | ||||
| -rw-r--r-- | libloragw/tst/test_loragw_spi.c (renamed from loragw_hal/test/test_loragw_spi.c) | 0 |
24 files changed, 462 insertions, 218 deletions
diff --git a/loragw_hal/Makefile b/libloragw/Makefile index 872952a..38d2fae 100644 --- a/loragw_hal/Makefile +++ b/libloragw/Makefile @@ -3,8 +3,8 @@ include library.cfg # constant symbols CC=gcc -CFLAGS=-O2 -Iinc -C99FLAGS=-O2 -std=c99 -Iinc +CFLAGS=-O2 -Iinc -I. +C99FLAGS=-O2 -std=c99 -Iinc -I. # configuration-dependant symbols ifeq ($(LGW_PHY),native) @@ -14,12 +14,12 @@ ifeq ($(LGW_PHY),ftdi) LDFLAGS=-lrt -lmpsse endif - # general build targets -all: test_loragw_spi test_loragw_reg test_loragw_hal +all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal clean: + rm -f *.a rm -f test_* rm -f obj/*.o rm -f .conf_ok @@ -37,8 +37,13 @@ else endif endif @echo "*** Config seems ok ***" + @echo "" @touch .conf_ok +# static library + +libloragw.a: obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o + ar rcs libloragw.a obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o # library module target @@ -57,26 +62,16 @@ obj/loragw_reg.o: .conf_ok src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h $(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG) obj/loragw_hal.o: .conf_ok src/loragw_hal.c src/arb_fw.var src/agc_fw.var inc/loragw_hal.h inc/loragw_reg.h inc/loragw_spi.h inc/loragw_aux.h - $(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o $(FLAG_HAL) - + $(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL) # test programs -obj/test_loragw_spi.o: test/test_loragw_spi.c inc/loragw_spi.h - $(CC) -c $(C99FLAGS) -Iinc test/test_loragw_spi.c -o obj/test_loragw_spi.o - -obj/test_loragw_reg.o: test/test_loragw_reg.c inc/loragw_reg.h - $(CC) -c $(C99FLAGS) -Iinc test/test_loragw_reg.c -o obj/test_loragw_reg.o - -obj/test_loragw_hal.o: test/test_loragw_hal.c inc/loragw_hal.h inc/loragw_aux.h - $(CC) -c $(C99FLAGS) test/test_loragw_hal.c -o obj/test_loragw_hal.o - -test_loragw_spi: .conf_ok obj/test_loragw_spi.o obj/loragw_spi.o - $(CC) obj/test_loragw_spi.o obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS) +test_loragw_spi: tst/test_loragw_spi.c obj/loragw_spi.o + $(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS) -test_loragw_reg: .conf_ok obj/test_loragw_reg.o obj/loragw_reg.o obj/loragw_spi.o - $(CC) obj/test_loragw_reg.o obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS) +test_loragw_reg: tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o + $(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS) -test_loragw_hal: .conf_ok obj/test_loragw_hal.o obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o - $(CC) obj/test_loragw_hal.o 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 obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o + $(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) diff --git a/libloragw/README.TXT b/libloragw/README.TXT new file mode 100644 index 0000000..9d13a4a --- /dev/null +++ b/libloragw/README.TXT @@ -0,0 +1,30 @@ +Lora Gateway HAL library - Content of subdirectories +==================================================== + +## 1. doc ## + +Contains the user manual, licensing informations, udev rules, etc. + +## 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. + +## 3. obj ## + +Contained the compiled intermediary objects. + +## 4. src ## + +Contain library C sources. + +## 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 new file mode 100644 index 0000000..87b0704 --- /dev/null +++ b/libloragw/VERSION @@ -0,0 +1,20 @@ +/* Software library version: */ +#define VERSION_LIBRARY "beta7" + +/* API version */ +#define VERSION_API "beta" + +/* 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/loragw_hal/99-libftdi.rules b/libloragw/doc/99-libftdi.rules index 8487413..8487413 100644 --- a/loragw_hal/99-libftdi.rules +++ b/libloragw/doc/99-libftdi.rules diff --git a/libloragw/doc/CHANGELOG.TXT b/libloragw/doc/CHANGELOG.TXT new file mode 100644 index 0000000..4ec6bd7 --- /dev/null +++ b/libloragw/doc/CHANGELOG.TXT @@ -0,0 +1,35 @@ +Lora Gateway HAL changelog +========================== + + 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/loragw_hal/INSTALL_FTDI.TXT b/libloragw/doc/INSTALL_FTDI.TXT index d26ad4b..d26ad4b 100644 --- a/loragw_hal/INSTALL_FTDI.TXT +++ b/libloragw/doc/INSTALL_FTDI.TXT diff --git a/libloragw/doc/LICENSE.TXT b/libloragw/doc/LICENSE.TXT new file mode 100644 index 0000000..eab9548 --- /dev/null +++ b/libloragw/doc/LICENSE.TXT @@ -0,0 +1,8 @@ +THE FOLLOWING SOFTWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND +(2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER. +CONSEQUENTLY, SEMTECH SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR +CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT +OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION +CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + +Copyright (C) SEMTECH S.A. diff --git a/loragw_hal/README.txt b/libloragw/doc/MANUAL.TXT index 58e7fbe..1659f03 100644 --- a/loragw_hal/README.txt +++ b/libloragw/doc/MANUAL.TXT @@ -1,14 +1,12 @@ -+===============================================+ -| / _____) _ | | | -| ( (____ _____ ____ _| |_ _____ ____| |__ | -| \____ \| ___ | (_ _) ___ |/ ___) _ \ | -| _____) ) ____| | | || |_| ____( (___| | | | | -| (______/|_____)_|_|_| \__)_____)\____)_| |_| | -| ©2013 Semtech-Cycleo | -| | -| Description: | -| Lora Gateway HAL documentation | -+===============================================+ + / _____) _ | | + ( (____ _____ ____ _| |_ _____ ____| |__ + \____ \| ___ | (_ _) ___ |/ ___) _ \ + _____) ) ____| | | || |_| ____( (___| | | | + (______/|_____)_|_|_| \__)_____)\____)_| |_| + ©2013 Semtech-Cycleo + +Lora Gateway HAL user manual +============================ 1. Introduction --------------- @@ -18,8 +16,7 @@ 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, FSK or GFSK -modulations. +used to send and receive packets wirelessly using Lora or FSK modulations. 2. Components of the library @@ -145,12 +142,17 @@ instructions. 4. Hardware dependencies ------------------------ +### 4.1. Hardware revision ### + The loragw_reg and loragw_hal are written for a specific version on the Semtech -hardware. -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. +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. @@ -169,6 +171,22 @@ that the SPI communication is working 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 @@ -191,11 +209,6 @@ loop { } <stop the gateway> -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*. - - **/!\ 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. @@ -209,11 +222,11 @@ 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 ### -6. License ----------- - -To Be Defined. +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/loragw_hal/inc/loragw_aux.h b/libloragw/inc/loragw_aux.h index 09f543f..09f543f 100644 --- a/loragw_hal/inc/loragw_aux.h +++ b/libloragw/inc/loragw_aux.h diff --git a/loragw_hal/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h index d5daafd..08aa945 100644 --- a/loragw_hal/inc/loragw_hal.h +++ b/libloragw/inc/loragw_hal.h @@ -27,6 +27,10 @@ Description: #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_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)) +#define IS_FSK_DR(dr) ((dr >= DR_FSK_MIN) && (dr <= DR_FSK_MAX)) + #define IS_TX_MODE(mode) ((mode == IMMEDIATE) || (mode == TIMESTAMPED) || (mode == ON_GPS)) /* -------------------------------------------------------------------------- */ @@ -41,25 +45,17 @@ Description: #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 -#define LGW_DATABUFF_SIZE 1024 -#define LGW_REF_BW 125000 /* typical bandwidth of data channel */ - -/* -SX1275 frequency setting : -F_register(24bit) = F_rf (Hz) / F_step(Hz) - = F_rf (Hz) * 2^19 / F_xtal(Hz) - = F_rf (Hz) * 256/15625 -*/ -#define LGW_XTAL_FREQU 32000000 -#define LGW_SX1257_DENOMINATOR 15625 /* pll settings denominator when the numerator is 2^8 */ +#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 */ /* to use those parameters, declare a local constant, and use 'rf_chain' as index */ -#define LGW_RF_RX_LOWFREQ {863000000, 863000000} -#define LGW_RF_RX_UPFREQ {870000000, 870000000} -#define LGW_RF_RX_BANDWIDTH {800000, 800000} /* bandwidth of the radios */ -#define LGW_RF_TX_LOWFREQ {863000000, 863000000} -#define LGW_RF_TX_UPFREQ {870000000, 870000000} +#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 */ /* type of if_chain + modem */ #define IF_UNDEFINED 0 @@ -82,37 +78,46 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz) IF_FSK_STD } /* values available for the 'modulation' parameters */ +/* NOTE: arbitrary values */ #define MOD_UNDEFINED 0 #define MOD_LORA 0x10 #define MOD_FSK 0x20 -#define MOD_GFSK 0x21 -/* values available for the 'bandwidth' parameters */ +/* values available for the 'bandwidth' parameters (Lora & FSK) */ +/* NOTE: directly encode FSK RX bandwidth, do not change */ #define BW_UNDEFINED 0 -#define BW_500KHZ 0x04 -#define BW_250KHZ 0x08 -#define BW_125KHZ 0x0C -// TODO: add all the supported FSK bandwidth +#define BW_500KHZ 0x01 +#define BW_250KHZ 0x02 +#define BW_125KHZ 0x03 +#define BW_62K5HZ 0x04 +#define BW_31K2HZ 0x05 +#define BW_15K6HZ 0x06 +#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 */ #define DR_UNDEFINED 0 -#define DR_LORA_SF7 0x1002 -#define DR_LORA_SF8 0x1004 -#define DR_LORA_SF9 0x1008 -#define DR_LORA_SF10 0x1010 -#define DR_LORA_SF11 0x1020 -#define DR_LORA_SF12 0x1040 -#define DR_LORA_MULTI 0x107E -// TODO: add FSK data rates - -/* values available for the 'coderate' parameters */ +#define DR_LORA_SF7 0x02 +#define DR_LORA_SF8 0x04 +#define DR_LORA_SF9 0x08 +#define DR_LORA_SF10 0x10 +#define DR_LORA_SF11 0x20 +#define DR_LORA_SF12 0x40 +#define DR_LORA_MULTI 0x7E +/* NOTE: for FSK directly use baudrate between 300 bauds and 250 kbauds */ +#define DR_FSK_MIN 300 +#define DR_FSK_MAX 250000 + +/* values available for the 'coderate' parameters (Lora only) */ +/* NOTE: arbitrary values */ #define CR_UNDEFINED 0 -#define CR_LORA_4_5 0x11 -#define CR_LORA_4_6 0x12 -#define CR_LORA_4_7 0x13 -#define CR_LORA_4_8 0x14 +#define CR_LORA_4_5 0x01 +#define CR_LORA_4_6 0x02 +#define CR_LORA_4_7 0x03 +#define CR_LORA_4_8 0x04 /* values available for the 'status' parameter */ +/* NOTE: values according to hardware specification */ #define STAT_UNDEFINED 0x00 #define STAT_NO_CRC 0x01 #define STAT_CRC_BAD 0x11 @@ -131,6 +136,7 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz) #define RX_STATUS 2 /* status code for TX_STATUS */ +/* NOTE: arbitrary values */ #define TX_STATUS_UNKNOWN 0 #define TX_OFF 1 /* TX modem disabled, it will ignore commands */ #define TX_FREE 2 /* TX modem is free, ready to receive a command */ @@ -138,6 +144,7 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz) #define TX_EMITTING 4 /* TX modem is emitting */ /* status code for RX_STATUS */ +/* NOTE: arbitrary values */ #define RX_STATUS_UNKNOWN 0 #define RX_OFF 1 /* RX modem is disabled, it will ignore commands */ #define RX_ON 2 /* RX modem is receiving */ @@ -164,7 +171,7 @@ struct lgw_conf_rxif_s { uint8_t rf_chain; /*!> to which RF chain is that IF chain associated */ int32_t freq_hz; /*!> center frequ of the IF chain, relative to RF chain frequency */ uint8_t bandwidth; /*!> RX bandwidth, 0 for default */ - uint16_t datarate; /*!> RX datarate, 0 for default */ + uint32_t datarate; /*!> RX datarate, 0 for default */ }; /** @@ -185,7 +192,7 @@ struct lgw_pkt_rx_s { 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; /*!> pointer to the payload */ + uint8_t payload[256]; /*!> buffer containing the payload */ }; /** @@ -201,14 +208,14 @@ struct lgw_pkt_tx_s { uint8_t modulation; /*!> modulation to use for the packet */ uint8_t bandwidth; /*!> modulation bandwidth (Lora only) */ bool invert_pol; /*!> invert signal polarity, for orthogonal downlinks (Lora only) */ - uint16_t f_dev; /*!> frequency deviation (FSK only) */ - uint16_t datarate; /*!> TX datarate */ - uint8_t coderate; /*!> error-correcting code of the packet */ + uint8_t f_dev; /*!> frequency deviation, in kHz (FSK only) */ + uint16_t datarate; /*!> TX datarate (baudrate for FSK) */ + uint8_t coderate; /*!> error-correcting code of the packet (Lora 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 */ + bool no_header; /*!> if true, enable implicit header mode (Lora), fixed length (FSK) */ uint16_t size; /*!> payload size in bytes */ - uint8_t *payload; /*!> pointer to the payload */ + uint8_t payload[256]; /*!> buffer containing the payload */ }; /* -------------------------------------------------------------------------- */ @@ -265,6 +272,12 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data); */ int lgw_status(uint8_t select, uint8_t *code); +/** +@brief Allow user to check the version/options of the library once compiled +@return pointer on a human-readable null terminated string +*/ +const char* lgw_version_info(void); + #endif /* --- EOF ------------------------------------------------------------------ */ diff --git a/loragw_hal/inc/loragw_reg.h b/libloragw/inc/loragw_reg.h index 870780f..870780f 100644 --- a/loragw_hal/inc/loragw_reg.h +++ b/libloragw/inc/loragw_reg.h diff --git a/loragw_hal/inc/loragw_spi.h b/libloragw/inc/loragw_spi.h index 68d8bcf..68d8bcf 100644 --- a/loragw_hal/inc/loragw_spi.h +++ b/libloragw/inc/loragw_spi.h diff --git a/loragw_hal/library.cfg b/libloragw/library.cfg index ac24416..ac24416 100644 --- a/loragw_hal/library.cfg +++ b/libloragw/library.cfg diff --git a/loragw_hal/obj/.gitkeep b/libloragw/obj/.gitkeep index e69de29..e69de29 100644 --- a/loragw_hal/obj/.gitkeep +++ b/libloragw/obj/.gitkeep diff --git a/loragw_hal/src/agc_fw.var b/libloragw/src/agc_fw.var index 7d30fb9..7d30fb9 100644 --- a/loragw_hal/src/agc_fw.var +++ b/libloragw/src/agc_fw.var diff --git a/loragw_hal/src/arb_fw.var b/libloragw/src/arb_fw.var index 014a8e5..014a8e5 100644 --- a/loragw_hal/src/arb_fw.var +++ b/libloragw/src/arb_fw.var diff --git a/loragw_hal/src/loragw_aux.c b/libloragw/src/loragw_aux.c index 1c7e354..1c7e354 100644 --- a/loragw_hal/src/loragw_aux.c +++ b/libloragw/src/loragw_aux.c diff --git a/loragw_hal/src/loragw_hal.c b/libloragw/src/loragw_hal.c index 5b261f2..a57d9f1 100644 --- a/loragw_hal/src/loragw_hal.c +++ b/libloragw/src/loragw_hal.c @@ -15,7 +15,6 @@ Description: /* --- DEPENDANCIES --------------------------------------------------------- */ #include <stdint.h> /* C99 types */ -#include <stdlib.h> /* malloc & free */ #include <stdbool.h> /* bool type */ #include <stdio.h> /* printf fprintf */ #include <math.h> /* NaN */ @@ -61,6 +60,14 @@ const uint32_t rf_tx_upfreq[LGW_RF_CHAIN_NB] = LGW_RF_TX_UPFREQ; #define MCU_ARB_FW_BYTE 8192 /* size of the firmware IN BYTES (= twice the number of 14b words) */ #define MCU_AGC_FW_BYTE 8192 /* size of the firmware IN BYTES (= twice the number of 14b words) */ +/* +SX1275 frequency setting : +F_register(24bit) = F_rf (Hz) / F_step(Hz) + = F_rf (Hz) * 2^19 / F_xtal(Hz) + = F_rf (Hz) * 256/15625 +*/ +#define SX1257_DENOM 15625 /* pll settings denominator when the numerator is 2^8 */ + #define SX1257_CLK_OUT 1 #define SX1257_TX_DAC_CLK_SEL 1 /* 0:int, 1:ext */ #define SX1257_TX_DAC_GAIN 2 /* 3:0, 2:-3, 1:-6, 0:-9 dBFS (default 2) */ @@ -74,14 +81,16 @@ const uint32_t rf_tx_upfreq[LGW_RF_CHAIN_NB] = LGW_RF_TX_UPFREQ; #define SX1257_RX_ADC_TRIM 6 /* 0 to 7, 6 for 32MHz ref, 5 for 36MHz ref */ #define SX1257_RXBB_BW 2 -#define RSSI_OFFSET_LORA_MULTI -130.0 /* calibrated value */ -#define RSSI_OFFSET_LORA_STD -168.0 /* calibrated for all bandwidth */ -#define RSSI_OFFSET_FSK 0.0 /* TODO */ +#define RSSI_OFFSET_LORA_MULTI -128.0 /* calibrated value */ +#define RSSI_OFFSET_LORA_STD -167.0 /* calibrated for all bandwidth */ +#define RSSI_OFFSET_FSK -146.5 /* calibrated value */ +#define RSSI_SLOPE_FSK 1.2 /* calibrated value */ #define TX_METADATA_NB 16 #define RX_METADATA_NB 16 #define MIN_LORA_PREAMBLE 4 +#define MIN_FSK_PREAMBLE 3 #define PLL_LOCK_MAX_ATTEMPTS 6 /* -------------------------------------------------------------------------- */ @@ -90,6 +99,10 @@ const uint32_t rf_tx_upfreq[LGW_RF_CHAIN_NB] = LGW_RF_TX_UPFREQ; #include "arb_fw.var" /* external definition of the variable */ #include "agc_fw.var" /* external definition of the variable */ +/* Version string, used to identify the library version/options once compiled */ +#include "VERSION" +const char lgw_version_string[] = "Library: " VERSION_LIBRARY "; API: " VERSION_API "; SPI layer: " LGW_PHY "; Chip id: " ACCEPT_CHIP_ID "; SPI reg: " ACCEPT_VERSION_REG "; Radio(s): " INFO_RADIO_CHIP "; Usable band: " INFO_RF_PARAM "; Reference plateform: " INFO_REF_HARDWARE ";"; + /* The following static variables are the configuration set that the user can modify using rxrf_setconf and rxif_setconf functions. @@ -104,16 +117,18 @@ static bool lgw_is_started = false; static bool rf_enable[LGW_RF_CHAIN_NB] = {0, 0}; static uint32_t rf_rx_freq[LGW_IF_CHAIN_NB] = {0, 0}; /* absolute, in Hz */ -static uint8_t if_rf_switch = 0x00; /* each IF from 0 to 7 has 1 bit associated to it, 0 -> radio A, 1 -> radio B */ -/* IF 8 and 9 are on radio A */ - static bool if_enable[LGW_IF_CHAIN_NB] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static bool if_rf_chain[LGW_IF_CHAIN_NB] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* for each IF, 0 -> radio A, 1 -> radio B */ static int32_t if_freq[LGW_IF_CHAIN_NB] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* relative to radio frequency, +/- in Hz */ static uint8_t lora_multi_sfmask[LGW_MULTI_NB] = {0, 0, 0, 0}; /* enables SF for Lora 'multi' modems */ -static uint8_t lora_rx_bw = 0; /* for the Lora standalone modem(s) */ -static uint16_t lora_rx_sf = 0; /* for the Lora standalone modem(s) */ -static uint8_t lora_rx_ppm_offset = 0; /* for the Lora standalone modem(s) */ + +static uint8_t lora_rx_bw = 0; /* bandwidth setting for Lora standalone modem */ +static uint8_t lora_rx_sf = 0; /* spreading factor setting for Lora standalone modem */ +static bool lora_rx_ppm_offset = 0; + +static uint8_t fsk_rx_bw = 0; /* bandwidth setting of FSK modem */ +static uint32_t fsk_rx_dr = 0; /* FSK modem datarate in bauds */ /* -------------------------------------------------------------------------- */ /* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */ @@ -291,8 +306,8 @@ int setup_sx1257(uint8_t rf_chain, uint32_t freq_hz) { sx125x_write(rf_chain, 0x0D, SX1257_RXBB_BW + SX1257_RX_ADC_TRIM*4 + SX1257_RX_ADC_BW*32); /* set RX PLL frequency */ - part_int = freq_hz / LGW_SX1257_DENOMINATOR; /* integer part, gives the MSB and the middle byte */ - part_frac = ((freq_hz % LGW_SX1257_DENOMINATOR) << 8) / LGW_SX1257_DENOMINATOR; /* fractional part, gives LSB */ + part_int = freq_hz / SX1257_DENOM; /* integer part, gives the MSB and the middle byte */ + part_frac = ((freq_hz % SX1257_DENOM) << 8) / SX1257_DENOM; /* fractional part, gives LSB */ sx125x_write(rf_chain, 0x01,0xFF & (part_int >> 8)); /* Most Significant Byte */ sx125x_write(rf_chain, 0x02,0xFF & part_int); /* middle byte */ sx125x_write(rf_chain, 0x03,0xFF & part_frac); /* Least Significant Byte */ @@ -352,7 +367,7 @@ void lgw_constant_adjust(void) { // lgw_reg_w(LGW_CORR_SIG_NOISE_RATIO_SF11,4); /* default 4 */ // lgw_reg_w(LGW_CORR_SIG_NOISE_RATIO_SF12,4); /* default 4 */ - /* Lora 'multi' modems setup */ + /* Lora 'multi' demodulators setup */ lgw_reg_w(LGW_PREAMBLE_SYMB1_NB,4); /* default 10 */ // lgw_reg_w(LGW_FREQ_TO_TIME_DRIFT,9); /* default 9 */ // lgw_reg_w(LGW_FREQ_TO_TIME_INVERT,29); /* default 29 */ @@ -370,7 +385,7 @@ void lgw_constant_adjust(void) { // lgw_reg_w(LGW_ADJUST_MODEM_START_OFFSET_SF12_RDX4,4092); /* default 4092 */ // lgw_reg_w(LGW_MAX_PAYLOAD_LEN,255); /* default 255 */ - /* MBWSSF Modem */ + /* Lora standalone 'MBWSSF' demodulator setup */ // lgw_reg_w(LGW_MBWSSF_MODEM_ENABLE,1); /* default 0 */ // lgw_reg_w(LGW_MBWSSF_PREAMBLE_SYMB1_NB,10); /* default 10 */ // lgw_reg_w(LGW_MBWSSF_FREQ_TO_TIME_DRIFT,36); /* default 36 */ @@ -386,37 +401,41 @@ void lgw_constant_adjust(void) { // lgw_reg_w(LGW_MBWSSF_TRACKING_INTEGRAL,0); /* default 0 */ // lgw_reg_w(LGW_MBWSSF_AGC_FREEZE_ON_DETECT,1); /* default 1 */ - /* FSK datapath */ + /* FSK datapath setup */ lgw_reg_w(LGW_FSK_RX_INVERT,1); /* default 0 */ lgw_reg_w(LGW_FSK_MODEM_INVERT_IQ,1); /* default 0 */ - /* FSK demod */ - // lgw_reg_w(LGW_FSK_AUTO_AFC_ON,0); /* default 0 */ - // lgw_reg_w(LGW_FSK_BROADCAST,0); /* default 0 */ + /* FSK demodulator setup */ + lgw_reg_w(LGW_FSK_RSSI_LENGTH,4); /* default 0 */ + lgw_reg_w(LGW_FSK_PKT_MODE,1); /* variable length, default 0 */ + lgw_reg_w(LGW_FSK_PSIZE,3); /* ???, default 0 */ lgw_reg_w(LGW_FSK_CRC_EN,1); /* default 0 */ - // lgw_reg_w(LGW_FSK_CRC_IBM,0); /* default 0 */ // lgw_reg_w(LGW_FSK_DCFREE_ENC,0); /* default 0 */ + // lgw_reg_w(LGW_FSK_CRC_IBM,0); /* default 0 */ lgw_reg_w(LGW_FSK_ERROR_OSR_TOL,10); /* default 0 */ - lgw_reg_w(LGW_FSK_MODEM_INVERT_IQ,1); /* default 0 */ + lgw_reg_w(LGW_FSK_REF_PATTERN_LSB,0x01010101); /* default 0 */ + lgw_reg_w(LGW_FSK_REF_PATTERN_MSB,0x01010101); /* default 0 */ + lgw_reg_w(LGW_FSK_PKT_LENGTH,255); /* max packet length in variable length mode */ + // lgw_reg_w(LGW_FSK_NODE_ADRS,0); /* default 0 */ - lgw_reg_w(LGW_FSK_PATTERN_TIMEOUT_CFG,64); /* default 0 */ - lgw_reg_w(LGW_FSK_PKT_LENGTH,64); /* default 0 */ - lgw_reg_w(LGW_FSK_PKT_MODE,1); /* default 0 */ - lgw_reg_w(LGW_FSK_PSIZE,3); /* default 0 */ - lgw_reg_w(LGW_FSK_REF_PATTERN_LSB,0x55); /* default 0 */ - lgw_reg_w(LGW_FSK_REF_PATTERN_MSB,0x55); /* default 0 */ - lgw_reg_w(LGW_FSK_RSSI_LENGTH,4); /* default 0 */ - lgw_reg_w(LGW_FSK_CH_BW_EXPO,2); /* 125kHz (default 0, 500kHz) */ + // lgw_reg_w(LGW_FSK_BROADCAST,0); /* default 0 */ + // lgw_reg_w(LGW_FSK_AUTO_AFC_ON,0); /* default 0 */ + lgw_reg_w(LGW_FSK_PATTERN_TIMEOUT_CFG,128); /* sync timeout (allow 8 bytes preamble + 8 bytes sync word, default 0 */ - /* FSK mod */ - lgw_reg_w(LGW_FSK_TX_PSIZE,3); /* default 0 */ - lgw_reg_w(LGW_FSK_TX_GAUSSIAN_SELECT_BT,1); /* default 0 */ + /* TX general parameters */ + lgw_reg_w(LGW_TX_START_DELAY,1000); /* default 0 */ - /* TX */ + /* TX Lora */ // lgw_reg_w(LGW_TX_MODE,0); /* default 0 */ - lgw_reg_w(LGW_TX_START_DELAY,1000); /* default 0 */ lgw_reg_w(LGW_TX_SWAP_IQ,1); /* "normal" polarity; default 0 */ + /* TX FSK */ + // lgw_reg_w(LGW_FSK_TX_GAUSSIAN_EN,1); /* default 1 */ + lgw_reg_w(LGW_FSK_TX_GAUSSIAN_SELECT_BT,1); /* Gaussian filter always on TX, default 0 */ + lgw_reg_w(LGW_FSK_TX_PSIZE,3); /* default 0 */ + // lgw_reg_w(LGW_FSK_TX_PATTERN_EN, 1); /* default 1 */ + // lgw_reg_w(LGW_FSK_TX_PREAMBLE_SEQ,0); /* default 0 */ + return; } @@ -494,10 +513,10 @@ int lgw_rxif_setconf(uint8_t if_chain, struct |
