LMiC adapted to work with SX1272MB2xAS LoRa shield.
Fork of LMiC by
Diff: oslmic.cpp
- Revision:
- 8:5879e83f632a
- Parent:
- 5:464c1f2d6cbb
diff -r 29058a7ccf23 -r 5879e83f632a oslmic.cpp --- a/oslmic.cpp Thu Feb 25 21:28:23 2016 +0000 +++ b/oslmic.cpp Mon Apr 02 12:04:59 2018 +0000 @@ -7,7 +7,19 @@ * * Contributors: * IBM Zurich Research Lab - initial API, implementation and documentation - *******************************************************************************/ + * + * ///////////////////////////////////////////////////////////////////////////// + * + * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring + * device for agriculture using LoRaWAN technology. + * + * Date of issued copy: 25 January 2018 + * + * Modifications: + * - No external modifications of the existing "AS IT IS" software. + * - Comment out debug messages of each function for more clear + * debugging procedure. + ******************************************************************************/ #include "lmic.h" #include "debug.h" @@ -21,23 +33,23 @@ void os_init () { - debug("os_init enter\r\n"); + //debug("os_init enter\r\n"); memset(&OS, 0x00, sizeof(OS)); hal_init(); radio_init(); LMIC_init(); - debug("os_init exit\r\n"); + //debug("os_init exit\r\n"); } ostime_t os_getTime () { - debug("os_getTime enter %d\r\n",hal_ticks()); + //debug("os_getTime enter %d\r\n",hal_ticks()); return hal_ticks(); } static u1_t unlinkjob (osjob_t** pnext, osjob_t* job) { - debug("unlinkjob enter\r\n"); + //debug("unlinkjob enter\r\n"); for( ; *pnext; pnext = &((*pnext)->next)) { if(*pnext == job) { // unlink *pnext = job->next; @@ -50,7 +62,7 @@ // clear scheduled job void os_clearCallback (osjob_t* job) { - debug("os_clearCallback enter\r\n"); + //debug("os_clearCallback enter\r\n"); hal_disableIRQs(); unlinkjob(&OS.scheduledjobs, job) || unlinkjob(&OS.runnablejobs, job); hal_enableIRQs(); @@ -59,7 +71,7 @@ // schedule immediately runnable job void os_setCallback (osjob_t* job, osjobcb_t cb) { - debug("os_setCallback enter\r\n"); + //debug("os_setCallback enter\r\n"); osjob_t** pnext; hal_disableIRQs(); // remove if job was already queued @@ -76,7 +88,7 @@ // schedule timed job void os_setTimedCallback (osjob_t* job, ostime_t time, osjobcb_t cb) { - debug("os_setTimedCallback enter %d\r\n",time); + //debug("os_setTimedCallback enter %d\r\n",time); osjob_t** pnext; hal_disableIRQs(); // remove if job was already queued @@ -100,7 +112,7 @@ // execute jobs from timer and from run queue void os_runloop () { - debug("os_runloop enter\r\n"); + debug_str("os_runloop enter\r\n"); while(1) { osjob_t* j = NULL; hal_disableIRQs(); @@ -120,3 +132,27 @@ } } } + +void os_runloop_once() { + + bool has_deadline = false; + osjob_t* j = NULL; + hal_disableIRQs(); + + // 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 + j = OS.scheduledjobs; + OS.scheduledjobs = j->next; + has_deadline = true; + } else { // nothing pending + hal_sleep(); // wake by irq (timer already restarted) + } + hal_enableIRQs(); + if(j) { // run job callback + // printf("%lu: Running job %p, cb %p, deadline %lu\r\n", os_getTime(), j, j->func, has_deadline ? j->deadline : 0); + j->func(j); + } +}