1 /*! 2 * \file RegionEU868.h 3 * 4 * \brief Region definition for EU868 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 * \author Johannes Bruder ( STACKFORCE ) 32 * 33 * \defgroup REGIONEU868 Region EU868 34 * Implementation according to LoRaWAN Specification v1.0.2. 35 * \{ 36 */ 37 #ifndef __REGION_EU868_H__ 38 #define __REGION_EU868_H__ 39 40 #ifdef __cplusplus 41 extern "C" 42 { 43 #endif 44 45 #include "region/Region.h" 46 47 /*! 48 * LoRaMac maximum number of channels 49 */ 50 #define EU868_MAX_NB_CHANNELS 16 51 52 /*! 53 * Number of default channels 54 */ 55 #define EU868_NUMB_DEFAULT_CHANNELS 3 56 57 /*! 58 * Number of channels to apply for the CF list 59 */ 60 #define EU868_NUMB_CHANNELS_CF_LIST 5 61 62 /*! 63 * Minimal datarate that can be used by the node 64 */ 65 #define EU868_TX_MIN_DATARATE DR_0 66 67 /*! 68 * Maximal datarate that can be used by the node 69 */ 70 #define EU868_TX_MAX_DATARATE DR_7 71 72 /*! 73 * Minimal datarate that can be used by the node 74 */ 75 #define EU868_RX_MIN_DATARATE DR_0 76 77 /*! 78 * Maximal datarate that can be used by the node 79 */ 80 #define EU868_RX_MAX_DATARATE DR_7 81 82 /*! 83 * Default datarate used by the node 84 */ 85 #define EU868_DEFAULT_DATARATE DR_0 86 87 /*! 88 * Minimal Rx1 receive datarate offset 89 */ 90 #define EU868_MIN_RX1_DR_OFFSET 0 91 92 /*! 93 * Maximal Rx1 receive datarate offset 94 */ 95 #define EU868_MAX_RX1_DR_OFFSET 5 96 97 /*! 98 * Minimal Tx output power that can be used by the node 99 */ 100 #define EU868_MIN_TX_POWER TX_POWER_7 101 102 /*! 103 * Maximal Tx output power that can be used by the node 104 */ 105 #define EU868_MAX_TX_POWER TX_POWER_0 106 107 /*! 108 * Default Tx output power used by the node 109 */ 110 #define EU868_DEFAULT_TX_POWER TX_POWER_0 111 112 /*! 113 * Default Max EIRP 114 */ 115 #define EU868_DEFAULT_MAX_EIRP 16.0f 116 117 /*! 118 * Default antenna gain 119 */ 120 #define EU868_DEFAULT_ANTENNA_GAIN 2.15f 121 122 /*! 123 * Enabled or disabled the duty cycle 124 */ 125 #define EU868_DUTY_CYCLE_ENABLED 1 126 127 /*! 128 * Maximum RX window duration 129 */ 130 #define EU868_MAX_RX_WINDOW 3000 131 132 #if ( EU868_DEFAULT_DATARATE > DR_5 ) 133 #error "A default DR higher than DR_5 may lead to connectivity loss." 134 #endif 135 136 /*! 137 * Second reception window channel frequency definition. 138 */ 139 #define EU868_RX_WND_2_FREQ 869525000 140 141 /*! 142 * Second reception window channel datarate definition. 143 */ 144 #define EU868_RX_WND_2_DR DR_0 145 146 /*! 147 * Default uplink dwell time configuration 148 */ 149 #define EU868_DEFAULT_UPLINK_DWELL_TIME 0 150 151 /* 152 * CLASS B 153 */ 154 /*! 155 * Beacon frequency 156 */ 157 #define EU868_BEACON_CHANNEL_FREQ 869525000 158 159 /*! 160 * Ping slot channel frequency 161 */ 162 #define EU868_PING_SLOT_CHANNEL_FREQ 869525000 163 164 /*! 165 * Payload size of a beacon frame 166 */ 167 #define EU868_BEACON_SIZE 17 168 169 /*! 170 * Size of RFU 1 field 171 */ 172 #define EU868_RFU1_SIZE 1 173 174 /*! 175 * Size of RFU 2 field 176 */ 177 #define EU868_RFU2_SIZE 0 178 179 /*! 180 * Datarate of the beacon channel 181 */ 182 #define EU868_BEACON_CHANNEL_DR DR_3 183 184 /*! 185 * Bandwith of the beacon channel 186 */ 187 #define EU868_BEACON_CHANNEL_BW 0 188 189 /*! 190 * Ping slot channel datarate 191 */ 192 #define EU868_PING_SLOT_CHANNEL_DR DR_3 193 194 /*! 195 * Maximum number of bands 196 */ 197 #define EU868_MAX_NB_BANDS 6 198 199 /*! 200 * Band 0 definition 201 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 202 */ 203 #define EU868_BAND0 { 100 , EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 1.0 % 204 205 /*! 206 * Band 1 definition 207 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 208 */ 209 #define EU868_BAND1 { 100 , EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 1.0 % 210 211 /*! 212 * Band 2 definition 213 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 214 */ 215 #define EU868_BAND2 { 1000, EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 0.1 % 216 217 /*! 218 * Band 3 definition 219 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 220 */ 221 #define EU868_BAND3 { 10 , EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 10.0 % 222 223 /*! 224 * Band 4 definition 225 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 226 */ 227 #define EU868_BAND4 { 100 , EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 1.0 % 228 229 /*! 230 * Band 5 definition 231 * Band = { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff, 232 * DutyCycleTimePeriod, MaxAllowedTimeOnAir, AggregatedTimeOnAir, StartTimeOfPeriod } 233 */ 234 #define EU868_BAND5 { 1000, EU868_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 0.1 % 235 236 /*! 237 * LoRaMac default channel 1 238 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 239 */ 240 #define EU868_LC1 { 868100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 } 241 242 /*! 243 * LoRaMac default channel 2 244 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 245 */ 246 #define EU868_LC2 { 868300000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 } 247 248 /*! 249 * LoRaMac default channel 3 250 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 251 */ 252 #define EU868_LC3 { 868500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 } 253 254 /*! 255 * LoRaMac channels which are allowed for the join procedure 256 */ 257 #define EU868_JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) ) 258 259 /*! 260 * Data rates table definition 261 */ 262 static const uint8_t DataratesEU868[] = { 12, 11, 10, 9, 8, 7, 7, 50 }; 263 264 /*! 265 * Bandwidths table definition in Hz 266 */ 267 static const uint32_t BandwidthsEU868[] = { 125000, 125000, 125000, 125000, 125000, 125000, 250000, 0 }; 268 269 /*! 270 * Maximum payload with respect to the datarate index. 271 */ 272 static const uint8_t MaxPayloadOfDatarateEU868[] = { 51, 51, 51, 115, 242, 242, 242, 242 }; 273 274 /*! 275 * \brief The function gets a value of a specific phy attribute. 276 * 277 * \param [IN] getPhy Pointer to the function parameters. 278 * 279 * \retval Returns a structure containing the PHY parameter. 280 */ 281 PhyParam_t RegionEU868GetPhyParam( GetPhyParams_t* getPhy ); 282 283 /*! 284 * \brief Updates the last TX done parameters of the current channel. 285 * 286 * \param [IN] txDone Pointer to the function parameters. 287 */ 288 void RegionEU868SetBandTxDone( SetBandTxDoneParams_t* txDone ); 289 290 /*! 291 * \brief Initializes the channels masks and the channels. 292 * 293 * \param [IN] type Sets the initialization type. 294 */ 295 void RegionEU868InitDefaults( InitDefaultsParams_t* params ); 296 297 /*! 298 * \brief Verifies a parameter. 299 * 300 * \param [IN] verify Pointer to the function parameters. 301 * 302 * \param [IN] type Sets the initialization type. 303 * 304 * \retval Returns true, if the parameter is valid. 305 */ 306 bool RegionEU868Verify( VerifyParams_t* verify, PhyAttribute_t phyAttribute ); 307 308 /*! 309 * \brief The function parses the input buffer and sets up the channels of the 310 * CF list. 311 * 312 * \param [IN] applyCFList Pointer to the function parameters. 313 */ 314 void RegionEU868ApplyCFList( ApplyCFListParams_t* applyCFList ); 315 316 /*! 317 * \brief Sets a channels mask. 318 * 319 * \param [IN] chanMaskSet Pointer to the function parameters. 320 * 321 * \retval Returns true, if the channels mask could be set. 322 */ 323 bool RegionEU868ChanMaskSet( ChanMaskSetParams_t* chanMaskSet ); 324 325 /*! 326 * Computes the Rx window timeout and offset. 327 * 328 * \param [IN] datarate Rx window datarate index to be used 329 * 330 * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame. 331 * 332 * \param [IN] rxError System maximum timing error of the receiver. In milliseconds 333 * The receiver will turn on in a [-rxError : +rxError] ms 334 * interval around RxOffset 335 * 336 * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields. 337 */ 338 void RegionEU868ComputeRxWindowParameters( int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams ); 339 340 /*! 341 * \brief Configuration of the RX windows. 342 * 343 * \param [IN] rxConfig Pointer to the function parameters. 344 * 345 * \param [OUT] datarate The datarate index which was set. 346 * 347 * \retval Returns true, if the configuration was applied successfully. 348 */ 349 bool RegionEU868RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ); 350 351 /*! 352 * \brief TX configuration. 353 * 354 * \param [IN] txConfig Pointer to the function parameters. 355 * 356 * \param [OUT] txPower The tx power index which was set. 357 * 358 * \param [OUT] txTimeOnAir The time-on-air of the frame. 359 * 360 * \retval Returns true, if the configuration was applied successfully. 361 */ 362 bool RegionEU868TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir ); 363 364 /*! 365 * \brief The function processes a Link ADR Request. 366 * 367 * \param [IN] linkAdrReq Pointer to the function parameters. 368 * 369 * \retval Returns the status of the operation, according to the LoRaMAC specification. 370 */ 371 uint8_t RegionEU868LinkAdrReq( LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed ); 372 373 /*! 374 * \brief The function processes a RX Parameter Setup Request. 375 * 376 * \param [IN] rxParamSetupReq Pointer to the function parameters. 377 * 378 * \retval Returns the status of the operation, according to the LoRaMAC specification. 379 */ 380 uint8_t RegionEU868RxParamSetupReq( RxParamSetupReqParams_t* rxParamSetupReq ); 381 382 /*! 383 * \brief The function processes a Channel Request. 384 * 385 * \param [IN] newChannelReq Pointer to the function parameters. 386 * 387 * \retval Returns the status of the operation, according to the LoRaMAC specification. 388 */ 389 int8_t RegionEU868NewChannelReq( NewChannelReqParams_t* newChannelReq ); 390 391 /*! 392 * \brief The function processes a TX ParamSetup Request. 393 * 394 * \param [IN] txParamSetupReq Pointer to the function parameters. 395 * 396 * \retval Returns the status of the operation, according to the LoRaMAC specification. 397 * Returns -1, if the functionality is not implemented. In this case, the end node 398 * shall not process the command. 399 */ 400 int8_t RegionEU868TxParamSetupReq( TxParamSetupReqParams_t* txParamSetupReq ); 401 402 /*! 403 * \brief The function processes a DlChannel Request. 404 * 405 * \param [IN] dlChannelReq Pointer to the function parameters. 406 * 407 * \retval Returns the status of the operation, according to the LoRaMAC specification. 408 */ 409 int8_t RegionEU868DlChannelReq( DlChannelReqParams_t* dlChannelReq ); 410 411 /*! 412 * \brief Alternates the datarate of the channel for the join request. 413 * 414 * \param [IN] currentDr Current datarate. 415 * 416 * \retval Datarate to apply. 417 */ 418 int8_t RegionEU868AlternateDr( int8_t currentDr, AlternateDrType_t type ); 419 420 /*! 421 * \brief Searches and set the next random available channel 422 * 423 * \param [OUT] channel Next channel to use for TX. 424 * 425 * \param [OUT] time Time to wait for the next transmission according to the duty 426 * cycle. 427 * 428 * \param [OUT] aggregatedTimeOff Updates the aggregated time off. 429 * 430 * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate] 431 */ 432 LoRaMacStatus_t RegionEU868NextChannel( NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff ); 433 434 /*! 435 * \brief Adds a channel. 436 * 437 * \param [IN] channelAdd Pointer to the function parameters. 438 * 439 * \retval Status of the operation. 440 */ 441 LoRaMacStatus_t RegionEU868ChannelAdd( ChannelAddParams_t* channelAdd ); 442 443 /*! 444 * \brief Removes a channel. 445 * 446 * \param [IN] channelRemove Pointer to the function parameters. 447 * 448 * \retval Returns true, if the channel was removed successfully. 449 */ 450 bool RegionEU868ChannelsRemove( ChannelRemoveParams_t* channelRemove ); 451 452 /*! 453 * \brief Computes new datarate according to the given offset 454 * 455 * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms 456 * 457 * \param [IN] dr Current datarate 458 * 459 * \param [IN] drOffset Offset to be applied 460 * 461 * \retval newDr Computed datarate. 462 */ 463 uint8_t RegionEU868ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset ); 464 465 /*! 466 * \brief Sets the radio into beacon reception mode 467 * 468 * \param [IN] rxBeaconSetup Pointer to the function parameters 469 */ 470 void RegionEU868RxBeaconSetup( RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr ); 471 472 /*! \} defgroup REGIONEU868 */ 473 474 #ifdef __cplusplus 475 } 476 #endif 477 478 #endif // __REGION_EU868_H__ 479