Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/lora : Expose configurations to Kconfig #15007

Merged
merged 15 commits into from
Oct 2, 2020
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
24 changes: 13 additions & 11 deletions drivers/sx127x/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "timex.h"
#include "ztimer.h"
#include "thread.h"
#include "kernel_defines.h"

#include "periph/gpio.h"
#include "periph/spi.h"
Expand Down Expand Up @@ -171,17 +172,18 @@ void sx127x_init_radio_settings(sx127x_t *dev)
sx127x_set_channel(dev, SX127X_CHANNEL_DEFAULT);
sx127x_set_modem(dev, SX127X_MODEM_DEFAULT);
sx127x_set_tx_power(dev, SX127X_RADIO_TX_POWER);
sx127x_set_bandwidth(dev, LORA_BW_DEFAULT);
sx127x_set_spreading_factor(dev, LORA_SF_DEFAULT);
sx127x_set_coding_rate(dev, LORA_CR_DEFAULT);
sx127x_set_bandwidth(dev, CONFIG_LORA_BW_DEFAULT);
sx127x_set_spreading_factor(dev, CONFIG_LORA_SF_DEFAULT);
sx127x_set_coding_rate(dev, CONFIG_LORA_CR_DEFAULT);
sx127x_set_crc(dev, LORA_PAYLOAD_CRC_ON_DEFAULT);
sx127x_set_freq_hop(dev, LORA_FREQUENCY_HOPPING_DEFAULT);
sx127x_set_hop_period(dev, LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT);
sx127x_set_fixed_header_len_mode(dev, LORA_FIXED_HEADER_LEN_MODE_DEFAULT);
sx127x_set_iq_invert(dev, LORA_IQ_INVERTED_DEFAULT);
sx127x_set_payload_length(dev, LORA_PAYLOAD_LENGTH_DEFAULT);
sx127x_set_preamble_length(dev, LORA_PREAMBLE_LENGTH_DEFAULT);
sx127x_set_symbol_timeout(dev, LORA_SYMBOL_TIMEOUT_DEFAULT);
sx127x_set_freq_hop(dev, IS_ACTIVE(CONFIG_LORA_FREQUENCY_HOPPING_DEFAULT) ? true : false);
sx127x_set_hop_period(dev, CONFIG_LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT);
sx127x_set_fixed_header_len_mode(dev, IS_ACTIVE(CONFIG_LORA_FIXED_HEADER_LEN_MODE_DEFAULT) ?
true : false);
sx127x_set_iq_invert(dev, IS_ACTIVE(CONFIG_LORA_IQ_INVERTED_DEFAULT) ? true : false);
sx127x_set_payload_length(dev, CONFIG_LORA_PAYLOAD_LENGTH_DEFAULT);
sx127x_set_preamble_length(dev, CONFIG_LORA_PREAMBLE_LENGTH_DEFAULT);
sx127x_set_symbol_timeout(dev, CONFIG_LORA_SYMBOL_TIMEOUT_DEFAULT);
sx127x_set_rx_single(dev, SX127X_RX_SINGLE);
sx127x_set_tx_timeout(dev, SX127X_TX_TIMEOUT_DEFAULT);
}
Expand Down Expand Up @@ -292,7 +294,7 @@ static int _init_gpios(sx127x_t *dev)
}
else {
/* if frequency hopping is enabled, DIO2 pin must be defined */
assert(LORA_FREQUENCY_HOPPING_DEFAULT == false);
assert(!IS_ACTIVE(CONFIG_LORA_FREQUENCY_HOPPING_DEFAULT));
}

/* check if DIO3 pin is defined */
Expand Down
173 changes: 137 additions & 36 deletions sys/include/net/lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <stdint.h>
#include <stdlib.h>

#include "kernel_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -38,66 +40,165 @@ extern "C" {
#define LORA_FREQUENCY_RESOLUTION_DEFAULT (61.03515625)
#endif

/** @brief Preamble length, same for Tx and Rx */
#ifndef LORA_PREAMBLE_LENGTH_DEFAULT
#define LORA_PREAMBLE_LENGTH_DEFAULT (8U)
/** @brief Preamble length, same for Tx and Rx
*
* Configure preamble used in LoRa frame. Each LoRa frame begins with a
* preamble. It starts with a series of upchirps to cover the whole frequency
* band of the particular channel assigned. The last two upchirps encode the
* sync word. Sync word is used to differentiate between LoRa transmissions that
* use the same frequency bands. The sync word is followed by two and a quarter
* downchirps, for a duration of 2.25 symbols. The total duration of this
* preamble can be configured between 10.25 and 65,539.25 symbol hence the value
* can range from 8 to 65537.
*/
#ifndef CONFIG_LORA_PREAMBLE_LENGTH_DEFAULT
#define CONFIG_LORA_PREAMBLE_LENGTH_DEFAULT (8U)
#endif

