1 /*!
2  * \file      RegionEU433.h
3  *
4  * \brief     Region definition for EU433
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  REGIONEU433 Region EU433
34  *            Implementation according to LoRaWAN Specification v1.0.2.
35  * \{
36  */
37 #ifndef __REGION_EU433_H__
38 #define __REGION_EU433_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 EU433_MAX_NB_CHANNELS                       16
51 
52 /*!
53  * Number of default channels
54  */
55 #define EU433_NUMB_DEFAULT_CHANNELS                 3
56 
57 /*!
58  * Number of channels to apply for the CF list
59  */
60 #define EU433_NUMB_CHANNELS_CF_LIST                 5
61 
62 /*!
63  * Minimal datarate that can be used by the node
64  */
65 #define EU433_TX_MIN_DATARATE                       DR_0
66 
67 /*!
68  * Maximal datarate that can be used by the node
69  */
70 #define EU433_TX_MAX_DATARATE                       DR_7
71 
72 /*!
73  * Minimal datarate that can be used by the node
74  */
75 #define EU433_RX_MIN_DATARATE                       DR_0
76 
77 /*!
78  * Maximal datarate that can be used by the node
79  */
80 #define EU433_RX_MAX_DATARATE                       DR_7
81 
82 /*!
83  * Default datarate used by the node
84  */
85 #define EU433_DEFAULT_DATARATE                      DR_0
86 
87 /*!
88  * Minimal Rx1 receive datarate offset
89  */
90 #define EU433_MIN_RX1_DR_OFFSET                     0
91 
92 /*!
93  * Maximal Rx1 receive datarate offset
94  */
95 #define EU433_MAX_RX1_DR_OFFSET                     5
96 
97 /*!
98  * Minimal Tx output power that can be used by the node
99  */
100 #define EU433_MIN_TX_POWER                          TX_POWER_5
101 
102 /*!
103  * Maximal Tx output power that can be used by the node
104  */
105 #define EU433_MAX_TX_POWER                          TX_POWER_0
106 
107 /*!
108  * Default Tx output power used by the node
109  */
110 #define EU433_DEFAULT_TX_POWER                      TX_POWER_0
111 
112 /*!
113  * Default Max EIRP
114  */
115 #define EU433_DEFAULT_MAX_EIRP                      12.15f
116 
117 /*!
118  * Default antenna gain
119  */
120 #define EU433_DEFAULT_ANTENNA_GAIN                  2.15f
121 
122 /*!
123  * Enabled or disabled the duty cycle
124  */
125 #define EU433_DUTY_CYCLE_ENABLED                    1
126 
127 /*!
128  * Maximum RX window duration
129  */
130 #define EU433_MAX_RX_WINDOW                         3000
131 
132 /*!
133  * Verification of default datarate
134  */
135 #if ( EU433_DEFAULT_DATARATE > DR_5 )
136 #error "A default DR higher than DR_5 may lead to connectivity loss."
137 #endif
138 
139 /*!
140  * Second reception window channel frequency definition.
141  */
142 #define EU433_RX_WND_2_FREQ                         434665000
143 
144 /*!
145  * Second reception window channel datarate definition.
146  */
147 #define EU433_RX_WND_2_DR                           DR_0
148 
149 /*!
150  * LoRaMac maximum number of bands
151  */
152 #define EU433_MAX_NB_BANDS                          1
153 
154 /*!
155  * Default uplink dwell time configuration
156  */
157 #define EU433_DEFAULT_UPLINK_DWELL_TIME             0
158 
159 /*
160  * CLASS B
161  */
162 /*!
163  * Beacon frequency
164  */
165 #define EU433_BEACON_CHANNEL_FREQ                   434665000
166 
167 /*!
168  * Ping slot channel frequency
169  */
170 #define EU433_PING_SLOT_CHANNEL_FREQ                434665000
171 
172 /*!
173  * Payload size of a beacon frame
174  */
175 #define EU433_BEACON_SIZE                           17
176 
177 /*!
178  * Size of RFU 1 field
179  */
180 #define EU433_RFU1_SIZE                             1
181 
182 /*!
183  * Size of RFU 2 field
184  */
185 #define EU433_RFU2_SIZE                             0
186 
187 /*!
188  * Datarate of the beacon channel
189  */
190 #define EU433_BEACON_CHANNEL_DR                     DR_3
191 
192 /*!
193  * Bandwith of the beacon channel
194  */
195 #define EU433_BEACON_CHANNEL_BW                     0
196 
197 /*!
198  * Ping slot channel datarate
199  */
200 #define EU433_PING_SLOT_CHANNEL_DR                  DR_3
201 
202 /*!
203  * Band 0 definition
204  * Band = { DutyCycle, TxMaxPower, LastBandUpdateTime, LastMaxCreditAssignTime, TimeCredits, MaxTimeCredits, ReadyForTransmission }
205  */
206 #define EU433_BAND0                                 { 100, EU433_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 EU433_LC1                                   { 433175000, 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 EU433_LC2                                   { 433375000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
219 
220 /*!
221  * LoRaMac default channel 3
222  * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
223  */
224 #define EU433_LC3                                   { 433575000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
225 
226 /*!
227  * LoRaMac channels which are allowed for the join procedure
228  */
229 #define EU433_JOIN_CHANNELS                         ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) )
230 
231 /*!
232  * Data rates table definition
233  */
234 static const uint8_t DataratesEU433[] = { 12, 11, 10,  9,  8,  7,  7, 50 };
235 
236 /*!
237  * Bandwidths table definition in Hz
238  */
239 static const uint32_t BandwidthsEU433[] = { 125000, 125000, 125000, 125000, 125000, 125000, 250000, 0 };
240 
241 /*!
242  * Maximum payload with respect to the datarate index.
243  */
244 static const uint8_t MaxPayloadOfDatarateEU433[] = { 51, 51, 51, 115, 242, 242, 242, 242 };
245 
246 /*!
247  * \brief The function gets a value of a specific phy attribute.
248  *
249  * \param [IN] getPhy Pointer to the function parameters.
250  *
251  * \retval Returns a structure containing the PHY parameter.
252  */
253 PhyParam_t RegionEU433GetPhyParam( GetPhyParams_t* getPhy );
254 
255 /*!
256  * \brief Updates the last TX done parameters of the current channel.
257  *
258  * \param [IN] txDone Pointer to the function parameters.
259  */
260 void RegionEU433SetBandTxDone( SetBandTxDoneParams_t* txDone );
261 
262 /*!
263  * \brief Initializes the channels masks and the channels.
264  *
265  * \param [IN] type Sets the initialization type.
266  */
267 void RegionEU433InitDefaults( InitDefaultsParams_t* params );
268 
269 /*!
270  * \brief Verifies a parameter.
271  *
272  * \param [IN] verify Pointer to the function parameters.
273  *
274  * \param [IN] type Sets the initialization type.
275  *
276  * \retval Returns true, if the parameter is valid.
277  */
278 bool RegionEU433Verify( VerifyParams_t* verify, PhyAttribute_t phyAttribute );
279 
280 /*!
281  * \brief The function parses the input buffer and sets up the channels of the
282  *        CF list.
283  *
284  * \param [IN] applyCFList Pointer to the function parameters.
285  */
286 void RegionEU433ApplyCFList( ApplyCFListParams_t* applyCFList );
287 
288 /*!
289  * \brief Sets a channels mask.
290  *
291  * \param [IN] chanMaskSet Pointer to the function parameters.
292  *
293  * \retval Returns true, if the channels mask could be set.
294  */
295 bool RegionEU433ChanMaskSet( ChanMaskSetParams_t* chanMaskSet );
296 
297 /*!
298  * Computes the Rx window timeout and offset.
299  *
300  * \param [IN] datarate     Rx window datarate index to be used
301  *
302  * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame.
303  *
304  * \param [IN] rxError      System maximum timing error of the receiver. In milliseconds
305  *                          The receiver will turn on in a [-rxError : +rxError] ms
306  *                          interval around RxOffset
307  *
308  * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields.
309  */
310 void RegionEU433ComputeRxWindowParameters( int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams );
311 
312 /*!
313  * \brief Configuration of the RX windows.
314  *
315  * \param [IN] rxConfig Pointer to the function parameters.
316  *
317  * \param [OUT] datarate The datarate index which was set.
318  *
319  * \retval Returns true, if the configuration was applied successfully.
320  */
321 bool RegionEU433RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate );
322 
323 /*!
324  * \brief TX configuration.
325  *
326  * \param [IN] txConfig Pointer to the function parameters.
327  *
328  * \param [OUT] txPower The tx power index which was set.
329  *
330  * \param [OUT] txTimeOnAir The time-on-air of the frame.
331  *
332  * \retval Returns true, if the configuration was applied successfully.
333  */
334 bool RegionEU433TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir );
335 
336 /*!
337  * \brief The function processes a Link ADR Request.
338  *
339  * \param [IN] linkAdrReq Pointer to the function parameters.
340  *
341  * \retval Returns the status of the operation, according to the LoRaMAC specification.
342  */
343 uint8_t RegionEU433LinkAdrReq( LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed );
344 
345 /*!
346  * \brief The function processes a RX Parameter Setup Request.
347  *
348  * \param [IN] rxParamSetupReq Pointer to the function parameters.
349  *
350  * \retval Returns the status of the operation, according to the LoRaMAC specification.
351  */
352 uint8_t RegionEU433RxParamSetupReq( RxParamSetupReqParams_t* rxParamSetupReq );
353 
354 /*!
355  * \brief The function processes a Channel Request.
356  *
357  * \param [IN] newChannelReq Pointer to the function parameters.
358  *
359  * \retval Returns the status of the operation, according to the LoRaMAC specification.
360  */
361 int8_t RegionEU433NewChannelReq( NewChannelReqParams_t* newChannelReq );
362 
363 /*!
364  * \brief The function processes a TX ParamSetup Request.
365  *
366  * \param [IN] txParamSetupReq Pointer to the function parameters.
367  *
368  * \retval Returns the status of the operation, according to the LoRaMAC specification.
369  *         Returns -1, if the functionality is not implemented. In this case, the end node
370  *         shall not process the command.
371  */
372 int8_t RegionEU433TxParamSetupReq( TxParamSetupReqParams_t* txParamSetupReq );
373 
374 /*!
375  * \brief The function processes a DlChannel Request.
376  *
377  * \param [IN] dlChannelReq Pointer to the function parameters.
378  *
379  * \retval Returns the status of the operation, according to the LoRaMAC specification.
380  */
381 int8_t RegionEU433DlChannelReq( DlChannelReqParams_t* dlChannelReq );
382 
383 /*!
384  * \brief Alternates the datarate of the channel for the join request.
385  *
386  * \param [IN] currentDr Current datarate.
387  *
388  * \retval Datarate to apply.
389  */
390 int8_t RegionEU433AlternateDr( int8_t currentDr, AlternateDrType_t type );
391 
392 /*!
393  * \brief Searches and set the next random available channel
394  *
395  * \param [OUT] channel Next channel to use for TX.
396  *
397  * \param [OUT] time Time to wait for the next transmission according to the duty
398  *              cycle.
399  *
400  * \param [OUT] aggregatedTimeOff Updates the aggregated time off.
401  *
402  * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate]
403  */
404 LoRaMacStatus_t RegionEU433NextChannel( NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff );
405 
406 /*!
407  * \brief Adds a channel.
408  *
409  * \param [IN] channelAdd Pointer to the function parameters.
410  *
411  * \retval Status of the operation.
412  */
413 LoRaMacStatus_t RegionEU433ChannelAdd( ChannelAddParams_t* channelAdd );
414 
415 /*!
416  * \brief Removes a channel.
417  *
418  * \param [IN] channelRemove Pointer to the function parameters.
419  *
420  * \retval Returns true, if the channel was removed successfully.
421  */
422 bool RegionEU433ChannelsRemove( ChannelRemoveParams_t* channelRemove  );
423 
424 /*!
425  * \brief Computes new datarate according to the given offset
426  *
427  * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms
428  *
429  * \param [IN] dr Current datarate
430  *
431  * \param [IN] drOffset Offset to be applied
432  *
433  * \retval newDr Computed datarate.
434  */
435 uint8_t RegionEU433ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
436 
437 /*!
438  * \brief Sets the radio into beacon reception mode
439  *
440  * \param [IN] rxBeaconSetup Pointer to the function parameters
441  */
442 void RegionEU433RxBeaconSetup( RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr );
443 
444 /*! \} defgroup REGIONEU433 */
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif // __REGION_EU433_H__
451