Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:02dd72d1d465 1 /**
borlanic 0:02dd72d1d465 2 * Copyright (c) 2017, Arm Limited and affiliates.
borlanic 0:02dd72d1d465 3 * SPDX-License-Identifier: Apache-2.0
borlanic 0:02dd72d1d465 4 *
borlanic 0:02dd72d1d465 5 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:02dd72d1d465 6 * you may not use this file except in compliance with the License.
borlanic 0:02dd72d1d465 7 * You may obtain a copy of the License at
borlanic 0:02dd72d1d465 8 *
borlanic 0:02dd72d1d465 9 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:02dd72d1d465 10 *
borlanic 0:02dd72d1d465 11 * Unless required by applicable law or agreed to in writing, software
borlanic 0:02dd72d1d465 12 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:02dd72d1d465 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:02dd72d1d465 14 * See the License for the specific language governing permissions and
borlanic 0:02dd72d1d465 15 * limitations under the License.
borlanic 0:02dd72d1d465 16 */
borlanic 0:02dd72d1d465 17
borlanic 0:02dd72d1d465 18 #ifndef LORARADIO_H_
borlanic 0:02dd72d1d465 19 #define LORARADIO_H_
borlanic 0:02dd72d1d465 20
borlanic 0:02dd72d1d465 21 #include "platform/Callback.h"
borlanic 0:02dd72d1d465 22 #include "PinNames.h"
borlanic 0:02dd72d1d465 23
borlanic 0:02dd72d1d465 24 /**
borlanic 0:02dd72d1d465 25 * Structure to hold RF controls for LoRa Radio.
borlanic 0:02dd72d1d465 26 * SX1276 have an extra control for the crystal (used in DOSCO-L072CZ)
borlanic 0:02dd72d1d465 27 */
borlanic 0:02dd72d1d465 28 typedef struct {
borlanic 0:02dd72d1d465 29 PinName rf_switch_ctl1;
borlanic 0:02dd72d1d465 30 PinName rf_switch_ctl2;
borlanic 0:02dd72d1d465 31 PinName txctl;
borlanic 0:02dd72d1d465 32 PinName rxctl;
borlanic 0:02dd72d1d465 33 PinName ant_switch;
borlanic 0:02dd72d1d465 34 PinName pwr_amp_ctl;
borlanic 0:02dd72d1d465 35 PinName tcxo;
borlanic 0:02dd72d1d465 36 } rf_ctrls;
borlanic 0:02dd72d1d465 37
borlanic 0:02dd72d1d465 38 /** Radio driver internal state.
borlanic 0:02dd72d1d465 39 * State machine states definition.
borlanic 0:02dd72d1d465 40 */
borlanic 0:02dd72d1d465 41 typedef enum radio_state {
borlanic 0:02dd72d1d465 42 RF_IDLE = 0,
borlanic 0:02dd72d1d465 43 RF_RX_RUNNING,
borlanic 0:02dd72d1d465 44 RF_TX_RUNNING,
borlanic 0:02dd72d1d465 45 RF_CAD,
borlanic 0:02dd72d1d465 46 } radio_state_t;
borlanic 0:02dd72d1d465 47
borlanic 0:02dd72d1d465 48 /** Type of the modem.
borlanic 0:02dd72d1d465 49 * [LORA/FSK]
borlanic 0:02dd72d1d465 50 */
borlanic 0:02dd72d1d465 51 typedef enum modem_type {
borlanic 0:02dd72d1d465 52 MODEM_FSK = 0,
borlanic 0:02dd72d1d465 53 MODEM_LORA
borlanic 0:02dd72d1d465 54 } radio_modems_t;
borlanic 0:02dd72d1d465 55
borlanic 0:02dd72d1d465 56 /** Radio FSK modem parameters.
borlanic 0:02dd72d1d465 57 *
borlanic 0:02dd72d1d465 58 */
borlanic 0:02dd72d1d465 59 typedef struct radio_fsk_settings {
borlanic 0:02dd72d1d465 60 int8_t power;
borlanic 0:02dd72d1d465 61 uint32_t f_dev;
borlanic 0:02dd72d1d465 62 uint32_t bandwidth;
borlanic 0:02dd72d1d465 63 uint32_t bandwidth_afc;
borlanic 0:02dd72d1d465 64 uint32_t datarate;
borlanic 0:02dd72d1d465 65 uint16_t preamble_len;
borlanic 0:02dd72d1d465 66 bool fix_len;
borlanic 0:02dd72d1d465 67 uint8_t payload_len;
borlanic 0:02dd72d1d465 68 bool crc_on;
borlanic 0:02dd72d1d465 69 bool iq_inverted;
borlanic 0:02dd72d1d465 70 bool rx_continuous;
borlanic 0:02dd72d1d465 71 uint32_t tx_timeout;
borlanic 0:02dd72d1d465 72 uint32_t rx_single_timeout;
borlanic 0:02dd72d1d465 73 } radio_fsk_settings_t;
borlanic 0:02dd72d1d465 74
borlanic 0:02dd72d1d465 75 /** Radio FSK packet handler state.
borlanic 0:02dd72d1d465 76 *
borlanic 0:02dd72d1d465 77 */
borlanic 0:02dd72d1d465 78 typedef struct radio_fsk_packet_handler {
borlanic 0:02dd72d1d465 79 uint8_t preamble_detected;
borlanic 0:02dd72d1d465 80 uint8_t sync_word_detected;
borlanic 0:02dd72d1d465 81 int8_t rssi_value;
borlanic 0:02dd72d1d465 82 int32_t afc_value;
borlanic 0:02dd72d1d465 83 uint8_t rx_gain;
borlanic 0:02dd72d1d465 84 uint16_t size;
borlanic 0:02dd72d1d465 85 uint16_t nb_bytes;
borlanic 0:02dd72d1d465 86 uint8_t fifo_thresh;
borlanic 0:02dd72d1d465 87 uint8_t chunk_size;
borlanic 0:02dd72d1d465 88 } radio_fsk_packet_handler_t;
borlanic 0:02dd72d1d465 89
borlanic 0:02dd72d1d465 90 /** Radio LoRa modem parameters.
borlanic 0:02dd72d1d465 91 *
borlanic 0:02dd72d1d465 92 */
borlanic 0:02dd72d1d465 93 typedef struct radio_lora_settings {
borlanic 0:02dd72d1d465 94 int8_t power;
borlanic 0:02dd72d1d465 95 uint32_t bandwidth;
borlanic 0:02dd72d1d465 96 uint32_t datarate;
borlanic 0:02dd72d1d465 97 bool low_datarate_optimize;
borlanic 0:02dd72d1d465 98 uint8_t coderate;
borlanic 0:02dd72d1d465 99 uint16_t preamble_len;
borlanic 0:02dd72d1d465 100 bool fix_len;
borlanic 0:02dd72d1d465 101 uint8_t payload_len;
borlanic 0:02dd72d1d465 102 bool crc_on;
borlanic 0:02dd72d1d465 103 bool freq_hop_on;
borlanic 0:02dd72d1d465 104 uint8_t hop_period;
borlanic 0:02dd72d1d465 105 bool iq_inverted;
borlanic 0:02dd72d1d465 106 bool rx_continuous;
borlanic 0:02dd72d1d465 107 uint32_t tx_timeout;
borlanic 0:02dd72d1d465 108 bool public_network;
borlanic 0:02dd72d1d465 109 } radio_lora_settings_t;
borlanic 0:02dd72d1d465 110
borlanic 0:02dd72d1d465 111 /** Radio LoRa packet handler state.
borlanic 0:02dd72d1d465 112 *
borlanic 0:02dd72d1d465 113 */
borlanic 0:02dd72d1d465 114 typedef struct radio_lora_packet_handler {
borlanic 0:02dd72d1d465 115 int8_t snr_value;
borlanic 0:02dd72d1d465 116 int8_t rssi_value;
borlanic 0:02dd72d1d465 117 uint8_t size;
borlanic 0:02dd72d1d465 118 } radio_lora_packet_handler_t;
borlanic 0:02dd72d1d465 119
borlanic 0:02dd72d1d465 120 /** Radio settings.
borlanic 0:02dd72d1d465 121 *
borlanic 0:02dd72d1d465 122 */
borlanic 0:02dd72d1d465 123 typedef struct radio_settings {
borlanic 0:02dd72d1d465 124 uint8_t state;
borlanic 0:02dd72d1d465 125 uint8_t modem;
borlanic 0:02dd72d1d465 126 uint32_t channel;
borlanic 0:02dd72d1d465 127 radio_fsk_settings_t fsk;
borlanic 0:02dd72d1d465 128 radio_fsk_packet_handler_t fsk_packet_handler;
borlanic 0:02dd72d1d465 129 radio_lora_settings_t lora;
borlanic 0:02dd72d1d465 130 radio_lora_packet_handler_t lora_packet_handler;
borlanic 0:02dd72d1d465 131 } radio_settings_t;
borlanic 0:02dd72d1d465 132
borlanic 0:02dd72d1d465 133 /** Radio driver callback functions.
borlanic 0:02dd72d1d465 134 *
borlanic 0:02dd72d1d465 135 */
borlanic 0:02dd72d1d465 136 typedef struct radio_events {
borlanic 0:02dd72d1d465 137 /**
borlanic 0:02dd72d1d465 138 * Callback when Transmission is done
borlanic 0:02dd72d1d465 139 */
borlanic 0:02dd72d1d465 140 mbed::Callback<void()> tx_done;
borlanic 0:02dd72d1d465 141
borlanic 0:02dd72d1d465 142 /**
borlanic 0:02dd72d1d465 143 * Callback when Transmission is timed out
borlanic 0:02dd72d1d465 144 */
borlanic 0:02dd72d1d465 145 mbed::Callback<void()> tx_timeout;
borlanic 0:02dd72d1d465 146
borlanic 0:02dd72d1d465 147 /**
borlanic 0:02dd72d1d465 148 * Rx Done callback prototype.
borlanic 0:02dd72d1d465 149 *
borlanic 0:02dd72d1d465 150 * @param payload Received buffer pointer.
borlanic 0:02dd72d1d465 151 * @param size Received buffer size.
borlanic 0:02dd72d1d465 152 * @param rssi RSSI value computed while receiving the frame [dBm].
borlanic 0:02dd72d1d465 153 * @param snr Raw SNR value given by the radio hardware.
borlanic 0:02dd72d1d465 154 * FSK : N/A (set to 0)
borlanic 0:02dd72d1d465 155 * LoRa: SNR value in dB
borlanic 0:02dd72d1d465 156 */
borlanic 0:02dd72d1d465 157 mbed::Callback<void(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)> rx_done;
borlanic 0:02dd72d1d465 158
borlanic 0:02dd72d1d465 159 /**
borlanic 0:02dd72d1d465 160 * Callback when Reception is timed out
borlanic 0:02dd72d1d465 161 */
borlanic 0:02dd72d1d465 162 mbed::Callback<void()> rx_timeout;
borlanic 0:02dd72d1d465 163
borlanic 0:02dd72d1d465 164 /**
borlanic 0:02dd72d1d465 165 * Callback when Reception ends up in error
borlanic 0:02dd72d1d465 166 */
borlanic 0:02dd72d1d465 167 mbed::Callback<void()> rx_error;
borlanic 0:02dd72d1d465 168
borlanic 0:02dd72d1d465 169 /**
borlanic 0:02dd72d1d465 170 * FHSS Change Channel callback prototype.
borlanic 0:02dd72d1d465 171 *
borlanic 0:02dd72d1d465 172 * @param current_channel The index number of the current channel.
borlanic 0:02dd72d1d465 173 */
borlanic 0:02dd72d1d465 174 mbed::Callback<void(uint8_t current_channel)> fhss_change_channel;
borlanic 0:02dd72d1d465 175
borlanic 0:02dd72d1d465 176 /**
borlanic 0:02dd72d1d465 177 * CAD Done callback prototype.
borlanic 0:02dd72d1d465 178 *
borlanic 0:02dd72d1d465 179 * @param channel_busy True, if Channel activity detected.
borlanic 0:02dd72d1d465 180 */
borlanic 0:02dd72d1d465 181 mbed::Callback<void(bool channel_busy)> cad_done;
borlanic 0:02dd72d1d465 182 } radio_events_t;
borlanic 0:02dd72d1d465 183
borlanic 0:02dd72d1d465 184 /**
borlanic 0:02dd72d1d465 185 * Interface for the radios, contains the main functions that a radio needs, and five callback functions.
borlanic 0:02dd72d1d465 186 */
borlanic 0:02dd72d1d465 187 class LoRaRadio
borlanic 0:02dd72d1d465 188 {
borlanic 0:02dd72d1d465 189
borlanic 0:02dd72d1d465 190 public:
borlanic 0:02dd72d1d465 191
borlanic 0:02dd72d1d465 192 /**
borlanic 0:02dd72d1d465 193 * Registers radio events with the Mbed LoRaWAN stack and undergoes the initialization steps if any.
borlanic 0:02dd72d1d465 194 *
borlanic 0:02dd72d1d465 195 * @param events The structure containing the driver callback functions.
borlanic 0:02dd72d1d465 196 */
borlanic 0:02dd72d1d465 197 virtual void init_radio(radio_events_t *events) = 0;
borlanic 0:02dd72d1d465 198
borlanic 0:02dd72d1d465 199 /**
borlanic 0:02dd72d1d465 200 * Resets the radio module.
borlanic 0:02dd72d1d465 201 */
borlanic 0:02dd72d1d465 202 virtual void radio_reset() = 0;
borlanic 0:02dd72d1d465 203
borlanic 0:02dd72d1d465 204 /**
borlanic 0:02dd72d1d465 205 * Put the RF module in the sleep mode.
borlanic 0:02dd72d1d465 206 */
borlanic 0:02dd72d1d465 207 virtual void sleep(void) = 0;
borlanic 0:02dd72d1d465 208
borlanic 0:02dd72d1d465 209 /**
borlanic 0:02dd72d1d465 210 * Sets the radio in the standby mode.
borlanic 0:02dd72d1d465 211 */
borlanic 0:02dd72d1d465 212 virtual void standby(void) = 0;
borlanic 0:02dd72d1d465 213
borlanic 0:02dd72d1d465 214 /**
borlanic 0:02dd72d1d465 215 * Sets the reception parameters.
borlanic 0:02dd72d1d465 216 *
borlanic 0:02dd72d1d465 217 * @param modem The radio modem to be used [0: FSK, 1: LoRa].
borlanic 0:02dd72d1d465 218 * @param bandwidth Sets the bandwidth.
borlanic 0:02dd72d1d465 219 * FSK : >= 2600 and <= 250000 Hz
borlanic 0:02dd72d1d465 220 * LoRa: [0: 125 kHz, 1: 250 kHz,
borlanic 0:02dd72d1d465 221 * 2: 500 kHz, 3: Reserved]
borlanic 0:02dd72d1d465 222 * @param datarate Sets the datarate.
borlanic 0:02dd72d1d465 223 * FSK : 600..300000 bits/s
borlanic 0:02dd72d1d465 224 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
borlanic 0:02dd72d1d465 225 * 10: 1024, 11: 2048, 12: 4096 chips]
borlanic 0:02dd72d1d465 226 * @param coderate Sets the coding rate (LoRa only).
borlanic 0:02dd72d1d465 227 * FSK : N/A ( set to 0 )
borlanic 0:02dd72d1d465 228 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
borlanic 0:02dd72d1d465 229 * @param bandwidth_afc Sets the AFC bandwidth (FSK only).
borlanic 0:02dd72d1d465 230 * FSK : >= 2600 and <= 250000 Hz
borlanic 0:02dd72d1d465 231 * LoRa: N/A (set to 0)
borlanic 0:02dd72d1d465 232 * @param preamble_len Sets the preamble length (LoRa only).
borlanic 0:02dd72d1d465 233 * FSK : N/A (set to 0)
borlanic 0:02dd72d1d465 234 * LoRa: Length in symbols (the hardware adds four more symbols).
borlanic 0:02dd72d1d465 235 * @param symb_timeout Sets the RxSingle timeout value.
borlanic 0:02dd72d1d465 236 * FSK : Timeout number of bytes
borlanic 0:02dd72d1d465 237 * LoRa: Timeout in symbols
borlanic 0:02dd72d1d465 238 * @param fix_len Fixed length packets [0: variable, 1: fixed].
borlanic 0:02dd72d1d465 239 * @param payload_len Sets the payload length when fixed length is used.
borlanic 0:02dd72d1d465 240 * @param crc_on Enables/disables the CRC [0: OFF, 1: ON].
borlanic 0:02dd72d1d465 241 * @param freq_hop_on Enables/disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only).
borlanic 0:02dd72d1d465 242 * @param hop_period The number of symbols bewteen each hop (LoRa only).
borlanic 0:02dd72d1d465 243 * @param iq_inverted Inverts the IQ signals (LoRa only).
borlanic 0:02dd72d1d465 244 * FSK : N/A (set to 0)
borlanic 0:02dd72d1d465 245 * LoRa: [0: not inverted, 1: inverted]
borlanic 0:02dd72d1d465 246 * @param rx_continuous Sets the reception in continuous mode.
borlanic 0:02dd72d1d465 247 * [false: single mode, true: continuous mode]
borlanic 0:02dd72d1d465 248 */
borlanic 0:02dd72d1d465 249 virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
borlanic 0:02dd72d1d465 250 uint32_t datarate, uint8_t coderate,
borlanic 0:02dd72d1d465 251 uint32_t bandwidth_afc, uint16_t preamble_len,
borlanic 0:02dd72d1d465 252 uint16_t symb_timeout, bool fix_len,
borlanic 0:02dd72d1d465 253 uint8_t payload_len,
borlanic 0:02dd72d1d465 254 bool crc_on, bool freq_hop_on, uint8_t hop_period,
borlanic 0:02dd72d1d465 255 bool iq_inverted, bool rx_continuous) = 0;
borlanic 0:02dd72d1d465 256
borlanic 0:02dd72d1d465 257 /**
borlanic 0:02dd72d1d465 258 * Sets the transmission parameters.
borlanic 0:02dd72d1d465 259 *
borlanic 0:02dd72d1d465 260 * @param modem The radio modem to be used [0: FSK, 1: LoRa].
borlanic 0:02dd72d1d465 261 * @param power Sets the output power [dBm].
borlanic 0:02dd72d1d465 262 * @param fdev Sets the frequency deviation (FSK only).
borlanic 0:02dd72d1d465 263 * FSK : [Hz]
borlanic 0:02dd72d1d465 264 * LoRa: 0
borlanic 0:02dd72d1d465 265 * @param bandwidth Sets the bandwidth (LoRa only).
borlanic 0:02dd72d1d465 266 * FSK : 0
borlanic 0:02dd72d1d465 267 * LoRa: [0: 125 kHz, 1: 250 kHz,
borlanic 0:02dd72d1d465 268 * 2: 500 kHz, 3: Reserved]
borlanic 0:02dd72d1d465 269 * @param datarate Sets the datarate.
borlanic 0:02dd72d1d465 270 * FSK : 600..300000 bits/s
borlanic 0:02dd72d1d465 271 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
borlanic 0:02dd72d1d465 272 * 10: 1024, 11: 2048, 12: 4096 chips]
borlanic 0:02dd72d1d465 273 * @param coderate Sets the coding rate (LoRa only).
borlanic 0:02dd72d1d465 274 * FSK : N/A ( set to 0 )
borlanic 0:02dd72d1d465 275 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
borlanic 0:02dd72d1d465 276 * @param preamble_len Sets the preamble length.
borlanic 0:02dd72d1d465 277 * @param fix_len Fixed length packets [0: variable, 1: fixed].
borlanic 0:02dd72d1d465 278 * @param crc_on Enables/disables the CRC [0: OFF, 1: ON].
borlanic 0:02dd72d1d465 279 * @param freq_hop_on Enables/disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only).
borlanic 0:02dd72d1d465 280 * @param hop_period The number of symbols between each hop (LoRa only).
borlanic 0:02dd72d1d465 281 * @param iq_inverted Inverts IQ signals (LoRa only)
borlanic 0:02dd72d1d465 282 * FSK : N/A (set to 0).
borlanic 0:02dd72d1d465 283 * LoRa: [0: not inverted, 1: inverted]
borlanic 0:02dd72d1d465 284 * @param timeout The transmission timeout [us].
borlanic 0:02dd72d1d465 285 */
borlanic 0:02dd72d1d465 286 virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
borlanic 0:02dd72d1d465 287 uint32_t bandwidth, uint32_t datarate,
borlanic 0:02dd72d1d465 288 uint8_t coderate, uint16_t preamble_len,
borlanic 0:02dd72d1d465 289 bool fix_len, bool crc_on, bool freq_hop_on,
borlanic 0:02dd72d1d465 290 uint8_t hop_period, bool iq_inverted, uint32_t timeout) = 0;
borlanic 0:02dd72d1d465 291
borlanic 0:02dd72d1d465 292 /**
borlanic 0:02dd72d1d465 293 * Sends the buffer of size
borlanic 0:02dd72d1d465 294 *
borlanic 0:02dd72d1d465 295 * Prepares the packet to be sent and sets the radio in transmission.
borlanic 0:02dd72d1d465 296 *
borlanic 0:02dd72d1d465 297 * @param buffer A pointer to the buffer.
borlanic 0:02dd72d1d465 298 * @param size The buffer size.
borlanic 0:02dd72d1d465 299 */
borlanic 0:02dd72d1d465 300 virtual void send(uint8_t *buffer, uint8_t size) = 0;
borlanic 0:02dd72d1d465 301
borlanic 0:02dd72d1d465 302 /**
borlanic 0:02dd72d1d465 303 * Sets the radio in reception mode for a given time.
borlanic 0:02dd72d1d465 304 *
borlanic 0:02dd72d1d465 305 * If the timeout is set to 0, it essentially puts the receiver in continuous mode and it should
borlanic 0:02dd72d1d465 306 * be treated as if in continuous mode. However, an appropriate way to set the receiver in continuous mode is
borlanic 0:02dd72d1d465 307 * to use the `set_rx_config()` API.
borlanic 0:02dd72d1d465 308 *
borlanic 0:02dd72d1d465 309 * @param timeout Reception timeout [ms].
borlanic 0:02dd72d1d465 310 *
borlanic 0:02dd72d1d465 311 */
borlanic 0:02dd72d1d465 312 virtual void receive(uint32_t timeout) = 0;
borlanic 0:02dd72d1d465 313
borlanic 0:02dd72d1d465 314 /**
borlanic 0:02dd72d1d465 315 * Sets the carrier frequency
borlanic 0:02dd72d1d465 316 *
borlanic 0:02dd72d1d465 317 * @param freq Channel RF frequency.
borlanic 0:02dd72d1d465 318 */
borlanic 0:02dd72d1d465 319 virtual void set_channel(uint32_t freq) = 0;
borlanic 0:02dd72d1d465 320
borlanic 0:02dd72d1d465 321 /**
borlanic 0:02dd72d1d465 322 * Generates a 32 bit random value based on the RSSI readings.
borlanic 0:02dd72d1d465 323 *
borlanic 0:02dd72d1d465 324 * \remark This function sets the radio in LoRa modem mode and disables all interrupts.
borlanic 0:02dd72d1d465 325 * After calling this function, either `Radio.SetRxConfig` or
borlanic 0:02dd72d1d465 326 * `Radio.SetTxConfig` functions must be called.
borlanic 0:02dd72d1d465 327 *
borlanic 0:02dd72d1d465 328 * @return A 32 bit random value.
borlanic 0:02dd72d1d465 329 */
borlanic 0:02dd72d1d465 330 virtual uint32_t random(void) = 0;
borlanic 0:02dd72d1d465 331
borlanic 0:02dd72d1d465 332 /**
borlanic 0:02dd72d1d465 333 * Gets the radio status.
borlanic 0:02dd72d1d465 334 *
borlanic 0:02dd72d1d465 335 * @return The current radio status.
borlanic 0:02dd72d1d465 336 */
borlanic 0:02dd72d1d465 337 virtual uint8_t get_status(void) = 0;
borlanic 0:02dd72d1d465 338
borlanic 0:02dd72d1d465 339 /**
borlanic 0:02dd72d1d465 340 * Sets the maximum payload length.
borlanic 0:02dd72d1d465 341 *
borlanic 0:02dd72d1d465 342 * @param modem The radio modem to be used [0: FSK, 1: LoRa].
borlanic 0:02dd72d1d465 343 * @param max The maximum payload length in bytes.
borlanic 0:02dd72d1d465 344 */
borlanic 0:02dd72d1d465 345 virtual void set_max_payload_length(radio_modems_t modem, uint8_t max) = 0;
borlanic 0:02dd72d1d465 346
borlanic 0:02dd72d1d465 347 /**
borlanic 0:02dd72d1d465 348 * Sets the network to public or private.
borlanic 0:02dd72d1d465 349 *
borlanic 0:02dd72d1d465 350 * Updates the sync byte. Applies to LoRa modem only.
borlanic 0:02dd72d1d465 351 *
borlanic 0:02dd72d1d465 352 * @param enable If true, it enables a public network.
borlanic 0:02dd72d1d465 353 */
borlanic 0:02dd72d1d465 354 virtual void set_public_network(bool enable) = 0;
borlanic 0:02dd72d1d465 355
borlanic 0:02dd72d1d465 356 /**
borlanic 0:02dd72d1d465 357 * Computes the packet time on air for the given payload.
borlanic 0:02dd72d1d465 358 *
borlanic 0:02dd72d1d465 359 * \remark This can only be called once `SetRxConfig` or `SetTxConfig` have been called.
borlanic 0:02dd72d1d465 360 *
borlanic 0:02dd72d1d465 361 * @param modem The radio modem to be used [0: FSK, 1: LoRa].
borlanic 0:02dd72d1d465 362 * @param pkt_len The packet payload length.
borlanic 0:02dd72d1d465 363 * @return The computed `airTime` for the given packet payload length.
borlanic 0:02dd72d1d465 364 */
borlanic 0:02dd72d1d465 365 virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len) = 0;
borlanic 0:02dd72d1d465 366
borlanic 0:02dd72d1d465 367 /**
borlanic 0:02dd72d1d465 368 * Performs carrier sensing.
borlanic 0:02dd72d1d465 369 *
borlanic 0:02dd72d1d465 370 * Checks for a certain time if the RSSI is above a given threshold.
borlanic 0:02dd72d1d465 371 * This threshold determines whether or not there is a transmission going on
borlanic 0:02dd72d1d465 372 * in the channel already.
borlanic 0:02dd72d1d465 373 *
borlanic 0:02dd72d1d465 374 * @param modem The type of the radio modem.
borlanic 0:02dd72d1d465 375 * @param freq The carrier frequency.
borlanic 0:02dd72d1d465 376 * @param rssi_threshold The threshold value of RSSI.
borlanic 0:02dd72d1d465 377 * @param max_carrier_sense_time The time set for sensing the channel (ms).
borlanic 0:02dd72d1d465 378 *
borlanic 0:02dd72d1d465 379 * @return True if there is no active transmission
borlanic 0:02dd72d1d465 380 * in the channel, otherwise false.
borlanic 0:02dd72d1d465 381 */
borlanic 0:02dd72d1d465 382 virtual bool perform_carrier_sense(radio_modems_t modem,
borlanic 0:02dd72d1d465 383 uint32_t freq,
borlanic 0:02dd72d1d465 384 int16_t rssi_threshold,
borlanic 0:02dd72d1d465 385 uint32_t max_carrier_sense_time) = 0;
borlanic 0:02dd72d1d465 386
borlanic 0:02dd72d1d465 387 /**
borlanic 0:02dd72d1d465 388 * Sets the radio in CAD mode.
borlanic 0:02dd72d1d465 389 *
borlanic 0:02dd72d1d465 390 */
borlanic 0:02dd72d1d465 391 virtual void start_cad(void) = 0;
borlanic 0:02dd72d1d465 392
borlanic 0:02dd72d1d465 393 /**
borlanic 0:02dd72d1d465 394 * Checks whether the given RF is in range.
borlanic 0:02dd72d1d465 395 *
borlanic 0:02dd72d1d465 396 * @param frequency The frequency to be checked.
borlanic 0:02dd72d1d465 397 */
borlanic 0:02dd72d1d465 398 virtual bool check_rf_frequency(uint32_t frequency) = 0;
borlanic 0:02dd72d1d465 399
borlanic 0:02dd72d1d465 400 /** Sets the radio in continuous wave transmission mode.
borlanic 0:02dd72d1d465 401 *
borlanic 0:02dd72d1d465 402 * @param freq The RF frequency of the channel.
borlanic 0:02dd72d1d465 403 * @param power The output power [dBm].
borlanic 0:02dd72d1d465 404 * @param time The transmission mode timeout [s].
borlanic 0:02dd72d1d465 405 */
borlanic 0:02dd72d1d465 406 virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time) = 0;
borlanic 0:02dd72d1d465 407
borlanic 0:02dd72d1d465 408 /**
borlanic 0:02dd72d1d465 409 * Acquires exclusive access to this radio.
borlanic 0:02dd72d1d465 410 */
borlanic 0:02dd72d1d465 411 virtual void lock(void) = 0;
borlanic 0:02dd72d1d465 412
borlanic 0:02dd72d1d465 413 /**
borlanic 0:02dd72d1d465 414 * Releases the exclusive access to this radio.
borlanic 0:02dd72d1d465 415 */
borlanic 0:02dd72d1d465 416 virtual void unlock(void) = 0;
borlanic 0:02dd72d1d465 417 };
borlanic 0:02dd72d1d465 418
borlanic 0:02dd72d1d465 419 #endif // LORARADIO_H_