Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions SX126X/SX126X_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-3-Clause
*/

#include <math.h>
#include "ThisThread.h"
#include "mbed_wait_api.h"
#include "Timer.h"
#include "SX126X_LoRaRadio.h"
Expand All @@ -34,8 +33,12 @@ SPDX-License-Identifier: BSD-3-Clause
#define SPI_FREQUENCY 16000000
#endif

using namespace mbed;
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/ThisThread.h"
using namespace rtos;
#endif

using namespace mbed;

#ifdef MBED_CONF_RTOS_PRESENT
/**
Expand Down Expand Up @@ -203,7 +206,8 @@ bool SX126X_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
receive();

// hold on a bit, radio turn-around time
ThisThread::sleep_for(1);
delay(1);


Timer elapsed_time;
elapsed_time.start();
Expand Down Expand Up @@ -504,10 +508,10 @@ void SX126X_LoRaRadio::radio_reset()
_reset_ctl.output();
_reset_ctl = 0;
// should be enough, required is 50-100 us
ThisThread::sleep_for(2);
delay(2);
_reset_ctl.input();
// give some time for automatic image calibration
ThisThread::sleep_for(6);
delay(6);
}

void SX126X_LoRaRadio::wakeup()
Expand Down Expand Up @@ -541,7 +545,7 @@ void SX126X_LoRaRadio::sleep(void)
#endif

write_opmode_command(RADIO_SET_SLEEP, &sleep_state, 1);
ThisThread::sleep_for(2);
delay(2);
}

uint32_t SX126X_LoRaRadio::random(void)
Expand All @@ -553,7 +557,7 @@ uint32_t SX126X_LoRaRadio::random(void)
_reception_mode = RECEPTION_MODE_OTHER;
_rx_timeout = 0xFFFFFFFF;
receive();
ThisThread::sleep_for(1);
delay(1);
read_register(RANDOM_NUMBER_GENERATORBASEADDR, buf, 4);
standby();

Expand Down Expand Up @@ -596,6 +600,15 @@ void SX126X_LoRaRadio::read_opmode_command(uint8_t cmd,
_chip_select = 1;
}

void SX126X_LoRaRadio::delay(uint ms)
{
#ifdef MBED_CONF_RTOS_PRESENT
ThisThread::sleep_for(ms);
#else
wait_ms(ms);
#endif
}

void SX126X_LoRaRadio::write_to_register(uint16_t addr, uint8_t data)
{
write_to_register(addr, &data, 1);
Expand Down
1 change: 1 addition & 0 deletions SX126X/SX126X_LoRaRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class SX126X_LoRaRadio : public LoRaRadio {
void set_device_ready(void);
int8_t get_rssi();
uint8_t get_fsk_bw_reg_val(uint32_t bandwidth);
void delay(uint ms);
void write_to_register(uint16_t addr, uint8_t data);
void write_to_register(uint16_t addr, uint8_t *data, uint8_t size);
uint8_t read_register(uint16_t addr);
Expand Down
35 changes: 25 additions & 10 deletions SX1272/SX1272_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ SPDX-License-Identifier: BSD-3-Clause
#include "sx1272Regs-Fsk.h"
#include "sx1272Regs-LoRa.h"

#include "rtos/ThisThread.h"
#include "platform/Callback.h"
#include "drivers/Timer.h"
#include "platform/mbed_wait_api.h"

#include <math.h> //rint

using namespace mbed;
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/ThisThread.h"
using namespace rtos;
#endif

using namespace mbed;

#ifdef MBED_CONF_SX1272_LORA_DRIVER_SPI_FREQUENCY
#define SPI_FREQUENCY MBED_CONF_SX1272_LORA_DRIVER_SPI_FREQUENCY
Expand Down Expand Up @@ -384,9 +387,9 @@ void SX1272_LoRaRadio::radio_reset()
{
_reset_ctl.output();
_reset_ctl = 0;
ThisThread::sleep_for(2);
delay(2);
_reset_ctl.input();
ThisThread::sleep_for(6);
delay(6);
}

/**
Expand Down Expand Up @@ -721,7 +724,7 @@ void SX1272_LoRaRadio::send(uint8_t *buffer, uint8_t size)
// FIFO operations can not take place in Sleep mode
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
standby();
ThisThread::sleep_for(1);
delay(1);
}

if (_rf_settings.fsk.fix_len == false) {
Expand Down Expand Up @@ -771,7 +774,7 @@ void SX1272_LoRaRadio::send(uint8_t *buffer, uint8_t size)
// FIFO operations can not take place in Sleep mode
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
standby();
ThisThread::sleep_for(1);
delay(1);
}
// write payload buffer
write_fifo(buffer, size);
Expand Down Expand Up @@ -1044,7 +1047,7 @@ bool SX1272_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
set_operation_mode(RF_OPMODE_RECEIVER);

// hold on a bit, radio turn-around time
ThisThread::sleep_for(1);
delay(1);

Timer elapsed_time;
elapsed_time.start();
Expand Down Expand Up @@ -1162,7 +1165,7 @@ uint32_t SX1272_LoRaRadio::random()
set_operation_mode(RF_OPMODE_RECEIVER);

for (i = 0; i < 32; i++) {
ThisThread::sleep_for(1);
delay(1);
// Unfiltered RSSI value reading. Only takes the LSB value
rnd |= ((uint32_t) read_register(REG_LR_RSSIWIDEBAND) & 0x01) << i;
}
Expand Down Expand Up @@ -1212,6 +1215,18 @@ void SX1272_LoRaRadio::rf_irq_task(void)
}
#endif

/**
* delay
*/
void SX1272_LoRaRadio::delay(uint ms)
{
#ifdef MBED_CONF_RTOS_PRESENT
ThisThread::sleep_for(ms);
#else
wait_ms(ms);
#endif
}

