1 /*! 2 * \file RegionRU864.h 3 * 4 * \brief Region definition for RU864 5 * 6 * \copyright Revised BSD License, see section \ref LICENSE. 7 * 8 * \code 9 * ______ _ 10 * / _____) _ | | 11 * ( (____ _____ ____ _| |_ _____ ____| |__ 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 13 * _____) ) ____| | | || |_| ____( (___| | | | 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 15 * (C)2013-2017 Semtech 16 * 17 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 18 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 19 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 20 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 21 * embedded.connectivity.solutions=============== 22 * 23 * \endcode 24 * 25 * \author Miguel Luis ( Semtech ) 26 * 27 * \author Gregory Cristian ( Semtech ) 28 * 29 * \author Daniel Jaeckle ( STACKFORCE ) 30 * 31 * \defgroup REGIONRU864 Region RU864 32 * Implementation according to LoRaWAN Specification v1.0.2. 33 * \{ 34 */ 35 #ifndef __REGION_RU864_H__ 36 #define __REGION_RU864_H__ 37 38 #ifdef __cplusplus 39 extern "C" 40 { 41 #endif 42 43 #include "region/Region.h" 44 45 /*! 46 * LoRaMac maximum number of channels 47 */ 48 #define RU864_MAX_NB_CHANNELS 16 49 50 /*! 51 * Number of default channels 52 */ 53 #define RU864_NUMB_DEFAULT_CHANNELS 2 54 55 /*! 56 * Number of channels to apply for the CF list 57 */ 58 #define RU864_NUMB_CHANNELS_CF_LIST 5 59 60 /*! 61 * Minimal datarate that can be used by the node 62 */ 63 #define RU864_TX_MIN_DATARATE DR_0 64 65 /*! 66 * Maximal datarate that can be used by the node 67 */ 68 #define RU864_TX_MAX_DATARATE DR_7 69 70 /*! 71 * Minimal datarate that can be used by the node 72 */ 73 #define RU864_RX_MIN_DATARATE DR_0 74 75 /*! 76 * Maximal datarate that can be used by the node 77 */ 78 #define RU864_RX_MAX_DATARATE DR_7 79 80 /*! 81 * Default datarate used by the node 82 */ 83 #define RU864_DEFAULT_DATARATE DR_0 84 85 /*! 86 * Minimal Rx1 receive datarate offset 87 */ 88 #define RU864_MIN_RX1_DR_OFFSET 0 89 90 /*! 91 * Maximal Rx1 receive datarate offset 92 */ 93 #define RU864_MAX_RX1_DR_OFFSET 5 94 95 /*! 96 * Minimal Tx output power that can be used by the node 97 */ 98 #define RU864_MIN_TX_POWER TX_POWER_7 99 100 /*! 101 * Maximal Tx output power that can be used by the node 102 */ 103 #define RU864_MAX_TX_POWER TX_POWER_0 104 105 /*! 106 * Default Tx output power used by the node 107 */ 108 #define RU864_DEFAULT_TX_POWER TX_POWER_0 109 110 /*! 111 * Default Max EIRP 112 */ 113 #define RU864_DEFAULT_MAX_EIRP 16.0f 114 115 /*! 116 * Default antenna gain 117 */ 118 #define RU864_DEFAULT_ANTENNA_GAIN 2.15f 119 120 /*! 121 * Enabled or disabled the duty cycle 122 */ 123 #define RU864_DUTY_CYCLE_ENABLED 1 124 125 /*! 126 * Maximum RX window duration 127 */ 128 #define RU864_MAX_RX_WINDOW 3000 //TODO 129 130 #if ( RU864_DEFAULT_DATARATE > DR_5 ) 131 #error "A default DR higher than DR_5 may lead to connectivity loss." 132 #endif 133 134 /*! 135 * Second reception window channel frequency definition. 136 */ 137 #define RU864_RX_WND_2_FREQ 869100000 138 139 /*! 140 * Second reception window channel datarate definition. 141 */ 142 #define RU864_RX_WND_2_DR DR_0 143 144 /*! 145 * Default uplink dwell time configuration 146 */ 147 #define RU864_DEFAULT_UPLINK_DWELL_TIME 0 148 149 /* 150 * CLASS B 151 */ 152 /*! 153 * Beacon frequency 154 */ 155 #define RU864_BEACON_CHANNEL_FREQ 869100000 156 157 /*! 158 * Ping slot channel frequency 159 */ 160 #define RU864_PING_SLOT_CHANNEL_FREQ 868900000 161 162 /*! 163 * Payload size of a beacon frame 164 */ 165 #define RU864_BEACON_SIZE 17 166 167 /*! 168 * Size of RFU 1 field 169 */ 170 #define RU864_RFU1_SIZE 1 171 172 /*! 173 * Size of RFU 2 field 174 */ 175 #define RU864_RFU2_SIZE 0 176 177 /*! 178 * Datarate of the beacon channel 179 */ 180 #define RU864_BEACON_CHANNEL_DR DR_3 181 182 /*! 183 * Bandwith of the beacon channel (Index of BandwidthsRU864[]) 184 */ 185 #define RU864_BEACON_CHANNEL_BW 0 186 187 /*! 188 * Datarate of the ping slot channel 189 */ 190 #define RU864_PING_SLOT_CHANNEL_DR DR_3 191 192 /*! 193 * Ping slot channel datarate 194 */ 195 #define RU864_PING_SLOT_CHANNEL_DR DR_3 196 197 /*! 198 * Maximum number of bands 199 */ 200 #define RU864_MAX_NB_BANDS 1 201 202 /*! 203 * Band 0 definition 204 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 205 */ 206 #define RU864_BAND0 { 100 , RU864_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 1.0 % 207 208 /*! 209 * LoRaMac default channel 1 210 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 211 */ 212 #define RU864_LC1 { 868900000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } 213 214 /*! 215 * LoRaMac default channel 2 216 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 217 */ 218 #define RU864_LC2 { 869100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } 219 220 221 /*! 222 * LoRaMac channels which are allowed for the join procedure 223 */ 224 #define RU864_JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) ) 225 226 /*! 227 * Data rates table definition 228 */ 229 static const uint8_t DataratesRU864[] = { 12, 11, 10, 9, 8, 7, 7, 50 }; 230 231 /*! 232 * Bandwidths table definition in Hz 233 */ 234 static const uint32_t BandwidthsRU864[] = { 125000, 125000, 125000, 125000, 125000, 125000, 250000, 0 }; 235 236 /*! 237 * Maximum payload with respect to the datarate index. 238 */ 239 static const uint8_t MaxPayloadOfDatarateRU864[] = { 51, 51, 51, 115, 242, 242, 242, 242 }; 240 241 /*! 242 * \brief The function gets a value of a specific phy attribute. 243 * 244 * \param [IN] getPhy Pointer to the function parameters. 245 * 246 * \retval Returns a structure containing the PHY parameter. 247 */ 248 PhyParam_t RegionRU864GetPhyParam( GetPhyParams_t* getPhy ); 249 250 /*! 251 * \brief Updates the last TX done parameters of the current channel. 252 * 253 * \param [IN] txDone Pointer to the function parameters. 254 */ 255 void RegionRU864SetBandTxDone( SetBandTxDoneParams_t* txDone ); 256 257 /*! 258 * \brief Initializes the channels masks and the channels. 259 * 260 * \param [IN] type Sets the initialization type. 261 */ 262 void RegionRU864InitDefaults( InitDefaultsParams_t* params ); 263 264 /*! 265 * \brief Verifies a parameter. 266 * 267 * \param [IN] verify Pointer to the function parameters. 268 * 269 * \param [IN] type Sets the initialization type. 270 * 271 * \retval Returns true, if the parameter is valid. 272 */ 273 bool RegionRU864Verify( VerifyParams_t* verify, PhyAttribute_t phyAttribute ); 274 275 /*! 276 * \brief The function parses the input buffer and sets up the channels of the 277 * CF list. 278 * 279 * \param [IN] applyCFList Pointer to the function parameters. 280 */ 281 void RegionRU864ApplyCFList( ApplyCFListParams_t* applyCFList ); 282 283 /*! 284 * \brief Sets a channels mask. 285 * 286 * \param [IN] chanMaskSet Pointer to the function parameters. 287 * 288 * \retval Returns true, if the channels mask could be set. 289 */ 290 bool RegionRU864ChanMaskSet( ChanMaskSetParams_t* chanMaskSet ); 291 292 /*! 293 * Computes the Rx window timeout and offset. 294 * 295 * \param [IN] datarate Rx window datarate index to be used 296 * 297 * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame. 298 * 299 * \param [IN] rxError System maximum timing error of the receiver. In milliseconds 300 * The receiver will turn on in a [-rxError : +rxError] ms 301 * interval around RxOffset 302 * 303 * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields. 304 */ 305 void RegionRU864ComputeRxWindowParameters( int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams ); 306 307 /*! 308 * \brief Configuration of the RX windows. 309 * 310 * \param [IN] rxConfig Pointer to the function parameters. 311 * 312 * \param [OUT] datarate The datarate index which was set. 313 * 314 * \retval Returns true, if the configuration was applied successfully. 315 */ 316 bool RegionRU864RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ); 317 318 /*! 319 * \brief TX configuration. 320 * 321 * \param [IN] txConfig Pointer to the function parameters. 322 * 323 * \param [OUT] txPower The tx power index which was set. 324 * 325 * \param [OUT] txTimeOnAir The time-on-air of the frame. 326 * 327 * \retval Returns true, if the configuration was applied successfully. 328 */ 329 bool RegionRU864TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir ); 330 331 /*! 332 * \brief The function processes a Link ADR Request. 333 * 334 * \param [IN] linkAdrReq Pointer to the function parameters. 335 * 336 * \retval Returns the status of the operation, according to the LoRaMAC specification. 337 */ 338 uint8_t RegionRU864LinkAdrReq( LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed ); 339 340 /*! 341 * \brief The function processes a RX Parameter Setup Request. 342 * 343 * \param [IN] rxParamSetupReq Pointer to the function parameters. 344 * 345 * \retval Returns the status of the operation, according to the LoRaMAC specification. 346 */ 347 uint8_t RegionRU864RxParamSetupReq( RxParamSetupReqParams_t* rxParamSetupReq ); 348 349 /*! 350 * \brief The function processes a Channel Request. 351 * 352 * \param [IN] newChannelReq Pointer to the function parameters. 353 * 354 * \retval Returns the status of the operation, according to the LoRaMAC specification. 355 */ 356 int8_t RegionRU864NewChannelReq( NewChannelReqParams_t* newChannelReq ); 357 358 /*! 359 * \brief The function processes a TX ParamSetup Request. 360 * 361 * \param [IN] txParamSetupReq Pointer to the function parameters. 362 * 363 * \retval Returns the status of the operation, according to the LoRaMAC specification. 364 * Returns -1, if the functionality is not implemented. In this case, the end node 365 * shall not process the command. 366 */ 367 int8_t RegionRU864TxParamSetupReq( TxParamSetupReqParams_t* txParamSetupReq ); 368 369 /*! 370 * \brief The function processes a DlChannel Request. 371 * 372 * \param [IN] dlChannelReq Pointer to the function parameters. 373 * 374 * \retval Returns the status of the operation, according to the LoRaMAC specification. 375 */ 376 int8_t RegionRU864DlChannelReq( DlChannelReqParams_t* dlChannelReq ); 377 378 /*! 379 * \brief Alternates the datarate of the channel for the join request. 380 * 381 * \param [IN] currentDr Current datarate. 382 * 383 * \retval Datarate to apply. 384 */ 385 int8_t RegionRU864AlternateDr( int8_t currentDr, AlternateDrType_t type ); 386 387 /*! 388 * \brief Searches and set the next random available channel 389 * 390 * \param [OUT] channel Next channel to use for TX. 391 * 392 * \param [OUT] time Time to wait for the next transmission according to the duty 393 * cycle. 394 * 395 * \param [OUT] aggregatedTimeOff Updates the aggregated time off. 396 * 397 * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate] 398 */ 399 LoRaMacStatus_t RegionRU864NextChannel( NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff ); 400 401 /*! 402 * \brief Adds a channel. 403 * 404 * \param [IN] channelAdd Pointer to the function parameters. 405 * 406 * \retval Status of the operation. 407 */ 408 LoRaMacStatus_t RegionRU864ChannelAdd( ChannelAddParams_t* channelAdd ); 409 410 /*! 411 * \brief Removes a channel. 412 * 413 * \param [IN] channelRemove Pointer to the function parameters. 414 * 415 * \retval Returns true, if the channel was removed successfully. 416 */ 417 bool RegionRU864ChannelsRemove( ChannelRemoveParams_t* channelRemove ); 418 419 /*! 420 * \brief Computes new datarate according to the given offset 421 * 422 * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms 423 * 424 * \param [IN] dr Current datarate 425 * 426 * \param [IN] drOffset Offset to be applied 427 * 428 * \retval newDr Computed datarate. 429 */ 430 uint8_t RegionRU864ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset ); 431 432 /*! 433 * \brief Sets the radio into beacon reception mode 434 * 435 * \param [IN] rxBeaconSetup Pointer to the function parameters 436 */ 437 void RegionRU864RxBeaconSetup( RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr ); 438 439 /*! \} defgroup REGIONRU864 */ 440 441 #ifdef __cplusplus 442 } 443 #endif 444 445 #endif // __REGION_RU864_H__ 446