![]() |
SX126x-Arduino
2.0.1
|
SX126x driver implementation. More...
#include <math.h>
#include <string.h>
#include "boards/mcu/board.h"
#include "sx126x.h"
#include "boards/sx126x/sx126x-board.h"
Data Structures | |
struct | RadioRegisters_t |
Radio registers definition. More... | |
Functions | |
void | SX126xOnDioIrq (void) |
DIO 0 IRQ callback. More... | |
void | SX126xSetPollingMode (void) |
DIO 0 IRQ callback. More... | |
void | SX126xSetInterruptMode (void) |
DIO 0 IRQ callback. More... | |
void | SX126xProcessIrqs (void) |
void | SX126xInit (DioIrqHandler dioIrq) |
Initializes the radio driver. More... | |
void | SX126xReInit (DioIrqHandler dioIrq) |
Re-Initializes the radio driver after CPU wakeup from deep sleep. More... | |
RadioOperatingModes_t | SX126xGetOperatingMode (void) |
Gets the current Operation Mode of the Radio. More... | |
void | SX126xSetOperatingMode (RadioOperatingModes_t mode) |
Sets/Updates the current Radio OperationMode variable. More... | |
void | SX126xCheckDeviceReady (void) |
Wakeup the radio if it is in Sleep mode and check that Busy is low. More... | |
void | SX126xSetPayload (uint8_t *payload, uint8_t size) |
Saves the payload to be send in the radio buffer. More... | |
uint8_t | SX126xGetPayload (uint8_t *buffer, uint8_t *size, uint8_t maxSize) |
Reads the payload received. If the received payload is longer than maxSize, then the method returns 1 and do not set size and payload. More... | |
void | SX126xSendPayload (uint8_t *payload, uint8_t size, uint32_t timeout) |
Sends a payload. More... | |
uint8_t | SX126xSetSyncWord (uint8_t *syncWord) |
Sets the Sync Word given by index used in GFSK. More... | |
void | SX126xSetCrcSeed (uint16_t seed) |
Sets the seed value for the LFSR used for the CRC calculation. More... | |
void | SX126xSetCrcPolynomial (uint16_t polynomial) |
Sets the polynomial used for the CRC calculation. More... | |
void | SX126xSetWhiteningSeed (uint16_t seed) |
Sets the Initial value of the LFSR used for the whitening in GFSK protocols. More... | |
uint32_t | SX126xGetRandom (void) |
Gets a 32 bits random value generated by the radio. More... | |
void | SX126xSetSleep (SleepParams_t sleepConfig) |
Sets the radio in sleep mode. More... | |
void | SX126xSetStandby (RadioStandbyModes_t standbyConfig) |
Sets the radio in configuration mode. More... | |
void | SX126xSetFs (void) |
Sets the radio in FS mode. More... | |
void | SX126xSetTx (uint32_t timeout) |
Sets the radio in transmission mode. More... | |
void | SX126xSetRx (uint32_t timeout) |
Sets the radio in reception mode. More... | |
void | SX126xSetRxBoosted (uint32_t timeout) |
Sets the radio in reception mode with Boosted LNA gain. More... | |
void | SX126xSetRxDutyCycle (uint32_t rxTime, uint32_t sleepTime) |
Sets the Rx duty cycle management parameters. More... | |
void | SX126xSetCad (void) |
Sets the radio in CAD mode. More... | |
void | SX126xSetTxContinuousWave (void) |
Sets the radio in continuous wave transmission mode. More... | |
void | SX126xSetTxInfinitePreamble (void) |
Sets the radio in continuous preamble transmission mode. More... | |
void | SX126xSetStopRxTimerOnPreambleDetect (bool enable) |
Decide which interrupt will stop the internal radio rx timer. More... | |
void | SX126xSetLoRaSymbNumTimeout (uint8_t SymbNum) |
Set the number of symbol the radio will wait to validate a reception. More... | |
void | SX126xSetRegulatorMode (RadioRegulatorMode_t mode) |
Sets the power regulators operating mode. More... | |
void | SX126xCalibrate (CalibrationParams_t calibParam) |
Calibrates the given radio block. More... | |
void | SX126xCalibrateImage (uint32_t freq) |
Calibrates the Image rejection depending of the frequency. More... | |
void | SX126xSetPaConfig (uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut) |
Sets the transmission parameters. More... | |
void | SX126xSetRxTxFallbackMode (uint8_t fallbackMode) |
Defines into which mode the chip goes after a TX / RX done. More... | |
void | SX126xSetDioIrqParams (uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) |
Sets the IRQ mask and DIO masks. More... | |
uint16_t | SX126xGetIrqStatus (void) |
Returns the current IRQ status. More... | |
void | SX126xSetDio2AsRfSwitchCtrl (uint8_t enable) |
Indicates if DIO2 is used to control an RF Switch. More... | |
void | SX126xSetDio3AsTcxoCtrl (RadioTcxoCtrlVoltage_t tcxoVoltage, uint32_t timeout) |
Indicates if the Radio main clock is supplied from a tcxo. More... | |
void | SX126xSetRfFrequency (uint32_t frequency) |
Sets the RF frequency. More... | |
void | SX126xSetPacketType (RadioPacketTypes_t packetType) |
Sets the radio for the given protocol. More... | |
RadioPacketTypes_t | SX126xGetPacketType (void) |
Gets the current radio protocol. More... | |
void | SX126xSetTxParams (int8_t power, RadioRampTimes_t rampTime) |
Sets the transmission parameters. More... | |
void | SX126xSetModulationParams (ModulationParams_t *modulationParams) |
Set the modulation parameters. More... | |
void | SX126xSetPacketParams (PacketParams_t *packetParams) |
Sets the packet parameters. More... | |
void | SX126xSetCadParams (RadioLoRaCadSymbols_t cadSymbolNum, uint8_t cadDetPeak, uint8_t cadDetMin, RadioCadExitModes_t cadExitMode, uint32_t cadTimeout) |
Sets the Channel Activity Detection (CAD) parameters. More... | |
void | SX126xSetBufferBaseAddress (uint8_t txBaseAddress, uint8_t rxBaseAddress) |
Sets the data buffer base address for transmission and reception. More... | |
RadioStatus_t | SX126xGetStatus (void) |
Gets the current radio status. More... | |
int8_t | SX126xGetRssiInst (void) |
Returns the instantaneous RSSI value for the last packet received. More... | |
void | SX126xGetRxBufferStatus (uint8_t *payloadLength, uint8_t *rxStartBufferPointer) |
Gets the last received packet buffer status. More... | |
void | SX126xGetPacketStatus (PacketStatus_t *pktStatus) |
Gets the last received packet payload length. More... | |
RadioError_t | SX126xGetDeviceErrors (void) |
Returns the possible system errors. More... | |
void | SX126xClearDeviceErrors (void) |
Clear all the errors in the device. More... | |
void | SX126xClearIrqStatus (uint16_t irq) |
Clears the IRQs. More... | |
Variables | |
static RadioOperatingModes_t | OperatingMode |
Holds the internal operating mode of the radio. More... | |
static RadioPacketTypes_t | PacketType |
Stores the current packet type set in the radio. More... | |
volatile uint32_t | FrequencyError = 0 |
Stores the last frequency error measured on LoRa received packet. More... | |
static bool | ImageCalibrated = false |
Hold the status of the Image calibration. More... | |
SX126x driver implementation.
void SX126xOnDioIrq | ( | void | ) |
DIO 0 IRQ callback.
void SX126xSetPollingMode | ( | void | ) |
DIO 0 IRQ callback.
void SX126xSetInterruptMode | ( | void | ) |
DIO 0 IRQ callback.
void SX126xProcessIrqs | ( | void | ) |
void SX126xInit | ( | DioIrqHandler | dioIrq | ) |
Initializes the radio driver.
void SX126xReInit | ( | DioIrqHandler | dioIrq | ) |
Re-Initializes the radio driver after CPU wakeup from deep sleep.
RadioOperatingModes_t SX126xGetOperatingMode | ( | void | ) |
Gets the current Operation Mode of the Radio.
RadioOperatingModes_t | last operating mode |
void SX126xSetOperatingMode | ( | RadioOperatingModes_t | mode | ) |
Sets/Updates the current Radio OperationMode variable.
mode | New operating mode |
void SX126xCheckDeviceReady | ( | void | ) |
Wakeup the radio if it is in Sleep mode and check that Busy is low.
void SX126xSetPayload | ( | uint8_t * | payload, |
uint8_t | size | ||
) |
Saves the payload to be send in the radio buffer.
payload | A pointer to the payload |
size | The size of the payload |
uint8_t SX126xGetPayload | ( | uint8_t * | payload, |
uint8_t * | size, | ||
uint8_t | maxSize | ||
) |
Reads the payload received. If the received payload is longer than maxSize, then the method returns 1 and do not set size and payload.
payload | A pointer to a buffer into which the payload will be copied |
size | A pointer to the size of the payload received |
maxSize | The maximal size allowed to copy into the buffer |
void SX126xSendPayload | ( | uint8_t * | payload, |
uint8_t | size, | ||
uint32_t | timeout | ||
) |
Sends a payload.
payload | A pointer to the payload to send |
size | The size of the payload to send |
timeout | The timeout for Tx operation |
uint8_t SX126xSetSyncWord | ( | uint8_t * | syncWord | ) |
Sets the Sync Word given by index used in GFSK.
syncWord | SyncWord bytes ( 8 bytes ) |
status | [0: OK, 1: NOK] |
void SX126xSetCrcSeed | ( | uint16_t | seed | ) |
Sets the seed value for the LFSR used for the CRC calculation.
seed | Initial LFSR value ( 2 bytes ) |
void SX126xSetCrcPolynomial | ( | uint16_t | polynomial | ) |
Sets the polynomial used for the CRC calculation.
polynomial | The seed value |
void SX126xSetWhiteningSeed | ( | uint16_t | seed | ) |
Sets the Initial value of the LFSR used for the whitening in GFSK protocols.
seed | Initial LFSR value |
uint32_t SX126xGetRandom | ( | void | ) |
Gets a 32 bits random value generated by the radio.
randomValue | 32 bits random value |
void SX126xSetSleep | ( | SleepParams_t | sleepConfig | ) |
Sets the radio in sleep mode.
sleepConfig | The sleep configuration describing data retention and RTC wake-up |
void SX126xSetStandby | ( | RadioStandbyModes_t | mode | ) |
Sets the radio in configuration mode.
mode | The standby mode to put the radio into |
void SX126xSetFs | ( | void | ) |
Sets the radio in FS mode.
void SX126xSetTx | ( | uint32_t | timeout | ) |
Sets the radio in transmission mode.
timeout | Structure describing the transmission timeout value |
void SX126xSetRx | ( | uint32_t | timeout | ) |
Sets the radio in reception mode.
timeout | Structure describing the reception timeout value |
void SX126xSetRxBoosted | ( | uint32_t | timeout | ) |
Sets the radio in reception mode with Boosted LNA gain.
timeout | Structure describing the reception timeout value |
void SX126xSetRxDutyCycle | ( | uint32_t | rxTime, |
uint32_t | sleepTime | ||
) |
Sets the Rx duty cycle management parameters.
rxTime | Structure describing reception timeout value |
sleepTime | Structure describing sleep timeout value |
void SX126xSetCad | ( | void | ) |
Sets the radio in CAD mode.
void SX126xSetTxContinuousWave | ( | void | ) |
Sets the radio in continuous wave transmission mode.
void SX126xSetTxInfinitePreamble | ( | void | ) |
Sets the radio in continuous preamble transmission mode.
void SX126xSetStopRxTimerOnPreambleDetect | ( | bool | enable | ) |
Decide which interrupt will stop the internal radio rx timer.
enable | [0: Timer stop after header/syncword detection 1: Timer stop after preamble detection] |
void SX126xSetLoRaSymbNumTimeout | ( | uint8_t | SymbNum | ) |
Set the number of symbol the radio will wait to validate a reception.
SymbNum | number of LoRa symbols |
void SX126xSetRegulatorMode | ( | RadioRegulatorMode_t | mode | ) |
Sets the power regulators operating mode.
mode | [0: LDO, 1:DC_DC] |
void SX126xCalibrate | ( | CalibrationParams_t | calibParam | ) |
Calibrates the given radio block.
calibParam | The description of blocks to be calibrated |
void SX126xCalibrateImage | ( | uint32_t | freq | ) |
Calibrates the Image rejection depending of the frequency.
freq | The operating frequency |
void SX126xSetPaConfig | ( | uint8_t | paDutyCycle, |
uint8_t | hpMax, | ||
uint8_t | deviceSel, | ||
uint8_t | paLut | ||
) |
Sets the transmission parameters.
paDutyCycle | Duty Cycle for the PA |
hpMax | 0 for sx1261, 7 for sx1262 |
deviceSel | 1 for sx1261, 0 for sx1262 |
paLut | 0 for 14dBm LUT, 1 for 22dBm LUT |
void SX126xSetRxTxFallbackMode | ( | uint8_t | fallbackMode | ) |
Defines into which mode the chip goes after a TX / RX done.
fallbackMode | The mode in which the radio goes |
void SX126xSetDioIrqParams | ( | uint16_t | irqMask, |
uint16_t | dio1Mask, | ||
uint16_t | dio2Mask, | ||
uint16_t | dio3Mask | ||
) |
Sets the IRQ mask and DIO masks.
irqMask | General IRQ mask |
dio1Mask | DIO1 mask |
dio2Mask | DIO2 mask |
dio3Mask | DIO3 mask |
uint16_t SX126xGetIrqStatus | ( | void | ) |
Returns the current IRQ status.
irqStatus | IRQ status |
void SX126xSetDio2AsRfSwitchCtrl | ( | uint8_t | enable | ) |
Indicates if DIO2 is used to control an RF Switch.
enable | true of false |
void SX126xSetDio3AsTcxoCtrl | ( | RadioTcxoCtrlVoltage_t | tcxoVoltage, |
uint32_t | timeout | ||
) |
Indicates if the Radio main clock is supplied from a tcxo.
tcxoVoltage | voltage used to control the TCXO |
timeout | time given to the TCXO to go to 32MHz |
void SX126xSetRfFrequency | ( | uint32_t | frequency | ) |
Sets the RF frequency.
frequency | RF frequency [Hz] |
void SX126xSetPacketType | ( | RadioPacketTypes_t | packetType | ) |
Sets the radio for the given protocol.
packetType | [PACKET_TYPE_GFSK, PACKET_TYPE_LORA] |
RadioPacketTypes_t SX126xGetPacketType | ( | void | ) |
Gets the current radio protocol.
packetType | [PACKET_TYPE_GFSK, PACKET_TYPE_LORA] |
void SX126xSetTxParams | ( | int8_t | power, |
RadioRampTimes_t | rampTime | ||
) |
Sets the transmission parameters.
power | RF output power [-18..13] dBm |
rampTime | Transmission ramp up time |
void SX126xSetModulationParams | ( | ModulationParams_t * | modParams | ) |
Set the modulation parameters.
modParams | A structure describing the modulation parameters |
void SX126xSetPacketParams | ( | PacketParams_t * | packetParams | ) |
Sets the packet parameters.
packetParams | A structure describing the packet parameters |
void SX126xSetCadParams | ( | RadioLoRaCadSymbols_t | cadSymbolNum, |
uint8_t | cadDetPeak, | ||
uint8_t | cadDetMin, | ||
RadioCadExitModes_t | cadExitMode, | ||
uint32_t | cadTimeout | ||
) |
Sets the Channel Activity Detection (CAD) parameters.
cadSymbolNum | The number of symbol to use for CAD operations [LORA_CAD_01_SYMBOL, LORA_CAD_02_SYMBOL, LORA_CAD_04_SYMBOL, LORA_CAD_08_SYMBOL, LORA_CAD_16_SYMBOL] |
cadDetPeak | Limit for detection of SNR peak used in the CAD |
cadDetMin | Set the minimum symbol recognition for CAD |
cadExitMode | Operation to be done at the end of CAD action [LORA_CAD_ONLY, LORA_CAD_RX, LORA_CAD_LBT] |
cadTimeout | Defines the timeout value to abort the CAD activity |
void SX126xSetBufferBaseAddress | ( | uint8_t | txBaseAddress, |
uint8_t | rxBaseAddress | ||
) |
Sets the data buffer base address for transmission and reception.
txBaseAddress | Transmission base address |
rxBaseAddress | Reception base address |
RadioStatus_t SX126xGetStatus | ( | void | ) |
Gets the current radio status.
status | Radio status |
int8_t SX126xGetRssiInst | ( | void | ) |
Returns the instantaneous RSSI value for the last packet received.
rssiInst | Instantaneous RSSI |
void SX126xGetRxBufferStatus | ( | uint8_t * | payloadLength, |
uint8_t * | rxStartBuffer | ||
) |
Gets the last received packet buffer status.
payloadLength | Last received packet payload length |
rxStartBuffer | Last received packet buffer address pointer |
void SX126xGetPacketStatus | ( | PacketStatus_t * | pktStatus | ) |
Gets the last received packet payload length.
pktStatus | A structure of packet status |
RadioError_t SX126xGetDeviceErrors | ( | void | ) |
Returns the possible system errors.
sysErrors | Value representing the possible sys failures |
void SX126xClearDeviceErrors | ( | void | ) |
Clear all the errors in the device.
void SX126xClearIrqStatus | ( | uint16_t | irq | ) |
Clears the IRQs.
irq | IRQ(s) to be cleared |
|
static |
Holds the internal operating mode of the radio.
|
static |
Stores the current packet type set in the radio.
volatile uint32_t FrequencyError = 0 |
Stores the last frequency error measured on LoRa received packet.
|
static |
Hold the status of the Image calibration.