Skip to content

Commit 561c615

Browse files
committed
modules: Add lora_basics_modem module
This module provides: * The cmake files for LoRa Basics Modem * The "HAL" described here: https://github.com/Lora-net/SWL2001/blob/master/lbm_lib/PORTING_GUIDE.md * Reimplementations of the logging functions in smtc_modem_hal_dbg_trace.h Signed-off-by: Félix Piédallu <[email protected]>
1 parent e9112ce commit 561c615

File tree

13 files changed

+1688
-0
lines changed

13 files changed

+1688
-0
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (c) 2024 Semtech Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef SMTC_MODEM_HAL_INIT_H
8+
#define SMTC_MODEM_HAL_INIT_H
9+
10+
#include <stdint.h>
11+
12+
#include <zephyr/device.h>
13+
#include <zephyr/sys_clock.h>
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/**
20+
* @brief Defines the battery level callback handler function signature.
21+
*
22+
* @retval 0 if the node is connected to an external power source
23+
* @retval 1..254 battery level, where 1 is the minimum and 254 is the maximum value
24+
* @retval 255 if the node was not able to measure the battery level
25+
*/
26+
typedef uint8_t (*lorawan_battery_level_cb_t)(void);
27+
28+
/**
29+
* @brief Defines the battery voltage callback handler function signature.
30+
*
31+
* @retval The battery voltage, in mV
32+
*/
33+
typedef uint16_t (*lorawan_battery_voltage_cb_t)(void);
34+
35+
/**
36+
* @brief Defines the system temperature callback handler function signature.
37+
*
38+
* @retval The temperature, in degrees Celsius
39+
*/
40+
typedef int8_t (*lorawan_temperature_cb_t)(void);
41+
42+
#ifdef CONFIG_LORA_BASICS_MODEM_FUOTA
43+
44+
struct lorawan_fuota_cb {
45+
/**
46+
* @brief Callback to return the hardware version.
47+
*
48+
* See HW version in FMP Specification TS006-1.0.0.
49+
*
50+
* @return The device's hardware version.
51+
*/
52+
uint32_t (*get_hw_version)(void);
53+
54+
/**
55+
* @brief Callback to return the firmware version.
56+
*
57+
* See FW version in FMP Specification TS006-1.0.0.
58+
*
59+
* @return The device's firmware version.
60+
*/
61+
uint32_t (*get_fw_version)(void);
62+
63+
/**
64+
* @brief Callback to return the firmware status.
65+
*
66+
* See UpImageStatus in FMP Specification TS006-1.0.0.
67+
*
68+
* @return The device's firmware status.
69+
*/
70+
uint8_t (*get_fw_status_available)();
71+
72+
/**
73+
* @brief Callback to return the firmware upgrade next version.
74+
*
75+
* See nextFirmwareVersion in FMP Specification TS006-1.0.0.
76+
*
77+
* @return The next firmware upgrade image version.
78+
*/
79+
uint32_t (*get_next_fw_version)(void);
80+
81+
/**
82+
* @brief Callback to delete a chosen firmware upgrade image.
83+
*
84+
* See DevDeleteImageReq in FMP Specification TS006-1.0.0.
85+
*
86+
* @param [in] fw_version The firmware version to delete.
87+
* @return 0 if the firmware was deleted, or a DevDeleteImageAns.
88+
*/
89+
uint8_t (*get_fw_delete_status)(uint32_t fw_version);
90+
};
91+
92+
#endif /* CONFIG_LORA_BASICS_MODEM_FUOTA */
93+
94+
#ifdef CONFIG_LORA_BASICS_MODEM_USER_STORAGE_IMPL
95+
96+
struct lorawan_user_storage_cb {
97+
98+
/**
99+
* @brief Persistently store context from the lora basics modem
100+
*
101+
* The application should use some persistent storage to store the context.
102+
*
103+
* @param[in] ctx_id The ID of the context to store. Each ID must be stored
104+
* separately.
105+
* @param[in] offset Memory offset after ctx address
106+
* @param[in] buffer The buffer to store.
107+
* @param[in] size The size of the buffer to store, in bytes.
108+
*/
109+
void (*context_store)(const uint8_t ctx_id, const uint32_t offset, const uint8_t *buffer,
110+
const uint32_t size);
111+
112+
/**
113+
* @brief Restore context to the lora basics modem
114+
*
115+
* The application should load the context from the persistent storage used in
116+
* context_store.
117+
*
118+
* @param[in] ctx_id The ID of the context to restore.
119+
* @param[in] offset Memory offset after ctx address
120+
* @param[in] buffer The buffer to read into.
121+
* @param[in] size The size of the buffer, in bytes.
122+
*/
123+
void (*context_restore)(const uint8_t ctx_id, const uint32_t offset, uint8_t *buffer,
124+
const uint32_t size);
125+
};
126+
127+
#endif /* CONFIG_LORA_BASICS_MODEM_USER_STORAGE_IMPL */
128+
129+
/**
130+
* @brief Initialization of the hal implementation.
131+
*
132+
* This must be called before smtc_modem_init
133+
*
134+
* @param[in] transceiver The device pointer of the transceiver instance that will be used.
135+
*/
136+
void lorawan_smtc_modem_hal_init(const struct device *transceiver);
137+
138+
/**
139+
* @brief Register a battery level callback function.
140+
*
141+
* Provide the LoRaWAN stack with a function to be called whenever a battery
142+
* level needs to be read.
143+
*
144+
* Should no callback be provided the lorawan backend will report 255.
145+
*
146+
* @param cb Pointer to the battery level function
147+
*/
148+
void lorawan_register_battery_level_callback(lorawan_battery_level_cb_t cb);
149+
150+
/**
151+
* @brief Register a battery voltage callback function.
152+
*
153+
* Provide the LoRaWAN stack with a function to be called whenever a battery
154+
* voltage needs to be read.
155+
*
156+
*
157+
* @param cb Pointer to the battery voltage function
158+
*/
159+
void lorawan_register_battery_voltage_callback(lorawan_battery_voltage_cb_t cb);
160+
161+
/**
162+
* @brief Register a temperature callback function.
163+
*
164+
* Provide the LoRaWAN stack with a function to be called whenever the system
165+
* temperature needs to be read.
166+
*
167+
* @param cb Pointer to the temperature function
168+
*/
169+
void lorawan_register_temperature_callback(lorawan_temperature_cb_t cb);
170+
171+
#ifdef CONFIG_LORA_BASICS_MODEM_FUOTA
172+
/**
173+
* @brief Register callbacks for the LoRaWAN Firmware Upgrade OTA feature.
174+
*
175+
* Calling this too late (after Device Management messages are received) might
176+
* create undefined behaviour. See documentation at:
177+
* https://resources.lora-alliance.org/technical-specifications/ts006-1-0-0-firmware-management-protocol
178+
*
179+
* @param[in] cb The callbacks to use for the hal implementation. All must be set.
180+
*
181+
*/
182+
void lorawan_register_fuota_callbacks(struct lorawan_fuota_cb *cb);
183+
184+
#endif /* CONFIG_LORA_BASICS_MODEM_FUOTA */
185+
186+
#ifdef CONFIG_LORA_BASICS_MODEM_USER_STORAGE_IMPL
187+
/**
188+
* @brief Register the user storage implementation callbacks for the LoRaWAN stack..
189+
*
190+
* Calling this too late (after smtc_modem_init) might create undefined behaviour.
191+
*
192+
* @param[in] cb The callbacks to use for the hal implementation. All must be set.
193+
*
194+
*/
195+
void lorawan_register_user_storage_callbacks(struct lorawan_user_storage_cb *cb);
196+
197+
#endif /* CONFIG_LORA_BASICS_MODEM_USER_STORAGE_IMPL */
198+
199+
/**
200+
* @brief Interruptible sleep that will exit when radio events happen.
201+
*
202+
*/
203+
void smtc_modem_hal_interruptible_msleep(k_timeout_t timeout);
204+
205+
/**
206+
* @brief If smtc_modem_hal_interruptible_msleep is running, interrupt it.
207+
*
208+
* This function is used to trigger the LoRa Basics Modem stack when an event occurs,
209+
* whether it is an interrupt from the transceiver, a timer or a user request.
210+
*
211+
*/
212+
void smtc_modem_hal_wake_up(void);
213+
214+
#ifdef __cplusplus
215+
}
216+
#endif
217+
218+
#endif /* SMTC_MODEM_HAL_INIT_H */

