SingingCat 0
application
Data Structures | Macros | Typedefs | Enumerations | Functions
sx126x.c File Reference

SX126x radio driver implementation. More...

#include "sx1262/sx126x.h"
#include "sx1262/sx126x_hal.h"
#include "sx1262/sx126x_regs.h"

Go to the source code of this file.

Data Structures

struct  gfsk_bw_t
 

Macros

#define SX126X_PLL_STEP_SCALED   (SX126X_XTAL_FREQ >> (25 - SX126X_PLL_STEP_SHIFT_AMOUNT))
 PLL step - scaled with SX126X_PLL_STEP_SHIFT_AMOUNT. More...
 
#define SX126X_PLL_STEP_SHIFT_AMOUNT   (14)
 Scaling factor used to perform fixed-point operations. More...
 
#define SX126X_RTC_FREQ_IN_HZ   64000UL
 Internal frequency of the radio. More...
 
#define SX126X_XTAL_FREQ   32000000UL
 Internal frequency of the radio. More...
 

Typedefs

typedef enum sx126x_commands_size_e sx126x_commands_size_t
 
typedef enum sx126x_commands_e sx126x_commands_t
 

Enumerations

enum  sx126x_commands_e {
  SX126X_SET_SLEEP = 0x84 , SX126X_SET_STANDBY = 0x80 , SX126X_SET_FS = 0xC1 , SX126X_SET_TX = 0x83 ,
  SX126X_SET_RX = 0x82 , SX126X_SET_STOP_TIMER_ON_PREAMBLE = 0x9F , SX126X_SET_RX_DUTY_CYCLE = 0x94 , SX126X_SET_CAD = 0xC5 ,
  SX126X_SET_TX_CONTINUOUS_WAVE = 0xD1 , SX126X_SET_TX_INFINITE_PREAMBLE = 0xD2 , SX126X_SET_REGULATOR_MODE = 0x96 , SX126X_CALIBRATE = 0x89 ,
  SX126X_CALIBRATE_IMAGE = 0x98 , SX126X_SET_PA_CFG = 0x95 , SX126X_SET_RX_TX_FALLBACK_MODE = 0x93 , SX126X_WRITE_REGISTER = 0x0D ,
  SX126X_READ_REGISTER = 0x1D , SX126X_WRITE_BUFFER = 0x0E , SX126X_READ_BUFFER = 0x1E , SX126X_SET_DIO_IRQ_PARAMS = 0x08 ,
  SX126X_GET_IRQ_STATUS = 0x12 , SX126X_CLR_IRQ_STATUS = 0x02 , SX126X_SET_DIO2_AS_RF_SWITCH_CTRL = 0x9D , SX126X_SET_DIO3_AS_TCXO_CTRL = 0x97 ,
  SX126X_SET_RF_FREQUENCY = 0x86 , SX126X_SET_PKT_TYPE = 0x8A , SX126X_GET_PKT_TYPE = 0x11 , SX126X_SET_TX_PARAMS = 0x8E ,
  SX126X_SET_MODULATION_PARAMS = 0x8B , SX126X_SET_PKT_PARAMS = 0x8C , SX126X_SET_CAD_PARAMS = 0x88 , SX126X_SET_BUFFER_BASE_ADDRESS = 0x8F ,
  SX126X_SET_LORA_SYMB_NUM_TIMEOUT = 0xA0 , SX126X_GET_STATUS = 0xC0 , SX126X_GET_RX_BUFFER_STATUS = 0x13 , SX126X_GET_PKT_STATUS = 0x14 ,
  SX126X_GET_RSSI_INST = 0x15 , SX126X_GET_STATS = 0x10 , SX126X_RESET_STATS = 0x00 , SX126X_GET_DEVICE_ERRORS = 0x17 ,
  SX126X_CLR_DEVICE_ERRORS = 0x07
}
 
enum  sx126x_commands_size_e {
  SX126X_SIZE_SET_SLEEP = 2 , SX126X_SIZE_SET_STANDBY = 2 , SX126X_SIZE_SET_FS = 1 , SX126X_SIZE_SET_TX = 4 ,
  SX126X_SIZE_SET_RX = 4 , SX126X_SIZE_SET_STOP_TIMER_ON_PREAMBLE = 2 , SX126X_SIZE_SET_RX_DUTY_CYCLE = 7 , SX126X_SIZE_SET_CAD = 1 ,
  SX126X_SIZE_SET_TX_CONTINUOUS_WAVE = 1 , SX126X_SIZE_SET_TX_INFINITE_PREAMBLE = 1 , SX126X_SIZE_SET_REGULATOR_MODE = 2 , SX126X_SIZE_CALIBRATE = 2 ,
  SX126X_SIZE_CALIBRATE_IMAGE = 3 , SX126X_SIZE_SET_PA_CFG = 5 , SX126X_SIZE_SET_RX_TX_FALLBACK_MODE = 2 , SX126X_SIZE_WRITE_REGISTER = 3 ,
  SX126X_SIZE_READ_REGISTER = 4 , SX126X_SIZE_WRITE_BUFFER = 2 , SX126X_SIZE_READ_BUFFER = 3 , SX126X_SIZE_SET_DIO_IRQ_PARAMS = 9 ,
  SX126X_SIZE_GET_IRQ_STATUS = 2 , SX126X_SIZE_CLR_IRQ_STATUS = 3 , SX126X_SIZE_SET_DIO2_AS_RF_SWITCH_CTRL = 2 , SX126X_SIZE_SET_DIO3_AS_TCXO_CTRL = 5 ,
  SX126X_SIZE_SET_RF_FREQUENCY = 5 , SX126X_SIZE_SET_PKT_TYPE = 2 , SX126X_SIZE_GET_PKT_TYPE = 3 , SX126X_SIZE_SET_TX_PARAMS = 3 ,
  SX126X_SIZE_SET_MODULATION_PARAMS_GFSK = 9 , SX126X_SIZE_SET_MODULATION_PARAMS_LORA = 5 , SX126X_SIZE_SET_PKT_PARAMS_GFSK = 10 , SX126X_SIZE_SET_PKT_PARAMS_LORA = 7 ,
  SX126X_SIZE_SET_CAD_PARAMS = 8 , SX126X_SIZE_SET_BUFFER_BASE_ADDRESS = 3 , SX126X_SIZE_SET_LORA_SYMB_NUM_TIMEOUT = 2 , SX126X_SIZE_GET_STATUS = 1 ,
  SX126X_SIZE_GET_RX_BUFFER_STATUS = 2 , SX126X_SIZE_GET_PKT_STATUS = 2 , SX126X_SIZE_GET_RSSI_INST = 2 , SX126X_SIZE_GET_STATS = 2 ,
  SX126X_SIZE_RESET_STATS = 7 , SX126X_SIZE_GET_DEVICE_ERRORS = 2 , SX126X_SIZE_CLR_DEVICE_ERRORS = 3 , SX126X_SIZE_MAX_BUFFER = 255 ,
  SX126X_SIZE_DUMMY_BYTE = 1
}
 

