Skip to content

Commit

Permalink
v3.2.1
Browse files Browse the repository at this point in the history
* HAL: Fixed downlink support for SX1301AP2 reference design: soft reset of the
FPGA was missing for proper IQ inversion configuration.

* HAL: Added support for several versions of FPGA (currently v18 and v19)

* HAL: Reduced radio TX PLL bandwidth to reduce the noise level.

* util_tx_test: Added FSK support and added minimal TX gain LUT.

* util_spectral_scan: Removed FPGA soft reset, now done by the HAL.

* util_tx_continous: reworked to use HAL functions instead of 'manual' config,
and use same SX1301 calibration firmware as the HAL.

* Updated all makefiles to handle the creation of obj directory when necessary.
  • Loading branch information
mcoracin committed Apr 25, 2016
1 parent a48215d commit 73f05ed
Show file tree
Hide file tree
Showing 28 changed files with 1,201 additions and 2,237 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.2.0
3.2.1
28 changes: 14 additions & 14 deletions libloragw/Makefile
Expand Up @@ -12,6 +12,9 @@ AR := $(CROSS_COMPILE)ar

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

OBJDIR = obj
INCLUDES = $(wildcard inc/*.h)

### linking options

LIBS := -lloragw -lrt -lm
Expand All @@ -23,51 +26,48 @@ all: libloragw.a test_loragw_spi test_loragw_reg test_loragw_hal test_loragw_gps
clean:
rm -f libloragw.a
rm -f test_loragw_*
rm -f obj/*.o
rm -f $(OBJDIR)/*.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
#File initialization
@echo "#ifndef _LORAGW_CONFIGURATION_H" >> $@
@echo "#define _LORAGW_CONFIGURATION_H" >> $@
# Release version
# Release version
@echo "Release version : $(LIBLORAGW_VERSION)"
@echo " #define LIBLORAGW_VERSION "\"$(LIBLORAGW_VERSION)\""" >> $@
# Debug options
# 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)" >> $@
@echo " #define DEBUG_GPIO $(DEBUG_GPIO)" >> $@
# end of file
# 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 $@

obj/loragw_spi.o: src/loragw_spi.native.c inc/loragw_spi.h inc/config.h
$(CC) -c $(CFLAGS) $< -o $@
$(OBJDIR):
mkdir -p $(OBJDIR)

obj/loragw_reg.o: src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h inc/config.h
$(OBJDIR)/%.o: src/%.c $(INCLUDES) inc/config.h | $(OBJDIR)
$(CC) -c $(CFLAGS) $< -o $@

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 src/cal_fw.var inc/config.h
$(OBJDIR)/loragw_spi.o: src/loragw_spi.native.c $(INCLUDES) inc/config.h | $(OBJDIR)
$(CC) -c $(CFLAGS) $< -o $@

obj/loragw_gps.o: src/loragw_gps.c inc/loragw_gps.h inc/config.h
$(OBJDIR)/loragw_hal.o: src/loragw_hal.c $(INCLUDES) src/arb_fw.var src/agc_fw.var src/cal_fw.var inc/config.h | $(OBJDIR)
$(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
libloragw.a: $(OBJDIR)/loragw_hal.o $(OBJDIR)/loragw_gps.o $(OBJDIR)/loragw_reg.o $(OBJDIR)/loragw_spi.o $(OBJDIR)/loragw_aux.o
$(AR) rcs $@ $^

### test programs
Expand Down
Empty file removed libloragw/obj/.gitkeep
Empty file.
8 changes: 6 additions & 2 deletions libloragw/readme.md
Expand Up @@ -179,8 +179,12 @@ messages if the DEBUG_xxx is set to 1 in library.cfg

### 3.3. Building procedures ###

For cross-compilation set the CROSS_COMPILE variable in the Makefile with the
correct toolchain name.
For cross-compilation set the ARCH and CROSS_COMPILE variables in the Makefile,
or in your shell environment, with the correct toolchain name and path.
ex:
export PATH=/home/foo/rpi-toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:$PATH
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-

The Makefile in the libloragw directory will parse the library.cfg file and
generate a config.h C header file containing #define options.
Expand Down
2 changes: 1 addition & 1 deletion libloragw/src/loragw_hal.c
Expand Up @@ -90,7 +90,7 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz)
#define SX125x_TX_DAC_CLK_SEL 1 /* 0:int, 1:ext */
#define SX125x_TX_DAC_GAIN 2 /* 3:0, 2:-3, 1:-6, 0:-9 dBFS (default 2) */
#define SX125x_TX_MIX_GAIN 14 /* -38 + 2*TxMixGain dB (default 14) */
#define SX125x_TX_PLL_BW 3 /* 0:75, 1:150, 2:225, 3:300 kHz (default 3) */
#define SX125x_TX_PLL_BW 1 /* 0:75, 1:150, 2:225, 3:300 kHz (default 3) */
#define SX125x_TX_ANA_BW 0 /* 17.5 / 2*(41-TxAnaBw) MHz (default 0) */
#define SX125x_TX_DAC_BW 5 /* 24 + 8*TxDacBw Nb FIR taps (default 2) */
#define SX125x_RX_LNA_GAIN 1 /* 1 to 6, 1 highest gain */
Expand Down
21 changes: 18 additions & 3 deletions libloragw/src/loragw_reg.c
Expand Up @@ -60,7 +60,7 @@ struct lgw_reg_s {
#define PAGE_ADDR 0x00
#define PAGE_MASK 0x03

#define FPGA_VERSION 18
const uint8_t FPGA_VERSION[] = { 18, 19 }; /* several versions supported */

/*
auto generated register mapping for C code : 11-Jul-2013 13:20:40
Expand Down Expand Up @@ -413,6 +413,18 @@ int page_switch(uint8_t target) {
return LGW_REG_SUCCESS;
}

bool check_fpga_version(uint8_t version) {
int i;

for (i = 0; i < (int)(sizeof FPGA_VERSION); i++) {
if (FPGA_VERSION[i] == version ) {
return true;
}
}

return false;
}

/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */

Expand All @@ -435,17 +447,20 @@ int lgw_connect(void) {
/* Detect if the gateway has an FPGA with SPI mux header support */
/* First, we assume there is an FPGA, and try to read its version */
spi_stat = lgw_spi_r(lgw_spi_target, LGW_SPI_MUX_MODE1, LGW_SPI_MUX_TARGET_FPGA, loregs[LGW_VERSION].addr, &u);
if (spi_stat != LGW_SPI_SUCCESS) {
if (spi_stat != LGW_SPI_SUCCESS) {
DEBUG_MSG("ERROR READING VERSION REGISTER\n");
return LGW_REG_ERROR;
}
if (u != FPGA_VERSION) {
if (check_fpga_version(u) != true) {
/* We failed to read expected FPGA version, so let's assume there is no FPGA */
DEBUG_MSG("INFO: no FPGA detected\n");
lgw_spi_mux_mode = LGW_SPI_MUX_MODE0;
} else {
DEBUG_MSG("INFO: detected FPGA with SPI mux header\n");
lgw_spi_mux_mode = LGW_SPI_MUX_MODE1;
/* FPGA Soft Reset */
lgw_spi_w(lgw_spi_target, lgw_spi_mux_mode, LGW_SPI_MUX_TARGET_FPGA, 0, 1);
lgw_spi_w(lgw_spi_target, lgw_spi_mux_mode, LGW_SPI_MUX_TARGET_FPGA, 0, 0);
}

/* check SX1301 version */
Expand Down
12 changes: 6 additions & 6 deletions libloragw/src/loragw_spi.native.c
Expand Up @@ -51,9 +51,9 @@ Maintainer: Sylvain Miermont
/* -------------------------------------------------------------------------- */
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */

#define READ_ACCESS 0x00
#define READ_ACCESS 0x00
#define WRITE_ACCESS 0x80
#define SPI_SPEED 8000000
#define SPI_SPEED 8000000
#define SPI_DEV_PATH "/dev/spidev0.0"
//#define SPI_DEV_PATH "/dev/spidev32766.0"

Expand Down Expand Up @@ -193,7 +193,7 @@ int lgw_spi_w(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, ui
k.tx_buf = (unsigned long) out_buf;
k.len = command_size;
k.speed_hz = SPI_SPEED;
k.cs_change = 1;
k.cs_change = 0;
k.bits_per_word = 8;
a = ioctl(spi_device, SPI_IOC_MESSAGE(1), &k);

Expand Down Expand Up @@ -244,7 +244,7 @@ int lgw_spi_r(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, ui
k.tx_buf = (unsigned long) out_buf;
k.rx_buf = (unsigned long) in_buf;
k.len = command_size;
k.cs_change = 1;
k.cs_change = 0;
a = ioctl(spi_device, SPI_IOC_MESSAGE(1), &k);

/* determine return code */
Expand Down Expand Up @@ -299,7 +299,7 @@ int lgw_spi_wb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, u
k[0].tx_buf = (unsigned long) &command[0];
k[0].len = command_size;
k[0].cs_change = 0;
k[1].cs_change = 1;
k[1].cs_change = 0;
for (i=0; size_to_do > 0; ++i) {
chunk_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK;
offset = i * LGW_BURST_CHUNK;
Expand Down Expand Up @@ -361,7 +361,7 @@ int lgw_spi_rb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, u
k[0].tx_buf = (unsigned long) &command[0];
k[0].len = command_size;
k[0].cs_change = 0;
k[1].cs_change = 1;
k[1].cs_change = 0;
for (i=0; size_to_do > 0; ++i) {
chunk_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK;
offset = i * LGW_BURST_CHUNK;
Expand Down
2 changes: 1 addition & 1 deletion libloragw/tst/test_loragw_gps.c
Expand Up @@ -98,7 +98,7 @@ int main()
printf("*** Library version information ***\n%s\n***\n", lgw_version_info());

/* Open and configure GPS */
i = lgw_gps_enable("/dev/ttyACM0", NULL, 0, &gps_tty_dev);
i = lgw_gps_enable("/dev/ttyAMA0", NULL, 0, &gps_tty_dev);
if (i != LGW_GPS_SUCCESS) {
printf("ERROR: IMPOSSIBLE TO ENABLE GPS\n");
exit(EXIT_FAILURE);
Expand Down
46 changes: 23 additions & 23 deletions libloragw/tst/test_loragw_hal.c
Expand Up @@ -208,52 +208,52 @@ int main(int argc, char **argv)
memset(&ifconf, 0, sizeof(ifconf));

ifconf.enable = true;
ifconf.rf_chain = 0;
ifconf.freq_hz = -300000;
ifconf.rf_chain = 1;
ifconf.freq_hz = -400000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(0, ifconf); /* chain 0: LoRa 125kHz, all SF, on f0 - 0.3 MHz */
lgw_rxif_setconf(0, ifconf); /* chain 0: LoRa 125kHz, all SF, on f1 - 0.4 MHz */

ifconf.enable = true;
ifconf.rf_chain = 0;
ifconf.freq_hz = 300000;
ifconf.rf_chain = 1;
ifconf.freq_hz = -200000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(1, ifconf); /* chain 1: LoRa 125kHz, all SF, on f0 + 0.3 MHz */
lgw_rxif_setconf(1, ifconf); /* chain 1: LoRa 125kHz, all SF, on f1 - 0.2 MHz */

ifconf.enable = true;
ifconf.rf_chain = 1;
ifconf.freq_hz = -300000;
ifconf.freq_hz = 0;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(2, ifconf); /* chain 2: LoRa 125kHz, all SF, on f1 - 0.3 MHz */
lgw_rxif_setconf(2, ifconf); /* chain 2: LoRa 125kHz, all SF, on f1 - 0.0 MHz */

ifconf.enable = true;
ifconf.rf_chain = 1;
ifconf.freq_hz = 300000;
ifconf.rf_chain = 0;
ifconf.freq_hz = -400000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(3, ifconf); /* chain 3: LoRa 125kHz, all SF, on f1 + 0.3 MHz */
lgw_rxif_setconf(3, ifconf); /* chain 3: LoRa 125kHz, all SF, on f0 - 0.4 MHz */

ifconf.enable = true;
ifconf.rf_chain = 0;
ifconf.freq_hz = -100000;
ifconf.freq_hz = -200000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(4, ifconf); /* chain 4: LoRa 125kHz, all SF, on f0 - 0.1 MHz */
lgw_rxif_setconf(4, ifconf); /* chain 4: LoRa 125kHz, all SF, on f0 - 0.2 MHz */

ifconf.enable = true;
ifconf.rf_chain = 0;
ifconf.freq_hz = 100000;
ifconf.freq_hz = 0;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(5, ifconf); /* chain 5: LoRa 125kHz, all SF, on f0 + 0.1 MHz */
lgw_rxif_setconf(5, ifconf); /* chain 5: LoRa 125kHz, all SF, on f0 + 0.0 MHz */

ifconf.enable = true;
ifconf.rf_chain = 1;
ifconf.freq_hz = -100000;
ifconf.rf_chain = 0;
ifconf.freq_hz = 200000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(6, ifconf); /* chain 6: LoRa 125kHz, all SF, on f1 - 0.1 MHz */
lgw_rxif_setconf(6, ifconf); /* chain 6: LoRa 125kHz, all SF, on f0 + 0.2 MHz */

ifconf.enable = true;
ifconf.rf_chain = 1;
ifconf.freq_hz = 100000;
ifconf.rf_chain = 0;
ifconf.freq_hz = 400000;
ifconf.datarate = DR_LORA_MULTI;
lgw_rxif_setconf(7, ifconf); /* chain 7: LoRa 125kHz, all SF, on f1 + 0.1 MHz */
lgw_rxif_setconf(7, ifconf); /* chain 7: LoRa 125kHz, all SF, on f0 + 0.4 MHz */

/* set configuration for LoRa 'stand alone' channel */
memset(&ifconf, 0, sizeof(ifconf));
Expand All @@ -279,8 +279,8 @@ int main(int argc, char **argv)
txpkt.tx_mode = IMMEDIATE;
txpkt.rf_power = 10;
txpkt.modulation = MOD_LORA;
txpkt.bandwidth = BW_250KHZ;
txpkt.datarate = DR_LORA_SF10;
txpkt.bandwidth = BW_125KHZ;
txpkt.datarate = DR_LORA_SF9;
txpkt.coderate = CR_LORA_4_5;
strcpy((char *)txpkt.payload, "TX.TEST.LORA.GW.????" );
txpkt.size = 20;
Expand Down

0 comments on commit 73f05ed

Please sign in to comment.