Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic_config_preconditions.h
1/* lmic_config_preconditions.h Fri May 19 2017 23:58:34 tmm */
2
3/*
4
5Module: lmic_config_preconditions.h
6
7Function:
8 Preconditions for LMIC configuration.
9
10Version:
11 V2.0.0 Sun Aug 06 2017 17:40:44 tmm Edit level 1
12
13Copyright notice:
14 This file copyright (C) 2017 by
15
16 MCCI Corporation
17 3520 Krums Corners Road
18 Ithaca, NY 14850
19
20 MIT License
21
22 Permission is hereby granted, free of charge, to any person obtaining a copy
23 of this software and associated documentation files (the "Software"), to deal
24 in the Software without restriction, including without limitation the rights
25 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26 copies of the Software, and to permit persons to whom the Software is
27 furnished to do so, subject to the following conditions:
28
29 The above copyright notice and this permission notice shall be included in all
30 copies or substantial portions of the Software.
31
32 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 SOFTWARE.
39
40Author:
41 Terry Moore, MCCI Corporation July 2017
42
43Revision history:
44 2.0.0 Sun Aug 06 2017 17:40:44 tmm
45 Module created.
46
47*/
48
49#ifndef _LMIC_CONFIG_PRECONDITIONS_H_
50# define _LMIC_CONFIG_PRECONDITIONS_H_
51
52// We need to be able to compile with different options without editing source.
53// When building with a more advanced environment, set the following variable:
54// ARDUINO_LMIC_PROJECT_CONFIG_H=my_project_config.h
55//
56// otherwise the lmic_project_config.h from the ../../project_config directory will be used.
57#ifndef ARDUINO_LMIC_PROJECT_CONFIG_H
58# define ARDUINO_LMIC_PROJECT_CONFIG_H ../../project_config/lmic_project_config.h
59#endif
60
61#define CFG_TEXT_1(x) CFG_TEXT_2(x)
62#define CFG_TEXT_2(x) #x
63
64// constants for comparison
65#define LMIC_REGION_eu868 1
66#define LMIC_REGION_us915 2
67#define LMIC_REGION_cn783 3
68#define LMIC_REGION_eu433 4
69#define LMIC_REGION_au915 5
70#define LMIC_REGION_cn490 6
71#define LMIC_REGION_as923 7
72#define LMIC_REGION_kr920 8
73#define LMIC_REGION_in866 9
74
75// Some regions have country-specific overrides. For generality, we specify
76// country codes using the LMIC_COUNTY_CODE_C() macro These values are chosen
77// from the 2-letter domain suffixes standardized by ISO-3166-1 alpha2 (see
78// https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). They are therefore
79// 16-bit constants. By convention, we use UPPER-CASE letters, thus
80// LMIC_COUNTRY_CODE('J', 'P'), not ('j', 'p').
81#define LMIC_COUNTRY_CODE_C(c1, c2) ((c1) * 256 + (c2))
82
83// this special code means "no country code defined"
84#define LMIC_COUNTRY_CODE_NONE 0
85
86// specific countries. Only the ones that are needed by the code are defined.
87#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('J', 'P')
88
89// include the file that the user is really supposed to edit. But for really strange
90// ports, this can be suppressed
91#ifndef ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
92# include CFG_TEXT_1(ARDUINO_LMIC_PROJECT_CONFIG_H)
93#endif /* ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS */
94
95#if defined(CFG_au921) && !defined(CFG_au915)
96# warning "CFG_au921 was deprecated in favour of CFG_au915. Support for CFG_au921 might be removed in the future."
97# define CFG_au915
98#endif
99
100// for backwards compatibility to legacy code, define CFG_au921 if we see CFG_au915.
101#if defined(CFG_au915) && !defined(CFG_au921)
102# define CFG_au921
103#endif
104
105// a mask of the supported regions
106// TODO(tmm@mcci.com) consider moving this block to a central file as it's not
107// user-editable.
108#define LMIC_REGIONS_SUPPORTED ( \
109 (1 << LMIC_REGION_eu868) | \
110 (1 << LMIC_REGION_us915) | \
111 /* (1 << LMIC_REGION_cn783) | */ \
112 /* (1 << LMIC_REGION_eu433) | */ \
113 (1 << LMIC_REGION_au915) | \
114 /* (1 << LMIC_REGION_cn490) | */ \
115 (1 << LMIC_REGION_as923) | \
116 (1 << LMIC_REGION_kr920) | \
117 (1 << LMIC_REGION_in866) | \
118 0)
119
120// the selected region.
121// TODO(tmm@mcci.com) consider moving this block to a central file as it's not
122// user-editable.
123#if defined(CFG_eu868)
124# define CFG_region LMIC_REGION_eu868
125#elif defined(CFG_us915)
126# define CFG_region LMIC_REGION_us915
127#elif defined(CFG_cn783)
128# define CFG_region LMIC_REGION_cn783
129#elif defined(CFG_eu433)
130# define CFG_region LMIC_REGION_eu433
131#elif defined(CFG_au915)
132# define CFG_region LMIC_REGION_au915
133#elif defined(CFG_cn490)
134# define CFG_region LMIC_REGION_cn490
135#elif defined(CFG_as923jp)
136# define CFG_as923 1 /* CFG_as923jp implies CFG_as923 */
137# define CFG_region LMIC_REGION_as923
138# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP
139#elif defined(CFG_as923)
140# define CFG_region LMIC_REGION_as923
141#elif defined(CFG_kr920)
142# define CFG_region LMIC_REGION_kr920
143#elif defined(CFG_in866)
144# define CFG_region LMIC_REGION_in866
145#else
146# define CFG_region 0
147#endif
148
149// LMIC_CFG_*_ENA -- either 1 or 0 based on whether that region
150// is enabled. Note: these must be after the code that special-cases
151// CFG_as923jp.
152#if defined(CFG_eu868)
153# define LMIC_CFG_eu868_ENA 1
154#else
155# define LMIC_CFG_eu868_ENA 0
156#endif
157
158#if defined(CFG_us915)
159# define LMIC_CFG_us915_ENA 1
160#else
161# define LMIC_CFG_us915_ENA 0
162#endif
163
164#if defined(CFG_cn783)
165# define LMIC_CFG_cn783_ENA 1
166#else
167# define LMIC_CFG_cn783_ENA 0
168#endif
169
170#if defined(CFG_eu433)
171# define LMIC_CFG_eu433_ENA 1
172#else
173# define LMIC_CFG_eu433_ENA 0
174#endif
175
176#if defined(CFG_au915)
177# define LMIC_CFG_au915_ENA 1
178#else
179# define LMIC_CFG_au915_ENA 0
180#endif
181
182#if defined(CFG_cn490)
183# define LMIC_CFG_cn490_ENA 1
184#else
185# define LMIC_CFG_cn490_ENA 0
186#endif
187
188#if defined(CFG_as923)
189# define LMIC_CFG_as923_ENA 1
190#else
191# define LMIC_CFG_as923_ENA 0
192#endif
193
194#if defined(CFG_kr920)
195# define LMIC_CFG_kr920_ENA 1
196#else
197# define LMIC_CFG_kr920_ENA 0
198#endif
199
200#if defined(CFG_in866)
201# define LMIC_CFG_in866_ENA 1
202#else
203# define LMIC_CFG_in866_ENA 0
204#endif
205
219# define CFG_LMIC_REGION_MASK \
220 ((LMIC_CFG_eu868_ENA << LMIC_REGION_eu868) | \
221 (LMIC_CFG_us915_ENA << LMIC_REGION_us915) | \
222 (LMIC_CFG_cn783_ENA << LMIC_REGION_cn783) | \
223 (LMIC_CFG_eu433_ENA << LMIC_REGION_eu433) | \
224 (LMIC_CFG_au915_ENA << LMIC_REGION_au915) | \
225 (LMIC_CFG_cn490_ENA << LMIC_REGION_cn490) | \
226 (LMIC_CFG_as923_ENA << LMIC_REGION_as923) | \
227 (LMIC_CFG_kr920_ENA << LMIC_REGION_kr920) | \
228 (LMIC_CFG_in866_ENA << LMIC_REGION_in866) | \
229 0)
230
237#define CFG_LMIC_EU_like_MASK ( \
238 (1 << LMIC_REGION_eu868) | \
239 /* (1 << LMIC_REGION_us915) | */ \
240 (1 << LMIC_REGION_cn783) | \
241 (1 << LMIC_REGION_eu433) | \
242 /* (1 << LMIC_REGION_au915) | */ \
243 /* (1 << LMIC_REGION_cn490) | */ \
244 (1 << LMIC_REGION_as923) | \
245 (1 << LMIC_REGION_kr920) | \
246 (1 << LMIC_REGION_in866) | \
247 0)
248
257#define CFG_LMIC_US_like_MASK ( \
258 /* (1 << LMIC_REGION_eu868) | */ \
259 (1 << LMIC_REGION_us915) | \
260 /* (1 << LMIC_REGION_cn783) | */ \
261 /* (1 << LMIC_REGION_eu433) | */ \
262 (1 << LMIC_REGION_au915) | \
263 /* (1 << LMIC_REGION_cn490) | */ \
264 /* (1 << LMIC_REGION_as923) | */ \
265 /* (1 << LMIC_REGION_kr920) | */ \
266 /* (1 << LMIC_REGION_in866) | */ \
267 0)
268
269//
270// booleans that are true if the configured region is EU-like or US-like.
271// TODO(tmm@mcci.com) consider moving this block to a central file as it's not
272// user-editable.
273//
274
276#define CFG_LMIC_EU_like (!!(CFG_LMIC_REGION_MASK & CFG_LMIC_EU_like_MASK))
278#define CFG_LMIC_US_like (!!(CFG_LMIC_REGION_MASK & CFG_LMIC_US_like_MASK))
279
280//
281// The supported LMIC LoRaWAN spec versions. These need to be numerically ordered,
282// so that we can (for example) compare
283//
284// LMIC_LORAWAN_SPEC_VERSION < LMIC_LORAWAN_SPEC_VERSION_1_0_3.
285//
286#define LMIC_LORAWAN_SPEC_VERSION_1_0_2 0x01000200u
287#define LMIC_LORAWAN_SPEC_VERSION_1_0_3 0x01000300u
288
289#endif /* _LMIC_CONFIG_PRECONDITIONS_H_ */