> #### New features

* Added support for USB interface between the HOST and the concentrator,
for sx1250 based concentrator only.
* Added support for Listen-Before-Talk for AS923 region, using the additional
sx1261 radio from the Semtech Corecell reference design v3.
* Added support for Spectral Scan with additional sx1261 radio from the Semtech
Corecell reference design v3.
* Added support for SX1303 chip, for further Fine Timestamping support.
* Merged the master-fdd-cn490 branch to bring support for CN490 Full-Duplex
reference design. It is an integration of the releases v1.1.0, v1.1.1, v1.1.2
described below.

> #### Changes

* HAL: Reworked the complete communication layer. A new loragw_com module has
been introduced to handle switching from a USB or a SPI communication interface,
aligned function prototypes for sx125x, sx1250 and sx1261 radios. For USB, a
mode has been added to group SPI write commands request to the STM32 MCU, in
order to optimize latency during time critical configuration phases.
* HAL: Added preliminary support for Fine Timestamping for TDOA localization.
* HAL: Updated AGC firmware to v6: add configurable delay for PA to start, add
Listen-Before-Talk support.
* HAL: Added new API function lgw_demod_setconf() to set global demodulator
settings.
* HAL: Added new API functions for Spectral Scan.
* Packet Forwarder: The type of interface is configurable in the
global_conf.json file: com_type can be "USB" or "SPI".
* Packet Forwarder: Changed the parameters to configure fine timestamping in the
global_conf.json.
* Packet Forwarder: Added sections to configure the spectral scan and
Listen-Before-Talk features.
* Packet Forwarder: Added a new thread for background spectral scan example,
to show how to use the spectral scan API provided by the HAL, without
interfering with the main tasks of the gateway (aka Receive uplinks and transmit
downlinks).
* Packet Forwarder: Added "nhdr" field parsing from "txpk" JSON downlink request
in order to be able to send beacon request from Network Server.
* Packet Forwarder: Added chan_multiSF_All in global_conf.json to choose which
spreading factors to enable for multi-sf demodulators.
* Packet Forwarder: Updated PROTOCOL.md to v1.6.
* Tools: added util_spectral_scan, a standalone spectral scanner utility.

> #### Notes

* This release has been validated on the Semtech Corecell reference design v3
with USB interface.

v1.1.2

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* packet forwarder: updated global_conf.json.sx1255.CN490.full-duplex with RSSI
temperature compensation coefficients, and updated RSSI offset for radio 1.

v1.1.1

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* HAL: Updated SX1302 LNA/PA LUT configuration for Full Duplex CN490 reference
design.
* test_loragw_hal_rx/tx: added --fdd option to enable Full Duplex
* packet forwarder: updated global_conf.json.sx1255.CN490.full-duplex for CN490
reference design.

v1.1.0

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* HAL: Added support for CN490 full duplex reference design.
This commit is contained in:
Michael Coracin 2020-12-09 09:21:09 +01:00
commit 2c14708bdb
107 changed files with 13516 additions and 3249 deletions

View file

@ -0,0 +1,43 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2020 Semtech
Description:
Basic driver for Analog AD5338R DAC.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_AD5338R_H
#define _LORAGW_AD5338R_H
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
#define VOLTAGE2HEX_H(a) ( (a)*1024/5/4 )
#define VOLTAGE2HEX_L(a) ( (((int)((a)*1024/5)) & 0x3) * 64 )
/* -------------------------------------------------------------------------- */
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
#define I2C_PORT_DAC_AD5338R 0x0C
#define AD5338R_CMD_SIZE 3
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
int ad5338r_configure(int i2c_fd, uint8_t i2c_addr);
int ad5338r_write(int i2c_fd, uint8_t i2c_addr, uint8_t buf[static AD5338R_CMD_SIZE]);
#endif

View file

@ -19,11 +19,23 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include "config.h" /* library configuration options (dynamically generated) */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include <sys/time.h> /* gettimeofday, structtimeval */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define DEBUG_PERF 0 /* Debug timing performances: level [0..4] */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
/**
@brief Get a particular bit value from a byte
@param b [in] Any byte from which we want a bit value
@ -33,6 +45,22 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#define TAKE_N_BITS_FROM(b, p, n) (((b) >> (p)) & ((1 << (n)) - 1))
/**
@brief Substract struct timeval values
@param a [in] struct timeval a
@param b [in] struct timeval b
@param b [out] struct timeval resulting from (a - b)
*/
#define TIMER_SUB(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
@ -42,6 +70,65 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
*/
void wait_ms(unsigned long t);
/**
@brief Wait for a certain time (microsencond accuracy)
@param t number of microseconds to wait.
*/
void wait_us(unsigned long t);
/**
@brief Calculate the time on air of a LoRa packet in microseconds
@param bw packet bandwidth
@param sf packet spreading factor
@param cr packet coding rate
@param n_symbol_preamble packet preamble length (number of symbols)
@param no_header true if packet has no header
@param no_crc true if packet has no CRC
@param size packet size in bytes
@param nb_symbols pointer to return the total number of symbols in packet
@param nb_symbols_payload pointer to return the number of symbols in packet payload
@param t_symbol_us pointer to return the duration of a symbol in microseconds
@return the packet time on air in microseconds
*/
uint32_t lora_packet_time_on_air( const uint8_t bw,
const uint8_t sf,
const uint8_t cr,
const uint16_t n_symbol_preamble,
const bool no_header,
const bool no_crc,
const uint8_t size,
double * nb_symbols,
uint32_t * nb_symbols_payload,
uint16_t * t_symbol_us);
/**
@brief Record the current time, for measure start
@param tm Pointer to the current time value
*/
void _meas_time_start(struct timeval *tm);
/**
@brief Measure the ellapsed time since given time
@param debug_level debug print debug level to be used
@param start_time start time of the measure to be used
@param str string to be used for debug print
*/
void _meas_time_stop(int debug_level, struct timeval start_time, const char *str);
/**
@brief Get the current time for later timeout check
@param start contains the current time to be used as start time for timeout
*/
void timeout_start(struct timeval * start);
/**
@brief Check if the given timeout time in milliseconds has ellapsed compared to start time
@param start reference start time
@param timeout_ms the timeout duration in milliseconds
@return -1 if the timeout has exceeded, 0 otherwise
*/
int timeout_check(struct timeval start, uint32_t timeout_ms);
#endif
/* --- EOF ------------------------------------------------------------------ */

123
libloragw/inc/loragw_com.h Normal file
View file

