* Initial release for SX1302 CoreCell Reference Design.
This commit is contained in:
Michael Coracin 2019-07-12 15:40:13 +02:00
commit 4c61c5d48e
79 changed files with 30157 additions and 0 deletions

View file

@ -0,0 +1,84 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
SX1302 AGC parameters definition.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_AGC_PARAMS_H
#define _LORAGW_AGC_PARAMS_H
/* -------------------------------------------------------------------------- */
/* --- PRIVATE TYPES -------------------------------------------------------- */
struct agc_gain_params_s {
uint8_t ana_min;
uint8_t ana_max;
uint8_t ana_thresh_l;
uint8_t ana_thresh_h;
uint8_t dec_attn_min;
uint8_t dec_attn_max;
uint8_t dec_thresh_l;
uint8_t dec_thresh_h1;
uint8_t dec_thresh_h2;
uint8_t chan_attn_min;
uint8_t chan_attn_max;
uint8_t chan_thresh_l;
uint8_t chan_thresh_h;
uint8_t deviceSel; /* sx1250 only */
uint8_t hpMax; /* sx1250 only */
uint8_t paDutyCycle; /* sx1250 only */
};
/* -------------------------------------------------------------------------- */
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
const struct agc_gain_params_s agc_params_sx1250 = {
.ana_min = 1,
.ana_max = 13,
.ana_thresh_l = 3,
.ana_thresh_h = 12,
.dec_attn_min = 4,
.dec_attn_max = 15,
.dec_thresh_l = 40,
.dec_thresh_h1 = 80,
.dec_thresh_h2 = 90,
.chan_attn_min = 4,
.chan_attn_max = 14,
.chan_thresh_l = 52,
.chan_thresh_h = 132,
.deviceSel = 0,
.hpMax = 7,
.paDutyCycle = 4
};
const struct agc_gain_params_s agc_params_sx125x = {
.ana_min = 0,
.ana_max = 9,
.ana_thresh_l = 16,
.ana_thresh_h = 35,
.dec_attn_min = 7,
.dec_attn_max = 11,
.dec_thresh_l = 45,
.dec_thresh_h1 = 100,
.dec_thresh_h2 = 115,
.chan_attn_min = 4,
.chan_attn_max = 14,
.chan_thresh_l = 52,
.chan_thresh_h = 132,
.deviceSel = 0,
.hpMax = 0,
.paDutyCycle = 0
};
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,47 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
LoRa concentrator HAL common auxiliary functions
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_AUX_H
#define _LORAGW_AUX_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/**
@brief Get a particular bit value from a byte
@param b [in] Any byte from which we want a bit value
@param p [in] Position of the bit in the byte [0..7]
@param n [in] Number of bits we want to get
@return The value corresponding the requested bits
*/
#define TAKE_N_BITS_FROM(b, p, n) (((b) >> (p)) & ((1 << (n)) - 1))
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Wait for a certain time (millisecond accuracy)
@param t number of milliseconds to wait.
*/
void wait_ms(unsigned long t);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,59 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
LoRa concentrator radio calibration functions
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_CAL_H
#define _LORAGW_CAL_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
struct lgw_sx125x_cal_rx_result_s {
int8_t amp;
int8_t phi;
uint16_t rej;
uint16_t rej_init;
uint16_t snr;
};
struct lgw_sx125x_cal_tx_result_s {
uint8_t dac_gain;
uint8_t mix_gain;
int8_t offset_i;
int8_t offset_q;
uint16_t rej;
uint16_t sig;
};
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
int sx1302_cal_start(uint8_t version, struct lgw_conf_rxrf_s * rf_chain_cfg, struct lgw_tx_gain_lut_s * txgain_lut);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,74 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
LoRa concentrator HAL debug functions
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_DBG_H
#define _LORAGW_DBG_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief
@param
*/
void dbg_log_buffer_to_file(FILE * file, uint8_t * buffer, uint16_t size);
/**
@brief
@param
*/
void dbg_log_payload_diff_to_file(FILE * file, uint8_t * buffer1, uint8_t * buffer2, uint16_t size);
/**
@brief
@param
*/
void dbg_init_random(void);
/**
@brief
@param
*/
void dbg_generate_random_payload(uint32_t pkt_cnt, uint8_t * buffer_expected, uint8_t size);
/**
@brief
@param
*/
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 ------------------------------------------------------------------ */

234
libloragw/inc/loragw_gps.h Normal file
View file

