Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
hal.h
1/*
2 * Copyright (c) 2014-2016 IBM Corporation.
3 * Copyright (c) 2016, 2018-2026 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_hal_h_
30#define _lmic_hal_h_
31
32#ifndef _oslmic_types_h_
33# include "oslmic_types.h"
34#endif
35
36#ifndef _lmic_env_h_
37# include "lmic_env.h"
38#endif
39
40#ifdef __cplusplus
41extern "C"{
42#endif
43
44// The type of an optional user-defined failure handler routine
45typedef void LMIC_ABI_STD lmic_hal_failure_handler_t(const char* const file, const uint16_t line);
46
47/*
48 * initialize hardware (IO, SPI, TIMER, IRQ).
49 * This API is deprecated as it uses the const global lmic_pins,
50 * which the platform can't control or change.
51 */
52void lmic_hal_init (void);
53
54/*
55 * Initialize hardware, passing in platform-specific context
56 * The pointer is to a HalPinmap_t.
57 */
58void lmic_hal_init_ex (const void *pContext);
59
60/*
61 * drive radio RX/TX pins (0=rx, 1=tx). Actual polarity
62 * is determined by the value of HalPinmap_t::rxtx_rx_active.
63 */
64void lmic_hal_pin_rxtx (u1_t val);
65
66/*
67 * control radio RST pin (0=low, 1=high, 2=floating)
68 */
69void lmic_hal_pin_rst (u1_t val);
70
71/*
72 * Perform SPI write transaction with radio chip
73 * - write the command byte 'cmd'
74 * - write 'len' bytes out of 'buf'
75 */
76void lmic_hal_spi_write(u1_t cmd, const u1_t* buf, size_t len);
77
78/*
79 * Perform SPI read transaction with radio chip
80 * - write the command byte 'cmd'
81 * - read 'len' bytes into 'buf'
82 */
83void lmic_hal_spi_read(u1_t cmd, u1_t* buf, size_t len);
84
85/*
86 * Perform SPI read transaction with SX126x series radio chip
87 * - write the command byte 'cmd'
88 * - write the 'addr_len' register address bytes 'addr'
89 * - write the 'NOP' byte 0x00
90 * - read 'buf_len' bytes into 'buf'
91 */
92#if (defined(CFG_sx1261_radio) || defined(CFG_sx1262_radio))
93void lmic_hal_spi_read_sx126x(u1_t cmd, u1_t* addr, size_t addr_len, u1_t* buf, size_t buf_len);
94#endif
95
96/*
97 * disable all CPU interrupts.
98 * - might be invoked nested
99 * - will be followed by matching call to lmic_hal_enableIRQs()
100 */
101void lmic_hal_disableIRQs (void);
102
103/*
104 * enable CPU interrupts.
105 */
106void lmic_hal_enableIRQs (void);
107
108/*
109 * return CPU interrupt nesting count
110 */
111uint8_t lmic_hal_getIrqLevel (void);
112
113/*
114 * put system and CPU in low-power mode, sleep until interrupt.
115 */
116void lmic_hal_sleep (void);
117
118/*
119 * return 32-bit system time in ticks.
120 */
121u4_t lmic_hal_ticks (void);
122
123/*
124 * busy-wait until specified timestamp (in ticks) is reached. If on-time, return 0,
125 * otherwise return the number of ticks we were late.
126 */
127u4_t lmic_hal_waitUntil (u4_t time);
128
129/*
130 * check and rewind timer for target time.
131 * - return 1 if target time is close
132 * - otherwise rewind timer for target time or full period and return 0
133 */
134u1_t lmic_hal_checkTimer (u4_t targettime);
135
136/*
137 * perform fatal failure action.
138 * - called by assertions
139 * - action could be HALT or reboot
140 */
141void lmic_hal_failed (const char *file, u2_t line);
142
143/*
144 * set a custom hal failure handler routine. The default behaviour, defined in
145 * lmic_hal_failed(), is to halt by looping infintely.
146 */
147void lmic_hal_set_failure_handler (lmic_hal_failure_handler_t*);
148
149/*
150 * get the calibration value for radio_rssi
151 */
152s1_t lmic_hal_getRssiCal (void);
153
154/*
155 * control the radio state
156 * - if val == 0, turn tcxo off and otherwise prepare for sleep
157 * - if val == 1, turn tcxo on and otherwise prep for activity
158 * - return the number of ticks that we need to wait
159 */
160ostime_t lmic_hal_setModuleActive (bit_t val);
161
162/* find out if we're using Tcxo controlled by a host pin */
163bit_t lmic_hal_queryUsingTcxo(void);
164
165/* SX126x function: find out if the board is configured for DC-DC regulator control */
166bit_t lmic_hal_queryUsingDcdc(void);
167
168/* SX126x function: find out if the board is configured to control the RF switch with modem DIO2 */
169bit_t lmic_hal_queryUsingDIO2AsRfSwitch(void);
170
171/* SX126x function: find out if the board is configured to control a TCXO with modem DIO3 */
172bit_t lmic_hal_queryUsingDIO3AsTCXOSwitch(void);
173
174/* represent the various radio TX power policy */
175enum {
176 LMICHAL_radio_tx_power_policy_rfo = 0,
177 LMICHAL_radio_tx_power_policy_paboost = 1,
178 LMICHAL_radio_tx_power_policy_20dBm = 2,
179};
180
181/*
182 * query the configuration as to the Tx Power Policy
183 * to be used on this board, given our desires and
184 * requested power.
185 */
186uint8_t lmic_hal_getTxPowerPolicy(
187 u1_t inputPolicy,
188 s1_t requestedPower,
189 u4_t freq
190 );
191
192void lmic_hal_pollPendingIRQs_helper();
193void lmic_hal_processPendingIRQs(void);
194bit_t lmic_hal_radio_spi_is_busy();
195
197static inline void lmic_hal_pollPendingIRQs(void)
198 {
199#if !defined(LMIC_USE_INTERRUPTS)
200 lmic_hal_pollPendingIRQs_helper();
201#endif /* !defined(LMIC_USE_INTERRUPTS) */
202 }
203
204#ifdef __cplusplus
205} // extern "C"
206#endif
207
208#endif // _lmic_hal_h_