@ -0,0 +1,123 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2020 Semtech
Description:
Functions to abstract the communication interface used to communicate with
the concentrator.
Single-byte read/write and burst read/write.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_COM_H
#define _LORAGW_COM_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_COM_SUCCESS 0
#define LGW_COM_ERROR -1
#define LGW_SPI_MUX_TARGET_SX1302 0x00
#define LGW_SPI_MUX_TARGET_RADIOA 0x01
#define LGW_SPI_MUX_TARGET_RADIOB 0x02
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
typedef enum com_type_e {
LGW_COM_SPI,
LGW_COM_USB,
LGW_COM_UNKNOWN
} lgw_com_type_t;
typedef enum com_write_mode_e {
LGW_COM_WRITE_MODE_SINGLE,
LGW_COM_WRITE_MODE_BULK,
LGW_COM_WRITE_MODE_UNKNOWN
} lgw_com_write_mode_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
*
*/
int lgw_com_open(lgw_com_type_t com_type, const char *com_path);
/**
*
*/
int lgw_com_close(void);
/**
*
*/
int lgw_com_w(uint8_t spi_mux_target, uint16_t address, uint8_t data);
/**
*
*/
int lgw_com_r(uint8_t spi_mux_target, uint16_t address, uint8_t *data);
/**
*
*/
int lgw_com_rmw(uint8_t spi_mux_target, uint16_t address, uint8_t offs, uint8_t leng, uint8_t data);
/**
*
*/
int lgw_com_wb(uint8_t spi_mux_target, uint16_t address, const uint8_t *data, uint16_t size);
/**
*
*/
int lgw_com_rb(uint8_t spi_mux_target, uint16_t address, uint8_t *data, uint16_t size);
/**
*
*/
int lgw_com_set_write_mode(lgw_com_write_mode_t write_mode);
/**
*
*/
int lgw_com_flush(void);
/**
*
*/
uint16_t lgw_com_chunk_size(void);
/**
*
**/
int lgw_com_get_temperature(float * temperature);
/**
*
**/
void* lgw_com_target(void);
/**
*
**/
lgw_com_type_t lgw_com_type(void);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -57,18 +57,6 @@ void dbg_generate_random_payload(uint32_t pkt_cnt, uint8_t * buffer_expected, ui
*/
int dbg_check_payload(struct lgw_conf_debug_s * context, FILE * file, uint8_t * payload_received, uint8_t size, uint8_t ref_payload_idx, uint8_t sf);
/**
@brief
@param
*/
void dbg_init_gpio(void);
/**
@brief
@param
*/
void dbg_toggle_gpio(void);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -22,6 +22,8 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "loragw_com.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
@ -42,7 +44,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* return status code */
#define LGW_HAL_SUCCESS 0
#define LGW_HAL_ERROR -1
#define LGW_LBT_ISSUE 1
#define LGW_LBT_NOT_ALLOWED 1
/* radio-specific parameters */
#define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */
@ -50,10 +52,10 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#define LGW_RF_RX_BANDWIDTH {1000000, 1000000} /* bandwidth of the radios */
/* concentrator chipset-specific parameters */
/* to use array parameters, declare a local const and use 'if_chain' as index */
#define LGW_IF_CHAIN_NB 10 /* number of IF+modem RX chains */
#define LGW_REF_BW 125000 /* typical bandwidth of data channel */
#define LGW_MULTI_NB 8 /* number of LoRa 'multi SF' chains */
#define LGW_MULTI_SF_EN 0xFF /* bitmask to enable/disable SF for multi-sf correlators (12 11 10 9 8 7 6 5) */
/* values available for the 'modulation' parameters */
/* NOTE: arbitrary values */
@ -86,7 +88,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* values available for the 'coderate' parameters (LoRa only) */
/* NOTE: arbitrary values */
#define CR_UNDEFINED 0
#define CR_UNDEFINED 0 /* CR0 exists but is not recommended, so consider it as invalid */
#define CR_LORA_4_5 0x01
#define CR_LORA_4_6 0x02
#define CR_LORA_4_7 0x03
@ -126,6 +128,12 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* Maximum size of Tx gain LUT */
#define TX_GAIN_LUT_SIZE_MAX 16
/* Listen-Before-Talk */
#define LGW_LBT_CHANNEL_NB_MAX 16 /* Maximum number of LBT channels */
/* Spectral Scan */
#define LGW_SPECTRAL_SCAN_RESULT_SIZE 33 /* The number of results returned by spectral scan function, to be used for memory allocation */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
@ -147,10 +155,11 @@ typedef enum {
@brief Configuration structure for board specificities
*/
struct lgw_conf_board_s {
bool lorawan_public; /*!> Enable ONLY for *public* networks using the LoRa MAC protocol */
uint8_t clksrc; /*!> Index of RF chain which provides clock to concentrator */
bool full_duplex; /*!> Indicates if the gateway operates in full duplex mode or not */
char spidev_path[64];/*!> Path to access the SPI device to connect to the SX1302 */
bool lorawan_public; /*!> Enable ONLY for *public* networks using the LoRa MAC protocol */
uint8_t clksrc; /*!> Index of RF chain which provides clock to concentrator */
bool full_duplex; /*!> Indicates if the gateway operates in full duplex mode or not */
lgw_com_type_t com_type; /*!> The COMmunication interface (SPI/USB) to connect to the SX1302 */
char com_path[64]; /*!> Path to access the COM device to connect to the SX1302 */
};
/**
@ -197,6 +206,14 @@ struct lgw_conf_rxif_s {
uint8_t implicit_coderate; /*!> LoRa Service implicit header coding rate */
};
/**
@struct lgw_conf_demod_s
@brief Configuration structure for LoRa/FSK demodulators
*/
struct lgw_conf_demod_s {
uint8_t multisf_datarate; /*!> bitmask to enable spreading-factors for correlators (SF12 - SF5) */
};
/**
@struct lgw_pkt_rx_s
@brief Structure containing the metadata of a packet that was received and a pointer to the payload
@ -221,6 +238,8 @@ struct lgw_pkt_rx_s {
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 */
bool ftime_received; /*!> a fine timestamp has been received */
uint32_t ftime; /*!> packet fine timestamp (nanoseconds since last PPS) */
};
/**
@ -288,13 +307,62 @@ struct lgw_conf_debug_s {
};
/**
@struct lgw_conf_debug_s
@brief Configuration structure for debug
@enum lgw_ftime_mode_t
@brief Fine timestamping modes
*/
struct lgw_conf_timestamp_s {
bool enable_precision_ts;
uint8_t max_ts_metrics;
uint8_t nb_symbols;
typedef enum {
LGW_FTIME_MODE_HIGH_CAPACITY, /*!> fine timestamps for SF5 -> SF10 */
LGW_FTIME_MODE_ALL_SF /*!> fine timestamps for SF5 -> SF12 */
} lgw_ftime_mode_t;
/**
@struct lgw_conf_ftime_s
@brief Configuration structure for fine timestamping
*/
struct lgw_conf_ftime_s {
bool enable; /*!> Enable / Disable fine timestamping */
lgw_ftime_mode_t mode; /*!> Fine timestamping mode */
};
/**
@enum lgw_lbt_scan_time_t
@brief Radio types that can be found on the LoRa Gateway
*/
typedef enum {
LGW_LBT_SCAN_TIME_128_US = 128,
LGW_LBT_SCAN_TIME_5000_US = 5000,
} lgw_lbt_scan_time_t;
/**
@brief Structure containing a Listen-Before-Talk channel configuration
*/
struct lgw_conf_chan_lbt_s{
uint32_t freq_hz; /*!> LBT channel frequency */
uint8_t bandwidth; /*!> LBT channel bandwidth */
lgw_lbt_scan_time_t scan_time_us; /*!> LBT channel carrier sense time */
uint16_t transmit_time_ms; /*!> LBT channel transmission duration when allowed */
};
/**
@struct lgw_conf_lbt_s
@brief Configuration structure for listen-before-talk
*/
struct lgw_conf_lbt_s {
bool enable; /*!> enable or disable LBT */
int8_t rssi_target; /*!> RSSI threshold to detect if channel is busy or not (dBm) */
uint8_t nb_channel; /*!> number of LBT channels */
struct lgw_conf_chan_lbt_s channels[LGW_LBT_CHANNEL_NB_MAX]; /*!> LBT channels configuration */
};
/**
@struct lgw_conf_sx1261_s
@brief Configuration structure for additional SX1261 radio used for LBT and Spectral Scan
*/
struct lgw_conf_sx1261_s {
bool enable; /*!> enable or disable SX1261 radio */
char spi_path[64]; /*!> Path to access the SPI device to connect to the SX1261 (not used for USB com type) */
int8_t rssi_offset; /*!> value to be applied to the sx1261 RSSI value (dBm) */
struct lgw_conf_lbt_s lbt_conf; /*!> listen-before-talk configuration */
};
/**
@ -308,16 +376,30 @@ typedef struct lgw_context_s {
/* RX context */
struct lgw_conf_rxrf_s rf_chain_cfg[LGW_RF_CHAIN_NB];
struct lgw_conf_rxif_s if_chain_cfg[LGW_IF_CHAIN_NB];
struct lgw_conf_demod_s demod_cfg;
struct lgw_conf_rxif_s lora_service_cfg; /* LoRa service channel config parameters */
struct lgw_conf_rxif_s fsk_cfg; /* FSK channel config parameters */
/* TX context */
struct lgw_tx_gain_lut_s tx_gain_lut[LGW_RF_CHAIN_NB];
/* Misc */
struct lgw_conf_timestamp_s timestamp_cfg;
struct lgw_conf_ftime_s ftime_cfg;
struct lgw_conf_sx1261_s sx1261_cfg;
/* Debug */
struct lgw_conf_debug_s debug_cfg;
} lgw_context_t;
/**
@struct lgw_spectral_scan_status_t
@brief Spectral Scan status
*/
typedef enum lgw_spectral_scan_status_e {
LGW_SPECTRAL_SCAN_STATUS_NONE,
LGW_SPECTRAL_SCAN_STATUS_ON_GOING,
LGW_SPECTRAL_SCAN_STATUS_ABORTED,
LGW_SPECTRAL_SCAN_STATUS_COMPLETED,
LGW_SPECTRAL_SCAN_STATUS_UNKNOWN
} lgw_spectral_scan_status_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
@ -344,23 +426,37 @@ 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 Configure LoRa/FSK demodulators
@param conf structure containing the configuration parameters
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_demod_setconf(struct lgw_conf_demod_s * conf);
/**
@brief Configure the Tx gain LUT
@param pointer to structure defining the LUT
@param conf pointer to structure defining the LUT
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_txgain_setconf(uint8_t rf_chain, struct lgw_tx_gain_lut_s * conf);
/**
@brief Configure the precision timestamp
@brief Configure the fine timestamping
@param conf pointer to structure defining the config to be applied
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_ftime_setconf(struct lgw_conf_ftime_s * conf);
/*
@brief Configure the SX1261 radio for LBT/Spectral Scan
@param pointer to structure defining the config to be applied
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_timestamp_setconf(struct lgw_conf_timestamp_s * conf);
int lgw_sx1261_setconf(struct lgw_conf_sx1261_s * conf);
/**
@brief Configure the debug context
@param pointer to structure defining the config to be applied
@param conf pointer to structure defining the config to be applied
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_debug_setconf(struct lgw_conf_debug_s * conf);
@ -464,7 +560,36 @@ const char* lgw_version_info(void);
@param packet is a pointer to the packet structure
@return the packet time on air in milliseconds
*/
uint32_t lgw_time_on_air(struct lgw_pkt_tx_s * packet);
uint32_t lgw_time_on_air(const struct lgw_pkt_tx_s * packet);
/**
@brief Start scaning the channel centered on the given frequency
@param freq_hz channel center frequency
@param nb_scan number of measures to be done for the scan
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_spectral_scan_start(uint32_t freq_hz, uint16_t nb_scan);
/**
@brief Get the current scan status
@param status a pointer to the returned status
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_spectral_scan_get_status(lgw_spectral_scan_status_t * status);
/**
@brief Get the channel scan results
@param levels an array containing the power levels for which the scan results are given
@param values ar array containing the results of the scan for each power levels
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_spectral_scan_get_results(int16_t levels_dbm[static LGW_SPECTRAL_SCAN_RESULT_SIZE], uint16_t results[static LGW_SPECTRAL_SCAN_RESULT_SIZE]);
/**
@brief Abort the current scan
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_spectral_scan_abort();
#endif

View file

@ -70,6 +70,16 @@ int i2c_linuxdev_read(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t
*/
int i2c_linuxdev_write(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t data);
/**
@brief Write a raw buffer to an I2C port
@param i2c_fd I2C port file descriptor index
@param device_addr I2C device address
@param buffer Buffer to be written to the device
@param size Size of the buffer to be written
@return 0 if I2C data write is successful, -1 else
*/
int i2c_linuxdev_write_buffer(int i2c_fd, uint8_t device_addr, uint8_t *buffer, uint8_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,65 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2020 Semtech
Description:
LoRa concentrator Listen-Before-Talk functions
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_LBT_H
#define _LORAGW_LBT_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "loragw_hal.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Configure the SX1261 and start LBT channel scanning
@param sx1261_context the sx1261 radio parameters to take into account for scanning
@param pkt description of the packet to be transmitted
@return 0 for success, -1 for failure
*/
int lgw_lbt_start(const struct lgw_conf_sx1261_s * sx1261_context, const struct lgw_pkt_tx_s * pkt);
/**
@brief Stop LBT scanning
@return 0 for success, -1 for failure
*/
int lgw_lbt_stop(void);
/**
@brief Check if packet was allowed to be transmitted or not
@param rf_chain the TX path on which TX was requested
@param tx_ok pointer to return if the packet was allowed to be transmitted or not.
@return 0 for success, -1 for failure
*/
int lgw_lbt_tx_status(uint8_t rf_chain, bool * tx_ok);
#endif
/* --- EOF ------------------------------------------------------------------ */

197
libloragw/inc/loragw_mcu.h Normal file
View file

@ -0,0 +1,197 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2020 Semtech
Description:
Host specific functions to address the LoRa concentrator MCU for USB
interface.
Single-byte read/write and burst read/write.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_MCU_H
#define _LORAGW_MCU_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
static const char mcu_version_string[] = "00.02.06";
#define MAX_SIZE_COMMAND ( 4200 )
#define MAX_SPI_COMMAND ( MAX_SIZE_COMMAND - CMD_OFFSET__DATA - 1 )
#define LGW_USB_BURST_CHUNK ( 4096 )
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
typedef enum order_id_e
{
ORDER_ID__REQ_PING = 0x00,
ORDER_ID__REQ_GET_STATUS = 0x01,
ORDER_ID__REQ_BOOTLOADER_MODE = 0x02,
ORDER_ID__REQ_RESET = 0x03,
ORDER_ID__REQ_WRITE_GPIO = 0x04,
ORDER_ID__REQ_SPI = 0x05, /* deprecated */
ORDER_ID__REQ_MULTIPLE_SPI = 0x06,
ORDER_ID__ACK_PING = 0x40,
ORDER_ID__ACK_GET_STATUS = 0x41,
ORDER_ID__ACK_BOOTLOADER_MODE = 0x42,
ORDER_ID__ACK_RESET = 0x43,
ORDER_ID__ACK_WRITE_GPIO = 0x44,
ORDER_ID__ACK_SPI = 0x45, /* deprecated */
ORDER_ID__ACK_MULTIPLE_SPI = 0x46,
ORDER_ID__UNKNOW_CMD = 0xFF
} order_id_t;
typedef enum
{
CMD_OFFSET__ID,
CMD_OFFSET__SIZE_MSB,
CMD_OFFSET__SIZE_LSB,
CMD_OFFSET__CMD,
CMD_OFFSET__DATA
} e_cmd_order_offset;
typedef enum
{
REQ_RESET__TYPE,
REQ_RESET_SIZE
} e_cmd_offset_req_reset;
typedef enum
{
REQ_WRITE_GPIO__PORT,
REQ_WRITE_GPIO__PIN,
REQ_WRITE_GPIO__STATE,
REQ_WRITE_GPIO_SIZE
} e_cmd_offset_req_write_gpio;
typedef enum
{
ACK_PING__UNIQUE_ID_0, ACK_PING__UNIQUE_ID_1, ACK_PING__UNIQUE_ID_2, ACK_PING__UNIQUE_ID_3,
ACK_PING__UNIQUE_ID_4, ACK_PING__UNIQUE_ID_5, ACK_PING__UNIQUE_ID_6, ACK_PING__UNIQUE_ID_7,
ACK_PING__UNIQUE_ID_8, ACK_PING__UNIQUE_ID_9, ACK_PING__UNIQUE_ID_10, ACK_PING__UNIQUE_ID_11,
ACK_PING__VERSION_0, ACK_PING__VERSION_1, ACK_PING__VERSION_2, ACK_PING__VERSION_3, ACK_PING__VERSION_4,
ACK_PING__VERSION_5, ACK_PING__VERSION_6, ACK_PING__VERSION_7, ACK_PING__VERSION_8,
ACK_PING_SIZE,
} e_cmd_offset_ack_ping;
typedef enum
{
ACK_GET_STATUS__SYSTEM_TIME_31_24, ACK_GET_STATUS__SYSTEM_TIME_23_16, ACK_GET_STATUS__SYSTEM_TIME_15_8, ACK_GET_STATUS__SYSTEM_TIME_7_0,
ACK_GET_STATUS__TEMPERATURE_15_8, ACK_GET_STATUS__TEMPERATURE_7_0,
ACK_GET_STATUS_SIZE
} e_cmd_offset_ack_get_status;
typedef enum
{
ACK_GPIO_WRITE__STATUS,
ACK_GPIO_WRITE_SIZE
} e_cmd_offset_ack_gpio_write;
typedef enum
{
ACK_RESET__STATUS,
ACK_RESET_SIZE
} e_cmd_offset_ack_reset;
typedef enum
{
MCU_SPI_TARGET_SX1302, /* SX1302 + SX1250 */
MCU_SPI_TARGET_SX1261 /* LBT/Spectral Scan additional radio */
} e_cmd_spi_target;
typedef enum
{
MCU_SPI_REQ_TYPE_READ_WRITE = 0x01, /* Read/Write SPI request */
MCU_SPI_REQ_TYPE_READ_MODIFY_WRITE = 0x02 /* Read-Modify-Write SPI request */
} e_cmd_spi_req_type;
typedef enum
{
RESET_TYPE__GTW
} e_reset_type;
typedef enum
{
SPI_STATUS_OK,
SPI_STATUS_FAIL,
SPI_STATUS_WRONG_PARAM,
SPI_STATUS_TIMEOUT
} e_spi_status;
typedef struct {
uint32_t unique_id_high;
uint32_t unique_id_mid;
uint32_t unique_id_low;
char version[10]; /* format is V00.00.00\0 */
} s_ping_info;
typedef struct {
uint32_t system_time_ms;
float temperature;
} s_status;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
*
*/
int mcu_ping(int fd, s_ping_info * info);
/**
*
*/
int mcu_boot(int fd);
/**
*
*/
int mcu_get_status(int fd, s_status * status);
/**
*
*/
int mcu_gpio_write(int fd, uint8_t gpio_port, uint8_t gpio_id, uint8_t gpio_value);
/**
@brief Send a SX1302 read/write SPI request to the MCU
@param fd File descriptor of the device used to access the MCU
@param in_out_buf The buffer containing the multiple requests to be sent to the
SX1302 with the SPI header (r/w, target mux). This buffer will also contain the
SPI answer when the function exits.
@param buf_size The size of the given input/output buffer
@return 0 for SUCCESS, -1 for failure
*/
int mcu_spi_write(int fd, uint8_t * in_out_buf, size_t buf_size);
/**
*
*/
int mcu_spi_store(uint8_t * in_out_buf, size_t buf_size);
/**
*
*/
int mcu_spi_flush(int fd);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -27,6 +27,8 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#include "config.h" /* library configuration options (dynamically generated) */
#include "loragw_com.h"
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */
@ -44,14 +46,12 @@ struct lgw_reg_s {
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED FUNCTIONS -------------------------------------------- */
int reg_w_align32(void *spi_target, uint8_t spi_mux_target, struct lgw_reg_s r, int32_t reg_value);
int reg_r_align32(void *spi_target, uint8_t spi_mux_target, struct lgw_reg_s r, int32_t *reg_value);
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_REG_SUCCESS 0
#define LGW_REG_ERROR -1
#define LGW_REG_WARNING -2
#define SX1302_REG_COMMON_PAGE_PAGE 0
#define SX1302_REG_COMMON_CTRL0_CLK32_RIF_CTRL 1
@ -1432,14 +1432,15 @@ int reg_r_align32(void *spi_target, uint8_t spi_mux_target, struct lgw_reg_s r,
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Connect LoRa concentrator by opening SPI link
@param spidev_path path to the SPI device to be used to connect to the SX1302
@brief Connect LoRa concentrator by opening COM link
@param com_type type of COM interface to be used (SPI or USB)
@param com_path path to the COM device to be used to connect to the SX1302
@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_connect(const char * spidev_path);
int lgw_connect(const lgw_com_type_t com_type, const char * com_path);
/**
@brief Disconnect LoRa concentrator by closing SPI link
@brief Disconnect LoRa concentrator by closing COM link
@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_disconnect(void);
@ -1472,19 +1473,28 @@ int lgw_reg_wb(uint16_t register_id, uint8_t *data, uint16_t size);
/**
@brief LoRa concentrator register burst read
@param register_id register number in the data structure describing registers
@param data pointer to byte array that will be written from the LoRa concentrator
@param data pointer to byte array to store the data read from the LoRa concentrator
@param size size of the transfer, in byte(s)
@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size);
/**
TODO
@brief LoRa concentrator memory burst write
@param mem_addr the address of the memory section to write to
@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_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_mem_wb(uint16_t mem_addr, const uint8_t *data, uint16_t size);
/**
TODO
@brief LoRa concentrator memory burst read
@param mem_addr the address of the memory section to read from
@param data pointer to byte array to store the data read from the LoRa concentrator
@param size size of the transfer, in byte(s)
@param fifo_mode the type of memory to read from
@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_mem_rb(uint16_t mem_addr, uint8_t *data, uint16_t size, bool fifo_mode);

View file

@ -31,25 +31,20 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#define LGW_SPI_SUCCESS 0
#define LGW_SPI_ERROR -1
#define LGW_BURST_CHUNK 1024
#define SPI_SPEED 2000000
#define LGW_SPI_MUX_TARGET_SX1302 0x00
#define LGW_SPI_MUX_TARGET_RADIOA 0x01
#define LGW_SPI_MUX_TARGET_RADIOB 0x02
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief LoRa concentrator SPI setup (configure I/O and peripherals)
@param spidev_path path to the SPI device to be used to connect to the SX1302
@param com_path path to the SPI device to be used to connect to the SX1302
@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(const char * spidev_path, void **spi_target_ptr);
int lgw_spi_open(const char * com_path, void **com_target_ptr);
/**
@brief LoRa concentrator SPI close
@ -57,7 +52,7 @@ int lgw_spi_open(const char * spidev_path, void **spi_target_ptr);
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_close(void *spi_target);
int lgw_spi_close(void *com_target);
/**
@brief LoRa concentrator SPI single-byte write
@ -66,7 +61,7 @@ int lgw_spi_close(void *spi_target);
@param data data byte to write
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_w(void *spi_target, uint8_t spi_mux_target, uint16_t address, uint8_t data);
int lgw_spi_w(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t data);
/**
@brief LoRa concentrator SPI single-byte read
@ -75,7 +70,18 @@ int lgw_spi_w(void *spi_target, uint8_t spi_mux_target, uint16_t address, uint8_
@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_target, uint16_t address, uint8_t *data);
int lgw_spi_r(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data);
/**
@brief LoRa concentrator SPI single-byte read-modify-write
@param spi_target generic pointer to SPI target (implementation dependant)
@param address 7-bit register address
@param offs start offset of the bits to be modified
@param leng number of bits to be modified
@param data value to be written in the selected bits
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
*/
int lgw_spi_rmw(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t offs, uint8_t leng, uint8_t data);
/**
@brief LoRa concentrator SPI burst (multiple-byte) write
@ -85,7 +91,7 @@ int lgw_spi_r(void *spi_target, uint8_t spi_mux_target, uint16_t address, uint8_
@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_target, uint16_t address, const uint8_t *data, uint16_t size);
int lgw_spi_wb(void *com_target, uint8_t spi_mux_target, uint16_t address, const uint8_t *data, uint16_t size);
/**
@brief LoRa concentrator SPI burst (multiple-byte) read
@ -95,7 +101,12 @@ int lgw_spi_wb(void *spi_target, uint8_t spi_mux_target, uint16_t address, const
@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_target, uint16_t address, uint8_t *data, uint16_t size);
int lgw_spi_rb(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data, uint16_t size);
/**
*
**/
uint16_t lgw_spi_chunk_size(void);
#endif

View file

@ -33,23 +33,30 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define I2C_PORT_TEMP_SENSOR_0 0x39 /* STTS751-0DP3F */
#define I2C_PORT_TEMP_SENSOR_1 0x3B /* STTS751-1DP3F */
/*
0x39: STTS751-0DP3F
0x3B: STTS751-1DP3F
0x38: STTS751-0DP3F on full duplex CN490 ref design
*/
static const uint8_t I2C_PORT_TEMP_SENSOR[] = {0x39, 0x3B, 0x38};
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
/**
@brief TODO
@param TODO
@return TODO
@brief Configure the temperature sensor (ST TS751)
@param i2c_fd file descriptor to access the sensor through I2C
@param i2c_addr the I2C device address of the sensor
@return LGW_I2C_ERROR if fails, LGW_I2C_SUCCESS otherwise
*/
int stts751_configure(int i2c_fd, uint8_t i2c_addr);
/**
@brief TODO
@param TODO
@return TODO
@brief Get the temperature from the sensor
@param i2c_fd file descriptor to access the sensor through I2C
@param i2c_addr the I2C device address of the sensor
@param temperature pointer to store the temerature read from sensor
@return LGW_I2C_ERROR if fails, LGW_I2C_SUCCESS otherwise
*/
int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature);

View file

@ -20,83 +20,30 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include <stdbool.h> /* bool type */
#include "sx1250_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define SX1250_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 25) / 32000000U)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
typedef enum {
CALIBRATE = 0x89,
CALIBRATE_IMAGE = 0x98,
CLR_IRQ_STATUS = 0x02,
STOP_TIMER_ON_PREAMBLE = 0x9F,
SET_RFSWITCHMODE = 0x9D,
GET_IRQ_STATUS = 0x12,
GET_RX_BUFFER_STATUS = 0x13,
GET_PACKET_STATUS = 0x14,
READ_BUFFER = 0x1E,
READ_REGISTER = 0x1D,
SET_DIO_IRQ_PARAMS = 0x08,
SET_MODULATION_PARAMS = 0x8B,
SET_PA_CONFIG = 0x95,
SET_PACKET_PARAMS = 0x8C,
SET_PACKET_TYPE = 0x8A,
SET_RF_FREQUENCY = 0x86,
SET_BUFFER_BASE_ADDRESS = 0x8F,
SET_SLEEP = 0x84,
SET_STANDBY = 0x80,
SET_RX = 0x82,
SET_TX = 0x83,
SET_TX_PARAMS = 0x8E,
WRITE_BUFFER = 0x0E,
WRITE_REGISTER = 0x0D,
SET_TXCONTINUOUSWAVE = 0xD1,
SET_TXCONTINUOUSPREAMBLE= 0xD2,
GET_STATUS = 0xC0,
SET_REGULATORMODE = 0x96,
SET_FS = 0xC1,
GET_DEVICE_ERRORS = 0x17
} sx1250_op_code_t;
typedef enum {
STDBY_RC = 0x00,
STDBY_XOSC = 0x01
} sx1250_standby_modes_t;
typedef enum {
PACKET_TYPE_GFSK = 0x00,
PACKET_TYPE_LORA = 0x01
} sx1250_packet_type_t;
typedef enum {
SET_RAMP_10U = 0x00,
SET_RAMP_20U = 0x01,
SET_RAMP_40U = 0x02,
SET_RAMP_80U = 0x03,
SET_RAMP_200U = 0x04,
SET_RAMP_800U = 0x05,
SET_RAMP_1700U = 0x06,
SET_RAMP_3400U = 0x07
} sx1250_ramp_time_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1250_write_command(uint8_t rf_chain, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1250_read_command(uint8_t rf_chain, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1250_calibrate(uint8_t rf_chain, uint32_t freq_hz);
int sx1250_setup(uint8_t rf_chain, uint32_t freq_hz, bool single_input_mode);
int sx1250_reg_w(sx1250_op_code_t op_code, uint8_t *data, uint16_t size, uint8_t rf_chain);
int sx1250_reg_r(sx1250_op_code_t op_code, uint8_t *data, uint16_t size, uint8_t rf_chain);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -141,8 +141,8 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz)
int sx125x_setup(uint8_t rf_chain, uint8_t rf_clkout, bool rf_enable, uint8_t rf_radio_type, uint32_t freq_hz);
int lgw_sx125x_reg_w(radio_reg_t idx, uint8_t data, uint8_t rf_chain);
int lgw_sx125x_reg_r(radio_reg_t idx, uint8_t *data, uint8_t rf_chain);
int sx125x_reg_w(radio_reg_t idx, uint8_t data, uint8_t rf_chain);
int sx125x_reg_r(radio_reg_t idx, uint8_t *data, uint8_t rf_chain);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,66 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1261 radio used to handle LBT
and Spectral Scan.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SX1261_H
#define _LORAGW_SX1261_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include <stdbool.h> /* bool type */
#include "loragw_hal.h"
#include "sx1261_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
static const char sx1261_pram_version_string[] = "2D06";
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1261_connect(lgw_com_type_t com_type, const char *com_path);
int sx1261_disconnect(void);
int sx1261_reg_w(sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1261_reg_r(sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1261_load_pram(void);
int sx1261_calibrate(uint32_t freq_hz);
int sx1261_setup(void);
int sx1261_set_rx_params(uint32_t freq_hz, uint8_t bandwidth);
int sx1261_lbt_start(lgw_lbt_scan_time_t scan_time_us, int8_t threshold_dbm);
int sx1261_lbt_stop(void);
int sx1261_spectral_scan_start(uint16_t nb_scan);
int sx1261_spectral_scan_status(lgw_spectral_scan_status_t * status);
int sx1261_spectral_scan_get_results(int8_t rssi_offset, int16_t * levels_dbm, uint16_t * results);
int sx1261_spectral_scan_abort(void);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -46,48 +46,56 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@struct sx1302_if_cfg_t
@brief TODO
@enum sx1302_model_id_t
@brief
*/
typedef struct {
bool if_enable;
bool if_rf_chain; /* for each IF, 0 -> radio A, 1 -> radio B */
int32_t if_freq; /* relative to radio frequency, +/- in Hz */
} sx1302_if_cfg_t;
typedef enum {
CHIP_MODEL_ID_SX1302 = 0x02, /* SX1302 can be 0x00 or 0x02 */
CHIP_MODEL_ID_SX1303 = 0x03,
CHIP_MODEL_ID_UNKNOWN
} sx1302_model_id_t;
/**
@struct sx1302_lora_service_cfg_t
@brief TODO
@enum sx1302_rx_frequency_tracking_t
@brief Frequency Tracking mode
*/
typedef struct {
uint8_t lora_rx_bw; /* bandwidth setting for LoRa standalone modem */
uint8_t lora_rx_sf; /* spreading factor setting for LoRa standalone modem */
bool lora_rx_implicit_hdr; /* implicit header setting for LoRa standalone modem */
uint8_t lora_rx_implicit_length; /* implicit header payload length setting for LoRa standalone modem */
bool lora_rx_implicit_crc_en; /* implicit header payload crc enable setting for LoRa standalone modem */
uint8_t lora_rx_implicit_coderate; /* implicit header payload coderate setting for LoRa standalone modem */
} sx1302_lora_service_cfg_t;
typedef enum {
RX_FREQ_TRACK_OFF = 0x00,
RX_FREQ_TRACK_ON = 0x01,
RX_FREQ_TRACK_AUTO = 0x03
} sx1302_rx_frequency_tracking_t;
/**
@struct sx1302_fsk_cfg_t
@brief TODO
@enum sx1302_rx_fine_timing_mode_t
@brief Fine Timing mode
*/
typedef struct {
uint8_t fsk_rx_bw; /* bandwidth setting of FSK modem */
uint32_t fsk_rx_dr; /* FSK modem datarate in bauds */
uint8_t fsk_sync_word_size; /* default number of bytes for FSK sync word */
uint64_t fsk_sync_word; /* default FSK sync word (ALIGNED RIGHT, MSbit first) */
} sx1302_fsk_cfg_t;
typedef enum {
RX_FINE_TIMING_MODE_ABS = 0x01,
RX_FINE_TIMING_MODE_LINEAR = 0x02,
RX_FINE_TIMING_MODE_AUTO = 0x03
} sx1302_rx_fine_timing_mode_t;
/**
@enum sx1302_rx_dft_peak_mode_t
@brief DFT peak mode
*/
typedef enum {
RX_DFT_PEAK_MODE_DISABLED = 0x00,
RX_DFT_PEAK_MODE_FULL = 0x01,
RX_DFT_PEAK_MODE_TRACK = 0x02,
RX_DFT_PEAK_MODE_AUTO = 0x03
} sx1302_rx_dft_peak_mode_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief TODO
@param TODO
@return TODO
@brief Initialize sx1302 for operating, and needed internal structures (rx_buffer,....)
@param conf a pointer to the fine timestamp configuration context
@return LGW_REG_SUCCESS if no error, LGW_REG_ERROR otherwise
*/
void sx1302_init(struct lgw_conf_timestamp_s *conf);
int sx1302_init(const struct lgw_conf_ftime_s *conf);
/**
@brief Get the SX1302 unique identifier
@ -96,6 +104,13 @@ void sx1302_init(struct lgw_conf_timestamp_s *conf);
*/
int sx1302_get_eui(uint64_t * eui);
/**
@brief Get the SX1302/SX1303 Chip Model ID
@param model_id pointer to the memory holding the Chip Model ID
@return LGW_REG_SUCCESS if no error, LGW_REG_ERROR otherwise
*/
int sx1302_get_model_id(sx1302_model_id_t * model_id);
/**
@brief Check AGC & ARB MCUs parity error, and update timestamp counter wraping status
@brief This function needs to be called regularly (every few seconds) by the upper layer
@ -145,10 +160,10 @@ int sx1302_radio_calibrate(struct lgw_conf_rxrf_s * context_rf_chain, uint8_t cl
/**
@brief Configure the PA and LNA LUTs
@param N/A
@param context_board A pointer to the current board configuration context
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_pa_lna_lut_configure(void);
int sx1302_pa_lna_lut_configure(struct lgw_conf_board_s * context_board);
/**
@brief Configure the Radio Front-End stage of the SX1302
@ -158,9 +173,9 @@ int sx1302_pa_lna_lut_configure(void);
int sx1302_radio_fe_configure(void);
/**
@brief TODO
@param TODO
@return TODO
@brief Returns the type of the given modem index (LoRa MultiSF, LoRa SingleSF, FSK)
@param if_chain the index if the IF chain
@return The IF chain type
*/
uint8_t sx1302_get_ifmod_config(uint8_t if_chain);
@ -174,10 +189,11 @@ int sx1302_channelizer_configure(struct lgw_conf_rxif_s * if_cfg, bool fix_gain)
/**
@brief Configure the correlator stage of the SX1302 LoRa multi-SF modems
@param N/A
@param if_cfg A pointer to the channels configuration
@param demod_cfg A pointer to the demodulators configuration
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_correlator_configure(void);
int sx1302_lora_correlator_configure(struct lgw_conf_rxif_s * if_cfg, struct lgw_conf_demod_s * demod_cfg);
/**
@brief Configure the correlator stage of the SX1302 LoRa single-SF modem
@ -238,16 +254,16 @@ int sx1302_gps_enable(bool enable);
uint32_t sx1302_timestamp_counter(bool pps);
/**
@brief TODO
@param TODO
@return TODO
@brief Load firmware to AGC MCU memory
@param firmware A pointer to the fw binary to be loaded
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_agc_load_firmware(const uint8_t *firmware);
/**
@brief TODO
@param TODO
@return TODO
@brief Read the AGC status register for current status
@param status A pointer to store the current status returned
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_agc_status(uint8_t* status);
@ -277,7 +293,7 @@ int sx1302_agc_mailbox_write(uint8_t mailbox, uint8_t value);
@param TODO
@return TODO
*/
int sx1302_agc_start(uint8_t version, lgw_radio_type_t radio_type, uint8_t ana_gain, uint8_t dec_gain, uint8_t fdd_mode);
int sx1302_agc_start(uint8_t version, lgw_radio_type_t radio_type, uint8_t ana_gain, uint8_t dec_gain, bool full_duplex, bool lbt_enable);
/**
@brief TODO
@ -319,7 +335,7 @@ int sx1302_arb_debug_write(uint8_t reg_id, uint8_t value);
@param TODO
@return TODO
*/
int sx1302_arb_start(uint8_t version);
int sx1302_arb_start(uint8_t version, const struct lgw_conf_ftime_s * ftime_context);
/**
@brief TODO
@ -367,14 +383,15 @@ int sx1302_parse(lgw_context_t * context, struct lgw_pkt_rx_s * p);
/**
@brief Configure the delay to be applied by the SX1302 for TX to start
@param rf_chain The RF chain index to be configured
@param radio_type The type of radio for this RF chain
@param modulation The modulation used for the TX
@param bandwidth The bandwidth used for the TX
@param delay The TX start delay calculated and applied
@param rf_chain RF chain index to be configured
@param radio_type Type of radio for this RF chain
@param modulation Modulation used for the TX
@param bandwidth Bandwidth used for the TX
@param chirp_lowpass Chirp Low Pass filtering configuration
@param delay TX start delay calculated and applied
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_tx_set_start_delay(uint8_t rf_chain, lgw_radio_type_t radio_type, uint8_t modulation, uint8_t bandwidth, uint16_t * delay);
int sx1302_tx_set_start_delay(uint8_t rf_chain, lgw_radio_type_t radio_type, uint8_t modulation, uint8_t bandwidth, uint8_t chirp_lowpass, uint16_t * delay);
/**
@brief Compute the offset to be applied on RSSI for temperature compensation
@ -420,6 +437,20 @@ int sx1302_tx_configure(lgw_radio_type_t radio_type);
*/
int sx1302_send(lgw_radio_type_t radio_type, struct lgw_tx_gain_lut_s * tx_lut, bool lwan_public, struct lgw_conf_rxif_s * context_fsk, struct lgw_pkt_tx_s * pkt_data);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_set_gpio(uint8_t gpio_reg_val);
/**
@brief TODO
@param TODO
@return TODO
*/
double sx1302_dc_notch_delay(double if_freq_hz);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -59,8 +59,8 @@ typedef struct rx_packet_s {
uint32_t timestamp_cnt;
uint16_t rx_crc16_value; /* LoRa only */
uint8_t num_ts_metrics_stored; /* LoRa only */
uint8_t timestamp_avg[255]; /* LoRa only */
uint8_t timestamp_stddev[255]; /* LoRa only */
int8_t timestamp_avg[255]; /* LoRa only */
int8_t timestamp_stddev[255]; /* LoRa only */
uint8_t packet_checksum;
} rx_packet_t;
@ -110,25 +110,10 @@ int rx_buffer_pop(rx_buffer_t * self, rx_packet_t * pkt);
/* -------------------------------------------------------------------------- */
/* --- DEBUG FUNCTIONS PROTOTYPES ------------------------------------------- */
/**
@brief TODO
@param TODO
@return TODO
*/
uint16_t rx_buffer_read_ptr_addr(void);
/**
@brief TODO
@param TODO
@return TODO
*/
uint16_t rx_buffer_write_ptr_addr(void);
/**
@brief TODO
@param TODO
@return TODO
*/
void rx_buffer_dump(FILE * file, uint16_t start_addr, uint16_t end_addr);
#endif

View file

@ -27,6 +27,8 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#include <stdint.h> /* C99 types*/
#include <stdbool.h> /* boolean type */
#include "loragw_hal.h"
#include "loragw_sx1302.h"
#include "config.h" /* library configuration options (dynamically generated) */
@ -72,11 +74,11 @@ void timestamp_counter_delete(timestamp_counter_t * self);
/**
@brief Update the counter wrapping status based on given current counter
@param self Pointer to the counter handler
@param pps Set to true to update the PPS trig counter status
@param cnt Current value of the counter to be used for the update
@param pps Current value of the pps counter to be used for the update
@param cnt Current value of the freerun counter to be used for the update
@return N/A
*/
void timestamp_counter_update(timestamp_counter_t * self, bool pps, uint32_t cnt);
void timestamp_counter_update(timestamp_counter_t * self, uint32_t pps, uint32_t cnt);
/**
@brief Convert the 27-bits counter given by the SX1302 to a 32-bits counter which wraps on a uint32_t.
@ -98,22 +100,24 @@ uint32_t timestamp_pkt_expand(timestamp_counter_t * self, uint32_t cnt_us);
/**
@brief Reads the SX1302 internal counter register, and return the 32-bits 1 MHz counter
@param self Pointer to the counter handler
@param pps Set to true to expand the counter based on the PPS trig wrapping status
@return the current 32-bits counter
@param pps Current value of the freerun counter
@param pps Current value of the PPS counter
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
uint32_t timestamp_counter_get(timestamp_counter_t * self, bool pps);
int timestamp_counter_get(timestamp_counter_t * self, uint32_t * inst, uint32_t * pps);
/**
@brief Get the timestamp correction to applied to the packet timestamp
@param ifmod modem type
@brief Get the correction to applied to the LoRa packet timestamp (count_us)
@param context gateway configuration context
@param bandwidth modulation bandwidth
@param datarate modulation datarate
@param coderate modulation coding rate
@param crc_en indicates if CRC is enabled or disabled
@param payload_length payload length
@param dft_peak_mode DFT peak mode configuration of the modem
@return The correction to be applied to the packet timestamp, in microseconds
*/
uint32_t timestamp_counter_correction(int ifmod, uint8_t bandwidth, uint8_t datarate, uint8_t coderate, uint32_t crc_en, uint16_t payload_length);
int32_t timestamp_counter_correction(lgw_context_t * context, uint8_t bandwidth, uint8_t datarate, uint8_t coderate, bool crc_en, uint8_t payload_length, sx1302_rx_dft_peak_mode_t dft_peak_mode);
/**
@brief Configure the SX1302 to output legacy timestamp or precision timestamp
@ -125,7 +129,19 @@ uint32_t timestamp_counter_correction(int ifmod, uint8_t bandwidth, uint8_t data
@param nb_symbols The sampling rate of timestamp metrics
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int timestamp_counter_mode(bool enable_precision_ts, uint8_t max_ts_metrics, uint8_t nb_symbols);
int timestamp_counter_mode(bool ftime_enable);
/**
@brief Compute a precise timestamp (fine timestamp) based on given coarse timestamp, metrics given by sx1302 and current GW xtal drift
@param ts_metrics_nb The number of timestamp metrics given in ts_metrics array
@param ts_metrics An array containing timestamp metrics to compute fine timestamp
@param pkt_coarse_tmst The packet coarse timestamp
@param sf packet spreading factor, used to shift timestamp from end of header to end of preamble
@param if_freq_hz the IF frequency, to take into account DC noth delay
@param result_ftime A pointer to store the resulting fine timestamp
@return 0 if success, -1 otherwise
*/
int precise_timestamp_calculate(uint8_t ts_metrics_nb, const int8_t * ts_metrics, uint32_t pkt_coarse_tmst, uint8_t sf, int32_t if_freq_hz, uint32_t * result_ftime);
#endif

View file

@ -0,0 +1,98 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2020 Semtech
Description:
Host specific functions to address the LoRa concentrator registers through
a USB interface.
Single-byte read/write and burst read/write.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_USB_H
#define _LORAGW_USB_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "loragw_com.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_USB_SUCCESS 0
#define LGW_USB_ERROR -1
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
*
*/
int lgw_usb_open(const char * com_path, void **com_target_ptr);
/**
*
*/
int lgw_usb_close(void *com_target);
/**
*
*/
int lgw_usb_w(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t data);
/**
*
*/
int lgw_usb_r(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data);
/**
*
*/
int lgw_usb_wb(void *com_target, uint8_t spi_mux_target, uint16_t address, const uint8_t *data, uint16_t size);
/**
*
*/
int lgw_usb_rb(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data, uint16_t size);
/**
*
*/
int lgw_usb_rmw(void *com_target, uint16_t address, uint8_t offs, uint8_t leng, uint8_t data);
/**
*
**/
int lgw_usb_set_write_mode(lgw_com_write_mode_t write_mode);
/**
*
**/
int lgw_usb_flush(void *com_target);
/**
*
**/
uint16_t lgw_usb_chunk_size(void);
/**
*
**/
int lgw_usb_get_temperature(void *com_target, float * temperature);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,46 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1250 radios.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1250_COM_H
#define _SX1250_COM_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "loragw_com.h"
#include "sx1250_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1250_com_w(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1250_com_r(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,93 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1250 radios.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1250_DEFS_H
#define _SX1250_DEFS_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define SX1250_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 25) / 32000000U)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
typedef enum {
CALIBRATE = 0x89,
CALIBRATE_IMAGE = 0x98,
CLR_IRQ_STATUS = 0x02,
STOP_TIMER_ON_PREAMBLE = 0x9F,
SET_RFSWITCHMODE = 0x9D,
GET_IRQ_STATUS = 0x12,
GET_RX_BUFFER_STATUS = 0x13,
GET_PACKET_STATUS = 0x14,
READ_BUFFER = 0x1E,
READ_REGISTER = 0x1D,
SET_DIO_IRQ_PARAMS = 0x08,
SET_MODULATION_PARAMS = 0x8B,
SET_PA_CONFIG = 0x95,
SET_PACKET_PARAMS = 0x8C,
SET_PACKET_TYPE = 0x8A,
SET_RF_FREQUENCY = 0x86,
SET_BUFFER_BASE_ADDRESS = 0x8F,
SET_SLEEP = 0x84,
SET_STANDBY = 0x80,
SET_RX = 0x82,
SET_TX = 0x83,
SET_TX_PARAMS = 0x8E,
WRITE_BUFFER = 0x0E,
WRITE_REGISTER = 0x0D,
SET_TXCONTINUOUSWAVE = 0xD1,
SET_TXCONTINUOUSPREAMBLE= 0xD2,
GET_STATUS = 0xC0,
SET_REGULATORMODE = 0x96,
SET_FS = 0xC1,
GET_DEVICE_ERRORS = 0x17
} sx1250_op_code_t;
typedef enum {
STDBY_RC = 0x00,
STDBY_XOSC = 0x01
} sx1250_standby_modes_t;
typedef enum {
PACKET_TYPE_GFSK = 0x00,
PACKET_TYPE_LORA = 0x01
} sx1250_packet_type_t;
typedef enum {
SET_RAMP_10U = 0x00,
SET_RAMP_20U = 0x01,
SET_RAMP_40U = 0x02,
SET_RAMP_80U = 0x03,
SET_RAMP_200U = 0x04,
SET_RAMP_800U = 0x05,
SET_RAMP_1700U = 0x06,
SET_RAMP_3400U = 0x07
} sx1250_ramp_time_t;
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,45 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1250 radios.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1250_SPI_H
#define _SX1250_SPI_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "sx1250_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1250_spi_w(void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1250_spi_r(void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,45 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1250 radios.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1250_USB_H
#define _SX1250_USB_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "sx1250_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1250_usb_w(void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1250_usb_r(void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,45 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1255/SX1257 radios SPI access.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX125X_COM_H
#define _SX125X_COM_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "loragw_com.h"
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx125x_com_r(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t *data);
int sx125x_com_w(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t data);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,43 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1255/SX1257 radios SPI access.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX125X_SPI_H
#define _SX125X_SPI_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx125x_spi_r(void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t *data);
int sx125x_spi_w(void *com_target, uint8_t spi_mux_target, uint8_t address, uint8_t data);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,73 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle the sx1261 radio used for LBT/Spectral Scan.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1261_COM_H
#define _SX1261_COM_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "loragw_com.h"
#include "sx1261_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
*
*/
int sx1261_com_open(lgw_com_type_t com_type, const char *com_path);
/**
*
*/
int sx1261_com_close(void);
/**
*
*/
int sx1261_com_w(sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
/**
*
*/
int sx1261_com_r(sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
/**
*
*/
int sx1261_com_set_write_mode(lgw_com_write_mode_t write_mode);
/**
*
*/
int sx1261_com_flush(void);
#endif
/* --- EOF ------------------------------------------------------------------ */

109
libloragw/inc/sx1261_defs.h Normal file
View file

@ -0,0 +1,109 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1261 radio.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1261_DEFS_H
#define _SX1261_DEFS_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define SX1261_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 25) / 32000000U)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
typedef enum {
SX1261_CALIBRATE_IMAGE = 0x98,
SX1261_CLR_IRQ_STATUS = 0x02,
SX1261_STOP_TIMER_ON_PREAMBLE = 0x9F,
SX1261_SET_RFSWITCHMODE = 0x9D,
SX1261_GET_IRQ_STATUS = 0x12,
SX1261_GET_RX_BUFFER_STATUS = 0x13,
SX1261_GET_PACKET_STATUS = 0x14,
SX1261_GET_RSSI_INST = 0x15,
SX1261_READ_BUFFER = 0x1E,
SX1261_READ_REGISTER = 0x1D,
SX1261_SET_DIO_IRQ_PARAMS = 0x08,
SX1261_SET_MODULATION_PARAMS = 0x8B,
SX1261_SET_PA_CONFIG = 0x95,
SX1261_SET_PACKET_PARAMS = 0x8C,
SX1261_SET_PACKET_TYPE = 0x8A,
SX1261_SET_RF_FREQUENCY = 0x86,
SX1261_SET_BUFFER_BASE_ADDRESS = 0x8F,
SX1261_SET_SLEEP = 0x84,
SX1261_SET_STANDBY = 0x80,
SX1261_SET_RX = 0x82,
SX1261_SET_TX = 0x83,
SX1261_SET_TX_PARAMS = 0x8E,
SX1261_WRITE_BUFFER = 0x0E,
SX1261_WRITE_REGISTER = 0x0D,
SX1261_SET_TXCONTINUOUSWAVE = 0xD1,
SX1261_SET_TXCONTINUOUSPREAMBLE = 0xD2,
SX1261_GET_STATUS = 0xC0,
SX1261_SET_REGULATORMODE = 0x96,
SX1261_SET_FS = 0xC1,
SX1261_GET_DEVICE_ERRORS = 0x17
} sx1261_op_code_t;
typedef enum {
SX1261_STDBY_RC = 0x00,
SX1261_STDBY_XOSC = 0x01
} sx1261_standby_modes_t;
typedef enum {
SX1261_PACKET_TYPE_GFSK = 0x00,
SX1261_PACKET_TYPE_LORA = 0x01
} sx1261_packet_type_t;
typedef enum {
SX1261_SET_RAMP_10U = 0x00,
SX1261_SET_RAMP_20U = 0x01,
SX1261_SET_RAMP_40U = 0x02,
SX1261_SET_RAMP_80U = 0x03,
SX1261_SET_RAMP_200U = 0x04,
SX1261_SET_RAMP_800U = 0x05,
SX1261_SET_RAMP_1700U = 0x06,
SX1261_SET_RAMP_3400U = 0x07
} sx1261_ramp_time_t;
typedef enum {
SX1261_STATUS_MODE_STBY_RC = 0x20, /* 0x02 - bits 6:4 */
SX1261_STATUS_MODE_STBY_XOSC = 0x30, /* 0x03 - bits 6:4 */
SX1261_STATUS_MODE_FS = 0x40, /* 0x04 - bits 6:4 */
SX1261_STATUS_MODE_RX = 0x50, /* 0x05 - bits 6:4 */
SX1261_STATUS_MODE_TX = 0x60 /* 0x06 - bits 6:4 */
} sx1261_status_mode_t;
typedef enum {
SX1261_STATUS_READY = 0x02, /* 0x02 - bits 3:1 */
SX1261_STATUS_TIMEOUT = 0x03, /* 0x03 - bits 3:1 */
SX1261_STATUS_PROCESSING_ERROR = 0x04, /* 0x04 - bits 3:1 */
SX1261_STATUS_EXECUTION_FAILED = 0x05, /* 0x05 - bits 3:1 */
SX1261_STATUS_TX_DONE = 0x06 /* 0x06 - bits 3:1 */
} sx1261_status_command_status_t;
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,46 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1261 radio through SPI
interface.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1261_SPI_H
#define _SX1261_SPI_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "sx1261_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1261_spi_w(void *com_target, sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
int sx1261_spi_r(void *com_target, sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,64 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1261 radio through USB
interface.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _SX1261_USB_H
#define _SX1261_USB_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "loragw_com.h"
#include "sx1261_defs.h"
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
*
**/
int sx1261_usb_w(void *com_target, sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
/**
*
**/
int sx1261_usb_r(void *com_target, sx1261_op_code_t op_code, uint8_t *data, uint16_t size);
/**
*
**/
int sx1261_usb_set_write_mode(lgw_com_write_mode_t write_mode);
/**
*
**/
int sx1261_usb_flush(void *com_target);
#endif
/* --- EOF ------------------------------------------------------------------ */