BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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