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_MOTE_L152RC_2 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 #include "config.h" 00040 00041 #define EV(a,b,c) /**/ 00042 #define DO_DEVDB(field1,field2) /**/ 00043 #if !defined(CFG_noassert) 00044 #define ASSERT(cond) if(!(cond)) hal_failed() 00045 #else 00046 #define ASSERT(cond) /**/ 00047 #endif 00048 00049 #define os_clearMem(a,b) memset(a,0,b) 00050 #define os_copyMem(a,b,c) memcpy(a,b,c) 00051 00052 typedef struct osjob_t osjob_t; 00053 typedef struct band_t band_t; 00054 typedef struct chnldef_t chnldef_t; 00055 typedef struct rxsched_t rxsched_t; 00056 typedef struct bcninfo_t bcninfo_t; 00057 typedef const u1_t* xref2cu1_t; 00058 typedef u1_t* xref2u1_t; 00059 #define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t 00060 #define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t 00061 #define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t 00062 #define TYPEDEF_xref2band_t typedef band_t* xref2band_t 00063 #define TYPEDEF_xref2osjob_t typedef osjob_t* xref2osjob_t 00064 00065 #define SIZEOFEXPR(x) sizeof(x) 00066 00067 #define ON_LMIC_EVENT(ev) onEvent(ev) 00068 #define DECL_ON_LMIC_EVENT void onEvent(ev_t e) 00069 00070 extern u4_t AESAUX[]; 00071 extern u4_t AESKEY[]; 00072 #define AESkey ((u1_t*)AESKEY) 00073 #define AESaux ((u1_t*)AESAUX) 00074 #define FUNC_ADDR(func) (&(func)) 00075 00076 u1_t radio_rand1 (void); 00077 #define os_getRndU1() radio_rand1() 00078 00079 #define DEFINE_LMIC struct lmic_t LMIC 00080 #define DECLARE_LMIC extern struct lmic_t LMIC 00081 00082 void radio_init (void); 00083 void radio_irq_handler (u1_t dio); 00084 void os_init (void); 00085 void os_runloop (void); 00086 00087 //================================================================================ 00088 00089 00090 #ifndef RX_RAMPUP 00091 #define RX_RAMPUP (us2osticks(2000)) 00092 #endif 00093 #ifndef TX_RAMPUP 00094 #define TX_RAMPUP (us2osticks(2000)) 00095 #endif 00096 00097 /* OSTICKS_PER_SEC is platform specific. Moved to hal.h */ 00098 00099 typedef s4_t ostime_t; 00100 00101 #if !HAS_ostick_conv 00102 #define us2osticks(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC) / 1000000)) 00103 #define ms2osticks(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC) / 1000)) 00104 #define sec2osticks(sec) ((ostime_t)( (s8_t)(sec) * OSTICKS_PER_SEC)) 00105 #define osticks2ms(os) ((s4_t)(((os)*(s8_t)1000 ) / OSTICKS_PER_SEC)) 00106 #define osticks2us(os) ((s4_t)(((os)*(s8_t)1000000 ) / OSTICKS_PER_SEC)) 00107 // Special versions 00108 #define us2osticksCeil(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 999999) / 1000000)) 00109 #define us2osticksRound(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 500000) / 1000000)) 00110 #define ms2osticksCeil(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 999) / 1000)) 00111 #define ms2osticksRound(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 500) / 1000)) 00112 #endif 00113 00114 00115 struct osjob_t; // fwd decl. 00116 typedef void (*osjobcb_t) (struct osjob_t*); 00117 struct osjob_t { 00118 struct osjob_t* next; 00119 ostime_t deadline; 00120 osjobcb_t func; 00121 }; 00122 TYPEDEF_xref2osjob_t; 00123 00124 00125 #ifndef HAS_os_calls 00126 00127 #ifndef os_getDevKey 00128 void os_getDevKey (xref2u1_t buf); 00129 #endif 00130 #ifndef os_getArtEui 00131 void os_getArtEui (xref2u1_t buf); 00132 #endif 00133 #ifndef os_getDevEui 00134 void os_getDevEui (xref2u1_t buf); 00135 #endif 00136 #ifndef os_setCallback 00137 void os_setCallback (xref2osjob_t job, osjobcb_t cb); 00138 #endif 00139 #ifndef os_setTimedCallback 00140 void os_setTimedCallback (xref2osjob_t job, ostime_t time, osjobcb_t cb); 00141 #endif 00142 #ifndef os_clearCallback 00143 void os_clearCallback (xref2osjob_t job); 00144 #endif 00145 #ifndef os_getTime 00146 ostime_t os_getTime (void); 00147 #endif 00148 #ifndef os_getTimeSecs 00149 uint os_getTimeSecs (void); 00150 #endif 00151 #ifndef os_radio 00152 void os_radio (u1_t mode); 00153 #endif 00154 #ifndef os_getBattLevel 00155 u1_t os_getBattLevel (void); 00156 #endif 00157 00158 #ifndef os_rlsbf4 00159 //! Read 32-bit quantity from given pointer in little endian byte order. 00160 u4_t os_rlsbf4 (xref2cu1_t buf); 00161 #endif 00162 #ifndef os_wlsbf4 00163 //! Write 32-bit quntity into buffer in little endian byte order. 00164 void os_wlsbf4 (xref2u1_t buf, u4_t value); 00165 #endif 00166 #ifndef os_rmsbf4 00167 //! Read 32-bit quantity from given pointer in big endian byte order. 00168 u4_t os_rmsbf4 (xref2cu1_t buf); 00169 #endif 00170 #ifndef os_wmsbf4 00171 //! Write 32-bit quntity into buffer in big endian byte order. 00172 void os_wmsbf4 (xref2u1_t buf, u4_t value); 00173 #endif 00174 #ifndef os_rlsbf2 00175 //! Read 16-bit quantity from given pointer in little endian byte order. 00176 u2_t os_rlsbf2 (xref2cu1_t buf); 00177 #endif 00178 #ifndef os_wlsbf2 00179 //! Write 16-bit quntity into buffer in little endian byte order. 00180 void os_wlsbf2 (xref2u1_t buf, u2_t value); 00181 #endif 00182 00183 //! Get random number (default impl for u2_t). 00184 #ifndef os_getRndU2 00185 #define os_getRndU2() ((u2_t)((os_getRndU1()<<8)|os_getRndU1())) 00186 #endif 00187 #ifndef os_crc16 00188 u2_t os_crc16 (xref2u1_t d, uint len); 00189 #endif 00190 00191 #endif // !HAS_os_calls 00192 00193 // ====================================================================== 00194 // AES support 00195 // !!Keep in sync with lorabase.hpp!! 00196 00197 #ifndef AES_ENC // if AES_ENC is defined as macro all other values must be too 00198 #define AES_ENC 0x00 00199 #define AES_DEC 0x01 00200 #define AES_MIC 0x02 00201 #define AES_CTR 0x04 00202 #define AES_MICNOAUX 0x08 00203 #endif 00204 #ifndef AESkey // if AESkey is defined as macro all other values must be too 00205 extern xref2u1_t AESkey; 00206 extern xref2u1_t AESaux; 00207 #endif 00208 #ifndef os_aes 00209 u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len); 00210 #endif 00211 00212 00213 00214 #endif // _oslmic_h_
Generated on Mon Jul 18 2022 07:47:29 by
1.7.2