Functions

sx126x_status_t sx126x_cal (struct network_context *nctx, const sx126x_cal_mask_t param)
 Perform the calibration of the requested blocks. More...
 
sx126x_status_t sx126x_cal_img (struct network_context *nctx, const uint32_t freq_in_hz)
 Perform device operating frequency band image rejection calibration. More...
 
sx126x_status_t sx126x_cfg_rx_boosted (struct network_context *nctx, const bool state)
 Configure the boost mode in reception. More...
 
sx126x_status_t sx126x_cfg_tx_clamp (struct network_context *nctx)
 Configure the Tx PA clamp. More...
 
sx126x_status_t sx126x_clear_device_errors (struct network_context *nctx)
 Clear all active errors. More...
 
sx126x_status_t sx126x_clear_irq_status (struct network_context *nctx, const sx126x_irq_mask_t irq_mask)
 Clear selected system interrupts. More...
 
uint32_t sx126x_convert_freq_in_hz_to_pll_step (uint32_t freq_in_hz)
 Get the number of PLL steps for a given frequency in Hertz. More...
 
uint32_t sx126x_convert_timeout_in_ms_to_rtc_step (uint32_t timeout_in_ms)
 Get the number of RTC steps for a given timeout in millisecond. More...
 
sx126x_status_t sx126x_get_and_clear_irq_status (struct network_context *nctx, sx126x_irq_mask_t *irq)
 Clears any radio irq status flags that are set and returns the flags that were cleared. More...
 
sx126x_status_t sx126x_get_device_errors (struct network_context *nctx, sx126x_errors_mask_t *errors)
 Get the list of all active errors. More...
 
sx126x_status_t sx126x_get_irq_status (struct network_context *nctx, sx126x_irq_mask_t *irq)
 Get system interrupt status. More...
 
uint32_t sx126x_get_lora_bw_in_hz (sx126x_lora_bw_t bw)
 Get the actual value in Hertz of a given LoRa bandwidth. More...
 
sx126x_status_t sx126x_get_lora_pkt_status (struct network_context *nctx, sx126x_pkt_status_lora_t *pkt_status)
 Get the status of the last LoRa packet received. More...
 
sx126x_status_t sx126x_get_lora_stats (struct network_context *nctx, sx126x_stats_lora_t *stats)
 Get the statistics about LoRa communication. More...
 
uint32_t sx126x_get_lora_time_on_air_in_ms (const sx126x_pkt_params_lora_t *pkt_p, const sx126x_mod_params_lora_t *mod_p)
 Get the time on air in ms for LoRa transmission. More...
 
uint32_t sx126x_get_lora_time_on_air_numerator (const sx126x_pkt_params_lora_t *pkt_p, const sx126x_mod_params_lora_t *mod_p)
 Compute the numerator for LoRa time-on-air computation. More...
 
sx126x_status_t sx126x_get_pkt_type (struct network_context *nctx, sx126x_pkt_type_t *pkt_type)
 Get the current packet type. More...
 
sx126x_status_t sx126x_get_random_numbers (struct network_context *nctx, uint32_t *numbers, unsigned int n)
 Generate one or more 32-bit random numbers. More...
 
sx126x_status_t sx126x_get_rssi_inst (struct network_context *nctx, int16_t *rssi_in_dbm)
 Get the instantaneous RSSI value. More...
 
sx126x_status_t sx126x_get_rx_buffer_status (struct network_context *nctx, sx126x_rx_buffer_status_t *rx_buffer_status)
 Get the current Rx buffer status for both LoRa and GFSK Rx operations. More...
 
sx126x_status_t sx126x_get_status (struct network_context *nctx, sx126x_chip_status_t *radio_status)
 Get the chip status. More...
 
sx126x_status_t sx126x_read_buffer (struct network_context *nctx, const uint8_t offset, uint8_t *buffer, const uint8_t size)
 Read data from radio Rx buffer memory space. More...
 
sx126x_status_t sx126x_read_register (struct network_context *nctx, const uint16_t address, uint8_t *buffer, const uint8_t size)
 Read data from register memory space. More...
 
