├── README.md
├── doc
├── LMiC-v1.5.pdf
├── README.txt
└── release-notes.txt
├── examples
├── beacon
│ ├── beacon.ewd
│ ├── beacon.ewp
│ ├── beacon.eww
│ ├── beacon.uvoptx
│ ├── beacon.uvprojx
│ ├── main.c
│ └── makefile
├── hello
│ ├── debug.h
│ ├── hello
│ ├── hello.ewd
│ ├── hello.ewp
│ ├── hello.eww
│ ├── hello.uvoptx
│ ├── hello.uvprojx
│ ├── main.c
│ └── makefile
├── interrupt
│ ├── debug.h
│ ├── interrupt.ewd
│ ├── interrupt.ewp
│ ├── interrupt.eww
│ ├── interrupt.uvoptx
│ ├── interrupt.uvprojx
│ ├── main.c
│ ├── makefile
│ └── sensor.c
├── join
│ ├── join.ewd
│ ├── join.ewp
│ ├── join.eww
│ ├── join.uvoptx
│ ├── join.uvprojx
│ ├── main.c
│ └── makefile
├── periodic
│ ├── debug.h
│ ├── main.c
│ ├── makefile
│ ├── periodic
│ ├── periodic.ewd
│ ├── periodic.ewp
│ ├── periodic.eww
│ ├── periodic.uvoptx
│ ├── periodic.uvprojx
│ └── sensor.c
├── ping
│ ├── main.c
│ ├── makefile
│ ├── ping.ewd
│ ├── ping.ewp
│ ├── ping.eww
│ ├── ping.uvoptx
│ └── ping.uvprojx
├── projects.gmk
├── thethingsnetwork-send-v1
│ ├── .gitignore
│ ├── Makefile
│ ├── thethingsnetwork-send-v1.cpp
│ └── thethingsnetwork-send-v1.ino
└── transmit
│ ├── main.c
│ ├── makefile
│ ├── transmit.ewd
│ ├── transmit.ewp
│ ├── transmit.eww
│ ├── transmit.uvoptx
│ └── transmit.uvprojx
└── lmic
├── Makefile
├── aes.c
├── config.h
├── hal.c
├── hal.h
├── lmic.c
├── lmic.h
├── local_hal.h
├── lorabase.h
├── oslmic.c
├── oslmic.h
└── radio.c
/README.md:
--------------------------------------------------------------------------------
1 | # lmic_pi
2 | Raspberry Pi port LoRaMAC in C / LoRaWAN in C http://www.research.ibm.com/labs/zurich/ics/lrsc/lmic.html
3 |
4 | This is a port of IBM's LMIC 1.5 to the Raspberry Pi using the wiringPi library for GPIO/SPI.
5 | It is adapted for TTN (http://thethingsnetwork.org).
6 |
7 | It has been tested with an HopeRF RFM95W chip, but should also work with a SX1272 or SX1276.
8 |
9 | Some of the changes were taken from or inspired by the arduino-lmic-v1.5 port of tftelkamp (https://github.com/tftelkamp/arduino-lmic-v1.5.git)
10 |
11 | The connections of the pins are defined in the main programs in the examples directory.
12 | Standard connections are:
13 | WiringPi 6 == nss
14 |
15 | not connected == rxtx: not used for RFM95
16 |
17 | WiringPi 0 == reset (needed for RFM92/RFM95)
18 |
19 | WiringPi 7,4,5 == dio0, dio1, dio2
20 |
21 | WiringPi 12 == MOSI
22 |
23 | WiringPi 13 == MISO
24 |
25 | WiringPi 14 == SCK
26 |
27 | GND == GND
28 |
29 | 3.3V == +3.3V
30 |
31 | The only examples currently implemented are hello (which does nothing) and thethingsnetwork-send-v1 which sends test strings to the TTN network (if a gateway is in reach).
32 | Do not forget to put your own device number in thethingsnetwork-send-v1.cpp!!
33 |
--------------------------------------------------------------------------------
/doc/LMiC-v1.5.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ernstdevreede/lmic_pi/c4a7c2080faf3fb76277f78b6d035c284a5eec9c/doc/LMiC-v1.5.pdf
--------------------------------------------------------------------------------
/doc/README.txt:
--------------------------------------------------------------------------------
1 | DISCLAIMER:
2 | Please note that the software is provided AS IS and we cannot
3 | provide support for optimizations, adaptations, integration,
4 | ports to other platforms or device drivers!
5 |
--------------------------------------------------------------------------------
/doc/release-notes.txt:
--------------------------------------------------------------------------------
1 | ==============================================================================
2 | LMIC VERSION 1.4 (17-Mar-2015)
3 | -------------------------------
4 |
5 | - changed API: inverted port indicator flag in LMIC.txrxFlags
6 | (now TXRX_PORT, previously TXRX_NOPORT)
7 |
8 | - fixed offset OFF_CFLIST constant
9 |
10 | - changed CRC-16 algorithm for beacons to CCITT(XMODEM) polynomial
11 |
12 | - fixed radio driver (low data rate optimization for SF11+SF12 only for BW125)
13 |
14 | - fixed timer rollover handling in job queue
15 |
16 | ==============================================================================
17 | LMIC VERSION 1.5 (8-May-2015)
18 | ------------------------------
19 |
20 | - fixed condition in convFreq()
21 |
22 | - fixed freq*100 bug and freq==0 bug for CFList
23 |
24 | - fixed TX scheduling bug
25 |
26 | - better support for GNU compiler toolchain
27 |
28 | ==============================================================================
29 |
--------------------------------------------------------------------------------
/examples/beacon/beacon.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\beacon.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/beacon/beacon.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 255
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 |
198 |
199 | lmic
200 | 0
201 | 0
202 | 0
203 | 0
204 |
205 | 2
206 | 2
207 | 1
208 | 0
209 | 0
210 | 0
211 | 0
212 | ..\..\lmic\aes.c
213 | aes.c
214 | 0
215 | 0
216 |
217 |
218 | 2
219 | 3
220 | 5
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\hal.h
226 | hal.h
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 1
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\lmic.c
239 | lmic.c
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 5
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.h
252 | lmic.h
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lorabase.h
265 | lorabase.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 1
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\oslmic.c
278 | oslmic.c
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 5
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.h
291 | oslmic.h
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 1
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\radio.c
304 | radio.c
305 | 0
306 | 0
307 |
308 |
309 |
310 |
311 | stm32
312 | 0
313 | 0
314 | 0
315 | 0
316 |
317 | 3
318 | 10
319 | 1
320 | 0
321 | 0
322 | 0
323 | 0
324 | ..\..\stm32\debug.c
325 | debug.c
326 | 0
327 | 0
328 |
329 |
330 | 3
331 | 11
332 | 5
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.h
338 | debug.h
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 1
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\hal.c
351 | hal.c
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hw.c
364 | hw.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 5
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.h
377 | hw.h
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 2
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\startup_stm32l1xx_md_keil.s
390 | startup_stm32l1xx_md_keil.s
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 5
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\stm32l1xx.h
403 | stm32l1xx.h
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 1
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\system_stm32l1xx.c
416 | system_stm32l1xx.c
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 5
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.h
429 | system_stm32l1xx.h
430 | 0
431 | 0
432 |
433 |
434 |
435 |
436 | ::CMSIS
437 | 0
438 | 0
439 | 0
440 | 1
441 |
442 |
443 |
444 |
--------------------------------------------------------------------------------
/examples/beacon/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 |
15 | //////////////////////////////////////////////////
16 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
17 | //////////////////////////////////////////////////
18 |
19 | // application router ID (LSBF)
20 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
21 |
22 | // unique device ID (LSBF)
23 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
24 |
25 | // device-specific AES key (derived from device EUI)
26 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
27 |
28 |
29 | //////////////////////////////////////////////////
30 | // APPLICATION CALLBACKS
31 | //////////////////////////////////////////////////
32 |
33 | // provide application router ID (8 bytes, LSBF)
34 | void os_getArtEui (u1_t* buf) {
35 | memcpy(buf, APPEUI, 8);
36 | }
37 |
38 | // provide device ID (8 bytes, LSBF)
39 | void os_getDevEui (u1_t* buf) {
40 | memcpy(buf, DEVEUI, 8);
41 | }
42 |
43 | // provide device key (16 bytes)
44 | void os_getDevKey (u1_t* buf) {
45 | memcpy(buf, DEVKEY, 16);
46 | }
47 |
48 |
49 | //////////////////////////////////////////////////
50 | // MAIN - INITIALIZATION AND STARTUP
51 | //////////////////////////////////////////////////
52 |
53 | // initial job
54 | static void initfunc (osjob_t* j) {
55 | // reset MAC state
56 | LMIC_reset();
57 | // start joining
58 | LMIC_startJoining();
59 | // init done - onEvent() callback will be invoked...
60 | }
61 |
62 |
63 | // application entry point
64 | int main () {
65 | osjob_t initjob;
66 |
67 | // initialize runtime env
68 | os_init();
69 | // initialize debug library
70 | debug_init();
71 | // setup initial job
72 | os_setCallback(&initjob, initfunc);
73 | // execute scheduled jobs and events
74 | os_runloop();
75 | // (not reached)
76 | return 0;
77 | }
78 |
79 |
80 | //////////////////////////////////////////////////
81 | // LMIC EVENT CALLBACK
82 | //////////////////////////////////////////////////
83 |
84 | void onEvent (ev_t ev) {
85 | debug_event(ev);
86 |
87 | switch(ev) {
88 |
89 | // network joined, session established
90 | case EV_JOINED:
91 | // enable tracking mode, start scanning...
92 | LMIC_enableTracking(0);
93 | debug_str("SCANNING...\r\n");
94 | break;
95 |
96 | // beacon found by scanning
97 | case EV_BEACON_FOUND:
98 | // switch LEN on
99 | debug_led(1);
100 | break;
101 |
102 | // beacon tracked at expected time
103 | case EV_BEACON_TRACKED:
104 | debug_val("GPS time = ", LMIC.bcninfo.time);
105 | // switch LEN on
106 | debug_led(1);
107 | break;
108 |
109 | // beacon missed at expected time
110 | case EV_BEACON_MISSED:
111 | // switch LEN off
112 | debug_led(0);
113 | break;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/examples/beacon/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/hello/debug.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | #define debug_init()
5 | #define debug_str(s) (fprintf(stderr, "%s\n", s))
6 | #define debug_val(s,v) (fprintf(stderr, "%s: %d\n", s, v))
7 | #define debug_led(v) (fprintf(stderr, "led: %d\n", v))
8 |
--------------------------------------------------------------------------------
/examples/hello/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ernstdevreede/lmic_pi/c4a7c2080faf3fb76277f78b6d035c284a5eec9c/examples/hello/hello
--------------------------------------------------------------------------------
/examples/hello/hello.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\hello.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/hello/hello.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 255
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O10479 -O10479 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | lmic
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | ..\..\lmic\aes.c
192 | aes.c
193 | 0
194 | 0
195 |
196 |
197 | 1
198 | 2
199 | 5
200 | 0
201 | 0
202 | 0
203 | 0
204 | ..\..\lmic\hal.h
205 | hal.h
206 | 0
207 | 0
208 |
209 |
210 | 1
211 | 3
212 | 1
213 | 0
214 | 0
215 | 0
216 | 0
217 | ..\..\lmic\lmic.c
218 | lmic.c
219 | 0
220 | 0
221 |
222 |
223 | 1
224 | 4
225 | 5
226 | 0
227 | 0
228 | 0
229 | 0
230 | ..\..\lmic\lmic.h
231 | lmic.h
232 | 0
233 | 0
234 |
235 |
236 | 1
237 | 5
238 | 5
239 | 0
240 | 0
241 | 0
242 | 0
243 | ..\..\lmic\lorabase.h
244 | lorabase.h
245 | 0
246 | 0
247 |
248 |
249 | 1
250 | 6
251 | 1
252 | 0
253 | 0
254 | 0
255 | 0
256 | ..\..\lmic\oslmic.c
257 | oslmic.c
258 | 0
259 | 0
260 |
261 |
262 | 1
263 | 7
264 | 5
265 | 0
266 | 0
267 | 0
268 | 0
269 | ..\..\lmic\oslmic.h
270 | oslmic.h
271 | 0
272 | 0
273 |
274 |
275 | 1
276 | 8
277 | 1
278 | 0
279 | 0
280 | 0
281 | 0
282 | ..\..\lmic\radio.c
283 | radio.c
284 | 0
285 | 0
286 |
287 |
288 |
289 |
290 | stm32
291 | 0
292 | 0
293 | 0
294 | 0
295 |
296 | 2
297 | 9
298 | 1
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\stm32\debug.c
304 | debug.c
305 | 0
306 | 0
307 |
308 |
309 | 2
310 | 10
311 | 5
312 | 0
313 | 0
314 | 0
315 | 0
316 | ..\..\stm32\debug.h
317 | debug.h
318 | 0
319 | 0
320 |
321 |
322 | 2
323 | 11
324 | 1
325 | 0
326 | 0
327 | 0
328 | 0
329 | ..\..\stm32\hal.c
330 | hal.c
331 | 0
332 | 0
333 |
334 |
335 | 2
336 | 12
337 | 1
338 | 0
339 | 0
340 | 0
341 | 0
342 | ..\..\stm32\hw.c
343 | hw.c
344 | 0
345 | 0
346 |
347 |
348 | 2
349 | 13
350 | 5
351 | 0
352 | 0
353 | 0
354 | 0
355 | ..\..\stm32\hw.h
356 | hw.h
357 | 0
358 | 0
359 |
360 |
361 | 2
362 | 14
363 | 2
364 | 0
365 | 0
366 | 0
367 | 0
368 | ..\..\stm32\startup_stm32l1xx_md_keil.s
369 | startup_stm32l1xx_md_keil.s
370 | 0
371 | 0
372 |
373 |
374 | 2
375 | 15
376 | 5
377 | 0
378 | 0
379 | 0
380 | 0
381 | ..\..\stm32\stm32l1xx.h
382 | stm32l1xx.h
383 | 0
384 | 0
385 |
386 |
387 | 2
388 | 16
389 | 1
390 | 0
391 | 0
392 | 0
393 | 0
394 | ..\..\stm32\system_stm32l1xx.c
395 | system_stm32l1xx.c
396 | 0
397 | 0
398 |
399 |
400 | 2
401 | 17
402 | 5
403 | 0
404 | 0
405 | 0
406 | 0
407 | ..\..\stm32\system_stm32l1xx.h
408 | system_stm32l1xx.h
409 | 0
410 | 0
411 |
412 |
413 |
414 |
415 | app
416 | 0
417 | 0
418 | 0
419 | 0
420 |
421 | 3
422 | 18
423 | 1
424 | 0
425 | 0
426 | 0
427 | 0
428 | .\main.c
429 | main.c
430 | 0
431 | 0
432 |
433 |
434 |
435 |
436 |
--------------------------------------------------------------------------------
/examples/hello/hello.uvprojx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2.1
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 |
10 | Target 1
11 | 0x4
12 | ARM-ADS
13 |
14 |
15 | STM32L151C6
16 | STMicroelectronics
17 | IROM(0x08000000,0x8000) IRAM(0x20000000,0x2800) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE
18 |
19 |
20 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
21 | 6222
22 | $$Device:STM32L151C6$Device\Include\STM32L1xx.h
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | $$Device:STM32L151C6$SVD\STM32L1xx.svd
33 | 0
34 | 0
35 |
36 |
37 |
38 |
39 |
40 |
41 | 0
42 | 0
43 | 0
44 | 0
45 | 1
46 |
47 | .\build\
48 | hello
49 | 1
50 | 0
51 | 1
52 | 1
53 | 1
54 | .\
55 | 1
56 | 0
57 | 0
58 |
59 | 0
60 | 0
61 |
62 |
63 | 0
64 | 0
65 | 0
66 | 0
67 |
68 |
69 | 0
70 | 0
71 |
72 |
73 | 0
74 | 0
75 | 0
76 | 0
77 |
78 |
79 | 0
80 | 0
81 |
82 |
83 | 0
84 | 0
85 |
86 | 0
87 |
88 |
89 |
90 | 0
91 | 0
92 | 0
93 | 0
94 | 0
95 | 1
96 | 0
97 | 0
98 | 0
99 | 0
100 | 3
101 |
102 |
103 | 1
104 |
105 |
106 | SARMCM3.DLL
107 | -MPU -REMAP
108 | DCM.DLL
109 | -pCM3
110 | SARMCM3.DLL
111 | -MPU
112 | TCM.DLL
113 | -pCM3
114 |
115 |
116 |
117 | 1
118 | 0
119 | 0
120 | 0
121 | 16
122 |
123 |
124 | 0
125 | 1
126 | 1
127 | 1
128 | 1
129 | 1
130 | 1
131 | 1
132 | 0
133 | 1
134 |
135 |
136 | 1
137 | 1
138 | 1
139 | 1
140 | 1
141 | 1
142 | 0
143 | 1
144 | 1
145 | 1
146 | 1
147 |
148 | 0
149 | 11
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 | STLink\ST-LINKIII-KEIL_SWO.dll
164 |
165 |
166 |
167 |
168 | 1
169 | 0
170 | 0
171 | 1
172 | 1
173 | 4096
174 |
175 | 1
176 | BIN\UL2CM3.DLL
177 | "" ()
178 |
179 |
180 |
181 |
182 | 0
183 |
184 |
185 |
186 | 0
187 | 1
188 | 1
189 | 1
190 | 1
191 | 1
192 | 1
193 | 1
194 | 0
195 | 1
196 | 1
197 | 0
198 | 0
199 | 1
200 | 0
201 | 0
202 | 0
203 | 1
204 | 1
205 | 1
206 | 1
207 | 1
208 | 1
209 | 1
210 | 1
211 | 0
212 | 0
213 | "Cortex-M3"
214 |
215 | 0
216 | 0
217 | 0
218 | 1
219 | 1
220 | 0
221 | 0
222 | 0
223 | 0
224 | 0
225 | 8
226 | 1
227 | 0
228 | 0
229 | 3
230 | 3
231 | 0
232 | 0
233 | 0
234 | 0
235 | 0
236 | 0
237 | 0
238 | 0
239 | 0
240 | 0
241 | 1
242 | 0
243 | 0
244 | 0
245 | 0
246 | 1
247 | 0
248 |
249 |
250 | 0
251 | 0x0
252 | 0x0
253 |
254 |
255 | 0
256 | 0x0
257 | 0x0
258 |
259 |
260 | 0
261 | 0x0
262 | 0x0
263 |
264 |
265 | 0
266 | 0x0
267 | 0x0
268 |
269 |
270 | 0
271 | 0x0
272 | 0x0
273 |
274 |
275 | 0
276 | 0x0
277 | 0x0
278 |
279 |
280 | 0
281 | 0x20000000
282 | 0x2800
283 |
284 |
285 | 1
286 | 0x8000000
287 | 0x8000
288 |
289 |
290 | 0
291 | 0x0
292 | 0x0
293 |
294 |
295 | 1
296 | 0x0
297 | 0x0
298 |
299 |
300 | 1
301 | 0x0
302 | 0x0
303 |
304 |
305 | 1
306 | 0x0
307 | 0x0
308 |
309 |
310 | 1
311 | 0x8000000
312 | 0x8000
313 |
314 |
315 | 1
316 | 0x0
317 | 0x0
318 |
319 |
320 | 0
321 | 0x0
322 | 0x0
323 |
324 |
325 | 0
326 | 0x0
327 | 0x0
328 |
329 |
330 | 0
331 | 0x0
332 | 0x0
333 |
334 |
335 | 0
336 | 0x20000000
337 | 0x2800
338 |
339 |
340 | 0
341 | 0x0
342 | 0x0
343 |
344 |
345 |
346 |
347 |
348 | 1
349 | 1
350 | 0
351 | 0
352 | 0
353 | 0
354 | 0
355 | 0
356 | 0
357 | 0
358 | 2
359 | 0
360 | 0
361 | 1
362 | 0
363 |
364 |
365 | STM32L1XX_MD CFG_lmic_clib CFG_eu868 CFG_wimod_board CFG_sx1272_radio
366 |
367 | ../../lmic;../../stm32
368 |
369 |
370 |
371 | 1
372 | 0
373 | 0
374 | 0
375 | 0
376 | 0
377 | 0
378 | 0
379 | 0
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | 0
389 | 0
390 | 0
391 | 0
392 | 1
393 | 0
394 | 0x08000000
395 | 0x20000000
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 | lmic
409 |
410 |
411 | aes.c
412 | 1
413 | ..\..\lmic\aes.c
414 |
415 |
416 | hal.h
417 | 5
418 | ..\..\lmic\hal.h
419 |
420 |
421 | lmic.c
422 | 1
423 | ..\..\lmic\lmic.c
424 |
425 |
426 | lmic.h
427 | 5
428 | ..\..\lmic\lmic.h
429 |
430 |
431 | lorabase.h
432 | 5
433 | ..\..\lmic\lorabase.h
434 |
435 |
436 | oslmic.c
437 | 1
438 | ..\..\lmic\oslmic.c
439 |
440 |
441 | oslmic.h
442 | 5
443 | ..\..\lmic\oslmic.h
444 |
445 |
446 | radio.c
447 | 1
448 | ..\..\lmic\radio.c
449 |
450 |
451 |
452 |
453 | stm32
454 |
455 |
456 | debug.c
457 | 1
458 | ..\..\stm32\debug.c
459 |
460 |
461 | debug.h
462 | 5
463 | ..\..\stm32\debug.h
464 |
465 |
466 | hal.c
467 | 1
468 | ..\..\stm32\hal.c
469 |
470 |
471 | hw.c
472 | 1
473 | ..\..\stm32\hw.c
474 |
475 |
476 | hw.h
477 | 5
478 | ..\..\stm32\hw.h
479 |
480 |
481 | startup_stm32l1xx_md_keil.s
482 | 2
483 | ..\..\stm32\startup_stm32l1xx_md_keil.s
484 |
485 |
486 | stm32l1xx.h
487 | 5
488 | ..\..\stm32\stm32l1xx.h
489 |
490 |
491 | system_stm32l1xx.c
492 | 1
493 | ..\..\stm32\system_stm32l1xx.c
494 |
495 |
496 | system_stm32l1xx.h
497 | 5
498 | ..\..\stm32\system_stm32l1xx.h
499 |
500 |
501 |
502 |
503 | app
504 |
505 |
506 | main.c
507 | 1
508 | .\main.c
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
--------------------------------------------------------------------------------
/examples/hello/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 | #include "local_hal.h"
15 |
16 | // Pin mapping
17 | lmic_pinmap pins = {
18 | .nss = 6,
19 | .rxtx = 5, // Not connected on RFM92/RFM95
20 | .rst = 0, // Needed on RFM92/RFM95
21 | .dio = {7,4,5}
22 | };
23 |
24 |
25 |
26 | // LMIC application callbacks not used in his example
27 | void os_getArtEui (u1_t* buf) {
28 | }
29 |
30 | void os_getDevEui (u1_t* buf) {
31 | }
32 |
33 | void os_getDevKey (u1_t* buf) {
34 | }
35 |
36 | void onEvent (ev_t ev) {
37 | }
38 |
39 | // counter
40 | static int cnt = 0;
41 |
42 | // log text to USART and toggle LED
43 | static void initfunc (osjob_t* job) {
44 | // say hello
45 | debug_str("Hello World!\r\n");
46 | // log counter
47 | debug_val("cnt = ", cnt);
48 | // toggle LED
49 | debug_led(++cnt & 1);
50 | // reschedule job every second
51 | os_setTimedCallback(job, os_getTime()+sec2osticks(1), initfunc);
52 | }
53 |
54 | // application entry point
55 | int main () {
56 | osjob_t initjob;
57 |
58 | // initialize runtime env
59 | os_init();
60 | // initialize debug library
61 | debug_init();
62 | // setup initial job
63 | os_setCallback(&initjob, initfunc);
64 | // execute scheduled jobs and events
65 | os_runloop();
66 | // (not reached)
67 | return 0;
68 | }
69 |
--------------------------------------------------------------------------------
/examples/hello/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/interrupt/debug.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | #define debug_init()
5 | #define debug_str(s) (fprintf(stderr, "%s\n", s))
6 | #define debug_val(s,v) (fprintf(stderr, "%s: %d\n", s, v))
7 | #define debug_led(v) (fprintf(stderr, "led: %d\n", v))
8 |
--------------------------------------------------------------------------------
/examples/interrupt/interrupt.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\interrupt.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/interrupt/interrupt.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 255
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 | 1
198 | 2
199 | 1
200 | 0
201 | 0
202 | 0
203 | 0
204 | .\sensor.c
205 | sensor.c
206 | 0
207 | 0
208 |
209 |
210 |
211 |
212 | lmic
213 | 0
214 | 0
215 | 0
216 | 0
217 |
218 | 2
219 | 3
220 | 1
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\aes.c
226 | aes.c
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 5
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\hal.h
239 | hal.h
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 1
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.c
252 | lmic.c
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lmic.h
265 | lmic.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 5
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\lorabase.h
278 | lorabase.h
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 1
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.c
291 | oslmic.c
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 5
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\oslmic.h
304 | oslmic.h
305 | 0
306 | 0
307 |
308 |
309 | 2
310 | 10
311 | 1
312 | 0
313 | 0
314 | 0
315 | 0
316 | ..\..\lmic\radio.c
317 | radio.c
318 | 0
319 | 0
320 |
321 |
322 |
323 |
324 | stm32
325 | 0
326 | 0
327 | 0
328 | 0
329 |
330 | 3
331 | 11
332 | 1
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.c
338 | debug.c
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 5
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\debug.h
351 | debug.h
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hal.c
364 | hal.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 1
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.c
377 | hw.c
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 5
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\hw.h
390 | hw.h
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 2
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\startup_stm32l1xx_md_keil.s
403 | startup_stm32l1xx_md_keil.s
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 5
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\stm32l1xx.h
416 | stm32l1xx.h
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 1
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.c
429 | system_stm32l1xx.c
430 | 0
431 | 0
432 |
433 |
434 | 3
435 | 19
436 | 5
437 | 0
438 | 0
439 | 0
440 | 0
441 | ..\..\stm32\system_stm32l1xx.h
442 | system_stm32l1xx.h
443 | 0
444 | 0
445 |
446 |
447 |
448 |
449 | ::CMSIS
450 | 0
451 | 0
452 | 0
453 | 1
454 |
455 |
456 |
457 |
--------------------------------------------------------------------------------
/examples/interrupt/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 |
15 | // sensor functions
16 | extern void initsensor(osjobcb_t callback);
17 | extern u2_t readsensor(void);
18 |
19 |
20 | //////////////////////////////////////////////////
21 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
22 | //////////////////////////////////////////////////
23 |
24 | // application router ID (LSBF)
25 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
26 |
27 | // unique device ID (LSBF)
28 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
29 |
30 | // device-specific AES key (derived from device EUI)
31 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
32 |
33 |
34 | //////////////////////////////////////////////////
35 | // APPLICATION CALLBACKS
36 | //////////////////////////////////////////////////
37 |
38 | // provide application router ID (8 bytes, LSBF)
39 | void os_getArtEui (u1_t* buf) {
40 | memcpy(buf, APPEUI, 8);
41 | }
42 |
43 | // provide device ID (8 bytes, LSBF)
44 | void os_getDevEui (u1_t* buf) {
45 | memcpy(buf, DEVEUI, 8);
46 | }
47 |
48 | // provide device key (16 bytes)
49 | void os_getDevKey (u1_t* buf) {
50 | memcpy(buf, DEVKEY, 16);
51 | }
52 |
53 |
54 | //////////////////////////////////////////////////
55 | // SENSOR CALLBACK (run by sensor IRQ job)
56 | //////////////////////////////////////////////////
57 |
58 | // report sensor value when change was detected
59 | static void sensorfunc (osjob_t* j) {
60 | // read sensor
61 | u2_t val = readsensor();
62 | debug_val("val = ", val);
63 | // prepare and schedule data for transmission
64 | LMIC.frame[0] = val << 8;
65 | LMIC.frame[1] = val;
66 | LMIC_setTxData2(1, LMIC.frame, 2, 0); // (port 1, 2 bytes, unconfirmed)
67 | }
68 |
69 |
70 | //////////////////////////////////////////////////
71 | // MAIN - INITIALIZATION AND STARTUP
72 | //////////////////////////////////////////////////
73 |
74 | // initial job
75 | static void initfunc (osjob_t* j) {
76 | // intialize sensor hardware
77 | initsensor(sensorfunc);
78 | // reset MAC state
79 | LMIC_reset();
80 | // start joining
81 | LMIC_startJoining();
82 | // init done - onEvent() callback will be invoked...
83 | }
84 |
85 |
86 | // application entry point
87 | int main () {
88 | osjob_t initjob;
89 |
90 | // initialize runtime env
91 | os_init();
92 | // initialize debug library
93 | debug_init();
94 | // setup initial job
95 | os_setCallback(&initjob, initfunc);
96 | // execute scheduled jobs and events
97 | os_runloop();
98 | // (not reached)
99 | return 0;
100 | }
101 |
102 |
103 | //////////////////////////////////////////////////
104 | // LMIC EVENT CALLBACK
105 | //////////////////////////////////////////////////
106 |
107 | void onEvent (ev_t ev) {
108 | debug_event(ev);
109 |
110 | switch(ev) {
111 |
112 | // network joined, session established
113 | case EV_JOINED:
114 | // switch on LED
115 | debug_led(1);
116 | // (further actions will be interrupt-driven)
117 | break;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/examples/interrupt/makefile:
--------------------------------------------------------------------------------
1 | LMICCFG = -DCFG_EXTI_IRQ_HANDLER=sensorirq
2 |
3 | include ../projects.gmk
4 |
--------------------------------------------------------------------------------
/examples/interrupt/sensor.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "hw.h"
14 |
15 | // use PB12 (DIP switch 1)
16 | #define INP_PORT 1
17 | #define INP_PIN 12
18 |
19 | static osjob_t irqjob;
20 |
21 | // use DIP1 as sensor value
22 | void initsensor (osjobcb_t callback) {
23 | // configure input
24 | RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // clock enable port B
25 | hw_cfg_pin(GPIOx(INP_PORT), INP_PIN, GPIOCFG_MODE_INP | GPIOCFG_OSPEED_40MHz | GPIOCFG_OTYPE_OPEN);
26 | hw_cfg_extirq(INP_PORT, INP_PIN, GPIO_IRQ_CHANGE);
27 | // save application callback
28 | irqjob.func = callback;
29 | }
30 |
31 | // read PB12
32 | u2_t readsensor () {
33 | return ((GPIOB->IDR & (1 << INP_PIN)) != 0);
34 | }
35 |
36 | // called by EXTI_IRQHandler
37 | // (set preprocessor option CFG_EXTI_IRQ_HANDLER=sensorirq)
38 | void sensorirq () {
39 | if((EXTI->PR & (1<PR = (1<
2 |
3 |
4 |
5 | $WS_DIR$\join.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/join/join.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 255
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 |
198 |
199 | lmic
200 | 0
201 | 0
202 | 0
203 | 0
204 |
205 | 2
206 | 2
207 | 1
208 | 0
209 | 0
210 | 0
211 | 0
212 | ..\..\lmic\aes.c
213 | aes.c
214 | 0
215 | 0
216 |
217 |
218 | 2
219 | 3
220 | 5
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\hal.h
226 | hal.h
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 1
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\lmic.c
239 | lmic.c
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 5
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.h
252 | lmic.h
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lorabase.h
265 | lorabase.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 1
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\oslmic.c
278 | oslmic.c
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 5
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.h
291 | oslmic.h
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 1
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\radio.c
304 | radio.c
305 | 0
306 | 0
307 |
308 |
309 |
310 |
311 | stm32
312 | 0
313 | 0
314 | 0
315 | 0
316 |
317 | 3
318 | 10
319 | 1
320 | 0
321 | 0
322 | 0
323 | 0
324 | ..\..\stm32\debug.c
325 | debug.c
326 | 0
327 | 0
328 |
329 |
330 | 3
331 | 11
332 | 5
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.h
338 | debug.h
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 1
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\hal.c
351 | hal.c
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hw.c
364 | hw.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 5
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.h
377 | hw.h
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 2
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\startup_stm32l1xx_md_keil.s
390 | startup_stm32l1xx_md_keil.s
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 5
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\stm32l1xx.h
403 | stm32l1xx.h
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 1
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\system_stm32l1xx.c
416 | system_stm32l1xx.c
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 5
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.h
429 | system_stm32l1xx.h
430 | 0
431 | 0
432 |
433 |
434 |
435 |
436 | ::CMSIS
437 | 0
438 | 0
439 | 0
440 | 1
441 |
442 |
443 |
444 |
--------------------------------------------------------------------------------
/examples/join/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 |
15 | //////////////////////////////////////////////////
16 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
17 | //////////////////////////////////////////////////
18 |
19 | // application router ID (LSBF)
20 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
21 |
22 | // unique device ID (LSBF)
23 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
24 |
25 | // device-specific AES key (derived from device EUI)
26 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
27 |
28 |
29 | //////////////////////////////////////////////////
30 | // APPLICATION CALLBACKS
31 | //////////////////////////////////////////////////
32 |
33 | // provide application router ID (8 bytes, LSBF)
34 | void os_getArtEui (u1_t* buf) {
35 | memcpy(buf, APPEUI, 8);
36 | }
37 |
38 | // provide device ID (8 bytes, LSBF)
39 | void os_getDevEui (u1_t* buf) {
40 | memcpy(buf, DEVEUI, 8);
41 | }
42 |
43 | // provide device key (16 bytes)
44 | void os_getDevKey (u1_t* buf) {
45 | memcpy(buf, DEVKEY, 16);
46 | }
47 |
48 |
49 | //////////////////////////////////////////////////
50 | // MAIN - INITIALIZATION AND STARTUP
51 | //////////////////////////////////////////////////
52 |
53 | // initial job
54 | static void initfunc (osjob_t* j) {
55 | // reset MAC state
56 | LMIC_reset();
57 | // start joining
58 | LMIC_startJoining();
59 | // init done - onEvent() callback will be invoked...
60 | }
61 |
62 |
63 | // application entry point
64 | int main () {
65 | osjob_t initjob;
66 |
67 | // initialize runtime env
68 | os_init();
69 | // initialize debug library
70 | debug_init();
71 | // setup initial job
72 | os_setCallback(&initjob, initfunc);
73 | // execute scheduled jobs and events
74 | os_runloop();
75 | // (not reached)
76 | return 0;
77 | }
78 |
79 |
80 | //////////////////////////////////////////////////
81 | // UTILITY JOB
82 | //////////////////////////////////////////////////
83 |
84 | static osjob_t blinkjob;
85 | static u1_t ledstate = 0;
86 |
87 | static void blinkfunc (osjob_t* j) {
88 | // toggle LED
89 | ledstate = !ledstate;
90 | debug_led(ledstate);
91 | // reschedule blink job
92 | os_setTimedCallback(j, os_getTime()+ms2osticks(100), blinkfunc);
93 | }
94 |
95 |
96 | //////////////////////////////////////////////////
97 | // LMIC EVENT CALLBACK
98 | //////////////////////////////////////////////////
99 |
100 | void onEvent (ev_t ev) {
101 | debug_event(ev);
102 |
103 | switch(ev) {
104 |
105 | // starting to join network
106 | case EV_JOINING:
107 | // start blinking
108 | blinkfunc(&blinkjob);
109 | break;
110 |
111 | // network joined, session established
112 | case EV_JOINED:
113 | // cancel blink job
114 | os_clearCallback(&blinkjob);
115 | // switch on LED
116 | debug_led(1);
117 | // (don't schedule any new actions)
118 | break;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/examples/join/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/periodic/debug.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | #define debug_init()
5 | #define debug_str(s) (fprintf(stderr, "%s\n", s))
6 | #define debug_val(s,v) (fprintf(stderr, "%s: %d\n", s, v))
7 | #define debug_led(v) (fprintf(stderr, "led: %d\n", v))
8 |
9 | #define debug_event(e) (fprintf(stderr, "Ev:%d\n", e))
10 |
--------------------------------------------------------------------------------
/examples/periodic/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 | #include "local_hal.h"
15 |
16 | // sensor functions
17 | extern void initsensor(void);
18 | extern u2_t readsensor(void);
19 |
20 | // Pin mapping
21 | lmic_pinmap pins = {
22 | .nss = 6,
23 | .rxtx = 2, // Not connected on RFM92/RFM95
24 | .rst = 0, // Needed on RFM92/RFM95
25 | .dio = {7,4,5}
26 | };
27 |
28 |
29 | //////////////////////////////////////////////////
30 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
31 | //////////////////////////////////////////////////
32 |
33 | // application router ID (LSBF)
34 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
35 |
36 | // unique device ID (LSBF)
37 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
38 |
39 | // device-specific AES key (derived from device EUI)
40 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
41 |
42 |
43 | //////////////////////////////////////////////////
44 | // APPLICATION CALLBACKS
45 | //////////////////////////////////////////////////
46 |
47 | // provide application router ID (8 bytes, LSBF)
48 | void os_getArtEui (u1_t* buf) {
49 | memcpy(buf, APPEUI, 8);
50 | }
51 |
52 | // provide device ID (8 bytes, LSBF)
53 | void os_getDevEui (u1_t* buf) {
54 | memcpy(buf, DEVEUI, 8);
55 | }
56 |
57 | // provide device key (16 bytes)
58 | void os_getDevKey (u1_t* buf) {
59 | memcpy(buf, DEVKEY, 16);
60 | }
61 |
62 |
63 | //////////////////////////////////////////////////
64 | // MAIN - INITIALIZATION AND STARTUP
65 | //////////////////////////////////////////////////
66 |
67 | // initial job
68 | static void initfunc (osjob_t* j) {
69 | // intialize sensor hardware
70 | initsensor();
71 | // reset MAC state
72 | LMIC_reset();
73 | // start joining
74 | LMIC_startJoining();
75 | // init done - onEvent() callback will be invoked...
76 | }
77 |
78 |
79 | // application entry point
80 | int main () {
81 | osjob_t initjob;
82 |
83 | // initialize runtime env
84 | os_init();
85 | // initialize debug library
86 | debug_init();
87 | // setup initial job
88 | os_setCallback(&initjob, initfunc);
89 | // execute scheduled jobs and events
90 | os_runloop();
91 | // (not reached)
92 | return 0;
93 | }
94 |
95 |
96 | //////////////////////////////////////////////////
97 | // UTILITY JOB
98 | //////////////////////////////////////////////////
99 |
100 | static osjob_t reportjob;
101 |
102 | // report sensor value every minute
103 | static void reportfunc (osjob_t* j) {
104 | // read sensor
105 | u2_t val = readsensor();
106 | debug_val("val = ", val);
107 | // prepare and schedule data for transmission
108 | LMIC.frame[0] = val << 8;
109 | LMIC.frame[1] = val;
110 | LMIC_setTxData2(1, LMIC.frame, 2, 0); // (port 1, 2 bytes, unconfirmed)
111 | // reschedule job in 60 seconds
112 | os_setTimedCallback(j, os_getTime()+sec2osticks(15), reportfunc);
113 | }
114 |
115 |
116 | //////////////////////////////////////////////////
117 | // LMIC EVENT CALLBACK
118 | //////////////////////////////////////////////////
119 |
120 | void onEvent (ev_t ev) {
121 | debug_event(ev);
122 |
123 | switch(ev) {
124 |
125 | // network joined, session established
126 | case EV_JOINED:
127 | // switch on LED
128 | debug_led(1);
129 | // kick-off periodic sensor job
130 | reportfunc(&reportjob);
131 | break;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/examples/periodic/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/periodic/periodic:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ernstdevreede/lmic_pi/c4a7c2080faf3fb76277f78b6d035c284a5eec9c/examples/periodic/periodic
--------------------------------------------------------------------------------
/examples/periodic/periodic.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\periodic.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/periodic/periodic.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 0
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 | 1
198 | 2
199 | 1
200 | 0
201 | 0
202 | 0
203 | 0
204 | .\sensor.c
205 | sensor.c
206 | 0
207 | 0
208 |
209 |
210 |
211 |
212 | lmic
213 | 0
214 | 0
215 | 0
216 | 0
217 |
218 | 2
219 | 3
220 | 1
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\aes.c
226 | aes.c
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 5
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\hal.h
239 | hal.h
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 1
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.c
252 | lmic.c
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lmic.h
265 | lmic.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 5
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\lorabase.h
278 | lorabase.h
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 1
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.c
291 | oslmic.c
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 5
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\oslmic.h
304 | oslmic.h
305 | 0
306 | 0
307 |
308 |
309 | 2
310 | 10
311 | 1
312 | 0
313 | 0
314 | 0
315 | 0
316 | ..\..\lmic\radio.c
317 | radio.c
318 | 0
319 | 0
320 |
321 |
322 |
323 |
324 | stm32
325 | 0
326 | 0
327 | 0
328 | 0
329 |
330 | 3
331 | 11
332 | 1
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.c
338 | debug.c
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 5
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\debug.h
351 | debug.h
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hal.c
364 | hal.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 1
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.c
377 | hw.c
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 5
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\hw.h
390 | hw.h
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 2
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\startup_stm32l1xx_md_keil.s
403 | startup_stm32l1xx_md_keil.s
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 5
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\stm32l1xx.h
416 | stm32l1xx.h
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 1
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.c
429 | system_stm32l1xx.c
430 | 0
431 | 0
432 |
433 |
434 | 3
435 | 19
436 | 5
437 | 0
438 | 0
439 | 0
440 | 0
441 | ..\..\stm32\system_stm32l1xx.h
442 | system_stm32l1xx.h
443 | 0
444 | 0
445 |
446 |
447 |
448 |
449 | ::CMSIS
450 | 0
451 | 0
452 | 0
453 | 1
454 |
455 |
456 |
457 |
--------------------------------------------------------------------------------
/examples/periodic/sensor.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | //#include "hw.h"
14 | #include
15 |
16 | // use PB12 (DIP switch 1) as sensor value
17 | void initsensor () {
18 | return;
19 | // RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // clock enable port B
20 | // hw_cfg_pin(GPIOB, 12, GPIOCFG_MODE_INP | GPIOCFG_OSPEED_40MHz | GPIOCFG_OTYPE_OPEN); // PB12
21 | }
22 |
23 | // read PB12
24 | u2_t readsensor () {
25 | return random();
26 | //((GPIOB->IDR & (1 << 12)) != 0);
27 | }
28 |
--------------------------------------------------------------------------------
/examples/ping/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 |
15 | //////////////////////////////////////////////////
16 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
17 | //////////////////////////////////////////////////
18 |
19 | // application router ID (LSBF)
20 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
21 |
22 | // unique device ID (LSBF)
23 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
24 |
25 | // device-specific AES key (derived from device EUI)
26 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
27 |
28 |
29 | //////////////////////////////////////////////////
30 | // APPLICATION CALLBACKS
31 | //////////////////////////////////////////////////
32 |
33 | // provide application router ID (8 bytes, LSBF)
34 | void os_getArtEui (u1_t* buf) {
35 | memcpy(buf, APPEUI, 8);
36 | }
37 |
38 | // provide device ID (8 bytes, LSBF)
39 | void os_getDevEui (u1_t* buf) {
40 | memcpy(buf, DEVEUI, 8);
41 | }
42 |
43 | // provide device key (16 bytes)
44 | void os_getDevKey (u1_t* buf) {
45 | memcpy(buf, DEVKEY, 16);
46 | }
47 |
48 |
49 | //////////////////////////////////////////////////
50 | // MAIN - INITIALIZATION AND STARTUP
51 | //////////////////////////////////////////////////
52 |
53 | // initial job
54 | static void initfunc (osjob_t* j) {
55 | // reset MAC state
56 | LMIC_reset();
57 | // start joining
58 | LMIC_startJoining();
59 | // init done - onEvent() callback will be invoked...
60 | }
61 |
62 |
63 | // application entry point
64 | int main () {
65 | osjob_t initjob;
66 |
67 | // initialize runtime env
68 | os_init();
69 | // initialize debug library
70 | debug_init();
71 | // setup initial job
72 | os_setCallback(&initjob, initfunc);
73 | // execute scheduled jobs and events
74 | os_runloop();
75 | // (not reached)
76 | return 0;
77 | }
78 |
79 |
80 | //////////////////////////////////////////////////
81 | // LMIC EVENT CALLBACK
82 | //////////////////////////////////////////////////
83 |
84 | void onEvent (ev_t ev) {
85 | debug_event(ev);
86 |
87 | switch(ev) {
88 |
89 | // network joined, session established
90 | case EV_JOINED:
91 | // enable pinging mode, start scanning...
92 | // (set local ping interval configuration to 2^1 == 2 sec)
93 | LMIC_setPingable(1);
94 | debug_str("SCANNING...\r\n");
95 | break;
96 |
97 | // beacon found by scanning
98 | case EV_BEACON_FOUND:
99 | // send empty frame up to notify server of ping mode and interval!
100 | LMIC_sendAlive();
101 | break;
102 |
103 | // data frame received in ping slot
104 | case EV_RXCOMPLETE:
105 | // log frame data
106 | debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
107 | if(LMIC.dataLen == 1) {
108 | // set LED state if exactly one byte is received
109 | debug_led(LMIC.frame[LMIC.dataBeg] & 0x01);
110 | }
111 | break;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/examples/ping/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/ping/ping.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\ping.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/ping/ping.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 255
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 |
198 |
199 | lmic
200 | 0
201 | 0
202 | 0
203 | 0
204 |
205 | 2
206 | 2
207 | 1
208 | 0
209 | 0
210 | 0
211 | 0
212 | ..\..\lmic\aes.c
213 | aes.c
214 | 0
215 | 0
216 |
217 |
218 | 2
219 | 3
220 | 5
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\hal.h
226 | hal.h
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 1
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\lmic.c
239 | lmic.c
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 5
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.h
252 | lmic.h
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lorabase.h
265 | lorabase.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 1
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\oslmic.c
278 | oslmic.c
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 5
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.h
291 | oslmic.h
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 1
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\radio.c
304 | radio.c
305 | 0
306 | 0
307 |
308 |
309 |
310 |
311 | stm32
312 | 0
313 | 0
314 | 0
315 | 0
316 |
317 | 3
318 | 10
319 | 1
320 | 0
321 | 0
322 | 0
323 | 0
324 | ..\..\stm32\debug.c
325 | debug.c
326 | 0
327 | 0
328 |
329 |
330 | 3
331 | 11
332 | 5
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.h
338 | debug.h
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 1
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\hal.c
351 | hal.c
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hw.c
364 | hw.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 5
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.h
377 | hw.h
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 2
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\startup_stm32l1xx_md_keil.s
390 | startup_stm32l1xx_md_keil.s
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 5
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\stm32l1xx.h
403 | stm32l1xx.h
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 1
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\system_stm32l1xx.c
416 | system_stm32l1xx.c
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 5
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.h
429 | system_stm32l1xx.h
430 | 0
431 | 0
432 |
433 |
434 |
435 |
436 | ::CMSIS
437 | 0
438 | 0
439 | 0
440 | 1
441 |
442 |
443 |
444 |
--------------------------------------------------------------------------------
/examples/projects.gmk:
--------------------------------------------------------------------------------
1 | # SELECT TOOLCHAIN GNU/IAR/KEIL
2 | TOOLCHAIN = keil
3 |
4 | # EDIT CONFIGURATIONS BELOW TO REFLECT COMPILER INSTALL DIR AND CMSIS INCLUDE DIR
5 |
6 | # IAR TOOLCHAIN
7 | ifeq (${TOOLCHAIN}, iar)
8 | IAR = C:/PROGRA~2/IARSYS~1/EMBEDD~1.5_2/arm
9 | INC = ${IAR}/CMSIS/Include
10 | CC = ${IAR}/bin/iccarm
11 | AS = ${IAR}/bin/iasmarm
12 | LN = ${IAR}/bin/ilinkarm
13 | HEX = ${IAR}/bin/ielftool --ihex
14 |
15 | CCOPTS = --cpu=Cortex-M3 --endian=little --diag_suppress Pa050,Pa089,Pe066
16 | ASOPTS = --cpu Cortex-M3
17 | LNOPTS = --semihosting --config ${IAR}/config/linker/ST/STM32L152xB.icf
18 | endif
19 |
20 | # KEIL TOOLCHAIN
21 | ifeq (${TOOLCHAIN}, keil)
22 | KEIL = C:/Keil_v5
23 | INC = ${KEIL}/ARM/Pack/ARM/CMSIS/4.1.0/CMSIS/Include
24 | CC = ${KEIL}/ARM/ARMCC/bin/armcc.exe
25 | AS = ${KEIL}/ARM/ARMCC/bin/armasm.exe
26 | LN = ${KEIL}/ARM/ARMCC/bin/armlink.exe
27 | HEX = ${KEIL}/ARM/ARMCC/bin/fromelf.exe --i32
28 |
29 | CCOPTS = --cpu=Cortex-M3 -c --c99 -D__MICROLIB --apcs=interwork --split_sections
30 | ASOPTS = --cpu Cortex-M3 --pd "__MICROLIB SETA 1"
31 | LNOPTS = --library_type=microlib --ro-base 0x08000000 --entry 0x08000000 --rw-base 0x20000000 --entry Reset_Handler --first __Vectors --strict --summary_stderr --info summarysizes
32 | HEXOPTS = --output
33 | endif
34 |
35 | # GNU TOOLCHAIN
36 | ifeq (${TOOLCHAIN}, gnu)
37 | GNU = C:/Software/gcc-arm-none-eabi
38 | CC = ${GNU}/bin/arm-none-eabi-gcc
39 | AS = ${GNU}/bin/arm-none-eabi-as
40 | LN = ${GNU}/bin/arm-none-eabi-gcc
41 | HEX = ${GNU}/bin/arm-none-eabi-objcopy -O ihex
42 |
43 | CMSIS_INC = ../../stm32/CMSIS/Include
44 | define CMSIS_MSG
45 | ERROR: CMSIS Library missing: $(CMSIS_INC)
46 | ## CMSIS: Cortex Microcontroller Software Interface Standard
47 | ## CMSIS Library can be obtained from the STM32L1xx standard peripherals library
48 | ## Download URL: www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257913
49 | endef
50 | ifeq (,$(wildcard $(CMSIS_INC)))
51 | $(error $(CMSIS_MSG))
52 | endif
53 |
54 | LINKER_SCRIPT = ../../stm32/STM32L152VB_FLASH.ld
55 | define LNK_SCRIPT_MSG
56 | ERROR: Linker Script missing: $(LINKER_SCRIPT)
57 | ## Linker Script can be obtained from the STM32L1xx standard peripherals library
58 | ## Download URL: www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257913
59 | endef
60 | ifeq (,$(wildcard $(LINKER_SCRIPT)))
61 | $(error $(LNK_SCRIPT_MSG))
62 | endif
63 |
64 | INC = $(CMSIS_INC)
65 |
66 | CPU = -mcpu=cortex-m3 -mthumb
67 | CCOPTS = $(CPU) -c -std=gnu99
68 | CCOPTS += -fno-common -fmessage-length=0 -fno-builtin -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP
69 | ASOPTS = $(CPU)
70 | LNOPTS = $(CPU) -Wl,--gc-sections -T$(LINKER_SCRIPT)
71 | endif
72 |
73 | # LMIC CONFIG
74 | LMICCFG += -DSTM32L1XX_MD -DCFG_DEBUG -DCFG_eu868 -DCFG_wimod_board -DCFG_sx1272_radio -DCFG_lmic_clib
75 |
76 | LMICDIR = ../../lmic
77 | HALDIR = ../../stm32
78 | BUILDDIR = build
79 |
80 | # RULES
81 | SRCS = $(notdir $(wildcard ${LMICDIR}/*.c ${HALDIR}/*.c ${HALDIR}/*_${TOOLCHAIN}.s *.c))
82 | OBJS = $(patsubst %, ${BUILDDIR}/%.o, $(basename ${SRCS}))
83 |
84 | VPATH = ${LMICDIR} ${HALDIR} .
85 |
86 | ${BUILDDIR}/%.o: %.c | ${BUILDDIR}
87 | ${CC} ${CCOPTS} ${LMICCFG} -I${INC} -I${LMICDIR} -I${HALDIR} $< -o$@
88 |
89 | ${BUILDDIR}/%.o: %.s | ${BUILDDIR}
90 | ${AS} ${ASOPTS} -I${INC} $< -o $@
91 |
92 | ${BUILDDIR}/%.out: ${OBJS}
93 | ${LN} ${LNOPTS} -o $@ $^
94 |
95 | ${BUILDDIR}/%.hex: ${BUILDDIR}/%.out
96 | ${HEX} $< ${HEXOPTS} $@
97 |
98 | all: ${BUILDDIR}/$(notdir ${CURDIR}).hex
99 |
100 | clean:
101 | rm -rf ${BUILDDIR} Debug RTE settings *.dep *.bak *.sfr *.map *.uvguix.*
102 |
103 | ${BUILDDIR}:
104 | mkdir $@
105 |
106 | .PHONY: all clean
107 |
108 | .SECONDARY:
109 |
--------------------------------------------------------------------------------
/examples/thethingsnetwork-send-v1/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | thethingsnetwork-send-v1
3 |
--------------------------------------------------------------------------------
/examples/thethingsnetwork-send-v1/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS=-I../../lmic
2 | LDFLAGS=-lwiringPi
3 |
4 | thethingsnetwork-send-v1: thethingsnetwork-send-v1.cpp
5 | cd ../../lmic && $(MAKE)
6 | $(CC) $(CFLAGS) -o thethingsnetwork-send-v1 thethingsnetwork-send-v1.cpp ../../lmic/*.o $(LDFLAGS)
7 |
8 | all: thethingsnetwork-send-v1
9 |
10 | .PHONY: clean
11 |
12 | clean:
13 | rm -f *.o thethingsnetwork-send-v1
14 |
--------------------------------------------------------------------------------
/examples/thethingsnetwork-send-v1/thethingsnetwork-send-v1.cpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
3 | *
4 | * Permission is hereby granted, free of charge, to anyone
5 | * obtaining a copy of this document and accompanying files,
6 | * to do whatever they want with them without any restriction,
7 | * including, but not limited to, copying, modification and redistribution.
8 | * NO WARRANTY OF ANY KIND IS PROVIDED.
9 | *
10 | * This example sends a valid LoRaWAN packet with payload "Hello, world!", that
11 | * will be processed by The Things Network server.
12 | *
13 | * Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in g1,
14 | * 0.1% in g2).
15 | *
16 | * Change DEVADDR to a unique address!
17 | * See http://thethingsnetwork.org/wiki/AddressSpace
18 | *
19 | * Do not forget to define the radio type correctly in config.h, default is:
20 | * #define CFG_sx1272_radio 1
21 | * for SX1272 and RFM92, but change to:
22 | * #define CFG_sx1276_radio 1
23 | * for SX1276 and RFM95.
24 | *
25 | *******************************************************************************/
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | // LoRaWAN Application identifier (AppEUI)
35 | // Not used in this example
36 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
37 |
38 | // LoRaWAN DevEUI, unique device ID (LSBF)
39 | // Not used in this example
40 | static const u1_t DEVEUI[8] = { 0x42, 0x42, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
41 |
42 | // LoRaWAN NwkSKey, network session key
43 | // Use this key for The Things Network
44 | static const u1_t DEVKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
45 |
46 | // LoRaWAN AppSKey, application session key
47 | // Use this key to get your data decrypted by The Things Network
48 | static const u1_t ARTKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
49 |
50 | // LoRaWAN end-device address (DevAddr)
51 | // See http://thethingsnetwork.org/wiki/AddressSpace
52 | static const u4_t DEVADDR = 0xffffffff ; // <-- Change this address for every node!
53 |
54 | //////////////////////////////////////////////////
55 | // APPLICATION CALLBACKS
56 | //////////////////////////////////////////////////
57 |
58 | // provide application router ID (8 bytes, LSBF)
59 | void os_getArtEui (u1_t* buf) {
60 | memcpy(buf, APPEUI, 8);
61 | }
62 |
63 | // provide device ID (8 bytes, LSBF)
64 | void os_getDevEui (u1_t* buf) {
65 | memcpy(buf, DEVEUI, 8);
66 | }
67 |
68 | // provide device key (16 bytes)
69 | void os_getDevKey (u1_t* buf) {
70 | memcpy(buf, DEVKEY, 16);
71 | }
72 |
73 | u4_t cntr=0;
74 | u1_t mydata[] = {"Hello, world! "};
75 | static osjob_t sendjob;
76 |
77 | // Pin mapping
78 | lmic_pinmap pins = {
79 | .nss = 6,
80 | .rxtx = UNUSED_PIN, // Not connected on RFM92/RFM95
81 | .rst = 0, // Needed on RFM92/RFM95
82 | .dio = {7,4,5}
83 | };
84 |
85 | void onEvent (ev_t ev) {
86 | //debug_event(ev);
87 |
88 | switch(ev) {
89 | // scheduled data sent (optionally data received)
90 | // note: this includes the receive window!
91 | case EV_TXCOMPLETE:
92 | // use this event to keep track of actual transmissions
93 | fprintf(stdout, "Event EV_TXCOMPLETE, time: %d\n", millis() / 1000);
94 | if(LMIC.dataLen) { // data received in rx slot after tx
95 | //debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
96 | fprintf(stdout, "Data Received!\n");
97 | }
98 | break;
99 | default:
100 | break;
101 | }
102 | }
103 |
104 | static void do_send(osjob_t* j){
105 | time_t t=time(NULL);
106 | fprintf(stdout, "[%x] (%ld) %s\n", hal_ticks(), t, ctime(&t));
107 | // Show TX channel (channel numbers are local to LMIC)
108 | // Check if there is not a current TX/RX job running
109 | if (LMIC.opmode & (1 << 7)) {
110 | fprintf(stdout, "OP_TXRXPEND, not sending");
111 | } else {
112 | // Prepare upstream data transmission at the next possible time.
113 | char buf[100];
114 | sprintf(buf, "Hello world! [%d]", cntr++);
115 | int i=0;
116 | while(buf[i]) {
117 | mydata[i]=buf[i];
118 | i++;
119 | }
120 | mydata[i]='\0';
121 | LMIC_setTxData2(1, mydata, strlen(buf), 0);
122 | }
123 | // Schedule a timed job to run at the given timestamp (absolute system time)
124 | os_setTimedCallback(j, os_getTime()+sec2osticks(20), do_send);
125 |
126 | }
127 |
128 | void setup() {
129 | // LMIC init
130 | wiringPiSetup();
131 |
132 | os_init();
133 | // Reset the MAC state. Session and pending data transfers will be discarded.
134 | LMIC_reset();
135 | // Set static session parameters. Instead of dynamically establishing a session
136 | // by joining the network, precomputed session parameters are be provided.
137 | LMIC_setSession (0x1, DEVADDR, (u1_t*)DEVKEY, (u1_t*)ARTKEY);
138 | // Disable data rate adaptation
139 | LMIC_setAdrMode(0);
140 | // Disable link check validation
141 | LMIC_setLinkCheckMode(0);
142 | // Disable beacon tracking
143 | LMIC_disableTracking ();
144 | // Stop listening for downstream data (periodical reception)
145 | LMIC_stopPingable();
146 | // Set data rate and transmit power (note: txpow seems to be ignored by the library)
147 | LMIC_setDrTxpow(DR_SF7,14);
148 | //
149 | }
150 |
151 | void loop() {
152 |
153 | do_send(&sendjob);
154 |
155 | while(1) {
156 | os_runloop();
157 | // os_runloop_once();
158 | }
159 | }
160 |
161 |
162 | int main() {
163 | setup();
164 |
165 | while (1) {
166 | loop();
167 | }
168 | return 0;
169 | }
170 |
171 |
--------------------------------------------------------------------------------
/examples/thethingsnetwork-send-v1/thethingsnetwork-send-v1.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
3 | *
4 | * Permission is hereby granted, free of charge, to anyone
5 | * obtaining a copy of this document and accompanying files,
6 | * to do whatever they want with them without any restriction,
7 | * including, but not limited to, copying, modification and redistribution.
8 | * NO WARRANTY OF ANY KIND IS PROVIDED.
9 | *
10 | * This example sends a valid LoRaWAN packet with payload "Hello, world!", that
11 | * will be processed by The Things Network server.
12 | *
13 | * Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in g1,
14 | * 0.1% in g2).
15 | *
16 | * Change DEVADDR to a unique address!
17 | * See http://thethingsnetwork.org/wiki/AddressSpace
18 | *
19 | * Do not forget to define the radio type correctly in config.h, default is:
20 | * #define CFG_sx1272_radio 1
21 | * for SX1272 and RFM92, but change to:
22 | * #define CFG_sx1276_radio 1
23 | * for SX1276 and RFM95.
24 | *
25 | *******************************************************************************/
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | // LoRaWAN Application identifier (AppEUI)
32 | // Not used in this example
33 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
34 |
35 | // LoRaWAN DevEUI, unique device ID (LSBF)
36 | // Not used in this example
37 | static const u1_t DEVEUI[8] = { 0x42, 0x42, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
38 |
39 | // LoRaWAN NwkSKey, network session key
40 | // Use this key for The Things Network
41 | static const u1_t DEVKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
42 |
43 | // LoRaWAN AppSKey, application session key
44 | // Use this key to get your data decrypted by The Things Network
45 | static const u1_t ARTKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
46 |
47 | // LoRaWAN end-device address (DevAddr)
48 | // See http://thethingsnetwork.org/wiki/AddressSpace
49 | static const u4_t DEVADDR = 0x03FF0001 ; // <-- Change this address for every node!
50 |
51 | //////////////////////////////////////////////////
52 | // APPLICATION CALLBACKS
53 | //////////////////////////////////////////////////
54 |
55 | // provide application router ID (8 bytes, LSBF)
56 | void os_getArtEui (u1_t* buf) {
57 | memcpy(buf, APPEUI, 8);
58 | }
59 |
60 | // provide device ID (8 bytes, LSBF)
61 | void os_getDevEui (u1_t* buf) {
62 | memcpy(buf, DEVEUI, 8);
63 | }
64 |
65 | // provide device key (16 bytes)
66 | void os_getDevKey (u1_t* buf) {
67 | memcpy(buf, DEVKEY, 16);
68 | }
69 |
70 | uint8_t mydata[] = "Hello, world!";
71 | static osjob_t sendjob;
72 |
73 | // Pin mapping
74 | lmic_pinmap pins = {
75 | .nss = 10,
76 | .rxtx = 7, // Not connected on RFM92/RFM95
77 | .rst = 9, // Needed on RFM92/RFM95
78 | .dio = {2, 5, 6},
79 | };
80 |
81 | void onEvent (ev_t ev) {
82 | //debug_event(ev);
83 |
84 | switch(ev) {
85 | // scheduled data sent (optionally data received)
86 | // note: this includes the receive window!
87 | case EV_TXCOMPLETE:
88 | // use this event to keep track of actual transmissions
89 | Serial.print("Event EV_TXCOMPLETE, time: ");
90 | Serial.println(millis() / 1000);
91 | if(LMIC.dataLen) { // data received in rx slot after tx
92 | //debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
93 | Serial.println("Data Received!");
94 | }
95 | break;
96 | default:
97 | break;
98 | }
99 | }
100 |
101 | void do_send(osjob_t* j){
102 | Serial.print("Time: ");
103 | Serial.println(millis() / 1000);
104 | // Show TX channel (channel numbers are local to LMIC)
105 | Serial.print("Send, txCnhl: ");
106 | Serial.println(LMIC.txChnl);
107 | Serial.print("Opmode check: ");
108 | // Check if there is not a current TX/RX job running
109 | if (LMIC.opmode & (1 << 7)) {
110 | Serial.println("OP_TXRXPEND, not sending");
111 | } else {
112 | Serial.println("ok");
113 | // Prepare upstream data transmission at the next possible time.
114 | LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
115 | }
116 | // Schedule a timed job to run at the given timestamp (absolute system time)
117 | os_setTimedCallback(j, os_getTime()+sec2osticks(120), do_send);
118 |
119 | }
120 |
121 | void setup() {
122 | Serial.begin(9600);
123 | Serial.println("Starting");
124 | // LMIC init
125 | os_init();
126 | // Reset the MAC state. Session and pending data transfers will be discarded.
127 | LMIC_reset();
128 | // Set static session parameters. Instead of dynamically establishing a session
129 | // by joining the network, precomputed session parameters are be provided.
130 | LMIC_setSession (0x1, DEVADDR, (uint8_t*)DEVKEY, (uint8_t*)ARTKEY);
131 | // Disable data rate adaptation
132 | LMIC_setAdrMode(0);
133 | // Disable link check validation
134 | LMIC_setLinkCheckMode(0);
135 | // Disable beacon tracking
136 | LMIC_disableTracking ();
137 | // Stop listening for downstream data (periodical reception)
138 | LMIC_stopPingable();
139 | // Set data rate and transmit power (note: txpow seems to be ignored by the library)
140 | LMIC_setDrTxpow(DR_SF7,14);
141 | //
142 | Serial.flush();
143 | }
144 |
145 | void loop() {
146 |
147 | do_send(&sendjob);
148 |
149 | while(1) {
150 | os_runloop_once();
151 | }
152 | }
153 |
154 |
--------------------------------------------------------------------------------
/examples/transmit/main.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 | #include "debug.h"
14 |
15 | //////////////////////////////////////////////////
16 | // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
17 | //////////////////////////////////////////////////
18 |
19 | // application router ID (LSBF)
20 | static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
21 |
22 | // unique device ID (LSBF)
23 | static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
24 |
25 | // device-specific AES key (derived from device EUI)
26 | static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
27 |
28 |
29 | //////////////////////////////////////////////////
30 | // APPLICATION CALLBACKS
31 | //////////////////////////////////////////////////
32 |
33 | // provide application router ID (8 bytes, LSBF)
34 | void os_getArtEui (u1_t* buf) {
35 | memcpy(buf, APPEUI, 8);
36 | }
37 |
38 | // provide device ID (8 bytes, LSBF)
39 | void os_getDevEui (u1_t* buf) {
40 | memcpy(buf, DEVEUI, 8);
41 | }
42 |
43 | // provide device key (16 bytes)
44 | void os_getDevKey (u1_t* buf) {
45 | memcpy(buf, DEVKEY, 16);
46 | }
47 |
48 |
49 | //////////////////////////////////////////////////
50 | // MAIN - INITIALIZATION AND STARTUP
51 | //////////////////////////////////////////////////
52 |
53 | // initial job
54 | static void initfunc (osjob_t* j) {
55 | // reset MAC state
56 | LMIC_reset();
57 | // start joining
58 | LMIC_startJoining();
59 | // init done - onEvent() callback will be invoked...
60 | }
61 |
62 |
63 | // application entry point
64 | int main () {
65 | osjob_t initjob;
66 |
67 | // initialize runtime env
68 | os_init();
69 | // initialize debug library
70 | debug_init();
71 | // setup initial job
72 | os_setCallback(&initjob, initfunc);
73 | // execute scheduled jobs and events
74 | os_runloop();
75 | // (not reached)
76 | return 0;
77 | }
78 |
79 |
80 | //////////////////////////////////////////////////
81 | // LMIC EVENT CALLBACK
82 | //////////////////////////////////////////////////
83 |
84 | void onEvent (ev_t ev) {
85 | debug_event(ev);
86 |
87 | switch(ev) {
88 |
89 | // network joined, session established
90 | case EV_JOINED:
91 | debug_val("netid = ", LMIC.netid);
92 | goto tx;
93 |
94 | // scheduled data sent (optionally data received)
95 | case EV_TXCOMPLETE:
96 | if(LMIC.dataLen) { // data received in rx slot after tx
97 | debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
98 | }
99 | tx:
100 | // immediately prepare next transmission
101 | LMIC.frame[0] = LMIC.snr;
102 | // schedule transmission (port 1, datalen 1, no ack requested)
103 | LMIC_setTxData2(1, LMIC.frame, 1, 0);
104 | // (will be sent as soon as duty cycle permits)
105 | break;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/examples/transmit/makefile:
--------------------------------------------------------------------------------
1 | include ../projects.gmk
2 |
3 |
--------------------------------------------------------------------------------
/examples/transmit/transmit.eww:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $WS_DIR$\transmit.ewp
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/transmit/transmit.uvoptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.0
5 |
6 | ### uVision Project, (C) Keil Software
7 |
8 |
9 | *.c
10 | *.s*; *.src; *.a*
11 | *.obj
12 | *.lib
13 | *.txt; *.h; *.inc
14 | *.plm
15 | *.cpp
16 |
17 |
18 |
19 | 0
20 | 0
21 |
22 |
23 |
24 | Target 1
25 | 0x4
26 | ARM-ADS
27 |
28 | 12000000
29 |
30 | 1
31 | 1
32 | 0
33 | 1
34 |
35 |
36 | 1
37 | 65535
38 | 0
39 | 0
40 | 0
41 |
42 |
43 | 79
44 | 66
45 | 8
46 | .\
47 |
48 |
49 | 1
50 | 1
51 | 1
52 | 0
53 | 1
54 | 1
55 | 0
56 | 1
57 | 0
58 | 0
59 | 0
60 | 0
61 |
62 |
63 | 1
64 | 1
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 0
71 | 0
72 |
73 |
74 | 1
75 | 0
76 | 1
77 |
78 | 0
79 |
80 | 0
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 0
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 0
101 | 0
102 | 11
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | STLink\ST-LINKIII-KEIL_SWO.dll
114 |
115 |
116 |
117 | 0
118 | DLGTARM
119 | (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)
120 |
121 |
122 | 0
123 | ARMDBGFLAGS
124 |
125 |
126 |
127 | 0
128 | DLGUARM
129 | (105=-1,-1,-1,-1,0)
130 |
131 |
132 | 0
133 | ST-LINKIII-KEIL_SWO
134 | -U-O2254 -O10446 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128.FLM -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM)
135 |
136 |
137 | 0
138 | UL2CM3
139 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L1xx_128 -FS08000000 -FL08000 -FP0($$Device:STM32L151C6$Flash\STM32L1xx_128.FLM))
140 |
141 |
142 |
143 |
144 | 0
145 |
146 |
147 | 0
148 | 0
149 | 1
150 | 0
151 | 0
152 | 0
153 | 0
154 | 1
155 | 0
156 | 0
157 | 0
158 | 0
159 | 0
160 | 0
161 | 0
162 | 0
163 | 0
164 | 0
165 | 0
166 | 0
167 | 0
168 | 0
169 | 0
170 | 0
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | app
179 | 0
180 | 0
181 | 0
182 | 0
183 |
184 | 1
185 | 1
186 | 1
187 | 0
188 | 0
189 | 0
190 | 0
191 | .\main.c
192 | main.c
193 | 0
194 | 0
195 |
196 |
197 |
198 |
199 | lmic
200 | 0
201 | 0
202 | 0
203 | 0
204 |
205 | 2
206 | 2
207 | 1
208 | 0
209 | 0
210 | 0
211 | 0
212 | ..\..\lmic\aes.c
213 | aes.c
214 | 0
215 | 0
216 |
217 |
218 | 2
219 | 3
220 | 5
221 | 0
222 | 0
223 | 0
224 | 0
225 | ..\..\lmic\hal.h
226 | hal.h
227 | 0
228 | 0
229 |
230 |
231 | 2
232 | 4
233 | 1
234 | 0
235 | 0
236 | 0
237 | 0
238 | ..\..\lmic\lmic.c
239 | lmic.c
240 | 0
241 | 0
242 |
243 |
244 | 2
245 | 5
246 | 5
247 | 0
248 | 0
249 | 0
250 | 0
251 | ..\..\lmic\lmic.h
252 | lmic.h
253 | 0
254 | 0
255 |
256 |
257 | 2
258 | 6
259 | 5
260 | 0
261 | 0
262 | 0
263 | 0
264 | ..\..\lmic\lorabase.h
265 | lorabase.h
266 | 0
267 | 0
268 |
269 |
270 | 2
271 | 7
272 | 1
273 | 0
274 | 0
275 | 0
276 | 0
277 | ..\..\lmic\oslmic.c
278 | oslmic.c
279 | 0
280 | 0
281 |
282 |
283 | 2
284 | 8
285 | 5
286 | 0
287 | 0
288 | 0
289 | 0
290 | ..\..\lmic\oslmic.h
291 | oslmic.h
292 | 0
293 | 0
294 |
295 |
296 | 2
297 | 9
298 | 1
299 | 0
300 | 0
301 | 0
302 | 0
303 | ..\..\lmic\radio.c
304 | radio.c
305 | 0
306 | 0
307 |
308 |
309 |
310 |
311 | stm32
312 | 0
313 | 0
314 | 0
315 | 0
316 |
317 | 3
318 | 10
319 | 1
320 | 0
321 | 0
322 | 0
323 | 0
324 | ..\..\stm32\debug.c
325 | debug.c
326 | 0
327 | 0
328 |
329 |
330 | 3
331 | 11
332 | 5
333 | 0
334 | 0
335 | 0
336 | 0
337 | ..\..\stm32\debug.h
338 | debug.h
339 | 0
340 | 0
341 |
342 |
343 | 3
344 | 12
345 | 1
346 | 0
347 | 0
348 | 0
349 | 0
350 | ..\..\stm32\hal.c
351 | hal.c
352 | 0
353 | 0
354 |
355 |
356 | 3
357 | 13
358 | 1
359 | 0
360 | 0
361 | 0
362 | 0
363 | ..\..\stm32\hw.c
364 | hw.c
365 | 0
366 | 0
367 |
368 |
369 | 3
370 | 14
371 | 5
372 | 0
373 | 0
374 | 0
375 | 0
376 | ..\..\stm32\hw.h
377 | hw.h
378 | 0
379 | 0
380 |
381 |
382 | 3
383 | 15
384 | 2
385 | 0
386 | 0
387 | 0
388 | 0
389 | ..\..\stm32\startup_stm32l1xx_md_keil.s
390 | startup_stm32l1xx_md_keil.s
391 | 0
392 | 0
393 |
394 |
395 | 3
396 | 16
397 | 5
398 | 0
399 | 0
400 | 0
401 | 0
402 | ..\..\stm32\stm32l1xx.h
403 | stm32l1xx.h
404 | 0
405 | 0
406 |
407 |
408 | 3
409 | 17
410 | 1
411 | 0
412 | 0
413 | 0
414 | 0
415 | ..\..\stm32\system_stm32l1xx.c
416 | system_stm32l1xx.c
417 | 0
418 | 0
419 |
420 |
421 | 3
422 | 18
423 | 5
424 | 0
425 | 0
426 | 0
427 | 0
428 | ..\..\stm32\system_stm32l1xx.h
429 | system_stm32l1xx.h
430 | 0
431 | 0
432 |
433 |
434 |
435 |
436 | ::CMSIS
437 | 0
438 | 0
439 | 0
440 | 1
441 |
442 |
443 |
444 |
--------------------------------------------------------------------------------
/lmic/Makefile:
--------------------------------------------------------------------------------
1 | CC=g++
2 |
3 | DEPS=config.h hal.h lmic.h local_hal.h lorabase.h oslmic.h
4 | OBJ=aes.o hal.o lmic.o oslmic.o radio.o
5 |
6 | %.o: %.c $(DEPS)
7 | $(CC) -c -o $@ $< $(CFLAGS)
8 |
9 | all: $(OBJ)
10 |
11 | .PHONY: clean
12 |
13 | clean:
14 | rm *.o
15 |
--------------------------------------------------------------------------------
/lmic/config.h:
--------------------------------------------------------------------------------
1 | #ifndef _config_h_
2 | #define _config_h_
3 |
4 | #define CFG_sx1276_radio 1
5 | #define CFG_eu868 1
6 |
7 | #define US_PER_OSTICK 50
8 | //#define OSTICKS_PER_SEC 20000
9 |
10 | #endif
11 |
12 |
--------------------------------------------------------------------------------
/lmic/hal.c:
--------------------------------------------------------------------------------
1 | #include "config.h"
2 | #include "oslmic.h"
3 | #include "hal.h"
4 | #include "local_hal.h"
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 |
12 | int fd;
13 |
14 | // -----------------------------------------------------------------------------
15 | // I/O
16 |
17 | static void hal_io_init () {
18 | wiringPiSetup();
19 | pinMode(pins.nss, OUTPUT);
20 | pinMode(pins.rxtx, OUTPUT);
21 | pinMode(pins.rst, OUTPUT);
22 | pinMode(pins.dio[0], INPUT);
23 | pinMode(pins.dio[1], INPUT);
24 | pinMode(pins.dio[2], INPUT);
25 | }
26 |
27 | // val == 1 => tx 1
28 | void hal_pin_rxtx (u1_t val) {
29 | digitalWrite(pins.rxtx, val);
30 | }
31 |
32 | // set radio RST pin to given value (or keep floating!)
33 | void hal_pin_rst (u1_t val) {
34 | if(val == 0 || val == 1) { // drive pin
35 | pinMode(pins.rst, OUTPUT);
36 | digitalWrite(pins.rst, val);
37 | // digitalWrite(0, val==0?LOW:HIGH);
38 | } else { // keep pin floating
39 | pinMode(pins.rst, INPUT);
40 | }
41 | }
42 |
43 | static bool dio_states[NUM_DIO] = {0};
44 |
45 | static void hal_io_check() {
46 | u1_t i;
47 | for (i = 0; i < NUM_DIO; ++i) {
48 | if (dio_states[i] != digitalRead(pins.dio[i])) {
49 | dio_states[i] = !dio_states[i];
50 | if (dio_states[i]) {
51 | radio_irq_handler(i);
52 | }
53 | }
54 | }
55 | }
56 |
57 | // -----------------------------------------------------------------------------
58 | // SPI
59 | //
60 | static int spifd;
61 |
62 | static void hal_spi_init () {
63 | spifd = wiringPiSPISetup(0, 10000000);
64 | }
65 |
66 | void hal_pin_nss (u1_t val) {
67 | digitalWrite(pins.nss, val);
68 | }
69 |
70 | // perform SPI transaction with radio
71 | u1_t hal_spi (u1_t out) {
72 | u1_t res = wiringPiSPIDataRW(0, &out, 1);
73 | return out;
74 | }
75 |
76 |
77 | // -----------------------------------------------------------------------------
78 | // TIME
79 |
80 | struct timespec tstart={0,0};
81 | static void hal_time_init () {
82 | int res=clock_gettime(CLOCK_MONOTONIC_RAW, &tstart);
83 | tstart.tv_nsec=0; //Makes difference calculations in hal_ticks() easier
84 | }
85 |
86 | u4_t hal_ticks (void) {
87 | // LMIC requires ticks to be 15.5μs - 100 μs long
88 | struct timespec ts;
89 | clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
90 | ts.tv_sec-=tstart.tv_sec;
91 | u8_t ticks=ts.tv_sec*(1000000/US_PER_OSTICK)+ts.tv_nsec/(1000*US_PER_OSTICK);
92 | // fprintf(stderr, "%d hal_ticks()=%d\n", sizeof(time_t), ticks);
93 | return (u4_t)ticks;
94 | }
95 |
96 | // Returns the number of ticks until time.
97 | static u4_t delta_time(u4_t time) {
98 | u4_t t = hal_ticks( );
99 | s4_t d = time - t;
100 | //fprintf(stderr, "deltatime(%d)=%d (%d)\n", time, d, t);
101 | if (d<=5) { return 0; }
102 | else {
103 | return (u4_t)d;
104 | }
105 | }
106 |
107 | void hal_waitUntil (u4_t time) {
108 | u4_t now=hal_ticks();
109 | u4_t delta = delta_time(time);
110 | //fprintf(stderr, "waitUntil(%d) delta=%d\n", time, delta);
111 | s4_t t=time-now;
112 | if (delta==0) return;
113 | if (t>0) {
114 | //fprintf(stderr, "delay(%d)\n", t*US_PER_OSTICK/1000);
115 | delay(t*US_PER_OSTICK/1000);
116 | return;
117 | }
118 | }
119 |
120 | // check and rewind for target time
121 | u1_t hal_checkTimer (u4_t time) {
122 | // No need to schedule wakeup, since we're not sleeping
123 | // fprintf(stderr, "hal_checkTimer(%d):%d (%d)\n", time, delta_time(time), hal_ticks());
124 | return delta_time(time) <= 0;
125 | }
126 |
127 | static u8_t irqlevel = 0;
128 |
129 | void IRQ0(void) {
130 | // fprintf(stderr, "IRQ0 %d\n", irqlevel);
131 | if (irqlevel==0) {
132 | radio_irq_handler(0);
133 | return;
134 | }
135 | }
136 |
137 | void IRQ1(void) {
138 | if (irqlevel==0){
139 | radio_irq_handler(1);
140 | }
141 | }
142 |
143 | void IRQ2(void) {
144 | if (irqlevel==0){
145 | radio_irq_handler(2);
146 | }
147 | }
148 |
149 | void hal_disableIRQs () {
150 | // cli();
151 | irqlevel++;
152 | // fprintf(stderr, "disableIRQs(%d)\n", irqlevel);
153 | }
154 |
155 | void hal_enableIRQs () {
156 | if(--irqlevel == 0) {
157 | // fprintf(stderr, "enableIRQs(%d)\n", irqlevel);
158 | // sei();
159 |
160 | // Instead of using proper interrupts (which are a bit tricky
161 | // and/or not available on all pins on AVR), just poll the pin
162 | // values. Since os_runloop disables and re-enables interrupts,
163 | // putting this here makes sure we check at least once every
164 | // loop.
165 | //
166 | // As an additional bonus, this prevents the can of worms that
167 | // we would otherwise get for running SPI transfers inside ISRs
168 | hal_io_check();
169 | }
170 | }
171 |
172 | void hal_sleep () {
173 | // Not implemented
174 | }
175 |
176 | void hal_failed (const char *file, u2_t line) {
177 | fprintf(stderr, "FAILURE\n");
178 | fprintf(stderr, "%s:%d\n",file, line);
179 | hal_disableIRQs();
180 | while(1);
181 | }
182 |
183 | void hal_init() {
184 | fd=wiringPiSetup();
185 | hal_io_init();
186 | // configure radio SPI
187 | hal_spi_init();
188 | // configure timer and interrupt handler
189 | hal_time_init();
190 | wiringPiISR(pins.dio[0], INT_EDGE_RISING, IRQ0);
191 | wiringPiISR(pins.dio[1], INT_EDGE_RISING, IRQ1);
192 | wiringPiISR(pins.dio[2], INT_EDGE_RISING, IRQ2);
193 |
194 |
195 | }
196 |
197 |
--------------------------------------------------------------------------------
/lmic/hal.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #ifndef _hal_hpp_
13 | #define _hal_hpp_
14 |
15 | /*
16 | * initialize hardware (IO, SPI, TIMER, IRQ).
17 | */
18 | void hal_init (void);
19 |
20 | /*
21 | * drive radio NSS pin (0=low, 1=high).
22 | */
23 | void hal_pin_nss (u1_t val);
24 |
25 | /*
26 | * drive radio RX/TX pins (0=rx, 1=tx).
27 | */
28 | void hal_pin_rxtx (u1_t val);
29 |
30 | /*
31 | * control radio RST pin (0=low, 1=high, 2=floating)
32 | */
33 | void hal_pin_rst (u1_t val);
34 |
35 | /*
36 | * perform 8-bit SPI transaction with radio.
37 | * - write given byte 'outval'
38 | * - read byte and return value
39 | */
40 | u1_t hal_spi (u1_t outval);
41 |
42 | /*
43 | * disable all CPU interrupts.
44 | * - might be invoked nested
45 | * - will be followed by matching call to hal_enableIRQs()
46 | */
47 | void hal_disableIRQs (void);
48 |
49 | /*
50 | * enable CPU interrupts.
51 | */
52 | void hal_enableIRQs (void);
53 |
54 | /*
55 | * put system and CPU in low-power mode, sleep until interrupt.
56 | */
57 | void hal_sleep (void);
58 |
59 | /*
60 | * return 32-bit system time in ticks.
61 | */
62 | u4_t hal_ticks (void);
63 |
64 | /*
65 | * busy-wait until specified timestamp (in ticks) is reached.
66 | */
67 | void hal_waitUntil (u4_t time);
68 |
69 | /*
70 | * check and rewind timer for target time.
71 | * - return 1 if target time is close
72 | * - otherwise rewind timer for target time or full period and return 0
73 | */
74 | u1_t hal_checkTimer (u4_t targettime);
75 |
76 | /*
77 | * perform fatal failure action.
78 | * - called by assertions
79 | * - action could be HALT or reboot
80 | */
81 | void hal_failed (const char *file, u2_t line);
82 |
83 | #endif // _hal_hpp_
84 |
--------------------------------------------------------------------------------
/lmic/lmic.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | //! @file
13 | //! @brief LMIC API
14 |
15 | #ifndef _lmic_h_
16 | #define _lmic_h_
17 |
18 | #include "config.h"
19 | #include "oslmic.h"
20 | #include "lorabase.h"
21 |
22 | // LMIC version
23 | #define LMIC_VERSION_MAJOR 1
24 | #define LMIC_VERSION_MINOR 5
25 | #define LMIC_VERSION_BUILD 1431528305
26 |
27 | enum { MAX_FRAME_LEN = 64 }; //!< Library cap on max frame length
28 | enum { TXCONF_ATTEMPTS = 8 }; //!< Transmit attempts for confirmed frames
29 | enum { MAX_MISSED_BCNS = 20 }; // threshold for triggering rejoin requests
30 | enum { MAX_RXSYMS = 100 }; // stop tracking beacon beyond this
31 |
32 | enum { LINK_CHECK_CONT = 12 , // continue with this after reported dead link
33 | LINK_CHECK_DEAD = 24 , // after this UP frames and no response from NWK assume link is dead
34 | LINK_CHECK_INIT = -12 , // UP frame count until we inc datarate
35 | LINK_CHECK_OFF =-128 }; // link check disabled
36 |
37 | enum { TIME_RESYNC = 6*128 }; // secs
38 | enum { TXRX_GUARD_ms = 6000 }; // msecs - don't start TX-RX transaction before beacon
39 | enum { JOIN_GUARD_ms = 9000 }; // msecs - don't start Join Req/Acc transaction before beacon
40 | enum { TXRX_BCNEXT_secs = 2 }; // secs - earliest start after beacon time
41 | enum { RETRY_PERIOD_secs = 3 }; // secs - random period for retrying a confirmed send
42 |
43 | #if defined(CFG_eu868) // EU868 spectrum ====================================================
44 |
45 | enum { MAX_CHANNELS = 16 }; //!< Max supported channels
46 | enum { MAX_BANDS = 4 };
47 |
48 | enum { LIMIT_CHANNELS = (1<<4) }; // EU868 will never have more channels
49 | //! \internal
50 | struct band_t {
51 | u2_t txcap; // duty cycle limitation: 1/txcap
52 | s1_t txpow; // maximum TX power
53 | u1_t lastchnl; // last used channel
54 | ostime_t avail; // channel is blocked until this time
55 | };
56 | TYPEDEF_xref2band_t; //!< \internal
57 |
58 | #elif defined(CFG_us915) // US915 spectrum =================================================
59 |
60 | enum { MAX_XCHANNELS = 2 }; // extra channels in RAM, channels 0-71 are immutable
61 | enum { MAX_TXPOW_125kHz = 30 };
62 |
63 | #endif // ==========================================================================
64 |
65 | // Keep in sync with evdefs.hpp::drChange
66 | enum { DRCHG_SET, DRCHG_NOJACC, DRCHG_NOACK, DRCHG_NOADRACK, DRCHG_NWKCMD };
67 | enum { KEEP_TXPOW = -128 };
68 |
69 |
70 | //! \internal
71 | struct rxsched_t {
72 | u1_t dr;
73 | u1_t intvExp; // 0..7
74 | u1_t slot; // runs from 0 to 128
75 | u1_t rxsyms;
76 | ostime_t rxbase;
77 | ostime_t rxtime; // start of next spot
78 | u4_t freq;
79 | };
80 | TYPEDEF_xref2rxsched_t; //!< \internal
81 |
82 |
83 | //! Parsing and tracking states of beacons.
84 | enum { BCN_NONE = 0x00, //!< No beacon received
85 | BCN_PARTIAL = 0x01, //!< Only first (common) part could be decoded (info,lat,lon invalid/previous)
86 | BCN_FULL = 0x02, //!< Full beacon decoded
87 | BCN_NODRIFT = 0x04, //!< No drift value measured yet
88 | BCN_NODDIFF = 0x08 }; //!< No differential drift measured yet
89 | //! Information about the last and previous beacons.
90 | struct bcninfo_t {
91 | ostime_t txtime; //!< Time when the beacon was sent
92 | s1_t rssi; //!< Adjusted RSSI value of last received beacon
93 | s1_t snr; //!< Scaled SNR value of last received beacon
94 | u1_t flags; //!< Last beacon reception and tracking states. See BCN_* values.
95 | u4_t time; //!< GPS time in seconds of last beacon (received or surrogate)
96 | //
97 | u1_t info; //!< Info field of last beacon (valid only if BCN_FULL set)
98 | s4_t lat; //!< Lat field of last beacon (valid only if BCN_FULL set)
99 | s4_t lon; //!< Lon field of last beacon (valid only if BCN_FULL set)
100 | };
101 |
102 | // purpose of receive window - lmic_t.rxState
103 | enum { RADIO_RST=0, RADIO_TX=1, RADIO_RX=2, RADIO_RXON=3 };
104 | // Netid values / lmic_t.netid
105 | enum { NETID_NONE=(int)~0U, NETID_MASK=(int)0xFFFFFF };
106 | // MAC operation modes (lmic_t.opmode).
107 | enum { OP_NONE = 0x0000,
108 | OP_SCAN = 0x0001, // radio scan to find a beacon
109 | OP_TRACK = 0x0002, // track my networks beacon (netid)
110 | OP_JOINING = 0x0004, // device joining in progress (blocks other activities)
111 | OP_TXDATA = 0x0008, // TX user data (buffered in pendTxData)
112 | OP_POLL = 0x0010, // send empty UP frame to ACK confirmed DN/fetch more DN data
113 | OP_REJOIN = 0x0020, // occasionally send JOIN REQUEST
114 | OP_SHUTDOWN = 0x0040, // prevent MAC from doing anything
115 | OP_TXRXPEND = 0x0080, // TX/RX transaction pending
116 | OP_RNDTX = 0x0100, // prevent TX lining up after a beacon
117 | OP_PINGINI = 0x0200, // pingable is initialized and scheduling active
118 | OP_PINGABLE = 0x0400, // we're pingable
119 | OP_NEXTCHNL = 0x0800, // find a new channel
120 | OP_LINKDEAD = 0x1000, // link was reported as dead
121 | OP_TESTMODE = 0x2000, // developer test mode
122 | };
123 | // TX-RX transaction flags - report back to user
124 | enum { TXRX_ACK = 0x80, // confirmed UP frame was acked
125 | TXRX_NACK = 0x40, // confirmed UP frame was not acked
126 | TXRX_NOPORT = 0x20, // set if a frame with a port was RXed, clr if no frame/no port
127 | TXRX_PORT = 0x10, // set if a frame with a port was RXed, LMIC.frame[LMIC.dataBeg-1] => port
128 | TXRX_DNW1 = 0x01, // received in 1st DN slot
129 | TXRX_DNW2 = 0x02, // received in 2dn DN slot
130 | TXRX_PING = 0x04 }; // received in a scheduled RX slot
131 | // Event types for event callback
132 | enum _ev_t { EV_SCAN_TIMEOUT=1, EV_BEACON_FOUND,
133 | EV_BEACON_MISSED, EV_BEACON_TRACKED, EV_JOINING,
134 | EV_JOINED, EV_RFU1, EV_JOIN_FAILED, EV_REJOIN_FAILED,
135 | EV_TXCOMPLETE, EV_LOST_TSYNC, EV_RESET,
136 | EV_RXCOMPLETE, EV_LINK_DEAD, EV_LINK_ALIVE };
137 | typedef enum _ev_t ev_t;
138 |
139 |
140 | struct lmic_t {
141 | // Radio settings TX/RX (also accessed by HAL)
142 | ostime_t txend;
143 | ostime_t rxtime;
144 | u4_t freq;
145 | s1_t rssi;
146 | s1_t snr;
147 | rps_t rps;
148 | u1_t rxsyms;
149 | u1_t dndr;
150 | s1_t txpow; // dBm
151 |
152 | osjob_t osjob;
153 |
154 | // Channel scheduling
155 | #if defined(CFG_eu868)
156 | band_t bands[MAX_BANDS];
157 | u4_t channelFreq[MAX_CHANNELS];
158 | u2_t channelDrMap[MAX_CHANNELS];
159 | u2_t channelMap;
160 | #elif defined(CFG_us915)
161 | u4_t xchFreq[MAX_XCHANNELS]; // extra channel frequencies (if device is behind a repeater)
162 | u2_t xchDrMap[MAX_XCHANNELS]; // extra channel datarate ranges ---XXX: ditto
163 | u2_t channelMap[(72+MAX_XCHANNELS+15)/16]; // enabled bits
164 | u2_t chRnd; // channel randomizer
165 | #endif
166 | u1_t txChnl; // channel for next TX
167 | u1_t globalDutyRate; // max rate: 1/2^k
168 | ostime_t globalDutyAvail; // time device can send again
169 |
170 | u4_t netid; // current network id (~0 - none)
171 | u2_t opmode;
172 | u1_t upRepeat; // configured up repeat
173 | s1_t adrTxPow; // ADR adjusted TX power
174 | u1_t datarate; // current data rate
175 | u1_t errcr; // error coding rate (used for TX only)
176 | u1_t rejoinCnt; // adjustment for rejoin datarate
177 | s2_t drift; // last measured drift
178 | s2_t lastDriftDiff;
179 | s2_t maxDriftDiff;
180 |
181 | u1_t pendTxPort;
182 | u1_t pendTxConf; // confirmed data
183 | u1_t pendTxLen; // +0x80 = confirmed
184 | u1_t pendTxData[MAX_LEN_PAYLOAD];
185 |
186 | u2_t devNonce; // last generated nonce
187 | u1_t nwkKey[16]; // network session key
188 | u1_t artKey[16]; // application router session key
189 | devaddr_t devaddr;
190 | u4_t seqnoDn; // device level down stream seqno
191 | u4_t seqnoUp;
192 |
193 | u1_t dnConf; // dn frame confirm pending: LORA::FCT_ACK or 0
194 | s1_t adrAckReq; // counter until we reset data rate (0=off)
195 | u1_t adrChanged;
196 |
197 | u1_t margin;
198 | bit_t ladrAns; // link adr adapt answer pending
199 | bit_t devsAns; // device status answer pending
200 | u1_t adrEnabled;
201 | u1_t moreData; // NWK has more data pending
202 | bit_t dutyCapAns; // have to ACK duty cycle settings
203 | u1_t snchAns; // answer set new channel
204 | // 2nd RX window (after up stream)
205 | u1_t dn2Dr;
206 | u4_t dn2Freq;
207 | u1_t dn2Ans; // 0=no answer pend, 0x80+ACKs
208 |
209 | // Class B state
210 | u1_t missedBcns; // unable to track last N beacons
211 | u1_t bcninfoTries; // how often to try (scan mode only)
212 | u1_t pingSetAns; // answer set cmd and ACK bits
213 | rxsched_t ping; // pingable setup
214 |
215 | // Public part of MAC state
216 | u1_t txCnt;
217 | u1_t txrxFlags; // transaction flags (TX-RX combo)
218 | u1_t dataBeg; // 0 or start of data (dataBeg-1 is port)
219 | u1_t dataLen; // 0 no data or zero length data, >0 byte count of data
220 | u1_t frame[MAX_LEN_FRAME];
221 |
222 | u1_t bcnChnl;
223 | u1_t bcnRxsyms; //
224 | ostime_t bcnRxtime;
225 | bcninfo_t bcninfo; // Last received beacon info
226 | };
227 | //! \var struct lmic_t LMIC
228 | //! The state of LMIC MAC layer is encapsulated in this variable.
229 | DECLARE_LMIC; //!< \internal
230 |
231 | //! Construct a bit map of allowed datarates from drlo to drhi (both included).
232 | #define DR_RANGE_MAP(drlo,drhi) (((u2_t)0xFFFF<<(drlo)) & ((u2_t)0xFFFF>>(15-(drhi))))
233 | #if defined(CFG_eu868)
234 | enum { BAND_MILLI=0, BAND_CENTI=1, BAND_DECI=2, BAND_AUX=3 };
235 | bit_t LMIC_setupBand (u1_t bandidx, s1_t txpow, u2_t txcap);
236 | #endif
237 | bit_t LMIC_setupChannel (u1_t channel, u4_t freq, u2_t drmap, s1_t band);
238 | void LMIC_disableChannel (u1_t channel);
239 |
240 | void LMIC_setDrTxpow (dr_t dr, s1_t txpow); // set default/start DR/txpow
241 | void LMIC_setAdrMode (bit_t enabled); // set ADR mode (if mobile turn off)
242 | bit_t LMIC_startJoining (void);
243 |
244 | void LMIC_shutdown (void);
245 | void LMIC_init (void);
246 | void LMIC_reset (void);
247 | void LMIC_clrTxData (void);
248 | void LMIC_setTxData (void);
249 | int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed);
250 | void LMIC_sendAlive (void);
251 |
252 | bit_t LMIC_enableTracking (u1_t tryBcnInfo);
253 | void LMIC_disableTracking (void);
254 |
255 | void LMIC_stopPingable (void);
256 | void LMIC_setPingable (u1_t intvExp);
257 | void LMIC_tryRejoin (void);
258 |
259 | void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey);
260 | void LMIC_setLinkCheckMode (bit_t enabled);
261 |
262 | // Special APIs - for development or testing
263 | // !!!See implementation for caveats!!!
264 |
265 | #endif // _lmic_h_
266 |
--------------------------------------------------------------------------------
/lmic/local_hal.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2015 Matthijs Kooijman
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * This the HAL to run LMIC on top of the Arduino environment.
9 | *******************************************************************************/
10 | #ifndef _localhal_hal_h_
11 | #define _localhal_hal_h_
12 |
13 | static const int NUM_DIO = 3;
14 |
15 | #define UNUSED_PIN 255
16 |
17 | struct lmic_pinmap {
18 | u1_t nss;
19 | u1_t rxtx;
20 | u1_t rst;
21 | u1_t dio[NUM_DIO];
22 | };
23 |
24 | // Declared here, to be defined an initialized by the application
25 | extern lmic_pinmap pins;
26 |
27 | #endif // _localhal_hal_h_
28 |
29 |
--------------------------------------------------------------------------------
/lmic/lorabase.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #ifndef _lorabase_h_
13 | #define _lorabase_h_
14 |
15 | // ================================================================================
16 | // BEG: Keep in sync with lorabase.hpp
17 | //
18 |
19 | enum _cr_t { CR_4_5=0, CR_4_6, CR_4_7, CR_4_8 };
20 | enum _sf_t { FSK=0, SF7, SF8, SF9, SF10, SF11, SF12, SFrfu };
21 | enum _bw_t { BW125=0, BW250, BW500, BWrfu };
22 | typedef u1_t cr_t;
23 | typedef u1_t sf_t;
24 | typedef u1_t bw_t;
25 | typedef u1_t dr_t;
26 | // Radio parameter set (encodes SF/BW/CR/IH/NOCRC)
27 | typedef u2_t rps_t;
28 | TYPEDEF_xref2rps_t;
29 |
30 | enum { ILLEGAL_RPS = 0xFF };
31 | enum { DR_PAGE_EU868 = 0x00 };
32 | enum { DR_PAGE_US915 = 0x10 };
33 |
34 | // Global maximum frame length
35 | enum { STD_PREAMBLE_LEN = 8 };
36 | enum { MAX_LEN_FRAME = 64 };
37 | enum { LEN_DEVNONCE = 2 };
38 | enum { LEN_ARTNONCE = 3 };
39 | enum { LEN_NETID = 3 };
40 | enum { DELAY_JACC1 = 5 }; // in secs
41 | enum { DELAY_DNW1 = 1 }; // in secs down window #1
42 | enum { DELAY_EXTDNW2 = 1 }; // in secs
43 | enum { DELAY_JACC2 = DELAY_JACC1+(int)DELAY_EXTDNW2 }; // in secs
44 | enum { DELAY_DNW2 = DELAY_DNW1 +(int)DELAY_EXTDNW2 }; // in secs down window #1
45 | enum { BCN_INTV_exp = 7 };
46 | enum { BCN_INTV_sec = 1<> 3) & 0x3); }
350 | inline rps_t setBw (rps_t params, bw_t cr) { return (rps_t)((params & ~0x18) | (cr<<3)); }
351 | inline cr_t getCr (rps_t params) { return (cr_t)((params >> 5) & 0x3); }
352 | inline rps_t setCr (rps_t params, cr_t cr) { return (rps_t)((params & ~0x60) | (cr<<5)); }
353 | inline int getNocrc(rps_t params) { return ((params >> 7) & 0x1); }
354 | inline rps_t setNocrc(rps_t params, int nocrc) { return (rps_t)((params & ~0x80) | (nocrc<<7)); }
355 | inline int getIh (rps_t params) { return ((params >> 8) & 0xFF); }
356 | inline rps_t setIh (rps_t params, int ih) { return (rps_t)((params & ~0xFF00) | (ih<<8)); }
357 | inline rps_t makeRps (sf_t sf, bw_t bw, cr_t cr, int ih, int nocrc) {
358 | return sf | (bw<<3) | (cr<<5) | (nocrc?(1<<7):0) | ((ih&0xFF)<<8);
359 | }
360 | #define MAKERPS(sf,bw,cr,ih,nocrc) ((rps_t)((sf) | ((bw)<<3) | ((cr)<<5) | ((nocrc)?(1<<7):0) | ((ih&0xFF)<<8)))
361 | // Two frames with params r1/r2 would interfere on air: same SFx + BWx
362 | inline int sameSfBw(rps_t r1, rps_t r2) { return ((r1^r2)&0x1F) == 0; }
363 |
364 | extern const u1_t _DR2RPS_CRC[];
365 | inline rps_t updr2rps (dr_t dr) { return (rps_t)_DR2RPS_CRC[dr+1]; }
366 | inline rps_t dndr2rps (dr_t dr) { return setNocrc(updr2rps(dr),1); }
367 | inline int isFasterDR (dr_t dr1, dr_t dr2) { return dr1 > dr2; }
368 | inline int isSlowerDR (dr_t dr1, dr_t dr2) { return dr1 < dr2; }
369 | inline dr_t incDR (dr_t dr) { return _DR2RPS_CRC[dr+2]==ILLEGAL_RPS ? dr : (dr_t)(dr+1); } // increase data rate
370 | inline dr_t decDR (dr_t dr) { return _DR2RPS_CRC[dr ]==ILLEGAL_RPS ? dr : (dr_t)(dr-1); } // decrease data rate
371 | inline dr_t assertDR (dr_t dr) { return _DR2RPS_CRC[dr+1]==ILLEGAL_RPS ? DR_DFLTMIN : dr; } // force into a valid DR
372 | inline bit_t validDR (dr_t dr) { return _DR2RPS_CRC[dr+1]!=ILLEGAL_RPS; } // in range
373 | inline dr_t lowerDR (dr_t dr, u1_t n) { while(n--){dr=decDR(dr);} return dr; } // decrease data rate by n steps
374 |
375 | //
376 | // BEG: Keep in sync with lorabase.hpp
377 | // ================================================================================
378 |
379 |
380 | // Convert between dBm values and power codes (MCMD_LADR_XdBm)
381 | s1_t pow2dBm (u1_t mcmd_ladr_p1);
382 | // Calculate airtime
383 | ostime_t calcAirTime (rps_t rps, u1_t plen);
384 | // Sensitivity at given SF/BW
385 | int getSensitivity (rps_t rps);
386 |
387 |
388 | #endif // _lorabase_h_
389 |
--------------------------------------------------------------------------------
/lmic/oslmic.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | #include "lmic.h"
13 |
14 | // RUNTIME STATE
15 | static struct {
16 | osjob_t* scheduledjobs;
17 | osjob_t* runnablejobs;
18 | } OS;
19 |
20 | void os_init () {
21 | memset(&OS, 0x00, sizeof(OS));
22 | hal_init();
23 | radio_init();
24 | LMIC_init();
25 | }
26 |
27 | ostime_t os_getTime () {
28 | return hal_ticks();
29 | }
30 |
31 | static u1_t unlinkjob (osjob_t** pnext, osjob_t* job) {
32 | for( ; *pnext; pnext = &((*pnext)->next)) {
33 | if(*pnext == job) { // unlink
34 | *pnext = job->next;
35 | return 1;
36 | }
37 | }
38 | return 0;
39 | }
40 |
41 | // clear scheduled job
42 | void os_clearCallback (osjob_t* job) {
43 | hal_disableIRQs();
44 | unlinkjob(&OS.scheduledjobs, job) || unlinkjob(&OS.runnablejobs, job);
45 | hal_enableIRQs();
46 | }
47 |
48 | // schedule immediately runnable job
49 | void os_setCallback (osjob_t* job, osjobcb_t cb) {
50 | osjob_t** pnext;
51 | hal_disableIRQs();
52 | // remove if job was already queued
53 | os_clearCallback(job);
54 | // fill-in job
55 | job->func = cb;
56 | job->next = NULL;
57 | // add to end of run queue
58 | for(pnext=&OS.runnablejobs; *pnext; pnext=&((*pnext)->next));
59 | *pnext = job;
60 | hal_enableIRQs();
61 | }
62 |
63 | // schedule timed job
64 | void os_setTimedCallback (osjob_t* job, ostime_t time, osjobcb_t cb) {
65 | osjob_t** pnext;
66 | hal_disableIRQs();
67 | // remove if job was already queued
68 | os_clearCallback(job);
69 | // fill-in job
70 | job->deadline = time;
71 | job->func = cb;
72 | job->next = NULL;
73 | // insert into schedule
74 | for(pnext=&OS.scheduledjobs; *pnext; pnext=&((*pnext)->next)) {
75 | if((*pnext)->deadline - time > 0) { // (cmp diff, not abs!)
76 | // enqueue before next element and stop
77 | job->next = *pnext;
78 | break;
79 | }
80 | }
81 | *pnext = job;
82 | hal_enableIRQs();
83 | }
84 |
85 | // execute jobs from timer and from run queue
86 | void os_runloop () {
87 | while(1) {
88 | osjob_t* j = NULL;
89 | hal_disableIRQs();
90 | // check for runnable jobs
91 | if(OS.runnablejobs) {
92 | j = OS.runnablejobs;
93 | OS.runnablejobs = j->next;
94 | } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
95 | j = OS.scheduledjobs;
96 | OS.scheduledjobs = j->next;
97 | } else { // nothing pending
98 | hal_sleep(); // wake by irq (timer already restarted)
99 | }
100 | hal_enableIRQs();
101 | if(j) { // run job callback
102 | j->func(j);
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/lmic/oslmic.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014-2015 IBM Corporation.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Zurich Research Lab - initial API, implementation and documentation
10 | *******************************************************************************/
11 |
12 | //! \file
13 | #ifndef _oslmic_h_
14 | #define _oslmic_h_
15 |
16 | // Dependencies required for the LoRa MAC in C to run.
17 | // These settings can be adapted to the underlying system.
18 | // You should not, however, change the lmic.[hc]
19 |
20 |
21 |
22 | //================================================================================
23 | //================================================================================
24 | // Target platform as C library
25 | typedef unsigned char bit_t;
26 | typedef unsigned char u1_t;
27 | typedef signed char s1_t;
28 | typedef unsigned short u2_t;
29 | typedef short s2_t;
30 | typedef unsigned int u4_t;
31 | typedef int s4_t;
32 | typedef unsigned long long u8_t;
33 | typedef long long s8_t;
34 | typedef unsigned int uint;
35 | typedef const char* str_t;
36 |
37 | #include
38 | #include "hal.h"
39 | #define EV(a,b,c) /**/
40 | #define DO_DEVDB(field1,field2) /**/
41 | #if !defined(CFG_noassert)
42 | #define ASSERT(cond) if(!(cond)) hal_failed(__FILE__,__LINE__)
43 | #else
44 | #define ASSERT(cond) /**/
45 | #endif
46 |
47 | #define os_clearMem(a,b) memset(a,0,b)
48 | #define os_copyMem(a,b,c) memcpy(a,b,c)
49 |
50 | typedef struct osjob_t osjob_t;
51 | typedef struct band_t band_t;
52 | typedef struct chnldef_t chnldef_t;
53 | typedef struct rxsched_t rxsched_t;
54 | typedef struct bcninfo_t bcninfo_t;
55 | typedef const u1_t* xref2cu1_t;
56 | typedef u1_t* xref2u1_t;
57 | #define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t
58 | #define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t
59 | #define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t
60 | #define TYPEDEF_xref2band_t typedef band_t* xref2band_t
61 | #define TYPEDEF_xref2osjob_t typedef osjob_t* xref2osjob_t
62 |
63 | #define SIZEOFEXPR(x) sizeof(x)
64 |
65 | #define ON_LMIC_EVENT(ev) onEvent(ev)
66 | #define DECL_ON_LMIC_EVENT void onEvent(ev_t e)
67 |
68 | extern u4_t AESAUX[];
69 | extern u4_t AESKEY[];
70 | #define AESkey ((u1_t*)AESKEY)
71 | #define AESaux ((u1_t*)AESAUX)
72 | #define FUNC_ADDR(func) (&(func))
73 |
74 | u1_t radio_rand1 (void);
75 | #define os_getRndU1() radio_rand1()
76 |
77 | #define DEFINE_LMIC struct lmic_t LMIC
78 | #define DECLARE_LMIC extern struct lmic_t LMIC
79 |
80 | void radio_init (void);
81 | void radio_irq_handler (u1_t dio);
82 | void os_init (void);
83 | void os_runloop (void);
84 |
85 | //================================================================================
86 |
87 |
88 | #ifndef RX_RAMPUP
89 | #define RX_RAMPUP (us2osticks(2000))
90 | #endif
91 | #ifndef TX_RAMPUP
92 | #define TX_RAMPUP (us2osticks(2000))
93 | #endif
94 |
95 | #ifndef OSTICKS_PER_SEC
96 | //#define OSTICKS_PER_SEC 32768
97 | #define OSTICKS_PER_SEC 20000
98 | #elif OSTICKS_PER_SEC < 10000 || OSTICKS_PER_SEC > 64516
99 | #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long.
100 | #endif
101 |
102 | typedef s4_t ostime_t;
103 |
104 | #if !HAS_ostick_conv
105 | #define us2osticks(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC) / 1000000))
106 | #define ms2osticks(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC) / 1000))
107 | #define sec2osticks(sec) ((ostime_t)( (s8_t)(sec) * OSTICKS_PER_SEC))
108 | #define osticks2ms(os) ((s4_t)(((os)*(s8_t)1000 ) / OSTICKS_PER_SEC))
109 | #define osticks2us(os) ((s4_t)(((os)*(s8_t)1000000 ) / OSTICKS_PER_SEC))
110 | // Special versions
111 | #define us2osticksCeil(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 999999) / 1000000))
112 | #define us2osticksRound(us) ((ostime_t)( ((s8_t)(us) * OSTICKS_PER_SEC + 500000) / 1000000))
113 | #define ms2osticksCeil(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 999) / 1000))
114 | #define ms2osticksRound(ms) ((ostime_t)( ((s8_t)(ms) * OSTICKS_PER_SEC + 500) / 1000))
115 | #endif
116 |
117 |
118 | struct osjob_t; // fwd decl.
119 | typedef void (*osjobcb_t) (struct osjob_t*);
120 | struct osjob_t {
121 | struct osjob_t* next;
122 | ostime_t deadline;
123 | osjobcb_t func;
124 | };
125 | TYPEDEF_xref2osjob_t;
126 |
127 |
128 | #ifndef HAS_os_calls
129 |
130 | #ifndef os_getDevKey
131 | void os_getDevKey (xref2u1_t buf);
132 | #endif
133 | #ifndef os_getArtEui
134 | void os_getArtEui (xref2u1_t buf);
135 | #endif
136 | #ifndef os_getDevEui
137 | void os_getDevEui (xref2u1_t buf);
138 | #endif
139 | #ifndef os_setCallback
140 | void os_setCallback (xref2osjob_t job, osjobcb_t cb);
141 | #endif
142 | #ifndef os_setTimedCallback
143 | void os_setTimedCallback (xref2osjob_t job, ostime_t time, osjobcb_t cb);
144 | #endif
145 | #ifndef os_clearCallback
146 | void os_clearCallback (xref2osjob_t job);
147 | #endif
148 | #ifndef os_getTime
149 | ostime_t os_getTime (void);
150 | #endif
151 | #ifndef os_getTimeSecs
152 | uint os_getTimeSecs (void);
153 | #endif
154 | #ifndef os_radio
155 | void os_radio (u1_t mode);
156 | #endif
157 | #ifndef os_getBattLevel
158 | u1_t os_getBattLevel (void);
159 | #endif
160 |
161 | #ifndef os_rlsbf4
162 | //! Read 32-bit quantity from given pointer in little endian byte order.
163 | u4_t os_rlsbf4 (xref2cu1_t buf);
164 | #endif
165 | #ifndef os_wlsbf4
166 | //! Write 32-bit quntity into buffer in little endian byte order.
167 | void os_wlsbf4 (xref2u1_t buf, u4_t value);
168 | #endif
169 | #ifndef os_rmsbf4
170 | //! Read 32-bit quantity from given pointer in big endian byte order.
171 | u4_t os_rmsbf4 (xref2cu1_t buf);
172 | #endif
173 | #ifndef os_wmsbf4
174 | //! Write 32-bit quntity into buffer in big endian byte order.
175 | void os_wmsbf4 (xref2u1_t buf, u4_t value);
176 | #endif
177 | #ifndef os_rlsbf2
178 | //! Read 16-bit quantity from given pointer in little endian byte order.
179 | u2_t os_rlsbf2 (xref2cu1_t buf);
180 | #endif
181 | #ifndef os_wlsbf2
182 | //! Write 16-bit quntity into buffer in little endian byte order.
183 | void os_wlsbf2 (xref2u1_t buf, u2_t value);
184 | #endif
185 |
186 | //! Get random number (default impl for u2_t).
187 | #ifndef os_getRndU2
188 | #define os_getRndU2() ((u2_t)((os_getRndU1()<<8)|os_getRndU1()))
189 | #endif
190 | #ifndef os_crc16
191 | u2_t os_crc16 (xref2u1_t d, uint len);
192 | #endif
193 |
194 | #endif // !HAS_os_calls
195 |
196 | // ======================================================================
197 | // AES support
198 | // !!Keep in sync with lorabase.hpp!!
199 |
200 | #ifndef AES_ENC // if AES_ENC is defined as macro all other values must be too
201 | #define AES_ENC 0x00
202 | #define AES_DEC 0x01
203 | #define AES_MIC 0x02
204 | #define AES_CTR 0x04
205 | #define AES_MICNOAUX 0x08
206 | #endif
207 | #ifndef AESkey // if AESkey is defined as macro all other values must be too
208 | extern xref2u1_t AESkey;
209 | extern xref2u1_t AESaux;
210 | #endif
211 | #ifndef os_aes
212 | u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len);
213 | #endif
214 |
215 |
216 |
217 | #endif // _oslmic_h_
218 |
--------------------------------------------------------------------------------