@ -0,0 +1,234 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Library of functions to manage a GNSS module (typically GPS) for accurate
timestamping of packets and synchronisation of gateways.
A limited set of module brands/models are supported.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_GPS_H
#define _LORAGW_GPS_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#define _GNU_SOURCE
#include <stdint.h> /* C99 types */
#include <time.h> /* time library */
#include <termios.h> /* speed_t */
#include <unistd.h> /* ssize_t */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@struct coord_s
@brief Time solution required for timestamp to absolute time conversion
*/
struct tref {
time_t systime; /*!> system time when solution was calculated */
uint32_t count_us; /*!> reference concentrator internal timestamp */
struct timespec utc; /*!> reference UTC time (from GPS/NMEA) */
struct timespec gps; /*!> reference GPS time (since 01.Jan.1980) */
double xtal_err; /*!> raw clock error (eg. <1 'slow' XTAL) */
};
/**
@struct coord_s
@brief Geodesic coordinates
*/
struct coord_s {
double lat; /*!> latitude [-90,90] (North +, South -) */
double lon; /*!> longitude [-180,180] (East +, West -)*/
short alt; /*!> altitude in meters (WGS 84 geoid ref.) */
};
/**
@enum gps_msg
@brief Type of GPS (and other GNSS) sentences
*/
enum gps_msg {
UNKNOWN, /*!> neutral value */
IGNORED, /*!> frame was not parsed by the system */
INVALID, /*!> system try to parse frame but failed */
INCOMPLETE, /*!> frame parsed was missing bytes */
/* NMEA messages of interest */
NMEA_RMC, /*!> Recommended Minimum data (time + date) */
NMEA_GGA, /*!> Global positioning system fix data (pos + alt) */
NMEA_GNS, /*!> GNSS fix data (pos + alt, sat number) */
NMEA_ZDA, /*!> Time and Date */
/* NMEA message useful for time reference quality assessment */
NMEA_GBS, /*!> GNSS Satellite Fault Detection */
NMEA_GST, /*!> GNSS Pseudo Range Error Statistics */
NMEA_GSA, /*!> GNSS DOP and Active Satellites (sat number) */
NMEA_GSV, /*!> GNSS Satellites in View (sat SNR) */
/* Misc. NMEA messages */
NMEA_GLL, /*!> Latitude and longitude, with time fix and status */
NMEA_TXT, /*!> Text Transmission */
NMEA_VTG, /*!> Course over ground and Ground speed */
/* uBlox proprietary NMEA messages of interest */
UBX_NAV_TIMEGPS, /*!> GPS Time Solution */
UBX_NAV_TIMEUTC /*!> UTC Time Solution */
};
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_GPS_SUCCESS 0
#define LGW_GPS_ERROR -1
#define LGW_GPS_MIN_MSG_SIZE (8)
#define LGW_GPS_UBX_SYNC_CHAR (0xB5)
#define LGW_GPS_NMEA_SYNC_CHAR (0x24)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Configure a GPS module
@param tty_path path to the TTY connected to the GPS
@param gps_familly parameter (eg. ubx6 for uBlox gen.6)
@param target_brate target baudrate for communication (0 keeps default target baudrate)
@param fd_ptr pointer to a variable to receive file descriptor on GPS tty
@return success if the function was able to connect and configure a GPS module
*/
int lgw_gps_enable(char* tty_path, char* gps_familly, speed_t target_brate, int* fd_ptr);
/**
@brief Restore GPS serial configuration and close serial device
@param fd file descriptor on GPS tty
@return success if the function was able to complete
*/
int lgw_gps_disable(int fd);
/**
@brief Parse messages coming from the GPS system (or other GNSS)
@param serial_buff pointer to the string to be parsed
@param buff_size maximum string lengths for NMEA parsing (incl. null char)
@return type of frame parsed
The RAW NMEA sentences are parsed to a global set of variables shared with the
lgw_gps_get function.
If the lgw_parse_nmea and lgw_gps_get are used in different threads, a mutex
lock must be acquired before calling either function.
*/
enum gps_msg lgw_parse_nmea(const char* serial_buff, int buff_size);
/**
@brief Parse Ublox proprietary messages coming from the GPS system
@param serial_buff pointer to the string to be parsed
@param buff_size maximum string lengths for UBX parsing (incl. null char)
@param msg_size number of bytes parsed as UBX message if found
@return type of frame parsed
The RAW UBX sentences are parsed to a global set of variables shared with the
lgw_gps_get function.
If the lgw_parse_ubx and lgw_gps_get are used in different threads, a mutex
lock must be acquired before calling either function.
*/
enum gps_msg lgw_parse_ubx(const char* serial_buff, size_t buff_size, size_t *msg_size);
/**
@brief Get the GPS solution (space & time) for the concentrator
@param utc pointer to store UTC time, with ns precision (NULL to ignore)
@param gps_time pointer to store GPS time, with ns precision (NULL to ignore)
@param loc pointer to store coordinates (NULL to ignore)
@param err pointer to store coordinates standard deviation (NULL to ignore)
@return success if the chosen elements could be returned
This function read the global variables generated by the NMEA/UBX parsing
functions lgw_parse_nmea/lgw_parse_ubx. It returns time and location data in a
format that is exploitable by other functions in that library sub-module.
If the lgw_parse_nmea/lgw_parse_ubx and lgw_gps_get are used in different
threads, a mutex lock must be acquired before calling either function.
*/
int lgw_gps_get(struct timespec *utc, struct timespec *gps_time, struct coord_s *loc, struct coord_s *err);
/**
@brief Get time and position information from the serial GPS last message received
@param utc UTC time, with ns precision (leap seconds are ignored)
@param gps_time timestamp of last time pulse from the GPS module converted to the UNIX epoch
(leap seconds are ignored)
@param loc location information
@param err location error estimate if supported
@return success if timestamp was read and time reference could be refreshed
Set systime to 0 in ref to trigger initial synchronization.
*/
int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struct timespec gps_time);
/**
@brief Convert concentrator timestamp counter value to UTC time
@param ref time reference structure required for time conversion
@param count_us internal timestamp counter of the LoRa concentrator
@param utc pointer to store UTC time, with ns precision (leap seconds ignored)
@return success if the function was able to convert timestamp to UTC
This function is typically used when a packet is received to transform the
internal counter-based timestamp in an absolute timestamp with an accuracy in
the order of a couple microseconds (ns resolution).
*/
int lgw_cnt2utc(struct tref ref, uint32_t count_us, struct timespec* utc);
/**
@brief Convert UTC time to concentrator timestamp counter value
@param ref time reference structure required for time conversion
@param utc UTC time, with ns precision (leap seconds are ignored)
@param count_us pointer to store internal timestamp counter of LoRa concentrator
@return success if the function was able to convert UTC to timestamp
This function is typically used when a packet must be sent at an accurate time
(eg. to send a piggy-back response after receiving a packet from a node) to
transform an absolute UTC time into a matching internal concentrator timestamp.
*/
int lgw_utc2cnt(struct tref ref,struct timespec utc, uint32_t* count_us);
/**
@brief Convert concentrator timestamp counter value to GPS time
@param ref time reference structure required for time conversion
@param count_us internal timestamp counter of the LoRa concentrator
@param gps_time pointer to store GPS time, with ns precision (leap seconds ignored)
@return success if the function was able to convert timestamp to GPS time
This function is typically used when a packet is received to transform the
internal counter-based timestamp in an absolute timestamp with an accuracy in
the order of a millisecond.
*/
int lgw_cnt2gps(struct tref ref, uint32_t count_us, struct timespec* gps_time);
/**
@brief Convert GPS time to concentrator timestamp counter value
@param ref time reference structure required for time conversion
@param gps_time GPS time, with ns precision (leap seconds are ignored)
@param count_us pointer to store internal timestamp counter of LoRa concentrator
@return success if the function was able to convert GPS time to timestamp
This function is typically used when a packet must be sent at an accurate time
(eg. to send a piggy-back response after receiving a packet from a node) to
transform an absolute GPS time into a matching internal concentrator timestamp.
*/
int lgw_gps2cnt(struct tref ref, struct timespec gps_time, uint32_t* count_us);
#endif
/* --- EOF ------------------------------------------------------------------ */