sx126x_status_t sx126x_reset (struct network_context *nctx)
 Perform a hard reset of the chip. More...
 
sx126x_status_t sx126x_reset_stats (struct network_context *nctx)
 Reset all the statistics for both Lora and GFSK communications. More...
 
sx126x_status_t sx126x_set_buffer_base_address (struct network_context *nctx, const uint8_t tx_base_address, const uint8_t rx_base_address)
 Set buffer start addresses for both Tx and Rx operations. More...
 
sx126x_status_t sx126x_set_cad (struct network_context *nctx)
 Set the chip in CAD (Channel Activity Detection) mode. More...
 
sx126x_status_t sx126x_set_cad_params (struct network_context *nctx, const sx126x_cad_params_t *params)
 Set the parameters for CAD operation. More...
 
sx126x_status_t sx126x_set_dio2_as_rf_sw_ctrl (struct network_context *nctx, const bool enable)
 Configure the embedded RF switch control. More...
 
sx126x_status_t sx126x_set_dio3_as_tcxo_ctrl (struct network_context *nctx, const sx126x_tcxo_ctrl_voltages_t tcxo_voltage, const uint32_t timeout)
 Configure the embedded TCXO switch control. More...
 
sx126x_status_t sx126x_set_dio_irq_params (struct network_context *nctx, const uint16_t irq_mask, const uint16_t dio1_mask, const uint16_t dio2_mask, const uint16_t dio3_mask)
 Set which interrupt signals are redirected to the dedicated DIO pin. More...
 
sx126x_status_t sx126x_set_lora_mod_params (struct network_context *nctx, const sx126x_mod_params_lora_t *params)
 Set the modulation parameters for LoRa packets. More...
 
sx126x_status_t sx126x_set_lora_pkt_params (struct network_context *nctx, const sx126x_pkt_params_lora_t *params)
 Set the packet parameters for LoRa packets. More...
 
sx126x_status_t sx126x_set_lora_symb_nb_timeout (struct network_context *nctx, const uint8_t nb_of_symbs)
 
sx126x_status_t sx126x_set_lora_sync_word (struct network_context *nctx, const uint8_t sync_word)
 Configure the sync word used in LoRa packet. More...
 
sx126x_status_t sx126x_set_pa_cfg (struct network_context *nctx, const sx126x_pa_cfg_params_t *params)
 Configure the PA (Power Amplifier) More...
 
sx126x_status_t sx126x_set_pkt_type (struct network_context *nctx, const sx126x_pkt_type_t pkt_type)
 Set the packet type. More...
 
sx126x_status_t sx126x_set_reg_mode (struct network_context *nctx, const sx126x_reg_mod_t mode)
 Configure the regulator mode to be used. More...
 
sx126x_status_t sx126x_set_rf_freq (struct network_context *nctx, const uint32_t freq_in_hz)
 Set the RF frequency for future radio operations. More...
 
sx126x_status_t sx126x_set_rf_freq_in_pll_steps (struct network_context *nctx, const uint32_t freq)
 Set the RF frequency for future radio operations - parameter in PLL steps. More...
 
sx126x_status_t sx126x_set_rx (struct network_context *nctx, const uint32_t timeout_in_ms)
 Set the chip in reception mode. More...
 
sx126x_status_t sx126x_set_rx_duty_cycle_with_timings_in_rtc_step (struct network_context *nctx, const uint32_t rx_time_in_rtc_step, const uint32_t sleep_time_in_rtc_step)
 Set the chip in reception mode with duty cycling. More...
 
sx126x_status_t sx126x_set_rx_tx_fallback_mode (struct network_context *nctx, const sx126x_fallback_modes_t fallback_mode)
 Set chip mode to be used after successful transmission or reception. More...
 
sx126x_status_t sx126x_set_rx_with_timeout_in_rtc_step (struct network_context *nctx, const uint32_t timeout_in_rtc_step)
 Set the chip in reception mode. More...
 
sx126x_status_t sx126x_set_standby (struct network_context *nctx, const sx126x_standby_cfg_t cfg)
 Set the chip in stand-by mode. More...
 
sx126x_status_t sx126x_set_tx (struct network_context *nctx, const uint32_t timeout_in_ms)
 Set the chip in transmission mode. More...
 
sx126x_status_t sx126x_set_tx_params (struct network_context *nctx, const int8_t pwr_in_dbm, const sx126x_ramp_time_t ramp_time)
 Set the parameters for TX power and power amplifier ramp time. More...
 
sx126x_status_t sx126x_set_tx_with_timeout_in_rtc_step (struct network_context *nctx, const uint32_t timeout_in_rtc_step)
 Set the chip in transmission mode. More...
 
sx126x_status_t sx126x_write_buffer (struct network_context *nctx, const uint8_t offset, const uint8_t *buffer, const uint8_t size)
 Write data into radio Tx buffer memory space. More...
 
sx126x_status_t sx126x_write_register (struct network_context *nctx, const uint16_t address, const uint8_t *buffer, const uint8_t size)
 Write data into register memory space. More...
 

Detailed Description

SX126x radio driver implementation.

Revised BSD License Copyright Semtech Corporation 2020. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file sx126x.c.

Macro Definition Documentation

◆ SX126X_PLL_STEP_SCALED

#define SX126X_PLL_STEP_SCALED   (SX126X_XTAL_FREQ >> (25 - SX126X_PLL_STEP_SHIFT_AMOUNT))

PLL step - scaled with SX126X_PLL_STEP_SHIFT_AMOUNT.

Definition at line 70 of file sx126x.c.

◆ SX126X_PLL_STEP_SHIFT_AMOUNT

