43#ifndef _oslmic_types_h_
44# include "oslmic_types.h"
53#define DO_DEVDB(field1,field2)
54#if !defined(CFG_noassert)
55#define ASSERT(cond) if(!(cond)) lmic_hal_failed(__FILE__, __LINE__)
62#define os_clearMem(pDest,nDest) memset(pDest,0,nDest)
70#define os_copyMem(pDest,pSrc,nSrc) memcpy(pDest,pSrc,nSrc)
73typedef struct band_t band_t;
74typedef struct chnldef_t chnldef_t;
81#ifndef LMIC_PRId_ostime_t
83# define LMIC_PRId_ostime_t PRId32
86#define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t
87#define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t
88#define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t
89#define TYPEDEF_xref2band_t typedef band_t* xref2band_t
90#define TYPEDEF_xref2osjob_t typedef osjob_t* xref2osjob_t
92#define SIZEOFEXPR(x) sizeof(x)
94#define DECL_ON_LMIC_EVENT LMIC_DECLARE_FUNCTION_WEAK(void, onEvent, (ev_t e))
96#define FUNC_ADDR(func) (&(func))
99#define os_getRndU1() radio_rand1()
101#define DEFINE_LMIC struct lmic_t LMIC
102#define DECLARE_LMIC extern struct lmic_t LMIC
117int os_init_ex (
const void *pPinMap);
118void os_runloop (
void);
119void os_runloop_once (
void);
120u1_t radio_rssi (
void);
125#ifndef RX_RAMPUP_DEFAULT
131#define RX_RAMPUP_DEFAULT (us2osticksCeil(10000))
139#define TX_RAMPUP (us2osticks(10000))
142#ifndef OSTICKS_PER_SEC
143#define OSTICKS_PER_SEC 32768
144#elif OSTICKS_PER_SEC < 10000 || OSTICKS_PER_SEC > 64516
145#error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long.
149#define us2osticks(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC) / 1000000))
150#define ms2osticks(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC) / 1000))
151#define sec2osticks(sec) ((ostime_t)( (int64_t)(sec) * OSTICKS_PER_SEC))
152#define osticks2ms(os) ((s4_t)(((os)*(int64_t)1000 ) / OSTICKS_PER_SEC))
153#define osticks2us(os) ((s4_t)(((os)*(int64_t)1000000 ) / OSTICKS_PER_SEC))
155#define us2osticksCeil(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC + 999999) / 1000000))
156#define us2osticksRound(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC + 500000) / 1000000))
157#define ms2osticksCeil(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC + 999) / 1000))
158#define ms2osticksRound(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC + 500) / 1000))
179static inline int os_jobIsTimed(xref2osjob_t job) {
180 return (job->deadline != 0);
186void os_getDevKey (xref2u1_t buf);
189void os_getArtEui (xref2u1_t buf);
192void os_getDevEui (xref2u1_t buf);
194#ifndef os_setCallback
195void os_setCallback (xref2osjob_t job,
osjobcb_t cb);
197#ifndef os_setTimedCallback
198void os_setTimedCallback (xref2osjob_t job, ostime_t time,
osjobcb_t cb);
200#ifndef os_setIdleJobFunction
203#ifndef os_clearCallback
204void os_clearCallback (xref2osjob_t job);
206#ifndef os_getRadioRxRampup
207ostime_t os_getRadioRxRampup (
void);
210ostime_t os_getTime (
void);
212#ifndef os_getTimeSecs
213uint os_getTimeSecs (
void);
216void os_radio (u1_t mode);
219void os_radio_v2 (u1_t mode, xref2osjob_t job);
221#ifndef os_getBattLevel
222u1_t os_getBattLevel (
void);
224#ifndef os_queryTimeCriticalJobs
226bit_t os_queryTimeCriticalJobs(ostime_t time);
235void os_wlsbf4 (xref2u1_t buf, u4_t value);
243void os_wmsbf4 (xref2u1_t buf, u4_t value);
251void os_wlsbf2 (xref2u1_t buf, u2_t value);
259void os_wlsbf8 (xref2u1_t buf, uint64_t value);
264#define os_getRndU2() ((u2_t)((os_getRndU1()<<8)|os_getRndU1()))
267u2_t os_crc16 (xref2cu1_t d, uint len);
284#define RESOLVE_TABLE(table) constant_table_ ## table
287#define LENOF_TABLE(table) (sizeof(RESOLVE_TABLE(table)) / sizeof(RESOLVE_TABLE(table)[0]))
290#define TABLE_GET_U1(table, index) table_get_u1(RESOLVE_TABLE(table), index)
291#define TABLE_GET_S1(table, index) table_get_s1(RESOLVE_TABLE(table), index)
292#define TABLE_GET_U2(table, index) table_get_u2(RESOLVE_TABLE(table), index)
293#define TABLE_GET_S2(table, index) table_get_s2(RESOLVE_TABLE(table), index)
294#define TABLE_GET_U4(table, index) table_get_u4(RESOLVE_TABLE(table), index)
295#define TABLE_GET_S4(table, index) table_get_s4(RESOLVE_TABLE(table), index)
296#define TABLE_GET_OSTIME(table, index) table_get_ostime(RESOLVE_TABLE(table), index)
297#define TABLE_GET_U1_TWODIM(table, index1, index2) table_get_u1(RESOLVE_TABLE(table)[index1], index2)
300 #include <avr/pgmspace.h>
304 #define TABLE_GETTER(postfix, type, pgm_type) \
305 static inline type table_get ## postfix(const type *table, size_t index) { \
306 if (__builtin_constant_p(table[index])) \
307 return table[index]; \
308 return pgm_read_ ## pgm_type(&table[index]); \
311 TABLE_GETTER(_u1, u1_t,
byte);
312 TABLE_GETTER(_s1, s1_t,
byte);
313 TABLE_GETTER(_u2, u2_t, word);
314 TABLE_GETTER(_s2, s2_t, word);
315 TABLE_GETTER(_u4, u4_t, dword);
316 TABLE_GETTER(_s4, s4_t, dword);
319 typedef int check_sizeof_ostime_t[(
sizeof(ostime_t) == 4) ? 0 : -1];
320 TABLE_GETTER(_ostime, ostime_t, dword);
323 #define CONST_TABLE(type, name) const type PROGMEM RESOLVE_TABLE(name)
325 static inline u1_t table_get_u1(
const u1_t *table,
size_t index) {
return table[index]; }
326 static inline s1_t table_get_s1(
const s1_t *table,
size_t index) {
return table[index]; }
327 static inline u2_t table_get_u2(
const u2_t *table,
size_t index) {
return table[index]; }
328 static inline s2_t table_get_s2(
const s2_t *table,
size_t index) {
return table[index]; }
329 static inline u4_t table_get_u4(
const u4_t *table,
size_t index) {
return table[index]; }
330 static inline s4_t table_get_s4(
const s4_t *table,
size_t index) {
return table[index]; }
331 static inline ostime_t table_get_ostime(
const ostime_t *table,
size_t index) {
return table[index]; }
334 #define CONST_TABLE(type, name) const type RESOLVE_TABLE(name)
340#if LMIC_ENABLE_event_logging
341extern void LMICOS_logEvent(
const char *pMessage);
342extern void LMICOS_logEventUint32(
const char *pMessage, uint32_t datum);
344# define LMICOS_logEvent(m) do { ; } while (0)
345# define LMICOS_logEventUint32(m, d) do { ; } while (0)
void os_wlsbf4(xref2u1_t buf, u4_t v)
Write 32-bit quantity into buffer in little endian byte order.
Definition lmic.c:107
u4_t os_rlsbf4(xref2cu1_t buf)
Read 32-bit quantity from given pointer in little endian byte order.
Definition lmic.c:86
uint64_t os_rlsbf8(xref2cu1_t buf)
Read 64-bit quantity from given pointer in little endian byte order.
Definition lmic.c:116
void os_wmsbf4(xref2u1_t buf, u4_t v)
Write 32-bit quantity into buffer in big endian byte order.
Definition lmic.c:129
void os_wlsbf8(xref2u1_t buf, uint64_t v)
Write 64-bit quantity into buffer in little endian byte order.
Definition lmic.c:122
void os_wlsbf2(xref2u1_t buf, u2_t v)
Write 16-bit quantity into buffer in little endian byte order.
Definition lmic.c:100
u4_t os_rmsbf4(xref2cu1_t buf)
Read 32-bit quantity from given pointer in big endian byte order.
Definition lmic.c:93
u2_t os_rlsbf2(xref2cu1_t buf)
Read 16-bit quantity from given pointer in little endian byte order.
Definition lmic.c:80
osjobcbfn_t * osjobcb_t
the pointer-to-function for osjob_t callbacks
Definition oslmic.h:168
void osjobcbfn_t(struct osjob_t *)
the function type for osjob_t callbacks
Definition oslmic.h:165
u1_t radio_rand1(void)
Generate an 8-bit uniformly-distributed integer.
Definition radio_sx127x.c:1236
void radio_irq_handler(u1_t dio)
legacy radio IRQ handler
Definition radio_sx127x.c:1361
int radio_init(void)
Initialize radio at system startup.
Definition radio_sx127x.c:1148
void radio_irq_handler_v2(u1_t dio, ostime_t tref)
Radio IRQ handler.
Definition radio_sx127x.c:1386
void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi)
Measure the current broadband RSSI for the current channel.
Definition radio_sx127x.c:1270
Information about the last and previous beacons.
Definition lmic.h:193