Fix ADR channel mask handling

Dependents:  

Fork of lmic_MOTE_L152RC by canuck lehead

Committer:
dkjendal
Date:
Thu Aug 25 16:53:47 2016 +0000
Revision:
14:f8a4a16a7df8
Parent:
9:83ae7f34e88c
Hybrid mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dudmuck 0:f2716e543d97 1 /*******************************************************************************
dudmuck 0:f2716e543d97 2 * Copyright (c) 2014-2015 IBM Corporation.
dudmuck 0:f2716e543d97 3 * All rights reserved. This program and the accompanying materials
dudmuck 0:f2716e543d97 4 * are made available under the terms of the Eclipse Public License v1.0
dudmuck 0:f2716e543d97 5 * which accompanies this distribution, and is available at
dudmuck 0:f2716e543d97 6 * http://www.eclipse.org/legal/epl-v10.html
dudmuck 0:f2716e543d97 7 *
dudmuck 0:f2716e543d97 8 * Contributors:
dudmuck 0:f2716e543d97 9 * IBM Zurich Research Lab - initial API, implementation and documentation
dudmuck 0:f2716e543d97 10 *******************************************************************************/
dudmuck 0:f2716e543d97 11
dudmuck 0:f2716e543d97 12 #include "lmic.h"
dudmuck 0:f2716e543d97 13
dudmuck 0:f2716e543d97 14 // RUNTIME STATE
dudmuck 0:f2716e543d97 15 static struct {
dudmuck 0:f2716e543d97 16 osjob_t* scheduledjobs;
dudmuck 0:f2716e543d97 17 osjob_t* runnablejobs;
dudmuck 0:f2716e543d97 18 } OS;
dudmuck 0:f2716e543d97 19
dudmuck 0:f2716e543d97 20 void os_init () {
dudmuck 0:f2716e543d97 21 memset(&OS, 0x00, sizeof(OS));
dudmuck 0:f2716e543d97 22 hal_init();
dudmuck 0:f2716e543d97 23 radio_init();
dudmuck 0:f2716e543d97 24 LMIC_init();
dudmuck 0:f2716e543d97 25 }
dudmuck 0:f2716e543d97 26
dudmuck 0:f2716e543d97 27 ostime_t os_getTime () {
dudmuck 0:f2716e543d97 28 return hal_ticks();
dudmuck 0:f2716e543d97 29 }
dudmuck 0:f2716e543d97 30
dudmuck 0:f2716e543d97 31 static u1_t unlinkjob (osjob_t** pnext, osjob_t* job) {
dudmuck 0:f2716e543d97 32 for( ; *pnext; pnext = &((*pnext)->next)) {
dudmuck 0:f2716e543d97 33 if(*pnext == job) { // unlink
dudmuck 0:f2716e543d97 34 *pnext = job->next;
dudmuck 0:f2716e543d97 35 return 1;
dudmuck 0:f2716e543d97 36 }
dudmuck 0:f2716e543d97 37 }
dudmuck 0:f2716e543d97 38 return 0;
dudmuck 0:f2716e543d97 39 }
dudmuck 0:f2716e543d97 40
dudmuck 0:f2716e543d97 41 // clear scheduled job
dudmuck 0:f2716e543d97 42 void os_clearCallback (osjob_t* job) {
dudmuck 0:f2716e543d97 43 hal_disableIRQs();
dudmuck 0:f2716e543d97 44 unlinkjob(&OS.scheduledjobs, job) || unlinkjob(&OS.runnablejobs, job);
dudmuck 0:f2716e543d97 45 hal_enableIRQs();
dudmuck 0:f2716e543d97 46 }
dudmuck 0:f2716e543d97 47
dudmuck 0:f2716e543d97 48 // schedule immediately runnable job
dudmuck 0:f2716e543d97 49 void os_setCallback (osjob_t* job, osjobcb_t cb) {
dudmuck 0:f2716e543d97 50 osjob_t** pnext;
dudmuck 0:f2716e543d97 51 hal_disableIRQs();
dudmuck 0:f2716e543d97 52 // remove if job was already queued
dudmuck 0:f2716e543d97 53 os_clearCallback(job);
dudmuck 0:f2716e543d97 54 // fill-in job
dudmuck 0:f2716e543d97 55 job->func = cb;
dudmuck 0:f2716e543d97 56 job->next = NULL;
dudmuck 0:f2716e543d97 57 // add to end of run queue
dudmuck 0:f2716e543d97 58 for(pnext=&OS.runnablejobs; *pnext; pnext=&((*pnext)->next));
dudmuck 0:f2716e543d97 59 *pnext = job;
dudmuck 0:f2716e543d97 60 hal_enableIRQs();
dudmuck 0:f2716e543d97 61 }
dudmuck 0:f2716e543d97 62
dudmuck 0:f2716e543d97 63 // schedule timed job
dudmuck 0:f2716e543d97 64 void os_setTimedCallback (osjob_t* job, ostime_t time, osjobcb_t cb) {
dudmuck 0:f2716e543d97 65 osjob_t** pnext;
dudmuck 0:f2716e543d97 66 hal_disableIRQs();
dudmuck 0:f2716e543d97 67 // remove if job was already queued
dudmuck 0:f2716e543d97 68 os_clearCallback(job);
dudmuck 0:f2716e543d97 69 // fill-in job
dudmuck 0:f2716e543d97 70 job->deadline = time;
dudmuck 0:f2716e543d97 71 job->func = cb;
dudmuck 0:f2716e543d97 72 job->next = NULL;
dudmuck 0:f2716e543d97 73 // insert into schedule
dudmuck 0:f2716e543d97 74 for(pnext=&OS.scheduledjobs; *pnext; pnext=&((*pnext)->next)) {
dudmuck 0:f2716e543d97 75 if((*pnext)->deadline - time > 0) { // (cmp diff, not abs!)
dudmuck 0:f2716e543d97 76 // enqueue before next element and stop
dudmuck 0:f2716e543d97 77 job->next = *pnext;
dudmuck 0:f2716e543d97 78 break;
dudmuck 0:f2716e543d97 79 }
dudmuck 0:f2716e543d97 80 }
dudmuck 0:f2716e543d97 81 *pnext = job;
dudmuck 0:f2716e543d97 82 hal_enableIRQs();
dudmuck 0:f2716e543d97 83 }
dudmuck 0:f2716e543d97 84
dudmuck 0:f2716e543d97 85 // execute jobs from timer and from run queue
dudmuck 0:f2716e543d97 86 void os_runloop () {
dudmuck 0:f2716e543d97 87 while(1) {
dudmuck 0:f2716e543d97 88 osjob_t* j = NULL;
dudmuck 0:f2716e543d97 89 hal_disableIRQs();
dudmuck 0:f2716e543d97 90 // check for runnable jobs
dudmuck 0:f2716e543d97 91 if(OS.runnablejobs) {
dudmuck 0:f2716e543d97 92 j = OS.runnablejobs;
dudmuck 0:f2716e543d97 93 OS.runnablejobs = j->next;
dudmuck 0:f2716e543d97 94 } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
dudmuck 0:f2716e543d97 95 j = OS.scheduledjobs;
dudmuck 0:f2716e543d97 96 OS.scheduledjobs = j->next;
dudmuck 0:f2716e543d97 97 } else { // nothing pending
dudmuck 0:f2716e543d97 98 hal_sleep(); // wake by irq (timer already restarted)
dudmuck 0:f2716e543d97 99 }
dudmuck 0:f2716e543d97 100 hal_enableIRQs();
dudmuck 0:f2716e543d97 101 if(j) { // run job callback
dudmuck 0:f2716e543d97 102 j->func(j);
dudmuck 0:f2716e543d97 103 }
dudmuck 0:f2716e543d97 104 }
dudmuck 0:f2716e543d97 105 }
dudmuck 9:83ae7f34e88c 106