/**
* Writes a single byte to a given register
*/
Expand Down Expand Up @@ -1452,14 +1467,14 @@ void SX1272_LoRaRadio::set_sx1272_variant_type()
{
if (_rf_ctrls.ant_switch != NC) {
_ant_switch.input();
ThisThread::sleep_for(1);
delay(1);
if (_ant_switch == 1) {
radio_variant = SX1272MB1DCS;
} else {
radio_variant = SX1272MB2XAS;
}
_ant_switch.output();
ThisThread::sleep_for(1);
delay(1);
} else {
radio_variant = MBED_CONF_SX1272_LORA_DRIVER_RADIO_VARIANT;
}
Expand Down
1 change: 1 addition & 0 deletions SX1272/SX1272_LoRaRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class SX1272_LoRaRadio: public LoRaRadio {
void set_rf_tx_power(int8_t power);
int16_t get_rssi(radio_modems_t modem);
uint8_t get_fsk_bw_reg_val(uint32_t bandwidth);
void delay(uint ms);
void write_to_register(uint8_t addr, uint8_t data);
void write_to_register(uint8_t addr, uint8_t *data, uint8_t size);
uint8_t read_register(uint8_t addr);
Expand Down
31 changes: 23 additions & 8 deletions SX1276/SX1276_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ SPDX-License-Identifier: BSD-3-Clause
#include "platform/Callback.h"
#include "platform/mbed_wait_api.h"
#include "drivers/Timer.h"
#include "rtos/ThisThread.h"

#include "SX1276_LoRaRadio.h"
#include "sx1276Regs-Fsk.h"
#include "sx1276Regs-LoRa.h"

#include <math.h> //rint

#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/ThisThread.h"
using namespace rtos;
#endif

using namespace mbed;

/*!
Expand Down Expand Up @@ -286,9 +289,9 @@ void SX1276_LoRaRadio::radio_reset()
{
_reset_ctl.output();
_reset_ctl = 0;
ThisThread::sleep_for(2);
delay(2);
_reset_ctl.input();
ThisThread::sleep_for(6);
delay(6);
}

/**
Expand Down Expand Up @@ -355,7 +358,7 @@ uint32_t SX1276_LoRaRadio::random(void)
set_operation_mode(RF_OPMODE_RECEIVER);

for (i = 0; i < 32; i++) {
ThisThread::sleep_for(1);
delay(1);
// Unfiltered RSSI value reading. Only takes the LSB value
rnd |= ((uint32_t) read_register(REG_LR_RSSIWIDEBAND) & 0x01) << i;
}
Expand Down Expand Up @@ -803,7 +806,7 @@ void SX1276_LoRaRadio::send(uint8_t *buffer, uint8_t size)
// FIFO operations can not take place in Sleep mode
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
standby();
ThisThread::sleep_for(1);
delay(1);
}
// write_to_register payload buffer
write_fifo(buffer, size);
Expand Down Expand Up @@ -1023,7 +1026,7 @@ bool SX1276_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
set_operation_mode(RF_OPMODE_RECEIVER);

// hold on a bit, radio turn-around time
ThisThread::sleep_for(1);
delay(1);

Timer elapsed_time;
elapsed_time.start();
Expand Down Expand Up @@ -1181,6 +1184,18 @@ void SX1276_LoRaRadio::rf_irq_task(void)
}
#endif

/**
* delay
*/
void SX1276_LoRaRadio::delay(uint ms)
{
#ifdef MBED_CONF_RTOS_PRESENT
ThisThread::sleep_for(ms);
#else
wait_ms(ms);
#endif
}

/**
* Writes a single byte to a given register
*/
Expand Down Expand Up @@ -1325,14 +1340,14 @@ void SX1276_LoRaRadio::set_sx1276_variant_type()
{
if (_rf_ctrls.ant_switch != NC) {
_ant_switch.input();
ThisThread::sleep_for(1);
delay(1);
if (_ant_switch == 1) {
radio_variant = SX1276MB1LAS;
} else {
radio_variant = SX1276MB1MAS;
}
_ant_switch.output();
ThisThread::sleep_for(1);
delay(1);
} else {
radio_variant = MBED_CONF_SX1276_LORA_DRIVER_RADIO_VARIANT;
}
Expand Down
1 change: 1 addition & 0 deletions SX1276/SX1276_LoRaRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class SX1276_LoRaRadio: public LoRaRadio {
void set_rf_tx_power(int8_t power);
int16_t get_rssi(radio_modems_t modem);
uint8_t get_fsk_bw_reg_val(uint32_t bandwidth);
void delay(uint ms);
void write_to_register(uint8_t addr, uint8_t data);
void write_to_register(uint8_t addr, uint8_t *data, uint8_t size);
uint8_t read_register(uint8_t addr);
Expand Down