Skip to content
Merged
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
72 changes: 1 addition & 71 deletions drivers/wireless/lpwan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,76 +28,6 @@ config LPWAN_SX127X
---help---
This options adds driver support for the Samtech SX127X chip.

if LPWAN_SX127X

config LPWAN_SX127X_RFFREQ_DEFAULT
int "SX127X default RF frequency"
default 433000000

config LPWAN_SX127X_SPIFREQ
int "SX127X SPI frequency"
default 1000000
---help---
SX127X SPI frequency up to 10MHz

config LPWAN_SX127X_TXPOWER_DEFAULT
int "SX127X default TX power"
default 14

config LPWAN_SX127X_PREAMBLE_DEFAULT
int "SX127X default preamble length"
default 8

config LPWAN_SX127X_MODULATION_DEFAULT
int "SX127X default modulation scheme"
default 3 if LPWAN_SX127X_LORA
default 1 if LPWAN_SX127X_FSKOOK
range 1 3
---help---
1 - FSK, 2 - OOK, 3 - LORA

config LPWAN_SX127X_CRCON
int "SX127X CRC ON"
range 0 1
default 0

config LPWAN_SX127X_RXSUPPORT
bool "SX127X RX support"
default n

if LPWAN_SX127X_RXSUPPORT

config LPWAN_SX127X_RXFIFO_LEN
int "SX127X RX FIFO length"
default 5

config LPWAN_SX127X_RXFIFO_DATA_LEN
int "SX127X RX FIFO data length"
default 64

endif #LPWAN_SX127X_RXSUPPORT

config LPWAN_SX127X_TXSUPPORT
bool "SX127X TX support"
default n

config LPWAN_SX127X_LORA
bool "SX127X LORA support"
default y

if LPWAN_SX127X_LORA

config LPWAN_SX127X_LORA_IMPHEADER
int "SX127X LORA implicit header ON"
range 0 1
default 0

endif # LPWAN_SX127X_LORA

config LPWAN_SX127X_FSKOOK
bool "SX127X FSK/OOK support"
default n

endif # WL_SX127X
source "drivers/wireless/lpwan/sx127x/Kconfig"

endif # DRIVERS_LPWAN
2 changes: 1 addition & 1 deletion drivers/wireless/lpwan/sx126x/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ config LPWAN_SX126X_MAX_DEVICES
int "SX126X maximum devices"
default 1

endif # DRIVERS_LPWAN
endif # LPWAN_SX126X
107 changes: 107 additions & 0 deletions drivers/wireless/lpwan/sx127x/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

if LPWAN_SX127X

config LPWAN_SX127X_RFFREQ_DEFAULT
int "SX127X default RF frequency"
default 433000000

config LPWAN_SX127X_SPIFREQ
int "SX127X SPI frequency"
default 1000000
---help---
SX127X SPI frequency up to 10MHz

config LPWAN_SX127X_TXPOWER_DEFAULT
int "SX127X default TX power"
default 14

config LPWAN_SX127X_PREAMBLE_DEFAULT
int "SX127X default preamble length"
default 8

config LPWAN_SX127X_MODULATION_DEFAULT
int "SX127X default modulation scheme"
default 3 if LPWAN_SX127X_LORA
default 1 if LPWAN_SX127X_FSKOOK
range 1 3
---help---
1 - FSK, 2 - OOK, 3 - LORA

config LPWAN_SX127X_CRCON
int "SX127X CRC ON"
range 0 1
default 0

config LPWAN_SX127X_RXSUPPORT
bool "SX127X RX support"
default n

if LPWAN_SX127X_RXSUPPORT

config LPWAN_SX127X_RXFIFO_LEN
int "SX127X RX FIFO length"
default 5

config LPWAN_SX127X_RXFIFO_DATA_LEN
int "SX127X RX FIFO data length"
default 64

config LPWAN_SX127X_RX_TIMEOUT
int "SX127X RX Timeout in Milliseconds"
default 10000
---help---
If device stopped receiving data for more than
LPWAN_SX127X_RX_TIMEOUT milliseconds it means the
frequency drift is too high that AFC failed to fix
the reception frequency. So if we leave the RX mode,
entering in standby and returning will clear the
AFC and fix the communication again.
If you don't want to use RX timeout set it to -1.

