26 #ifndef SX1276_LORARADIO_H_ 27 #define SX1276_LORARADIO_H_ 32 #include "InterruptIn.h" 33 #include "DigitalOut.h" 34 #include "DigitalInOut.h" 36 #include "platform/PlatformMutex.h" 37 #ifdef MBED_CONF_RTOS_PRESENT 38 #include "rtos/Thread.h" 41 #include "lorawan/LoRaRadio.h" 43 #ifdef MBED_CONF_SX1276_LORA_DRIVER_BUFFER_SIZE 44 #define MAX_DATA_BUFFER_SIZE_SX1276 MBED_CONF_SX1276_LORA_DRIVER_BUFFER_SIZE 46 #define MAX_DATA_BUFFER_SIZE_SX1276 255 50 #include "LowPowerTimeout.h" 51 #define ALIAS_LORAWAN_TIMER mbed::LowPowerTimeout 54 #define ALIAS_LORAWAN_TIMER mbed::Timeout 84 PinName miso = MBED_CONF_SX1276_LORA_DRIVER_SPI_MISO,
85 PinName sclk = MBED_CONF_SX1276_LORA_DRIVER_SPI_SCLK,
86 PinName nss = MBED_CONF_SX1276_LORA_DRIVER_SPI_CS,
87 PinName reset = MBED_CONF_SX1276_LORA_DRIVER_RESET,
88 PinName dio0 = MBED_CONF_SX1276_LORA_DRIVER_DIO0,
89 PinName dio1 = MBED_CONF_SX1276_LORA_DRIVER_DIO1,
90 PinName dio2 = MBED_CONF_SX1276_LORA_DRIVER_DIO2,
91 PinName dio3 = MBED_CONF_SX1276_LORA_DRIVER_DIO3,
92 PinName dio4 = MBED_CONF_SX1276_LORA_DRIVER_DIO4,
93 PinName dio5 = MBED_CONF_SX1276_LORA_DRIVER_DIO5,
94 PinName rf_switch_ctl1 = MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL1,
95 PinName rf_switch_ctl2 = MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL2,
96 PinName txctl = MBED_CONF_SX1276_LORA_DRIVER_TXCTL,
97 PinName rxctl = MBED_CONF_SX1276_LORA_DRIVER_RXCTL,
98 PinName ant_switch = MBED_CONF_SX1276_LORA_DRIVER_ANT_SWITCH,
99 PinName pwr_amp_ctl = MBED_CONF_SX1276_LORA_DRIVER_PWR_AMP_CTL,
100 PinName tcxo = MBED_CONF_SX1276_LORA_DRIVER_TCXO
124 virtual void sleep(
void);
167 uint32_t datarate, uint8_t coderate,
168 uint32_t bandwidth_afc, uint16_t preamble_len,
169 uint16_t symb_timeout,
bool fix_len,
171 bool crc_on,
bool freq_hop_on, uint8_t hop_period,
172 bool iq_inverted,
bool rx_continuous);
204 uint32_t bandwidth, uint32_t datarate,
205 uint8_t coderate, uint16_t preamble_len,
206 bool fix_len,
bool crc_on,
bool freq_hop_on,
207 uint8_t hop_period,
bool iq_inverted, uint32_t timeout);
217 virtual void send(uint8_t *buffer, uint8_t size);
253 virtual uint32_t
random(
void);
308 int16_t rssi_threshold,
309 uint32_t max_carrier_sense_time);
335 virtual void lock(
void);
340 virtual void unlock(
void);
389 uint8_t _data_buffer[MAX_DATA_BUFFER_SIZE_SX1276];
395 ALIAS_LORAWAN_TIMER tx_timeout_timer;
397 #ifdef MBED_CONF_RTOS_PRESENT 405 uint8_t radio_variant;
408 void setup_registers();
409 void default_antenna_switch_ctrls();
410 void set_antenna_switch(uint8_t operation_mode);
414 void setup_interrupts();
415 void set_operation_mode(uint8_t operation_mode);
416 void set_low_power_mode();
417 void set_sx1276_variant_type();
418 uint8_t get_pa_conf_reg(uint32_t channel);
419 void set_rf_tx_power(int8_t power);
421 uint8_t get_fsk_bw_reg_val(uint32_t bandwidth);
422 void write_to_register(uint8_t addr, uint8_t data);
423 void write_to_register(uint8_t addr, uint8_t *data, uint8_t size);
424 uint8_t read_register(uint8_t addr);
425 void read_register(uint8_t addr, uint8_t *buffer, uint8_t size);
426 void write_fifo(uint8_t *buffer, uint8_t size);
427 void read_fifo(uint8_t *buffer, uint8_t size);
428 void transmit(uint32_t timeout);
429 void rf_irq_task(
void);
430 void set_modem(uint8_t modem);
431 void rx_chain_calibration(
void);
440 void timeout_irq_isr();
443 void handle_dio0_irq();
444 void handle_dio1_irq();
445 void handle_dio2_irq();
446 void handle_dio3_irq();
447 void handle_dio4_irq();
448 void handle_dio5_irq();
449 void handle_timeout_irq();
454 #endif // SX1276_LORARADIO_H_ The Thread class allow defining, creating, and controlling thread functions in the system...
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preamble_len, bool fix_len, bool crc_on, bool freq_hop_on, uint8_t hop_period, bool iq_inverted, uint32_t timeout)
Sets the transmission parameters.
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time)
Sets the radio in continuous wave transmission mode.
SX1276_LoRaRadio(PinName mosi=MBED_CONF_SX1276_LORA_DRIVER_SPI_MOSI, PinName miso=MBED_CONF_SX1276_LORA_DRIVER_SPI_MISO, PinName sclk=MBED_CONF_SX1276_LORA_DRIVER_SPI_SCLK, PinName nss=MBED_CONF_SX1276_LORA_DRIVER_SPI_CS, PinName reset=MBED_CONF_SX1276_LORA_DRIVER_RESET, PinName dio0=MBED_CONF_SX1276_LORA_DRIVER_DIO0, PinName dio1=MBED_CONF_SX1276_LORA_DRIVER_DIO1, PinName dio2=MBED_CONF_SX1276_LORA_DRIVER_DIO2, PinName dio3=MBED_CONF_SX1276_LORA_DRIVER_DIO3, PinName dio4=MBED_CONF_SX1276_LORA_DRIVER_DIO4, PinName dio5=MBED_CONF_SX1276_LORA_DRIVER_DIO5, PinName rf_switch_ctl1=MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL1, PinName rf_switch_ctl2=MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL2, PinName txctl=MBED_CONF_SX1276_LORA_DRIVER_TXCTL, PinName rxctl=MBED_CONF_SX1276_LORA_DRIVER_RXCTL, PinName ant_switch=MBED_CONF_SX1276_LORA_DRIVER_ANT_SWITCH, PinName pwr_amp_ctl=MBED_CONF_SX1276_LORA_DRIVER_PWR_AMP_CTL, PinName tcxo=MBED_CONF_SX1276_LORA_DRIVER_TCXO)
Use this constructor if pin definitions are provided manually.
virtual void start_cad(void)
Sets the radio in CAD mode.
enum modem_type radio_modems_t
Type of modem.
Structure to hold RF controls for LoRa Radio.
virtual void receive(uint32_t timeout)
For backwards compatibility.
virtual bool check_rf_frequency(uint32_t frequency)
Check if the given RF is in range.
virtual void unlock(void)
Release exclusive access.
virtual void standby(void)
Sets the radio in standby mode.
virtual bool perform_carrier_sense(radio_modems_t modem, uint32_t freq, int16_t rssi_threshold, uint32_t max_carrier_sense_time)
Perform carrier sensing.
A digital input/output, used for setting or reading a bi-directional pin.
virtual void radio_reset()
Resets the radio module.
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max)
Sets the maximum payload length.
virtual void set_public_network(bool enable)
Sets the network to public or private.
virtual void set_channel(uint32_t freq)
Sets the carrier frequency.
Reporting functions for upper layers.
virtual ~SX1276_LoRaRadio()
Destructor.
virtual void send(uint8_t *buffer, uint8_t size)
Sends the buffer of size.
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
Computes the packet time on air for the given payload.
virtual uint32_t random(void)
Generates a 32 bits random value based on the RSSI readings.
virtual uint8_t get_status(void)
Get radio status.
A digital interrupt input, used to call a function on a rising or falling edge.
A digital output, used for setting the state of a pin.
virtual void set_rx_config(radio_modems_t modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidth_afc, uint16_t preamble_len, uint16_t symb_timeout, bool fix_len, uint8_t payload_len, bool crc_on, bool freq_hop_on, uint8_t hop_period, bool iq_inverted, bool rx_continuous)
Sets the reception parameters.
A SPI Master, used for communicating with SPI slave devices.
virtual void init_radio(radio_events_t *events)
Registers radio events with the Mbed LoRaWAN stack and undergoes initialization steps if any...
virtual void lock(void)
Acquire exclusive access.
virtual void sleep(void)
Put the RF module in sleep mode.
Radio driver implementation for Semtech SX1272 plus variants.
Interface for the radios, containing the main functions that a radio needs, and five callback functio...
virtual void receive(void)
Sets the radio to receive.