Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LMiC by
oslmic.h
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 #endif 00094 00095 #ifndef OSTICKS_PER_SEC 00096 #define OSTICKS_PER_SEC 15625 00097 #elif OSTICKS_PER_SEC < 10000 || OSTICKS_PER_SEC > 64516 00098 #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long. 00099 #endif 00100 00101 typedef s4_t ostime_t; 00102 00103 #if !HAS_ostick_conv 00104 #define us2osticks(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC) / 1000000)) 00105 #define ms2osticks(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC) / 1000)) 00106 #define sec2osticks(sec) ((ostime_t)( (s8_t)(sec) * OSTICKS_PER_SEC)) 00107 #define osticks2ms(os) ((s4_t)(((os)*(s8_t)1000 ) / OSTICKS_PER_SEC)) 00108 #define osticks2us(os) ((s4_t)(((os)*(s8_t)1000000 ) / OSTICKS_PER_SEC)) 00109 // Special versions 00110 #define us2osticksCeil(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 999999) / 1000000)) 00111 #define us2osticksRound(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 500000) / 1000000)) 00112 #define ms2osticksCeil(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 999) / 1000)) 00113 #define ms2osticksRound(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 500) / 1000)) 00114 #endif 00115 00116 00117 struct osjob_t; // fwd decl. 00118 typedef void (*osjobcb_t) (struct osjob_t*); 00119 struct osjob_t { 00120 struct osjob_t* next; 00121 ostime_t deadline; 00122 osjobcb_t func; 00123 }; 00124 TYPEDEF_xref2osjob_t; 00125 00126 00127 #ifndef HAS_os_calls 00128 00129 #ifndef os_getDevKey 00130 void os_getDevKey (xref2u1_t buf); 00131 #endif 00132 #ifndef os_getArtEui 00133 void os_getArtEui (xref2u1_t buf); 00134 #endif 00135 #ifndef os_getDevEui 00136 void os_getDevEui (xref2u1_t buf); 00137 #endif 00138 #ifndef os_setCallback 00139 void os_setCallback (xref2osjob_t job, osjobcb_t cb); 00140 #endif 00141 #ifndef os_setTimedCallback 00142 void os_setTimedCallback (xref2osjob_t job, ostime_t time, osjobcb_t cb); 00143 #endif 00144 #ifndef os_clearCallback 00145 void os_clearCallback (xref2osjob_t job); 00146 #endif 00147 #ifndef os_getTime 00148 ostime_t os_getTime (void); 00149 #endif 00150 #ifndef os_getTimeSecs 00151 uint os_getTimeSecs (void); 00152 #endif 00153 #ifndef os_radio 00154 void os_radio (u1_t mode); 00155 #endif 00156 #ifndef os_getBattLevel 00157 u1_t os_getBattLevel (void); 00158 #endif 00159 00160 #ifndef os_rlsbf4 00161 //! Read 32-bit quantity from given pointer in little endian byte order. 00162 u4_t os_rlsbf4 (xref2cu1_t buf); 00163 #endif 00164 #ifndef os_wlsbf4 00165 //! Write 32-bit quntity into buffer in little endian byte order. 00166 void os_wlsbf4 (xref2u1_t buf, u4_t value); 00167 #endif 00168 #ifndef os_rmsbf4 00169 //! Read 32-bit quantity from given pointer in big endian byte order. 00170 u4_t os_rmsbf4 (xref2cu1_t buf); 00171 #endif 00172 #ifndef os_wmsbf4 00173 //! Write 32-bit quntity into buffer in big endian byte order. 00174 void os_wmsbf4 (xref2u1_t buf, u4_t value); 00175 #endif 00176 #ifndef os_rlsbf2 00177 //! Read 16-bit quantity from given pointer in little endian byte order. 00178 u2_t os_rlsbf2 (xref2cu1_t buf); 00179 #endif 00180 #ifndef os_wlsbf2 00181 //! Write 16-bit quntity into buffer in little endian byte order. 00182 void os_wlsbf2 (xref2u1_t buf, u2_t value); 00183 #endif 00184 00185 //! Get random number (default impl for u2_t). 00186 #ifndef os_getRndU2 00187 #define os_getRndU2() ((u2_t)((os_getRndU1()<<8)|os_getRndU1())) 00188 #endif 00189 #ifndef os_crc16 00190 u2_t os_crc16 (xref2u1_t d, uint len); 00191 #endif 00192 00193 #endif // !HAS_os_calls 00194 00195 // ====================================================================== 00196 // AES support 00197 // !!Keep in sync with lorabase.hpp!! 00198 00199 #ifndef AES_ENC // if AES_ENC is defined as macro all other values must be too 00200 #define AES_ENC 0x00 00201 #define AES_DEC 0x01 00202 #define AES_MIC 0x02 00203 #define AES_CTR 0x04 00204 #define AES_MICNOAUX 0x08 00205 #endif 00206 #ifndef AESkey // if AESkey is defined as macro all other values must be too 00207 extern xref2u1_t AESkey; 00208 extern xref2u1_t AESaux; 00209 #endif 00210 #ifndef os_aes 00211 u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len); 00212 #endif 00213 00214 00215 00216 #endif // _oslmic_h_
Generated on Thu Jul 14 2022 20:52:24 by
1.7.2
