LMiC LoRa Semtech + Nucleo

Dependents:   LoRaWAN-lmic-app

Fork of LMiC by Pascal Nysten

Revision:
1:d3b7bde3995c
Parent:
0:62d1edcc13d1
diff -r 62d1edcc13d1 -r d3b7bde3995c oslmic.cpp
--- a/oslmic.cpp	Thu Jan 22 12:50:49 2015 +0000
+++ b/oslmic.cpp	Tue Mar 31 13:36:56 2015 +0000
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 IBM Corporation.
+ * Copyright (c) 2014-2015 IBM Corporation.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -17,14 +17,14 @@
     osjob_t* runnablejobs;
 } OS;
 
-void os_init (void) {
+void os_init () {
     memset(&OS, 0x00, sizeof(OS));
     hal_init();
     radio_init();
     LMIC_init();
 }
 
-ostime_t os_getTime (void) {
+ostime_t os_getTime () {
     return hal_ticks();
 }
 
@@ -72,7 +72,7 @@
     job->next = NULL;
     // insert into schedule
     for(pnext=&OS.scheduledjobs; *pnext; pnext=&((*pnext)->next)) {
-        if(time < (*pnext)->deadline) {
+        if((*pnext)->deadline - time > 0) { // (cmp diff, not abs!)
             // enqueue before next element and stop
             job->next = *pnext;
             break;
@@ -83,15 +83,15 @@
 }
 
 // execute jobs from timer and from run queue
-void os_runloop (void) {
+void os_runloop () {
     while(1) {
         osjob_t* j = NULL;
         hal_disableIRQs();
-	// check for runnable jobs
-	if(OS.runnablejobs) {
+        // check for runnable jobs
+        if(OS.runnablejobs) {
             j = OS.runnablejobs;
             OS.runnablejobs = j->next;
-	} else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
+        } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
             j = OS.scheduledjobs;
             OS.scheduledjobs = j->next;
         } else { // nothing pending
@@ -99,9 +99,7 @@
         }
         hal_enableIRQs();
         if(j) { // run job callback
-            if(j->func) {
-                j->func(j);
-            }
+            j->func(j);
         }
     }
 }