Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lora.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Manivannan Sadhasivam
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11#ifndef ZEPHYR_INCLUDE_DRIVERS_LORA_H_
12#define ZEPHYR_INCLUDE_DRIVERS_LORA_H_
13
22#include <stdint.h>
23#include <zephyr/kernel.h>
24#include <zephyr/device.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
37};
38
43 SF_6 = 6,
50};
51
56 CR_4_5 = 1,
57 CR_4_6 = 2,
58 CR_4_7 = 3,
59 CR_4_8 = 4,
60};
61
69
72
75
78
81
84
86 bool tx;
87
96
107};
108
121typedef void (*lora_recv_cb)(const struct device *dev, uint8_t *data, uint16_t size,
122 int16_t rssi, int8_t snr);
123
130typedef int (*lora_api_config)(const struct device *dev,
131 struct lora_modem_config *config);
132
139typedef int (*lora_api_send)(const struct device *dev,
140 uint8_t *data, uint32_t data_len);
141
148typedef int (*lora_api_send_async)(const struct device *dev,
149 uint8_t *data, uint32_t data_len,
150 struct k_poll_signal *async);
151
158typedef int (*lora_api_recv)(const struct device *dev, uint8_t *data,
159 uint8_t size,
160 k_timeout_t timeout, int16_t *rssi, int8_t *snr);
161
169typedef int (*lora_api_recv_async)(const struct device *dev, lora_recv_cb cb);
170
177typedef int (*lora_api_test_cw)(const struct device *dev, uint32_t frequency,
178 int8_t tx_power, uint16_t duration);
179
180struct lora_driver_api {
181 lora_api_config config;
182 lora_api_send send;
183 lora_api_send_async send_async;
184 lora_api_recv recv;
185 lora_api_recv_async recv_async;
186 lora_api_test_cw test_cw;
187};
188
199static inline int lora_config(const struct device *dev,
200 struct lora_modem_config *config)
201{
202 const struct lora_driver_api *api =
203 (const struct lora_driver_api *)dev->api;
204
205 return api->config(dev, config);
206}
207
218static inline int lora_send(const struct device *dev,
219 uint8_t *data, uint32_t data_len)
220{
221 const struct lora_driver_api *api =
222 (const struct lora_driver_api *)dev->api;
223
224 return api->send(dev, data, data_len);
225}
226
241static inline int lora_send_async(const struct device *dev,
242 uint8_t *data, uint32_t data_len,
243 struct k_poll_signal *async)
244{
245 const struct lora_driver_api *api =
246 (const struct lora_driver_api *)dev->api;
247
248 return api->send_async(dev, data, data_len, async);
249}
250
265static inline int lora_recv(const struct device *dev, uint8_t *data,
266 uint8_t size,
267 k_timeout_t timeout, int16_t *rssi, int8_t *snr)
268{
269 const struct lora_driver_api *api =
270 (const struct lora_driver_api *)dev->api;
271
272 return api->recv(dev, data, size, timeout, rssi, snr);
273}
274
289static inline int lora_recv_async(const struct device *dev, lora_recv_cb cb)
290{
291 const struct lora_driver_api *api =
292 (const struct lora_driver_api *)dev->api;
293
294 return api->recv_async(dev, cb);
295}
296
309static inline int lora_test_cw(const struct device *dev, uint32_t frequency,
310 int8_t tx_power, uint16_t duration)
311{
312 const struct lora_driver_api *api =
313 (const struct lora_driver_api *)dev->api;
314
315 if (api->test_cw == NULL) {
316 return -ENOSYS;
317 }
318
319 return api->test_cw(dev, frequency, tx_power, duration);
320}
321
322#ifdef __cplusplus
323}
324#endif
325
330#endif /* ZEPHYR_INCLUDE_DRIVERS_LORA_H_ */
static ssize_t send(int sock, const void *buf, size_t len, int flags)
POSIX wrapper for zsock_send.
Definition: socket.h:882
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition: socket.h:888
static int lora_test_cw(const struct device *dev, uint32_t frequency, int8_t tx_power, uint16_t duration)
Transmit an unmodulated continuous wave at a given frequency.
Definition: lora.h:309
static int lora_recv(const struct device *dev, uint8_t *data, uint8_t size, k_timeout_t timeout, int16_t *rssi, int8_t *snr)
Receive data over LoRa.
Definition: lora.h:265
lora_datarate
LoRa data-rate.
Definition: lora.h:42
static int lora_send_async(const struct device *dev, uint8_t *data, uint32_t data_len, struct k_poll_signal *async)
Asynchronously send data over LoRa.
Definition: lora.h:241
static int lora_recv_async(const struct device *dev, lora_recv_cb cb)
Receive data asynchronously over LoRa.
Definition: lora.h:289
lora_coding_rate
LoRa coding rate.
Definition: lora.h:55
lora_signal_bandwidth
LoRa signal bandwidth.
Definition: lora.h:33
static int lora_config(const struct device *dev, struct lora_modem_config *config)
Configure the LoRa modem.
Definition: lora.h:199
static int lora_send(const struct device *dev, uint8_t *data, uint32_t data_len)
Send data over LoRa.
Definition: lora.h:218
@ SF_12
Definition: lora.h:49
@ SF_8
Definition: lora.h:45
@ SF_11
Definition: lora.h:48
@ SF_10
Definition: lora.h:47
@ SF_9
Definition: lora.h:46
@ SF_6
Definition: lora.h:43
@ SF_7
Definition: lora.h:44
@ CR_4_5
Definition: lora.h:56
@ CR_4_6
Definition: lora.h:57
@ CR_4_8
Definition: lora.h:59
@ CR_4_7
Definition: lora.h:58
@ BW_250_KHZ
Definition: lora.h:35
@ BW_125_KHZ
Definition: lora.h:34
@ BW_500_KHZ
Definition: lora.h:36
#define ENOSYS
Function not implemented.
Definition: errno.h:83
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT8_TYPE__ int8_t
Definition: stdint.h:72
__INT16_TYPE__ int16_t
Definition: stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
void * data
Address of the device instance private data.
Definition: device.h:397
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
Definition: kernel.h:5622
Kernel timeout type.
Definition: sys_clock.h:65
Structure containing the configuration of a LoRa modem.
Definition: lora.h:66
uint32_t frequency
Frequency in Hz to use for transceiving.
Definition: lora.h:68
enum lora_signal_bandwidth bandwidth
The bandwidth to use for transceiving.
Definition: lora.h:71
bool tx
Set to true for transmission, false for receiving.
Definition: lora.h:86
int8_t tx_power
TX-power in dBm to use for transmission.
Definition: lora.h:83
bool iq_inverted
Invert the In-Phase and Quadrature (IQ) signals.
Definition: lora.h:95
enum lora_coding_rate coding_rate
The coding rate to use for transceiving.
Definition: lora.h:77
uint16_t preamble_len
Length of the preamble.
Definition: lora.h:80
enum lora_datarate datarate
The data-rate to use for transceiving.
Definition: lora.h:74
bool public_network
Sets the sync-byte to use:
Definition: lora.h:106