463
libloragw/inc/loragw_hal.h Normal file
View file

@ -0,0 +1,463 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
LoRa concentrator Hardware Abstraction Layer
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_HAL_H
#define _LORAGW_HAL_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define IS_LORA_BW(bw) ((bw == BW_125KHZ) || (bw == BW_250KHZ) || (bw == BW_500KHZ))
#define IS_LORA_DR(dr) ((dr == DR_LORA_SF5) || (dr == DR_LORA_SF6) || (dr == DR_LORA_SF7) || (dr == DR_LORA_SF8) || (dr == DR_LORA_SF9) || (dr == DR_LORA_SF10) || (dr == DR_LORA_SF11) || (dr == DR_LORA_SF12))
#define IS_LORA_CR(cr) ((cr == CR_LORA_4_5) || (cr == CR_LORA_4_6) || (cr == CR_LORA_4_7) || (cr == CR_LORA_4_8))
#define IS_FSK_BW(bw) ((bw >= 1) && (bw <= 7))
#define IS_FSK_DR(dr) ((dr >= DR_FSK_MIN) && (dr <= DR_FSK_MAX))
#define IS_TX_MODE(mode) ((mode == IMMEDIATE) || (mode == TIMESTAMPED) || (mode == ON_GPS))
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* return status code */
#define LGW_HAL_SUCCESS 0
#define LGW_HAL_ERROR -1
#define LGW_LBT_ISSUE 1
/* radio-specific parameters */
#define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */
#define LGW_RF_CHAIN_NB 2 /* number of RF chains */
#define LGW_RF_RX_BANDWIDTH {1000000, 1000000} /* bandwidth of the radios */
/* 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 */
/* values available for the 'modulation' parameters */
/* NOTE: arbitrary values */
#define MOD_UNDEFINED 0
#define MOD_CW 0x08
#define MOD_LORA 0x10
#define MOD_FSK 0x20
/* values available for the 'bandwidth' parameters (LoRa & FSK) */
/* NOTE: directly encode FSK RX bandwidth, do not change */
#define BW_UNDEFINED 0
#define BW_500KHZ 0x06
#define BW_250KHZ 0x05
#define BW_125KHZ 0x04
/* values available for the 'datarate' parameters */
/* NOTE: LoRa values used directly to code SF bitmask in 'multi' modem, do not change */
#define DR_UNDEFINED 0
#define DR_LORA_SF5 5
#define DR_LORA_SF6 6
#define DR_LORA_SF7 7
#define DR_LORA_SF8 8
#define DR_LORA_SF9 9
#define DR_LORA_SF10 10
#define DR_LORA_SF11 11
#define DR_LORA_SF12 12
/* NOTE: for FSK directly use baudrate between 500 bauds and 250 kbauds */
#define DR_FSK_MIN 500
#define DR_FSK_MAX 250000
/* values available for the 'coderate' parameters (LoRa only) */
/* NOTE: arbitrary values */
#define CR_UNDEFINED 0
#define CR_LORA_4_5 0x01
#define CR_LORA_4_6 0x02
#define CR_LORA_4_7 0x03
#define CR_LORA_4_8 0x04
/* values available for the 'status' parameter */
/* NOTE: values according to hardware specification */
#define STAT_UNDEFINED 0x00
#define STAT_NO_CRC 0x01
#define STAT_CRC_BAD 0x11
#define STAT_CRC_OK 0x10
/* values available for the 'tx_mode' parameter */
#define IMMEDIATE 0
#define TIMESTAMPED 1
#define ON_GPS 2
/* values available for 'select' in the status function */
#define TX_STATUS 1
#define RX_STATUS 2
/* status code for TX_STATUS */
/* NOTE: arbitrary values */
#define TX_STATUS_UNKNOWN 0
#define TX_OFF 1 /* TX modem disabled, it will ignore commands */
#define TX_FREE 2 /* TX modem is free, ready to receive a command */
#define TX_SCHEDULED 3 /* TX modem is loaded, ready to send the packet after an event and/or delay */
#define TX_EMITTING 4 /* TX modem is emitting */
/* status code for RX_STATUS */
/* NOTE: arbitrary values */
#define RX_STATUS_UNKNOWN 0
#define RX_OFF 1 /* RX modem is disabled, it will ignore commands */
#define RX_ON 2 /* RX modem is receiving */
#define RX_SUSPENDED 3 /* RX is suspended while a TX is ongoing */
/* Maximum size of Tx gain LUT */
#define TX_GAIN_LUT_SIZE_MAX 16
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@enum lgw_radio_type_t
@brief Radio types that can be found on the LoRa Gateway
*/
typedef enum {
LGW_RADIO_TYPE_NONE,
LGW_RADIO_TYPE_SX1255,
LGW_RADIO_TYPE_SX1257,
LGW_RADIO_TYPE_SX1272,
LGW_RADIO_TYPE_SX1276,
LGW_RADIO_TYPE_SX1250
} lgw_radio_type_t;
/**
@struct lgw_conf_board_s
@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 */
};
/**
@struct lgw_rssi_tcomp_s
@brief Structure containing all coefficients necessary to compute the offset to be applied on RSSI for current temperature
*/
struct lgw_rssi_tcomp_s {
float coeff_a;
float coeff_b;
float coeff_c;
float coeff_d;
float coeff_e;
};
/**
@struct lgw_conf_rxrf_s
@brief Configuration structure for a RF chain
*/
struct lgw_conf_rxrf_s {
bool enable; /*!> enable or disable that RF chain */
uint32_t freq_hz; /*!> center frequency of the radio in Hz */
float rssi_offset; /*!> Board-specific RSSI correction factor */
struct lgw_rssi_tcomp_s rssi_tcomp; /*!> Board-specific RSSI temperature compensation coefficients */
lgw_radio_type_t type; /*!> Radio type for that RF chain (SX1255, SX1257....) */
bool tx_enable; /*!> enable or disable TX on that RF chain */
};
/**
@struct lgw_conf_rxif_s
@brief Configuration structure for an IF chain
*/
struct lgw_conf_rxif_s {
bool enable; /*!> enable or disable that IF chain */
uint8_t rf_chain; /*!> to which RF chain is that IF chain associated */
int32_t freq_hz; /*!> center frequ of the IF chain, relative to RF chain frequency */
uint8_t bandwidth; /*!> RX bandwidth, 0 for default */
uint32_t datarate; /*!> RX datarate, 0 for default */
uint8_t sync_word_size; /*!> size of FSK sync word (number of bytes, 0 for default) */
uint64_t sync_word; /*!> FSK sync word (ALIGN RIGHT, eg. 0xC194C1) */
bool implicit_hdr; /*!> LoRa Service implicit header */
uint8_t implicit_payload_length; /*!> LoRa Service implicit header payload length (number of bytes, 0 for default) */
bool implicit_crc_en; /*!> LoRa Service implicit header CRC enable */
uint8_t implicit_coderate; /*!> LoRa Service implicit header coding rate */
};
/**
@struct lgw_pkt_rx_s
@brief Structure containing the metadata of a packet that was received and a pointer to the payload
*/
struct lgw_pkt_rx_s {
uint32_t freq_hz; /*!> central frequency of the IF chain */
int32_t freq_offset;
uint8_t if_chain; /*!> by which IF chain was packet received */
uint8_t status; /*!> status of the received packet */
uint32_t count_us; /*!> internal concentrator counter for timestamping, 1 microsecond resolution */
uint8_t rf_chain; /*!> through which RF chain the packet was received */
uint8_t modem_id;
uint8_t modulation; /*!> modulation used by the packet */
uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
uint32_t datarate; /*!> RX datarate of the packet (SF for LoRa) */
uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */
float rssic; /*!> average RSSI of the channel in dB */
float rssis; /*!> average RSSI of the signal in dB */
float snr; /*!> average packet SNR, in dB (LoRa only) */
float snr_min; /*!> minimum packet SNR, in dB (LoRa only) */
float snr_max; /*!> maximum packet SNR, in dB (LoRa only) */
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 */
};
/**
@struct lgw_pkt_tx_s
@brief Structure containing the configuration of a packet to send and a pointer to the payload
*/
struct lgw_pkt_tx_s {
uint32_t freq_hz; /*!> center frequency of TX */
uint8_t tx_mode; /*!> select on what event/time the TX is triggered */
uint32_t count_us; /*!> timestamp or delay in microseconds for TX trigger */
uint8_t rf_chain; /*!> through which RF chain will the packet be sent */
int8_t rf_power; /*!> TX power, in dBm */
uint8_t modulation; /*!> modulation to use for the packet */
int8_t freq_offset; /*!> frequency offset from Radio Tx frequency (CW mode) */
uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for LoRa) */
uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */
bool invert_pol; /*!> invert signal polarity, for orthogonal downlinks (LoRa only) */
uint8_t f_dev; /*!> frequency deviation, in kHz (FSK only) */
uint16_t preamble; /*!> set the preamble length, 0 for default */
bool no_crc; /*!> if true, do not send a CRC in the packet */
bool no_header; /*!> if true, enable implicit header mode (LoRa), fixed length (FSK) */
uint16_t size; /*!> payload size in bytes */
uint8_t payload[256]; /*!> buffer containing the payload */
};
/**
@struct lgw_tx_gain_s
@brief Structure containing all gains of Tx chain
*/
struct lgw_tx_gain_s {
int8_t rf_power; /*!> measured TX power at the board connector, in dBm */
uint8_t dig_gain; /*!> (sx125x) 2 bits: control of the digital gain of SX1302 */
uint8_t pa_gain; /*!> (sx125x) 2 bits: control of the external PA (SX1302 I/O)
(sx1250) 1 bits: enable/disable the external PA (SX1302 I/O) */
uint8_t dac_gain; /*!> (sx125x) 2 bits: control of the radio DAC */
uint8_t mix_gain; /*!> (sx125x) 4 bits: control of the radio mixer */
int8_t offset_i; /*!> (sx125x) calibrated I offset */
int8_t offset_q; /*!> (sx125x) calibrated Q offset */
uint8_t pwr_idx; /*!> (sx1250) 6 bits: control the radio power index to be used for configuration */
};
/**
@struct lgw_tx_gain_lut_s
@brief Structure defining the Tx gain LUT
*/
struct lgw_tx_gain_lut_s {
struct lgw_tx_gain_s lut[TX_GAIN_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
uint8_t size; /*!> Number of LUT indexes */
};
/**
@struct lgw_conf_debug_s
@brief Configuration structure for debug
*/
struct conf_ref_payload_s {
uint32_t id;
uint8_t payload[255];
uint32_t prev_cnt;
};
struct lgw_conf_debug_s {
uint8_t nb_ref_payload;
struct conf_ref_payload_s ref_payload[16];
char log_file_name[128];
};
/**
@struct lgw_conf_debug_s
@brief Configuration structure for debug
*/
struct lgw_conf_timestamp_s {
bool enable_precision_ts;
uint8_t max_ts_metrics;
uint8_t nb_symbols;
};
/**
@struct lgw_context_s
@brief Configuration context shared across modules
*/
typedef struct lgw_context_s {
/* Global context */
bool is_started;
struct lgw_conf_board_s board_cfg;
/* 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_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;
/* Debug */
struct lgw_conf_debug_s debug_cfg;
} lgw_context_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Configure the gateway board
@param conf structure containing the configuration parameters
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_board_setconf(struct lgw_conf_board_s * conf);
/**
@brief Configure an RF chain (must configure before start)
@param rf_chain number of the RF chain to configure [0, LGW_RF_CHAIN_NB - 1]
@param conf structure containing the configuration parameters
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s * conf);
/**
@brief Configure an IF chain + modem (must configure before start)
@param if_chain number of the IF chain + modem to configure [0, LGW_IF_CHAIN_NB - 1]
@param conf structure containing the configuration parameters
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s * conf);
/**
@brief Configure the Tx gain LUT
@param 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
@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);
/**
@brief Configure the debug context
@param 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);
/**
@brief Connect to the LoRa concentrator, reset it and configure it according to previously set parameters
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_start(void);
/**
@brief Stop the LoRa concentrator and disconnect it
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_stop(void);
/**
@brief A non-blocking function that will fetch up to 'max_pkt' packets from the LoRa concentrator FIFO and data buffer
@param max_pkt maximum number of packet that must be retrieved (equal to the size of the array of struct)
@param pkt_data pointer to an array of struct that will receive the packet metadata and payload pointers
@return LGW_HAL_ERROR id the operation failed, else the number of packets retrieved
*/
int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s * pkt_data);
/**
@brief Schedule a packet to be send immediately or after a delay depending on tx_mode
@param pkt_data structure containing the data and metadata for the packet to send
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
/!\ When sending a packet, there is a delay (approx 1.5ms) for the analog
circuitry to start and be stable. This delay is adjusted by the HAL depending
on the board version (lgw_i_tx_start_delay_us).
In 'timestamp' mode, this is transparent: the modem is started
lgw_i_tx_start_delay_us microseconds before the user-set timestamp value is
reached, the preamble of the packet start right when the internal timestamp
counter reach target value.
In 'immediate' mode, the packet is emitted as soon as possible: transferring the
packet (and its parameters) from the host to the concentrator takes some time,
then there is the lgw_i_tx_start_delay_us, then the packet is emitted.
In 'triggered' mode (aka PPS/GPS mode), the packet, typically a beacon, is
emitted lgw_i_tx_start_delay_us microsenconds after a rising edge of the
trigger signal. Because there is no way to anticipate the triggering event and
start the analog circuitry beforehand, that delay must be taken into account in
the protocol.
*/
int lgw_send(struct lgw_pkt_tx_s * pkt_data);
/**
@brief Give the the status of different part of the LoRa concentrator
@param select is used to select what status we want to know
@param code is used to return the status code
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_status(uint8_t rf_chain, uint8_t select, uint8_t * code);
/**
@brief Abort a currently scheduled or ongoing TX
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_abort_tx(uint8_t rf_chain);
/**
@brief Return value of internal counter when latest event (eg GPS pulse) was captured
@param trig_cnt_us pointer to receive timestamp value
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_get_trigcnt(uint32_t * trig_cnt_us);
/**
@brief Return instateneous value of internal counter
@param inst_cnt_us pointer to receive timestamp value
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_get_instcnt(uint32_t * inst_cnt_us);
/**
@brief Return the LoRa concentrator EUI
@param eui pointer to receive eui
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_get_eui(uint64_t * eui);
/**
@brief Allow user to check the version/options of the library once compiled
@return pointer on a human-readable null terminated string
*/
const char* lgw_version_info(void);
/**
@brief Return time on air of given packet, in milliseconds
@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);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,75 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Host specific functions to address the LoRa concentrator I2C peripherals.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_I2C_H
#define _LORAGW_I2C_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_I2C_SUCCESS 0
#define LGW_I2C_ERROR -1
#define I2C_DEVICE "/dev/i2c-1"
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief Open I2C port
@param path Path to the I2C device driver (absolute or relative)
@param device_addr Address of the device
@param i2c_fd Pointer to receive I2C port file descriptor index
@return 0 if I2C port was open successfully, -1 else
*/
int i2c_linuxdev_open(const char *path, uint8_t device_addr, int *i2c_fd);
/**
@brief Close I2C port
@param i2c_fd I2C port file descriptor index
@return 0 if I2C port was closed successfully, -1 else
*/
int i2c_linuxdev_close(int i2c_fd);
/**
@brief Read data from an I2C port
@param i2c_fd I2C port file descriptor index
@param device_addr I2C device address
@param reg_addr Address of the register to be read
@param data Pointer to a buffer to store read data
@return 0 if I2C data read is successful, -1 else
*/
int i2c_linuxdev_read(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t *data);
/**
@brief Write data to an I2C port
@param i2c_fd I2C port file descriptor index
@param device_addr I2C device address
@param reg_addr Address of the register to write to
@param data byte to write in the register
@return 0 if I2C data write is successful, -1 else
*/
int i2c_linuxdev_write(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t data);
#endif
/* --- EOF ------------------------------------------------------------------ */

