BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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