Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic_bandplan.h
1/*
2* Copyright (c) 2014-2016 IBM Corporation.
3* Copyright (c) 2017, 2019-2021 MCCI Corporation.
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef _lmic_bandplan_h_
30# define _lmic_bandplan_h_
31
32#ifndef _lmic_h_
33# include "lmic.h"
34#endif
35
36#if defined(CFG_eu868)
37# include "lmic_bandplan_eu868.h"
38#elif defined(CFG_us915)
39# include "lmic_bandplan_us915.h"
40#elif defined(CFG_au915)
41# include "lmic_bandplan_au915.h"
42#elif defined(CFG_as923)
43# include "lmic_bandplan_as923.h"
44#elif defined(CFG_kr920)
45# include "lmic_bandplan_kr920.h"
46#elif defined(CFG_in866)
47# include "lmic_bandplan_in866.h"
48#else
49# error "CFG_... not properly set for bandplan"
50#endif
51
52// check post-conditions
53#ifndef DNW2_SAFETY_ZONE
54# error "DNW2_SAFETY_ZONE not defined by bandplan"
55#endif
56
57#ifndef LMICbandplan_maxFrameLen
58# error "LMICbandplan_maxFrameLen() not defined by bandplan"
59#endif
60
61#ifndef pow2dBm
62# error "pow2dBm() not defined by bandplan"
63#endif
64
65#ifndef dr2hsym
66# error "dr2hsym() not defined by bandplan"
67#endif
68
69#if !defined(LMICbandplan_isValidBeacon1) && !defined(DISABLE_BEACONS)
70# error "LMICbandplan_isValidBeacon1 not defined by bandplan"
71#endif
72
73#if !defined(LMICbandplan_isFSK)
74# error "LMICbandplan_isFSK() not defined by bandplan"
75#endif
76
77#if !defined(LMICbandplan_txDoneFSK)
78# error "LMICbandplan_txDoneFSK() not defined by bandplan"
79#endif
80
81#if !defined(LMICbandplan_joinAcceptChannelClear)
82# error "LMICbandplan_joinAcceptChannelClear() not defined by bandplan"
83#endif
84
85#if !defined(LMICbandplan_getInitialDrJoin)
86# error "LMICbandplan_getInitialDrJoin() not defined by bandplan"
87#endif
88
89#if !defined(LMICbandplan_hasJoinCFlist)
90# error "LMICbandplan_hasJoinCFlist() not defined by bandplan"
91#endif
92
93#if !defined(LMICbandplan_advanceBeaconChannel)
94# error "LMICbandplan_advanceBeaconChannel() not defined by bandplan"
95#endif
96
97#if !defined(LMICbandplan_resetDefaultChannels)
98# error "LMICbandplan_resetDefaultChannels() not defined by bandplan"
99#endif
100
101#if !defined(LMICbandplan_setSessionInitDefaultChannels)
102# error "LMICbandplan_setSessionInitDefaultChannels() not defined by bandplan"
103#endif
104
105#if !defined(LMICbandplan_setBcnRxParams)
106# error "LMICbandplan_setBcnRxParams() not defined by bandplan"
107#endif
108
109#if !defined(LMICbandplan_canMapChannels)
110# error "LMICbandplan_canMapChannels() not defined by bandplan"
111#endif
112
113#if !defined(LMICbandplan_mapChannels)
114# error "LMICbandplan_mapChannels() not defined by bandplan"
115#endif
116
117#if !defined(LMICbandplan_convFreq)
118# error "LMICbandplan_convFreq() not defined by bandplan"
119#endif
120
121#if !defined(LMICbandplan_queryMaxRx1DrOffset)
122# error "LMICbandplan_queryMaxRx1DrOffset() not defined by bandplan"
123#endif
124
125#if !defined(LMICbandplan_setRx1Params)
126# error "LMICbandplan_setRx1Params() not defined by bandplan"
127#endif
128
129#if !defined(LMICbandplan_initJoinLoop)
130# error "LMICbandplan_initJoinLoop() not defined by bandplan"
131#endif
132
133#if !defined(LMICbandplan_nextTx)
134# error "LMICbandplan_nextTx() not defined by bandplan"
135#endif
136
137#if !defined(LMICbandplan_updateTx)
138# error "LMICbandplan_updateTx() not defined by bandplan"
139#endif
140
141#if !defined(LMICbandplan_nextJoinState)
142# error "LMICbandplan_nextJoinState() not defined by bandplan"
143#endif
144
145#if !defined(LMICbandplan_initDefaultChannels)
146# error "LMICbandplan_initDefaultChannels() not defined by bandplan"
147#endif
148
149#if !defined(LMICbandplan_nextJoinTime)
150# error "LMICbandplan_nextJoinTime() not defined by bandplan"
151#endif
152
153#if !defined(LMICbandplan_init)
154# error "LMICbandplan_init() not defined by bandplan"
155#endif
156
157#if !defined(LMICbandplan_saveAdrState)
158# error "LMICbandplan_saveAdrState() not defined by bandplan"
159#endif
160
161#if !defined(LMICbandplan_compareAdrState)
162# error "LMICbandplan_compareAdrState() not defined by bandplan"
163#endif
164
165#if !defined(LMICbandplan_restoreAdrState)
166# error "LMICbandplan_restoreAdrState() not defined by bandplan"
167#endif
168
169#if !defined(LMICbandplan_isDataRateFeasible)
170# error "LMICbandplan_isDataRateFeasible() not defined by bandplan"
171#endif
172
173#if !defined(LMICbandplan_validDR)
174# error "LMICbandplan_validDR() not defined by bandplan"
175#endif
176
177#if !defined(LMICbandplan_processJoinAcceptCFList)
178# error "LMICbandplan_processJoinAcceptCFList() not defined by bandplan"
179#endif
180
181//
182// Things common to lmic.c code
183//
184#define LMICbandplan_MINRX_SYMS_LoRa_ClassA 6
185#define LMICbandplan_RX_ERROR_ABS_osticks ms2osticks(10)
186
187// Semtech inherently (by calculating in ms and taking ceilings)
188// rounds up to the next higher ms. It's a lot easier for us
189// to just add margin for things like hardware ramp-up time
190// and clock calibration when running from the LSE and HSI
191// clocks on an STM32.
192#define LMICbandplan_RX_EXTRA_MARGIN_osticks us2osticks(2000)
193
194// probably this should be the same as the Class-A value, but
195// we have not the means to thoroughly test this. This is the
196// number of rxsyms used in the computations for ping and beacon
197// windows.
198#define LMICbandplan_MINRX_SYMS_LoRa_ClassB 5
199
200#define LMICbandplan_PAMBL_SYMS 8
201#define LMICbandplan_PAMBL_FSK 5
202#define LMICbandplan_PRERX_FSK 1
203#define LMICbandplan_RXLEN_FSK (1+5+2)
204
205// Legacy names
206#if !defined(MINRX_SYMS)
207# define MINRX_SYMS LMICbandplan_MINRX_SYMS_LoRa_ClassB
208#endif // !defined(MINRX_SYMS)
209#define PAMBL_SYMS LMICbandplan_PAMBL_SYMS
210#define PAMBL_FSK LMICbandplan_PAMBL_FSK
211#define PRERX_FSK LMICbandplan_PRERX_FSK
212#define RXLEN_FSK LMICbandplan_RXLEN_FSK
213
214// this is regional, but so far all regions are the same
215#if !defined(LMICbandplan_MAX_FCNT_GAP)
216# define LMICbandplan_MAX_FCNT_GAP 16384
217#endif // !defined LWAN_MAX_FCNT_GAP
218
219// this is probably regional, but for now default can be the same
220#if !defined(LMICbandplan_TX_RECOVERY_ms)
221# define LMICbandplan_TX_RECOVERY_ms 500
222#endif
223
224#define BCN_INTV_osticks sec2osticks(BCN_INTV_sec)
225#define TXRX_GUARD_osticks ms2osticks(TXRX_GUARD_ms)
226#define JOIN_GUARD_osticks ms2osticks(JOIN_GUARD_ms)
227#define DELAY_JACC1_osticks sec2osticks(DELAY_JACC1)
228#define DELAY_JACC2_osticks sec2osticks(DELAY_JACC2)
229#define DELAY_EXTDNW2_osticks sec2osticks(DELAY_EXTDNW2)
230#define BCN_RESERVE_osticks ms2osticks(BCN_RESERVE_ms)
231#define BCN_GUARD_osticks ms2osticks(BCN_GUARD_ms)
232#define BCN_WINDOW_osticks ms2osticks(BCN_WINDOW_ms)
233#define AIRTIME_BCN_osticks us2osticks(AIRTIME_BCN)
234
235// Special APIs - for development or testing
236#define isTESTMODE() 0
237
238// internal APIs
239ostime_t LMICcore_rndDelay(u1_t secSpan);
240void LMICcore_setDrJoin(u1_t reason, u1_t dr);
241ostime_t LMICcore_adjustForDrift(ostime_t delay, ostime_t hsym, rxsyms_t rxsyms_in);
242
243// this has been exported to clients forever by lmic.h. including lorabase.h;
244// but with multiband lorabase can't really safely do this; it's really an LMIC-ism.
245// As are the rest of the static inlines..
246
248static inline bit_t validDR (dr_t dr) { return LMICbandplan_validDR(dr); } // in range
249
251extern CONST_TABLE(u1_t, _DR2RPS_CRC)[];
252
253static inline rps_t updr2rps (dr_t dr) { return (rps_t)TABLE_GET_U1(_DR2RPS_CRC, dr+1); }
254static inline rps_t dndr2rps (dr_t dr) { return setNocrc(updr2rps(dr),1); }
255static inline dr_t incDR (dr_t dr) { return TABLE_GET_U1(_DR2RPS_CRC, dr+2)==ILLEGAL_RPS ? dr : (dr_t)(dr+1); } // increase data rate
256static inline dr_t decDR (dr_t dr) { return TABLE_GET_U1(_DR2RPS_CRC, dr )==ILLEGAL_RPS ? dr : (dr_t)(dr-1); } // decrease data rate
257static inline dr_t assertDR (dr_t dr) { return TABLE_GET_U1(_DR2RPS_CRC, dr+1)==ILLEGAL_RPS ? (dr_t)DR_DFLTMIN : dr; } // force into a valid DR
258static inline dr_t lowerDR (dr_t dr, u1_t n) { while(n--){dr=decDR(dr);} return dr; } // decrease data rate by n steps
259
260
261#endif // _lmic_bandplan_h_
ostime_t LMICcore_adjustForDrift(ostime_t delay, ostime_t hsym, rxsyms_t rxsyms_in)
Adjust the delay (in ticks) of the target window-open time from nominal.
Definition lmic.c:1431
LMIC API.