Version of personalized IMPACT LoRa

Fork of LMiC-10secs by Alcatel-Lucent IoT Development

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers oslmic.h Source File

oslmic.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright (c) 2014-2015 IBM Corporation.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the Eclipse Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/epl-v10.html
00007  *
00008  * Contributors:
00009  *    IBM Zurich Research Lab - initial API, implementation and documentation
00010  *******************************************************************************/
00011 
00012 //! \file
00013 #ifndef _oslmic_h_
00014 #define _oslmic_h_
00015 
00016 // Dependencies required for the LoRa MAC in C to run.
00017 // These settings can be adapted to the underlying system.
00018 // You should not, however, change the lmic.[hc]
00019 
00020 
00021 
00022 //================================================================================
00023 //================================================================================
00024 // Target platform as C library
00025 typedef unsigned char      bit_t;
00026 typedef unsigned char      u1_t;
00027 typedef   signed char      s1_t;
00028 typedef unsigned short     u2_t;
00029 typedef          short     s2_t;
00030 typedef unsigned int       u4_t;
00031 typedef          int       s4_t;
00032 typedef unsigned long long u8_t;
00033 typedef          long long s8_t;
00034 typedef unsigned int       uint;
00035 typedef const char* str_t;
00036 
00037 #include <string.h>
00038 #include "hal.h"
00039 #define EV(a,b,c) /**/
00040 #define DO_DEVDB(field1,field2) /**/
00041 #if !defined(CFG_noassert)
00042 #define ASSERT(cond) if(!(cond)) hal_failed()
00043 #else
00044 #define ASSERT(cond) /**/
00045 #endif
00046 
00047 #define os_clearMem(a,b)   memset(a,0,b)
00048 #define os_copyMem(a,b,c)  memcpy(a,b,c)
00049 
00050 typedef     struct osjob_t osjob_t;
00051 typedef      struct band_t band_t;
00052 typedef   struct chnldef_t chnldef_t;
00053 typedef   struct rxsched_t rxsched_t;
00054 typedef   struct bcninfo_t bcninfo_t;
00055 typedef        const u1_t* xref2cu1_t;
00056 typedef              u1_t* xref2u1_t;
00057 #define TYPEDEF_xref2rps_t     typedef         rps_t* xref2rps_t
00058 #define TYPEDEF_xref2rxsched_t typedef     rxsched_t* xref2rxsched_t
00059 #define TYPEDEF_xref2chnldef_t typedef     chnldef_t* xref2chnldef_t
00060 #define TYPEDEF_xref2band_t    typedef        band_t* xref2band_t
00061 #define TYPEDEF_xref2osjob_t   typedef       osjob_t* xref2osjob_t
00062 
00063 #define SIZEOFEXPR(x) sizeof(x)
00064 
00065 #define ON_LMIC_EVENT(ev)  onEvent(ev)
00066 #define DECL_ON_LMIC_EVENT void onEvent(ev_t e)
00067 
00068 extern u4_t AESAUX[];
00069 extern u4_t AESKEY[];
00070 #define AESkey ((u1_t*)AESKEY)
00071 #define AESaux ((u1_t*)AESAUX)
00072 #define FUNC_ADDR(func) (&(func))
00073 
00074 u1_t radio_rand1 (void);
00075 #define os_getRndU1() radio_rand1()
00076 
00077 #define DEFINE_LMIC  struct lmic_t LMIC
00078 #define DECLARE_LMIC extern struct lmic_t LMIC
00079 
00080 void radio_init (void);
00081 void radio_irq_handler (u1_t dio);
00082 void os_init (void);
00083 void os_runloop (void);
00084 
00085 //================================================================================
00086 
00087 
00088 #ifndef RX_RAMPUP
00089 #define RX_RAMPUP  (us2osticks(2000))
00090 #endif
00091 #ifndef TX_RAMPUP
00092 //#define TX_RAMPUP  (us2osticks(2000))
00093 #define TX_RAMPUP  (sec2osticks(200))
00094 #endif
00095 
00096 #ifndef OSTICKS_PER_SEC
00097 #define OSTICKS_PER_SEC 15625
00098 #elif OSTICKS_PER_SEC < 10000 || OSTICKS_PER_SEC > 64516
00099 #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long.
00100 #endif
00101 
00102 typedef s4_t  ostime_t;
00103 
00104 #if !HAS_ostick_conv
00105 #define us2osticks(us)   ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC) / 1000000))
00106 #define ms2osticks(ms)   ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC)    / 1000))
00107 #define sec2osticks(sec) ((ostime_t)( (s8_t)(sec) * OSTICKS_PER_SEC))
00108 #define osticks2ms(os)   ((s4_t)(((os)*(s8_t)1000    ) / OSTICKS_PER_SEC))
00109 #define osticks2us(os)   ((s4_t)(((os)*(s8_t)1000000 ) / OSTICKS_PER_SEC))
00110 // Special versions
00111 #define us2osticksCeil(us)  ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 999999) / 1000000))
00112 #define us2osticksRound(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 500000) / 1000000))
00113 #define ms2osticksCeil(ms)  ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 999) / 1000))
00114 #define ms2osticksRound(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 500) / 1000))
00115 #endif
00116 
00117 
00118 struct osjob_t;  // fwd decl.
00119 typedef void (*osjobcb_t) (struct osjob_t*);
00120 struct osjob_t {
00121     struct osjob_t* next;
00122     ostime_t deadline;
00123     osjobcb_t  func;
00124 };
00125 TYPEDEF_xref2osjob_t;
00126 
00127 
00128 #ifndef HAS_os_calls
00129 
00130 #ifndef os_getDevKey
00131 void os_getDevKey (xref2u1_t buf);
00132 #endif
00133 #ifndef os_getArtEui
00134 void os_getArtEui (xref2u1_t buf);
00135 #endif
00136 #ifndef os_getDevEui
00137 void os_getDevEui (xref2u1_t buf);
00138 #endif
00139 #ifndef os_setCallback
00140 void os_setCallback (xref2osjob_t job, osjobcb_t cb);
00141 #endif
00142 #ifndef os_setTimedCallback
00143 void os_setTimedCallback (xref2osjob_t job, ostime_t time, osjobcb_t cb);
00144 #endif
00145 #ifndef os_clearCallback
00146 void os_clearCallback (xref2osjob_t job);
00147 #endif
00148 #ifndef os_getTime
00149 ostime_t os_getTime (void);
00150 #endif
00151 #ifndef os_getTimeSecs
00152 uint os_getTimeSecs (void);
00153 #endif
00154 #ifndef os_radio
00155 void os_radio (u1_t mode);
00156 #endif
00157 #ifndef os_getBattLevel
00158 u1_t os_getBattLevel (void);
00159 #endif
00160 
00161 #ifndef os_rlsbf4
00162 //! Read 32-bit quantity from given pointer in little endian byte order.
00163 u4_t os_rlsbf4 (xref2cu1_t buf);
00164 #endif
00165 #ifndef os_wlsbf4
00166 //! Write 32-bit quntity into buffer in little endian byte order.
00167 void os_wlsbf4 (xref2u1_t buf, u4_t value);
00168 #endif
00169 #ifndef os_rmsbf4
00170 //! Read 32-bit quantity from given pointer in big endian byte order.
00171 u4_t os_rmsbf4 (xref2cu1_t buf);
00172 #endif
00173 #ifndef os_wmsbf4
00174 //! Write 32-bit quntity into buffer in big endian byte order.
00175 void os_wmsbf4 (xref2u1_t buf, u4_t value);
00176 #endif
00177 #ifndef os_rlsbf2
00178 //! Read 16-bit quantity from given pointer in little endian byte order.
00179 u2_t os_rlsbf2 (xref2cu1_t buf);
00180 #endif
00181 #ifndef os_wlsbf2
00182 //! Write 16-bit quntity into buffer in little endian byte order.
00183 void os_wlsbf2 (xref2u1_t buf, u2_t value);
00184 #endif
00185 
00186 //! Get random number (default impl for u2_t).
00187 #ifndef os_getRndU2
00188 #define os_getRndU2() ((u2_t)((os_getRndU1()<<8)|os_getRndU1()))
00189 #endif
00190 #ifndef os_crc16
00191 u2_t os_crc16 (xref2u1_t d, uint len);
00192 #endif
00193 
00194 #endif // !HAS_os_calls
00195 
00196 // ======================================================================
00197 // AES support 
00198 // !!Keep in sync with lorabase.hpp!!
00199 
00200 #ifndef AES_ENC  // if AES_ENC is defined as macro all other values must be too
00201 #define AES_ENC       0x00 
00202 #define AES_DEC       0x01
00203 #define AES_MIC       0x02
00204 #define AES_CTR       0x04
00205 #define AES_MICNOAUX  0x08
00206 #endif
00207 #ifndef AESkey  // if AESkey is defined as macro all other values must be too
00208 extern xref2u1_t AESkey;
00209 extern xref2u1_t AESaux;
00210 #endif
00211 #ifndef os_aes
00212 u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len);
00213 #endif
00214 
00215 
00216 
00217 #endif // _oslmic_h_