#define SX126X_PLL_STEP_SHIFT_AMOUNT   (14)

Scaling factor used to perform fixed-point operations.

Definition at line 65 of file sx126x.c.

◆ SX126X_RTC_FREQ_IN_HZ

#define SX126X_RTC_FREQ_IN_HZ   64000UL

Internal frequency of the radio.

Definition at line 60 of file sx126x.c.

◆ SX126X_XTAL_FREQ

#define SX126X_XTAL_FREQ   32000000UL

Internal frequency of the radio.

Definition at line 55 of file sx126x.c.

Typedef Documentation

◆ sx126x_commands_size_t

Commands Interface buffer sizes

◆ sx126x_commands_t

Commands Interface

Enumeration Type Documentation

◆ sx126x_commands_e

Commands Interface

Definition at line 80 of file sx126x.c.

◆ sx126x_commands_size_e

Commands Interface buffer sizes

Definition at line 133 of file sx126x.c.

Function Documentation

◆ sx126x_cal()

sx126x_status_t sx126x_cal ( struct network_context nctx,
const sx126x_cal_mask_t  param 
)

Perform the calibration of the requested blocks.

Remarks
This function shall only be called in stand-by RC mode
The chip will return to stand-by RC mode on exit. Potential calibration issues can be read out with sx126x_get_device_errors command.
Parameters
[in]contextChip implementation context.
[in]paramMask holding the blocks to be calibrated
Returns
Operation status

Definition at line 338 of file sx126x.c.

◆ sx126x_cal_img()

sx126x_status_t sx126x_cal_img ( struct network_context nctx,
const uint32_t  freq_in_hz 
)

Perform device operating frequency band image rejection calibration.

Parameters
[in]contextChip implementation context.
[in]freq_in_hzFrequency in Hz used for the image calibration
Returns
Operation status

Definition at line 348 of file sx126x.c.

◆ sx126x_cfg_rx_boosted()

sx126x_status_t sx126x_cfg_rx_boosted ( struct network_context nctx,
const bool  state 
)

Configure the boost mode in reception.

Remarks
This configuration is not kept in the retention memory. Rx boosted mode shall be enabled each time the chip leaves sleep mode.
Parameters
[in]contextChip implementation context.
[in]stateBoost mode activation
Returns
Operation status

Definition at line 1015 of file sx126x.c.

◆ sx126x_cfg_tx_clamp()

sx126x_status_t sx126x_cfg_tx_clamp ( struct network_context nctx)

Configure the Tx PA clamp.

Remarks
Workaround - On the SX1262, during the chip initialization, calling this function optimize the PA clamping threshold. The call must be done after a Power On Reset, or a wake-up from cold Start.(see DS_SX1261-2_V1.2 datasheet chapter 15.2)
Parameters
[in]contextChip implementation context.
Returns
Operation status

Definition at line 1041 of file sx126x.c.

◆ sx126x_clear_device_errors()

sx126x_status_t sx126x_clear_device_errors ( struct network_context nctx)

Clear all active errors.

Parameters
[in]contextChip implementation context.
Returns
Operation status

Definition at line 842 of file sx126x.c.

◆ sx126x_clear_irq_status()

sx126x_status_t sx126x_clear_irq_status ( struct network_context nctx,
const sx126x_irq_mask_t  irq_mask 
)

Clear selected system interrupts.

Parameters
[in]contextChip implementation context.
[in]irq_maskVariable that holds the system interrupt to be cleared
Returns
Operation status
See also
sx126x_get_irq_status

Definition at line 491 of file sx126x.c.

◆ sx126x_convert_freq_in_hz_to_pll_step()

uint32_t sx126x_convert_freq_in_hz_to_pll_step ( uint32_t  freq_in_hz)

Get the number of PLL steps for a given frequency in Hertz.

Parameters
[in]freq_in_hzFrequency in Hertz
Returns
Number of PLL steps

Definition at line 993 of file sx126x.c.

References SX126X_PLL_STEP_SCALED, and SX126X_PLL_STEP_SHIFT_AMOUNT.

◆ sx126x_convert_timeout_in_ms_to_rtc_step()

uint32_t sx126x_convert_timeout_in_ms_to_rtc_step ( uint32_t  timeout_in_ms)

Get the number of RTC steps for a given timeout in millisecond.

Parameters
[in]timeout_in_msTimeout in millisecond
Returns
Number of RTC steps

Definition at line 1007 of file sx126x.c.

References SX126X_RTC_FREQ_IN_HZ.

◆ sx126x_get_and_clear_irq_status()

sx126x_status_t sx126x_get_and_clear_irq_status ( struct network_context nctx,
sx126x_irq_mask_t *  irq 
)

Clears any radio irq status flags that are set and returns the flags that were cleared.

Parameters
[in]contextChip implementation context.
[out]irqPointer to a variable for holding the system interrupt status. Can be NULL.
Returns
Operation status

Definition at line 502 of file sx126x.c.

◆ sx126x_get_device_errors()

sx126x_status_t sx126x_get_device_errors ( struct network_context nctx,
sx126x_errors_mask_t *  errors 
)

Get the list of all active errors.

Parameters
[in]contextChip implementation context.
[out]errorsPointer to a variable to store the error list
Returns
Operation status

Definition at line 825 of file sx126x.c.

◆ sx126x_get_irq_status()

sx126x_status_t sx126x_get_irq_status ( struct network_context nctx,
sx126x_irq_mask_t *  irq 
)

Get system interrupt status.

