|
| 1 | +/** |
| 2 | + * @file LoRaPHYAS923.h |
| 3 | + * |
| 4 | + * @brief Implements LoRaPHY for Asia-Pacific 923 MHz band |
| 5 | + * |
| 6 | + * \code |
| 7 | + * ______ _ |
| 8 | + * / _____) _ | | |
| 9 | + * ( (____ _____ ____ _| |_ _____ ____| |__ |
| 10 | + * \____ \| ___ | (_ _) ___ |/ ___) _ \ |
| 11 | + * _____) ) ____| | | || |_| ____( (___| | | | |
| 12 | + * (______/|_____)_|_|_| \__)_____)\____)_| |_| |
| 13 | + * (C)2013 Semtech |
| 14 | + * ___ _____ _ ___ _ _____ ___ ___ ___ ___ |
| 15 | + * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| |
| 16 | + * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| |
| 17 | + * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| |
| 18 | + * embedded.connectivity.solutions=============== |
| 19 | + * |
| 20 | + * \endcode |
| 21 | + * |
| 22 | + * |
| 23 | + * License: Revised BSD License, see LICENSE.TXT file include in the project |
| 24 | + * |
| 25 | + * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE ) |
| 26 | + * |
| 27 | + * Copyright (c) 2017, Arm Limited and affiliates. |
| 28 | + * SPDX-License-Identifier: BSD-3-Clause |
| 29 | + * |
| 30 | + */ |
| 31 | + |
| 32 | +#ifndef MBED_OS_LORAPHY_AS923_H_ |
| 33 | +#define MBED_OS_LORAPHY_AS923_H_ |
| 34 | + |
| 35 | +#include "LoRaPHY.h" |
| 36 | +#include "netsocket/LoRaRadio.h" |
| 37 | + |
| 38 | +/*! |
| 39 | + * LoRaMac maximum number of channels |
| 40 | + */ |
| 41 | +#define AS923_MAX_NB_CHANNELS 16 |
| 42 | + |
| 43 | +/*! |
| 44 | + * Maximum number of bands |
| 45 | + */ |
| 46 | +#define AS923_MAX_NB_BANDS 1 |
| 47 | + |
| 48 | +#define AS923_CHANNELS_MASK_SIZE 1 |
| 49 | + |
| 50 | + |
| 51 | +class LoRaPHYAS923 : public LoRaPHY { |
| 52 | + |
| 53 | +public: |
| 54 | + |
| 55 | + LoRaPHYAS923(); |
| 56 | + virtual ~LoRaPHYAS923(); |
| 57 | + |
| 58 | + /*! |
| 59 | + * \brief The function gets a value of a specific PHY attribute. |
| 60 | + * |
| 61 | + * \param [in] getPhy A pointer to the function parameters. |
| 62 | + * |
| 63 | + * \retval A structure containing the PHY parameter. |
| 64 | + */ |
| 65 | + virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy ); |
| 66 | + |
| 67 | + /*! |
| 68 | + * \brief Updates the last TX done parameters of the current channel. |
| 69 | + * |
| 70 | + * \param [in] txDone A pointer to the function parameters. |
| 71 | + */ |
| 72 | + virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone ); |
| 73 | + |
| 74 | + /*! |
| 75 | + * \brief Initializes the channels masks and the channels. |
| 76 | + * |
| 77 | + * \param [in] type Sets the initialization type. |
| 78 | + */ |
| 79 | + virtual void load_defaults(InitType_t type ); |
| 80 | + |
| 81 | + /*! |
| 82 | + * \brief Verifies a parameter. |
| 83 | + * |
| 84 | + * \param [in] verify A pointer to the function parameters. |
| 85 | + * |
| 86 | + * \param [in] phyAttribute The attribute to be verified. |
| 87 | + * |
| 88 | + * \retval True, if the parameter is valid. |
| 89 | + */ |
| 90 | + virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute ); |
| 91 | + |
| 92 | + /*! |
| 93 | + * \brief The function parses the input buffer and sets up the channels of the |
| 94 | + * CF list. |
| 95 | + * |
| 96 | + * \param [in] applyCFList A pointer to the function parameters. |
| 97 | + */ |
| 98 | + virtual void apply_cf_list(ApplyCFListParams_t* applyCFList ); |
| 99 | + |
| 100 | + /*! |
| 101 | + * \brief Sets a channels mask. |
| 102 | + * |
| 103 | + * \param [in] chanMaskSet A pointer to the function parameters. |
| 104 | + * |
| 105 | + * \retval True, if the channels mask could be set. |
| 106 | + */ |
| 107 | + virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet ); |
| 108 | + |
| 109 | + /*! |
| 110 | + * \brief Calculates the next datarate to set, when ADR is on or off. |
| 111 | + * |
| 112 | + * \param [in] adrNext A pointer to the function parameters. |
| 113 | + * |
| 114 | + * \param [out] drOut The calculated datarate for the next TX. |
| 115 | + * |
| 116 | + * \param [out] txPowOut The TX power for the next TX. |
| 117 | + * |
| 118 | + * \param [out] adrAckCounter The calculated ADR acknowledgement counter. |
| 119 | + * |
| 120 | + * \retval True, if an ADR request should be performed. |
| 121 | + */ |
| 122 | + virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut, |
| 123 | + int8_t* txPowOut, uint32_t* adrAckCounter ); |
| 124 | + |
| 125 | + /*! |
| 126 | + * \brief Configuration of the RX windows. |
| 127 | + * |
| 128 | + * \param [in] rxConfig A pointer to the function parameters. |
| 129 | + * |
| 130 | + * \param [out] datarate The datarate index set. |
| 131 | + * |
| 132 | + * \retval True, if the configuration was applied successfully. |
| 133 | + */ |
| 134 | + virtual bool rx_config(RxConfigParams_t* rxConfig, int8_t* datarate ); |
| 135 | + |
| 136 | + /* |
| 137 | + * RX window precise timing. |
| 138 | + * |
| 139 | + * For more details please consult the following document, chapter 3.1.2. |
| 140 | + * http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf |
| 141 | + * or |
| 142 | + * http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf |
| 143 | + * |
| 144 | + * Downlink start: T = Tx + 1s (+/- 20 us) |
| 145 | + * | |
| 146 | + * TRxEarly | TRxLate |
| 147 | + * | | | |
| 148 | + * | | +---+---+---+---+---+---+---+---+ |
| 149 | + * | | | Latest Rx window | |
| 150 | + * | | +---+---+---+---+---+---+---+---+ |
| 151 | + * | | | |
| 152 | + * +---+---+---+---+---+---+---+---+ |
| 153 | + * | Earliest Rx window | |
| 154 | + * +---+---+---+---+---+---+---+---+ |
| 155 | + * | |
| 156 | + * +---+---+---+---+---+---+---+---+ |
| 157 | + *Downlink preamble 8 symbols | | | | | | | | | |
| 158 | + * +---+---+---+---+---+---+---+---+ |
| 159 | + * |
| 160 | + * Worst case Rx window timings |
| 161 | + * |
| 162 | + * TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME |
| 163 | + * TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME |
| 164 | + * |
| 165 | + * TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR |
| 166 | + * |
| 167 | + * RxOffset = ( TRxLate + TRxEarly ) / 2 |
| 168 | + * |
| 169 | + * RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR |
| 170 | + * RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME |
| 171 | + * |
| 172 | + * The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol |
| 173 | + */ |
| 174 | + /*! |
| 175 | + * Computes the RX window timeout and offset. |
| 176 | + * |
| 177 | + * \param [in] datarate The RX window datarate index to be used. |
| 178 | + * |
| 179 | + * \param [in] minRxSymbols The minimum required number of symbols to detect an RX frame. |
| 180 | + * |
| 181 | + * \param [in] rxError The system maximum timing error of the receiver in milliseconds. |
| 182 | + * The receiver will turn on in a [-rxError : +rxError] ms |
| 183 | + * interval around RxOffset. |
| 184 | + * |
| 185 | + * \param [out] rxConfigParams The updated WindowTimeout and WindowOffset fields. |
| 186 | + */ |
| 187 | + virtual void compute_rx_win_params(int8_t datarate, |
| 188 | + uint8_t minRxSymbols, |
| 189 | + uint32_t rxError, |
| 190 | + RxConfigParams_t *rxConfigParams); |
| 191 | + |
| 192 | + /*! |
| 193 | + * \brief TX configuration. |
| 194 | + * |
| 195 | + * \param [in] txConfig A pointer to the function parameters. |
| 196 | + * |
| 197 | + * \param [out] txPower The TX power index set. |
| 198 | + * |
| 199 | + * \param [out] txTimeOnAir The time-on-air of the frame. |
| 200 | + * |
| 201 | + * \retval True, if the configuration was applied successfully. |
| 202 | + */ |
| 203 | + virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower, |
| 204 | + TimerTime_t* txTimeOnAir ); |
| 205 | + |
| 206 | + /*! |
| 207 | + * \brief The function processes a Link ADR Request. |
| 208 | + * |
| 209 | + * \param [in] linkAdrReq A pointer to the function parameters. |
| 210 | + * |
| 211 | + * \param [out] drOut The datarate applied. |
| 212 | + * |
| 213 | + * \param [out] txPowOut The TX power applied. |
| 214 | + * |
| 215 | + * \param [out] nbRepOut The number of repetitions to apply. |
| 216 | + * |
| 217 | + * \param [out] nbBytesParsed The number of bytes parsed. |
| 218 | + * |
| 219 | + * \retval The status of the operation, according to the LoRaMAC specification. |
| 220 | + */ |
| 221 | + virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq, |
| 222 | + int8_t* drOut, int8_t* txPowOut, |
| 223 | + uint8_t* nbRepOut, |
| 224 | + uint8_t* nbBytesParsed ); |
| 225 | + |
| 226 | + /*! |
| 227 | + * \brief The function processes a RX parameter setup request. |
| 228 | + * |
| 229 | + * \param [in] rxParamSetupReq A pointer to the function parameters. |
| 230 | + * |
| 231 | + * \retval The status of the operation, according to the LoRaMAC specification. |
| 232 | + */ |
| 233 | + virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq ); |
| 234 | + |
| 235 | + /*! |
| 236 | + * \brief The function processes a new channel request. |
| 237 | + * |
| 238 | + * \param [in] newChannelReq A pointer to the function parameters. |
| 239 | + * |
| 240 | + * \retval The status of the operation, according to the LoRaMAC specification. |
| 241 | + */ |
| 242 | + virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq ); |
| 243 | + |
| 244 | + /*! |
| 245 | + * \brief The function processes a TX ParamSetup request. |
| 246 | + * |
| 247 | + * \param [in] txParamSetupReq A pointer to the function parameters. |
| 248 | + * |
| 249 | + * \retval The status of the operation, according to the LoRaMAC specification. |
| 250 | + * Returns -1, if the functionality is not implemented. In this case, the end node |
| 251 | + * shall ignore the command. |
| 252 | + */ |
| 253 | + virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq ); |
| 254 | + |
| 255 | + /*! |
| 256 | + * \brief The function processes a DlChannel request. |
| 257 | + * |
| 258 | + * \param [in] dlChannelReq A pointer to the function parameters. |
| 259 | + * |
| 260 | + * \retval The status of the operation, according to the LoRaMAC specification. |
| 261 | + */ |
| 262 | + virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq ); |
| 263 | + |
| 264 | + /*! |
| 265 | + * \brief Alternates the datarate of the channel for the join request. |
| 266 | + * |
| 267 | + * \param [in] alternateDr A pointer to the function parameters. |
| 268 | + * |
| 269 | + * \retval The datarate to apply. |
| 270 | + */ |
| 271 | + virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr ); |
| 272 | + |
| 273 | + /*! |
| 274 | + * \brief Calculates the back-off time. |
| 275 | + * |
| 276 | + * \param [in] calcBackOff A pointer to the function parameters. |
| 277 | + */ |
| 278 | + virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff ); |
| 279 | + |
| 280 | + /*! |
| 281 | + * \brief Searches and sets the next random available channel. |
| 282 | + * |
| 283 | + * \param [in] nextChanParams The parameters for the next channel |
| 284 | + * |
| 285 | + * \param [out] channel The next channel to use for TX. |
| 286 | + * |
| 287 | + * \param [out] time The time to wait for the next transmission according to the duty cycle. |
| 288 | + * |
| 289 | + * \param [out] aggregatedTimeOff Updates the aggregated time off. |
| 290 | + * |
| 291 | + * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate]. |
| 292 | + */ |
| 293 | + virtual bool set_next_channel(NextChanParams_t* nextChanParams, |
| 294 | + uint8_t* channel, TimerTime_t* time, |
| 295 | + TimerTime_t* aggregatedTimeOff ); |
| 296 | + |
| 297 | + /*! |
| 298 | + * \brief Adds a channel. |
| 299 | + * |
| 300 | + * \param [in] channelAdd A pointer to the function parameters. |
| 301 | + * |
| 302 | + * \retval The status of the operation. |
| 303 | + */ |
| 304 | + virtual LoRaMacStatus_t add_channel(ChannelAddParams_t* channelAdd ); |
| 305 | + |
| 306 | + /*! |
| 307 | + * \brief Removes a channel. |
| 308 | + * |
| 309 | + * \param [in] channelRemove A pointer to the function parameters. |
| 310 | + * |
| 311 | + * \retval True, if the channel was removed successfully. |
| 312 | + */ |
| 313 | + virtual bool remove_channel(ChannelRemoveParams_t* channelRemove ); |
| 314 | + |
| 315 | + /*! |
| 316 | + * \brief Sets the radio into continuous wave mode. |
| 317 | + * |
| 318 | + * \param [in] continuousWave A pointer to the function parameters. |
| 319 | + */ |
| 320 | + virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave ); |
| 321 | + |
| 322 | + /*! |
| 323 | + * \brief Computes a new datarate according to the given offset. |
| 324 | + * |
| 325 | + * \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms |
| 326 | + * |
| 327 | + * \param [in] dr The current datarate. |
| 328 | + * |
| 329 | + * \param [in] drOffset The offset to be applied. |
| 330 | + * |
| 331 | + * \retval newDr The computed datarate. |
| 332 | + */ |
| 333 | + virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset ); |
| 334 | + |
| 335 | +private: |
| 336 | + uint8_t CountNbOfEnabledChannels(bool joined, uint8_t datarate, |
| 337 | + uint16_t* channelsMask, |
| 338 | + ChannelParams_t* channels, Band_t* bands, |
| 339 | + uint8_t* enabledChannels, uint8_t* delayTx); |
| 340 | + |
| 341 | + // Global attributes |
| 342 | + /*! |
| 343 | + * LoRaMAC channels |
| 344 | + */ |
| 345 | + ChannelParams_t Channels[AS923_MAX_NB_CHANNELS]; |
| 346 | + |
| 347 | + /*! |
| 348 | + * LoRaMac bands |
| 349 | + */ |
| 350 | + Band_t Bands[AS923_MAX_NB_BANDS]; |
| 351 | + |
| 352 | + /*! |
| 353 | + * LoRaMac channels mask |
| 354 | + */ |
| 355 | + uint16_t ChannelsMask[AS923_CHANNELS_MASK_SIZE]; |
| 356 | + |
| 357 | + /*! |
| 358 | + * LoRaMac channels default mask |
| 359 | + */ |
| 360 | + uint16_t ChannelsDefaultMask[AS923_CHANNELS_MASK_SIZE]; |
| 361 | +}; |
| 362 | + |
| 363 | +#endif /* MBED_OS_LORAPHY_AS923_H_ */ |
0 commit comments