├── CHANGELOG.md ├── LICENSE.txt ├── README.md └── src ├── lr1110_bootloader.c ├── lr1110_bootloader.h ├── lr1110_bootloader_types.h ├── lr1110_crypto_engine.c ├── lr1110_crypto_engine.h ├── lr1110_crypto_engine_types.h ├── lr1110_driver_version.c ├── lr1110_driver_version.h ├── lr1110_gnss.c ├── lr1110_gnss.h ├── lr1110_gnss_types.h ├── lr1110_hal.h ├── lr1110_lr_fhss.c ├── lr1110_lr_fhss.h ├── lr1110_lr_fhss_types.h ├── lr1110_radio.c ├── lr1110_radio.h ├── lr1110_radio_timings.c ├── lr1110_radio_timings.h ├── lr1110_radio_types.h ├── lr1110_regmem.c ├── lr1110_regmem.h ├── lr1110_system.c ├── lr1110_system.h ├── lr1110_system_types.h ├── lr1110_types.h ├── lr1110_wifi.c ├── lr1110_wifi.h ├── lr1110_wifi_types.h └── lr_fhss_v1_base_types.h /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # LR1110 driver changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [v7.0.0] 2021-12-06 8 | 9 | ### Added 10 | 11 | * [radio] Support of LR-FHSS (see lr1110_lr_fhss.c and lr1110_lr_fhss.h) 12 | * [system] `lr1110_system_calibrate_image_in_mhz()` function 13 | 14 | ### Removed 15 | 16 | * [GNSS] `lr1110_gnss_set_xtal_error()` and `lr1110_gnss_set_xtal_error()` functions 17 | 18 | ## [v6.0.0] 2021-09-24 19 | 20 | ### Added 21 | 22 | * [GNSS] `LR1110_GNSS_SCAN_MODE_3_SINGLE_SCAN_AND_5_FAST_SCANS` entry `lr1110_gnss_scan_mode_t` 23 | 24 | ### Changed 25 | 26 | * [GNSS] `lr1110_gnss_set_scan_mode()` function does not take out parameter anymore and is now based on lr1110_hal_write() 27 | * [GNSS] `lr1110_gnss_get_detected_satellites()` function returns also the doppler per satellite 28 | 29 | ### Removed 30 | 31 | * [GNSS] `lr1110_gnss_scan_continuous()` function and `LR1110_GNSS_DOUBLE_SCAN_MODE` entry in lr1110_gnss_scan_mode_t 32 | 33 | ## [v5.0.1] 2021-07-19 34 | 35 | ### Added 36 | 37 | * [bootloader] `lr1110_bootloader_clear_reset_status_info()` function 38 | * [crypto] Functions now return a status 39 | * [GNSS] `lr1110_gnss_get_result_destination()` function 40 | * [GNSS] `lr1110_gnss_almanac_update()` function - replaces `lr1110_gnss_almanac_full_update()` and `lr1110_gnss_one_satellite_almanac_update()` functions 41 | * [GNSS] `lr1110_gnss_compute_almanac_age` function 42 | * [HAL] `lr1110_hal_direct_read()` function - replaces `lr1110_hal_write_read()` function and no longer requires bidirectional SPI 43 | * [HAL] `LR1110_NOP` constant 44 | * [system] `lr1110_system_clear_reset_status_info()` function 45 | * [system] `lr1110_system_drive_dio_in_sleep_mode()` function 46 | * [Wi-Fi] `LR1110_WIFI_SCAN_MODE_UNTIL_SSID` entry in `lr1110_wifi_mode_t` 47 | * [Wi-Fi] `lr1110_wifi_is_well_formed_utf8_byte_sequence()` function 48 | 49 | ### Changed 50 | 51 | * [LICENSE] Revised BSD License changed to the Clear BSD License 52 | * [GNSS] `LR1110_GNSS_ERROR_UPDATE_TIME_DIFFERENCE_OVER_1_MONTH` is renamed `LR1110_GNSS_ERROR_ALMANAC_UPDATE_NOT_ALLOWED` in `lr1110_gnss_error_code_t` 53 | * [GNSS] `lr1110_gnss_parse_context_status_buffer()` returns a `lr1110_status_t` value 54 | * [system] `lr1110_system_get_status()` function implementation uses `lr1110_hal_direct_read()` function and no longer requires bidirectional SPI 55 | * [system] `lr1110_bootloader_get_status()` function implementation uses `lr1110_hal_direct_read()` function and no longer requires bidirectional SPI 56 | * [system] `lr1110_system_get_irq_status()` function - has a faster implementation based on the `lr1110_system_get_status()` function 57 | 58 | ### Fixed 59 | 60 | * [GNSS] Global almanac CRC endianness `lr1110_gnss_parse_context_status_buffer()` 61 | * [GNSS] `lr1110_gnss_parse_context_status_buffer()` takes into account the message header 62 | * [GNSS] Typo in `LR1110_GNSS_ALMANAC_REAC_RBUFFER_LENGTH` - now `LR1110_GNSS_ALMANAC_READ_RBUFFER_LENGTH` 63 | 64 | ### Removed 65 | 66 | * [GNSS] `lr1110_gnss_get_almanac_crc()` - Almanac CRC can be read thanks to `lr1110_gnss_get_context_status()` 67 | * [GNSS] `lr1110_gnss_almanac_full_update()` and `lr1110_gnss_one_satellite_almanac_update()` functions - merged in `lr1110_gnss_almanac_update()` function 68 | * [HAL] `lr1110_hal_write_read()` function - replaced by `lr1110_hal_direct_read()` function 69 | * [regmem] `lr1110_regmem_write_auxreg32()`and `lr1110_regmem_read_auxreg32()` functions 70 | * [Wi-Fi] `lr1110_wifi_cfg_hardware_debarker()` function 71 | 72 | ## [v4.0.0] 2021-04-06 73 | 74 | ### Added 75 | 76 | * [bootloader] `lr1110_bootloader_get_status` function 77 | * [bootloader] `lr1110_bootloader_irq_mask_t` type definition 78 | * [bootloader] `lr1110_bootloader_chip_modes_t` type definition 79 | * [bootloader] `lr1110_bootloader_reset_status_t` type definition 80 | * [bootloader] `lr1110_bootloader_command_status_t` type definition 81 | * [bootloader] `lr1110_bootloader_stat1_t` type definition 82 | * [bootloader] `lr1110_bootloader_stat2_t` type definition 83 | * [timings] Add the functions to compute the radio timings 84 | * [system] Add function `lr1110_system_enable_spi_crc` to enable or disable the CRC on SPI communication 85 | * [HAL] Add the CRC calculation for SPI 86 | 87 | ### Fixed 88 | 89 | * [GNSS] Fix typo: `lr1110_gnss_almanac_single_satellite_update_bytestram_t` to `lr1110_gnss_almanac_single_satellite_update_bytestream_t` 90 | * [GNSS] Fix size of context status 91 | 92 | ### Changed 93 | 94 | * [Wi-Fi] Added field `current_channel` to `lr1110_wifi_extended_full_result_t` 95 | 96 | ### Removed 97 | 98 | * [bootloader] `lr1110_bootloader_get_hash` function 99 | * [bootloader] `lr1110_bootloader_write_flash` function 100 | * [bootloader] `lr1110_bootloader_write_flash_full` function 101 | * [bootloader] `lr1110_bootloader_erase_page` function 102 | 103 | ## [v3.0.0] 2020-10-12 104 | 105 | ### Added 106 | 107 | * [bootloader] `lr1110_bootloader_read_chip_eui` function 108 | * [bootloader] `lr1110_bootloader_read_join_eui` function 109 | * [bootloader] `LR1110_BL_CHIP_EUI_LENGTH` constant 110 | * [bootloader] `LR1110_BL_JOIN_EUI_LENGTH` constant 111 | * [bootloader] `lr1110_bootloader_chip_eui_t` type definition 112 | * [bootloader] `lr1110_bootloader_join_eui_t` type definition 113 | * [GNSS] `lr1110_gnss_get_context_status` function 114 | * [GNSS] `lr1110_gnss_parse_context_status_buffer` function 115 | * [GNSS] `LR1110_GNSS_CONTEXT_STATUS_LENGTH` constant 116 | * [GNSS] `lr1110_gnss_error_code_t` type definition 117 | * [GNSS] `lr1110_gnss_freq_search_space_t` type definition 118 | * [GNSS] `lr1110_gnss_context_status_bytestream_t` type definition 119 | * [GNSS] `lr1110_gnss_context_status_t` type definition 120 | * [radio] `lr1110_radio_set_rx_with_timeout_in_rtc_step` and `lr1110_radio_set_tx_with_timeout_in_rtc_step` functions 121 | * [radio] `lr1110_radio_set_rx_duty_cycle_with_timings_in_rtc_step` function 122 | * [radio] `lr1110_radio_convert_time_in_ms_to_rtc_step` function 123 | * [system] `lr1110_system_wakeup` function 124 | * [system] `lr1110_system_read_pin_custom_eui` function 125 | * [system] `reset_status` field to `lr1110_system_stat2_t` 126 | * [Wi-Fi] `lr1110_wifi_scan_time_limit` function 127 | * [Wi-Fi] `lr1110_wifi_search_country_code_time_limit` function 128 | * [Wi-Fi] `lr1110_wifi_read_extended_full_results` function 129 | * [Wi-Fi] `LR1110_WIFI_CHANNEL_*_POS` and `LR1110_WIFI_CHANNEL_*_MASK` constants 130 | * [Wi-Fi] `LR1110_WIFI_SCAN_MODE_FULL_BEACON` entry in `lr1110_wifi_mode_t` 131 | * [Wi-Fi] `lr1110_wifi_extended_full_result_t` type definition 132 | * [Wi-Fi] `LR1110_WIFI_RESULT_FORMAT_EXTENDED_FULL` entry in `lr1110_wifi_result_format_t` 133 | 134 | ### Changed 135 | 136 | * [crypto] `LR1110_CRYPTO_COMPUTE_AES_CMAC_CMD_LENGTH` is now equal to ( 2 + 1 + 272 ) 137 | * [GNSS] `LR1110_GNSS_FULL_ALMANAC_UPDATE_PACKET_LENGTH` is renamed `LR1110_GNSS_FULL_ALMANAC_UPDATE_PKT_LENGTH` 138 | * [GNSS] `lr1110_gnss_scan_autonomous` takes also `effort_mode` as input parameter 139 | * [radio] Implementation of time-on-air computation for LoRa modulation 140 | * [radio] `lr1110_radio_set_lora_sync_word` takes a sync word as parameter instead of a network type 141 | * [radio] `lr1110_radio_set_rx` and `lr1110_radio_set_tx` take a timeout parameter in millisecond instead of RTC step 142 | * [radio] `lr1110_radio_set_rx_duty_cycle` takes a timeout parameter in millisecond instead of RTC step 143 | * [radio] `LR1110_RADIO_PACKET_NONE` is renamed `LR1110_RADIO_PKT_NONE` 144 | * [radio] `LR1110_RADIO_PA_REG_SUPPLY_DCDC` is renamed `LR1110_RADIO_PA_REG_SUPPLY_VREG` 145 | * [radio] `lr1110_radio_pa_regulator_supply_t` is renamed `lr1110_radio_pa_reg_supply_t` 146 | * [radio] `*_packet_*` is renamed `*_pkt_*` in `lr1110_radio_pkt_status_lora_t` 147 | * [radio] `nb_packet_falsesync` is renamed `nb_pkt_falsesync` in `lr1110_radio_stats_lora_t` 148 | * [Wi-Fi] `lr1110_extract_channel_info` is renamed `lr1110_wifi_parse_channel_info` 149 | * [Wi-Fi] `lr1110_extract_channel_from_info_byte` is renamed `lr1110_wifi_extract_channel_from_info_byte` 150 | * [Wi-Fi] `lr1110_extract_frame_type_info` is renamed `lr1110_wifi_parse_frame_type_info` 151 | * [Wi-Fi] `lr1110_extract_data_rate_info` is renamed `lr1110_wifi_parse_data_rate_info` 152 | * [Wi-Fi] `lr1110_wifi_n_results_max_per_chunk` is renamed `lr1110_wifi_get_nb_results_max_per_chunk` 153 | * [Wi-Fi] `lr1110_extract_signal_type_from_data_rate_info` is renamed `lr1110_wifi_extract_signal_type_from_data_rate_info` 154 | * [Wi-Fi] `LR1110_WIFI_ORIGIN_PACKET` is renamed `LR1110_WIFI_ORIGIN_UNKNWON` 155 | * [Wi-Fi] `LR1110_WIFI_SCAN_MODE_BEACON_AND_PACKET` is renamed `LR1110_WIFI_SCAN_MODE_BEACON_AND_PKT` 156 | 157 | ### Fixed 158 | 159 | * [all] Harmonized doxygen markups 160 | * [all] Harmonized license header 161 | * [all] Removed extraneous underscore in constants used for multiple inclusion protection 162 | * [GNSS] Inversion of `LR1110_GNSS_BIT_CHANGE_MASK` and `LR1110_GNSS_IRQ_PSEUDO_RANGE_MASK` definitions 163 | * [radio] Power amplifier ramp time values in lr1110_radio_ramp_time_t 164 | * [system] `chip_mode` read from `stat2` value 165 | 166 | ## [v2.0.1] 2020-05-04 167 | 168 | ### Fixed 169 | 170 | * [version] Enable c linkage driver version related functions 171 | 172 | ## [v2.0.0] 2020-04-27 173 | 174 | ### Added 175 | 176 | * [all] All functions declared in .h files now return a status. 177 | * [common] `lr1110_status_t` type definition 178 | * [bootloader] `lr1110_bootloader_fill_cbuffer_opcode_offset_flash` static function 179 | * [bootloader] `lr1110_bootloader_fill_cdata_flash` static function 180 | * [bootloader] `lr1110_bootloader_fill_cbuffer_cdata_flash` static function 181 | * [regmem] `lr1110_regmem_fill_cbuffer_opcode_address` static function 182 | * [regmem] `lr1110_regmem_fill_cbuffer_opcode_address_length` static function 183 | * [regmem] `lr1110_regmem_fill_cdata` static function 184 | * [regmem] `lr1110_regmem_fill_cbuffer_cdata_opcode_address_data` static function 185 | * [regmem] `lr1110_regmem_fill_out_buffer_from_raw_buffer` static function 186 | * [system] `LR1110_SYSTEM_VERSION_LENGTH` constant 187 | * [system] `lr1110_system_cal_mask_t` type definition 188 | * [system] `lr1110_system_irq_mask_t` type definition 189 | * [system] `lr1110_system_get_and_clear_irq_status` function 190 | * [system] `lr1110_system_get_irq_status` function 191 | * [crypto] `lr1110_crypto_fill_cbuffer_opcode_key_data` static function 192 | * [GNSS] `lr1110_gnss_uint8_to_uint32` static function 193 | 194 | ### Changed 195 | 196 | * [bootloader] `lr1110_bootloader_version_t` has now 3 fields: hardware, type, firmware 197 | * [bootloader] `lr1110_bootloader_get_version` fills the updated `lr1110_bootloader_version_t` structure 198 | * [system] `LR1110_SYSTEM_IRQ_NONE_MASK` is renamed `LR1110_SYSTEM_IRQ_NONE` 199 | * [system] `LR1110_SYSTEM_IRQ_TXDONE_MASK` is renamed `LR1110_SYSTEM_IRQ_TX_DONE` 200 | * [system] `LR1110_SYSTEM_IRQ_RXDONE_MASK` is renamed `LR1110_SYSTEM_IRQ_RX_DONE` 201 | * [system] `LR1110_SYSTEM_IRQ_PREAMBLEDETECTED_MASK` is renamed `LR1110_SYSTEM_IRQ_PREAMBLE_DETECTED` 202 | * [system] `LR1110_SYSTEM_IRQ_SYNCWORD_HEADERVALID_MASK` is renamed `LR1110_SYSTEM_IRQ_SYNC_WORD_HEADER_VALID` 203 | * [system] `LR1110_SYSTEM_IRQ_HEADERERR_MASK` is renamed `LR1110_SYSTEM_IRQ_HEADER_ERROR` 204 | * [system] `LR1110_SYSTEM_IRQ_CRCERR_MASK` is renamed `LR1110_SYSTEM_IRQ_CRC_ERROR` 205 | * [system] `LR1110_SYSTEM_IRQ_CADDONE_MASK` is renamed `LR1110_SYSTEM_IRQ_CAD_DONE` 206 | * [system] `LR1110_SYSTEM_IRQ_CADDETECTED_MASK` is renamed `LR1110_SYSTEM_IRQ_CAD_DETECTED` 207 | * [system] `LR1110_SYSTEM_IRQ_TIMEOUT_MASK` is renamed `LR1110_SYSTEM_IRQ_TIMEOUT` 208 | * [system] `LR1110_SYSTEM_IRQ_GNSSSCANDONE_MASK` is renamed `LR1110_SYSTEM_IRQ_GNSS_SCAN_DONE` 209 | * [system] `LR1110_SYSTEM_IRQ_WIFISCANDONE_MASK` is renamed `LR1110_SYSTEM_IRQ_WIFI_SCAN_DONE` 210 | * [system] `LR1110_SYSTEM_IRQ_EOL_MASK` is renamed `LR1110_SYSTEM_IRQ_EOL` 211 | * [system] `LR1110_SYSTEM_IRQ_CMDERR_MASK` is renamed `LR1110_SYSTEM_IRQ_CMD_ERROR` 212 | * [system] `LR1110_SYSTEM_IRQ_ERR_MASK` is renamed `LR1110_SYSTEM_IRQ_ERROR` 213 | * [system] `LR1110_SYSTEM_IRQ_FSK_LENGTH_ERROR_MASK` is renamed `LR1110_SYSTEM_IRQ_FSK_LEN_ERROR` 214 | * [system] `LR1110_SYSTEM_IRQ_FSK_ADDRESS_ERROR_MASK` is renamed `LR1110_SYSTEM_IRQ_FSK_ADDR_ERROR` 215 | * [system] `LR1110_SYSTEM_CALIBRATE_*_MASK` are renamed `LR1110_SYSTEM_CALIB_*_MASK` 216 | * [system] `lr1110_system_chip_mode_t` is renamed `lr1110_system_chip_modes_t` 217 | * [system] In `lr1110_system_chip_modes_t`, `LR1110_SYSTEM_CHIP_MODE_RC` is renamed `LR1110_SYSTEM_CHIP_MODE_STBY_RC` 218 | * [system] In `lr1110_system_chip_modes_t`, `LR1110_SYSTEM_CHIP_MODE_XOSC` is renamed `LR1110_SYSTEM_CHIP_MODE_STBY_XOSC` 219 | * [system] `lr1110_system_lfclk_config_t` is renamed `lr1110_system_lfclk_cfg_t` 220 | * [system] `lr1110_regmodes_t` is renamed `lr1110_system_reg_mode_t` 221 | * [system] `LR1110_SYSTEM_REGMODE_NO_DCDC` is renamed `LR1110_SYSTEM_REG_MODE_LDO` 222 | * [system] `LR1110_SYSTEM_REGMODE_DCDC_CONVERTER` is renamed `LR1110_SYSTEM_REG_MODE_DCDC` 223 | * [system] `lr1110_system_rfswitch_config_t` is renamed `lr1110_system_rfswitch_cfg_t` 224 | * [system] `lr1110_system_standby_config_t` is renamed `lr1110_system_standby_cfg_t` 225 | * [system] `LR1110_SYSTEM_STDBY_CONFIG_*` are renamed `LR1110_SYSTEM_STANDBY_CFG_*` 226 | * [system] `LR1110_SYSTEM_TCXO_SUPPLY_VOLTAGE_*V` are renamed `LR1110_SYSTEM_TCXO_CTRL_*V` 227 | * [system] `lr1110_system_sleep_config_t` is renamed `lr1110_system_sleep_cfg_t` 228 | * [system] `lr1110_system_set_regmode` is renamed `lr1110_system_set_reg_mode` 229 | * [system] `lr1110_system_config_lfclk` is renamed `lr1110_system_cfg_lfclk` 230 | * [system] `lr1110_system_clear_irq` is renamed `lr1110_system_clear_irq_status` 231 | * [crypto] `lr1110_crypto_derive_and_store_key` is renamed `lr1110_crypto_derive_key` 232 | * [crypto] `LR1110_CRYPTO_DERIVE_AND_STORE_KEY_OC` is renamed `LR1110_CRYPTO_DERIVE_KEY_OC` 233 | * [crypto] `LR1110_CRYPTO_DERIVE_AND_STORE_KEY_CMD_LENGTH` is renamed `LR1110_CRYPTO_DERIVE_KEY_CMD_LENGTH` 234 | * [radio] `lr1110_radio_rx_tx_fallback_mode_t` is renamed `lr1110_radio_fallback_modes_t` 235 | * [radio] `LR1110_RADIO_RX_TX_FALLBACK_MODE_*` are renamed `LR1110_RADIO_FALLBACK_*` 236 | * [radio] `LR1110_RADIO_RAMP_TIME_*` are renamed `LR1110_RADIO_RAMP_*` 237 | * [radio] `LR1110_RADIO_LORA_BW*` are renamed `LR1110_RADIO_LORA_BW_*` 238 | * [radio] `LR1110_RADIO_LORA_CRXY_LI` are renamed `LR1110_RADIO_LORA_CR_LI_X_Y` 239 | * [radio] `LR1110_RADIO_LORA_CRXY` are renamed `LR1110_RADIO_LORA_CR_X_Y` 240 | * [radio] `LR1110_RADIO_MODE_STANDBY*` are renamed `LR1110_RADIO_MODE_STANDBY_*` 241 | * [radio] `LR1110_RADIO_GFSK_CRC_XBYTE` are renamed `LR1110_RADIO_GFSK_CRC_X_BYTE` 242 | * [radio] `LR1110_RADIO_GFSK_CRC_XBYTES` are renamed `LR1110_RADIO_GFSK_CRC_X_BYTES` 243 | * [radio] `LR1110_RADIO_GFSK_CRC_XBYTE_INV` are renamed `LR1110_RADIO_GFSK_CRC_X_BYTE_INV` 244 | * [radio] `LR1110_RADIO_GFSK_CRC_XBYTES_INV` are renamed `LR1110_RADIO_GFSK_CRC_X_BYTES_INV` 245 | * [radio] `LR1110_RADIO_GFSK_DCFREE_*` are renamed `LR1110_RADIO_GFSK_DC_FREE_*` 246 | * [radio] `lr1110_radio_gfsk_header_type_t` is renamed `lr1110_radio_gfsk_pkt_len_modes_t` 247 | * [radio] `LR1110_RADIO_GFSK_HEADER_TYPE_IMPLICIT` is renamed `LR1110_RADIO_GFSK_PKT_FIX_LEN` 248 | * [radio] `LR1110_RADIO_GFSK_HEADER_TYPE_EXPLICIT` is renamed `LR1110_RADIO_GFSK_PKT_VAR_LEN` 249 | * [radio] `lr1110_radio_gfsk_preamble_detect_length_t` is renamed `lr1110_radio_gfsk_preamble_detector_t` 250 | * [radio] `LR1110_RADIO_GFSK_PREAMBLE_DETECTOR_LENGTH_*` are renamed `LR1110_RADIO_GFSK_PREAMBLE_DETECTOR_*` 251 | * [radio] `lr1110_radio_lora_header_type_t` is renamed `lr1110_radio_lora_pkt_len_modes_t` 252 | * [radio] `LR1110_RADIO_LORA_HEADER_*` are renamed `LR1110_RADIO_LORA_PKT_*` 253 | * [radio] `lr1110_radio_packet_types_t` is renamed `lr1110_radio_pkt_type_t` 254 | * [radio] `LR1110_RADIO_PACKET_*` are renamed `LR1110_RADIO_PKT_TYPE_*` 255 | * [radio] `lr1110_radio_gfsk_rx_bw_t` is renamed `lr1110_radio_gfsk_bw_t` 256 | * [radio] `LR1110_RADIO_GFSK_RX_BW_*` are renamed `LR1110_RADIO_GFSK_BW_*` 257 | * [radio] `lr1110_radio_pulse_shape_t` is renamed `lr1110_radio_gfsk_pulse_shape_t` 258 | * [radio] `LR1110_RADIO_PULSESHAPE_*` are renamed `LR1110_RADIO_GFSK_PULSE_SHAPE_*` 259 | * [radio] In `lr1110_radio_cad_params_t`, `symbol_num` is renamed `cad_symb_nb` 260 | * [radio] In `lr1110_radio_cad_params_t`, `det_peak` is renamed `cad_detect_peak` 261 | * [radio] In `lr1110_radio_cad_params_t`, `det_min` is renamed `cad_detect_min` 262 | * [radio] In `lr1110_radio_cad_params_t`, `exit_mode` is renamed `cad_exit_mode` 263 | * [radio] In `lr1110_radio_cad_params_t`, `timeout` is renamed `cad_timeout` 264 | * [radio] `lr1110_radio_packet_status_gfsk_t` is renamed `lr1110_radio_pkt_status_gfsk_t` 265 | * [radio] In `lr1110_radio_pkt_status_gfsk_t`, `rx_length_in_bytes` is renamed `rx_len_in_bytes` 266 | * [radio] `lr1110_radio_packet_status_lora_t` is renamed `lr1110_radio_pkt_status_lora_t` 267 | * [radio] `lr1110_radio_rxbuffer_status_t` is renamed `lr1110_radio_rx_buffer_status_t` 268 | * [radio] In `lr1110_radio_rx_buffer_status_t`, `rx_payload_length` is renamed `pld_len_in_bytes` 269 | * [radio] In `lr1110_radio_rx_buffer_status_t`, `rx_start_buffer_pointer` is renamed `buffer_start_pointer` 270 | * [radio] In `lr1110_radio_stats_gfsk_t`, `nb_packet_*` are renamed `nb_pkt_*` 271 | * [radio] In `lr1110_radio_stats_lora_t`, `nb_packet_received` is renamed `nb_pkt_received` 272 | * [radio] In `lr1110_radio_stats_lora_t`, `nb_packet_error_crc` is renamed `nb_pkt_error_crc` 273 | * [radio] In `lr1110_radio_stats_lora_t`, `nb_packet_error_header` is renamed `nb_pkt_header_error` 274 | * [radio] `lr1110_radio_modulation_param_*_t` are renamed `lr1110_radio_mod_params_*_t` 275 | * [radio] In `lr1110_radio_mod_params_gfsk_t`, `bitrate` is renamed `br_in_bps` 276 | * [radio] In `lr1110_radio_mod_params_gfsk_t`, `bandwidth` is renamed `bw_dsb_param` 277 | * [radio] In `lr1110_radio_mod_params_gfsk_t`, `fdev` is renamed `fdev_in_hz` 278 | * [radio] In `lr1110_radio_mod_params_lora_t`, `spreading_factor` is renamed `sf` 279 | * [radio] In `lr1110_radio_mod_params_lora_t`, `coding_rate` is renamed `cr` 280 | * [radio] In `lr1110_radio_mod_params_lora_t`, `ppm_offset` is renamed `ldro` 281 | * [radio] `lr1110_radio_packet_param_*_t` are renamed `lr1110_radio_pkt_params_*_t` 282 | * [radio] In `lr1110_radio_pkt_params_gfsk_t`, `preamble_length_tx_in_bit` is renamed `preamble_len_in_bits` 283 | * [radio] In `lr1110_radio_pkt_params_gfsk_t`, `preamble_detect` is renamed `preamble_detector` 284 | * [radio] In `lr1110_radio_pkt_params_gfsk_t`, `sync_word_length_in_bit` is renamed `sync_word_len_in_bits` 285 | * [radio] In `lr1110_radio_pkt_params_gfsk_t`, `payload_length_in_byte` is renamed `pld_len_in_bytes` 286 | * [radio] In `lr1110_radio_pkt_params_lora_t`, `preamble_length_in_symb` is renamed `preamble_len_in_symb` 287 | * [radio] In `lr1110_radio_pkt_params_lora_t`, `payload_length_in_byte` is renamed `pld_len_in_bytes` 288 | * [radio] `lr1110_radio_pa_config_t` are renamed `lr1110_radio_pa_cfg_t` 289 | * [Wi-Fi] `lr1110_wifi_configure_hardware_debarker` is renamed `lr1110_wifi_cfg_hardware_debarker` 290 | 291 | ### Fixed 292 | 293 | * [system] Enable c linkage for system-related functions 294 | 295 | ### Removed 296 | 297 | * [system] `LR1110_SYSTEM_IRQ_FHSS_MASK` constant 298 | * [system] `LR1110_SYSTEM_IRQ_INTERPACKET1_MASK` constant 299 | * [system] `LR1110_SYSTEM_IRQ_INTERPACKET2_MASK` constant 300 | * [system] `LR1110_SYSTEM_IRQ_RNGREQVLD_MASK` constant 301 | * [system] `LR1110_SYSTEM_IRQ_RNGREQDISC_MASK` constant 302 | * [system] `LR1110_SYSTEM_IRQ_RNGRESPDONE_MASK` constant 303 | * [system] `LR1110_SYSTEM_IRQ_RNGEXCHVLD_MASK` constant 304 | * [system] `LR1110_SYSTEM_IRQ_RNGTIMEOUT_MASK` constant 305 | 306 | ## [v1.0.0] 2020-03-18 307 | 308 | ### Added 309 | 310 | * [all] Initial version 311 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The Clear BSD License 2 | Copyright Semtech Corporation 2021. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted (subject to the limitations in the disclaimer 6 | below) provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Semtech corporation nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 17 | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 18 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 19 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LR1110_driver project 2 | 3 | This project has moved to [LR11xx driver](https://github.com/Lora-net/SWDR001) project. 4 | 5 | The source code remains available but will not be maintained. 6 | 7 | This package proposes an implementation in C of the driver for **LR1110** radio component. 8 | 9 | ## Components 10 | 11 | The driver is split in several components: 12 | 13 | - Bootloader 14 | - Register / memory access 15 | - System configuration 16 | - Radio 17 | - Wi-Fi Passive Scanning 18 | - GNSS Scan Scanning 19 | - Crypto engine 20 | 21 | ### Bootloader 22 | 23 | This component is used to update the firmware. 24 | 25 | ### Register / memory access 26 | 27 | This component is used to read / write data from registers or internal memory. 28 | 29 | ### System configuration 30 | 31 | This component is used to interact with system-wide parameters like clock sources, integrated RF switches, etc. 32 | 33 | ### Radio 34 | 35 | This component is used to send / receive data through the different modems (LoRa and GFSK) or perform a LoRa CAD (Channel Activity Detection). Parameters like power amplifier selection, output power and fallback modes are also accessible through this component. 36 | 37 | ### Wi-Fi Passive Scanning 38 | 39 | This component is used to configure and initiate the passive scanning of the Wi-Fi signals that can be shared to request a geolocation. 40 | 41 | ### GNSS Scanning 42 | 43 | This component is used to configure and initiate the acquisition of GNSS signals that can be shared to request a geolocation. 44 | 45 | ### Crypto engine 46 | 47 | This component is used to set and derive keys in the internal keychain and perform cryptographic operations with the integrated hardware accelerator. 48 | 49 | ## Structure 50 | 51 | Each component is based on different files: 52 | 53 | - lr1110_component.c: implementation of the functions related to component 54 | - lr1110_component.h: declarations of the functions related to component 55 | - lr1110_component_types.h: type definitions related to components 56 | 57 | ## HAL 58 | 59 | The HAL (Hardware Abstraction Layer) is a collection of functions that the user shall implement to write platform-dependant calls to the host. The list of functions is the following: 60 | 61 | - lr1110_hal_reset() 62 | - lr1110_hal_wakeup() 63 | - lr1110_hal_write() 64 | - lr1110_hal_read() 65 | - lr1110_hal_direct_read() 66 | -------------------------------------------------------------------------------- /src/lr1110_bootloader.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_bootloader.c 3 | * 4 | * @brief Bootloader driver implementation for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * ----------------------------------------------------------------------------- 37 | * --- DEPENDENCIES ------------------------------------------------------------ 38 | */ 39 | 40 | #include "lr1110_bootloader.h" 41 | #include "lr1110_hal.h" 42 | 43 | /* 44 | * ----------------------------------------------------------------------------- 45 | * --- PRIVATE MACROS----------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | * ----------------------------------------------------------------------------- 50 | * --- PRIVATE CONSTANTS ------------------------------------------------------- 51 | */ 52 | 53 | #define LR1110_FLASH_DATA_MAX_LENGTH_UINT32 ( 64 ) 54 | #define LR1110_FLASH_DATA_MAX_LENGTH_UINT8 ( LR1110_FLASH_DATA_MAX_LENGTH_UINT32 * 4 ) 55 | 56 | #define LR1110_BL_CMD_NO_PARAM_LENGTH ( 2 ) 57 | #define LR1110_BL_GET_STATUS_CMD_LENGTH ( 2 + 4 ) 58 | #define LR1110_BL_VERSION_CMD_LENGTH LR1110_BL_CMD_NO_PARAM_LENGTH 59 | #define LR1110_BL_ERASE_FLASH_CMD_LENGTH LR1110_BL_CMD_NO_PARAM_LENGTH 60 | #define LR1110_BL_WRITE_FLASH_ENCRYPTED_CMD_LENGTH ( LR1110_BL_CMD_NO_PARAM_LENGTH + 4 ) 61 | #define LR1110_BL_REBOOT_CMD_LENGTH ( LR1110_BL_CMD_NO_PARAM_LENGTH + 1 ) 62 | #define LR1110_BL_GET_PIN_CMD_LENGTH ( LR1110_BL_CMD_NO_PARAM_LENGTH ) 63 | #define LR1110_BL_READ_CHIP_EUI_CMD_LENGTH ( LR1110_BL_CMD_NO_PARAM_LENGTH ) 64 | #define LR1110_BL_READ_JOIN_EUI_CMD_LENGTH ( LR1110_BL_CMD_NO_PARAM_LENGTH ) 65 | 66 | /* 67 | * ----------------------------------------------------------------------------- 68 | * --- PRIVATE TYPES ----------------------------------------------------------- 69 | */ 70 | 71 | /*! 72 | * @brief Operating codes for bootloader-related operations 73 | */ 74 | enum 75 | { 76 | LR1110_BL_GET_STATUS_OC = 0x0100, 77 | LR1110_BL_GET_VERSION_OC = 0x0101, 78 | LR1110_BL_ERASE_FLASH_OC = 0x8000, 79 | LR1110_BL_WRITE_FLASH_ENCRYPTED_OC = 0x8003, 80 | LR1110_BL_REBOOT_OC = 0x8005, 81 | LR1110_BL_GET_PIN_OC = 0x800B, 82 | LR1110_BL_READ_CHIP_EUI_OC = 0x800C, 83 | LR1110_BL_READ_JOIN_EUI_OC = 0x800D, 84 | }; 85 | 86 | /* 87 | * ----------------------------------------------------------------------------- 88 | * --- PRIVATE VARIABLES ------------------------------------------------------- 89 | */ 90 | 91 | /* 92 | * ----------------------------------------------------------------------------- 93 | * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- 94 | */ 95 | 96 | /*! 97 | * @brief Returns the minimum of the operand given as parameter and the maximum allowed block size 98 | * 99 | * @param [in] operand Size to compare 100 | * 101 | * @returns Minimum between operand and @ref LR1110_FLASH_DATA_MAX_LENGTH_UINT32 102 | */ 103 | static uint8_t lr1110_bootloader_get_min_from_operand_and_max_block_size( uint32_t operand ); 104 | 105 | /* 106 | * ----------------------------------------------------------------------------- 107 | * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- 108 | */ 109 | 110 | lr1110_status_t lr1110_bootloader_get_status( const void* context, lr1110_bootloader_stat1_t* stat1, 111 | lr1110_bootloader_stat2_t* stat2, 112 | lr1110_bootloader_irq_mask_t* irq_status ) 113 | { 114 | uint8_t data[LR1110_BL_GET_STATUS_CMD_LENGTH]; 115 | 116 | const lr1110_status_t status = 117 | ( lr1110_status_t ) lr1110_hal_direct_read( context, data, LR1110_BL_GET_STATUS_CMD_LENGTH ); 118 | 119 | if( status == LR1110_STATUS_OK ) 120 | { 121 | stat1->is_interrupt_active = ( ( data[0] & 0x01 ) != 0 ) ? true : false; 122 | stat1->command_status = ( lr1110_bootloader_command_status_t )( data[0] >> 1 ); 123 | 124 | stat2->is_running_from_flash = ( ( data[1] & 0x01 ) != 0 ) ? true : false; 125 | stat2->chip_mode = ( lr1110_bootloader_chip_modes_t )( ( data[1] & 0x0F ) >> 1 ); 126 | stat2->reset_status = ( lr1110_bootloader_reset_status_t )( ( data[1] & 0xF0 ) >> 4 ); 127 | 128 | *irq_status = 129 | ( ( lr1110_bootloader_irq_mask_t ) data[2] << 24 ) + ( ( lr1110_bootloader_irq_mask_t ) data[3] << 16 ) + 130 | ( ( lr1110_bootloader_irq_mask_t ) data[4] << 8 ) + ( ( lr1110_bootloader_irq_mask_t ) data[5] << 0 ); 131 | } 132 | 133 | return status; 134 | } 135 | 136 | lr1110_status_t lr1110_bootloader_clear_reset_status_info( const void* context ) 137 | { 138 | const uint8_t cbuffer[LR1110_BL_CMD_NO_PARAM_LENGTH] = { 139 | ( uint8_t )( LR1110_BL_GET_STATUS_OC >> 8 ), 140 | ( uint8_t )( LR1110_BL_GET_STATUS_OC >> 0 ), 141 | }; 142 | 143 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_BL_CMD_NO_PARAM_LENGTH, 0, 0 ); 144 | } 145 | 146 | lr1110_status_t lr1110_bootloader_get_version( const void* context, lr1110_bootloader_version_t* version ) 147 | { 148 | const uint8_t cbuffer[LR1110_BL_VERSION_CMD_LENGTH] = { 149 | ( uint8_t )( LR1110_BL_GET_VERSION_OC >> 8 ), 150 | ( uint8_t )( LR1110_BL_GET_VERSION_OC >> 0 ), 151 | }; 152 | uint8_t rbuffer[LR1110_BL_VERSION_LENGTH] = { 0x00 }; 153 | 154 | const lr1110_status_t status = ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_BL_VERSION_CMD_LENGTH, 155 | rbuffer, LR1110_BL_VERSION_LENGTH ); 156 | 157 | if( status == LR1110_STATUS_OK ) 158 | { 159 | version->hw = rbuffer[0]; 160 | version->type = rbuffer[1]; 161 | version->fw = ( ( uint16_t ) rbuffer[2] << 8 ) + ( uint16_t ) rbuffer[3]; 162 | } 163 | 164 | return status; 165 | } 166 | 167 | lr1110_status_t lr1110_bootloader_erase_flash( const void* context ) 168 | { 169 | const uint8_t cbuffer[LR1110_BL_ERASE_FLASH_CMD_LENGTH] = { 170 | ( uint8_t )( LR1110_BL_ERASE_FLASH_OC >> 8 ), 171 | ( uint8_t )( LR1110_BL_ERASE_FLASH_OC >> 0 ), 172 | }; 173 | 174 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_BL_ERASE_FLASH_CMD_LENGTH, 0, 0 ); 175 | } 176 | 177 | lr1110_status_t lr1110_bootloader_write_flash_encrypted( const void* context, const uint32_t offset, 178 | const uint32_t* data, uint8_t length ) 179 | { 180 | const uint8_t cbuffer[LR1110_BL_WRITE_FLASH_ENCRYPTED_CMD_LENGTH] = { 181 | ( uint8_t )( LR1110_BL_WRITE_FLASH_ENCRYPTED_OC >> 8 ), 182 | ( uint8_t )( LR1110_BL_WRITE_FLASH_ENCRYPTED_OC >> 0 ), 183 | ( uint8_t )( offset >> 24 ), 184 | ( uint8_t )( offset >> 16 ), 185 | ( uint8_t )( offset >> 8 ), 186 | ( uint8_t )( offset >> 0 ), 187 | }; 188 | 189 | uint8_t cdata[256] = { 0 }; 190 | for( uint8_t index = 0; index < length; index++ ) 191 | { 192 | uint8_t* cdata_local = &cdata[index * sizeof( uint32_t )]; 193 | 194 | cdata_local[0] = ( uint8_t )( data[index] >> 24 ); 195 | cdata_local[1] = ( uint8_t )( data[index] >> 16 ); 196 | cdata_local[2] = ( uint8_t )( data[index] >> 8 ); 197 | cdata_local[3] = ( uint8_t )( data[index] >> 0 ); 198 | } 199 | 200 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_BL_WRITE_FLASH_ENCRYPTED_CMD_LENGTH, cdata, 201 | length * sizeof( uint32_t ) ); 202 | } 203 | 204 | lr1110_status_t lr1110_bootloader_write_flash_encrypted_full( const void* context, const uint32_t offset, 205 | const uint32_t* buffer, const uint32_t length ) 206 | { 207 | uint32_t remaining_length = length; 208 | uint32_t local_offset = offset; 209 | uint32_t loop = 0; 210 | 211 | while( remaining_length != 0 ) 212 | { 213 | const lr1110_status_t status = lr1110_bootloader_write_flash_encrypted( 214 | context, local_offset, buffer + loop * LR1110_FLASH_DATA_MAX_LENGTH_UINT32, 215 | lr1110_bootloader_get_min_from_operand_and_max_block_size( remaining_length ) ); 216 | 217 | if( status != LR1110_STATUS_OK ) 218 | { 219 | return status; 220 | } 221 | 222 | local_offset += LR1110_FLASH_DATA_MAX_LENGTH_UINT8; 223 | remaining_length = ( remaining_length < LR1110_FLASH_DATA_MAX_LENGTH_UINT32 ) 224 | ? 0 225 | : ( remaining_length - LR1110_FLASH_DATA_MAX_LENGTH_UINT32 ); 226 | 227 | loop++; 228 | } 229 | 230 | return LR1110_STATUS_OK; 231 | } 232 | 233 | lr1110_status_t lr1110_bootloader_reboot( const void* context, const bool stay_in_bootloader ) 234 | { 235 | const uint8_t cbuffer[LR1110_BL_REBOOT_CMD_LENGTH] = { 236 | ( uint8_t )( LR1110_BL_REBOOT_OC >> 8 ), 237 | ( uint8_t )( LR1110_BL_REBOOT_OC >> 0 ), 238 | ( stay_in_bootloader == true ) ? 0x03 : 0x00, 239 | }; 240 | 241 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_BL_REBOOT_CMD_LENGTH, 0, 0 ); 242 | } 243 | 244 | lr1110_status_t lr1110_bootloader_read_pin( const void* context, lr1110_bootloader_pin_t pin ) 245 | { 246 | const uint8_t cbuffer[LR1110_BL_GET_PIN_CMD_LENGTH] = { 247 | ( uint8_t )( LR1110_BL_GET_PIN_OC >> 8 ), 248 | ( uint8_t )( LR1110_BL_GET_PIN_OC >> 0 ), 249 | }; 250 | 251 | return ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_BL_GET_PIN_CMD_LENGTH, pin, 252 | LR1110_BL_PIN_LENGTH ); 253 | } 254 | 255 | lr1110_status_t lr1110_bootloader_read_chip_eui( const void* context, lr1110_bootloader_chip_eui_t chip_eui ) 256 | { 257 | const uint8_t cbuffer[LR1110_BL_READ_CHIP_EUI_CMD_LENGTH] = { 258 | ( uint8_t )( LR1110_BL_READ_CHIP_EUI_OC >> 8 ), 259 | ( uint8_t )( LR1110_BL_READ_CHIP_EUI_OC >> 0 ), 260 | }; 261 | 262 | return ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_BL_READ_CHIP_EUI_CMD_LENGTH, chip_eui, 263 | LR1110_BL_CHIP_EUI_LENGTH ); 264 | } 265 | 266 | lr1110_status_t lr1110_bootloader_read_join_eui( const void* context, lr1110_bootloader_join_eui_t join_eui ) 267 | { 268 | const uint8_t cbuffer[LR1110_BL_READ_JOIN_EUI_CMD_LENGTH] = { 269 | ( uint8_t )( LR1110_BL_READ_JOIN_EUI_OC >> 8 ), 270 | ( uint8_t )( LR1110_BL_READ_JOIN_EUI_OC >> 0 ), 271 | }; 272 | 273 | return ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_BL_READ_JOIN_EUI_CMD_LENGTH, join_eui, 274 | LR1110_BL_JOIN_EUI_LENGTH ); 275 | } 276 | 277 | /* 278 | * ----------------------------------------------------------------------------- 279 | * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- 280 | */ 281 | 282 | uint8_t lr1110_bootloader_get_min_from_operand_and_max_block_size( uint32_t operand ) 283 | { 284 | if( operand > LR1110_FLASH_DATA_MAX_LENGTH_UINT32 ) 285 | { 286 | return LR1110_FLASH_DATA_MAX_LENGTH_UINT32; 287 | } 288 | else 289 | { 290 | return ( uint8_t ) operand; 291 | } 292 | } 293 | 294 | /* --- EOF ------------------------------------------------------------------ */ 295 | -------------------------------------------------------------------------------- /src/lr1110_bootloader.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_bootloader.h 3 | * 4 | * @brief Bootloader driver definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_BOOTLOADER_H 36 | #define LR1110_BOOTLOADER_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include "lr1110_bootloader_types.h" 48 | #include "lr1110_types.h" 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /* 61 | * ----------------------------------------------------------------------------- 62 | * --- PUBLIC TYPES ------------------------------------------------------------ 63 | */ 64 | 65 | typedef uint32_t lr1110_bootloader_irq_mask_t; 66 | 67 | /* 68 | * ----------------------------------------------------------------------------- 69 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 70 | */ 71 | 72 | /*! 73 | * @brief Return the status registers and interrupt flags 74 | * 75 | * @remark To simplify system integration, this function does not actually execute the GetStatus command, which would 76 | * require bidirectional SPI communication. It obtains the stat1, stat2, and irq_status values by performing an ordinary 77 | * SPI read (which is required to send null/NOP bytes on the MOSI line). This is possible since the LR1110 returns these 78 | * values automatically whenever a read that does not directly follow a response-carrying command is performed. Unlike 79 | * with the GetStatus command, however, the reset status information is NOT cleared by this command. The function @ref 80 | * lr1110_bootloader_clear_reset_status_info may be used for this purpose when necessary. 81 | * 82 | * @param [in] context Chip implementation context 83 | * @param [out] stat1 Content of status register 1 84 | * @param [out] stat2 Content of status register 2 85 | * @param [out] irq_status Interrupt flags 86 | * 87 | * @returns Operation status 88 | */ 89 | lr1110_status_t lr1110_bootloader_get_status( const void* context, lr1110_bootloader_stat1_t* stat1, 90 | lr1110_bootloader_stat2_t* stat2, 91 | lr1110_bootloader_irq_mask_t* irq_status ); 92 | 93 | /*! 94 | * @brief Clear the reset status information stored in stat2 95 | * 96 | * @param [in] context Chip implementation context 97 | * 98 | * @returns Operation status 99 | */ 100 | lr1110_status_t lr1110_bootloader_clear_reset_status_info( const void* context ); 101 | 102 | /*! 103 | * @brief Return the version of the system (hardware and software) 104 | * 105 | * @param [in] context Chip implementation context 106 | * @param [out] version Pointer to the structure holding the system version 107 | * 108 | * @returns Operation status 109 | */ 110 | lr1110_status_t lr1110_bootloader_get_version( const void* context, lr1110_bootloader_version_t* version ); 111 | 112 | /*! 113 | * @brief Erase the whole flash memory of the chip 114 | * 115 | * This function shall be called before any attempt to write a new firmware in flash memory 116 | * 117 | * @param [in] context Chip implementation context 118 | * 119 | * @returns Operation status 120 | */ 121 | lr1110_status_t lr1110_bootloader_erase_flash( const void* context ); 122 | 123 | /*! 124 | * @brief Write encrypted data in program flash memory of the chip 125 | * 126 | * This function shall be used when updating the encrypted flash content of the LR1110. 127 | * The encrypted flash payload to transfer shall be represented as an array of words (i.e. 4-byte values). 128 | * 129 | * @param [in] context Chip implementation context 130 | * @param [in] offset The offset from start register of flash 131 | * @param [in] buffer Buffer holding the encrypted content. Its size in words must be at least length 132 | * @param [in] length Number of words (i.e. 4 bytes) in the buffer to transfer 133 | * 134 | * @returns Operation status 135 | */ 136 | lr1110_status_t lr1110_bootloader_write_flash_encrypted( const void* context, const uint32_t offset, 137 | const uint32_t* buffer, const uint8_t length ); 138 | 139 | /*! 140 | * @brief Write encrypted data in program flash memory of the chip 141 | * 142 | * This function shall be used when updating the encrypted flash content of the LR1110. 143 | * The encrypted flash payload to transfer shall be represented as an array of words (ie 4-byte values). 144 | * 145 | * @param [in] context Chip implementation context 146 | * @param [in] offset The offset from start register of flash 147 | * @param [in] buffer Buffer holding the encrypted content. Its size in words must be at least length 148 | * @param [in] length Number of words (i.e. 4 bytes) in the buffer to transfer 149 | * 150 | * @returns Operation status 151 | */ 152 | lr1110_status_t lr1110_bootloader_write_flash_encrypted_full( const void* context, const uint32_t offset, 153 | const uint32_t* buffer, const uint32_t length ); 154 | 155 | /*! 156 | * @brief Software reset of the chip. 157 | * 158 | * This method should be used to reboot the chip in a specified mode. 159 | * Rebooting in flash mode presumes that the content in flash memory is not corrupted (i.e. the integrity check 160 | * performed by the bootloader before executing the first instruction in flash is OK). 161 | * 162 | * @param [in] context Chip implementation context 163 | * @param [in] stay_in_bootloader Selector to stay in bootloader or execute flash code after reboot. If true, the 164 | * bootloader will not execute the flash code but activate SPI interface to allow firmware upgrade 165 | * 166 | * @returns Operation status 167 | */ 168 | lr1110_status_t lr1110_bootloader_reboot( const void* context, const bool stay_in_bootloader ); 169 | 170 | /*! 171 | * @brief Returns the 4-byte PIN which can be used to claim a device on cloud services. 172 | * 173 | * @param [in] context Chip implementation context 174 | * @param [out] pin Pointer to the array to be populated with the PIN 175 | * 176 | * @returns Operation status 177 | */ 178 | lr1110_status_t lr1110_bootloader_read_pin( const void* context, lr1110_bootloader_pin_t pin ); 179 | 180 | /*! 181 | * @brief Read and return the Chip EUI 182 | * 183 | * @param [in] context Chip implementation context 184 | * @param [out] chip_eui The buffer to be filled with chip EUI of the LR1110. It is up to the application to ensure 185 | * chip_eui is long enough to hold the chip EUI 186 | * 187 | * @returns Operation status 188 | */ 189 | lr1110_status_t lr1110_bootloader_read_chip_eui( const void* context, lr1110_bootloader_chip_eui_t chip_eui ); 190 | 191 | /*! 192 | * @brief Read and return the Join EUI 193 | * 194 | * @param [in] context Chip implementation context 195 | * @param [out] join_eui The buffer to be filled with Join EUI of the LR1110. It is up to the application to ensure 196 | * join_eui is long enough to hold the join EUI 197 | * 198 | * @returns Operation status 199 | */ 200 | lr1110_status_t lr1110_bootloader_read_join_eui( const void* context, lr1110_bootloader_join_eui_t join_eui ); 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif // LR1110_BOOTLOADER_H 207 | 208 | /* --- EOF ------------------------------------------------------------------ */ 209 | -------------------------------------------------------------------------------- /src/lr1110_bootloader_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_bootloader_types.h 3 | * 4 | * @brief Bootloader driver types for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_BOOTLOADER_TYPES_H 36 | #define LR1110_BOOTLOADER_TYPES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /*! 61 | * @brief Length in byte of the LR1110 version blob 62 | */ 63 | #define LR1110_BL_VERSION_LENGTH ( 4 ) 64 | 65 | /*! 66 | * @brief Length in bytes of a PIN 67 | */ 68 | #define LR1110_BL_PIN_LENGTH ( 4 ) 69 | 70 | /*! 71 | * @brief Length in bytes of a chip EUI 72 | */ 73 | #define LR1110_BL_CHIP_EUI_LENGTH ( 8 ) 74 | 75 | /*! 76 | * @brief Length in bytes of a join EUI 77 | */ 78 | #define LR1110_BL_JOIN_EUI_LENGTH ( 8 ) 79 | 80 | /* 81 | * ----------------------------------------------------------------------------- 82 | * --- PUBLIC TYPES ------------------------------------------------------------ 83 | */ 84 | 85 | /*! 86 | * @brief Fixed-length array to store a PIN 87 | */ 88 | typedef uint8_t lr1110_bootloader_pin_t[LR1110_BL_PIN_LENGTH]; 89 | 90 | /*! 91 | * @brief Fixed-length array to store a chipEUI 92 | */ 93 | typedef uint8_t lr1110_bootloader_chip_eui_t[LR1110_BL_CHIP_EUI_LENGTH]; 94 | 95 | /*! 96 | * @brief Fixed-length array to store a joinEUI 97 | */ 98 | typedef uint8_t lr1110_bootloader_join_eui_t[LR1110_BL_JOIN_EUI_LENGTH]; 99 | 100 | /*! 101 | * @brief Chip modes 102 | */ 103 | typedef enum lr1110_bootloader_chip_modes_e 104 | { 105 | LR1110_BOOTLOADER_CHIP_MODE_SLEEP = 0x00, 106 | LR1110_BOOTLOADER_CHIP_MODE_STBY_RC = 0x01, 107 | LR1110_BOOTLOADER_CHIP_MODE_STBY_XOSC = 0x02, 108 | LR1110_BOOTLOADER_CHIP_MODE_FS = 0x03, 109 | LR1110_BOOTLOADER_CHIP_MODE_RX = 0x04, 110 | LR1110_BOOTLOADER_CHIP_MODE_TX = 0x05, 111 | LR1110_BOOTLOADER_CHIP_MODE_LOC = 0x06, 112 | } lr1110_bootloader_chip_modes_t; 113 | 114 | /*! 115 | * @brief Reset status 116 | */ 117 | typedef enum lr1110_bootloader_reset_status_e 118 | { 119 | LR1110_BOOTLOADER_RESET_STATUS_CLEARED = 0x00, 120 | LR1110_BOOTLOADER_RESET_STATUS_ANALOG = 0x01, 121 | LR1110_BOOTLOADER_RESET_STATUS_EXTERNAL = 0x02, 122 | LR1110_BOOTLOADER_RESET_STATUS_SYSTEM = 0x03, 123 | LR1110_BOOTLOADER_RESET_STATUS_WATCHDOG = 0x04, 124 | LR1110_BOOTLOADER_RESET_STATUS_IOCD_RESTART = 0x05, 125 | LR1110_BOOTLOADER_RESET_STATUS_RTC_RESTART = 0x06, 126 | } lr1110_bootloader_reset_status_t; 127 | 128 | /*! 129 | * @brief Command status 130 | */ 131 | typedef enum lr1110_bootloader_command_status_e 132 | { 133 | LR1110_BOOTLOADER_CMD_STATUS_FAIL = 0x00, 134 | LR1110_BOOTLOADER_CMD_STATUS_PERR = 0x01, 135 | LR1110_BOOTLOADER_CMD_STATUS_OK = 0x02, 136 | LR1110_BOOTLOADER_CMD_STATUS_DATA = 0x03, 137 | } lr1110_bootloader_command_status_t; 138 | 139 | /*! 140 | * @brief Status register 1 structure definition 141 | */ 142 | typedef struct lr1110_bootloader_stat1_s 143 | { 144 | lr1110_bootloader_command_status_t command_status; 145 | bool is_interrupt_active; 146 | } lr1110_bootloader_stat1_t; 147 | 148 | /*! 149 | * @brief Status register 2 structure definition 150 | */ 151 | typedef struct lr1110_bootloader_stat2_s 152 | { 153 | lr1110_bootloader_reset_status_t reset_status; 154 | lr1110_bootloader_chip_modes_t chip_mode; 155 | bool is_running_from_flash; 156 | } lr1110_bootloader_stat2_t; 157 | 158 | /*! 159 | * @brief Bootloader version structure definition 160 | */ 161 | typedef struct lr1110_bootloader_version_s 162 | { 163 | uint8_t hw; 164 | uint8_t type; 165 | uint16_t fw; 166 | } lr1110_bootloader_version_t; 167 | 168 | /* 169 | * ----------------------------------------------------------------------------- 170 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 171 | */ 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif // LR1110_BOOTLOADER_TYPES_H 178 | 179 | /* --- EOF ------------------------------------------------------------------ */ 180 | -------------------------------------------------------------------------------- /src/lr1110_crypto_engine.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_crypto_engine.h 3 | * 4 | * @brief Cryptographic engine driver definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_CRYPTO_ENGINE_H 36 | #define LR1110_CRYPTO_ENGINE_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include "lr1110_crypto_engine_types.h" 48 | #include "lr1110_types.h" 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /* 61 | * ----------------------------------------------------------------------------- 62 | * --- PUBLIC TYPES ------------------------------------------------------------ 63 | */ 64 | 65 | /* 66 | * ----------------------------------------------------------------------------- 67 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 68 | */ 69 | 70 | /*! 71 | * @brief Select the crypto element to be used 72 | * 73 | * By default, the internal crypto engine is selected. It is not needed to call this command if one plans to use the 74 | * internal crypto engine. 75 | * 76 | * @param [in] context Chip implementation context 77 | * @param [in] element The type of crypto element to use 78 | * 79 | * @returns Operation status 80 | */ 81 | lr1110_status_t lr1110_crypto_select( const void* context, const lr1110_crypto_element_t element ); 82 | 83 | /*! 84 | * @brief Set a key in the previously selected crypto element. 85 | * 86 | * @param [in] context Chip implementation context 87 | * @param [out] status The status returned by the execution of this cryptographic function 88 | * @param [in] key_id The identifier of the key to be set 89 | * @param [in] key The key to be set 90 | * 91 | * @see lr1110_crypto_derive_key 92 | * 93 | * @returns Operation status 94 | */ 95 | lr1110_status_t lr1110_crypto_set_key( const void* context, lr1110_crypto_status_t* status, const uint8_t key_id, 96 | const lr1110_crypto_key_t key ); 97 | 98 | /*! 99 | * @brief Derive a key previously set. 100 | * 101 | * @param [in] context Chip implementation context 102 | * @param [out] status The status returned by the execution of this cryptographic function 103 | * @param [in] src_key_id The identifier of the key to be derived 104 | * @param [in] dest_key_id The identifier where the derived key will be stored after call to @ref 105 | * lr1110_crypto_store_to_flash 106 | * @param [in] nonce The nonce to be used to perform the derivation 107 | * 108 | * @see lr1110_crypto_set_key 109 | * 110 | * @returns Operation status 111 | */ 112 | lr1110_status_t lr1110_crypto_derive_key( const void* context, lr1110_crypto_status_t* status, const uint8_t src_key_id, 113 | const uint8_t dest_key_id, const lr1110_crypto_nonce_t nonce ); 114 | 115 | /*! 116 | * @brief Perform the needed operations to extract the payload from a join accept message. 117 | * 118 | * @param [in] context Chip implementation context 119 | * @param [out] status The status returned by the execution of this cryptographic function 120 | * @param [in] dec_key_id The identifier of the key used for message decryption 121 | * @param [in] ver_key_id The identifier of the key used for MIC verification 122 | * @param [in] lorawan_version LoRaWAN version to know the size of the header 123 | * @param [in] header The header to compute (length linked to lorawan_version) 124 | * @param [in] data The data to compute 125 | * @param [in] length The length in bytes of the data to compute 126 | * @param [out] data_out Placeholder for the decrypted data 127 | * 128 | * @returns Operation status 129 | */ 130 | lr1110_status_t lr1110_crypto_process_join_accept( const void* context, lr1110_crypto_status_t* status, 131 | const uint8_t dec_key_id, const uint8_t ver_key_id, 132 | const lr1110_crypto_lorawan_version_t lorawan_version, 133 | const uint8_t* header, const uint8_t* data, const uint8_t length, 134 | uint8_t* data_out ); 135 | 136 | /*! 137 | * @brief Compute an AES-CMAC. 138 | * 139 | * @param [in] context Chip implementation context 140 | * @param [out] status The status returned by the execution of this cryptographic function 141 | * @param [in] key_id The identifier of the keyused for the computation 142 | * @param [in] data The data to compute 143 | * @param [in] length The length in bytes of the data to compute 144 | * @param [out] mic Placeholder for the computed MIC (first 4 bytes of the AES-CMAC) 145 | * 146 | * @see lr1110_crypto_verify_aes_cmac 147 | * 148 | * @returns Operation status 149 | */ 150 | lr1110_status_t lr1110_crypto_compute_aes_cmac( const void* context, lr1110_crypto_status_t* status, 151 | const uint8_t key_id, const uint8_t* data, const uint16_t length, 152 | lr1110_crypto_mic_t mic ); 153 | 154 | /*! 155 | * @brief Compute an AES-CMAC and make a comparison with a value given as parameter. 156 | * 157 | * @param [in] context Chip implementation context 158 | * @param [out] status The status returned by the execution of this cryptographic function 159 | * @param [in] key_id The identifier of the key to be used for the computation 160 | * @param [in] data The data to compute 161 | * @param [in] length The length in bytes of the data to compute 162 | * @param [in] mic The MIC value (first 4 bytes of the CMAC) use for comparison 163 | * 164 | * @see lr1110_crypto_compute_aes_cmac 165 | * 166 | * @returns Operation status 167 | */ 168 | lr1110_status_t lr1110_crypto_verify_aes_cmac( const void* context, lr1110_crypto_status_t* status, 169 | const uint8_t key_id, const uint8_t* data, const uint16_t length, 170 | const lr1110_crypto_mic_t mic ); 171 | 172 | /*! 173 | * @brief Compute an AES encryption with a key ID specified in parameter. 174 | * 175 | * @param [in] context Chip implementation context 176 | * @param [out] status The status returned by the execution of this cryptographic function 177 | * @param [in] key_id The identifier of the key to be used for the computation 178 | * @param [in] data The data to encrypt 179 | * @param [in] length The length in bytes of the data to encrypt - this value shall be a multiple of 16 180 | * @param [out] result A pointer to a data buffer that will be filled with the encrypted data. Values of this buffer are 181 | * meaningful if and only if the return status is LR1110_CRYPTO_STATUS_SUCCESS 182 | * 183 | * @see lr1110_crypto_set_key, lr1110_crypto_derive_key 184 | * 185 | * @returns Operation status 186 | */ 187 | lr1110_status_t lr1110_crypto_aes_encrypt_01( const void* context, lr1110_crypto_status_t* status, const uint8_t key_id, 188 | const uint8_t* data, const uint16_t length, uint8_t* result ); 189 | 190 | /*! 191 | * @brief Compute an AES encryption with a key ID specified in parameter. 192 | * 193 | * @param [in] context Chip implementation context 194 | * @param [out] status The status returned by the execution of this cryptographic function 195 | * @param [in] key_id The identifier of the key to be used for the computation 196 | * @param [in] data The data to encrypt 197 | * @param [in] length The length in bytes of the data to encrypt - this value shall be a multiple of 16 198 | * @param [out] result A pointer to a data buffer that will be filled with the encrypted data. Values of this buffer are 199 | * meaningful if and only if the return status is LR1110_CRYPTO_STATUS_SUCCESS 200 | * 201 | * @see lr1110_crypto_set_key, lr1110_crypto_derive_key 202 | * 203 | * @returns Operation status 204 | */ 205 | lr1110_status_t lr1110_crypto_aes_encrypt( const void* context, lr1110_crypto_status_t* status, const uint8_t key_id, 206 | const uint8_t* data, const uint16_t length, uint8_t* result ); 207 | 208 | /*! 209 | * @brief Compute an AES decryption with a key ID specified in parameter. 210 | * 211 | * @param [in] context Chip implementation context 212 | * @param [out] status The status returned by the execution of this cryptographic function 213 | * @param [in] key_id The identifier of the key to be used for the computation 214 | * @param [in] data The data to decrypt 215 | * @param [in] length The length in bytes of the data to decrypt - this value shall be a multiple of 16 216 | * @param [out] result A pointer to a data buffer that will be filled with the decrypted data. Values of this buffer are 217 | * meaningful if and only if the return status is LR1110_CRYPTO_STATUS_SUCCESS 218 | * 219 | * @see lr1110_crypto_set_key, lr1110_crypto_derive_key 220 | * 221 | * @returns Operation status 222 | */ 223 | lr1110_status_t lr1110_crypto_aes_decrypt( const void* context, lr1110_crypto_status_t* status, const uint8_t key_id, 224 | const uint8_t* data, const uint16_t length, uint8_t* result ); 225 | 226 | /*! 227 | * @brief Store the crypto data (keys, parameters) from RAM into the flash memory. 228 | * 229 | * @param [in] context Chip implementation context 230 | * @param [out] status The status returned by the execution of this cryptographic function 231 | * 232 | * @see lr1110_crypto_restore_from_flash 233 | * 234 | * @returns Operation status 235 | */ 236 | lr1110_status_t lr1110_crypto_store_to_flash( const void* context, lr1110_crypto_status_t* status ); 237 | 238 | /*! 239 | * @brief Restore the crypto data (keys, parameters) from flash memory into RAM. 240 | * 241 | * @param [in] context Chip implementation context 242 | * @param [out] status The status returned by the execution of this cryptographic function 243 | * 244 | * @see lr1110_crypto_store_to_flash 245 | * 246 | * @returns Operation status 247 | */ 248 | lr1110_status_t lr1110_crypto_restore_from_flash( const void* context, lr1110_crypto_status_t* status ); 249 | 250 | /*! 251 | * @brief Set a specific parameter identified by param_id in the crypto RAM. 252 | * 253 | * This function does not store a parameter in the flash memory. The parameters shall be stored after using @ref 254 | * lr1110_crypto_store_to_flash command. 255 | * 256 | * @param [in] context Chip implementation context 257 | * @param [out] status The status returned by the execution of this cryptographic function 258 | * @param [in] param_id The identifier of the parameter to be set 259 | * @param [in] parameter The parameter to be set 260 | * 261 | * @see lr1110_crypto_get_parameter 262 | * 263 | * @returns Operation status 264 | */ 265 | lr1110_status_t lr1110_crypto_set_parameter( const void* context, lr1110_crypto_status_t* status, 266 | const uint8_t param_id, const lr1110_crypto_param_t parameter ); 267 | 268 | /*! 269 | * @brief Get a specific parameter identified by paramID from the crypto RAM. 270 | * 271 | * This function does not fetch a parameter from the flash memory. The parameters shall be restored before using @ref 272 | * lr1110_crypto_restore_from_flash command. 273 | * 274 | * @param [in] context Chip implementation context 275 | * @param [out] status The status returned by the execution of this cryptographic function 276 | * @param [in] param_id The identifier of the parameter to get 277 | * @param [out] parameter The placeholder to store the parameter 278 | * 279 | * @see lr1110_crypto_set_parameter 280 | * 281 | * @returns Operation status 282 | */ 283 | lr1110_status_t lr1110_crypto_get_parameter( const void* context, lr1110_crypto_status_t* status, 284 | const uint8_t param_id, lr1110_crypto_param_t parameter ); 285 | 286 | #ifdef __cplusplus 287 | } 288 | #endif 289 | 290 | #endif // LR1110_CRYPTO_ENGINE_H 291 | 292 | /* --- EOF ------------------------------------------------------------------ */ 293 | -------------------------------------------------------------------------------- /src/lr1110_crypto_engine_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_crypto_engine_types.h 3 | * 4 | * @brief Cryptographic engine driver types for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_CRYPTO_ENGINE_TYPES_H 36 | #define LR1110_CRYPTO_ENGINE_TYPES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | 49 | /* 50 | * ----------------------------------------------------------------------------- 51 | * --- PUBLIC MACROS ----------------------------------------------------------- 52 | */ 53 | 54 | /* 55 | * ----------------------------------------------------------------------------- 56 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 57 | */ 58 | 59 | /*! 60 | * @brief Length in bytes of a MIC 61 | */ 62 | #define LR1110_CRYPTO_MIC_LENGTH 0x04 63 | 64 | /*! 65 | * @brief Length in bytes of a AES CMAC 66 | */ 67 | #define LR1110_CRYPTO_AES_CMAC_LENGTH 0x10 68 | 69 | /*! 70 | * @brief Maximum length in bytes of data to be encrypted / decrypted 71 | */ 72 | #define LR1110_CRYPTO_DATA_MAX_LENGTH 0x0100 73 | 74 | /*! 75 | * @brief Length in bytes of a key for AES computation 76 | */ 77 | #define LR1110_CRYPTO_KEY_LENGTH 0x10 78 | 79 | /*! 80 | * @brief Length in bytes of a nonce 81 | */ 82 | #define LR1110_CRYPTO_NONCE_LENGTH 0x10 83 | 84 | /*! 85 | * @brief Length in bytes of a crypto parameter 86 | */ 87 | #define LR1110_CRYPTO_PARAMETER_LENGTH 0x04 88 | 89 | /*! 90 | * @brief Length in bytes of the status returned by an API 91 | */ 92 | #define LR1110_CRYPTO_STATUS_LENGTH 0x01 93 | 94 | /* 95 | * ----------------------------------------------------------------------------- 96 | * --- PUBLIC TYPES ------------------------------------------------------------ 97 | */ 98 | 99 | /*! 100 | * @brief Fixed-length array to store an AES CMAC 101 | */ 102 | typedef uint8_t lr1110_crypto_mic_t[LR1110_CRYPTO_MIC_LENGTH]; 103 | 104 | /*! 105 | * @brief Fixed-length array to store an AES CMAC 106 | */ 107 | typedef uint8_t lr1110_crypto_aes_cmac_t[LR1110_CRYPTO_AES_CMAC_LENGTH]; 108 | 109 | /*! 110 | * @brief Fixed-length array to store a crypto key 111 | */ 112 | typedef uint8_t lr1110_crypto_key_t[LR1110_CRYPTO_KEY_LENGTH]; 113 | 114 | /*! 115 | * @brief Fixed-length array to store a crypto nonce 116 | */ 117 | typedef uint8_t lr1110_crypto_nonce_t[LR1110_CRYPTO_NONCE_LENGTH]; 118 | 119 | /*! 120 | * @brief Fixed-length array to store a crypto parameter 121 | */ 122 | typedef uint8_t lr1110_crypto_param_t[LR1110_CRYPTO_PARAMETER_LENGTH]; 123 | 124 | /*! 125 | * @brief The supported crypto elements 126 | */ 127 | typedef enum 128 | { 129 | LR1110_CRYPTO_ELEMENT_CRYPTO_ENGINE = 0x00, //!< Internal crypto engine (default) 130 | LR1110_CRYPTO_ELEMENT_SECURE_ELEMENT = 0x01, //!< External secure element 131 | } lr1110_crypto_element_t; 132 | 133 | /*! 134 | * @brief The status returned by the crypto API 135 | */ 136 | typedef enum 137 | { 138 | LR1110_CRYPTO_STATUS_SUCCESS = 0x00, //!< The API command was successful 139 | LR1110_CRYPTO_STATUS_ERROR_FAIL_CMAC = 0x01, //!< AES-CMAC invalid or comparison failed 140 | LR1110_CRYPTO_STATUS_ERROR_INVALID_KEY_ID = 0x03, //!< Invalid key ID (source, destination) 141 | LR1110_CRYPTO_STATUS_ERROR_BUFFER_SIZE = 0x05, //!< Invalid data buffer size 142 | LR1110_CRYPTO_STATUS_ERROR = 0x06, //!< Other error 143 | } lr1110_crypto_status_t; 144 | 145 | /*! 146 | * @brief The supported LoRaWAN versions 147 | */ 148 | typedef enum 149 | { 150 | LR1110_CRYPTO_LORAWAN_VERSION_1_0_X = 0x00, 151 | LR1110_CRYPTO_LORAWAN_VERSION_1_1_X = 0x01, 152 | } lr1110_crypto_lorawan_version_t; 153 | 154 | /*! 155 | * @brief Crypto keys table index definition. 156 | */ 157 | typedef enum lr1110_crypto_keys_idx_e 158 | { 159 | LR1110_CRYPTO_KEYS_IDX_MOTHER_KEY = 1, 160 | LR1110_CRYPTO_KEYS_IDX_NWK_KEY = 2, 161 | LR1110_CRYPTO_KEYS_IDX_APP_KEY = 3, 162 | LR1110_CRYPTO_KEYS_IDX_J_S_ENC_KEY = 4, 163 | LR1110_CRYPTO_KEYS_IDX_J_S_INT_KEY = 5, 164 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_0 = 6, 165 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_1 = 7, 166 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_2 = 8, 167 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_3 = 9, 168 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_4 = 10, 169 | LR1110_CRYPTO_KEYS_IDX_GP_KE_KEY_5 = 11, 170 | LR1110_CRYPTO_KEYS_IDX_APP_S_KEY = 12, 171 | LR1110_CRYPTO_KEYS_IDX_F_NWK_S_INT_KEY = 13, 172 | LR1110_CRYPTO_KEYS_IDX_S_NWK_S_INT_KEY = 14, 173 | LR1110_CRYPTO_KEYS_IDX_NWK_S_ENC_KEY = 15, 174 | LR1110_CRYPTO_KEYS_IDX_RFU_0 = 16, 175 | LR1110_CRYPTO_KEYS_IDX_RFU_1 = 17, 176 | LR1110_CRYPTO_KEYS_IDX_MC_APP_S_KEY_0 = 18, 177 | LR1110_CRYPTO_KEYS_IDX_MC_APP_S_KEY_1 = 19, 178 | LR1110_CRYPTO_KEYS_IDX_MC_APP_S_KEY_2 = 20, 179 | LR1110_CRYPTO_KEYS_IDX_MC_APP_S_KEY_3 = 21, 180 | LR1110_CRYPTO_KEYS_IDX_MC_NWK_S_KEY_0 = 22, 181 | LR1110_CRYPTO_KEYS_IDX_MC_NWK_S_KEY_1 = 23, 182 | LR1110_CRYPTO_KEYS_IDX_MC_NWK_S_KEY_2 = 24, 183 | LR1110_CRYPTO_KEYS_IDX_MC_NWK_S_KEY_3 = 25, 184 | LR1110_CRYPTO_KEYS_IDX_GP0 = 26, 185 | LR1110_CRYPTO_KEYS_IDX_GP1 = 27, 186 | } lr1110_crypto_keys_idx_t; 187 | 188 | /* 189 | * ----------------------------------------------------------------------------- 190 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 191 | */ 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif // LR1110_CRYPTO_ENGINE_TYPES_H 198 | 199 | /* --- EOF ------------------------------------------------------------------ */ 200 | -------------------------------------------------------------------------------- /src/lr1110_driver_version.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_driver_version.c 3 | * 4 | * @brief Placeholder to keep the version of LR1110 driver. 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * ----------------------------------------------------------------------------- 37 | * --- DEPENDENCIES ------------------------------------------------------------ 38 | */ 39 | 40 | #include "lr1110_driver_version.h" 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- PRIVATE MACROS----------------------------------------------------------- 45 | */ 46 | 47 | #define STR_HELPER( x ) #x 48 | #define STR( x ) STR_HELPER( x ) 49 | 50 | #define LR1110_DRIVER_VERSION_FULL \ 51 | "v" STR( LR1110_DRIVER_VERSION_MAJOR ) "." STR( LR1110_DRIVER_VERSION_MINOR ) "." STR( LR1110_DRIVER_VERSION_PATCH ) 52 | 53 | /* 54 | * ----------------------------------------------------------------------------- 55 | * --- PRIVATE CONSTANTS ------------------------------------------------------- 56 | */ 57 | 58 | /* 59 | * ----------------------------------------------------------------------------- 60 | * --- PRIVATE TYPES ----------------------------------------------------------- 61 | */ 62 | 63 | /* 64 | * ----------------------------------------------------------------------------- 65 | * --- PRIVATE VARIABLES ------------------------------------------------------- 66 | */ 67 | 68 | /* 69 | * ----------------------------------------------------------------------------- 70 | * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- 71 | */ 72 | 73 | /* 74 | * ----------------------------------------------------------------------------- 75 | * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- 76 | */ 77 | 78 | const char* lr1110_driver_version_get_version_string( void ) 79 | { 80 | return ( const char* ) LR1110_DRIVER_VERSION_FULL; 81 | } 82 | 83 | /* 84 | * ----------------------------------------------------------------------------- 85 | * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- 86 | */ 87 | 88 | /* --- EOF ------------------------------------------------------------------ */ 89 | -------------------------------------------------------------------------------- /src/lr1110_driver_version.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_driver_version.h 3 | * 4 | * @brief Placeholder to keep the version of LR1110 driver. 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_DRIVER_VERSION_H 36 | #define LR1110_DRIVER_VERSION_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | /* 48 | * ----------------------------------------------------------------------------- 49 | * --- PUBLIC MACROS ----------------------------------------------------------- 50 | */ 51 | 52 | /* 53 | * ----------------------------------------------------------------------------- 54 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 55 | */ 56 | 57 | #define LR1110_DRIVER_VERSION_MAJOR 7 58 | #define LR1110_DRIVER_VERSION_MINOR 0 59 | #define LR1110_DRIVER_VERSION_PATCH 0 60 | 61 | /* 62 | * ----------------------------------------------------------------------------- 63 | * --- PUBLIC TYPES ------------------------------------------------------------ 64 | */ 65 | 66 | /* 67 | * ----------------------------------------------------------------------------- 68 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 69 | */ 70 | 71 | /*! 72 | * @brief Compare version information with current ones 73 | * 74 | * This macro expands to true boolean value if the version information provided in argument is compatible or 75 | * retro-compatible with the version of this code base 76 | */ 77 | #define LR1110_DRIVER_VERSION_CHECK( x, y, z ) \ 78 | ( x == LR1110_DRIVER_VERSION_MAJOR && \ 79 | ( y < LR1110_DRIVER_VERSION_MINOR || \ 80 | ( y == LR1110_DRIVER_VERSION_MINOR && z <= LR1110_DRIVER_VERSION_PATCH ) ) ) 81 | 82 | const char* lr1110_driver_version_get_version_string( void ); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif // LR1110_DRIVER_VERSION_H 89 | 90 | /* --- EOF ------------------------------------------------------------------ */ 91 | -------------------------------------------------------------------------------- /src/lr1110_gnss.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_gnss.h 3 | * 4 | * @brief GNSS scan driver definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_GNSS_H 36 | #define LR1110_GNSS_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include "lr1110_gnss_types.h" 48 | #include "lr1110_types.h" 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /* 61 | * ----------------------------------------------------------------------------- 62 | * --- PUBLIC TYPES ------------------------------------------------------------ 63 | */ 64 | 65 | /* 66 | * ----------------------------------------------------------------------------- 67 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 68 | */ 69 | 70 | /*! 71 | * @brief Get the size of results 72 | * 73 | * This method returns the size in bytes of the results available in LR1110 result buffer. 74 | * 75 | * @param [in] context Chip implementation context 76 | * @param [out] result_size Result size 77 | * 78 | * @returns Operation status 79 | */ 80 | lr1110_status_t lr1110_gnss_get_result_size( const void* context, uint16_t* result_size ); 81 | 82 | /*! 83 | * @brief Read GNSS results 84 | * 85 | * The GNSS results are pushed into a buffer directly. This buffer is provided by the application using the driver. It 86 | * MUST be long enough to contains at least result_buffer_size bytes. 87 | * 88 | * @warning No check is done on result_buffer size. If this application provided buffer is too small, there will be a 89 | * buffer overflow bug! 90 | * 91 | * @param [in] context Chip implementation context 92 | * @param [out] result_buffer Application provided buffer to be filled with result 93 | * @param [in] result_buffer_size The number of bytes to read from the LR1110 94 | * 95 | * @returns Operation status 96 | */ 97 | lr1110_status_t lr1110_gnss_read_results( const void* context, uint8_t* result_buffer, 98 | const uint16_t result_buffer_size ); 99 | 100 | /*! 101 | * @brief Get the time spent in signal acquisition and signal analysis 102 | * 103 | * These timings allow to compute the current consumption of the last GNSS scan. 104 | * 105 | * @param [in] context Chip implementation context 106 | * @param [out] timings GNSS timings of last GNSS scan 107 | * 108 | * @returns Operation status 109 | */ 110 | lr1110_status_t lr1110_gnss_get_timings( const void* context, lr1110_gnss_timings_t* timings ); 111 | 112 | /*! 113 | * @brief Update almanacs given as parameter 114 | * 115 | * @remark Note that information header and almanacs for all 128 SV (i.e. 129 20-byte long blocks) must be updated in a 116 | * row for the whole operation to be successful. Therefore, this function must be called as many times as needed without 117 | * any other operations in between. 118 | * 119 | * @param [in] context Chip implementation context 120 | * @param [in] blocks Buffer containing at least (nb_of_blocks * LR1110_GNSS_SINGLE_ALMANAC_WRITE_SIZE) bytes of almanac 121 | * @param [in] nb_of_blocks Number of blocks to transfer 122 | * 123 | * @returns Operation status 124 | */ 125 | lr1110_status_t lr1110_gnss_almanac_update( const void* context, const uint8_t* blocks, const uint8_t nb_of_blocks ); 126 | 127 | /*! 128 | * @brief Read the almanac 129 | * 130 | * @param [in] context Chip implementation context 131 | * @param [out] almanac_bytestream The bytestream of the almanac 132 | * 133 | * @returns Operation status 134 | */ 135 | lr1110_status_t lr1110_gnss_read_almanac( const void* context, 136 | lr1110_gnss_almanac_full_read_bytestream_t almanac_bytestream ); 137 | 138 | /*! 139 | * @brief Get almanac age for a satellite 140 | * 141 | * @param [in] context Chip implementation context 142 | * @param [in] sv_id ID of the satellite corresponding the to almanac requested 143 | * @param [out] almanac_age Almanac age in days since last GPS time overlap 144 | * 145 | * @returns Operation status 146 | */ 147 | lr1110_status_t lr1110_gnss_get_almanac_age_for_satellite( const void* context, const lr1110_gnss_satellite_id_t sv_id, 148 | uint16_t* almanac_age ); 149 | 150 | /*! 151 | * @brief Push data received from solver to LR1110 152 | * 153 | * @param [in] context Chip implementation context 154 | * @param [in] payload Payload received from solver 155 | * @param [in] payload_size Size of the payload received from solver (in bytes) 156 | * 157 | * @returns Operation status 158 | */ 159 | lr1110_status_t lr1110_gnss_push_solver_msg( const void* context, const uint8_t* payload, const uint16_t payload_size ); 160 | 161 | /*! 162 | * @brief Activate the GNSS scan constellation 163 | * 164 | * @param [in] context Chip implementation context 165 | * @param [in] constellation_mask Bit mask of the constellations to use. See @ref lr1110_gnss_constellation_t for the 166 | * possible values 167 | * 168 | * @returns Operation status 169 | * 170 | * @see lr1110_gnss_read_used_constellations 171 | */ 172 | lr1110_status_t lr1110_gnss_set_constellations_to_use( const void* context, 173 | const lr1110_gnss_constellation_mask_t constellation_mask ); 174 | 175 | /*! 176 | * @brief Read constellation used by the GNSS scanner from the almanac update configuration 177 | * 178 | * @param [in] context Chip implementation context 179 | * @param [out] constellations_used Bit mask of the constellations used. See @ref lr1110_gnss_constellation_t for the 180 | * possible values 181 | * 182 | * @returns Operation status 183 | * 184 | * @see lr1110_gnss_set_constellations_to_use 185 | */ 186 | lr1110_status_t lr1110_gnss_read_used_constellations( const void* context, 187 | lr1110_gnss_constellation_mask_t* constellations_used ); 188 | 189 | /*! 190 | * @brief Activate the almanac update 191 | * 192 | * @param [in] context Chip implementation context 193 | * @param [in] constellations_to_update Bit mask of the constellations to mark to update. See @ref 194 | * lr1110_gnss_constellation_t for the possible values 195 | * 196 | * @returns Operation status 197 | */ 198 | lr1110_status_t lr1110_gnss_set_almanac_update( const void* context, 199 | const lr1110_gnss_constellation_mask_t constellations_to_update ); 200 | 201 | /*! 202 | * @brief Function to read the almanac update configuration 203 | * 204 | * @param [in] context Chip implementation context 205 | * @param [out] constellations_to_update Bit mask of the constellations to mark to update. See @ref 206 | * lr1110_gnss_constellation_t for the possible values 207 | * 208 | * @returns Operation status 209 | */ 210 | lr1110_status_t lr1110_gnss_read_almanac_update( const void* context, 211 | lr1110_gnss_constellation_mask_t* constellations_to_update ); 212 | 213 | /*! 214 | * @brief Function to read the GNSS firmware version 215 | * 216 | * @param [in] context Chip implementation context 217 | * @param [in] version GNSS Firmware version currently running on the chip 218 | * 219 | * @returns Operation status 220 | */ 221 | lr1110_status_t lr1110_gnss_read_firmware_version( const void* context, lr1110_gnss_version_t* version ); 222 | 223 | /*! 224 | * @brief Function to read the supported constellation, GPS or BEIDOU other constellations 225 | * 226 | * @param [in] context Chip implementation context 227 | * @param [out] supported_constellations Bit mask of the constellations used. See @ref lr1110_gnss_constellation_t for 228 | * the possible values 229 | * 230 | * @returns Operation status 231 | */ 232 | lr1110_status_t lr1110_gnss_read_supported_constellations( const void* context, 233 | lr1110_gnss_constellation_mask_t* supported_constellations ); 234 | 235 | /*! 236 | * @brief Function to set the GNSS scan mode configuration 237 | * 238 | * @param [in] context Chip implementation context 239 | * @param [in] scan_mode GNSS scan mode 240 | * 241 | * @returns Operation status 242 | * 243 | * @ref lr1110_gnss_scan_mode_t 244 | */ 245 | lr1110_status_t lr1110_gnss_set_scan_mode( const void* context, const lr1110_gnss_scan_mode_t scan_mode ); 246 | 247 | /*! 248 | * @brief Gnss scan with no assisted parameters needed 249 | * 250 | * @param [in] context Chip implementation context 251 | * @param [in] date The actual date of scan. Its format is the number of seconds elapsed since January the 6th 1980 252 | * 00:00:00 with leap seconds included. 253 | * @param [in] effort_mode Effort mode @ref lr1110_gnss_search_mode_t 254 | * @param [in] gnss_input_parameters Bit mask indicating which information is added in the output payload @ref 255 | * lr1110_gnss_input_parameters_e 256 | * @param [in] nb_sat The expected number of satellite to provide. This value must be in the range [0:128] 257 | * 258 | * @returns Operation status 259 | */ 260 | lr1110_status_t lr1110_gnss_scan_autonomous( const void* context, const lr1110_gnss_date_t date, 261 | const lr1110_gnss_search_mode_t effort_mode, 262 | const uint8_t gnss_input_parameters, const uint8_t nb_sat ); 263 | 264 | /*! 265 | * @brief Gnss scan with assisted parameters. 266 | * 267 | * @param [in] context Chip implementation context 268 | * @param [in] date The actual date of scan. Its format is the number of seconds elapsed since January the 6th 1980 269 | * 00:00:00 with leap seconds included. 270 | * @param [in] effort_mode Effort mode @ref lr1110_gnss_search_mode_t 271 | * @param [in] gnss_input_parameters Bit mask indicating which information is added in the output payload @ref 272 | * lr1110_gnss_input_parameters_e 273 | * @param [in] nb_sat The expected number of satellite to provide. This value must be in the range [0:128] 274 | * 275 | * @returns Operation status 276 | */ 277 | lr1110_status_t lr1110_gnss_scan_assisted( const void* context, const lr1110_gnss_date_t date, 278 | const lr1110_gnss_search_mode_t effort_mode, 279 | const uint8_t gnss_input_parameters, const uint8_t nb_sat ); 280 | 281 | /*! 282 | * @brief Function to set the assistance position. 283 | * 284 | * @param [in] context Chip implementation context 285 | * @param [in] assistance_position, latitude 12 bits and longitude 12 bits 286 | * 287 | * @ref See lr1110_gnss_solver_assistance_position_t 288 | * 289 | * @returns Operation status 290 | */ 291 | lr1110_status_t lr1110_gnss_set_assistance_position( 292 | const void* context, const lr1110_gnss_solver_assistance_position_t* assistance_position ); 293 | 294 | /*! 295 | * @brief Function to read the assistance position. 296 | * 297 | * The assistance position read may be different from the one set beforehand with @ref 298 | * lr1110_gnss_set_assistance_position due to a scaling computation. 299 | * 300 | * @param [in] context Chip implementation context 301 | * @param [in] assistance_position, latitude 12 bits and longitude 12 bits 302 | * 303 | * @ref See lr1110_gnss_solver_assistance_position_t 304 | * 305 | * @returns Operation status 306 | */ 307 | lr1110_status_t lr1110_gnss_read_assistance_position( const void* context, 308 | lr1110_gnss_solver_assistance_position_t* assistance_position ); 309 | 310 | /*! 311 | * @brief Host receives an update from the network or assembles itself the update message and send it to the LR1110. 312 | * 313 | * @param [in] context Chip implementation context 314 | * @param [in] dmc_msg buffer containing the update the network 315 | * @param [in] dmc_msg_len length of this buffer 316 | * 317 | * @returns Operation status 318 | */ 319 | lr1110_status_t lr1110_gnss_push_dmc_msg( const void* context, uint8_t* dmc_msg, uint16_t dmc_msg_len ); 320 | 321 | /*! 322 | * @brief Get the GNSS context status 323 | * 324 | * This function returns the GNSS context status as a raw buffer. It is possible to use 325 | * lr1110_gnss_parse_context_status_buffer to obtain the details of the context status. 326 | * 327 | * @param [in] context Chip implementation context 328 | * @param [out] context_status_buffer Pointer to a buffer to be filled with context status information. Must be at least 329 | * 7 bytes long. It is up to the caller to ensure there is enough place in this buffer. 330 | * 331 | * @returns Operation status 332 | * 333 | * @see lr1110_gnss_parse_context_status_buffer 334 | */ 335 | lr1110_status_t lr1110_gnss_get_context_status( const void* context, 336 | lr1110_gnss_context_status_bytestream_t context_status_buffer ); 337 | 338 | /*! 339 | * @brief Get the number of detected satellites during last scan 340 | * 341 | * @param [in] context Chip implementation context 342 | * @param [out] nb_detected_satellites Number of satellites detected 343 | * 344 | * @returns Operation status 345 | */ 346 | lr1110_status_t lr1110_gnss_get_nb_detected_satellites( const void* context, uint8_t* nb_detected_satellites ); 347 | 348 | /*! 349 | * @brief Get the satellites detected on last scan with their IDs, C/N (aka CNR) and doppler 350 | * 351 | * @note Doppler is returned with 6ppm accuracy. 352 | * 353 | * @param [in] context Chip implementation context 354 | * @param [in] nb_detected_satellites Number of detected satellites on last scan (obtained by calling 355 | * lr1110_gnss_get_nb_detected_satellites) 356 | * @param [out] detected_satellite_id_snr_doppler Pointer to an array of structures of size big enough to contain 357 | * nb_detected_satellites elements 358 | * 359 | * @returns Operation status 360 | */ 361 | lr1110_status_t lr1110_gnss_get_detected_satellites( 362 | const void* context, const uint8_t nb_detected_satellites, 363 | lr1110_gnss_detected_satellite_t* detected_satellite_id_snr_doppler ); 364 | 365 | /** 366 | * @brief Parse a raw buffer of context status 367 | * 368 | * @param [in] context_status_bytestream The raw buffer of context status to parse. It is up to the caller to ensure the 369 | * buffer is at least LR1110_GNSS_CONTEXT_STATUS_LENGTH bytes long 370 | * @param [out] context_status Pointer to a structure of lr1110_gnss_context_status_t to be filled with information from 371 | * context_status_bytestream 372 | * 373 | * @returns Operation status 374 | * 375 | * @see lr1110_gnss_get_context_status 376 | */ 377 | lr1110_status_t lr1110_gnss_parse_context_status_buffer( 378 | const lr1110_gnss_context_status_bytestream_t context_status_bytestream, 379 | lr1110_gnss_context_status_t* context_status ); 380 | 381 | /** 382 | * @brief Extract the destination from the result returned by a GNSS scan 383 | * 384 | * @param [in] result_buffer Pointer to the buffer holding the result 385 | * @param [in] result_buffer_size Size of the result in byte 386 | * @param [out] destination Destination of the result 387 | * 388 | * @returns Operation status 389 | */ 390 | lr1110_status_t lr1110_gnss_get_result_destination( const uint8_t* result_buffer, const uint16_t result_buffer_size, 391 | lr1110_gnss_destination_t* destination ); 392 | 393 | /** 394 | * @brief Helper function that computes the age of an almanac. 395 | * 396 | * This function does not call the LR1110. 397 | * The almanac age is computed based on the following elements: 398 | * - almanac age as obtained from lr1110_gnss_get_almanac_age_for_satellite 399 | * - the number of days elapsed between Epoch (January 6th 1980) and the GPS rollover reference of the current 400 | * almanac 401 | * - the GPS date of today expressed in number of days elapsed since Epoch 402 | * 403 | * @remark It is important to use for nb_days_between_epoch_and_corresponding_gps_time_rollover the GPS time rollover 404 | * corresponding to the reference of the almanac_date. This is especially true when current date is just after a GPS 405 | * time rollover. 406 | * 407 | * @param [in] almanac_date Almanac date as obtained from lr1110_gnss_get_almanac_age_for_satellite 408 | * @param [in] nb_days_between_epoch_and_corresponding_gps_time_rollover Number of days elapsed between GPS Epoch and 409 | * the GPS rollover corresponding to the almanac_date 410 | * @param [in] nb_days_since_epoch Number of days elapsed between January 6th 1980 and now 411 | * 412 | * @returns Age of the almanac expressed in number of days between its start valid instant and now 413 | */ 414 | uint16_t lr1110_gnss_compute_almanac_age( uint16_t almanac_date, 415 | uint16_t nb_days_between_epoch_and_corresponding_gps_time_rollover, 416 | uint16_t nb_days_since_epoch ); 417 | 418 | #ifdef __cplusplus 419 | } 420 | #endif 421 | 422 | #endif // LR1110_GNSS_H 423 | 424 | /* --- EOF ------------------------------------------------------------------ */ 425 | -------------------------------------------------------------------------------- /src/lr1110_gnss_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_gnss_types.h 3 | * 4 | * @brief GNSS scan driver types for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_GNSS_TYPES_H 36 | #define LR1110_GNSS_TYPES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /*! 61 | * @brief Maximal buffer size 62 | */ 63 | #define LR1110_GNSS_MAX_SIZE_ARRAY 2820 //!< (128sv * 22bytes + 4bytes for CRC) 64 | 65 | /*! 66 | * @brief Number of almanacs in full update payload 67 | */ 68 | #define LR1110_GNSS_FULL_UPDATE_N_ALMANACS ( 128 ) 69 | 70 | /*! 71 | * @brief Size of the almanac of a single satellite when reading 72 | */ 73 | #define LR1110_GNSS_SINGLE_ALMANAC_READ_SIZE ( 22 ) 74 | 75 | /*! 76 | * @brief Size of the almanac of a single satellite when writing 77 | */ 78 | #define LR1110_GNSS_SINGLE_ALMANAC_WRITE_SIZE ( 20 ) 79 | 80 | /*! 81 | * @brief Size of the almanac of the GNSS context status buffer 82 | */ 83 | #define LR1110_GNSS_CONTEXT_STATUS_LENGTH ( 9 ) 84 | 85 | /*! 86 | * @brief Size of the whole almanac when reading 87 | */ 88 | #define LR1110_GNSS_FULL_ALMANAC_READ_BUFFER_SIZE \ 89 | ( ( LR1110_GNSS_FULL_UPDATE_N_ALMANACS * LR1110_GNSS_SINGLE_ALMANAC_READ_SIZE ) + 4 ) 90 | 91 | #define LR1110_GNSS_DMC_ALMANAC_UPDATE_POS ( 1U ) 92 | #define LR1110_GNSS_DMC_ALMANAC_UPDATE_GPS_MASK ( 0x01UL << LR1110_GNSS_DMC_ALMANAC_UPDATE_POS ) 93 | #define LR1110_GNSS_DMC_ALMANAC_UPDATE_BEIDOU_MASK ( 0x02UL << LR1110_GNSS_DMC_ALMANAC_UPDATE_POS ) 94 | 95 | #define LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_MSB_POS ( 0U ) 96 | #define LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_MSB_MASK ( 0x01UL << LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_MSB_POS ) 97 | 98 | #define LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_LSB_POS ( 7U ) 99 | #define LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_LSB_MASK ( 0x01UL << LR1110_GNSS_DMC_FREQUENCY_SEARCH_SPACE_LSB_POS ) 100 | 101 | /* 102 | * ----------------------------------------------------------------------------- 103 | * --- PUBLIC TYPES ------------------------------------------------------------ 104 | */ 105 | 106 | /*! 107 | * @brief Satellite ID type 108 | */ 109 | typedef uint8_t lr1110_gnss_satellite_id_t; 110 | 111 | /*! 112 | * @brief Bit mask indicating which information is added in the output payload - to be used with @ref 113 | * LR1110_GNSS_SCAN_MODE_0_SINGLE_SCAN_LEGACY 114 | */ 115 | enum lr1110_gnss_result_fields_legacy_e 116 | { 117 | LR1110_GNSS_RESULTS_LEGACY_PSEUDO_RANGE_MASK = ( 1 << 0 ), //!< Add pseudo-range information if set 118 | LR1110_GNSS_RESULTS_LEGACY_DOPPLER_MASK = ( 1 << 1 ), //!< Add all Doppler information if set - up to 5 if not 119 | LR1110_GNSS_RESULTS_LEGACY_BIT_CHANGE_MASK = ( 1 << 2 ), //!< Add bit change if set 120 | }; 121 | 122 | /*! 123 | * @brief bit mask indicating which information is added in the output payload - to be used with @ref 124 | * LR1110_GNSS_SCAN_MODE_3_SINGLE_SCAN_AND_5_FAST_SCANS 125 | */ 126 | enum lr1110_gnss_result_fields_e 127 | { 128 | LR1110_GNSS_RESULTS_DOPPLER_ENABLE_MASK = ( 1 << 0 ), //!< Add Doppler information if set 129 | LR1110_GNSS_RESULTS_DOPPLER_MASK = ( 1 << 1 ), //!< Add up to 14 Doppler if set - up to 7 if not. Valid if @ref 130 | //!< LR1110_GNSS_RESULTS_DOPPLER_ENABLE_MASK is set 131 | LR1110_GNSS_RESULTS_BIT_CHANGE_MASK = ( 1 << 2 ), //!< Add bit change if set 132 | }; 133 | 134 | /*! 135 | * @brief Constellation identifiers 136 | */ 137 | typedef enum 138 | { 139 | LR1110_GNSS_GPS_MASK = 0x01, 140 | LR1110_GNSS_BEIDOU_MASK = 0x02, 141 | } lr1110_gnss_constellation_t; 142 | 143 | /*! 144 | * @brief Bit mask of constellation configurations 145 | * 146 | * @see lr1110_gnss_constellation_t 147 | */ 148 | typedef uint8_t lr1110_gnss_constellation_mask_t; 149 | 150 | /*! 151 | * @brief Search mode for GNSS scan 152 | */ 153 | typedef enum 154 | { 155 | LR1110_GNSS_OPTION_DEFAULT = 0x00, //!< Search all requested satellites or fail 156 | LR1110_GNSS_OPTION_BEST_EFFORT = 0x01, //!< Add additional search if not all satellites are found 157 | } lr1110_gnss_search_mode_t; 158 | 159 | /*! 160 | * @brief GNSS response type indicates the destination: Host MCU, GNSS solver or GNSS DMC 161 | */ 162 | typedef enum 163 | { 164 | LR1110_GNSS_DESTINATION_HOST = 0x00, //!< Host MCU 165 | LR1110_GNSS_DESTINATION_SOLVER = 0x01, //!< GNSS Solver 166 | LR1110_GNSS_DESTINATION_DMC = 0x02, //!< GNSS DMC 167 | } lr1110_gnss_destination_t; 168 | 169 | /*! 170 | * @brief Message to host indicating the status of the message 171 | */ 172 | typedef enum 173 | { 174 | LR1110_GNSS_HOST_OK = 0x00, 175 | LR1110_GNSS_HOST_UNEXPECTED_CMD = 0x01, 176 | LR1110_GNSS_HOST_UNIMPLEMENTED_CMD = 0x02, 177 | LR1110_GNSS_HOST_INVALID_PARAMETERS = 0x03, 178 | LR1110_GNSS_HOST_MESSAGE_SANITY_CHECK_ERROR = 0x04, 179 | LR1110_GNSS_HOST_IQ_CAPTURE_FAILS = 0x05, 180 | LR1110_GNSS_HOST_NO_TIME = 0x06, 181 | LR1110_GNSS_HOST_NO_SATELLITE_DETECTED = 0x07, 182 | LR1110_GNSS_HOST_ALMANAC_IN_FLASH_TOO_OLD = 0x08, 183 | LR1110_GNSS_HOST_ALMANAC_UPDATE_FAILS_CRC_ERROR = 0x09, 184 | LR1110_GNSS_HOST_ALMANAC_UPDATE_FAILS_FLASH_INTEGRITY_ERROR = 0x0A, 185 | LR1110_GNSS_HOST_ALMANAC_UPDATE_NOT_ALLOWED = 0x0B, 186 | LR1110_GNSS_HOST_ALMANAC_CRC_ERROR = 0x0C, 187 | LR1110_GNSS_HOST_ALMANAC_VERSION_NOT_SUPPORTED = 0x0D, 188 | LR1110_GNSS_HOST_NOT_ENOUGH_SV_DETECTED_TO_BUILD_A_NAV_MESSAGE = 0x10, 189 | } lr1110_gnss_message_host_status_t; 190 | 191 | /*! 192 | * @brief Message to DMC operation code 193 | */ 194 | typedef enum 195 | { 196 | LR1110_GNSS_DMC_STATUS = 0x18, //!< Status message in payload 197 | } lr1110_gnss_message_dmc_opcode_t; 198 | 199 | /*! 200 | * @brief GNSS single or double scan mode 201 | */ 202 | typedef enum 203 | { 204 | LR1110_GNSS_SCAN_MODE_0_SINGLE_SCAN_LEGACY = 0x00, //!< Generated NAV message format = NAV1 205 | LR1110_GNSS_SCAN_MODE_3_SINGLE_SCAN_AND_5_FAST_SCANS = 0x03, //!< Generated NAV message format = NAV2 206 | } lr1110_gnss_scan_mode_t; 207 | 208 | /*! 209 | * @brief GNSS error codes 210 | */ 211 | typedef enum lr1110_gnss_error_code_e 212 | { 213 | LR1110_GNSS_NO_ERROR = 0, 214 | LR1110_GNSS_ERROR_ALMANAC_TOO_OLD = 1, 215 | LR1110_GNSS_ERROR_UPDATE_CRC_MISMATCH = 2, 216 | LR1110_GNSS_ERROR_UPDATE_FLASH_MEMORY_INTEGRITY = 3, 217 | LR1110_GNSS_ERROR_ALMANAC_UPDATE_NOT_ALLOWED = 4, //!< Impossible to update more than one constellation at a time 218 | } lr1110_gnss_error_code_t; 219 | 220 | /*! 221 | * @brief GNSS frequency search space 222 | */ 223 | typedef enum lr1110_gnss_freq_search_space_e 224 | { 225 | LR1110_GNSS_FREQUENCY_SEARCH_SPACE_250_HZ = 0, 226 | LR1110_GNSS_FREQUENCY_SEARCH_SPACE_500_HZ = 1, 227 | LR1110_GNSS_FREQUENCY_SEARCH_SPACE_1_KHZ = 2, 228 | LR1110_GNSS_FREQUENCY_SEARCH_SPACE_2_KHZ = 3, 229 | } lr1110_gnss_freq_search_space_t; 230 | 231 | /*! 232 | * @brief Representation of absolute time for GNSS operations 233 | * 234 | * The GNSS absolute time is represented as a 32 bits word that is the number of seconds elapsed since January 6th 1980, 235 | * 00:00:00 236 | * 237 | * The GNSS absolute time must take into account the Leap Seconds between UTC time and GPS time. 238 | */ 239 | typedef uint32_t lr1110_gnss_date_t; 240 | 241 | /*! 242 | * @brief Buffer that holds data for all almanacs full update - when reading 243 | */ 244 | typedef uint8_t lr1110_gnss_almanac_full_read_bytestream_t[LR1110_GNSS_FULL_ALMANAC_READ_BUFFER_SIZE]; 245 | 246 | /*! 247 | * @brief Buffer that holds data for context status 248 | */ 249 | typedef uint8_t lr1110_gnss_context_status_bytestream_t[LR1110_GNSS_CONTEXT_STATUS_LENGTH]; 250 | 251 | /*! 252 | * @brief Assistance position. 253 | */ 254 | typedef struct lr1110_gnss_solver_assistance_position_s 255 | { 256 | float latitude; //!< Latitude 12 bits (latitude in degree * 2048/90) with resolution 0.044° 257 | float longitude; //!< Longitude 12 bits (longitude in degree * 2048/180) with resolution 0.088° 258 | } lr1110_gnss_solver_assistance_position_t; 259 | 260 | /*! 261 | * @brief Detected SV structure 262 | */ 263 | typedef struct lr1110_gnss_detected_satellite_s 264 | { 265 | lr1110_gnss_satellite_id_t satellite_id; 266 | int8_t cnr; //!< Carrier-to-noise ration (C/N) in dB 267 | int16_t doppler; //!< SV doppler in Hz 268 | } lr1110_gnss_detected_satellite_t; 269 | 270 | /*! 271 | * @brief GNSS timings of the LR1110 272 | */ 273 | typedef struct lr1110_gnss_timings_s 274 | { 275 | uint32_t radio_ms; 276 | uint32_t computation_ms; 277 | } lr1110_gnss_timings_t; 278 | 279 | /*! 280 | * @brief Version structure of the LR1110 GNSS firmware 281 | */ 282 | typedef struct lr1110_gnss_version_s 283 | { 284 | uint8_t gnss_firmware; //!< Version of the firmware 285 | uint8_t gnss_almanac; //!< Version of the almanac format 286 | } lr1110_gnss_version_t; 287 | 288 | /*! 289 | * @brief Structure for GNSS context status 290 | */ 291 | typedef struct lr1110_gnss_context_status_s 292 | { 293 | uint8_t firmware_version; 294 | uint32_t global_almanac_crc; 295 | lr1110_gnss_error_code_t error_code; 296 | bool almanac_update_gps; 297 | bool almanac_update_beidou; 298 | lr1110_gnss_freq_search_space_t freq_search_space; 299 | } lr1110_gnss_context_status_t; 300 | 301 | /* 302 | * ----------------------------------------------------------------------------- 303 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 304 | */ 305 | 306 | #ifdef __cplusplus 307 | } 308 | #endif 309 | 310 | #endif // LR1110_GNSS_TYPES_H 311 | 312 | /* --- EOF ------------------------------------------------------------------ */ 313 | -------------------------------------------------------------------------------- /src/lr1110_hal.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_hal.h 3 | * 4 | * @brief Hardware Abstraction Layer (HAL) interface for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_HAL_H 36 | #define LR1110_HAL_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /** 61 | * @brief Write this to SPI bus while reading data, or as a dummy/placeholder 62 | */ 63 | #define LR1110_NOP ( 0x00 ) 64 | 65 | /* 66 | * ----------------------------------------------------------------------------- 67 | * --- PUBLIC TYPES ------------------------------------------------------------ 68 | */ 69 | 70 | /*! 71 | * @brief LR1110 HAL status 72 | */ 73 | typedef enum lr1110_hal_status_e 74 | { 75 | LR1110_HAL_STATUS_OK = 0, 76 | LR1110_HAL_STATUS_ERROR = 3, 77 | } lr1110_hal_status_t; 78 | 79 | /* 80 | * ----------------------------------------------------------------------------- 81 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 82 | */ 83 | 84 | /*! 85 | * @brief Radio data transfer - write 86 | * 87 | * @param [in] context Radio implementation parameters 88 | * @param [in] command Pointer to the buffer to be transmitted 89 | * @param [in] command_length Buffer size to be transmitted 90 | * @param [in] data Pointer to the buffer to be transmitted 91 | * @param [in] data_length Buffer size to be transmitted 92 | * 93 | * @returns Operation status 94 | */ 95 | lr1110_hal_status_t lr1110_hal_write( const void* context, const uint8_t* command, const uint16_t command_length, 96 | const uint8_t* data, const uint16_t data_length ); 97 | 98 | /*! 99 | * @brief Radio data transfer - read 100 | * 101 | * @remark This is a two-step radio read operation. It consists of writing the command, releasing then re-asserting the 102 | * NSS line, then reading a discarded dummy byte followed by data_length bytes of response data from the transceiver. 103 | * While reading the dummy bytes and the response data, the implementation of this function must ensure that only zero 104 | * bytes (NOP) are written to the SPI bus. 105 | * 106 | * @param [in] context Radio implementation parameters 107 | * @param [in] command Pointer to the buffer to be transmitted 108 | * @param [in] command_length Buffer size to be transmitted 109 | * @param [out] data Pointer to the buffer to be received 110 | * @param [in] data_length Buffer size to be received 111 | * 112 | * @returns Operation status 113 | * 114 | * @remark Some hardware SPI implementations write arbitary values on the MOSI line while reading. If this is done on 115 | * the LR1110, non-zero values may be interpreted as commands. This driver does not exploit this functionality, and 116 | * expects that zeros be sent on the MOSI line when this command is reading the command response data. 117 | */ 118 | lr1110_hal_status_t lr1110_hal_read( const void* context, const uint8_t* command, const uint16_t command_length, 119 | uint8_t* data, const uint16_t data_length ); 120 | 121 | /*! 122 | * @brief Direct read from the SPI bus 123 | * 124 | * @remark Unlike @ref lr1110_hal_read, this is a simple direct SPI bus SS/read/nSS operation. While reading the 125 | * response data, the implementation of this function must ensure that only zero bytes (NOP) are written to the SPI bus. 126 | * 127 | * @remark Formerly, that function depended on a lr1110_hal_write_read API function, which required bidirectional SPI 128 | * communication. Given that all other radio functionality can be implemented with unidirectional SPI, it has been 129 | * decided to make this HAL API change to simplify implementation requirements. 130 | * 131 | * @remark Only required by the @ref lr1110_system_get_status and @ref lr1110_bootloader_get_status commands 132 | * 133 | * @param [in] context Radio implementation parameters 134 | * @param [out] data Pointer to the buffer to be received 135 | * @param [in] data_length Buffer size to be received 136 | * 137 | * @returns Operation status 138 | */ 139 | lr1110_hal_status_t lr1110_hal_direct_read( const void* context, uint8_t* data, const uint16_t data_length ); 140 | 141 | /*! 142 | * @brief Reset the radio 143 | * 144 | * @param [in] context Radio implementation parameters 145 | * 146 | * @returns Operation status 147 | */ 148 | lr1110_hal_status_t lr1110_hal_reset( const void* context ); 149 | 150 | /*! 151 | * @brief Wake the radio up. 152 | * 153 | * @param [in] context Radio implementation parameters 154 | * 155 | * @returns Operation status 156 | */ 157 | lr1110_hal_status_t lr1110_hal_wakeup( const void* context ); 158 | 159 | /*! 160 | * @brief Return the computed CRC 161 | * 162 | * @param [in] initial_value initial value of the CRC 163 | * @param [in] buffer Buffer containing data used to compute the CRC 164 | * @param [in] length Length of buffer 165 | * 166 | * @returns CRC value 167 | */ 168 | inline static uint8_t lr1110_hal_compute_crc( const uint8_t initial_value, const uint8_t* buffer, uint16_t length ) 169 | { 170 | uint8_t crc = initial_value; 171 | 172 | for( uint16_t i = 0; i < length; i++ ) 173 | { 174 | uint8_t extract = buffer[i]; 175 | uint8_t sum; 176 | 177 | for( uint8_t j = 8; j > 0; j-- ) 178 | { 179 | sum = ( crc ^ extract ) & 0x01; 180 | crc >>= 1; 181 | 182 | if( sum != 0 ) 183 | { 184 | crc ^= 0x65; 185 | } 186 | 187 | extract >>= 1; 188 | } 189 | } 190 | 191 | return crc; 192 | } 193 | 194 | #ifdef __cplusplus 195 | } 196 | #endif 197 | 198 | #endif // LR1110_HAL_H 199 | -------------------------------------------------------------------------------- /src/lr1110_lr_fhss.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_lr_fhss.c 3 | * 4 | * @brief LR_FHSS driver implementation for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * ----------------------------------------------------------------------------- 37 | * --- DEPENDENCIES ------------------------------------------------------------ 38 | */ 39 | 40 | #include "lr1110_lr_fhss.h" 41 | #include "lr1110_radio.h" 42 | #include "lr1110_hal.h" 43 | 44 | /* 45 | * ----------------------------------------------------------------------------- 46 | * --- PRIVATE MACROS----------------------------------------------------------- 47 | */ 48 | 49 | #define LR1110_LR_FHSS_PKT_TYPE_LR_FHSS ( 0x04 ) 50 | #define LR_FHSS_BITRATE_IN_256_BPS_STEPS ( 125000 ) 51 | #define LR1110_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH ( 2 + 5 ) 52 | #define LR1110_LR_FHSS_BUILD_FRAME_LENGTH ( 2 + 9 ) 53 | #define LR1110_LR_FHSS_SET_SYNC_WORD_LENGTH ( 2 + 0 ) 54 | #define LR1110_LR_FHSS_SET_MODULATION_PARAM_DIVIDE_BITRATE_BY_256 ( 0x80000000 ) 55 | #define LR1110_LR_FHSS_HEADER_BITS ( 114 ) 56 | #define LR1110_LR_FHSS_FRAG_BITS ( 48 ) 57 | #define LR1110_LR_FHSS_BLOCK_PREAMBLE_BITS ( 2 ) 58 | #define LR1110_LR_FHSS_BLOCK_BITS ( LR1110_LR_FHSS_FRAG_BITS + LR1110_LR_FHSS_BLOCK_PREAMBLE_BITS ) 59 | #define LR1110_LR_FHSS_SYNCWORD_LENGTH ( 4 ) 60 | 61 | /* 62 | * ----------------------------------------------------------------------------- 63 | * --- PRIVATE CONSTANTS ------------------------------------------------------- 64 | */ 65 | 66 | /* 67 | * ----------------------------------------------------------------------------- 68 | * --- PRIVATE TYPES ----------------------------------------------------------- 69 | */ 70 | 71 | /*! 72 | * @brief Operating codes for radio-related operations 73 | */ 74 | enum 75 | { 76 | LR1110_LR_FHSS_SET_MODULATION_PARAM_OC = 0x020F, 77 | LR1110_LR_FHSS_BUILD_FRAME_OC = 0x022C, 78 | LR1110_LR_FHSS_SET_SYNC_WORD_OC = 0x022D, 79 | }; 80 | 81 | /*! 82 | * @brief Hopping enable/disabled enumerations for \ref lr1110_lr_fhss_build_frame 83 | */ 84 | typedef enum 85 | { 86 | LR1110_LR_FHSS_HOPPING_DISABLE = 0x00, 87 | LR1110_LR_FHSS_HOPPING_ENABLE = 0x01, 88 | } lr1110_lr_fhss_hopping_configuration_t; 89 | 90 | /*! 91 | * @brief Pulse shape configurations 92 | */ 93 | typedef enum 94 | { 95 | LR1110_LR_FHSS_PULSE_SHAPE_BT_1 = 0x0B //!< Gaussian BT 1.0 96 | } lr1110_lr_fhss_pulse_shape_t; 97 | 98 | /*! 99 | * @brief Modulation configuration for LR_FHSS packets 100 | */ 101 | typedef struct lr1110_lr_fhss_mod_params_lr_fhss_s 102 | { 103 | uint32_t br_in_bps; //!< LR_FHSS bitrate [bit/s] 104 | lr1110_lr_fhss_pulse_shape_t pulse_shape; //!< LR_FHSS pulse shape 105 | } lr1110_lr_fhss_mod_params_lr_fhss_t; 106 | 107 | /* 108 | * ----------------------------------------------------------------------------- 109 | * --- PRIVATE VARIABLES ------------------------------------------------------- 110 | */ 111 | 112 | /* 113 | * ----------------------------------------------------------------------------- 114 | * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- 115 | */ 116 | 117 | /*! 118 | * @brief Set the modulation parameters for LR_FHSS 119 | * 120 | * The command @ref lr1110_lr_fhss_set_pkt_type must be called prior this one. 121 | * 122 | * @param [in] context Chip implementation context 123 | * @param [in] mod_params The structure of modulation configuration 124 | * 125 | * @returns Operation status 126 | * 127 | * @see lr1110_lr_fhss_set_pkt_type 128 | */ 129 | static lr1110_status_t lr1110_lr_fhss_set_lr_fhss_mod_params( const void* context, 130 | const lr1110_lr_fhss_mod_params_lr_fhss_t* mod_params ); 131 | 132 | /*! 133 | * @brief Set the syncword for LR_FHSS 134 | * 135 | * Default value: 0x2C0F7995 136 | * 137 | * @param [in] context Chip implementation context 138 | * @param [in] sync_word The syncword to set. It is up to the caller to ensure this array is at least four bytes long 139 | * 140 | * @returns Operation status 141 | */ 142 | static lr1110_status_t lr1110_lr_fhss_set_sync_word( const void* context, 143 | const uint8_t sync_word[LR1110_LR_FHSS_SYNCWORD_LENGTH] ); 144 | 145 | /*! 146 | * @brief Get the bit count and block count for a LR-FHSS frame 147 | * 148 | * @param [in] params Parameter structure 149 | * @param [in] payload_length Length of physical payload, in bytes 150 | * 151 | * @returns Length of physical payload, in bits 152 | */ 153 | 154 | static uint16_t lr1110_lr_fhss_get_nb_bits( const lr_fhss_v1_params_t* params, uint16_t payload_length ); 155 | 156 | /* 157 | * ----------------------------------------------------------------------------- 158 | * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- 159 | */ 160 | 161 | lr1110_status_t lr1110_lr_fhss_init( const void* context ) 162 | { 163 | const lr1110_status_t set_packet_type_status = 164 | lr1110_radio_set_pkt_type( context, LR1110_LR_FHSS_PKT_TYPE_LR_FHSS ); 165 | if( set_packet_type_status != LR1110_STATUS_OK ) 166 | { 167 | return set_packet_type_status; 168 | } 169 | 170 | const lr1110_lr_fhss_mod_params_lr_fhss_t mod_lr_fhss = { 171 | .br_in_bps = LR1110_LR_FHSS_SET_MODULATION_PARAM_DIVIDE_BITRATE_BY_256 + LR_FHSS_BITRATE_IN_256_BPS_STEPS, 172 | .pulse_shape = LR1110_LR_FHSS_PULSE_SHAPE_BT_1 173 | }; 174 | 175 | const lr1110_status_t set_modulation_param_status = lr1110_lr_fhss_set_lr_fhss_mod_params( context, &mod_lr_fhss ); 176 | return set_modulation_param_status; 177 | } 178 | 179 | lr1110_status_t lr1110_lr_fhss_build_frame( const void* context, const lr1110_lr_fhss_params_t* lr_fhss_params, 180 | uint16_t hop_sequence_id, const uint8_t* payload, uint8_t payload_length ) 181 | { 182 | // Since the build_frame command is last, it is possible to check status through stat1 183 | 184 | lr1110_status_t status = lr1110_lr_fhss_set_sync_word( context, lr_fhss_params->lr_fhss_params.sync_word ); 185 | if( status != LR1110_STATUS_OK ) 186 | { 187 | return status; 188 | } 189 | 190 | const uint8_t cbuffer[LR1110_LR_FHSS_BUILD_FRAME_LENGTH] = { 191 | ( uint8_t )( LR1110_LR_FHSS_BUILD_FRAME_OC >> 8 ), 192 | ( uint8_t )( LR1110_LR_FHSS_BUILD_FRAME_OC >> 0 ), 193 | ( uint8_t ) lr_fhss_params->lr_fhss_params.header_count, 194 | ( uint8_t ) lr_fhss_params->lr_fhss_params.cr, 195 | ( uint8_t ) lr_fhss_params->lr_fhss_params.modulation_type, 196 | ( uint8_t ) lr_fhss_params->lr_fhss_params.grid, 197 | ( uint8_t )( lr_fhss_params->lr_fhss_params.enable_hopping ? LR1110_LR_FHSS_HOPPING_ENABLE 198 | : LR1110_LR_FHSS_HOPPING_DISABLE ), 199 | ( uint8_t ) lr_fhss_params->lr_fhss_params.bw, 200 | ( uint8_t )( hop_sequence_id >> 8 ), 201 | ( uint8_t )( hop_sequence_id >> 0 ), 202 | ( uint8_t ) lr_fhss_params->device_offset, 203 | }; 204 | 205 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_LR_FHSS_BUILD_FRAME_LENGTH, payload, 206 | payload_length ); 207 | } 208 | 209 | uint32_t lr1110_lr_fhss_get_time_on_air_in_ms( const lr1110_lr_fhss_params_t* params, uint16_t payload_length ) 210 | { 211 | // Multiply by 1000 / 488.28125, or equivalently 256/125, rounding up 212 | return ( ( lr1110_lr_fhss_get_nb_bits( ¶ms->lr_fhss_params, payload_length ) << 8 ) + 124 ) / 125; 213 | } 214 | 215 | unsigned int lr1110_lr_fhss_get_hop_sequence_count( const lr1110_lr_fhss_params_t* lr_fhss_params ) 216 | { 217 | if( ( lr_fhss_params->lr_fhss_params.grid == LR_FHSS_V1_GRID_25391_HZ ) || 218 | ( ( lr_fhss_params->lr_fhss_params.grid == LR_FHSS_V1_GRID_3906_HZ ) && 219 | ( lr_fhss_params->lr_fhss_params.bw < LR_FHSS_V1_BW_335938_HZ ) ) ) 220 | { 221 | return 384; 222 | } 223 | return 512; 224 | } 225 | 226 | /* 227 | * ----------------------------------------------------------------------------- 228 | * --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------- 229 | */ 230 | 231 | lr1110_status_t lr1110_lr_fhss_set_lr_fhss_mod_params( const void* radio, 232 | const lr1110_lr_fhss_mod_params_lr_fhss_t* mod_params ) 233 | { 234 | const uint8_t cbuffer[LR1110_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH] = { 235 | ( uint8_t )( LR1110_LR_FHSS_SET_MODULATION_PARAM_OC >> 8 ), 236 | ( uint8_t )( LR1110_LR_FHSS_SET_MODULATION_PARAM_OC >> 0 ), 237 | ( uint8_t )( mod_params->br_in_bps >> 24 ), 238 | ( uint8_t )( mod_params->br_in_bps >> 16 ), 239 | ( uint8_t )( mod_params->br_in_bps >> 8 ), 240 | ( uint8_t )( mod_params->br_in_bps >> 0 ), 241 | ( uint8_t ) mod_params->pulse_shape, 242 | }; 243 | 244 | return ( lr1110_status_t ) lr1110_hal_write( radio, cbuffer, 245 | LR1110_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH, 0, 0 ); 246 | } 247 | 248 | lr1110_status_t lr1110_lr_fhss_set_sync_word( const void* context, 249 | const uint8_t sync_word[LR1110_LR_FHSS_SYNCWORD_LENGTH] ) 250 | { 251 | const uint8_t cbuffer[LR1110_LR_FHSS_SET_SYNC_WORD_LENGTH] = { 252 | ( uint8_t )( LR1110_LR_FHSS_SET_SYNC_WORD_OC >> 8 ), 253 | ( uint8_t )( LR1110_LR_FHSS_SET_SYNC_WORD_OC >> 0 ), 254 | }; 255 | 256 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_LR_FHSS_SET_SYNC_WORD_LENGTH, sync_word, 257 | LR1110_LR_FHSS_SYNCWORD_LENGTH ); 258 | } 259 | 260 | uint16_t lr1110_lr_fhss_get_nb_bits( const lr_fhss_v1_params_t* params, uint16_t payload_length ) 261 | { 262 | uint16_t length_bits = ( payload_length + 2 ) * 8 + 6; 263 | switch( params->cr ) 264 | { 265 | case LR_FHSS_V1_CR_5_6: 266 | length_bits = ( ( length_bits * 6 ) + 4 ) / 5; 267 | break; 268 | 269 | case LR_FHSS_V1_CR_2_3: 270 | length_bits = length_bits * 3 / 2; 271 | break; 272 | 273 | case LR_FHSS_V1_CR_1_2: 274 | length_bits = length_bits * 2; 275 | break; 276 | 277 | case LR_FHSS_V1_CR_1_3: 278 | length_bits = length_bits * 3; 279 | break; 280 | } 281 | 282 | uint16_t payload_bits = ( length_bits / LR1110_LR_FHSS_FRAG_BITS ) * LR1110_LR_FHSS_BLOCK_BITS; 283 | uint16_t last_block_bits = length_bits % LR1110_LR_FHSS_FRAG_BITS; 284 | if( last_block_bits > 0 ) 285 | { 286 | payload_bits += last_block_bits + 2; 287 | } 288 | 289 | return LR1110_LR_FHSS_HEADER_BITS * params->header_count + payload_bits; 290 | } -------------------------------------------------------------------------------- /src/lr1110_lr_fhss.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_lr_fhss.h 3 | * 4 | * @brief LR_FHSS driver definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_LR_FHSS_H 36 | #define LR1110_LR_FHSS_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include "lr1110_lr_fhss_types.h" 48 | #include "lr1110_types.h" 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /** 61 | * @brief Length, in bytes, of a LR-FHSS sync word 62 | */ 63 | #define LR_FHSS_SYNC_WORD_BYTES ( 4 ) 64 | 65 | /* 66 | * ----------------------------------------------------------------------------- 67 | * --- PUBLIC TYPES ------------------------------------------------------------ 68 | */ 69 | 70 | /* 71 | * ----------------------------------------------------------------------------- 72 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 73 | */ 74 | 75 | /*! 76 | * @brief Initialize the LR_FHSS 77 | * 78 | * @param [in] context Chip implementation context 79 | * 80 | * @returns Operation status 81 | */ 82 | lr1110_status_t lr1110_lr_fhss_init( const void* context ); 83 | 84 | /*! 85 | * @brief Configure a payload to be sent with LR_FHSS 86 | * 87 | * When calling this method, lr1110_lr_fhss_set_sync_word is implicitely called to configure the sync word. 88 | * Note that the syncword must be 4 bytes long. 89 | * 90 | * @param [in] context Chip implementation context 91 | * @param [in] lr_fhss_params Parameter configuration structure of the LRFHSS 92 | * @param [in] hop_sequence_id Seed used to derive the hopping sequence pattern. Only the nine LSBs are taken into 93 | * account 94 | * @param [in] payload The payload to send. It is the responsibility of the caller to ensure that this references an 95 | * array containing at least payload_length elements 96 | * @param [in] payload_length The length of the payload 97 | * 98 | * @returns Operation status 99 | */ 100 | lr1110_status_t lr1110_lr_fhss_build_frame( const void* context, const lr1110_lr_fhss_params_t* lr_fhss_params, 101 | uint16_t hop_sequence_id, const uint8_t* payload, uint8_t payload_length ); 102 | 103 | /*! 104 | * @brief Get the time on air in ms for LR-FHSS transmission 105 | * 106 | * @param [in] params LR1110 LR-FHSS parameter structure 107 | * @param [in] payload_length Length of application-layer payload 108 | * 109 | * @returns Time-on-air value in ms for LR-FHSS transmission 110 | */ 111 | uint32_t lr1110_lr_fhss_get_time_on_air_in_ms( const lr1110_lr_fhss_params_t* params, uint16_t payload_length ); 112 | 113 | /** 114 | * @brief Return the number of hop sequences available using the given parameters 115 | * 116 | * @param [in] lr_fhss_params Parameter configuration structure of the LRFHSS 117 | * 118 | * @return Returns the number of valid hop sequences (512 or 384) 119 | */ 120 | unsigned int lr1110_lr_fhss_get_hop_sequence_count( const lr1110_lr_fhss_params_t* lr_fhss_params ); 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif // LR1110_LR_FHSS_H 127 | 128 | /* --- EOF ------------------------------------------------------------------ */ 129 | -------------------------------------------------------------------------------- /src/lr1110_lr_fhss_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_lr_fhss_types.h 3 | * 4 | * @brief LR_FHSS types definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_LR_FHSS_TYPES_H 36 | #define LR1110_LR_FHSS_TYPES_H 37 | 38 | /* 39 | * ----------------------------------------------------------------------------- 40 | * --- DEPENDENCIES ------------------------------------------------------------ 41 | */ 42 | 43 | #include "lr_fhss_v1_base_types.h" 44 | 45 | /* 46 | * ----------------------------------------------------------------------------- 47 | * --- PUBLIC TYPES ------------------------------------------------------------ 48 | */ 49 | 50 | /*! 51 | * @brief LR FHSS parameter structure 52 | */ 53 | typedef struct 54 | { 55 | lr_fhss_v1_params_t lr_fhss_params; //!< Base LR FHSS parameters 56 | int8_t device_offset; //bw ) + 116 | 2 * lr1110_radio_timings_get_lora_symb_time_in_us( mod_params->sf, mod_params->bw ) + 117 | RX_DONE_IRQ_PROCESSING_TIME_IN_US; 118 | } 119 | 120 | uint32_t lr1110_radio_timings_get_delay_between_last_bit_sent_and_tx_done_in_us( 121 | const lr1110_radio_ramp_time_t ramp_time ) 122 | { 123 | return lr1110_radio_timings_get_pa_ramp_time_in_us( ramp_time ) + TX_DONE_IRQ_PROCESSING_TIME_IN_US; 124 | } 125 | 126 | /* 127 | * ----------------------------------------------------------------------------- 128 | * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- 129 | */ 130 | 131 | static uint32_t lr1110_radio_timings_get_pa_ramp_time_in_us( const lr1110_radio_ramp_time_t ramp_time ) 132 | { 133 | switch( ramp_time ) 134 | { 135 | case LR1110_RADIO_RAMP_16_US: 136 | { 137 | return 16; 138 | } 139 | case LR1110_RADIO_RAMP_32_US: 140 | { 141 | return 32; 142 | } 143 | case LR1110_RADIO_RAMP_48_US: 144 | { 145 | return 48; 146 | } 147 | case LR1110_RADIO_RAMP_64_US: 148 | { 149 | return 64; 150 | } 151 | case LR1110_RADIO_RAMP_80_US: 152 | { 153 | return 80; 154 | } 155 | case LR1110_RADIO_RAMP_96_US: 156 | { 157 | return 96; 158 | } 159 | case LR1110_RADIO_RAMP_112_US: 160 | { 161 | return 112; 162 | } 163 | case LR1110_RADIO_RAMP_128_US: 164 | { 165 | return 128; 166 | } 167 | case LR1110_RADIO_RAMP_144_US: 168 | { 169 | return 144; 170 | } 171 | case LR1110_RADIO_RAMP_160_US: 172 | { 173 | return 160; 174 | } 175 | case LR1110_RADIO_RAMP_176_US: 176 | { 177 | return 176; 178 | } 179 | case LR1110_RADIO_RAMP_192_US: 180 | { 181 | return 192; 182 | } 183 | case LR1110_RADIO_RAMP_208_US: 184 | { 185 | return 208; 186 | } 187 | case LR1110_RADIO_RAMP_240_US: 188 | { 189 | return 240; 190 | } 191 | case LR1110_RADIO_RAMP_272_US: 192 | { 193 | return 272; 194 | } 195 | case LR1110_RADIO_RAMP_304_US: 196 | { 197 | return 304; 198 | } 199 | default: 200 | return 0; 201 | } 202 | } 203 | 204 | static uint32_t lr1110_radio_timings_get_lora_rx_input_delay_in_us( lr1110_radio_lora_bw_t bw ) 205 | { 206 | switch( bw ) 207 | { 208 | case LR1110_RADIO_LORA_BW_500: 209 | { 210 | return 16; 211 | } 212 | case LR1110_RADIO_LORA_BW_250: 213 | { 214 | return 31; 215 | } 216 | case LR1110_RADIO_LORA_BW_125: 217 | { 218 | return 57; 219 | } 220 | default: 221 | { 222 | return 0; 223 | } 224 | } 225 | } 226 | 227 | static uint32_t lr1110_radio_timings_get_lora_symb_time_in_us( const lr1110_radio_lora_sf_t sf, 228 | const lr1110_radio_lora_bw_t bw ) 229 | { 230 | return ( 1 << ( uint8_t ) sf ) * 1000000 / lr1110_radio_get_lora_bw_in_hz( bw ); 231 | } 232 | 233 | /* --- EOF ------------------------------------------------------------------ */ 234 | -------------------------------------------------------------------------------- /src/lr1110_radio_timings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lr1110_radio_timings.h 3 | * 4 | * @brief LR1110 timing helper functions definition 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_RADIO_TIMINGS_H 36 | #define LR1110_RADIO_TIMINGS_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include "lr1110_radio_types.h" 48 | 49 | /* 50 | * ----------------------------------------------------------------------------- 51 | * --- PUBLIC MACROS ----------------------------------------------------------- 52 | */ 53 | 54 | /* 55 | * ----------------------------------------------------------------------------- 56 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 57 | */ 58 | 59 | /* 60 | * ----------------------------------------------------------------------------- 61 | * --- PUBLIC TYPES ------------------------------------------------------------ 62 | */ 63 | 64 | /* 65 | * ----------------------------------------------------------------------------- 66 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 67 | */ 68 | 69 | /** 70 | * @brief Get the time between the last bit sent (on Tx side) and the Rx done event (on Rx side) 71 | * 72 | * @param [in] mod_params Pointer to a structure holding the LoRa modulation parameters used for the computation 73 | * 74 | * @returns Delay in microsecond 75 | */ 76 | uint32_t lr1110_radio_timings_get_delay_between_last_bit_sent_and_rx_done_in_us( 77 | const lr1110_radio_mod_params_lora_t* mod_params ); 78 | 79 | /** 80 | * @brief Get the time between the last bit sent and the Tx done event 81 | * 82 | * @param [in] ramp_time Power amplifier ramp time 83 | * 84 | * @returns Delay in microsecond 85 | */ 86 | uint32_t lr1110_radio_timings_get_delay_between_last_bit_sent_and_tx_done_in_us( 87 | const lr1110_radio_ramp_time_t ramp_time ); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif // LR1110_RADIO_TIMINGS_H 94 | 95 | /* --- EOF ------------------------------------------------------------------ */ 96 | -------------------------------------------------------------------------------- /src/lr1110_regmem.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_regmem.c 3 | * 4 | * @brief Register/memory driver implementation for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * ----------------------------------------------------------------------------- 37 | * --- DEPENDENCIES ------------------------------------------------------------ 38 | */ 39 | 40 | #include "lr1110_regmem.h" 41 | #include "lr1110_hal.h" 42 | 43 | /* 44 | * ----------------------------------------------------------------------------- 45 | * --- PRIVATE MACROS----------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | * ----------------------------------------------------------------------------- 50 | * --- PRIVATE CONSTANTS ------------------------------------------------------- 51 | */ 52 | 53 | #define LR1110_REGMEM_CLEAR_RXBUFFER_CMD_LENGTH 2 54 | #define LR1110_REGMEM_WRITE_REGMEM32_CMD_LENGTH ( 2 + 4 ) 55 | #define LR1110_REGMEM_READ_REGMEM32_CMD_LENGTH ( 2 + 4 + 1 ) 56 | #define LR1110_REGMEM_WRITE_MEM8_CMD_LENGTH ( 2 + 4 ) 57 | #define LR1110_REGMEM_READ_MEM8_CMD_LENGTH ( 2 + 4 + 1 ) 58 | #define LR1110_REGMEM_WRITE_BUFFER8_CMD_LENGTH ( 2 ) 59 | #define LR1110_REGMEM_READ_BUFFER8_CMD_LENGTH ( 2 + 2 ) 60 | #define LR1110_REGMEM_WRITE_REGMEM32_MASK_CMD_LENGTH ( 2 + 4 + 4 + 4 ) 61 | 62 | #define LR1110_REGMEM_BUFFER_SIZE_MAX ( 256 ) 63 | 64 | /* 65 | * ----------------------------------------------------------------------------- 66 | * --- PRIVATE TYPES ----------------------------------------------------------- 67 | */ 68 | 69 | /*! 70 | * @brief Operating codes for register and memory related operations 71 | */ 72 | enum 73 | { 74 | LR1110_REGMEM_WRITE_REGMEM32_OC = 0x0105, 75 | LR1110_REGMEM_READ_REGMEM32_OC = 0x0106, 76 | LR1110_REGMEM_WRITE_MEM8_OC = 0x0107, 77 | LR1110_REGMEM_READ_MEM8_OC = 0x0108, 78 | LR1110_REGMEM_WRITE_BUFFER8_OC = 0x0109, 79 | LR1110_REGMEM_READ_BUFFER8_OC = 0x010A, 80 | LR1110_REGMEM_CLEAR_RXBUFFER_OC = 0x010B, 81 | LR1110_REGMEM_WRITE_REGMEM32_MASK_OC = 0x010C, 82 | }; 83 | 84 | /* 85 | * ----------------------------------------------------------------------------- 86 | * --- PRIVATE VARIABLES ------------------------------------------------------- 87 | */ 88 | 89 | /* 90 | * ----------------------------------------------------------------------------- 91 | * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- 92 | */ 93 | 94 | /*! 95 | * @brief Helper function that fill both cbuffer with opcode and memory address 96 | * 97 | * It is typically used in read/write regmem32 functions. 98 | * 99 | * @warning It is up to the caller to ensure cbuffer is big enough to contain opcode and address! 100 | */ 101 | static void lr1110_regmem_fill_cbuffer_opcode_address( uint8_t* cbuffer, uint16_t opcode, uint32_t address ); 102 | 103 | /*! 104 | * @brief Helper function that fill both cbuffer with opcode memory address, and data length to read 105 | * 106 | * It is typically used in read functions. 107 | * 108 | * @warning It is up to the caller to ensure cbuffer is big enough to contain opcode and address! 109 | */ 110 | static void lr1110_regmem_fill_cbuffer_opcode_address_length( uint8_t* cbuffer, uint16_t opcode, uint32_t address, 111 | uint8_t length ); 112 | 113 | /*! 114 | * @brief Helper function that fill both cbuffer with data 115 | * 116 | * It is typically used in write write regmem32 functions. 117 | * 118 | * @warning It is up to the caller to ensure cdata is big enough to contain all data! 119 | */ 120 | static void lr1110_regmem_fill_cdata( uint8_t* cdata, const uint32_t* data, uint8_t data_length ); 121 | 122 | /*! 123 | * @brief Helper function that fill both cbuffer and cdata buffers with opcode, memory address and data 124 | * 125 | * It is typically used to factorize and write regmem32 operations. Behind the scene it calls the other helpers 126 | * lr1110_regmem_fill_cbuffer_opcode_address and lr1110_regmem_fill_cdata. 127 | * 128 | * @warning It is up to the caller to ensure cbuffer and cdata are big enough to contain their respective information! 129 | */ 130 | static void lr1110_regmem_fill_cbuffer_cdata_opcode_address_data( uint8_t* cbuffer, uint8_t* cdata, uint16_t opcode, 131 | uint32_t address, const uint32_t* data, 132 | uint8_t data_length ); 133 | 134 | /*! 135 | * @brief Helper function that convert an array of uint8_t into an array of uint32_t 136 | * 137 | * Typically used in the read function returning uint32_t array. 138 | * 139 | * @warning It is up to the caller to ensure the raw_buffer is of length at least "out_buffer_length * 140 | * sizeof(uint32_t)"! 141 | */ 142 | static void lr1110_regmem_fill_out_buffer_from_raw_buffer( uint32_t* out_buffer, const uint8_t* raw_buffer, 143 | uint8_t out_buffer_length ); 144 | 145 | /* 146 | * ----------------------------------------------------------------------------- 147 | * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- 148 | */ 149 | 150 | lr1110_status_t lr1110_regmem_write_regmem32( const void* context, const uint32_t address, const uint32_t* buffer, 151 | const uint8_t length ) 152 | { 153 | uint8_t cbuffer[LR1110_REGMEM_WRITE_REGMEM32_CMD_LENGTH]; 154 | uint8_t cdata[LR1110_REGMEM_BUFFER_SIZE_MAX]; 155 | 156 | lr1110_regmem_fill_cbuffer_cdata_opcode_address_data( cbuffer, cdata, LR1110_REGMEM_WRITE_REGMEM32_OC, address, 157 | buffer, length ); 158 | 159 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_REGMEM_WRITE_REGMEM32_CMD_LENGTH, cdata, 160 | length * sizeof( uint32_t ) ); 161 | } 162 | 163 | lr1110_status_t lr1110_regmem_read_regmem32( const void* context, const uint32_t address, uint32_t* buffer, 164 | const uint8_t length ) 165 | { 166 | uint8_t cbuffer[LR1110_REGMEM_READ_REGMEM32_CMD_LENGTH]; 167 | lr1110_status_t status = LR1110_STATUS_ERROR; 168 | 169 | lr1110_regmem_fill_cbuffer_opcode_address_length( cbuffer, LR1110_REGMEM_READ_REGMEM32_OC, address, length ); 170 | 171 | status = ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_REGMEM_READ_REGMEM32_CMD_LENGTH, 172 | ( uint8_t* ) buffer, length * sizeof( uint32_t ) ); 173 | 174 | if( status == LR1110_STATUS_OK ) 175 | { 176 | lr1110_regmem_fill_out_buffer_from_raw_buffer( buffer, ( const uint8_t* ) buffer, length ); 177 | } 178 | 179 | return status; 180 | } 181 | 182 | lr1110_status_t lr1110_regmem_write_mem8( const void* context, const uint32_t address, const uint8_t* buffer, 183 | const uint8_t length ) 184 | { 185 | uint8_t cbuffer[LR1110_REGMEM_WRITE_MEM8_CMD_LENGTH]; 186 | 187 | lr1110_regmem_fill_cbuffer_opcode_address( cbuffer, LR1110_REGMEM_WRITE_MEM8_OC, address ); 188 | 189 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_REGMEM_WRITE_MEM8_CMD_LENGTH, buffer, 190 | length ); 191 | } 192 | 193 | lr1110_status_t lr1110_regmem_read_mem8( const void* context, const uint32_t address, uint8_t* buffer, 194 | const uint8_t length ) 195 | { 196 | uint8_t cbuffer[LR1110_REGMEM_READ_MEM8_CMD_LENGTH]; 197 | 198 | lr1110_regmem_fill_cbuffer_opcode_address_length( cbuffer, LR1110_REGMEM_READ_MEM8_OC, address, length ); 199 | 200 | return ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_REGMEM_READ_MEM8_CMD_LENGTH, buffer, length ); 201 | } 202 | 203 | lr1110_status_t lr1110_regmem_write_buffer8( const void* context, const uint8_t* buffer, const uint8_t length ) 204 | { 205 | const uint8_t cbuffer[LR1110_REGMEM_WRITE_BUFFER8_CMD_LENGTH] = { 206 | ( uint8_t )( LR1110_REGMEM_WRITE_BUFFER8_OC >> 8 ), 207 | ( uint8_t )( LR1110_REGMEM_WRITE_BUFFER8_OC >> 0 ), 208 | }; 209 | 210 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_REGMEM_WRITE_BUFFER8_CMD_LENGTH, buffer, 211 | length ); 212 | } 213 | 214 | lr1110_status_t lr1110_regmem_read_buffer8( const void* context, uint8_t* buffer, const uint8_t offset, 215 | const uint8_t length ) 216 | { 217 | const uint8_t cbuffer[LR1110_REGMEM_READ_BUFFER8_CMD_LENGTH] = { 218 | ( uint8_t )( LR1110_REGMEM_READ_BUFFER8_OC >> 8 ), 219 | ( uint8_t )( LR1110_REGMEM_READ_BUFFER8_OC >> 0 ), 220 | offset, 221 | length, 222 | }; 223 | 224 | return ( lr1110_status_t ) lr1110_hal_read( context, cbuffer, LR1110_REGMEM_READ_BUFFER8_CMD_LENGTH, buffer, 225 | length ); 226 | } 227 | 228 | lr1110_status_t lr1110_regmem_clear_rxbuffer( const void* context ) 229 | { 230 | const uint8_t cbuffer[LR1110_REGMEM_CLEAR_RXBUFFER_CMD_LENGTH] = { 231 | ( uint8_t )( LR1110_REGMEM_CLEAR_RXBUFFER_OC >> 8 ), 232 | ( uint8_t )( LR1110_REGMEM_CLEAR_RXBUFFER_OC >> 0 ), 233 | }; 234 | 235 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_REGMEM_CLEAR_RXBUFFER_CMD_LENGTH, 0, 0 ); 236 | } 237 | 238 | lr1110_status_t lr1110_regmem_write_regmem32_mask( const void* context, const uint32_t address, const uint32_t mask, 239 | const uint32_t data ) 240 | { 241 | uint8_t cbuffer[LR1110_REGMEM_WRITE_REGMEM32_MASK_CMD_LENGTH]; 242 | 243 | lr1110_regmem_fill_cbuffer_opcode_address( cbuffer, LR1110_REGMEM_WRITE_REGMEM32_MASK_OC, address ); 244 | 245 | cbuffer[6] = ( uint8_t )( mask >> 24 ); 246 | cbuffer[7] = ( uint8_t )( mask >> 16 ); 247 | cbuffer[8] = ( uint8_t )( mask >> 8 ); 248 | cbuffer[9] = ( uint8_t )( mask >> 0 ); 249 | 250 | cbuffer[10] = ( uint8_t )( data >> 24 ); 251 | cbuffer[11] = ( uint8_t )( data >> 16 ); 252 | cbuffer[12] = ( uint8_t )( data >> 8 ); 253 | cbuffer[13] = ( uint8_t )( data >> 0 ); 254 | 255 | return ( lr1110_status_t ) lr1110_hal_write( context, cbuffer, LR1110_REGMEM_WRITE_REGMEM32_MASK_CMD_LENGTH, 0, 0 ); 256 | } 257 | 258 | /* 259 | * ----------------------------------------------------------------------------- 260 | * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- 261 | */ 262 | 263 | void lr1110_regmem_fill_cbuffer_opcode_address( uint8_t* cbuffer, uint16_t opcode, uint32_t address ) 264 | { 265 | cbuffer[0] = ( uint8_t )( opcode >> 8 ); 266 | cbuffer[1] = ( uint8_t )( opcode >> 0 ); 267 | 268 | cbuffer[2] = ( uint8_t )( address >> 24 ); 269 | cbuffer[3] = ( uint8_t )( address >> 16 ); 270 | cbuffer[4] = ( uint8_t )( address >> 8 ); 271 | cbuffer[5] = ( uint8_t )( address >> 0 ); 272 | } 273 | 274 | void lr1110_regmem_fill_cbuffer_opcode_address_length( uint8_t* cbuffer, uint16_t opcode, uint32_t address, 275 | uint8_t length ) 276 | { 277 | lr1110_regmem_fill_cbuffer_opcode_address( cbuffer, opcode, address ); 278 | cbuffer[6] = length; 279 | } 280 | 281 | void lr1110_regmem_fill_cdata( uint8_t* cdata, const uint32_t* data, uint8_t data_length ) 282 | { 283 | for( uint16_t index = 0; index < data_length; index++ ) 284 | { 285 | uint8_t* cdata_local = &cdata[index * sizeof( uint32_t )]; 286 | 287 | cdata_local[0] = ( uint8_t )( data[index] >> 24 ); 288 | cdata_local[1] = ( uint8_t )( data[index] >> 16 ); 289 | cdata_local[2] = ( uint8_t )( data[index] >> 8 ); 290 | cdata_local[3] = ( uint8_t )( data[index] >> 0 ); 291 | } 292 | } 293 | 294 | void lr1110_regmem_fill_cbuffer_cdata_opcode_address_data( uint8_t* cbuffer, uint8_t* cdata, uint16_t opcode, 295 | uint32_t address, const uint32_t* data, uint8_t data_length ) 296 | { 297 | lr1110_regmem_fill_cbuffer_opcode_address( cbuffer, opcode, address ); 298 | lr1110_regmem_fill_cdata( cdata, data, data_length ); 299 | } 300 | 301 | void lr1110_regmem_fill_out_buffer_from_raw_buffer( uint32_t* out_buffer, const uint8_t* raw_buffer, 302 | uint8_t out_buffer_length ) 303 | { 304 | for( uint8_t out_index = 0; out_index < out_buffer_length; out_index++ ) 305 | { 306 | const uint8_t* raw_buffer_local = &raw_buffer[out_index * 4]; 307 | 308 | out_buffer[out_index] = ( ( uint32_t ) raw_buffer_local[0] << 24 ) + 309 | ( ( uint32_t ) raw_buffer_local[1] << 16 ) + ( ( uint32_t ) raw_buffer_local[2] << 8 ) + 310 | ( ( uint32_t ) raw_buffer_local[3] << 0 ); 311 | } 312 | } 313 | 314 | /* --- EOF ------------------------------------------------------------------ */ 315 | -------------------------------------------------------------------------------- /src/lr1110_regmem.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_regmem.h 3 | * 4 | * @brief Register/memory driver definition for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_REGMEM_H 36 | #define LR1110_REGMEM_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include "lr1110_types.h" 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /* 61 | * ----------------------------------------------------------------------------- 62 | * --- PUBLIC TYPES ------------------------------------------------------------ 63 | */ 64 | 65 | /* 66 | * ----------------------------------------------------------------------------- 67 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 68 | */ 69 | 70 | /*! 71 | * @brief Write words into register memory space of LR1110. 72 | * 73 | * A word is 32-bit long. The writing operations write contiguously in register memory, starting at the address 74 | * provided. 75 | * 76 | * @param [in] context Chip implementation context 77 | * @param [in] address The register memory address to start writing operation 78 | * @param [in] data The buffer of words to write into memory. Its size must be enough to contain length words. 79 | * @param [in] length Number of words to write into memory 80 | * 81 | * @returns Operation status 82 | * 83 | * @see lr1110_regmem_read_regmem32 84 | */ 85 | lr1110_status_t lr1110_regmem_write_regmem32( const void* context, const uint32_t address, const uint32_t* buffer, 86 | const uint8_t length ); 87 | 88 | /*! 89 | * @brief Read words into register memory space of LR1110. 90 | * 91 | * A word is 32-bit long. The reading operations read contiguously from register memory, starting at the address 92 | * provided. 93 | * 94 | * @param [in] context Chip implementation context 95 | * @param [in] address The register memory address to start reading operation 96 | * @param [in] length Number of words to read from memory 97 | * @param [out] buffer Pointer to a words array to be filled with content from memory. Its size must be enough to 98 | * contain at least length words. 99 | * 100 | * @returns Operation status 101 | * 102 | * @see lr1110_regmem_write_regmem32 103 | */ 104 | lr1110_status_t lr1110_regmem_read_regmem32( const void* context, const uint32_t address, uint32_t* buffer, 105 | const uint8_t length ); 106 | 107 | /*! 108 | * @brief Write bytes into register memory space of LR1110. 109 | * 110 | * A byte is 8-bit long. The writing operations write contiguously in register memory, starting at the address provided. 111 | * 112 | * @param [in] context Chip implementation context 113 | * @param [in] address The register memory address to start writing operation 114 | * @param [in] data The buffer of bytes to write into memory. Its size must be enough to contain length bytes 115 | * @param [in] length Number of bytes to write into memory 116 | * 117 | * @returns Operation status 118 | * 119 | * @see lr1110_regmem_read_mem8 120 | */ 121 | lr1110_status_t lr1110_regmem_write_mem8( const void* context, const uint32_t address, const uint8_t* buffer, 122 | const uint8_t length ); 123 | 124 | /*! 125 | * @brief Read bytes into register memory space of LR1110. 126 | * 127 | * A byte is 8-bit long. The reading operations read contiguously from register memory, starting at the address 128 | * provided. 129 | * 130 | * @param [in] context Chip implementation context 131 | * @param [in] address The register memory address to start reading operation 132 | * @param [in] length Number of bytes to read from memory 133 | * @param [in] buffer Pointer to a byte array to be filled with content from memory. Its size must be enough to contain 134 | * at least length bytes 135 | * 136 | * @returns Operation status 137 | * 138 | * @see lr1110_regmem_write_mem8 139 | */ 140 | lr1110_status_t lr1110_regmem_read_mem8( const void* context, const uint32_t address, uint8_t* buffer, 141 | const uint8_t length ); 142 | 143 | /*! 144 | * @brief Write bytes into radio TX buffer memory space of LR1110. 145 | * 146 | * @param [in] context Chip implementation context 147 | * @param [in] data The buffer of bytes to write into radio buffer. Its size must be enough to contain length bytes 148 | * @param [in] length Number of bytes to write into radio buffer 149 | * 150 | * @returns Operation status 151 | * 152 | * @see lr1110_regmem_read_buffer8 153 | */ 154 | lr1110_status_t lr1110_regmem_write_buffer8( const void* context, const uint8_t* buffer, const uint8_t length ); 155 | 156 | /*! 157 | * @brief Read bytes from radio RX buffer memory space of LR1110. 158 | * 159 | * @param [in] context Chip implementation context 160 | * @param [in] offset Memory offset to start reading 161 | * @param [in] length Number of bytes to read from radio buffer 162 | * @param [in] data Pointer to a byte array to be filled with content from radio buffer. Its size must be enough to 163 | * contain at least length bytes 164 | * 165 | * @returns Operation status 166 | * 167 | * @see lr1110_regmem_write_buffer8 168 | */ 169 | lr1110_status_t lr1110_regmem_read_buffer8( const void* context, uint8_t* buffer, const uint8_t offset, 170 | const uint8_t length ); 171 | 172 | /*! 173 | * @brief Clear radio RX buffer 174 | * 175 | * Set to 0x00 all content of the radio RX buffer 176 | * 177 | * @param [in] context Chip implementation context 178 | * 179 | * @returns Operation status 180 | */ 181 | lr1110_status_t lr1110_regmem_clear_rxbuffer( const void* context ); 182 | 183 | /*! 184 | * @brief Read-modify-write data at given register/memory address 185 | * 186 | * @param [in] context Chip implementation context 187 | * @param [in] address The register memory address to be modified 188 | * @param [in] mask The mask to be applied on read data 189 | * @param [in] data The data to be written 190 | * 191 | * @returns Operation status 192 | */ 193 | lr1110_status_t lr1110_regmem_write_regmem32_mask( const void* context, const uint32_t address, const uint32_t mask, 194 | const uint32_t data ); 195 | 196 | #ifdef __cplusplus 197 | } 198 | #endif 199 | 200 | #endif // LR1110_REGMEM_H 201 | 202 | /* --- EOF ------------------------------------------------------------------ */ 203 | -------------------------------------------------------------------------------- /src/lr1110_system_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_system_types.h 3 | * 4 | * @brief System driver types for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_SYSTEM_TYPES_H 36 | #define LR1110_SYSTEM_TYPES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | /*! 61 | * @brief Length in byte of the LR1110 version blob 62 | */ 63 | #define LR1110_SYSTEM_VERSION_LENGTH ( 4 ) 64 | 65 | /*! 66 | * @brief Length of the LR1110 Unique Identifier in bytes 67 | * 68 | * The LR1110 Unique Identifiers is an 8 byte long buffer 69 | */ 70 | #define LR1110_SYSTEM_UID_LENGTH ( 8 ) 71 | #define LR1110_SYSTEM_JOIN_EUI_LENGTH ( 8 ) 72 | #define LR1110_SYSTEM_PIN_LENGTH ( 4 ) 73 | 74 | /* 75 | * ----------------------------------------------------------------------------- 76 | * --- PUBLIC TYPES ------------------------------------------------------------ 77 | */ 78 | 79 | /** 80 | * @brief Fixed-length array to store a UID 81 | */ 82 | typedef uint8_t lr1110_system_uid_t[LR1110_SYSTEM_UID_LENGTH]; 83 | 84 | /** 85 | * @brief Fixed-length array to store a joinEUI 86 | */ 87 | typedef uint8_t lr1110_system_join_eui_t[LR1110_SYSTEM_JOIN_EUI_LENGTH]; 88 | 89 | /** 90 | * @brief Fixed-length array to store a PIN 91 | */ 92 | typedef uint8_t lr1110_system_pin_t[LR1110_SYSTEM_PIN_LENGTH]; 93 | 94 | /** 95 | * @brief Type to store system interrupt flags 96 | */ 97 | typedef uint32_t lr1110_system_irq_mask_t; 98 | 99 | /** 100 | * @brief Interrupt flags 101 | */ 102 | enum lr1110_system_irq_e 103 | { 104 | LR1110_SYSTEM_IRQ_NONE = ( 0 << 0 ), 105 | LR1110_SYSTEM_IRQ_TX_DONE = ( 1 << 2 ), 106 | LR1110_SYSTEM_IRQ_RX_DONE = ( 1 << 3 ), 107 | LR1110_SYSTEM_IRQ_PREAMBLE_DETECTED = ( 1 << 4 ), 108 | LR1110_SYSTEM_IRQ_SYNC_WORD_HEADER_VALID = ( 1 << 5 ), 109 | LR1110_SYSTEM_IRQ_HEADER_ERROR = ( 1 << 6 ), 110 | LR1110_SYSTEM_IRQ_CRC_ERROR = ( 1 << 7 ), 111 | LR1110_SYSTEM_IRQ_CAD_DONE = ( 1 << 8 ), 112 | LR1110_SYSTEM_IRQ_CAD_DETECTED = ( 1 << 9 ), 113 | LR1110_SYSTEM_IRQ_TIMEOUT = ( 1 << 10 ), 114 | LR1110_SYSTEM_IRQ_LR_FHSS_INTRA_PKT_HOP = ( 1 << 11 ), 115 | LR1110_SYSTEM_IRQ_GNSS_SCAN_DONE = ( 1 << 19 ), 116 | LR1110_SYSTEM_IRQ_WIFI_SCAN_DONE = ( 1 << 20 ), 117 | LR1110_SYSTEM_IRQ_EOL = ( 1 << 21 ), 118 | LR1110_SYSTEM_IRQ_CMD_ERROR = ( 1 << 22 ), 119 | LR1110_SYSTEM_IRQ_ERROR = ( 1 << 23 ), 120 | LR1110_SYSTEM_IRQ_FSK_LEN_ERROR = ( 1 << 24 ), 121 | LR1110_SYSTEM_IRQ_FSK_ADDR_ERROR = ( 1 << 25 ), 122 | LR1110_SYSTEM_IRQ_ALL_MASK = 123 | LR1110_SYSTEM_IRQ_TX_DONE | LR1110_SYSTEM_IRQ_RX_DONE | LR1110_SYSTEM_IRQ_PREAMBLE_DETECTED | 124 | LR1110_SYSTEM_IRQ_SYNC_WORD_HEADER_VALID | LR1110_SYSTEM_IRQ_HEADER_ERROR | LR1110_SYSTEM_IRQ_CRC_ERROR | 125 | LR1110_SYSTEM_IRQ_CAD_DONE | LR1110_SYSTEM_IRQ_CAD_DETECTED | LR1110_SYSTEM_IRQ_TIMEOUT | 126 | LR1110_SYSTEM_IRQ_LR_FHSS_INTRA_PKT_HOP | LR1110_SYSTEM_IRQ_GNSS_SCAN_DONE | LR1110_SYSTEM_IRQ_WIFI_SCAN_DONE | 127 | LR1110_SYSTEM_IRQ_EOL | LR1110_SYSTEM_IRQ_CMD_ERROR | LR1110_SYSTEM_IRQ_ERROR | 128 | LR1110_SYSTEM_IRQ_FSK_LEN_ERROR | LR1110_SYSTEM_IRQ_FSK_ADDR_ERROR, 129 | }; 130 | 131 | /** 132 | * @brief Calibration flags 133 | */ 134 | enum lr1110_system_calibration_e 135 | { 136 | LR1110_SYSTEM_CALIB_LF_RC_MASK = ( 1 << 0 ), 137 | LR1110_SYSTEM_CALIB_HF_RC_MASK = ( 1 << 1 ), 138 | LR1110_SYSTEM_CALIB_PLL_MASK = ( 1 << 2 ), 139 | LR1110_SYSTEM_CALIB_ADC_MASK = ( 1 << 3 ), 140 | LR1110_SYSTEM_CALIB_IMG_MASK = ( 1 << 4 ), 141 | LR1110_SYSTEM_CALIB_PLL_TX_MASK = ( 1 << 5 ), 142 | }; 143 | 144 | typedef uint8_t lr1110_system_cal_mask_t; 145 | 146 | /** 147 | * @brief Error flags 148 | */ 149 | enum lr1110_system_errors_e 150 | { 151 | LR1110_SYSTEM_ERRORS_LF_RC_CALIB_MASK = ( 1 << 0 ), 152 | LR1110_SYSTEM_ERRORS_HF_RC_CALIB_MASK = ( 1 << 1 ), 153 | LR1110_SYSTEM_ERRORS_ADC_CALIB_MASK = ( 1 << 2 ), 154 | LR1110_SYSTEM_ERRORS_PLL_CALIB_MASK = ( 1 << 3 ), 155 | LR1110_SYSTEM_ERRORS_IMG_CALIB_MASK = ( 1 << 4 ), 156 | LR1110_SYSTEM_ERRORS_HF_XOSC_START_MASK = ( 1 << 5 ), 157 | LR1110_SYSTEM_ERRORS_LF_XOSC_START_MASK = ( 1 << 6 ), 158 | LR1110_SYSTEM_ERRORS_PLL_LOCK_MASK = ( 1 << 7 ), 159 | }; 160 | 161 | typedef uint16_t lr1110_system_errors_t; 162 | 163 | /** 164 | * @brief Chip modes 165 | */ 166 | typedef enum 167 | { 168 | LR1110_SYSTEM_CHIP_MODE_SLEEP = 0x00, 169 | LR1110_SYSTEM_CHIP_MODE_STBY_RC = 0x01, 170 | LR1110_SYSTEM_CHIP_MODE_STBY_XOSC = 0x02, 171 | LR1110_SYSTEM_CHIP_MODE_FS = 0x03, 172 | LR1110_SYSTEM_CHIP_MODE_RX = 0x04, 173 | LR1110_SYSTEM_CHIP_MODE_TX = 0x05, 174 | LR1110_SYSTEM_CHIP_MODE_LOC = 0x06, 175 | } lr1110_system_chip_modes_t; 176 | 177 | /** 178 | * @brief Reset status 179 | */ 180 | typedef enum 181 | { 182 | LR1110_SYSTEM_RESET_STATUS_CLEARED = 0x00, 183 | LR1110_SYSTEM_RESET_STATUS_ANALOG = 0x01, 184 | LR1110_SYSTEM_RESET_STATUS_EXTERNAL = 0x02, 185 | LR1110_SYSTEM_RESET_STATUS_SYSTEM = 0x03, 186 | LR1110_SYSTEM_RESET_STATUS_WATCHDOG = 0x04, 187 | LR1110_SYSTEM_RESET_STATUS_IOCD_RESTART = 0x05, 188 | LR1110_SYSTEM_RESET_STATUS_RTC_RESTART = 0x06, 189 | } lr1110_system_reset_status_t; 190 | 191 | /** 192 | * @brief Command status 193 | */ 194 | typedef enum 195 | { 196 | LR1110_SYSTEM_CMD_STATUS_FAIL = 0x00, 197 | LR1110_SYSTEM_CMD_STATUS_PERR = 0x01, 198 | LR1110_SYSTEM_CMD_STATUS_OK = 0x02, 199 | LR1110_SYSTEM_CMD_STATUS_DATA = 0x03, 200 | } lr1110_system_command_status_t; 201 | 202 | /** 203 | * @brief Low-frequency clock modes 204 | */ 205 | typedef enum 206 | { 207 | LR1110_SYSTEM_LFCLK_RC = 0x00, //!< (Default) 208 | LR1110_SYSTEM_LFCLK_XTAL = 0x01, 209 | LR1110_SYSTEM_LFCLK_EXT = 0x02 210 | } lr1110_system_lfclk_cfg_t; 211 | 212 | /** 213 | * @brief Regulator modes 214 | */ 215 | typedef enum 216 | { 217 | LR1110_SYSTEM_REG_MODE_LDO = 0x00, //!< (Default) 218 | LR1110_SYSTEM_REG_MODE_DCDC = 0x01, 219 | } lr1110_system_reg_mode_t; 220 | 221 | /** 222 | * @brief Info page ID 223 | */ 224 | typedef enum 225 | { 226 | LR1110_SYSTEM_INFOPAGE_0 = 0x00, //!< Info page #0 227 | LR1110_SYSTEM_INFOPAGE_1 = 0x01, //!< Info page #1 228 | } lr1110_system_infopage_id_t; 229 | 230 | /** 231 | * @brief RF switch configuration pin 232 | */ 233 | enum lr1110_system_rfswitch_cfg_pin_e 234 | { 235 | LR1110_SYSTEM_RFSW0_HIGH = ( 1 << 0 ), 236 | LR1110_SYSTEM_RFSW1_HIGH = ( 1 << 1 ), 237 | LR1110_SYSTEM_RFSW2_HIGH = ( 1 << 2 ), 238 | LR1110_SYSTEM_RFSW3_HIGH = ( 1 << 3 ), 239 | LR1110_SYSTEM_RFSW4_HIGH = ( 1 << 4 ), 240 | }; 241 | 242 | /** 243 | * @brief RF switch configuration structure definition 244 | */ 245 | typedef struct lr1110_system_rfswitch_cfg_s 246 | { 247 | uint8_t enable; 248 | uint8_t standby; 249 | uint8_t rx; 250 | uint8_t tx; 251 | uint8_t tx_hp; 252 | uint8_t tx_hf; 253 | uint8_t gnss; 254 | uint8_t wifi; 255 | } lr1110_system_rfswitch_cfg_t; 256 | 257 | /** 258 | * @brief Stand by configuration values 259 | */ 260 | typedef enum 261 | { 262 | LR1110_SYSTEM_STANDBY_CFG_RC = 0x00, 263 | LR1110_SYSTEM_STANDBY_CFG_XOSC = 0x01 264 | } lr1110_system_standby_cfg_t; 265 | 266 | /** 267 | * @brief TCXO supply voltage values 268 | */ 269 | typedef enum 270 | { 271 | LR1110_SYSTEM_TCXO_CTRL_1_6V = 0x00, //!< Supply voltage = 1.6v 272 | LR1110_SYSTEM_TCXO_CTRL_1_7V = 0x01, //!< Supply voltage = 1.7v 273 | LR1110_SYSTEM_TCXO_CTRL_1_8V = 0x02, //!< Supply voltage = 1.8v 274 | LR1110_SYSTEM_TCXO_CTRL_2_2V = 0x03, //!< Supply voltage = 2.2v 275 | LR1110_SYSTEM_TCXO_CTRL_2_4V = 0x04, //!< Supply voltage = 2.4v 276 | LR1110_SYSTEM_TCXO_CTRL_2_7V = 0x05, //!< Supply voltage = 2.7v 277 | LR1110_SYSTEM_TCXO_CTRL_3_0V = 0x06, //!< Supply voltage = 3.0v 278 | LR1110_SYSTEM_TCXO_CTRL_3_3V = 0x07, //!< Supply voltage = 3.3v 279 | } lr1110_system_tcxo_supply_voltage_t; 280 | 281 | /** 282 | * @brief Status register 1 structure definition 283 | */ 284 | typedef struct lr1110_system_stat1_s 285 | { 286 | lr1110_system_command_status_t command_status; 287 | bool is_interrupt_active; 288 | } lr1110_system_stat1_t; 289 | 290 | /** 291 | * @brief Status register 2 structure definition 292 | */ 293 | typedef struct lr1110_system_stat2_s 294 | { 295 | lr1110_system_reset_status_t reset_status; 296 | lr1110_system_chip_modes_t chip_mode; 297 | bool is_running_from_flash; 298 | } lr1110_system_stat2_t; 299 | 300 | /** 301 | * @brief Version structure definition 302 | */ 303 | typedef struct lr1110_system_version_s 304 | { 305 | uint8_t hw; 306 | uint8_t type; 307 | uint16_t fw; 308 | } lr1110_system_version_t; 309 | 310 | /** 311 | * @brief Sleep configuration structure definition 312 | */ 313 | typedef struct lr1110_system_sleep_cfg_s 314 | { 315 | bool is_warm_start; 316 | bool is_rtc_timeout; 317 | } lr1110_system_sleep_cfg_t; 318 | 319 | /* 320 | * ----------------------------------------------------------------------------- 321 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 322 | */ 323 | 324 | #ifdef __cplusplus 325 | } 326 | #endif 327 | 328 | #endif // LR1110_SYSTEM_TYPES_H 329 | 330 | /* --- EOF ------------------------------------------------------------------ */ 331 | -------------------------------------------------------------------------------- /src/lr1110_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_types.h 3 | * 4 | * @brief Type definitions for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_TYPES_H 36 | #define LR1110_TYPES_H 37 | 38 | /* 39 | * ----------------------------------------------------------------------------- 40 | * --- DEPENDENCIES ------------------------------------------------------------ 41 | */ 42 | 43 | /* 44 | * ----------------------------------------------------------------------------- 45 | * --- PUBLIC MACROS ----------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | * ----------------------------------------------------------------------------- 50 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 51 | */ 52 | 53 | #define LR1110_CMD_LENGTH_MAX ( 512 ) 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC TYPES ------------------------------------------------------------ 58 | */ 59 | 60 | /** 61 | * @brief LR1110 status 62 | */ 63 | typedef enum lr1110_status_e 64 | { 65 | LR1110_STATUS_OK = 0, 66 | LR1110_STATUS_ERROR = 3, 67 | } lr1110_status_t; 68 | 69 | /* 70 | * ----------------------------------------------------------------------------- 71 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 72 | */ 73 | 74 | #endif // LR1110_TYPES_H 75 | 76 | /* --- EOF ------------------------------------------------------------------ */ 77 | -------------------------------------------------------------------------------- /src/lr1110_wifi_types.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file lr1110_wifi_types.h 3 | * 4 | * @brief Wi-Fi passive scan driver types for LR1110 5 | * 6 | * The Clear BSD License 7 | * Copyright Semtech Corporation 2021. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted (subject to the limitations in the disclaimer 11 | * below) provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the Semtech corporation nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY 22 | * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef LR1110_WIFI_TYPES_H 36 | #define LR1110_WIFI_TYPES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * ----------------------------------------------------------------------------- 44 | * --- DEPENDENCIES ------------------------------------------------------------ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | /* 51 | * ----------------------------------------------------------------------------- 52 | * --- PUBLIC MACROS ----------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | * ----------------------------------------------------------------------------- 57 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 58 | */ 59 | 60 | #define LR1110_WIFI_MAC_ADDRESS_LENGTH ( 6 ) 61 | #define LR1110_WIFI_MAX_RESULTS ( 32 ) 62 | #define LR1110_WIFI_RESULT_SSID_LENGTH ( 32 ) 63 | #define LR1110_WIFI_MAX_COUNTRY_CODE ( 32 ) 64 | #define LR1110_WIFI_STR_COUNTRY_CODE_SIZE ( 2 ) 65 | 66 | #define LR1110_WIFI_CHANNEL_1_POS ( 0U ) //!< Channel at frequency 2.412 GHz 67 | #define LR1110_WIFI_CHANNEL_1_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_1_POS ) 68 | #define LR1110_WIFI_CHANNEL_2_POS ( 1U ) //!< Channel at frequency 2.417 GHz 69 | #define LR1110_WIFI_CHANNEL_2_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_2_POS ) 70 | #define LR1110_WIFI_CHANNEL_3_POS ( 2U ) //!< Channel at frequency 2.422 GHz 71 | #define LR1110_WIFI_CHANNEL_3_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_3_POS ) 72 | #define LR1110_WIFI_CHANNEL_4_POS ( 3U ) //!< Channel at frequency 2.427 GHz 73 | #define LR1110_WIFI_CHANNEL_4_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_4_POS ) 74 | #define LR1110_WIFI_CHANNEL_5_POS ( 4U ) //!< Channel at frequency 2.432 GHz 75 | #define LR1110_WIFI_CHANNEL_5_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_5_POS ) 76 | #define LR1110_WIFI_CHANNEL_6_POS ( 5U ) //!< Channel at frequency 2.437 GHz 77 | #define LR1110_WIFI_CHANNEL_6_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_6_POS ) 78 | #define LR1110_WIFI_CHANNEL_7_POS ( 6U ) //!< Channel at frequency 2.442 GHz 79 | #define LR1110_WIFI_CHANNEL_7_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_7_POS ) 80 | #define LR1110_WIFI_CHANNEL_8_POS ( 7U ) //!< Channel at frequency 2.447 GHz 81 | #define LR1110_WIFI_CHANNEL_8_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_8_POS ) 82 | #define LR1110_WIFI_CHANNEL_9_POS ( 8U ) //!< Channel at frequency 2.452 GHz 83 | #define LR1110_WIFI_CHANNEL_9_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_9_POS ) 84 | #define LR1110_WIFI_CHANNEL_10_POS ( 9U ) //!< Channel at frequency 2.457 GHz 85 | #define LR1110_WIFI_CHANNEL_10_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_10_POS ) 86 | #define LR1110_WIFI_CHANNEL_11_POS ( 10U ) //!< Channel at frequency 2.462 GHz 87 | #define LR1110_WIFI_CHANNEL_11_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_11_POS ) 88 | #define LR1110_WIFI_CHANNEL_12_POS ( 11U ) //!< Channel at frequency 2.467 GHz 89 | #define LR1110_WIFI_CHANNEL_12_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_12_POS ) 90 | #define LR1110_WIFI_CHANNEL_13_POS ( 12U ) //!< Channel at frequency 2.472 GHz 91 | #define LR1110_WIFI_CHANNEL_13_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_13_POS ) 92 | #define LR1110_WIFI_CHANNEL_14_POS ( 13U ) //!< Channel at frequency 2.484 GHz 93 | #define LR1110_WIFI_CHANNEL_14_MASK ( 0x01UL << LR1110_WIFI_CHANNEL_14_POS ) 94 | 95 | /* 96 | * ----------------------------------------------------------------------------- 97 | * --- PUBLIC TYPES ------------------------------------------------------------ 98 | */ 99 | 100 | /*! 101 | * @brief Type to store a Wi-Fi channel mask 102 | */ 103 | typedef uint16_t lr1110_wifi_channel_mask_t; 104 | 105 | /*! 106 | * @brief Type to store a Wi-Fi channel info byte 107 | */ 108 | typedef uint8_t lr1110_wifi_channel_info_byte_t; 109 | 110 | /*! 111 | * @brief Type to store a Wi-Fi datarate info byte 112 | */ 113 | typedef uint8_t lr1110_wifi_datarate_info_byte_t; 114 | 115 | /*! 116 | * @brief Type to store a Wi-Fi frame type info byte 117 | */ 118 | typedef uint8_t lr1110_wifi_frame_type_info_byte_t; 119 | 120 | /*! 121 | * @brief Type to store a Wi-Fi frame sub_type 122 | */ 123 | typedef uint8_t lr1110_wifi_frame_sub_type_t; 124 | 125 | /*! 126 | * @brief Wi-Fi FCS info byte 127 | */ 128 | typedef struct lr1110_wifi_fcs_info_byte_s 129 | { 130 | bool is_fcs_ok; //!< True if the LR1110 has checked the FCS and the check succeeded 131 | bool is_fcs_checked; //!< True if the LR1110 has checked the FCS 132 | } lr1110_wifi_fcs_info_byte_t; 133 | 134 | /*! 135 | * @brief Type to store a MAC address 136 | */ 137 | typedef uint8_t lr1110_wifi_mac_address_t[LR1110_WIFI_MAC_ADDRESS_LENGTH]; 138 | 139 | /*! 140 | * @brief Wi-Fi Channels index 141 | */ 142 | typedef enum 143 | { 144 | LR1110_WIFI_NO_CHANNEL = 0x00, 145 | LR1110_WIFI_CHANNEL_1 = 0x01, //!< Channel at frequency 2.412 GHz 146 | LR1110_WIFI_CHANNEL_2 = 0x02, //!< Channel at frequency 2.417 GHz 147 | LR1110_WIFI_CHANNEL_3 = 0x03, //!< Channel at frequency 2.422 GHz 148 | LR1110_WIFI_CHANNEL_4 = 0x04, //!< Channel at frequency 2.427 GHz 149 | LR1110_WIFI_CHANNEL_5 = 0x05, //!< Channel at frequency 2.432 GHz 150 | LR1110_WIFI_CHANNEL_6 = 0x06, //!< Channel at frequency 2.437 GHz 151 | LR1110_WIFI_CHANNEL_7 = 0x07, //!< Channel at frequency 2.442 GHz 152 | LR1110_WIFI_CHANNEL_8 = 0x08, //!< Channel at frequency 2.447 GHz 153 | LR1110_WIFI_CHANNEL_9 = 0x09, //!< Channel at frequency 2.452 GHz 154 | LR1110_WIFI_CHANNEL_10 = 0x0A, //!< Channel at frequency 2.457 GHz 155 | LR1110_WIFI_CHANNEL_11 = 0x0B, //!< Channel at frequency 2.462 GHz 156 | LR1110_WIFI_CHANNEL_12 = 0x0C, //!< Channel at frequency 2.467 GHz 157 | LR1110_WIFI_CHANNEL_13 = 0x0D, //!< Channel at frequency 2.472 GHz 158 | LR1110_WIFI_CHANNEL_14 = 0x0E, //!< Channel at frequency 2.484 GHz 159 | LR1110_WIFI_ALL_CHANNELS = 0x0F, 160 | } lr1110_wifi_channel_t; 161 | 162 | /*! 163 | * @brief WiFi theoretical Datarates 164 | */ 165 | typedef enum 166 | { 167 | LR1110_WIFI_DATARATE_1_MBPS = 1, 168 | LR1110_WIFI_DATARATE_2_MBPS = 2, 169 | LR1110_WIFI_DATARATE_6_MBPS = 3, 170 | LR1110_WIFI_DATARATE_9_MBPS = 4, 171 | LR1110_WIFI_DATARATE_12_MBPS = 5, 172 | LR1110_WIFI_DATARATE_18_MBPS = 6, 173 | LR1110_WIFI_DATARATE_24_MBPS = 7, 174 | LR1110_WIFI_DATARATE_36_MBPS = 8, 175 | LR1110_WIFI_DATARATE_48_MBPS = 9, 176 | LR1110_WIFI_DATARATE_54_MBPS = 10, 177 | LR1110_WIFI_DATARATE_6_5_MBPS = 11, 178 | LR1110_WIFI_DATARATE_13_MBPS = 12, 179 | LR1110_WIFI_DATARATE_19_5_MBPS = 13, 180 | LR1110_WIFI_DATARATE_26_MBPS = 14, 181 | LR1110_WIFI_DATARATE_39_MBPS = 15, 182 | LR1110_WIFI_DATARATE_52_MBPS = 16, 183 | LR1110_WIFI_DATARATE_58_MBPS = 17, 184 | LR1110_WIFI_DATARATE_65_MBPS = 18, 185 | LR1110_WIFI_DATARATE_7_2_MBPS = 19, 186 | LR1110_WIFI_DATARATE_14_4_MBPS = 20, 187 | LR1110_WIFI_DATARATE_21_7_MBPS = 21, 188 | LR1110_WIFI_DATARATE_28_9_MBPS = 22, 189 | LR1110_WIFI_DATARATE_43_3_MBPS = 23, 190 | LR1110_WIFI_DATARATE_57_8_MBPS = 24, 191 | LR1110_WIFI_DATARATE_65_2_MBPS = 25, 192 | LR1110_WIFI_DATARATE_72_2_MBPS = 26, 193 | } lr1110_wifi_datarate_t; 194 | 195 | /*! 196 | * @brief WiFi Frame Types 197 | */ 198 | typedef enum 199 | { 200 | LR1110_WIFI_FRAME_TYPE_MANAGEMENT = 0x00, 201 | LR1110_WIFI_FRAME_TYPE_CONTROL = 0x01, 202 | LR1110_WIFI_FRAME_TYPE_DATA = 0x02, 203 | } lr1110_wifi_frame_type_t; 204 | 205 | /*! 206 | * @brief The WiFi MAC address origin 207 | * 208 | * @see lr1110_wifi_parse_channel_info for details about the MAC address origin estimation of the LR1110 209 | */ 210 | typedef enum 211 | { 212 | LR1110_WIFI_ORIGIN_BEACON_FIX_AP = 1, //!< MAC address extracted from a packet coming from a fix Access Point 213 | LR1110_WIFI_ORIGIN_BEACON_MOBILE_AP = 2, //!< MAC address extracted from a packet coming from a mobile Access Point 214 | LR1110_WIFI_ORIGIN_UNKNOWN = 3, //!< Impossible to determine the origin of the packet the MAC is extracted from 215 | } lr1110_wifi_mac_origin_t; 216 | 217 | /*! 218 | * @brief Wi-Fi signal type for passive scanning configuration 219 | * 220 | * Note it is not possible to configure the WiFi passive scanning to search Wi-Fi type N GreenField. Only Wi-Fi type N 221 | * Mixed Mode can be scanned by LR1110. 222 | * 223 | * @warning LR1110_WIFI_TYPE_SCAN_G and LR1110_WIFI_TYPE_SCAN_N configurations are implemented the same way, and both 224 | * will scan Wi-Fi type G **AND** Wi-Fi type N. 225 | */ 226 | typedef enum 227 | { 228 | LR1110_WIFI_TYPE_SCAN_B = 0x01, //!< Wi-Fi B 229 | LR1110_WIFI_TYPE_SCAN_G = 0x02, //!< Wi-Fi G 230 | LR1110_WIFI_TYPE_SCAN_N = 0x03, //!< Wi-Fi N 231 | LR1110_WIFI_TYPE_SCAN_B_G_N = 0x04, //!< Wi-Fi B and Wi-Fi G/N 232 | } lr1110_wifi_signal_type_scan_t; 233 | 234 | /*! 235 | * @brief Wi-Fi signal type for passive scan results 236 | * 237 | * Note that the Wi-Fi N detected is Wi-Fi N Mixed mode, and not GreenField. 238 | */ 239 | typedef enum 240 | { 241 | LR1110_WIFI_TYPE_RESULT_B = 0x01, //!< WiFi B 242 | LR1110_WIFI_TYPE_RESULT_G = 0x02, //!< WiFi G 243 | LR1110_WIFI_TYPE_RESULT_N = 0x03, //!< WiFi N 244 | } lr1110_wifi_signal_type_result_t; 245 | 246 | /*! 247 | * @brief Wi-Fi capture mode 248 | * 249 | * The result type available depends on the Wi-Fi capture mode selected when calling the Wi-Fi scan API as follows: 250 | * 251 | * 252 | *
Scan Mode Type/Sub-type selected Corresponding read result function 253 | *
LR1110_WIFI_SCAN_MODE_BEACON Management/Beacon and Management/Probe Response @ref 254 | * lr1110_wifi_read_basic_complete_results, @ref lr1110_wifi_read_basic_mac_type_channel_results
255 | * LR1110_WIFI_SCAN_MODE_BEACON_AND_PKT Some from Management, Control and Data Types
256 | * LR1110_WIFI_SCAN_MODE_FULL_BEACON Management/Beacon and Management/Probe Response @ref 257 | * lr1110_wifi_read_extended_full_results 258 | * LR1110_WIFI_SCAN_MODE_UNTIL_SSID Management/Beacon and Management/Probe Response - until SSID field @ref 259 | * lr1110_wifi_read_extended_full_results 260 | *
261 | * 262 | * When the LR1110 receives a Wi-Fi frame, it starts demodulating it. Depending on the scan mode selected, only some 263 | * Wi-Fi frame type/sub-types are to be kept. The demodulation step is stopped as soon as the LR1110 detects the current 264 | * Wi-Fi frame is not of the required type/sub-types. This saves scan time and consumption. 265 | * 266 | * A Wi-Fi frame is never completely demodulated. The LR1110_WIFI_SCAN_MODE_FULL_BEACON uses a special configuration 267 | * allowing to demodulate more fields (until Frame Check Sequence field), at a price of higher scan duration and higher 268 | * consumption. 269 | */ 270 | typedef enum 271 | { 272 | LR1110_WIFI_SCAN_MODE_BEACON = 273 | 1, //!< Exposes Beacons and Probe Responses Access Points frames until Period Beacon field (Basic result) 274 | LR1110_WIFI_SCAN_MODE_BEACON_AND_PKT = 275 | 2, //!< Exposes some Management Access Points frames until Period Beacon field, and some other packets frame 276 | //!< until third Mac Address field (Basic result) 277 | LR1110_WIFI_SCAN_MODE_FULL_BEACON = 278 | 4, //!< Exposes Beacons and Probes Responses Access Points frames until Frame Check Sequence (FCS) field 279 | //!< (Extended result). In this mode, only signal type LR1110_WIFI_TYPE_SCAN_B is executed and other signal 280 | //!< types are silently discarded. 281 | LR1110_WIFI_SCAN_MODE_UNTIL_SSID = 5, //!< Exposes Beacons and Probes Responses Access Points frames until the end 282 | //!< of SSID field (Extended result) - available since firmware 0x0306 283 | } lr1110_wifi_mode_t; 284 | 285 | /*! 286 | * @brief Cumulative timings 287 | * 288 | * This structure is representing the cumulative time spent in the different modes of Wi-Fi passive scanning procedure. 289 | * All timings are provided in [us]. 290 | * */ 291 | typedef struct lr1110_wifi_cumulative_timings_s 292 | { 293 | uint32_t rx_detection_us; //!< Cumulative time spent during NFE or TOA 294 | uint32_t rx_correlation_us; //!< Cumulative time spent during preamble detection 295 | uint32_t rx_capture_us; //!< Cumulative time spent during signal acquisition 296 | uint32_t demodulation_us; //!< Cumulative time spent during software demodulation 297 | } lr1110_wifi_cumulative_timings_t; 298 | 299 | /*! 300 | * @brief Basic complete result structure 301 | * 302 | * The beacon period is expressed in TU (Time Unit). 1 TU is 1024 microseconds. 303 | */ 304 | typedef struct lr1110_wifi_basic_complete_result_s 305 | { 306 | lr1110_wifi_datarate_info_byte_t data_rate_info_byte; 307 | lr1110_wifi_channel_info_byte_t channel_info_byte; 308 | int8_t rssi; 309 | lr1110_wifi_frame_type_info_byte_t frame_type_info_byte; 310 | lr1110_wifi_mac_address_t mac_address; 311 | int16_t phi_offset; 312 | uint64_t timestamp_us; //!< Indicate the up-time of the Access Point transmitting the Beacon [us] 313 | uint16_t beacon_period_tu; 314 | } lr1110_wifi_basic_complete_result_t; 315 | 316 | /*! 317 | * @brief Basic MAC, type, channel result structure 318 | */ 319 | typedef struct lr1110_wifi_basic_mac_type_channel_result_s 320 | { 321 | lr1110_wifi_datarate_info_byte_t data_rate_info_byte; 322 | lr1110_wifi_channel_info_byte_t channel_info_byte; 323 | int8_t rssi; 324 | lr1110_wifi_mac_address_t mac_address; 325 | } lr1110_wifi_basic_mac_type_channel_result_t; 326 | 327 | /*! 328 | * @brief Extended full result structure 329 | * 330 | * @note The beacon period is expressed in TU (Time Unit). 1 TU is 1024 microseconds. 331 | * 332 | * @remark When used with @ref LR1110_WIFI_SCAN_MODE_UNTIL_SSID, the following field are always set to 0: 333 | * - field is_fcs_ok and is_fcs_checked in fcs_check_byte structure 334 | * - current_channel 335 | * - country_code 336 | * - io_regulation 337 | */ 338 | typedef struct 339 | { 340 | lr1110_wifi_datarate_info_byte_t data_rate_info_byte; 341 | lr1110_wifi_channel_info_byte_t channel_info_byte; 342 | int8_t rssi; 343 | uint8_t rate; //!< Rate index 344 | uint16_t service; //!< Service value 345 | uint16_t length; //!< Length of MPDU (in microseconds for WiFi B, bytes for WiFi G) 346 | uint16_t frame_control; //!< Frame Control structure 347 | lr1110_wifi_mac_address_t mac_address_1; 348 | lr1110_wifi_mac_address_t mac_address_2; 349 | lr1110_wifi_mac_address_t mac_address_3; 350 | uint64_t timestamp_us; //!< Indicate the up-time of the Access Point 351 | //!< transmitting the Beacon [us] 352 | uint16_t beacon_period_tu; 353 | uint16_t seq_control; //!< Sequence Control value 354 | uint8_t ssid_bytes[LR1110_WIFI_RESULT_SSID_LENGTH]; //!< Service Set 355 | //!< IDentifier 356 | lr1110_wifi_channel_t current_channel; //!< Current channel indicated in the Wi-Fi frame 357 | uint16_t country_code; //!< Country Code 358 | uint8_t io_regulation; //!< Input Output Regulation 359 | lr1110_wifi_fcs_info_byte_t fcs_check_byte; // 44 | #include 45 | 46 | /* 47 | * ----------------------------------------------------------------------------- 48 | * --- PUBLIC MACROS ----------------------------------------------------------- 49 | */ 50 | 51 | /* 52 | * ----------------------------------------------------------------------------- 53 | * --- PUBLIC CONSTANTS -------------------------------------------------------- 54 | */ 55 | 56 | /* 57 | * ----------------------------------------------------------------------------- 58 | * --- PUBLIC TYPES ------------------------------------------------------------ 59 | */ 60 | 61 | /** 62 | * @brief LR-FHSS modulation type 63 | */ 64 | typedef enum lr_fhss_v1_modulation_type_e 65 | { 66 | LR_FHSS_V1_MODULATION_TYPE_GMSK_488 = 0, 67 | } lr_fhss_v1_modulation_type_t; 68 | 69 | /** 70 | * @brief LR-FHSS coding rate 71 | */ 72 | typedef enum lr_fhss_v1_cr_e 73 | { 74 | LR_FHSS_V1_CR_5_6 = 0x00, 75 | LR_FHSS_V1_CR_2_3 = 0x01, 76 | LR_FHSS_V1_CR_1_2 = 0x02, 77 | LR_FHSS_V1_CR_1_3 = 0x03, 78 | } lr_fhss_v1_cr_t; 79 | 80 | /** 81 | * @brief LR-FHSS grid 82 | */ 83 | typedef enum lr_fhss_v1_grid_e 84 | { 85 | LR_FHSS_V1_GRID_25391_HZ = 0x00, 86 | LR_FHSS_V1_GRID_3906_HZ = 0x01, 87 | } lr_fhss_v1_grid_t; 88 | 89 | /** 90 | * @brief LR-FHSS bandwidth 91 | */ 92 | typedef enum lr_fhss_v1_bw_e 93 | { 94 | LR_FHSS_V1_BW_39063_HZ = 0x00, 95 | LR_FHSS_V1_BW_85938_HZ = 0x01, 96 | LR_FHSS_V1_BW_136719_HZ = 0x02, 97 | LR_FHSS_V1_BW_183594_HZ = 0x03, 98 | LR_FHSS_V1_BW_335938_HZ = 0x04, 99 | LR_FHSS_V1_BW_386719_HZ = 0x05, 100 | LR_FHSS_V1_BW_722656_HZ = 0x06, 101 | LR_FHSS_V1_BW_773438_HZ = 0x07, 102 | LR_FHSS_V1_BW_1523438_HZ = 0x08, 103 | LR_FHSS_V1_BW_1574219_HZ = 0x09, 104 | } lr_fhss_v1_bw_t; 105 | 106 | /** 107 | * @brief LR-FHSS parameter structure 108 | */ 109 | typedef struct lr_fhss_v1_params_s 110 | { 111 | const uint8_t* sync_word; /**< 4-byte sync word */ 112 | lr_fhss_v1_modulation_type_t modulation_type; 113 | lr_fhss_v1_cr_t cr; 114 | lr_fhss_v1_grid_t grid; 115 | lr_fhss_v1_bw_t bw; 116 | bool enable_hopping; 117 | uint8_t header_count; /**< Number of header blocks */ 118 | } lr_fhss_v1_params_t; 119 | 120 | /* 121 | * ----------------------------------------------------------------------------- 122 | * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- 123 | */ 124 | 125 | #endif // LR_FHSS_V1_BASE_TYPES_H__ 126 | 127 | /* --- EOF ------------------------------------------------------------------ */ 128 | --------------------------------------------------------------------------------