Parameters
[in]contextChip implementation context.
[out]irqPointer to a variable for holding the system interrupt status
Returns
Operation status
See also
sx126x_clear_irq_status

Definition at line 474 of file sx126x.c.

◆ sx126x_get_lora_bw_in_hz()

uint32_t sx126x_get_lora_bw_in_hz ( sx126x_lora_bw_t  bw)

Get the actual value in Hertz of a given LoRa bandwidth.

Parameters
[in]bwLoRa bandwidth parameter
Returns
Actual LoRa bandwidth in Hertz

Definition at line 850 of file sx126x.c.

Referenced by sx126x_get_lora_time_on_air_in_ms().

◆ sx126x_get_lora_pkt_status()

sx126x_status_t sx126x_get_lora_pkt_status ( struct network_context nctx,
sx126x_pkt_status_lora_t pkt_status 
)

Get the status of the last LoRa packet received.

Parameters
[in]contextChip implementation context.
[out]pkt_statusPointer to a structure to store the packet status
Returns
Operation status

Definition at line 755 of file sx126x.c.

◆ sx126x_get_lora_stats()

sx126x_status_t sx126x_get_lora_stats ( struct network_context nctx,
sx126x_stats_lora_t stats 
)

Get the statistics about LoRa communication.

Parameters
[in]contextChip implementation context.
[out]statsPointer to a structure to store LoRa-related statistics
Returns
Operation status

Definition at line 791 of file sx126x.c.

◆ sx126x_get_lora_time_on_air_in_ms()

uint32_t sx126x_get_lora_time_on_air_in_ms ( const sx126x_pkt_params_lora_t pkt_p,
const sx126x_mod_params_lora_t mod_p 
)

Get the time on air in ms for LoRa transmission.

Parameters
[in]pkt_pPointer to a structure holding the LoRa packet parameters
[in]mod_pPointer to a structure holding the LoRa modulation parameters
Returns
Time-on-air value in ms for LoRa transmission

Definition at line 927 of file sx126x.c.

References sx126x_mod_params_lora_s::bw, sx126x_get_lora_bw_in_hz(), and sx126x_get_lora_time_on_air_numerator().

◆ sx126x_get_lora_time_on_air_numerator()

uint32_t sx126x_get_lora_time_on_air_numerator ( const sx126x_pkt_params_lora_t pkt_p,
const sx126x_mod_params_lora_t mod_p 
)

Compute the numerator for LoRa time-on-air computation.

Remarks
To get the actual time-on-air in second, this value has to be divided by the LoRa bandwidth in Hertz.
Parameters
[in]pkt_pPointer to the structure holding the LoRa packet parameters
[in]mod_pPointer to the structure holding the LoRa modulation parameters
Returns
LoRa time-on-air numerator

Definition at line 889 of file sx126x.c.

References sx126x_mod_params_lora_s::cr, sx126x_pkt_params_lora_s::crc_is_on, sx126x_pkt_params_lora_s::header_type, sx126x_mod_params_lora_s::ldro, sx126x_pkt_params_lora_s::pld_len_in_bytes, sx126x_pkt_params_lora_s::preamble_len_in_symb, sx126x_mod_params_lora_s::sf, and SX126X_LORA_PKT_IMPLICIT.

Referenced by sx126x_get_lora_time_on_air_in_ms().

◆ sx126x_get_pkt_type()

sx126x_status_t sx126x_get_pkt_type ( struct network_context nctx,
sx126x_pkt_type_t pkt_type 
)

Get the current packet type.

Parameters
[in]contextChip implementation context.
[out]pkt_typePointer to a variable holding the packet type
Returns
Operation status

Definition at line 574 of file sx126x.c.

◆ sx126x_get_random_numbers()

sx126x_status_t sx126x_get_random_numbers ( struct network_context nctx,
uint32_t *  numbers,
unsigned int  n 
)

Generate one or more 32-bit random numbers.

Remarks
A valid packet type must have been configured with sx126x_set_pkt_type before using this command.
Parameters
[in]contextChip implementation context.
[out]numbersArray where numbers will be stored.
[in]nNumber of desired random numbers.
Returns
Operation status

This code can potentially result in interrupt generation. It is the responsibility of the calling code to disable radio interrupts before calling this function, and re-enable them afterwards if necessary, or be certain that any interrupts generated during this process will not cause undesired side-effects in the software.

Please note that the random numbers produced by the generator do not have a uniform or Gaussian distribution. If uniformity is needed, perform appropriate software post-processing.

Definition at line 936 of file sx126x.c.

◆ sx126x_get_rssi_inst()

sx126x_status_t sx126x_get_rssi_inst ( struct network_context nctx,
int16_t *  rssi_in_dbm 
)

Get the instantaneous RSSI value.

Remarks
This function shall be called when in Rx mode.
Parameters
[in]contextChip implementation context.
[out]rssi_in_dbmPointer to a variable to store the RSSI value in dBm
Returns
Operation status
See also
sx126x_set_rx

Definition at line 774 of file sx126x.c.

◆ sx126x_get_rx_buffer_status()

sx126x_status_t sx126x_get_rx_buffer_status ( struct network_context nctx,
sx126x_rx_buffer_status_t rx_buffer_status 
)

Get the current Rx buffer status for both LoRa and GFSK Rx operations.

This function is used to get the length of the received payload and the start address to be used when reading data from the Rx buffer.

Parameters
[in]contextChip implementation context.
[out]rx_buffer_statusPointer to a structure to store the current status
Returns
Operation status

Definition at line 737 of file sx126x.c.

◆ sx126x_get_status()

sx126x_status_t sx126x_get_status ( struct network_context nctx,
sx126x_chip_status_t radio_status 
)

