Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic_us_like.h
1/*
2* Copyright (c) 2014-2016 IBM Corporation.
3* Copyright (c) 2017, 2019 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_us_like_h_
30# define _lmic_us_like_h_
31
32// make sure we want US-like code
33#if !CFG_LMIC_US_like
34# error "lmic not configured for us-like bandplan"
35#endif
36
37// TODO(tmm@mcci.com): this should come from the lmic.h or lorabase.h file; and
38// it's probably affected by the fix to this issue:
39// https://github.com/mcci-catena/arduino-lmic/issues/2
40#define DNW2_SAFETY_ZONE ms2osticks(750)
41
42#define IS_CHANNEL_125khz(c) (c<64)
43#define IS_CHANNEL_500khz(c) (c>=64 && c<72)
44#define ENABLED_CHANNEL(chnl) ((LMIC.channelMap[(chnl >> 4)] & (1<<(chnl & 0x0F))) != 0)
45
46// library functions: called from bandplan
47void LMICuslike_initJoinLoop(void);
48
49// provide the isValidBeacon1 function -- int for bool.
50static inline int
51LMICuslike_isValidBeacon1(const uint8_t *d) {
52 return os_rlsbf2(&d[OFF_BCN_CRC1]) != os_crc16(d, OFF_BCN_CRC1);
53}
54
55#define LMICbandplan_isValidBeacon1(pFrame) LMICuslike_isValidBeacon1(pFrame)
56
57// provide a default for LMICbandplan_isFSK()
58#define LMICbandplan_isFSK() (0)
59
60// provide a default LMICbandplan_txDoneFSK()
61#define LMICbandplan_txDoneFSK(delay, func) do { } while (0)
62
63// provide a default LMICbandplan_joinAcceptChannelClear()
64#define LMICbandplan_joinAcceptChannelClear() do { } while (0)
65
67#define LMICbandplan_hasJoinCFlist() (1)
68
70void LMICuslike_processJoinAcceptCFList(void);
72#define LMICbandplan_processJoinAcceptCFList LMICuslike_processJoinAcceptCFList
73
74
75#define LMICbandplan_advanceBeaconChannel() \
76 do { LMIC.bcnChnl = (LMIC.bcnChnl+1) & 7; } while (0)
77
78// TODO(tmm@mcci.com): decide whether we want to do this on every
79// reset or just restore the last sub-band selected by the user.
80#define LMICbandplan_resetDefaultChannels() \
81 LMICbandplan_initDefaultChannels(/* normal */ 0)
82
83void LMICuslike_initDefaultChannels(bit_t fJoin);
84#define LMICbandplan_initDefaultChannels(fJoin) LMICuslike_initDefaultChannels(fJoin)
85
86#define LMICbandplan_setSessionInitDefaultChannels() \
87 do { /* nothing */} while (0)
88
89bit_t LMICuslike_canMapChannels(u1_t chpage, u2_t chmap);
90#define LMICbandplan_canMapChannels(chpage, chmap) LMICuslike_canMapChannels(chpage, chmap)
91
92bit_t LMICuslike_mapChannels(u1_t chpage, u2_t chmap);
93#define LMICbandplan_mapChannels(chpage, chmap) LMICuslike_mapChannels(chpage, chmap)
94
95ostime_t LMICuslike_nextTx(ostime_t now);
96#define LMICbandplan_nextTx(now) LMICuslike_nextTx(now)
97
98ostime_t LMICuslike_nextJoinState(void);
99#define LMICbandplan_nextJoinState() LMICuslike_nextJoinState();
100
101static inline ostime_t LMICuslike_nextJoinTime(ostime_t now) {
102 return now;
103}
104#define LMICbandplan_nextJoinTime(now) LMICuslike_nextJoinTime(now)
105
106#define LMICbandplan_init() \
107 do { /* nothing */ } while (0)
108
109void LMICuslike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer);
110#define LMICbandplan_saveAdrState(pState) LMICuslike_saveAdrState(pState)
111
112bit_t LMICuslike_compareAdrState(const lmic_saved_adr_state_t *pStateBuffer);
113#define LMICbandplan_compareAdrState(pState) LMICuslike_compareAdrState(pState)
114
115void LMICuslike_restoreAdrState(const lmic_saved_adr_state_t *pStateBuffer);
116#define LMICbandplan_restoreAdrState(pState) LMICuslike_restoreAdrState(pState)
117
118bit_t LMICuslike_isDataRateFeasible(dr_t dr);
119#define LMICbandplan_isDataRateFeasible(dr) LMICuslike_isDataRateFeasible(dr)
120
121#endif // _lmic_us_like_h_
u2_t os_rlsbf2(xref2cu1_t buf)
Read 16-bit quantity from given pointer in little endian byte order.
Definition lmic.c:80