1493
libloragw/inc/loragw_reg.h Normal file

File diff suppressed because it is too large Load diff

102
libloragw/inc/loragw_spi.h Normal file
View file

@ -0,0 +1,102 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Host specific functions to address the LoRa concentrator registers through
a SPI interface.
Single-byte read/write and burst read/write.
Could be used with multiple SPI ports in parallel (explicit file descriptor)
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SPI_H
#define _LORAGW_SPI_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* 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 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 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);
/**
@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_target, uint16_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_target, uint16_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_target, uint16_t address, const 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_target, uint16_t address, uint8_t *data, uint16_t size);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,57 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Basic driver for ST ts751 temperature sensor
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_STTS751_H
#define _LORAGW_STTS751_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED FUNCTIONS -------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define I2C_PORT_TEMP_SENSOR 0x39
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
/**
@brief TODO
@param TODO
@return TODO
*/
int lgw_stts751_configure(void);
/**
@brief TODO
@param TODO
@return TODO
*/
int lgw_stts751_get_temperature(float * temperature);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,101 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(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 _LORAGW_SX1250_H
#define _LORAGW_SX1250_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_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);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,148 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Functions used to handle LoRa concentrator SX1255/SX1257 radios.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SX125X_H
#define _LORAGW_SX125X_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
/* -------------------------------------------------------------------------- */
/* --- INTERNAL SHARED TYPES ------------------------------------------------ */
struct radio_reg_s
{
uint8_t addr; /* base address of the register */
uint8_t offs; /* position of the register LSB (between 0 to 7) */
uint8_t leng; /* number of bits in the register */
};
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define SX1257_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 19) / 32000000U)
#define SX1255_FREQ_TO_REG(f) (uint32_t)((uint64_t)f * (1 << 20) / 32000000U)
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
#define LGW_REG_SUCCESS 0
#define LGW_REG_ERROR -1
#define SX125x_32MHz_FRAC 15625 /* irreductible fraction for PLL register caculation */
#define SX125x_TX_DAC_CLK_SEL 0 /* 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 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 */
#define SX125x_RX_BB_GAIN 15 /* 0 to 15 , 15 highest gain */
#define SX125x_LNA_ZIN 0 /* 0:50, 1:200 Ohms (default 1) */
#define SX125x_RX_ADC_BW 7 /* 0 to 7, 2:100<BW<200, 5:200<BW<400,7:400<BW kHz SSB (default 7) */
#define SX125x_RX_ADC_TRIM 6 /* 0 to 7, 6 for 32MHz ref, 5 for 36MHz ref */
#define SX125x_RX_BB_BW 0 /* 0:750, 1:500, 2:375; 3:250 kHz SSB (default 1, max 3) */
#define SX125x_RX_PLL_BW 0 /* 0:75, 1:150, 2:225, 3:300 kHz (default 3, max 3) */
#define SX125x_ADC_TEMP 0 /* ADC temperature measurement mode (default 0) */
#define SX125x_XOSC_GM_STARTUP 13 /* (default 13) */
#define SX125x_XOSC_DISABLE 2 /* Disable of Xtal Oscillator blocks bit0:regulator, bit1:core(gm), bit2:amplifier */
typedef enum {
SX125x_REG_MODE = 0,
SX125x_REG_MODE__PA_DRIVER_EN = 1,
SX125x_REG_MODE__TX_EN = 2,
SX125x_REG_MODE__RX_EN = 3,
SX125x_REG_MODE__STANDBY_EN = 4,
SX125x_REG_FRF_RX_MSB = 5,
SX125x_REG_FRF_RX_MID = 6,
SX125x_REG_FRF_RX_LSB = 7,
SX125x_REG_FRF_TX_MSB = 8,
SX125x_REG_FRF_TX_MID = 9,
SX125x_REG_FRF_TX_LSB = 10,
SX125x_REG_VERSION = 11,
SX125x_REG_TX_GAIN = 12,
SX125x_REG_TX_GAIN__DAC_GAIN = 13,
SX125x_REG_TX_GAIN__MIX_GAIN = 14,
SX125x_REG_TX_BW = 15,
SX125x_REG_TX_BW__PLL_BW = 16,
SX125x_REG_TX_BW__ANA_BW = 17,
SX125x_REG_TX_DAC_BW = 18,
SX125x_REG_RX_ANA_GAIN = 19,
SX125x_REG_RX_ANA_GAIN__LNA_GAIN = 20,
SX125x_REG_RX_ANA_GAIN__BB_GAIN = 21,
SX125x_REG_RX_ANA_GAIN__LNA_ZIN = 22,
SX125x_REG_RX_BW = 23,
SX125x_REG_RX_BW__ADC_BW = 24,
SX125x_REG_RX_BW__ADC_TRIM = 25,
SX125x_REG_RX_BW__BB_BW = 26,
SX125x_REG_RX_PLL_BW = 27,
SX125x_REG_RX_PLL_BW__PLL_BW = 28,
SX125x_REG_RX_PLL_BW__ADC_TEMP_EN = 29,
SX125x_REG_DIO_MAPPING = 30,
SX125x_REG_DIO_MAPPING__DIO_0_MAPPING = 31,
SX125x_REG_DIO_MAPPING__DIO_1_MAPPING = 32,
SX125x_REG_DIO_MAPPING__DIO_2_MAPPING = 33,
SX125x_REG_DIO_MAPPING__DIO_3_MAPPING = 34,
SX125x_REG_CLK_SELECT = 35,
SX125x_REG_CLK_SELECT__DIG_LOOPBACK_EN = 36,
SX125x_REG_CLK_SELECT__RF_LOOPBACK_EN = 37,
SX125x_REG_CLK_SELECT__CLK_OUT = 38,
SX125x_REG_CLK_SELECT__DAC_CLK_SELECT = 39,
SX125x_REG_MODE_STATUS = 40,
SX125x_REG_MODE_STATUS__LOW_BAT_EN = 41,
SX125x_REG_MODE_STATUS__RX_PLL_LOCKED = 42,
SX125x_REG_MODE_STATUS__TX_PLL_LOCKED = 43,
SX125x_REG_LOW_BAT_THRESH = 44,
SX125x_REG_SX1257_XOSC_TEST = 45,
SX125x_REG_SX1257_XOSC_TEST__DISABLE = 46,
SX125x_REG_SX1257_XOSC_TEST__GM_STARTUP = 47,
SX125x_REG_SX1255_XOSC_TEST = 48,
SX125x_REG_SX1255_XOSC_TEST__DISABLE = 49,
SX125x_REG_SX1255_XOSC_TEST__GM_STARTUP = 50
}
radio_reg_t;
#define RADIO_TOTALREGS 51
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/*
SX1257 frequency setting :
F_register(24bit) = F_rf (Hz) / F_step(Hz)
= F_rf (Hz) * 2^19 / F_xtal(Hz)
= F_rf (Hz) * 2^19 / 32e6
= F_rf (Hz) * 256/15625
SX1255 frequency setting :
F_register(24bit) = F_rf (Hz) / F_step(Hz)
= F_rf (Hz) * 2^20 / F_xtal(Hz)
= F_rf (Hz) * 2^20 / 32e6
= F_rf (Hz) * 512/15625
*/
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
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);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,437 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
SX1302 Hardware Abstraction Layer entry functions.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SX1302_H
#define _LORAGW_SX1302_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* Default values */
#define SX1302_AGC_RADIO_GAIN_AUTO 0xFF
#define TX_START_DELAY_DEFAULT 1500 /* Calibrated value for 500KHz BW */
/* type of if_chain + modem */
#define IF_UNDEFINED 0
#define IF_LORA_STD 0x10 /* if + standard single-SF LoRa modem */
#define IF_LORA_MULTI 0x11 /* if + LoRa receiver with multi-SF capability */
#define IF_FSK_STD 0x20 /* if + standard FSK modem */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
#define REG_SELECT(rf_chain, a, b) ((rf_chain == 0) ? a : b)
#define SET_PPM_ON(bw,dr) (((bw == BW_125KHZ) && ((dr == DR_LORA_SF11) || (dr == DR_LORA_SF12))) || ((bw == BW_250KHZ) && (dr == DR_LORA_SF12)))
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@struct sx1302_if_cfg_t
@brief TODO
*/
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;
/**
@struct sx1302_lora_service_cfg_t
@brief TODO
*/
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;
/**
@struct sx1302_fsk_cfg_t
@brief TODO
*/
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;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief TODO
@param TODO
@return TODO
*/
void sx1302_init(struct lgw_conf_timestamp_s *conf);
/**
@brief Get the SX1302 unique identifier
@param eui pointerto the memory holding the concentrator EUI
@return LGW_REG_SUCCESS if no error, LGW_REG_ERROR otherwise
*/
int sx1302_get_eui(uint64_t * eui);
/**
@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
@param N/A
@return LGW_REG_SUCCESS if no error, LGW_REG_ERROR otherwise
*/
int sx1302_update(void);
/**
@brief Select the clock source radio
@param rf_chain The RF chain index from which to get the clock source
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_clock_select(uint8_t rf_chain);
/**
@brief Apply the radio reset sequence to the required RF chain index
@param rf_chain The RF chain index of the radio to be reset
@param type The type of radio to be reset
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_reset(uint8_t rf_chain, lgw_radio_type_t type);
/**
@brief Configure the radio type for the given RF chain
@param rf_chain The RF chain index to be configured
@param type The type of radio to be set for the given RF chain
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_set_mode(uint8_t rf_chain, lgw_radio_type_t type);
/**
@brief Give/Release control over the radios to/from the Host
@param host_ctrl Set to true to give control to the host, false otherwise
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_host_ctrl(bool host_ctrl);
/**
@brief Perform the radio calibration sequence and fill the TX gain LUT with calibration offsets
@param context_rf_chain The RF chains array from which to get RF chains current configuration
@param clksrc The RF chain index which provides the clock source
@param txgain_lut A pointer to the TX gain LUT to be filled
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_calibrate(struct lgw_conf_rxrf_s * context_rf_chain, uint8_t clksrc, struct lgw_tx_gain_lut_s * txgain_lut);
/**
@brief Configure the PA and LNA LUTs
@param N/A
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_pa_lna_lut_configure(void);
/**
@brief Configure the Radio Front-End stage of the SX1302
@param N/A
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_radio_fe_configure(void);
/**
@brief TODO
@param TODO
@return TODO
*/
uint8_t sx1302_get_ifmod_config(uint8_t if_chain);
/**
@brief Configure the channelizer stage of the SX1302
@param if_cfg A pointer to the channels configuration
@param fix_gain Set to true to force the channelizer to a fixed gain, false to let the AGC controlling it
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
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
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_correlator_configure(void);
/**
@brief Configure the correlator stage of the SX1302 LoRa single-SF modem
@param cfg A pointer to the channel configuration
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_service_correlator_configure(struct lgw_conf_rxif_s * cfg);
/**
@brief Configure the syncword to be used by LoRa modems (public:0x34, private:0x12)
@param public Set to true to use the "public" syncword, false to use the private one
@param lora_service_sf The spreading factor configured for the single-SF LoRa modem
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_syncword(bool public, uint8_t lora_service_sf);
/**
@brief Configure the LoRa multi-SF modems
@param radio_freq_hz The center frequency of the RF chain (0 or 1)
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_modem_configure(uint32_t radio_freq_hz);
/**
@brief Configure the LoRa single-SF modem
@param cfg A pointer to the channel configuration
@param radio_freq_hz The center frequency of the RF chain (0 or 1)
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_lora_service_modem_configure(struct lgw_conf_rxif_s * cfg, uint32_t radio_freq_hz);
/**
@brief Configure the FSK modem
@param cfg A pointer to the channel configuration
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_fsk_configure(struct lgw_conf_rxif_s * cfg);
/**
@brief Enable the modems
@param N/A
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_modem_enable(void);
/**
@brief Enable/Disable the GPS to allow PPS trigger and counter sampling
@param enbale Set to true to enable, false otherwise
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_gps_enable(bool enable);
/**
@brief Get the current SX1302 internal counter value
@param pps True for getting the counter value at last PPS
@return the counter value in mciroseconds (32-bits)
*/
uint32_t sx1302_timestamp_counter(bool pps);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_agc_load_firmware(const uint8_t *firmware);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_agc_status(uint8_t* status);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_agc_wait_status(uint8_t status);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_agc_mailbox_read(uint8_t mailbox, uint8_t* value);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_agc_mailbox_write(uint8_t mailbox, uint8_t value);
/**
@brief TODO
@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);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_load_firmware(const uint8_t *firmware);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_status(uint8_t* status);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_wait_status(uint8_t status);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_debug_read(uint8_t reg_id, uint8_t* value);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_debug_write(uint8_t reg_id, uint8_t value);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_arb_start(uint8_t version);
/**
@brief TODO
@param TODO
@return TODO
*/
uint8_t sx1302_arb_get_debug_stats_detect(uint8_t channel);
/**
@brief TODO
@param TODO
@return TODO
*/
uint8_t sx1302_arb_get_debug_stats_alloc(uint8_t channel);
/**
@brief TODO
@param TODO
@return TODO
*/
void sx1302_arb_print_debug_stats(void);
/**
@brief TODO
@param TODO
@return TODO
*/
uint16_t sx1302_lora_payload_crc(const uint8_t * data, uint8_t size);
/**
@brief TODO
@param TODO
@return TODO
*/
uint16_t sx1302_rx_buffer_read_ptr_addr(void);
/**
@brief TODO
@param TODO
@return TODO
*/
uint16_t sx1302_rx_buffer_write_ptr_addr(void);
/**
@brief Check if any data to be fetched from the SX1302 RX buffer and fetch it if any.
@param nb_bytes A pointer to allocated memory to hold the number of bytes fetched
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_fetch(uint16_t * nb_bytes);
/**
@brief Parse and return the next packet available in the fetched RX buffer.
@param context Gateway configuration context
@param p The structure to get the packet parsed
@return LGW_REG_SUCCESS if a packet could be parsed, LGW_REG_ERROR otherwise
*/
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
@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);
/**
@brief Compute the offset to be applied on RSSI for temperature compensation
@param context a pointer to the memory that holds the current temp comp context
@param temperature the temperature for which to compute the offset to be applied
@return the offset to be applied to RSSI
*/
float sx1302_rssi_get_temperature_offset(struct lgw_rssi_tcomp_s * context, float temperature);
/**
@brief Get current TX status of the SX1302
@param rf_chain the TX chain we want to get the status from
@return current status
*/
uint8_t sx1302_tx_status(uint8_t rf_chain);
/**
@brief Get current RX status of the SX1302
@param rf_chain the RX chain we want to get the status from
@return current status
@note NOT IMPLEMENTED
*/
uint8_t sx1302_rx_status(uint8_t rf_chain);
/**
@brief Abort current transmit
@param rf_chain the TX chain on which we want to abort transmit
@return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
*/
int sx1302_tx_abort(uint8_t rf_chain);
/**
@brief TODO
@param TODO
@return TODO
*/
int sx1302_tx_configure(lgw_radio_type_t radio_type);
/**
@brief TODO
@param TODO
@return TODO
*/
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);
#endif
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,134 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
SX1302 RX buffer Hardware Abstraction Layer
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SX1302_RX_H
#define _LORAGW_SX1302_RX_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@struct rx_packet_s
@brief packet structure as contained in the sx1302 RX packet engine
*/
typedef struct rx_packet_s {
uint8_t rxbytenb_modem;
uint8_t rx_channel_in;
bool crc_en;
uint8_t coding_rate; /* LoRa only */
uint8_t rx_rate_sf; /* LoRa only */
uint8_t modem_id;
int32_t frequency_offset_error; /* LoRa only */
uint8_t payload[255];
bool payload_crc_error;
bool sync_error; /* LoRa only */
bool header_error; /* LoRa only */
bool timing_set; /* LoRa only */
int8_t snr_average; /* LoRa only */
uint8_t rssi_chan_avg;
uint8_t rssi_signal_avg; /* LoRa only */
uint8_t rssi_chan_max_neg_delta;
uint8_t rssi_chan_max_pos_delta;
uint8_t rssi_sig_max_neg_delta; /* LoRa only */
uint8_t rssi_sig_max_pos_delta; /* LoRa only */
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 */
uint8_t packet_checksum;
} rx_packet_t;
/**
@struct rx_buffer_s
@brief buffer to hold the data fetched from the sx1302 RX buffer
*/
typedef struct rx_buffer_s {
uint8_t buffer[4096]; /*!> byte array to hald the data fetched from the RX buffer */
uint16_t buffer_size; /*!> The number of bytes currently stored in the buffer */
int buffer_index; /*!> Current parsing index in the buffer */
} rx_buffer_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
/**
@brief TODO
@param TODO
@return TODO
*/
int rx_buffer_new(rx_buffer_t * self);
/**
@brief TODO
@param TODO
@return TODO
*/
int rx_buffer_del(rx_buffer_t * self);
/**
@brief TODO
@param TODO
@return TODO
*/
int rx_buffer_fetch(rx_buffer_t * self);
/**
@brief TODO
@param TODO
@return TODO
*/
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
/* --- EOF ------------------------------------------------------------------ */