Get the chip status.

Parameters
[in]contextChip implementation context.
[out]radio_statusPointer to a structure holding the radio status
Returns
Operation status

Definition at line 718 of file sx126x.c.

◆ sx126x_read_buffer()

sx126x_status_t sx126x_read_buffer ( struct network_context nctx,
const uint8_t  offset,
uint8_t *  buffer,
const uint8_t  size 
)

Read data from radio Rx buffer memory space.

Parameters
[in]contextChip implementation context.
[in]offsetStart address in the Rx buffer of the chip
[in]bufferThe buffer of bytes to be filled with content from Rx radio buffer
[in]sizeThe number of bytes to read from the Rx radio buffer
Returns
Operation status
See also
sx126x_write_buffer

Definition at line 437 of file sx126x.c.

◆ sx126x_read_register()

sx126x_status_t sx126x_read_register ( struct network_context nctx,
const uint16_t  address,
uint8_t *  buffer,
const uint8_t  size 
)

Read data from register memory space.

Parameters
[in]contextChip implementation context.
[in]addressThe register memory address to start reading operation
[in]bufferThe buffer of bytes to be filled with data from registers
[in]sizeNumber of bytes to read from memory, starting from address
See also
sx126x_write_register

Definition at line 412 of file sx126x.c.

◆ sx126x_reset()

sx126x_status_t sx126x_reset ( struct network_context nctx)

Perform a hard reset of the chip.

Parameters
[in]contextChip implementation context.
Returns
Operation status

Definition at line 821 of file sx126x.c.

◆ sx126x_reset_stats()

sx126x_status_t sx126x_reset_stats ( struct network_context nctx)

Reset all the statistics for both Lora and GFSK communications.

Parameters
[in]contextChip implementation context.
Returns
Operation status

Definition at line 809 of file sx126x.c.

◆ sx126x_set_buffer_base_address()

sx126x_status_t sx126x_set_buffer_base_address ( struct network_context nctx,
const uint8_t  tx_base_address,
const uint8_t  rx_base_address 
)

Set buffer start addresses for both Tx and Rx operations.

Parameters
[in]contextChip implementation context.
[in]tx_base_addressThe start address used for Tx operations
[in]rx_base_addressThe start address used for Rx operations
Returns
Operation status

Definition at line 675 of file sx126x.c.

◆ sx126x_set_cad()

sx126x_status_t sx126x_set_cad ( struct network_context nctx)

Set the chip in CAD (Channel Activity Detection) mode.

Remarks
The LoRa packet type shall be selected with sx126x_set_pkt_type before this function is called.
The fallback mode is configured with sx126x_set_cad_params.
Parameters
[in]contextChip implementation context.
Returns
Operation status

Definition at line 320 of file sx126x.c.

◆ sx126x_set_cad_params()

sx126x_status_t sx126x_set_cad_params ( struct network_context nctx,
const sx126x_cad_params_t params 
)

Set the parameters for CAD operation.

Remarks
The command sx126x_set_pkt_type must be called prior to this one.
Parameters
[in]contextChip implementation context.
[in]paramsThe structure of CAD configuration
Returns
Operation status

Definition at line 659 of file sx126x.c.

◆ sx126x_set_dio2_as_rf_sw_ctrl()

sx126x_status_t sx126x_set_dio2_as_rf_sw_ctrl ( struct network_context nctx,
const bool  enable 
)

Configure the embedded RF switch control.

Parameters
[in]contextChip implementation context.
[in]enableEnable this feature if set to true
Returns
Operation status

Definition at line 516 of file sx126x.c.

◆ sx126x_set_dio3_as_tcxo_ctrl()

sx126x_status_t sx126x_set_dio3_as_tcxo_ctrl ( struct network_context nctx,
const sx126x_tcxo_ctrl_voltages_t  tcxo_voltage,
const uint32_t  timeout 
)

Configure the embedded TCXO switch control.

Remarks
This function shall only be called in standby RC mode.
The chip will wait for the timeout to happen before starting any operation that requires the TCXO.
Parameters
[in]contextChip implementation context.
[in]tcxo_voltageVoltage used to power the TCXO.
[in]timeoutTime needed for the TCXO to be stable.
Returns
Operation status

Definition at line 526 of file sx126x.c.

◆ sx126x_set_dio_irq_params()

sx126x_status_t sx126x_set_dio_irq_params ( struct network_context nctx,
const uint16_t  irq_mask,
const uint16_t  dio1_mask,
const uint16_t  dio2_mask,
const uint16_t  dio3_mask 
)

Set which interrupt signals are redirected to the dedicated DIO pin.

Remarks
By default, no interrupt signal is redirected.
An interrupt will not occur until it is enabled system-wide, even if it is redirected to a specific DIO.
The DIO pin will remain asserted until all redirected interrupt signals are cleared with a call to sx126x_clear_irq_status.
DIO2 and DIO3 are shared with other features. See sx126x_set_dio2_as_rf_sw_ctrl and sx126x_set_dio3_as_tcxo_ctrl
Parameters
[in]contextChip implementation context.
[in]irq_maskVariable that holds the system interrupt mask
[in]dio1_maskVariable that holds the interrupt mask for dio1
[in]dio2_maskVariable that holds the interrupt mask for dio2
[in]dio3_maskVariable that holds the interrupt mask for dio3
Returns
Operation status
See also
sx126x_clear_irq_status, sx126x_get_irq_status, sx126x_set_dio2_as_rf_sw_ctrl, sx126x_set_dio3_as_tcxo_ctrl

