diff --git a/libloragw/inc/config.h b/libloragw/inc/config.h new file mode 100644 index 00000000..dc8edbf4 --- /dev/null +++ b/libloragw/inc/config.h @@ -0,0 +1,11 @@ +#ifndef _LORAGW_CONFIGURATION_H +#define _LORAGW_CONFIGURATION_H + #define LIBLORAGW_VERSION "5.0.1" + #define DEBUG_AUX 1 + #define DEBUG_SPI 1 + #define DEBUG_REG 1 + #define DEBUG_HAL 1 + #define DEBUG_GPS 1 + #define DEBUG_GPIO + #define DEBUG_LBT 1 +#endif diff --git a/libloragw/libloragw.a b/libloragw/libloragw.a new file mode 100644 index 00000000..1d52311b Binary files /dev/null and b/libloragw/libloragw.a differ diff --git a/libloragw/library.cfg b/libloragw/library.cfg index f962ba27..613b5a8a 100644 --- a/libloragw/library.cfg +++ b/libloragw/library.cfg @@ -4,9 +4,9 @@ # Set the DEBUG_* to 1 to activate debug mode in individual modules. # Warning: that makes the module *very verbose*, do not use for production -DEBUG_AUX= 0 -DEBUG_SPI= 0 -DEBUG_REG= 0 -DEBUG_HAL= 0 -DEBUG_LBT= 0 -DEBUG_GPS= 0 +DEBUG_AUX= 1 +DEBUG_SPI= 1 +DEBUG_REG= 1 +DEBUG_HAL= 1 +DEBUG_LBT= 1 +DEBUG_GPS= 1 diff --git a/libloragw/src/loragw_spi.native.c b/libloragw/src/loragw_spi.native.c index c01ed1c1..3ba63307 100644 --- a/libloragw/src/loragw_spi.native.c +++ b/libloragw/src/loragw_spi.native.c @@ -253,6 +253,7 @@ int lgw_spi_r(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, ui return LGW_SPI_ERROR; } else { DEBUG_MSG("Note: SPI read success\n"); + DEBUG_PRINTF("Note: SPI read data: %u \n",in_buf[command_size - 1]); *data = in_buf[command_size - 1]; return LGW_SPI_SUCCESS; } diff --git a/libloragw/test_loragw_cal b/libloragw/test_loragw_cal new file mode 100755 index 00000000..61e3cd51 Binary files /dev/null and b/libloragw/test_loragw_cal differ diff --git a/libloragw/test_loragw_gps b/libloragw/test_loragw_gps new file mode 100755 index 00000000..0cfcade5 Binary files /dev/null and b/libloragw/test_loragw_gps differ diff --git a/libloragw/test_loragw_hal b/libloragw/test_loragw_hal new file mode 100755 index 00000000..79186d80 Binary files /dev/null and b/libloragw/test_loragw_hal differ diff --git a/libloragw/test_loragw_reg b/libloragw/test_loragw_reg new file mode 100755 index 00000000..13dbbd77 Binary files /dev/null and b/libloragw/test_loragw_reg differ diff --git a/libloragw/test_loragw_spi b/libloragw/test_loragw_spi new file mode 100755 index 00000000..dcaee00f Binary files /dev/null and b/libloragw/test_loragw_spi differ diff --git a/libloragw/tst/library.cfg b/libloragw/tst/library.cfg new file mode 100644 index 00000000..613b5a8a --- /dev/null +++ b/libloragw/tst/library.cfg @@ -0,0 +1,12 @@ +# That file will be included in the Makefile files that have hardware dependencies + +### Debug options ### +# Set the DEBUG_* to 1 to activate debug mode in individual modules. +# Warning: that makes the module *very verbose*, do not use for production + +DEBUG_AUX= 1 +DEBUG_SPI= 1 +DEBUG_REG= 1 +DEBUG_HAL= 1 +DEBUG_LBT= 1 +DEBUG_GPS= 1 diff --git a/libloragw/tst/loragw_spi.h b/libloragw/tst/loragw_spi.h new file mode 100644 index 00000000..fef1f48d --- /dev/null +++ b/libloragw/tst/loragw_spi.h @@ -0,0 +1,105 @@ +/* + / _____) _ | | +( (____ _____ ____ _| |_ _____ ____| |__ + \____ \| ___ | (_ _) ___ |/ ___) _ \ + _____) ) ____| | | || |_| ____( (___| | | | +(______/|_____)_|_|_| \__)_____)\____)_| |_| + (C)2013 Semtech-Cycleo + +Description: + Host specific functions to address the LoRa concentrator registers through a + SPI interface. + Single-byte read/write and burst read/write. + Does not handle pagination. + Could be used with multiple SPI ports in parallel (explicit file descriptor) + +License: Revised BSD License, see LICENSE.TXT file include in the project +Maintainer: Sylvain Miermont +*/ + + +#ifndef _LORAGW_SPI_H +#define _LORAGW_SPI_H + +/* -------------------------------------------------------------------------- */ +/* --- DEPENDANCIES --------------------------------------------------------- */ + +#include /* C99 types*/ + +#include "config.h" /* library configuration options (dynamically generated) */ + +/* -------------------------------------------------------------------------- */ +/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ + +#define LGW_SPI_SUCCESS 0 +#define LGW_SPI_ERROR -1 +#define LGW_BURST_CHUNK 1024 + +#define LGW_SPI_MUX_MODE0 0x0 /* No FPGA */ +#define LGW_SPI_MUX_MODE1 0x1 /* FPGA, with spi mux header */ + +#define LGW_SPI_MUX_TARGET_SX1301 0x0 +#define LGW_SPI_MUX_TARGET_FPGA 0x1 +#define LGW_SPI_MUX_TARGET_EEPROM 0x2 +#define LGW_SPI_MUX_TARGET_SX127X 0x3 + +/* -------------------------------------------------------------------------- */ +/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */ + +/** +@brief LoRa concentrator SPI setup (configure I/O and peripherals) +@param spi_target_ptr pointer on a generic pointer to SPI target (implementation dependant) +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ + +int lgw_spi_open(void **spi_target_ptr); + +/** +@brief LoRa concentrator SPI close +@param spi_target generic pointer to SPI target (implementation dependant) +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ + +int lgw_spi_close(void *spi_target); + +/** +@brief LoRa concentrator SPI single-byte write +@param spi_target generic pointer to SPI target (implementation dependant) +@param address 7-bit register address +@param data data byte to write +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ +int lgw_spi_w(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t data); + +/** +@brief LoRa concentrator SPI single-byte read +@param spi_target generic pointer to SPI target (implementation dependant) +@param address 7-bit register address +@param data data byte to write +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ +int lgw_spi_r(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data); + +/** +@brief LoRa concentrator SPI burst (multiple-byte) write +@param spi_target generic pointer to SPI target (implementation dependant) +@param address 7-bit register address +@param data pointer to byte array that will be sent to the LoRa concentrator +@param size size of the transfer, in byte(s) +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ +int lgw_spi_wb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size); + +/** +@brief LoRa concentrator SPI burst (multiple-byte) read +@param spi_target generic pointer to SPI target (implementation dependant) +@param address 7-bit register address +@param data pointer to byte array that will be written from the LoRa concentrator +@param size size of the transfer, in byte(s) +@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR) +*/ +int lgw_spi_rb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size); + +#endif + +/* --- EOF ------------------------------------------------------------------ */ diff --git a/libloragw/tst/test_loragw_spi.c b/libloragw/tst/test_loragw_spi.c index 872a0754..018f3a15 100644 --- a/libloragw/tst/test_loragw_spi.c +++ b/libloragw/tst/test_loragw_spi.c @@ -32,7 +32,7 @@ Maintainer: Sylvain Miermont /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ #define BURST_TEST_SIZE 2500 /* >> LGW_BURST_CHUNK */ -#define TIMING_REPEAT 1 /* repeat transactions multiple times for timing characterisation */ +#define TIMING_REPEAT 100 /* repeat transactions multiple times for timing characterisation */ /* -------------------------------------------------------------------------- */ /* --- MAIN FUNCTION -------------------------------------------------------- */ @@ -61,16 +61,17 @@ int main() lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data); /* burst R/W test, small bursts << LGW_BURST_CHUNK */ - for (i = 0; i < TIMING_REPEAT; ++i) + /* for (i = 0; i < TIMING_REPEAT; ++i) lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, dataout, 16); for (i = 0; i < TIMING_REPEAT; ++i) lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, datain, 16); /* burst R/W test, large bursts >> LGW_BURST_CHUNK */ - for (i = 0; i < TIMING_REPEAT; ++i) + /*for (i = 0; i < TIMING_REPEAT; ++i) lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, dataout, ARRAY_SIZE(dataout)); for (i = 0; i < TIMING_REPEAT; ++i) lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, datain, ARRAY_SIZE(datain)); + */ /* last read (blocking), just to be sure no to quit before the FTDI buffer is flushed */ lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data);