View file

@ -0,0 +1,117 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
SX1302 timestamp counter Hardware Abstraction Layer
Handles the conversion of a 32-bits 32MHz counter into a 32-bits 1 MHz counter.
This modules MUST be called regularly by the application to maintain counter
wrapping handling for conversion in 1MHz counter.
Provides function to compute the correction to be applied to the received
timestamp for demodulation processing time.
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
#ifndef _LORAGW_SX1302_TIMESTAMP_H
#define _LORAGW_SX1302_TIMESTAMP_H
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h> /* C99 types*/
#include <stdbool.h> /* boolean type */
#include "config.h" /* library configuration options (dynamically generated) */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC MACROS -------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PUBLIC TYPES --------------------------------------------------------- */
/**
@struct timestamp_counter_s
@brief context to maintain the internal counters (inst and pps trig) wrapping
*/
typedef struct timestamp_counter_s {
uint32_t counter_us_raw_27bits_inst_prev;
uint32_t counter_us_raw_27bits_pps_prev;
uint8_t counter_us_raw_27bits_inst_wrap;
uint8_t counter_us_raw_27bits_pps_wrap;
} timestamp_counter_t;
/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
/**
@brief TODO
@param TODO
@return TODO
*/
void timestamp_counter_new(timestamp_counter_t * self);
/**
@brief TODO
@param TODO
@return TODO
*/
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
@return N/A
*/
void timestamp_counter_update(timestamp_counter_t * self, bool 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.
@param self Pointer to the counter handler
@param pps Set to true to expand the counter based on the PPS trig wrapping status
@param cnt_us The 27-bits counter to be expanded
@return the 32-bits counter
*/
uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, 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
*/
uint32_t timestamp_counter_get(timestamp_counter_t * self, bool pps);
/**
@brief Get the timestamp correction to applied to the packet timestamp
@param ifmod modem type
@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
@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);
/**
@brief TODO
@param TODO
@return TODO
*/
int timestamp_counter_mode(bool enable_precision_ts, uint8_t max_ts_metrics, uint8_t nb_symbols);
#endif
/* --- EOF ------------------------------------------------------------------ */