/** @brief Symbols timeout (s) */
#ifndef LORA_SYMBOL_TIMEOUT_DEFAULT
#define LORA_SYMBOL_TIMEOUT_DEFAULT (10U)
/** @brief Symbol timeout period in symbols
*
* Configure symbol time out in terms of number of symbols. One symbol has a
* length in time of (2^SF)/BW seconds.
*/
#ifndef CONFIG_LORA_SYMBOL_TIMEOUT_DEFAULT
#define CONFIG_LORA_SYMBOL_TIMEOUT_DEFAULT (10U)
#endif

/** @brief Set default bandwidth to 125kHz */
#ifndef LORA_BW_DEFAULT
#define LORA_BW_DEFAULT (LORA_BW_125_KHZ)
/** @brief Set channel bandwidth
*
* Configure the channel bandwidth. Refer to country specific regulation on
* channel usage to identify the correct bandwidth.
*/
#if IS_ACTIVE(CONFIG_LORA_BW_DEFAULT_125)
#define CONFIG_LORA_BW_DEFAULT (LORA_BW_125_KHZ)
#elif IS_ACTIVE(CONFIG_LORA_BW_DEFAULT_250)
#define CONFIG_LORA_BW_DEFAULT (LORA_BW_250_KHZ)
#elif IS_ACTIVE(CONFIG_LORA_BW_DEFAULT_500)
#define CONFIG_LORA_BW_DEFAULT (LORA_BW_500_KHZ)
#endif

/** @brief Set default spreading factor to 12 */
#ifndef LORA_SF_DEFAULT
#define LORA_SF_DEFAULT (LORA_SF12)
#ifndef CONFIG_LORA_BW_DEFAULT
#define CONFIG_LORA_BW_DEFAULT (LORA_BW_125_KHZ)
#endif

/** @brief Set default coding rate to 8 */
#ifndef LORA_CR_DEFAULT
#define LORA_CR_DEFAULT (LORA_CR_4_8)
/** @brief Set Spreading Factor (SF)
*
* Configure Spreading Factor (SF). SF denotes the amount of spreading code
* applied to the original data signal. A larger SF increases the time on air,
* which increases energy consumption, reduces the data rate, and improves
* communication range. Each step up in spreading factor effectively doubles the
* time on air to transmit the same amount of data. Refer to country specific
* air time usage regulations before varying the SF. To calculate air time refer
* https://www.loratools.nl/#/airtime .
*/
#if IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF6)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF6)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF7)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF7)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF8)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF8)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF9)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF9)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF10)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF10)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF11)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF11)
#elif IS_ACTIVE(CONFIG_LORA_SF_DEFAULT_SF12)
#define CONFIG_LORA_SF_DEFAULT (LORA_SF12)
#endif

/** @brief Set fixed payload length on */
#ifndef LORA_FIX_LENGTH_PAYLOAD_ON_DEFAULT
#define LORA_FIX_LENGTH_PAYLOAD_ON_DEFAULT (false)
#ifndef CONFIG_LORA_SF_DEFAULT
#define CONFIG_LORA_SF_DEFAULT (LORA_SF7)
#endif

/** @brief Set inverted IQ on */
#ifndef LORA_IQ_INVERTED_DEFAULT
#define LORA_IQ_INVERTED_DEFAULT (false)
/** @brief Set Coding Rate (CR)
*
* Configure Coding Rate (CR). CR denotes the implementation of forward error
* correction (FEC). This may be done by encoding 4-bit data with redundancies
* into 5-bit, 6-bit, 7-bit, or 8-bit. Coding Rate (CR) value need to be
* adjusted according to conditions of the channel used for data transmission.
* If there are too many interferences in the channel, then it’s recommended to
* increase the value of CR. However, the rise in CR value will also increase
* the duration for the transmission. Refer to country specific air time usage
* regulations before varying the CR. To calculate air time refer
* https://www.loratools.nl/#/airtime .
*/
#if IS_ACTIVE(CONFIG_LORA_CR_DEFAULT_CR_4_5)
#define CONFIG_LORA_CR_DEFAULT (LORA_CR_4_5)
#elif IS_ACTIVE(CONFIG_LORA_CR_DEFAULT_CR_4_6)
#define CONFIG_LORA_CR_DEFAULT (LORA_CR_4_6)
#elif IS_ACTIVE(CONFIG_LORA_CR_DEFAULT_CR_4_7)
#define CONFIG_LORA_CR_DEFAULT (LORA_CR_4_7)
#elif IS_ACTIVE(CONFIG_LORA_CR_DEFAULT_CR_4_8)
#define CONFIG_LORA_CR_DEFAULT (LORA_CR_4_8)
#endif

