loragw_hal.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. LoRa concentrator Hardware Abstraction Layer
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. */
  12. #ifndef _LORAGW_HAL_H
  13. #define _LORAGW_HAL_H
  14. /* -------------------------------------------------------------------------- */
  15. /* --- DEPENDANCIES --------------------------------------------------------- */
  16. #include <stdint.h> /* C99 types */
  17. #include <stdbool.h> /* bool type */
  18. #include "loragw_com.h"
  19. #include "config.h" /* library configuration options (dynamically generated) */
  20. /* -------------------------------------------------------------------------- */
  21. /* --- PUBLIC MACROS -------------------------------------------------------- */
  22. #define IS_LORA_BW(bw) ((bw == BW_125KHZ) || (bw == BW_250KHZ) || (bw == BW_500KHZ))
  23. #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))
  24. #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))
  25. #define IS_FSK_BW(bw) ((bw >= 1) && (bw <= 7))
  26. #define IS_FSK_DR(dr) ((dr >= DR_FSK_MIN) && (dr <= DR_FSK_MAX))
  27. #define IS_TX_MODE(mode) ((mode == IMMEDIATE) || (mode == TIMESTAMPED) || (mode == ON_GPS))
  28. /* -------------------------------------------------------------------------- */
  29. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  30. /* return status code */
  31. #define LGW_HAL_SUCCESS 0
  32. #define LGW_HAL_ERROR -1
  33. #define LGW_LBT_NOT_ALLOWED 1
  34. /* radio-specific parameters */
  35. #define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */
  36. #define LGW_RF_CHAIN_NB 2 /* number of RF chains */
  37. #define LGW_RF_RX_BANDWIDTH {1000000, 1000000} /* bandwidth of the radios */
  38. /* concentrator chipset-specific parameters */
  39. #define LGW_IF_CHAIN_NB 10 /* number of IF+modem RX chains */
  40. #define LGW_REF_BW 125000 /* typical bandwidth of data channel */
  41. #define LGW_MULTI_NB 8 /* number of LoRa 'multi SF' chains */
  42. #define LGW_MULTI_SF_EN 0xFF /* bitmask to enable/disable SF for multi-sf correlators (12 11 10 9 8 7 6 5) */
  43. /* values available for the 'modulation' parameters */
  44. /* NOTE: arbitrary values */
  45. #define MOD_UNDEFINED 0
  46. #define MOD_CW 0x08
  47. #define MOD_LORA 0x10
  48. #define MOD_FSK 0x20
  49. /* values available for the 'bandwidth' parameters (LoRa & FSK) */
  50. /* NOTE: directly encode FSK RX bandwidth, do not change */
  51. #define BW_UNDEFINED 0
  52. #define BW_500KHZ 0x06
  53. #define BW_250KHZ 0x05
  54. #define BW_125KHZ 0x04
  55. /* values available for the 'datarate' parameters */
  56. /* NOTE: LoRa values used directly to code SF bitmask in 'multi' modem, do not change */
  57. #define DR_UNDEFINED 0
  58. #define DR_LORA_SF5 5
  59. #define DR_LORA_SF6 6
  60. #define DR_LORA_SF7 7
  61. #define DR_LORA_SF8 8
  62. #define DR_LORA_SF9 9
  63. #define DR_LORA_SF10 10
  64. #define DR_LORA_SF11 11
  65. #define DR_LORA_SF12 12
  66. /* NOTE: for FSK directly use baudrate between 500 bauds and 250 kbauds */
  67. #define DR_FSK_MIN 500
  68. #define DR_FSK_MAX 250000
  69. /* values available for the 'coderate' parameters (LoRa only) */
  70. /* NOTE: arbitrary values */
  71. #define CR_UNDEFINED 0 /* CR0 exists but is not recommended, so consider it as invalid */
  72. #define CR_LORA_4_5 0x01
  73. #define CR_LORA_4_6 0x02
  74. #define CR_LORA_4_7 0x03
  75. #define CR_LORA_4_8 0x04
  76. /* values available for the 'status' parameter */
  77. /* NOTE: values according to hardware specification */
  78. #define STAT_UNDEFINED 0x00
  79. #define STAT_NO_CRC 0x01
  80. #define STAT_CRC_BAD 0x11
  81. #define STAT_CRC_OK 0x10
  82. /* values available for the 'tx_mode' parameter */
  83. #define IMMEDIATE 0
  84. #define TIMESTAMPED 1
  85. #define ON_GPS 2
  86. /* values available for 'select' in the status function */
  87. #define TX_STATUS 1
  88. #define RX_STATUS 2
  89. /* status code for TX_STATUS */
  90. /* NOTE: arbitrary values */
  91. #define TX_STATUS_UNKNOWN 0
  92. #define TX_OFF 1 /* TX modem disabled, it will ignore commands */
  93. #define TX_FREE 2 /* TX modem is free, ready to receive a command */
  94. #define TX_SCHEDULED 3 /* TX modem is loaded, ready to send the packet after an event and/or delay */
  95. #define TX_EMITTING 4 /* TX modem is emitting */
  96. /* status code for RX_STATUS */
  97. /* NOTE: arbitrary values */
  98. #define RX_STATUS_UNKNOWN 0
  99. #define RX_OFF 1 /* RX modem is disabled, it will ignore commands */
  100. #define RX_ON 2 /* RX modem is receiving */
  101. #define RX_SUSPENDED 3 /* RX is suspended while a TX is ongoing */
  102. /* Maximum size of Tx gain LUT */
  103. #define TX_GAIN_LUT_SIZE_MAX 16
  104. /* Listen-Before-Talk */
  105. #define LGW_LBT_CHANNEL_NB_MAX 16 /* Maximum number of LBT channels */
  106. /* Spectral Scan */
  107. #define LGW_SPECTRAL_SCAN_RESULT_SIZE 33 /* The number of results returned by spectral scan function, to be used for memory allocation */
  108. /* -------------------------------------------------------------------------- */
  109. /* --- PUBLIC TYPES --------------------------------------------------------- */
  110. /**
  111. @enum lgw_radio_type_t
  112. @brief Radio types that can be found on the LoRa Gateway
  113. */
  114. typedef enum {
  115. LGW_RADIO_TYPE_NONE,
  116. LGW_RADIO_TYPE_SX1255,
  117. LGW_RADIO_TYPE_SX1257,
  118. LGW_RADIO_TYPE_SX1272,
  119. LGW_RADIO_TYPE_SX1276,
  120. LGW_RADIO_TYPE_SX1250
  121. } lgw_radio_type_t;
  122. /**
  123. @struct lgw_conf_board_s
  124. @brief Configuration structure for board specificities
  125. */
  126. struct lgw_conf_board_s {
  127. bool lorawan_public; /*!> Enable ONLY for *public* networks using the LoRa MAC protocol */
  128. uint8_t clksrc; /*!> Index of RF chain which provides clock to concentrator */
  129. bool full_duplex; /*!> Indicates if the gateway operates in full duplex mode or not */
  130. lgw_com_type_t com_type; /*!> The COMmunication interface (SPI/USB) to connect to the SX1302 */
  131. char com_path[64]; /*!> Path to access the COM device to connect to the SX1302 */
  132. };
  133. /**
  134. @struct lgw_rssi_tcomp_s
  135. @brief Structure containing all coefficients necessary to compute the offset to be applied on RSSI for current temperature
  136. */
  137. struct lgw_rssi_tcomp_s {
  138. float coeff_a;
  139. float coeff_b;
  140. float coeff_c;
  141. float coeff_d;
  142. float coeff_e;
  143. };
  144. /**
  145. @struct lgw_conf_rxrf_s
  146. @brief Configuration structure for a RF chain
  147. */
  148. struct lgw_conf_rxrf_s {
  149. bool enable; /*!> enable or disable that RF chain */
  150. uint32_t freq_hz; /*!> center frequency of the radio in Hz */
  151. float rssi_offset; /*!> Board-specific RSSI correction factor */
  152. struct lgw_rssi_tcomp_s rssi_tcomp; /*!> Board-specific RSSI temperature compensation coefficients */
  153. lgw_radio_type_t type; /*!> Radio type for that RF chain (SX1255, SX1257....) */
  154. bool tx_enable; /*!> enable or disable TX on that RF chain */
  155. bool single_input_mode; /*!> Configure the radio in single or differential input mode (SX1250 only) */
  156. };
  157. /**
  158. @struct lgw_conf_rxif_s
  159. @brief Configuration structure for an IF chain
  160. */
  161. struct lgw_conf_rxif_s {
  162. bool enable; /*!> enable or disable that IF chain */
  163. uint8_t rf_chain; /*!> to which RF chain is that IF chain associated */
  164. int32_t freq_hz; /*!> center frequ of the IF chain, relative to RF chain frequency */
  165. uint8_t bandwidth; /*!> RX bandwidth, 0 for default */
  166. uint32_t datarate; /*!> RX datarate, 0 for default */
  167. uint8_t sync_word_size; /*!> size of FSK sync word (number of bytes, 0 for default) */
  168. uint64_t sync_word; /*!> FSK sync word (ALIGN RIGHT, eg. 0xC194C1) */
  169. bool implicit_hdr; /*!> LoRa Service implicit header */
  170. uint8_t implicit_payload_length; /*!> LoRa Service implicit header payload length (number of bytes, 0 for default) */
  171. bool implicit_crc_en; /*!> LoRa Service implicit header CRC enable */
  172. uint8_t implicit_coderate; /*!> LoRa Service implicit header coding rate */
  173. };
  174. /**
  175. @struct lgw_conf_demod_s
  176. @brief Configuration structure for LoRa/FSK demodulators
  177. */
  178. struct lgw_conf_demod_s {
  179. uint8_t multisf_datarate; /*!> bitmask to enable spreading-factors for correlators (SF12 - SF5) */
  180. };
  181. /**
  182. @struct lgw_pkt_rx_s
  183. @brief Structure containing the metadata of a packet that was received and a pointer to the payload
  184. */
  185. struct lgw_pkt_rx_s {
  186. uint32_t freq_hz; /*!> central frequency of the IF chain */
  187. int32_t freq_offset;
  188. uint8_t if_chain; /*!> by which IF chain was packet received */
  189. uint8_t status; /*!> status of the received packet */
  190. uint32_t count_us; /*!> internal concentrator counter for timestamping, 1 microsecond resolution */
  191. uint8_t rf_chain; /*!> through which RF chain the packet was received */
  192. uint8_t modem_id;
  193. uint8_t modulation; /*!> modulation used by the packet */
  194. uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
  195. uint32_t datarate; /*!> RX datarate of the packet (SF for LoRa) */
  196. uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */
  197. float rssic; /*!> average RSSI of the channel in dB */
  198. float rssis; /*!> average RSSI of the signal in dB */
  199. float snr; /*!> average packet SNR, in dB (LoRa only) */
  200. float snr_min; /*!> minimum packet SNR, in dB (LoRa only) */
  201. float snr_max; /*!> maximum packet SNR, in dB (LoRa only) */
  202. uint16_t crc; /*!> CRC that was received in the payload */
  203. uint16_t size; /*!> payload size in bytes */
  204. uint8_t payload[256]; /*!> buffer containing the payload */
  205. bool ftime_received; /*!> a fine timestamp has been received */
  206. uint32_t ftime; /*!> packet fine timestamp (nanoseconds since last PPS) */
  207. };
  208. /**
  209. @struct lgw_pkt_tx_s
  210. @brief Structure containing the configuration of a packet to send and a pointer to the payload
  211. */
  212. struct lgw_pkt_tx_s {
  213. uint32_t freq_hz; /*!> center frequency of TX */
  214. uint8_t tx_mode; /*!> select on what event/time the TX is triggered */
  215. uint32_t count_us; /*!> timestamp or delay in microseconds for TX trigger */
  216. uint8_t rf_chain; /*!> through which RF chain will the packet be sent */
  217. int8_t rf_power; /*!> TX power, in dBm */
  218. uint8_t modulation; /*!> modulation to use for the packet */
  219. int8_t freq_offset; /*!> frequency offset from Radio Tx frequency (CW mode) */
  220. uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
  221. uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for LoRa) */
  222. uint8_t coderate; /*!> error-correcting code of the packet (LoRa only) */
  223. bool invert_pol; /*!> invert signal polarity, for orthogonal downlinks (LoRa only) */
  224. uint8_t f_dev; /*!> frequency deviation, in kHz (FSK only) */
  225. uint16_t preamble; /*!> set the preamble length, 0 for default */
  226. bool no_crc; /*!> if true, do not send a CRC in the packet */
  227. bool no_header; /*!> if true, enable implicit header mode (LoRa), fixed length (FSK) */
  228. uint16_t size; /*!> payload size in bytes */
  229. uint8_t payload[256]; /*!> buffer containing the payload */
  230. };
  231. /**
  232. @struct lgw_tx_gain_s
  233. @brief Structure containing all gains of Tx chain
  234. */
  235. struct lgw_tx_gain_s {
  236. int8_t rf_power; /*!> measured TX power at the board connector, in dBm */
  237. uint8_t dig_gain; /*!> (sx125x) 2 bits: control of the digital gain of SX1302 */
  238. uint8_t pa_gain; /*!> (sx125x) 2 bits: control of the external PA (SX1302 I/O)
  239. (sx1250) 1 bits: enable/disable the external PA (SX1302 I/O) */
  240. uint8_t dac_gain; /*!> (sx125x) 2 bits: control of the radio DAC */
  241. uint8_t mix_gain; /*!> (sx125x) 4 bits: control of the radio mixer */
  242. int8_t offset_i; /*!> (sx125x) calibrated I offset */
  243. int8_t offset_q; /*!> (sx125x) calibrated Q offset */
  244. uint8_t pwr_idx; /*!> (sx1250) 6 bits: control the radio power index to be used for configuration */
  245. };
  246. /**
  247. @struct lgw_tx_gain_lut_s
  248. @brief Structure defining the Tx gain LUT
  249. */
  250. struct lgw_tx_gain_lut_s {
  251. struct lgw_tx_gain_s lut[TX_GAIN_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
  252. uint8_t size; /*!> Number of LUT indexes */
  253. };
  254. /**
  255. @struct lgw_conf_debug_s
  256. @brief Configuration structure for debug
  257. */
  258. struct conf_ref_payload_s {
  259. uint32_t id;
  260. uint8_t payload[255];
  261. uint32_t prev_cnt;
  262. };
  263. struct lgw_conf_debug_s {
  264. uint8_t nb_ref_payload;
  265. struct conf_ref_payload_s ref_payload[16];
  266. char log_file_name[128];
  267. };
  268. /**
  269. @enum lgw_ftime_mode_t
  270. @brief Fine timestamping modes
  271. */
  272. typedef enum {
  273. LGW_FTIME_MODE_HIGH_CAPACITY, /*!> fine timestamps for SF5 -> SF10 */
  274. LGW_FTIME_MODE_ALL_SF /*!> fine timestamps for SF5 -> SF12 */
  275. } lgw_ftime_mode_t;
  276. /**
  277. @struct lgw_conf_ftime_s
  278. @brief Configuration structure for fine timestamping
  279. */
  280. struct lgw_conf_ftime_s {
  281. bool enable; /*!> Enable / Disable fine timestamping */
  282. lgw_ftime_mode_t mode; /*!> Fine timestamping mode */
  283. };
  284. /**
  285. @enum lgw_lbt_scan_time_t
  286. @brief Radio types that can be found on the LoRa Gateway
  287. */
  288. typedef enum {
  289. LGW_LBT_SCAN_TIME_128_US = 128,
  290. LGW_LBT_SCAN_TIME_5000_US = 5000,
  291. } lgw_lbt_scan_time_t;
  292. /**
  293. @brief Structure containing a Listen-Before-Talk channel configuration
  294. */
  295. struct lgw_conf_chan_lbt_s{
  296. uint32_t freq_hz; /*!> LBT channel frequency */
  297. uint8_t bandwidth; /*!> LBT channel bandwidth */
  298. lgw_lbt_scan_time_t scan_time_us; /*!> LBT channel carrier sense time */
  299. uint16_t transmit_time_ms; /*!> LBT channel transmission duration when allowed */
  300. };
  301. /**
  302. @struct lgw_conf_lbt_s
  303. @brief Configuration structure for listen-before-talk
  304. */
  305. struct lgw_conf_lbt_s {
  306. bool enable; /*!> enable or disable LBT */
  307. int8_t rssi_target; /*!> RSSI threshold to detect if channel is busy or not (dBm) */
  308. uint8_t nb_channel; /*!> number of LBT channels */
  309. struct lgw_conf_chan_lbt_s channels[LGW_LBT_CHANNEL_NB_MAX]; /*!> LBT channels configuration */
  310. };
  311. /**
  312. @struct lgw_conf_sx1261_s
  313. @brief Configuration structure for additional SX1261 radio used for LBT and Spectral Scan
  314. */
  315. struct lgw_conf_sx1261_s {
  316. bool enable; /*!> enable or disable SX1261 radio */
  317. char spi_path[64]; /*!> Path to access the SPI device to connect to the SX1261 (not used for USB com type) */
  318. int8_t rssi_offset; /*!> value to be applied to the sx1261 RSSI value (dBm) */
  319. struct lgw_conf_lbt_s lbt_conf; /*!> listen-before-talk configuration */
  320. };
  321. /**
  322. @struct lgw_context_s
  323. @brief Configuration context shared across modules
  324. */
  325. typedef struct lgw_context_s {
  326. /* Global context */
  327. bool is_started;
  328. struct lgw_conf_board_s board_cfg;
  329. /* RX context */
  330. struct lgw_conf_rxrf_s rf_chain_cfg[LGW_RF_CHAIN_NB];
  331. struct lgw_conf_rxif_s if_chain_cfg[LGW_IF_CHAIN_NB];
  332. struct lgw_conf_demod_s demod_cfg;
  333. struct lgw_conf_rxif_s lora_service_cfg; /* LoRa service channel config parameters */
  334. struct lgw_conf_rxif_s fsk_cfg; /* FSK channel config parameters */
  335. /* TX context */
  336. struct lgw_tx_gain_lut_s tx_gain_lut[LGW_RF_CHAIN_NB];
  337. /* Misc */
  338. struct lgw_conf_ftime_s ftime_cfg;
  339. struct lgw_conf_sx1261_s sx1261_cfg;
  340. /* Debug */
  341. struct lgw_conf_debug_s debug_cfg;
  342. } lgw_context_t;
  343. /**
  344. @struct lgw_spectral_scan_status_t
  345. @brief Spectral Scan status
  346. */
  347. typedef enum lgw_spectral_scan_status_e {
  348. LGW_SPECTRAL_SCAN_STATUS_NONE,
  349. LGW_SPECTRAL_SCAN_STATUS_ON_GOING,
  350. LGW_SPECTRAL_SCAN_STATUS_ABORTED,
  351. LGW_SPECTRAL_SCAN_STATUS_COMPLETED,
  352. LGW_SPECTRAL_SCAN_STATUS_UNKNOWN
  353. } lgw_spectral_scan_status_t;
  354. /* -------------------------------------------------------------------------- */
  355. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  356. /**
  357. @brief Configure the gateway board
  358. @param conf structure containing the configuration parameters
  359. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  360. */
  361. int lgw_board_setconf(struct lgw_conf_board_s * conf);
  362. /**
  363. @brief Configure an RF chain (must configure before start)
  364. @param rf_chain number of the RF chain to configure [0, LGW_RF_CHAIN_NB - 1]
  365. @param conf structure containing the configuration parameters
  366. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  367. */
  368. int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s * conf);
  369. /**
  370. @brief Configure an IF chain + modem (must configure before start)
  371. @param if_chain number of the IF chain + modem to configure [0, LGW_IF_CHAIN_NB - 1]
  372. @param conf structure containing the configuration parameters
  373. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  374. */
  375. int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s * conf);
  376. /**
  377. @brief Configure LoRa/FSK demodulators
  378. @param conf structure containing the configuration parameters
  379. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  380. */
  381. int lgw_demod_setconf(struct lgw_conf_demod_s * conf);
  382. /**
  383. @brief Configure the Tx gain LUT
  384. @param conf pointer to structure defining the LUT
  385. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  386. */
  387. int lgw_txgain_setconf(uint8_t rf_chain, struct lgw_tx_gain_lut_s * conf);
  388. /**
  389. @brief Configure the fine timestamping
  390. @param conf pointer to structure defining the config to be applied
  391. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  392. */
  393. int lgw_ftime_setconf(struct lgw_conf_ftime_s * conf);
  394. /*
  395. @brief Configure the SX1261 radio for LBT/Spectral Scan
  396. @param pointer to structure defining the config to be applied
  397. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  398. */
  399. int lgw_sx1261_setconf(struct lgw_conf_sx1261_s * conf);
  400. /**
  401. @brief Configure the debug context
  402. @param conf pointer to structure defining the config to be applied
  403. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  404. */
  405. int lgw_debug_setconf(struct lgw_conf_debug_s * conf);
  406. /**
  407. @brief Connect to the LoRa concentrator, reset it and configure it according to previously set parameters
  408. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  409. */
  410. int lgw_start(void);
  411. /**
  412. @brief Stop the LoRa concentrator and disconnect it
  413. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  414. */
  415. int lgw_stop(void);
  416. /**
  417. @brief A non-blocking function that will fetch up to 'max_pkt' packets from the LoRa concentrator FIFO and data buffer
  418. @param max_pkt maximum number of packet that must be retrieved (equal to the size of the array of struct)
  419. @param pkt_data pointer to an array of struct that will receive the packet metadata and payload pointers
  420. @return LGW_HAL_ERROR id the operation failed, else the number of packets retrieved
  421. */
  422. int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s * pkt_data);
  423. /**
  424. @brief Schedule a packet to be send immediately or after a delay depending on tx_mode
  425. @param pkt_data structure containing the data and metadata for the packet to send
  426. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  427. /!\ When sending a packet, there is a delay (approx 1.5ms) for the analog
  428. circuitry to start and be stable. This delay is adjusted by the HAL depending
  429. on the board version (lgw_i_tx_start_delay_us).
  430. In 'timestamp' mode, this is transparent: the modem is started
  431. lgw_i_tx_start_delay_us microseconds before the user-set timestamp value is
  432. reached, the preamble of the packet start right when the internal timestamp
  433. counter reach target value.
  434. In 'immediate' mode, the packet is emitted as soon as possible: transferring the
  435. packet (and its parameters) from the host to the concentrator takes some time,
  436. then there is the lgw_i_tx_start_delay_us, then the packet is emitted.
  437. In 'triggered' mode (aka PPS/GPS mode), the packet, typically a beacon, is
  438. emitted lgw_i_tx_start_delay_us microsenconds after a rising edge of the
  439. trigger signal. Because there is no way to anticipate the triggering event and
  440. start the analog circuitry beforehand, that delay must be taken into account in
  441. the protocol.
  442. */
  443. int lgw_send(struct lgw_pkt_tx_s * pkt_data);
  444. /**
  445. @brief Give the the status of different part of the LoRa concentrator
  446. @param select is used to select what status we want to know
  447. @param code is used to return the status code
  448. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  449. */
  450. int lgw_status(uint8_t rf_chain, uint8_t select, uint8_t * code);
  451. /**
  452. @brief Abort a currently scheduled or ongoing TX
  453. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  454. */
  455. int lgw_abort_tx(uint8_t rf_chain);
  456. /**
  457. @brief Return value of internal counter when latest event (eg GPS pulse) was captured
  458. @param trig_cnt_us pointer to receive timestamp value
  459. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  460. */
  461. int lgw_get_trigcnt(uint32_t * trig_cnt_us);
  462. /**
  463. @brief Return instateneous value of internal counter
  464. @param inst_cnt_us pointer to receive timestamp value
  465. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  466. */
  467. int lgw_get_instcnt(uint32_t * inst_cnt_us);
  468. /**
  469. @brief Return the LoRa concentrator EUI
  470. @param eui pointer to receive eui
  471. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  472. */
  473. int lgw_get_eui(uint64_t * eui);
  474. /**
  475. @brief Return the temperature measured by the LoRa concentrator sensor
  476. @param temperature The temperature measured, in degree celcius
  477. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  478. */
  479. int lgw_get_temperature(float * temperature);
  480. /**
  481. @brief Allow user to check the version/options of the library once compiled
  482. @return pointer on a human-readable null terminated string
  483. */
  484. const char* lgw_version_info(void);
  485. /**
  486. @brief Return time on air of given packet, in milliseconds
  487. @param packet is a pointer to the packet structure
  488. @return the packet time on air in milliseconds
  489. */
  490. uint32_t lgw_time_on_air(const struct lgw_pkt_tx_s * packet);
  491. /**
  492. @brief Start scaning the channel centered on the given frequency
  493. @param freq_hz channel center frequency
  494. @param nb_scan number of measures to be done for the scan
  495. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  496. */
  497. int lgw_spectral_scan_start(uint32_t freq_hz, uint16_t nb_scan);
  498. /**
  499. @brief Get the current scan status
  500. @param status a pointer to the returned status
  501. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  502. */
  503. int lgw_spectral_scan_get_status(lgw_spectral_scan_status_t * status);
  504. /**
  505. @brief Get the channel scan results
  506. @param levels an array containing the power levels for which the scan results are given
  507. @param values ar array containing the results of the scan for each power levels
  508. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  509. */
  510. 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]);
  511. /**
  512. @brief Abort the current scan
  513. @return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
  514. */
  515. int lgw_spectral_scan_abort();
  516. #endif
  517. /* --- EOF ------------------------------------------------------------------ */