From d3c6cfc0ee29774ee8985dc11d2f47d9af54ce3c Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Thu, 16 Apr 2020 00:29:41 +0100 Subject: [PATCH] drivers: lora: Add a continuous wave test API Add an API to transmit a continuous wave at a fixed frequency. This functionality is useful to test the radio in a lab setup. Signed-off-by: Andreas Sandberg --- drivers/lora/sx1276.c | 9 +++++++++ include/drivers/lora.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/lora/sx1276.c b/drivers/lora/sx1276.c index 26a4795f627..134549564d3 100644 --- a/drivers/lora/sx1276.c +++ b/drivers/lora/sx1276.c @@ -446,6 +446,13 @@ static int sx1276_lora_config(struct device *dev, return 0; } +static int sx1276_lora_test_cw(struct device *dev, u32_t frequency, + s8_t tx_power, u16_t duration) +{ + Radio.SetTxContinuousWave(frequency, tx_power, duration); + return 0; +} + /* Initialize Radio driver callbacks */ const struct Radio_s Radio = { .Init = SX1276Init, @@ -468,6 +475,7 @@ const struct Radio_s Radio = { .IrqProcess = NULL, .RxBoosted = NULL, .SetRxDutyCycle = NULL, + .SetTxContinuousWave = SX1276SetTxContinuousWave, }; static int sx1276_lora_init(struct device *dev) @@ -538,6 +546,7 @@ static const struct lora_driver_api sx1276_lora_api = { .config = sx1276_lora_config, .send = sx1276_lora_send, .recv = sx1276_lora_recv, + .test_cw = sx1276_lora_test_cw, }; DEVICE_AND_API_INIT(sx1276_lora, DT_INST_LABEL(0), diff --git a/include/drivers/lora.h b/include/drivers/lora.h index d15337cf8e0..b2cb016f731 100644 --- a/include/drivers/lora.h +++ b/include/drivers/lora.h @@ -75,10 +75,20 @@ typedef int (*lora_api_send)(struct device *dev, typedef int (*lora_api_recv)(struct device *dev, u8_t *data, u8_t size, k_timeout_t timeout, s16_t *rssi, s8_t *snr); +/** + * @typedef lora_api_test_cw() + * @brief Callback API for transmitting a continuous wave + * + * @see lora_test_cw() for argument descriptions. + */ +typedef int (*lora_api_test_cw)(struct device *dev, u32_t frequency, + s8_t tx_power, u16_t duration); + struct lora_driver_api { lora_api_config config; lora_api_send send; lora_api_recv recv; + lora_api_test_cw test_cw; }; /** @@ -139,4 +149,28 @@ static inline int lora_recv(struct device *dev, u8_t *data, u8_t size, return api->recv(dev, data, size, timeout, rssi, snr); } +/** + * @brief Transmit an unmodulated continuous wave at a given frequency + * + * @note Only use this functionality in a test setup where the + * transmission does not interfere with other devices. + * + * @param dev LoRa device + * @param frequency Output frequency (Hertz) + * @param tx_power TX power (dBm) + * @param duration Transmission duration in seconds. + * @return 0 on success, negative on error + */ +static inline int lora_test_cw(struct device *dev, u32_t frequency, + s8_t tx_power, u16_t duration) +{ + const struct lora_driver_api *api = dev->driver_api; + + if (!api->test_cw) { + return -ENOTSUP; + } + + return api->test_cw(dev, frequency, tx_power, duration); +} + #endif /* ZEPHYR_INCLUDE_DRIVERS_LORA_H_ */