Definition at line 453 of file sx126x.c.

◆ sx126x_set_lora_mod_params()

sx126x_status_t sx126x_set_lora_mod_params ( struct network_context nctx,
const sx126x_mod_params_lora_t params 
)

Set the modulation parameters for LoRa packets.

Remarks
The command sx126x_set_pkt_type must be called prior to this one.
Parameters
[in]contextChip implementation context.
[in]paramsThe structure of LoRa modulation configuration
Returns
Operation status

Definition at line 600 of file sx126x.c.

◆ sx126x_set_lora_pkt_params()

sx126x_status_t sx126x_set_lora_pkt_params ( struct network_context nctx,
const sx126x_pkt_params_lora_t params 
)

Set the packet parameters for LoRa packets.

Remarks
The command sx126x_set_pkt_type must be called prior to this one.
Parameters
[in]contextChip implementation context.
[in]paramsThe structure of LoRa packet configuration
Returns
Operation status

Definition at line 624 of file sx126x.c.

◆ sx126x_set_lora_symb_nb_timeout()

sx126x_status_t sx126x_set_lora_symb_nb_timeout ( struct network_context nctx,
const uint8_t  nb_of_symbs 
)

Definition at line 687 of file sx126x.c.

◆ sx126x_set_lora_sync_word()

sx126x_status_t sx126x_set_lora_sync_word ( struct network_context nctx,
const uint8_t  sync_word 
)

Configure the sync word used in LoRa packet.

Remarks
In the case of a LoRaWAN use case, the two following values are specified:
  • 0x12 for a private LoRaWAN network (default)
  • 0x34 for a public LoRaWAN network
Parameters
[in]contextChip implementation context.
[in]sync_wordSync word to be configured
Returns
Operation status

Definition at line 1023 of file sx126x.c.

◆ sx126x_set_pa_cfg()

sx126x_status_t sx126x_set_pa_cfg ( struct network_context nctx,
const sx126x_pa_cfg_params_t params 
)

Configure the PA (Power Amplifier)

This command is used to differentiate the SX1261 from the SX1262 / SX1268. When using this command, the user selects the PA to be used by the device as well as its configuration.

Parameters
[in]contextChip implementation context.
[in]paramsPower amplifier configuration parameters
Returns
Operation status

Definition at line 373 of file sx126x.c.

◆ sx126x_set_pkt_type()

sx126x_status_t sx126x_set_pkt_type ( struct network_context nctx,
const sx126x_pkt_type_t  pkt_type 
)

Set the packet type.

Parameters
[in]contextChip implementation context.
[in]pkt_typePacket type to set
Returns
Operation status

Definition at line 564 of file sx126x.c.

◆ sx126x_set_reg_mode()

sx126x_status_t sx126x_set_reg_mode ( struct network_context nctx,
const sx126x_reg_mod_t  mode 
)

Configure the regulator mode to be used.

Remarks
This function shall be called to set the correct regulator mode, depending on the usage of LDO or DC/DC on the PCB implementation.
Parameters
[in]contextChip implementation context.
[in]modeRegulator mode configuration.
Returns
Operation status

Definition at line 328 of file sx126x.c.

◆ sx126x_set_rf_freq()

sx126x_status_t sx126x_set_rf_freq ( struct network_context nctx,
const uint32_t  freq_in_hz 
)

Set the RF frequency for future radio operations.

Remarks
This commands shall be called only after a packet type is selected.
Parameters
[in]contextChip implementation context.
[in]freq_in_hzThe frequency in Hz to set for radio operations
Returns
Operation status

Definition at line 545 of file sx126x.c.

◆ sx126x_set_rf_freq_in_pll_steps()

sx126x_status_t sx126x_set_rf_freq_in_pll_steps ( struct network_context nctx,
const uint32_t  freq 
)

Set the RF frequency for future radio operations - parameter in PLL steps.

Remarks
This commands shall be called only after a packet type is selected.
Parameters
[in]contextChip implementation context.
[in]freqThe frequency in PLL steps to set for radio operations
Returns
Operation status

Definition at line 551 of file sx126x.c.

◆ sx126x_set_rx()

sx126x_status_t sx126x_set_rx ( struct network_context nctx,
const uint32_t  timeout_in_ms 
)

Set the chip in reception mode.

Remarks
The packet type shall be configured with sx126x_set_pkt_type before using this command.
By default, the chip returns automatically to standby RC mode as soon as a packet is received or if no packet has been received before the timeout. This behavior can be altered by sx126x_set_rx_tx_fallback_mode.
The timeout argument can have the following special values:
Special values Meaning
SX126X_RX_SINGLE_MODE Single: the chip stays in RX mode until a reception occurs, then switch to standby RC
Parameters
[in]contextChip implementation context.
[in]timeout_in_msThe timeout configuration in millisecond for Rx operation
Returns
Operation status

Definition at line 280 of file sx126x.c.

◆ sx126x_set_rx_duty_cycle_with_timings_in_rtc_step()

sx126x_status_t sx126x_set_rx_duty_cycle_with_timings_in_rtc_step ( struct network_context nctx,
const uint32_t  rx_time_in_rtc_step,
const uint32_t  sleep_time_in_rtc_step 
)

Set the chip in reception mode with duty cycling.

Remarks
The Rx mode duration is defined by: $ rx\_duration\_ms = rx_time \times \frac{1}{64} $
The sleep mode duration is defined by: $ sleep\_duration\_ms = sleep_time \times \frac{1}{64} $
Maximal timeout value is 0xFFFFFF (i.e. 511 seconds).
Parameters
[in]contextChip implementation context.
[in]rx_timeThe timeout of Rx period
[in]sleep_timeThe length of sleep period
Returns
Operation status

