LMiC adapted to work with SX1272MB2xAS LoRa shield.
Fork of LMiC by
Diff: lmic.cpp
- Revision:
- 6:eed5fd627a2b
- Parent:
- 5:464c1f2d6cbb
- Child:
- 7:29058a7ccf23
--- a/lmic.cpp Tue Feb 23 15:34:27 2016 +0000 +++ b/lmic.cpp Thu Feb 25 15:39:28 2016 +0000 @@ -58,34 +58,44 @@ #if !defined(HAS_os_calls) #if !defined(os_rlsbf2) -u2_t os_rlsbf2 (xref2cu1_t buf) { +u2_t os_rlsbf2 (xref2cu1_t buf) +{ + debug("LMIC os_rlsbf2 enter\r\n"); return (u2_t)(buf[0] | (buf[1]<<8)); } #endif #if !defined(os_rlsbf4) -u4_t os_rlsbf4 (xref2cu1_t buf) { +u4_t os_rlsbf4 (xref2cu1_t buf) +{ + debug("LMIC os_rlsbf4 enter\r\n"); return (u4_t)(buf[0] | (buf[1]<<8) | ((u4_t)buf[2]<<16) | ((u4_t)buf[3]<<24)); } #endif #if !defined(os_rmsbf4) -u4_t os_rmsbf4 (xref2cu1_t buf) { +u4_t os_rmsbf4 (xref2cu1_t buf) +{ + debug("LMIC os_rmsbf4 enter\r\n"); return (u4_t)(buf[3] | (buf[2]<<8) | ((u4_t)buf[1]<<16) | ((u4_t)buf[0]<<24)); } #endif #if !defined(os_wlsbf2) -void os_wlsbf2 (xref2u1_t buf, u2_t v) { +void os_wlsbf2 (xref2u1_t buf, u2_t v) +{ + debug("LMIC os_wlsbf2 enter\r\n"); buf[0] = v; buf[1] = v>>8; } #endif #if !defined(os_wlsbf4) -void os_wlsbf4 (xref2u1_t buf, u4_t v) { +void os_wlsbf4 (xref2u1_t buf, u4_t v) +{ + debug("LMIC os_wlsbf4 enter\r\n"); buf[0] = v; buf[1] = v>>8; buf[2] = v>>16; @@ -94,7 +104,9 @@ #endif #if !defined(os_wmsbf4) -void os_wmsbf4 (xref2u1_t buf, u4_t v) { +void os_wmsbf4 (xref2u1_t buf, u4_t v) +{ + debug("LMIC os_wmsbf4 enter\r\n"); buf[3] = v; buf[2] = v>>8; buf[1] = v>>16; @@ -103,19 +115,25 @@ #endif #if !defined(os_getBattLevel) -u1_t os_getBattLevel (void) { +u1_t os_getBattLevel (void) +{ + debug("LMIC os_getBattLevel enter\r\n"); return MCMD_DEVS_BATT_NOINFO; } #endif #if !defined(os_crc16) // New CRC-16 CCITT(XMODEM) checksum for beacons: -u2_t os_crc16 (xref2u1_t data, uint len) { +u2_t os_crc16 (xref2u1_t data, uint len) +{ + debug("LMIC os_crc16 enter\r\n"); u2_t remainder = 0; u2_t polynomial = 0x1021; - for( uint i = 0; i < len; i++ ) { + for( uint i = 0; i < len; i++ ) + { remainder ^= data[i] << 8; - for( u1_t bit = 8; bit > 0; bit--) { + for( u1_t bit = 8; bit > 0; bit--) + { if( (remainder & 0x8000) ) remainder = (remainder << 1) ^ polynomial; else @@ -136,7 +154,7 @@ static void micB0 (u4_t devaddr, u4_t seqno, int dndir, int len) { - debug("micB0 enter\r\n"); + debug("LMIC micB0 enter\r\n"); os_clearMem(AESaux,16); AESaux[0] = 0x49; AESaux[5] = dndir?1:0; @@ -148,7 +166,7 @@ static int aes_verifyMic (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t pdu, int len) { - debug("aes_verifyMic enter\r\n"); + debug("LMIC aes_verifyMic enter\r\n"); micB0(devaddr, seqno, dndir, len); os_copyMem(AESkey,key,16); return os_aes(AES_MIC, pdu, len) == os_rmsbf4(pdu+len); @@ -157,7 +175,7 @@ static void aes_appendMic (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t pdu, int len) { - debug("aes_appendMic enter\r\n"); + debug("LMIC aes_appendMic enter\r\n"); micB0(devaddr, seqno, dndir, len); os_copyMem(AESkey,key,16); // MSB because of internal structure of AES @@ -167,7 +185,7 @@ static void aes_appendMic0 (xref2u1_t pdu, int len) { - debug("aes_appendMic0 enter\r\n"); + debug("LMIC aes_appendMic0 enter\r\n"); os_getDevKey(AESkey); os_wmsbf4(pdu+len, os_aes(AES_MIC|AES_MICNOAUX, pdu, len)); // MSB because of internal structure of AES } @@ -175,7 +193,7 @@ static int aes_verifyMic0 (xref2u1_t pdu, int len) { - debug("aes_verifyMic0 enter\r\n"); + debug("LMIC aes_verifyMic0 enter\r\n"); os_getDevKey(AESkey); return os_aes(AES_MIC|AES_MICNOAUX, pdu, len) == os_rmsbf4(pdu+len); } @@ -183,7 +201,7 @@ static void aes_encrypt (xref2u1_t pdu, int len) { - debug("aes_encrypt enter\r\n"); + debug("LMIC aes_encrypt enter\r\n"); os_getDevKey(AESkey); os_aes(AES_ENC, pdu, len); } @@ -191,7 +209,7 @@ static void aes_cipher (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t payload, int len) { - debug("aes_cipher enter\r\n"); + debug("LMIC aes_cipher enter\r\n"); if( len <= 0 ) return; os_clearMem(AESaux, 16); @@ -206,7 +224,7 @@ static void aes_sessKeys (u2_t devnonce, xref2cu1_t artnonce, xref2u1_t nwkkey, xref2u1_t artkey) { - debug("aes_sessKeys enter\r\n"); + debug("LMIC aes_sessKeys enter\r\n"); os_clearMem(nwkkey, 16); nwkkey[0] = 0x01; os_copyMem(nwkkey+1, artnonce, LEN_ARTNONCE+LEN_NETID); @@ -292,13 +310,13 @@ int getSensitivity (rps_t rps) { - debug("getSensitivity enter\r\n"); + debug("LMIC getSensitivity enter\r\n"); return -141 + SENSITIVITY[getSf(rps)][getBw(rps)]; } ostime_t calcAirTime (rps_t rps, u1_t plen) { - debug("calcAirTime enter\r\n"); + debug("LMIC calcAirTime enter\r\n"); u1_t bw = getBw(rps); // 0,1,2 = 125,250,500kHz u1_t sf = getSf(rps); // 0=FSK, 1..6 = SF7..12 if( sf == FSK ) { @@ -415,7 +433,7 @@ static ostime_t calcRxWindow (u1_t secs, dr_t dr) { - debug("calcRxWindow enter\r\n"); + debug("LMIC calcRxWindow enter\r\n"); ostime_t rxoff, err; if( secs==0 ) { // aka 128 secs (next becaon) @@ -437,7 +455,7 @@ // Setup beacon RX parameters assuming we have an error of ms (aka +/-(ms/2)) static void calcBcnRxWindowFromMillis (u1_t ms, bit_t ini) { - debug("calcBcnRxWindowFromMillis enter\r\n"); + debug("LMIC calcBcnRxWindowFromMillis enter\r\n"); if( ini ) { LMIC.drift = 0; LMIC.maxDriftDiff = 0; @@ -453,7 +471,7 @@ // Setup scheduled RX window (ping/multicast slot) static void rxschedInit (xref2rxsched_t rxsched) { - debug("rxschedInit enter\r\n"); + debug("LMIC rxschedInit enter\r\n"); os_clearMem(AESkey,16); os_clearMem(LMIC.frame+8,8); os_wlsbf4(LMIC.frame, LMIC.bcninfo.time); @@ -472,7 +490,7 @@ static bit_t rxschedNext (xref2rxsched_t rxsched, ostime_t cando) { - debug("rxschedNext enter\r\n"); + debug("LMIC rxschedNext enter\r\n"); again: if( rxsched->rxtime - cando >= 0 ) return 1; @@ -492,7 +510,7 @@ static ostime_t rndDelay (u1_t secSpan) { - debug("rndDelay enter\r\n"); + debug("LMIC rndDelay enter\r\n"); u2_t r = os_getRndU2(); ostime_t delay = r; if( delay > OSTICKS_PER_SEC ) @@ -505,7 +523,7 @@ static void txDelay (ostime_t reftime, u1_t secSpan) { - debug("txDelay enter\r\n"); + debug("LMIC txDelay enter\r\n"); reftime += rndDelay(secSpan); if( LMIC.globalDutyRate == 0 || (reftime - LMIC.globalDutyAvail) > 0 ) { LMIC.globalDutyAvail = reftime; @@ -516,7 +534,7 @@ static void setDrJoin (u1_t reason, u1_t dr) { - debug("setDrJoin enter\r\n"); + debug("LMIC setDrJoin enter\r\n"); EV(drChange, INFO, (e_.reason = reason, e_.deveui = MAIN::CDEV->getEui(), e_.dr = dr|DR_PAGE, @@ -530,7 +548,7 @@ static void setDrTxpow (u1_t reason, u1_t dr, s1_t pow) { - debug("setDrTxpow enter\r\n"); + debug("LMIC setDrTxpow enter\r\n"); EV(drChange, INFO, (e_.reason = reason, e_.deveui = MAIN::CDEV->getEui(), e_.dr = dr|DR_PAGE, @@ -553,14 +571,14 @@ void LMIC_stopPingable (void) { - debug("LMIC_stopPingable enter\r\n"); + debug("LMIC LMIC_stopPingable enter\r\n"); LMIC.opmode &= ~(OP_PINGABLE|OP_PINGINI); } void LMIC_setPingable (u1_t intvExp) { - debug("LMIC_setPingable enter\r\n"); + debug("LMIC LMIC_setPingable enter\r\n"); // Change setting LMIC.ping.intvExp = (intvExp & 0x7); LMIC.opmode |= OP_PINGABLE; @@ -777,7 +795,7 @@ static void initDefaultChannels (void) { - debug("initDefaultChannels enter\r\n"); + debug("LMIC initDefaultChannels enter\r\n"); #ifdef CHNL_HYBRID int idx = CHNL_HYBRID >> 1; LMIC.channelMap[0] = 0x0000; @@ -805,7 +823,7 @@ static u4_t convFreq (xref2u1_t ptr) { - debug("convFreq enter\r\n"); + debug("LMIC convFreq enter\r\n"); u4_t freq = (os_rlsbf4(ptr-1) >> 8) * 100; if( freq < US915_FREQ_MIN || freq > US915_FREQ_MAX ) freq = 0; @@ -815,7 +833,7 @@ bit_t LMIC_setupChannel (u1_t chidx, u4_t freq, u2_t drmap, s1_t band) { - debug("LMIC_setupChannel enter\r\n"); + debug("LMIC LMIC_setupChannel enter\r\n"); if( chidx < 72 || chidx >= 72+MAX_XCHANNELS ) return 0; // channels 0..71 are hardwired chidx -= 72; @@ -834,7 +852,7 @@ static u1_t mapChannels (u1_t chpage, u2_t chmap) { - debug("mapChannels enter\r\n"); + debug("LMIC mapChannels enter\r\n"); if( chpage == MCMD_LADR_CHP_125ON || chpage == MCMD_LADR_CHP_125OFF ) { u2_t en125 = chpage == MCMD_LADR_CHP_125ON ? 0xFFFF : 0x0000; @@ -851,8 +869,8 @@ static void updateTx (ostime_t txbeg) { - debug("updateTx enter\r\n"); - u1_t chnl = LMIC.txChnl; + debug("LMIC updateTx enter\r\n"); + u1_t chnl = LMIC.txChnl; #ifdef JOIN_REQ_DEBUG printf("chnl%d ", chnl); #endif /* JOIN_REQ_DEBUG */ @@ -912,7 +930,7 @@ #define nextTx(now) (_nextTx(),(now)) static void _nextTx (void) { - debug("_nextTx enter\r\n"); + debug("LMIC _nextTx enter\r\n"); u1_t prev_ch = LMIC.txChnl; u1_t tries = 0; u1_t en_cnt; @@ -984,7 +1002,7 @@ static void initJoinLoop (void) { -debug("initJoinLoop enter\r\n"); +debug("LMIC initJoinLoop enter\r\n"); LMIC.chRnd = 0; #ifdef CHNL_HYBRID LMIC.joinBlockChnl = 0; @@ -1004,7 +1022,7 @@ static ostime_t nextJoinState (void) { - debug("nextJoinState enter\r\n"); + debug("LMIC nextJoinState enter\r\n"); u1_t failed = 0; if( LMIC.datarate == DR_SF8C ) { @@ -1048,14 +1066,14 @@ static void runEngineUpdate (xref2osjob_t osjob) { - debug("runEngineUpdate enter\r\n"); + debug("LMIC runEngineUpdate enter\r\n"); engineUpdate(); } static void reportEvent (ev_t ev) { - debug("reportEvent enter %d\r\n",ev); + debug("LMIC reportEvent enter %d\r\n",ev); EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV, e_.eui = MAIN::CDEV->getEui(), e_.info = ev)); @@ -1064,14 +1082,18 @@ } -static void runReset (xref2osjob_t osjob) { +static void runReset (xref2osjob_t osjob) +{ +debug("LMIC runReset enterr\n"); // Disable session LMIC_reset(); LMIC_startJoining(); reportEvent(EV_RESET); } -static void stateJustJoined (void) { +static void stateJustJoined (void) +{ +debug("LMIC stateJustJoined enter\r\n"); LMIC.seqnoDn = LMIC.seqnoUp = 0; LMIC.rejoinCnt = 0; LMIC.dnConf = LMIC.adrChanged = LMIC.ladrAns = LMIC.devsAns = 0; @@ -1092,7 +1114,9 @@ // Decode beacon - do not overwrite bcninfo unless we have a match! -static int decodeBeacon (void) { +static int decodeBeacon (void) +{ +debug("LMIC decodeBeacon enter\r\n"); ASSERT(LMIC.dataLen == LEN_BCN); // implicit header RX guarantees this xref2u1_t d = LMIC.frame; if( @@ -1128,7 +1152,9 @@ } -static bit_t decodeFrame (void) { +static bit_t decodeFrame (void) +{ +debug("LMIC decodeFrame enter\r\n"); xref2u1_t d = LMIC.frame; u1_t hdr = d[0]; u1_t ftype = hdr & HDR_FTYPE; @@ -1420,7 +1446,9 @@ // TX/RX transaction support -static void setupRx2 (void) { +static void setupRx2 (void) +{ +debug("LMIC setupRx2 enter\r\n"); LMIC.txrxFlags = TXRX_DNW2; LMIC.rps = dndr2rps(LMIC.dn2Dr); LMIC.freq = LMIC.dn2Freq; @@ -1429,13 +1457,18 @@ } -static void schedRx2 (ostime_t delay, osjobcb_t func) { +static void schedRx2 (ostime_t delay, osjobcb_t func) +{ +debug("LMIC schedRx2 enter\r\n"); // Add 1.5 symbols we need 5 out of 8. Try to sync 1.5 symbols into the preamble. - LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dn2Dr); +// LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dn2Dr); + LMIC.rxtime = LMIC.txend + delay; os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func); } -static void setupRx1 (osjobcb_t func) { +static void setupRx1 (osjobcb_t func) +{ +debug("LMIC setupRx1 enter\r\n"); LMIC.txrxFlags = TXRX_DNW1; // Turn LMIC.rps from TX over to RX LMIC.rps = setNocrc(LMIC.rps,1); @@ -1446,8 +1479,11 @@ // Called by HAL once TX complete and delivers exact end of TX time stamp in LMIC.rxtime -static void txDone (ostime_t delay, osjobcb_t func) { - if( (LMIC.opmode & (OP_TRACK|OP_PINGABLE|OP_PINGINI)) == (OP_TRACK|OP_PINGABLE) ) { +static void txDone (ostime_t delay, osjobcb_t func) +{ +debug("LMIC txDone enter\r\n"); + if( (LMIC.opmode & (OP_TRACK|OP_PINGABLE|OP_PINGINI)) == (OP_TRACK|OP_PINGABLE) ) + { rxschedInit(&LMIC.ping); // note: reuses LMIC.frame buffer! LMIC.opmode |= OP_PINGINI; } @@ -1457,14 +1493,16 @@ // Setup receive - LMIC.rxtime is preloaded with 1.5 symbols offset to tune // into the middle of the 8 symbols preamble. #if defined(CFG_eu868) - if( /* TX datarate */LMIC.rxsyms == DR_FSK ) { + if( /* TX datarate */LMIC.rxsyms == DR_FSK ) + { LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160); LMIC.rxsyms = RXLEN_FSK; } else #endif { - LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dndr); + // LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dndr); + LMIC.rxtime = LMIC.txend + delay; LMIC.rxsyms = MINRX_SYMS; } os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func); @@ -1474,18 +1512,23 @@ // ======================================== Join frames -static void onJoinFailed (xref2osjob_t osjob) { +static void onJoinFailed (xref2osjob_t osjob) +{ +debug("LMIC onJoinFailed enter\r\n"); // Notify app - must call LMIC_reset() to stop joining // otherwise join procedure continues. reportEvent(EV_JOIN_FAILED); } -static bit_t processJoinAccept (void) { +static bit_t processJoinAccept (void) +{ +debug("LMIC processJoinAccept enter\r\n"); ASSERT(LMIC.txrxFlags != TXRX_DNW1 || LMIC.dataLen != 0); ASSERT((LMIC.opmode & OP_TXRXPEND)!=0); - if( LMIC.dataLen == 0 ) { + if( LMIC.dataLen == 0 ) + { nojoinframe: /* keep retrying -- if( (LMIC.opmode & OP_JOINING) == 0 ) { ASSERT((LMIC.opmode & OP_REJOIN) != 0); @@ -1579,31 +1622,41 @@ } -static void processRx2Jacc (xref2osjob_t osjob) { +static void processRx2Jacc (xref2osjob_t osjob) +{ +debug("LMIC processRx2Jacc enter\r\n"); if( LMIC.dataLen == 0 ) LMIC.txrxFlags = 0; // nothing in 1st/2nd DN slot processJoinAccept(); } -static void setupRx2Jacc (xref2osjob_t osjob) { +static void setupRx2Jacc (xref2osjob_t osjob) +{ +debug("LMIC setupRx2Jacc enter\r\n"); LMIC.osjob.func = FUNC_ADDR(processRx2Jacc); setupRx2(); } -static void processRx1Jacc (xref2osjob_t osjob) { +static void processRx1Jacc (xref2osjob_t osjob) +{ +debug("LMIC processRx1Jacc enter\r\n"); if( LMIC.dataLen == 0 || !processJoinAccept() ) schedRx2(DELAY_JACC2_osticks, FUNC_ADDR(setupRx2Jacc)); } -static void setupRx1Jacc (xref2osjob_t osjob) { +static void setupRx1Jacc (xref2osjob_t osjob) +{ +debug("LMIC setupRx1Jacc enter\r\n"); setupRx1(FUNC_ADDR(processRx1Jacc)); } -static void jreqDone (xref2osjob_t osjob) { +static void jreqDone (xref2osjob_t osjob) +{ +debug("LMIC jreqDone enter\r\n"); txDone(DELAY_JACC1_osticks, FUNC_ADDR(setupRx1Jacc)); } @@ -1612,11 +1665,15 @@ // Fwd decl. static bit_t processDnData(void); -static void processRx2DnDataDelay (xref2osjob_t osjob) { +static void processRx2DnDataDelay (xref2osjob_t osjob) +{ +debug("LMIC processRx2DnDataDelay enter\r\n"); processDnData(); } -static void processRx2DnData (xref2osjob_t osjob) { +static void processRx2DnData (xref2osjob_t osjob) +{ +debug("LMIC processRx2DnData enter\r\n"); if( LMIC.dataLen == 0 ) { LMIC.txrxFlags = 0; // nothing in 1st/2nd DN slot // Delay callback processing to avoid up TX while gateway is txing our missed frame! @@ -1630,31 +1687,41 @@ } -static void setupRx2DnData (xref2osjob_t osjob) { +static void setupRx2DnData (xref2osjob_t osjob) +{ +debug("LMIC setupRx2DnData enter\r\n"); LMIC.osjob.func = FUNC_ADDR(processRx2DnData); setupRx2(); } -static void processRx1DnData (xref2osjob_t osjob) { +static void processRx1DnData (xref2osjob_t osjob) +{ +debug("LMIC processRx1DnData enter\r\n"); if( LMIC.dataLen == 0 || !processDnData() ) schedRx2(DELAY_DNW2_osticks, FUNC_ADDR(setupRx2DnData)); } -static void setupRx1DnData (xref2osjob_t osjob) { +static void setupRx1DnData (xref2osjob_t osjob) +{ +debug("LMIC setupRx1DnData enter\r\n"); setupRx1(FUNC_ADDR(processRx1DnData)); } -static void updataDone (xref2osjob_t osjob) { +static void updataDone (xref2osjob_t osjob) +{ +debug("LMIC updataDone enter\r\n"); txDone(DELAY_DNW1_osticks, FUNC_ADDR(setupRx1DnData)); } // ======================================== -static void buildDataFrame (void) { +static void buildDataFrame (void) +{ +debug("LMIC buildDataFrame enter\r\n"); bit_t txdata = ((LMIC.opmode & (OP_TXDATA|OP_POLL)) != OP_POLL); u1_t dlen = txdata ? LMIC.pendTxLen : 0; @@ -1772,7 +1839,9 @@ // Callback from HAL during scan mode or when job timer expires. -static void onBcnRx (xref2osjob_t job) { +static void onBcnRx (xref2osjob_t job) +{ +debug("LMIC onBcnRx enter\r\n"); // If we arrive via job timer make sure to put radio to rest. os_radio(RADIO_RST); os_clearCallback(&LMIC.osjob); @@ -1804,7 +1873,9 @@ // This mode ends with events: EV_SCAN_TIMEOUT/EV_SCAN_BEACON // Implicitely cancels any pending TX/RX transaction. // Also cancels an onpoing joining procedure. -static void startScan (void) { +static void startScan (void) +{ +debug("LMIC startScan enter\r\n"); ASSERT(LMIC.devaddr!=0 && (LMIC.opmode & OP_JOINING)==0); if( (LMIC.opmode & OP_SHUTDOWN) != 0 ) return; @@ -1818,7 +1889,9 @@ } -bit_t LMIC_enableTracking (u1_t tryBcnInfo) { +bit_t LMIC_enableTracking (u1_t tryBcnInfo) +{ +debug("LMIC LMIC_enableTracking enter\r\n"); if( (LMIC.opmode & (OP_SCAN|OP_TRACK|OP_SHUTDOWN)) != 0 ) return 0; // already in progress or failed to enable // If BCN info requested from NWK then app has to take are @@ -1829,7 +1902,9 @@ } -void LMIC_disableTracking (void) { +void LMIC_disableTracking (void) +{ +debug("LMIC LMIC_disableTracking enter\r\n"); LMIC.opmode &= ~(OP_SCAN|OP_TRACK); LMIC.bcninfoTries = 0; engineUpdate(); @@ -1842,7 +1917,9 @@ // // ================================================================================ -static void buildJoinRequest (u1_t ftype) { +static void buildJoinRequest (u1_t ftype) +{ +debug("LMIC buildJoinRequest enter\r\n"); // Do not use pendTxData since we might have a pending // user level frame in there. Use RX holding area instead. xref2u1_t d = LMIC.frame; @@ -1865,13 +1942,18 @@ DO_DEVDB(LMIC.devNonce,devNonce); } -static void startJoining (xref2osjob_t osjob) { +static void startJoining (xref2osjob_t osjob) +{ +debug("LMIC startJoining enter\r\n"); reportEvent(EV_JOINING); } // Start join procedure if not already joined. -bit_t LMIC_startJoining (void) { - if( LMIC.devaddr == 0 ) { +bit_t LMIC_startJoining (void) +{ +debug("LMIC LMIC_startJoining enter\r\n"); + if( LMIC.devaddr == 0 ) + { // There should be no TX/RX going on ASSERT((LMIC.opmode & (OP_POLL|OP_TXRXPEND)) == 0); // Lift any previous duty limitation @@ -1896,7 +1978,9 @@ // // ================================================================================ -static void processPingRx (xref2osjob_t osjob) { +static void processPingRx (xref2osjob_t osjob) +{ +debug("LMIC processPingRx enter\r\n"); if( LMIC.dataLen != 0 ) { LMIC.txrxFlags = TXRX_PING; if( decodeFrame() ) { @@ -1909,7 +1993,9 @@ } -static bit_t processDnData (void) { +static bit_t processDnData (void) +{ +debug("LMIC processDnData enter\r\n"); ASSERT((LMIC.opmode & OP_TXRXPEND)!=0); if( LMIC.dataLen == 0 ) { @@ -1973,7 +2059,9 @@ } -static void processBeacon (xref2osjob_t osjob) { +static void processBeacon (xref2osjob_t osjob) +{ +debug("LMIC processBeacon enter\r\n"); ostime_t lasttx = LMIC.bcninfo.txtime; // save here - decodeBeacon might overwrite u1_t flags = LMIC.bcninfo.flags; ev_t ev; @@ -2034,20 +2122,26 @@ } -static void startRxBcn (xref2osjob_t osjob) { +static void startRxBcn (xref2osjob_t osjob) +{ +debug("LMIC startRxBcn enter\r\n"); LMIC.osjob.func = FUNC_ADDR(processBeacon); os_radio(RADIO_RX); } -static void startRxPing (xref2osjob_t osjob) { +static void startRxPing (xref2osjob_t osjob) +{ +debug("LMIC startRxPing enter\r\n"); LMIC.osjob.func = FUNC_ADDR(processPingRx); os_radio(RADIO_RX); } // Decide what to do next for the MAC layer of a device -static void engineUpdate (void) { +static void engineUpdate (void) +{ +debug("LMIC engineUpdate enter\r\n"); // Check for ongoing state: scan or TX/RX transaction if( (LMIC.opmode & (OP_SCAN|OP_TXRXPEND|OP_SHUTDOWN)) != 0 ) return; @@ -2193,25 +2287,33 @@ } -void LMIC_setAdrMode (bit_t enabled) { +void LMIC_setAdrMode (bit_t enabled) +{ +debug("LMIC LMIC_setAdrMode enter\r\n"); LMIC.adrEnabled = enabled ? FCT_ADREN : 0; } // Should we have/need an ext. API like this? -void LMIC_setDrTxpow (dr_t dr, s1_t txpow) { +void LMIC_setDrTxpow (dr_t dr, s1_t txpow) +{ +debug("LMIC LMIC_setDrTxpow enter\r\n"); setDrTxpow(DRCHG_SET, dr, txpow); } -void LMIC_shutdown (void) { +void LMIC_shutdown (void) +{ +debug("LMIC LMIC_shutdown enter\r\n"); os_clearCallback(&LMIC.osjob); os_radio(RADIO_RST); LMIC.opmode |= OP_SHUTDOWN; } -void LMIC_reset (void) { +void LMIC_reset (void) +{ +debug("LMIC LMIC_reset enter\r\n"); EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV, e_.eui = MAIN::CDEV->getEui(), e_.info = EV_RESET)); @@ -2248,7 +2350,9 @@ } -void LMIC_clrTxData (void) { +void LMIC_clrTxData (void) +{ +debug("LMIC LMIC_clrTxData enter\r\n"); LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND|OP_POLL); LMIC.pendTxLen = 0; if( (LMIC.opmode & (OP_JOINING|OP_SCAN)) != 0 ) // do not interfere with JOINING @@ -2259,7 +2363,9 @@ } -void LMIC_setTxData (void) { +void LMIC_setTxData (void) +{ +debug("LMIC LMIC_setTxData enter\r\n"); LMIC.opmode |= OP_TXDATA; if( (LMIC.opmode & OP_JOINING) == 0 ) LMIC.txCnt = 0; // cancel any ongoing TX/RX retries @@ -2268,7 +2374,9 @@ // -int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) { +int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) +{ +debug("LMIC LMIC_setTxData2 enter\r\n"); if( dlen > SIZEOFEXPR(LMIC.pendTxData) ) return -2; if( data != (xref2u1_t)0 ) @@ -2282,14 +2390,18 @@ // Send a payload-less message to signal device is alive -void LMIC_sendAlive (void) { +void LMIC_sendAlive (void) +{ +debug("LMIC LMIC_sendAlive enter\r\n"); LMIC.opmode |= OP_POLL; engineUpdate(); } // Check if other networks are around. -void LMIC_tryRejoin (void) { +void LMIC_tryRejoin (void) +{ +debug("LMIC LMIC_tryRejoin enter\r\n"); LMIC.opmode |= OP_REJOIN; engineUpdate(); } @@ -2308,7 +2420,9 @@ //! If NULL the caller has copied the key into `LMIC.nwkKey` before. //! \param artKey the 16 byte application router session key used for message confidentiality. //! If NULL the caller has copied the key into `LMIC.artKey` before. -void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey) { +void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey) +{ +debug("LMIC LMIC_setSession enter\r\n"); LMIC.netid = netid; LMIC.devaddr = devaddr; if( nwkKey != (xref2u1_t)0 ) @@ -2333,7 +2447,9 @@ // This mode can be disabled and no connectivity prove (ADRACKREQ) is requested // nor is the datarate changed. // This must be called only if a session is established (e.g. after EV_JOINED) -void LMIC_setLinkCheckMode (bit_t enabled) { +void LMIC_setLinkCheckMode (bit_t enabled) +{ +debug("LMIC LMIC_setLinkCheckMode enter\r\n"); LMIC.adrChanged = 0; LMIC.adrAckReq = enabled ? LINK_CHECK_INIT : LINK_CHECK_OFF; }