1 /*! 2 * \file RegionKR920.h 3 * 4 * \brief Region definition for KR920 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 REGIONKR920 Region KR920 34 * Implementation according to LoRaWAN Specification v1.0.2. 35 * \{ 36 */ 37 #ifndef __REGION_KR920_H__ 38 #define __REGION_KR920_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 KR920_MAX_NB_CHANNELS 16 51 52 /*! 53 * Number of default channels 54 */ 55 #define KR920_NUMB_DEFAULT_CHANNELS 3 56 57 /*! 58 * Number of channels to apply for the CF list 59 */ 60 #define KR920_NUMB_CHANNELS_CF_LIST 5 61 62 /*! 63 * Minimal datarate that can be used by the node 64 */ 65 #define KR920_TX_MIN_DATARATE DR_0 66 67 /*! 68 * Maximal datarate that can be used by the node 69 */ 70 #define KR920_TX_MAX_DATARATE DR_5 71 72 /*! 73 * Minimal datarate that can be used by the node 74 */ 75 #define KR920_RX_MIN_DATARATE DR_0 76 77 /*! 78 * Maximal datarate that can be used by the node 79 */ 80 #define KR920_RX_MAX_DATARATE DR_5 81 82 /*! 83 * Default datarate used by the node 84 */ 85 #define KR920_DEFAULT_DATARATE DR_0 86 87 /*! 88 * Minimal Rx1 receive datarate offset 89 */ 90 #define KR920_MIN_RX1_DR_OFFSET 0 91 92 /*! 93 * Maximal Rx1 receive datarate offset 94 */ 95 #define KR920_MAX_RX1_DR_OFFSET 5 96 97 /*! 98 * Minimal Tx output power that can be used by the node 99 */ 100 #define KR920_MIN_TX_POWER TX_POWER_7 101 102 /*! 103 * Maximal Tx output power that can be used by the node 104 */ 105 #define KR920_MAX_TX_POWER TX_POWER_0 106 107 /*! 108 * Default Tx output power used by the node 109 */ 110 #define KR920_DEFAULT_TX_POWER TX_POWER_0 111 112 /*! 113 * Default Max EIRP for frequency 920.9 MHz - 921.9 MHz 114 */ 115 #define KR920_DEFAULT_MAX_EIRP_LOW 10.0f 116 117 /*! 118 * Default Max EIRP for frequency 922.1 MHz - 923.3 MHz 119 */ 120 #define KR920_DEFAULT_MAX_EIRP_HIGH 14.0f 121 122 /*! 123 * Default antenna gain 124 */ 125 #define KR920_DEFAULT_ANTENNA_GAIN 2.15f 126 127 /*! 128 * Enabled or disabled the duty cycle 129 */ 130 #define KR920_DUTY_CYCLE_ENABLED 0 131 132 /*! 133 * Maximum RX window duration 134 */ 135 #define KR920_MAX_RX_WINDOW 4000 136 137 #if ( KR920_DEFAULT_DATARATE > DR_5 ) 138 #error "A default DR higher than DR_5 may lead to connectivity loss." 139 #endif 140 141 /*! 142 * Second reception window channel frequency definition. 143 */ 144 #define KR920_RX_WND_2_FREQ 921900000 145 146 /*! 147 * Second reception window channel datarate definition. 148 */ 149 #define KR920_RX_WND_2_DR DR_0 150 151 /*! 152 * Default uplink dwell time configuration 153 */ 154 #define KR920_DEFAULT_UPLINK_DWELL_TIME 0 155 156 /* 157 * CLASS B 158 */ 159 /*! 160 * Beacon frequency 161 */ 162 #define KR920_BEACON_CHANNEL_FREQ 923100000 163 164 /*! 165 * Ping slot channel frequency 166 */ 167 #define KR920_PING_SLOT_CHANNEL_FREQ 923100000 168 169 /*! 170 * Payload size of a beacon frame 171 */ 172 #define KR920_BEACON_SIZE 17 173 174 /*! 175 * Size of RFU 1 field 176 */ 177 #define KR920_RFU1_SIZE 1 178 179 /*! 180 * Size of RFU 2 field 181 */ 182 #define KR920_RFU2_SIZE 0 183 184 /*! 185 * Datarate of the beacon channel 186 */ 187 #define KR920_BEACON_CHANNEL_DR DR_3 188 189 /*! 190 * Bandwith of the beacon channel 191 */ 192 #define KR920_BEACON_CHANNEL_BW 0 193 194 /*! 195 * Ping slot channel datarate 196 */ 197 #define KR920_PING_SLOT_CHANNEL_DR DR_3 198 199 /*! 200 * Maximum number of bands 201 */ 202 #define KR920_MAX_NB_BANDS 1 203 204 /*! 205 * Band 0 definition 206 * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission } 207 */ 208 #define KR920_BAND0 { 1 , KR920_MAX_TX_POWER, 0, 0, 0, 0, 0 } // 100.0 % 209 210 /*! 211 * LoRaMac default channel 1 212 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 213 */ 214 #define KR920_LC1 { 922100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } 215 216 /*! 217 * LoRaMac default channel 2 218 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 219 */ 220 #define KR920_LC2 { 922300000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } 221 222 /*! 223 * LoRaMac default channel 3 224 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 225 */ 226 #define KR920_LC3 { 922500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } 227 228 /*! 229 * LoRaMac channels which are allowed for the join procedure 230 */ 231 #define KR920_JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) ) 232 233 /*! 234 * RSSI threshold for a free channel [dBm] 235 */ 236 #define KR920_RSSI_FREE_TH -65 237 238 /*! 239 * Specifies the time the node performs a carrier sense 240 */ 241 #define KR920_CARRIER_SENSE_TIME 6 242 243 /*! 244 * Data rates table definition 245 */ 246 static const uint8_t DataratesKR920[] = { 12, 11, 10, 9, 8, 7 }; 247 248 /*! 249 * Bandwidths table definition in Hz 250 */ 251 static const uint32_t BandwidthsKR920[] = { 125000, 125000, 125000, 125000, 125000, 125000 }; 252 253 /*! 254 * Maximum payload with respect to the datarate index. 255 */ 256 static const uint8_t MaxPayloadOfDatarateKR920[] = { 51, 51, 51, 115, 242, 242 }; 257 258 /*! 259 * \brief The function gets a value of a specific phy attribute. 260 * 261 * \param [IN] getPhy Pointer to the function parameters. 262 * 263 * \retval Returns a structure containing the PHY parameter. 264 */ 265 PhyParam_t RegionKR920GetPhyParam( GetPhyParams_t* getPhy ); 266 267 /*! 268 * \brief Updates the last TX done parameters of the current channel. 269 * 270 * \param [IN] txDone Pointer to the function parameters. 271 */ 272 void RegionKR920SetBandTxDone( SetBandTxDoneParams_t* txDone ); 273 274 /*! 275 * \brief Initializes the channels masks and the channels. 276 * 277 * \param [IN] type Sets the initialization type. 278 */ 279 void RegionKR920InitDefaults( InitDefaultsParams_t* params ); 280 281 /*! 282 * \brief Verifies a parameter. 283 * 284 * \param [IN] verify Pointer to the function parameters. 285 * 286 * \param [IN] type Sets the initialization type. 287 * 288 * \retval Returns true, if the parameter is valid. 289 */ 290 bool RegionKR920Verify( VerifyParams_t* verify, PhyAttribute_t phyAttribute ); 291 292 /*! 293 * \brief The function parses the input buffer and sets up the channels of the 294 * CF list. 295 * 296 * \param [IN] applyCFList Pointer to the function parameters. 297 */ 298 void RegionKR920ApplyCFList( ApplyCFListParams_t* applyCFList ); 299 300 /*! 301 * \brief Sets a channels mask. 302 * 303 * \param [IN] chanMaskSet Pointer to the function parameters. 304 * 305 * \retval Returns true, if the channels mask could be set. 306 */ 307 bool RegionKR920ChanMaskSet( ChanMaskSetParams_t* chanMaskSet ); 308 309 /*! 310 * Computes the Rx window timeout and offset. 311 * 312 * \param [IN] datarate Rx window datarate index to be used 313 * 314 * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame. 315 * 316 * \param [IN] rxError System maximum timing error of the receiver. In milliseconds 317 * The receiver will turn on in a [-rxError : +rxError] ms 318 * interval around RxOffset 319 * 320 * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields. 321 */ 322 void RegionKR920ComputeRxWindowParameters( int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams ); 323 324 /*! 325 * \brief Configuration of the RX windows. 326 * 327 * \param [IN] rxConfig Pointer to the function parameters. 328 * 329 * \param [OUT] datarate The datarate index which was set. 330 * 331 * \retval Returns true, if the configuration was applied successfully. 332 */ 333 bool RegionKR920RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ); 334 335 /*! 336 * \brief TX configuration. 337 * 338 * \param [IN] txConfig Pointer to the function parameters. 339 * 340 * \param [OUT] txPower The tx power index which was set. 341 * 342 * \param [OUT] txTimeOnAir The time-on-air of the frame. 343 * 344 * \retval Returns true, if the configuration was applied successfully. 345 */ 346 bool RegionKR920TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir ); 347 348 /*! 349 * \brief The function processes a Link ADR Request. 350 * 351 * \param [IN] linkAdrReq Pointer to the function parameters. 352 * 353 * \retval Returns the status of the operation, according to the LoRaMAC specification. 354 */ 355 uint8_t RegionKR920LinkAdrReq( LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed ); 356 357 /*! 358 * \brief The function processes a RX Parameter Setup Request. 359 * 360 * \param [IN] rxParamSetupReq Pointer to the function parameters. 361 * 362 * \retval Returns the status of the operation, according to the LoRaMAC specification. 363 */ 364 uint8_t RegionKR920RxParamSetupReq( RxParamSetupReqParams_t* rxParamSetupReq ); 365 366 /*! 367 * \brief The function processes a Channel Request. 368 * 369 * \param [IN] newChannelReq Pointer to the function parameters. 370 * 371 * \retval Returns the status of the operation, according to the LoRaMAC specification. 372 */ 373 int8_t RegionKR920NewChannelReq( NewChannelReqParams_t* newChannelReq ); 374 375 /*! 376 * \brief The function processes a TX ParamSetup Request. 377 * 378 * \param [IN] txParamSetupReq Pointer to the function parameters. 379 * 380 * \retval Returns the status of the operation, according to the LoRaMAC specification. 381 * Returns -1, if the functionality is not implemented. In this case, the end node 382 * shall not process the command. 383 */ 384 int8_t RegionKR920TxParamSetupReq( TxParamSetupReqParams_t* txParamSetupReq ); 385 386 /*! 387 * \brief The function processes a DlChannel Request. 388 * 389 * \param [IN] dlChannelReq Pointer to the function parameters. 390 * 391 * \retval Returns the status of the operation, according to the LoRaMAC specification. 392 */ 393 int8_t RegionKR920DlChannelReq( DlChannelReqParams_t* dlChannelReq ); 394 395 /*! 396 * \brief Alternates the datarate of the channel for the join request. 397 * 398 * \param [IN] currentDr current datarate. 399 * 400 * \retval Datarate to apply. 401 */ 402 int8_t RegionKR920AlternateDr( int8_t currentDr, AlternateDrType_t type ); 403 404 /*! 405 * \brief Searches and set the next random available channel 406 * 407 * \param [OUT] channel Next channel to use for TX. 408 * 409 * \param [OUT] time Time to wait for the next transmission according to the duty 410 * cycle. 411 * 412 * \param [OUT] aggregatedTimeOff Updates the aggregated time off. 413 * 414 * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate] 415 */ 416 LoRaMacStatus_t RegionKR920NextChannel( NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff ); 417 418 /*! 419 * \brief Adds a channel. 420 * 421 * \param [IN] channelAdd Pointer to the function parameters. 422 * 423 * \retval Status of the operation. 424 */ 425 LoRaMacStatus_t RegionKR920ChannelAdd( ChannelAddParams_t* channelAdd ); 426 427 /*! 428 * \brief Removes a channel. 429 * 430 * \param [IN] channelRemove Pointer to the function parameters. 431 * 432 * \retval Returns true, if the channel was removed successfully. 433 */ 434 bool RegionKR920ChannelsRemove( ChannelRemoveParams_t* channelRemove ); 435 436 /*! 437 * \brief Computes new datarate according to the given offset 438 * 439 * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms 440 * 441 * \param [IN] dr Current datarate 442 * 443 * \param [IN] drOffset Offset to be applied 444 * 445 * \retval newDr Computed datarate. 446 */ 447 uint8_t RegionKR920ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset ); 448 449 /*! 450 * \brief Sets the radio into beacon reception mode 451 * 452 * \param [IN] rxBeaconSetup Pointer to the function parameters 453 */ 454 void RegionKR920RxBeaconSetup( RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr ); 455 456 /*! \} defgroup REGIONKR920 */ 457 458 #ifdef __cplusplus 459 } 460 #endif 461 462 #endif // __REGION_KR920_H__ 463