modules/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ comment "Lz4 module not available."
9696
comment "loramac-node module not available."
9797
depends on !ZEPHYR_LORAMAC_NODE_MODULE
9898

99+
comment "LoRa Basics Modem module not available."
100+
depends on !ZEPHYR_LORA_BASICS_MODEM_MODULE
101+
99102
comment "CANopenNode module not available."
100103
depends on !ZEPHYR_CANOPENNODE_MODULE
101104

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2024 Semtech Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(CONFIG_ZEPHYR_LORA_BASICS_MODEM_MODULE)
5+
# Based on makefiles from Semtech
6+
7+
set(LORA_BASICS_MODEM_DIR ${ZEPHYR_CURRENT_MODULE_DIR})
8+
set(LBM_LIB_DIR ${LORA_BASICS_MODEM_DIR}/lbm_lib)
9+
set(LBM_SMTC_MODEM_CORE_DIR ${LBM_LIB_DIR}/smtc_modem_core)
10+
set(LBM_RADIO_DRIVERS_DIR ${LBM_LIB_DIR}/smtc_modem_core/radio_drivers)
11+
12+
zephyr_library()
13+
14+
if(CONFIG_SEMTECH_LR11XX)
15+
include(${CMAKE_CURRENT_LIST_DIR}/lr11xx.cmake)
16+
endif()
17+
18+
if(CONFIG_SEMTECH_SX126X)
19+
include(${CMAKE_CURRENT_LIST_DIR}/sx126x.cmake)
20+
endif()
21+
22+
if(CONFIG_LORA_BASICS_MODEM_DRIVERS_RAL_RALF)
23+
zephyr_include_directories(
24+
${LBM_SMTC_MODEM_CORE_DIR}/smtc_ral/src
25+
${LBM_SMTC_MODEM_CORE_DIR}/smtc_ralf/src
26+
)
27+
zephyr_library_sources(
28+
${LBM_RAL_SOURCES}
29+
${LBM_RALF_SOURCES}
30+
)
31+
endif()
32+
33+
if(CONFIG_LORA_BASICS_MODEM)
34+
35+
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
36+
37+
zephyr_library_include_directories(
38+
${CMAKE_CURRENT_LIST_DIR}/smtc_modem_hal
39+
)
40+
41+
zephyr_library_sources(
42+
${CMAKE_CURRENT_LIST_DIR}/smtc_modem_hal/smtc_modem_hal.c
43+
${CMAKE_CURRENT_LIST_DIR}/smtc_modem_hal/smtc_modem_hal_storage.c
44+
${CMAKE_CURRENT_LIST_DIR}/smtc_modem_hal/smtc_modem_hal_dbg_trace.c
45+
)
46+
47+
endif()
48+
49+
endif()

modules/lora_basics_modem/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Semtech Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Top-level configuration file for LoRa Basics Modem containing LoRa
5+
# transceiver drivers and LBM LoRaWAN stack
6+
7+
config ZEPHYR_LORA_BASICS_MODEM_MODULE
8+
bool

0 commit comments

Comments
 (0)