Definition at line 302 of file sx126x.c.

◆ sx126x_set_rx_tx_fallback_mode()

sx126x_status_t sx126x_set_rx_tx_fallback_mode ( struct network_context nctx,
const sx126x_fallback_modes_t  fallback_mode 
)

Set chip mode to be used after successful transmission or reception.

Remarks
This setting is not taken into account during Rx Duty Cycle mode or Auto TxRx.
Parameters
[in]contextChip implementation context.
[in]fallback_modeSelected fallback mode
Returns
Operation status

Definition at line 386 of file sx126x.c.

◆ sx126x_set_rx_with_timeout_in_rtc_step()

sx126x_status_t sx126x_set_rx_with_timeout_in_rtc_step ( struct network_context nctx,
const uint32_t  timeout_in_rtc_step 
)

Set the chip in reception mode.

Remarks
The packet type shall be configured with sx126x_set_pkt_type before using this command.
By default, the chip returns automatically to standby RC mode as soon as a packet is received or if no packet has been received before the timeout. This behavior can be altered by sx126x_set_rx_tx_fallback_mode.
The timeout duration is obtained by: $ timeout\_duration\_ms = timeout_in_rtc_step \times \frac{1}{64} $
Maximal timeout value is SX126X_MAX_TIMEOUT_IN_RTC_STEP (i.e. 262 143 ms).
The timeout argument can have the following special values:
Special values Meaning
SX126X_RX_SINGLE_MODE Single: the chip stays in RX mode until a reception occurs, then switch to standby RC
SX126X_RX_CONTINUOUS Continuous: the chip stays in RX mode even after reception of a packet
Parameters
[in]contextChip implementation context.
[in]timeout_in_rtc_stepThe timeout configuration for Rx operation
Returns
Operation status

Definition at line 290 of file sx126x.c.

◆ sx126x_set_standby()

sx126x_status_t sx126x_set_standby ( struct network_context nctx,
const sx126x_standby_cfg_t  cfg 
)

Set the chip in stand-by mode.

Parameters
[in]contextChip implementation context.
[in]cfgStand-by mode configuration
Returns
Operation status

Definition at line 248 of file sx126x.c.

◆ sx126x_set_tx()

sx126x_status_t sx126x_set_tx ( struct network_context nctx,
const uint32_t  timeout_in_ms 
)

Set the chip in transmission mode.

Remarks
The packet type shall be configured with sx126x_set_pkt_type before using this command.
By default, the chip returns automatically to standby RC mode as soon as the packet is sent or if the packet has not been completely transmitted before the timeout. This behavior can be altered by sx126x_set_rx_tx_fallback_mode.
If the timeout argument is 0, then no timeout is used.
Parameters
[in]contextChip implementation context.
[in]timeout_in_msThe timeout configuration in millisecond for Tx operation
Returns
Operation status

Definition at line 258 of file sx126x.c.

◆ sx126x_set_tx_params()

sx126x_status_t sx126x_set_tx_params ( struct network_context nctx,
const int8_t  pwr_in_dbm,
const sx126x_ramp_time_t  ramp_time 
)

Set the parameters for TX power and power amplifier ramp time.

Parameters
[in]contextChip implementation context.
[in]pwr_in_dbmThe Tx output power in dBm
[in]ramp_timeThe ramping time configuration for the PA
Returns
Operation status

Definition at line 587 of file sx126x.c.

◆ sx126x_set_tx_with_timeout_in_rtc_step()

sx126x_status_t sx126x_set_tx_with_timeout_in_rtc_step ( struct network_context nctx,
const uint32_t  timeout_in_rtc_step 
)

Set the chip in transmission mode.

Remarks
The packet type shall be configured with sx126x_set_pkt_type before using this command.
By default, the chip returns automatically to standby RC mode as soon as the packet is sent or if the packet has not been completely transmitted before the timeout. This behavior can be altered by sx126x_set_rx_tx_fallback_mode.
The timeout duration can be computed with the formula: $ timeout\_duration\_ms = timeout_in_rtc_step \times * \frac{1}{64} $
Maximal value is SX126X_MAX_TIMEOUT_IN_RTC_STEP (i.e. 262 143 ms)
If the timeout argument is 0, then no timeout is used.
Parameters
[in]contextChip implementation context.
[in]timeout_in_rtc_stepThe timeout configuration for Tx operation
Returns
Operation status

Definition at line 268 of file sx126x.c.

◆ sx126x_write_buffer()

sx126x_status_t sx126x_write_buffer ( struct network_context nctx,
const uint8_t  offset,
const uint8_t *  buffer,
const uint8_t  size 
)

Write data into radio Tx buffer memory space.

Parameters
[in]contextChip implementation context.
[in]offsetStart address in the Tx buffer of the chip
[in]bufferThe buffer of bytes to write into radio buffer
[in]sizeThe number of bytes to write into Tx radio buffer
Returns
Operation status
See also
sx126x_read_buffer

Definition at line 426 of file sx126x.c.

◆ sx126x_write_register()

sx126x_status_t sx126x_write_register ( struct network_context nctx,
const uint16_t  address,
const uint8_t *  buffer,
const uint8_t  size 
)

Write data into register memory space.

Parameters
[in]contextChip implementation context.
[in]addressThe register memory address to start writing operation
[in]bufferThe buffer of bytes to write into memory.
[in]sizeNumber of bytes to write into memory, starting from address
See also
sx126x_read_register

Definition at line 400 of file sx126x.c.