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
52LMIC_BEGIN_DECLS
53
54// check post-conditions
55#ifndef DNW2_SAFETY_ZONE
56# error "DNW2_SAFETY_ZONE not defined by bandplan"
57#endif
58
59#ifndef LMICbandplan_maxFrameLen
60# error "LMICbandplan_maxFrameLen() not defined by bandplan"
61#endif
62
63#ifndef pow2dBm
64# error "pow2dBm() not defined by bandplan"
65#endif
66
67#ifndef dr2hsym
68# error "dr2hsym() not defined by bandplan"
69#endif
70
71#if !defined(LMICbandplan_isValidBeacon1) && !defined(DISABLE_BEACONS)
72# error "LMICbandplan_isValidBeacon1 not defined by bandplan"
73#endif
74
75#if !defined(LMICbandplan_isFSK)
76# error "LMICbandplan_isFSK() not defined by bandplan"
77#endif
78
79#if !defined(LMICbandplan_txDoneFSK)
80# error "LMICbandplan_txDoneFSK() not defined by bandplan"
81#endif
82
83#if !defined(LMICbandplan_joinAcceptChannelClear)
84# error "LMICbandplan_joinAcceptChannelClear() not defined by bandplan"
85#endif
86
87#if !defined(LMICbandplan_getInitialDrJoin)
88# error "LMICbandplan_getInitialDrJoin() not defined by bandplan"
89#endif
90
91#if !defined(LMICbandplan_hasJoinCFlist)
92# error "LMICbandplan_hasJoinCFlist() not defined by bandplan"
93#endif
94
95#if !defined(LMICbandplan_advanceBeaconChannel)
96# error "LMICbandplan_advanceBeaconChannel() not defined by bandplan"
97#endif
98
99#if !defined(LMICbandplan_resetDefaultChannels)
100# error "LMICbandplan_resetDefaultChannels() not defined by bandplan"
101#endif
102
103#if !defined(LMICbandplan_setSessionInitDefaultChannels)
104# error "LMICbandplan_setSessionInitDefaultChannels() not defined by bandplan"
105#endif
106
107#if !defined(LMICbandplan_setBcnRxParams)
108# error "LMICbandplan_setBcnRxParams() not defined by bandplan"
109#endif
110
111#if !defined(LMICbandplan_canMapChannels)
112# error "LMICbandplan_canMapChannels() not defined by bandplan"
113#endif
114
115#if !defined(LMICbandplan_mapChannels)
116# error "LMICbandplan_mapChannels() not defined by bandplan"
117#endif
118
119#if !defined(LMICbandplan_convFreq)
120# error "LMICbandplan_convFreq() not defined by bandplan"
121#endif
122
123#if !defined(LMICbandplan_queryMaxRx1DrOffset)
124# error "LMICbandplan_queryMaxRx1DrOffset() not defined by bandplan"
125#endif
126
127#if !defined(LMICbandplan_setRx1Params)
128# error "LMICbandplan_setRx1Params() not defined by bandplan"
129#endif
130
131#if !defined(LMICbandplan_initJoinLoop)
132# error "LMICbandplan_initJoinLoop() not defined by bandplan"
133#endif
134
135#if !defined(LMICbandplan_nextTx)
136# error "LMICbandplan_nextTx() not defined by bandplan"
137#endif
138
139#if !defined(LMICbandplan_updateTx)
140# error "LMICbandplan_updateTx() not defined by bandplan"
141#endif
142
143#if !defined(LMICbandplan_nextJoinState)
144# error "LMICbandplan_nextJoinState() not defined by bandplan"
145#endif
146
147#if !defined(LMICbandplan_initDefaultChannels)
148# error "LMICbandplan_initDefaultChannels() not defined by bandplan"
149#endif
150
151#if !defined(LMICbandplan_nextJoinTime)
152# error "LMICbandplan_nextJoinTime() not defined by bandplan"
153#endif
154
155#if !defined(LMICbandplan_init)
156# error "LMICbandplan_init() not defined by bandplan"
157#endif
158
159#if !defined(LMICbandplan_saveAdrState)
160# error "LMICbandplan_saveAdrState() not defined by bandplan"
161#endif
162
163#if !defined(LMICbandplan_compareAdrState)
164# error "LMICbandplan_compareAdrState() not defined by bandplan"
165#endif
166
167#if !defined(LMICbandplan_restoreAdrState)
168# error "LMICbandplan_restoreAdrState() not defined by bandplan"
169#endif
170
171#if !defined(LMICbandplan_isDataRateFeasible)
172# error "LMICbandplan_isDataRateFeasible() not defined by bandplan"
173#endif
174
175#if !defined(LMICbandplan_validDR)
176# error "LMICbandplan_validDR() not defined by bandplan"
177#endif
178
179#if !defined(LMICbandplan_processJoinAcceptCFList)
180# error "LMICbandplan_processJoinAcceptCFList() not defined by bandplan"
181#endif
182
183//
184// Things common to lmic.c code
185//
186#define LMICbandplan_MINRX_SYMS_LoRa_ClassA 6
187#define LMICbandplan_RX_ERROR_ABS_osticks ms2osticks(10)
188
189// Semtech inherently (by calculating in ms and taking ceilings)
190// rounds up to the next higher ms. It's a lot easier for us
191// to just add margin for things like hardware ramp-up time
192// and clock calibration when running from the LSE and HSI
193// clocks on an STM32.
194#define LMICbandplan_RX_EXTRA_MARGIN_osticks us2osticks(2000)
195
196// probably this should be the same as the Class-A value, but
197// we have not the means to thoroughly test this. This is the
198// number of rxsyms used in the computations for ping and beacon
199// windows.
200#define LMICbandplan_MINRX_SYMS_LoRa_ClassB 5
201
202#define LMICbandplan_PAMBL_SYMS 8
203#define LMICbandplan_PAMBL_FSK 5
204#define LMICbandplan_PRERX_FSK 1
205#define LMICbandplan_RXLEN_FSK (1+5+2)
206
207// Legacy names
208#if !defined(MINRX_SYMS)
209# define MINRX_SYMS LMICbandplan_MINRX_SYMS_LoRa_ClassB
210#endif // !defined(MINRX_SYMS)
211#define PAMBL_SYMS LMICbandplan_PAMBL_SYMS
212#define PAMBL_FSK LMICbandplan_PAMBL_FSK
213#define PRERX_FSK LMICbandplan_PRERX_FSK
214#define RXLEN_FSK LMICbandplan_RXLEN_FSK
215
216// this is regional, but so far all regions are the same
217#if !defined(LMICbandplan_MAX_FCNT_GAP)
218# define LMICbandplan_MAX_FCNT_GAP 16384
219#endif // !defined LWAN_MAX_FCNT_GAP
220
221// this is probably regional, but for now default can be the same
222#if !defined(LMICbandplan_TX_RECOVERY_ms)
223# define LMICbandplan_TX_RECOVERY_ms 500
224#endif
225
226#define BCN_INTV_osticks sec2osticks(BCN_INTV_sec)
227#define TXRX_GUARD_osticks ms2osticks(TXRX_GUARD_ms)
228#define JOIN_GUARD_osticks ms2osticks(JOIN_GUARD_ms)
229#define DELAY_JACC1_osticks sec2osticks(DELAY_JACC1)
230#define DELAY_JACC2_osticks sec2osticks(DELAY_JACC2)
231#define DELAY_EXTDNW2_osticks sec2osticks(DELAY_EXTDNW2)
232#define BCN_RESERVE_osticks ms2osticks(BCN_RESERVE_ms)
233#define BCN_GUARD_osticks ms2osticks(BCN_GUARD_ms)
234#define BCN_WINDOW_osticks ms2osticks(BCN_WINDOW_ms)
235#define AIRTIME_BCN_osticks us2osticks(AIRTIME_BCN)
236
237// Special APIs - for development or testing
238#define isTESTMODE() 0
239
240// internal APIs
241ostime_t LMICcore_rndDelay(u1_t secSpan);
242void LMICcore_setDrJoin(u1_t reason, u1_t dr);
243ostime_t LMICcore_adjustForDrift(ostime_t delay, ostime_t hsym, rxsyms_t rxsyms_in);
244
245// this has been exported to clients forever by lmic.h. including lorabase.h;
246// but with multiband lorabase can't really safely do this; it's really an LMIC-ism.
247// As are the rest of the static inlines..
248
250static inline bit_t validDR (dr_t dr) { return LMICbandplan_validDR(dr); } // in range
251
253extern CONST_TABLE(u1_t, _DR2RPS_CRC)[];
254
255static inline rps_t updr2rps (dr_t dr) { return (rps_t)TABLE_GET_U1(_DR2RPS_CRC, dr+1); }
256static inline rps_t dndr2rps (dr_t dr) { return setNocrc(updr2rps(dr),1); }
257static 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
258static inline dr_t decDR (dr_t dr) { return TABLE_GET_U1(_DR2RPS_CRC, dr )==ILLEGAL_RPS ? dr : (dr_t)(dr-1); } // decrease data rate
259static 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
260static inline dr_t lowerDR (dr_t dr, u1_t n) { while(n--){dr=decDR(dr);} return dr; } // decrease data rate by n steps
261
262LMIC_END_DECLS
263
264#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:1444
LMIC API.