endif #LPWAN_SX127X_RXSUPPORT

config LPWAN_SX127X_TXSUPPORT
bool "SX127X TX support"
default n

config LPWAN_SX127X_LORA
bool "SX127X LORA support"
default y

if LPWAN_SX127X_LORA

config LPWAN_SX127X_LORA_IMPHEADER
int "SX127X LORA implicit header ON"
range 0 1
default 0

endif # LPWAN_SX127X_LORA

config LPWAN_SX127X_FSKOOK
bool "SX127X FSK/OOK support"
default n

if LPWAN_SX127X_FSKOOK

choice
prompt "SX127X Bitrate"
default LPWAN_SX127X_FSKOOK_4800

config LPWAN_SX127X_FSKOOK_4800
bool "4800 BPS"

config LPWAN_SX127X_FSKOOK_38400
bool "38400 BPS"

config LPWAN_SX127X_FSKOOK_76800
bool "76800 BPS"

endchoice

endif # LPWAN_SX127X_FSKOOK

endif # WL_SX127X
111 changes: 110 additions & 1 deletion drivers/wireless/lpwan/sx127x/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

#define SX127X_FREQ_CALIBRATION (CONFIG_LPWAN_SX127X_RFFREQ_DEFAULT)

#ifdef CONFIG_LPWAN_SX127X_FSKOOK_4800

/* FSK default frequency deviation is 5kHz */

#define SX127X_FDEV_DEFAULT (5000)
Expand All @@ -90,6 +92,42 @@
#define SX127X_FSKOOK_RXBW_DEFAULT FSKOOK_BANDWIDTH_15P6KHZ
#define SX127X_FSKOOK_AFCBW_DEFAULT FSKOOK_BANDWIDTH_20P8KHZ

#endif /* CONFIG_LPWAN_SX127X_FSKOOK_4800 */

#ifdef CONFIG_LPWAN_SX127X_FSKOOK_38400

/* FSK frequency deviation for 38400 is 20kHz */

#define SX127X_FDEV_DEFAULT (20000)

/* FSK/OOK bitrate default */

#define SX127X_FOM_BITRATE_DEFAULT (38400)

/* FSK/OOK bandwidth for 38400 */

#define SX127X_FSKOOK_RXBW_DEFAULT FSKOOK_BANDWIDTH_250KHZ
#define SX127X_FSKOOK_AFCBW_DEFAULT FSKOOK_BANDWIDTH_250KHZ

#endif /* CONFIG_LPWAN_SX127X_FSKOOK_38400 */

#ifdef CONFIG_LPWAN_SX127X_FSKOOK_76800

/* FSK frequency deviation for 76800 is 75kHz */

#define SX127X_FDEV_DEFAULT (75000)

/* FSK/OOK bitrate default */

#define SX127X_FOM_BITRATE_DEFAULT (76800)

/* FSK/OOK bandwidth for 76800 */

#define SX127X_FSKOOK_RXBW_DEFAULT FSKOOK_BANDWIDTH_250KHZ
#define SX127X_FSKOOK_AFCBW_DEFAULT FSKOOK_BANDWIDTH_250KHZ

#endif /* CONFIG_LPWAN_SX127X_FSKOOK_76800 */

/* Default LORA bandwidth */

#define SX127X_LRM_BW_DEFAULT LORA_BANDWIDTH_7P8KHZ
Expand Down Expand Up @@ -278,10 +316,12 @@ struct sx127x_dev_s
bool pa_force; /* Force PA BOOST pin select */
#endif
#ifdef CONFIG_LPWAN_SX127X_RXSUPPORT
uint32_t rx_timeout; /* RX timeout (not supported) */
uint32_t rx_timeout; /* RX timeout in milliseconds */
uint16_t rx_fifo_len; /* Number of bytes stored in fifo */
uint16_t nxt_read; /* Next read index */
uint16_t nxt_write; /* Next write index */
clock_t last_rx_tick; /* Ticks since last RX event to detect timeout */
struct work_s rx_watchdog; /* Watchdog to detect timeout */