/** @brief Frequency hopping on */
#ifndef LORA_FREQUENCY_HOPPING_DEFAULT
#define LORA_FREQUENCY_HOPPING_DEFAULT (false)
#ifndef CONFIG_LORA_CR_DEFAULT
#define CONFIG_LORA_CR_DEFAULT (LORA_CR_4_5)
#endif

/** @brief Frequency hopping period */
#ifndef LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT
#define LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT (0U)
/** @brief Set this to 1 to enable inverted I/Q mode
*
* Enable this to invert the IQ signals used in RF modulation circuit. For more
* information on I/Q modulation technique visit http://www.ni.com/tutorial/4805/en/
*/
#ifdef DOXYGEN
#define CONFIG_LORA_IQ_INVERTED_DEFAULT
#endif

/** @brief Set fixed header length mode (implicit header) */
#ifndef LORA_FIXED_HEADER_LEN_MODE_DEFAULT
#define LORA_FIXED_HEADER_LEN_MODE_DEFAULT (false)
/** @brief Set this to 1 to enable frequency hopping
*
* If Frequency hopping spread spectrum (FHSS) is enabled a portion of each LoRa
* packet is transmitted on each hopping channel from a look up table of
* frequencies managed by the host microcontroller.
*/
#ifdef DOXYGEN
#define CONFIG_LORA_FREQUENCY_HOPPING_DEFAULT
#endif

/** @brief Enable payload CRC, optional */
#ifndef LORA_PAYLOAD_CRC_ON_DEFAULT
#define LORA_PAYLOAD_CRC_ON_DEFAULT (true)
/** @brief Frequency hopping period in symbols
*
* Configure the hopping period, in symbols, time which each transmission will
* dwell in any given channel. One symbol has a length in time of (2^SF)/BW
* seconds.
*/
#ifndef CONFIG_LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT
#define CONFIG_LORA_FREQUENCY_HOPPING_PERIOD_DEFAULT (0U)
#endif

/** @brief Set payload length, unused with implicit header */
#ifndef LORA_PAYLOAD_LENGTH_DEFAULT
#define LORA_PAYLOAD_LENGTH_DEFAULT (0U)
/** @brief Set this to 1 to enable fixed header length mode (implicit header)
*
* If fixed header length mode ( implicit header mode) is enabled, PHY header
* (`PHDR`) in LoRa frame is discarded. For more information, refer to the
* section "LoRa frame structure" in this
* <a href="https://link.springer.com/article/10.1186/s13638-019-1542-x">publication</a>
*/
#ifdef DOXYGEN
#define CONFIG_LORA_FIXED_HEADER_LEN_MODE_DEFAULT
#endif

/** @brief Enable/disable payload CRC, optional
*
* @deprecated Use inverse `CONFIG_LORA_PAYLOAD_CRC_OFF_DEFAULT` instead.
* Will be removed after 2021.04 release.
*/
#ifndef LORA_PAYLOAD_CRC_ON_DEFAULT
#if IS_ACTIVE(CONFIG_LORA_PAYLOAD_CRC_OFF_DEFAULT)
#define LORA_PAYLOAD_CRC_ON_DEFAULT (false)
#else
#define LORA_PAYLOAD_CRC_ON_DEFAULT (true)
#endif
#endif

/** @brief Configure payload length
*
* Configure the length of payload. The configuration is unused when using
* explicit header mode ( @ref CONFIG_LORA_FIXED_HEADER_LEN_MODE_DEFAULT ) as
* `PHDR` carries the length information.
*/
#ifndef CONFIG_LORA_PAYLOAD_LENGTH_DEFAULT
#define CONFIG_LORA_PAYLOAD_LENGTH_DEFAULT (0U)
#endif
/** @} */

/**
Expand Down
1 change: 1 addition & 0 deletions sys/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rsource "credman/Kconfig"
rsource "gnrc/Kconfig"
rsource "sock/Kconfig"
rsource "link_layer/Kconfig"
rsource "lora/Kconfig"
rsource "netif/Kconfig"

endmenu # Networking
Loading