Zephyr API Documentation  3.7.0-rc3
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
24#include <stdint.h>
25#include <zephyr/kernel.h>
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
39};
40
45 SF_6 = 6,
52};
53
58 CR_4_5 = 1,
59 CR_4_6 = 2,
60 CR_4_7 = 3,
61 CR_4_8 = 4,
62};
63
71
74
77
80
83
86
88 bool tx;
89
98
109};
110
123typedef void (*lora_recv_cb)(const struct device *dev, uint8_t *data, uint16_t size,
124 int16_t rssi, int8_t snr);
125
132typedef int (*lora_api_config)(const struct device *dev,
133 struct lora_modem_config *config);
134
141typedef int (*lora_api_send)(const struct device *dev,
142 uint8_t *data, uint32_t data_len);
143
150typedef int (*lora_api_send_async)(const struct device *dev,
151 uint8_t *data, uint32_t data_len,
152 struct k_poll_signal *async);
153
160typedef int (*lora_api_recv)(const struct device *dev, uint8_t *data,
161 uint8_t size,
162 k_timeout_t timeout, int16_t *rssi, int8_t *snr);
163
171typedef int (*lora_api_recv_async)(const struct device *dev, lora_recv_cb cb);
172
179typedef int (*lora_api_test_cw)(const struct device *dev, uint32_t frequency,
180 int8_t tx_power, uint16_t duration);
181
182__subsystem struct lora_driver_api {
183 lora_api_config config;
184 lora_api_send send;
185 lora_api_send_async send_async;
186 lora_api_recv recv;
187 lora_api_recv_async recv_async;
188 lora_api_test_cw test_cw;
189};
190
201static inline int lora_config(const struct device *dev,
202 struct lora_modem_config *config)
203{
204 const struct lora_driver_api *api =
205 (const struct lora_driver_api *)dev->api;
206
207 return api->config(dev, config);
208}
209
220static inline int lora_send(const struct device *dev,
221 uint8_t *data, uint32_t data_len)
222{
223 const struct lora_driver_api *api =
224 (const struct lora_driver_api *)dev->api;
225
226 return api->send(dev, data, data_len);
227}
228
243static inline int lora_send_async(const struct device *dev,
244 uint8_t *data, uint32_t data_len,
245 struct k_poll_signal *async)
246{
247 const struct lora_driver_api *api =
248 (const struct lora_driver_api *)dev->api;
249
250 return api->send_async(dev, data, data_len, async);
251}
252
267static inline int lora_recv(const struct device *dev, uint8_t *data,
268 uint8_t size,
269 k_timeout_t timeout, int16_t *rssi, int8_t *snr)
270{
271 const struct lora_driver_api *api =
272 (const struct lora_driver_api *)dev->api;
273
274 return api->recv(dev, data, size, timeout, rssi, snr);
275}
276
291static inline int lora_recv_async(const struct device *dev, lora_recv_cb cb)
292{
293 const struct lora_driver_api *api =
294 (const struct lora_driver_api *)dev->api;
295
296 return api->recv_async(dev, cb);
297}
298
311static inline int lora_test_cw(const struct device *dev, uint32_t frequency,
312 int8_t tx_power, uint16_t duration)
313{
314 const struct lora_driver_api *api =
315 (const struct lora_driver_api *)dev->api;
316
317 if (api->test_cw == NULL) {
318 return -ENOSYS;
319 }
320
321 return api->test_cw(dev, frequency, tx_power, duration);
322}
323
324#ifdef __cplusplus
325}
326#endif
327
332#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:916
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition: socket.h:922
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:311
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:267
lora_datarate
LoRa data-rate.
Definition: lora.h:44
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:243
static int lora_recv_async(const struct device *dev, lora_recv_cb cb)
Receive data asynchronously over LoRa.
Definition: lora.h:291
lora_coding_rate
LoRa coding rate.
Definition: lora.h:57
lora_signal_bandwidth
LoRa signal bandwidth.
Definition: lora.h:35
static int lora_config(const struct device *dev, struct lora_modem_config *config)
Configure the LoRa modem.
Definition: lora.h:201
static int lora_send(const struct device *dev, uint8_t *data, uint32_t data_len)
Send data over LoRa.
Definition: lora.h:220
@ SF_12
Definition: lora.h:51
@ SF_8
Definition: lora.h:47
@ SF_11
Definition: lora.h:50
@ SF_10
Definition: lora.h:49
@ SF_9
Definition: lora.h:48
@ SF_6
Definition: lora.h:45
@ SF_7
Definition: lora.h:46
@ CR_4_5
Definition: lora.h:58
@ CR_4_6
Definition: lora.h:59
@ CR_4_8
Definition: lora.h:61
@ CR_4_7
Definition: lora.h:60
@ BW_250_KHZ
Definition: lora.h:37
@ BW_125_KHZ
Definition: lora.h:36
@ BW_500_KHZ
Definition: lora.h:38
#define ENOSYS
Function not implemented.
Definition: errno.h:82
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:403
void * data
Address of the device instance private data.
Definition: device.h:413
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
Definition: kernel.h:5691
Kernel timeout type.
Definition: sys_clock.h:65
Structure containing the configuration of a LoRa modem.
Definition: lora.h:68
uint32_t frequency
Frequency in Hz to use for transceiving.
Definition: lora.h:70
enum lora_signal_bandwidth bandwidth
The bandwidth to use for transceiving.
Definition: lora.h:73
bool tx
Set to true for transmission, false for receiving.
Definition: lora.h:88
int8_t tx_power
TX-power in dBm to use for transmission.
Definition: lora.h:85
bool iq_inverted
Invert the In-Phase and Quadrature (IQ) signals.
Definition: lora.h:97
enum lora_coding_rate coding_rate
The coding rate to use for transceiving.
Definition: lora.h:79
uint16_t preamble_len
Length of the preamble.
Definition: lora.h:82
enum lora_datarate datarate
The data-rate to use for transceiving.
Definition: lora.h:76
bool public_network
Sets the sync-byte to use:
Definition: lora.h:108