/* Circular RX packet buffer */

Expand Down Expand Up @@ -1238,6 +1278,50 @@ static int sx127x_poll(FAR struct file *filep, FAR struct pollfd *fds,
#endif
}

/****************************************************************************
* Name: sx127x_rx_watchdog
*
* Description:
* Watchdog to detect SX127x RX communication stall
*
****************************************************************************/

#ifdef CONFIG_LPWAN_SX127X_RXSUPPORT
static void sx127x_rx_watchdog(FAR void *arg)
{
FAR struct sx127x_dev_s *dev = (FAR struct sx127x_dev_s *)arg;
clock_t now = clock_systime_ticks();

if (dev->opmode == SX127X_OPMODE_RX &&
(now - dev->last_rx_tick) > MSEC2TICK(dev->rx_timeout))
{
wlerr("RX stall detected, restarting RX\n");

/* Leave RX mode to clear AFC + bit sync */

sx127x_opmode_set(dev, SX127X_OPMODE_STANDBY);

/* datasheet-safe delay */

nxsched_usleep(100);

/* Re-enter RX */

sx127x_opmode_set(dev, SX127X_OPMODE_RX);

/* Avoid using old RX tick, otherwise it always will fail */

dev->last_rx_tick = now;
}

/* Reschedule watchdog */

work_queue(LPWORK, &dev->rx_watchdog,
sx127x_rx_watchdog, dev,
MSEC2TICK(dev->rx_timeout));
}
#endif

/****************************************************************************
* Name: sx127x_lora_isr0_process
*
Expand Down Expand Up @@ -1433,6 +1517,21 @@ static int sx127x_fskook_isr0_process(FAR struct sx127x_dev_s *dev)
ret = sx127x_fskook_rxhandle(dev);
if (ret > 0)
{
/* Should we take care of RX timeout? */

if (dev->rx_timeout > 0)
{
/* Keep a track of last RX time to detect timeout */

dev->last_rx_tick = clock_systime_ticks();

/* Prepare the work queue to take care of RX timeout */

work_queue(LPWORK, &dev->rx_watchdog,
sx127x_rx_watchdog, dev,
MSEC2TICK(dev->rx_timeout));
}

if (dev->pfd)
{
/* Data available for input */
Expand Down Expand Up @@ -4166,6 +4265,12 @@ static int sx127x_deinit(FAR struct sx127x_dev_s *dev)
{
wlinfo("Deinit sx127x dev\n");

#ifdef CONFIG_LPWAN_SX127X_RXSUPPORT
/* Cancel any running watchdog */

work_cancel(LPWORK, &dev->rx_watchdog);
#endif

/* Enter SLEEP mode */

sx127x_opmode_set(dev, SX127X_OPMODE_SLEEP);
Expand Down Expand Up @@ -4521,6 +4626,7 @@ static int sx127x_unregister(FAR struct sx127x_dev_s *dev)
nxsem_destroy(&dev->tx_sem);
#endif
#ifdef CONFIG_LPWAN_SX127X_RXSUPPORT
work_cancel(LPWORK, &dev->rx_watchdog);
nxsem_destroy(&dev->rx_sem);
nxmutex_destroy(&dev->rx_buffer_lock);
#endif
Expand Down Expand Up @@ -4576,6 +4682,9 @@ int sx127x_register(FAR struct spi_dev_s *spi,
dev->crcon = CONFIG_LPWAN_SX127X_CRCON;
#ifdef CONFIG_LPWAN_SX127X_FSKOOK
dev->fskook.fixlen = false;
# ifdef CONFIG_LPWAN_SX127X_RXSUPPORT
dev->rx_timeout = CONFIG_LPWAN_SX127X_RX_TIMEOUT;
# endif
#endif
#ifdef CONFIG_LPWAN_SX127X_LORA
dev->lora.invert_iq = false;
Expand Down
Loading