|
| 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 */ |
0 commit comments