Senet-ized LMIC for MOTE_L152RC

Fork of lmic_MOTE_L152RC by Semtech

Files at this revision

API Documentation at this revision

Comitter:
dudmuck
Date:
Mon Nov 16 23:52:45 2015 +0000
Parent:
8:0faa1bb768b5
Child:
10:6c0830baf10f
Commit message:
correct join behavior after link dead (joining again)

Changed in this revision

TARGET_MOTE_L152RC/debug.cpp Show annotated file Show diff for this revision Revisions of this file
TARGET_MOTE_L152RC/hal.cpp Show annotated file Show diff for this revision Revisions of this file
lmic.cpp Show annotated file Show diff for this revision Revisions of this file
oslmic.cpp Show annotated file Show diff for this revision Revisions of this file
oslmic.h Show annotated file Show diff for this revision Revisions of this file
radio.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TARGET_MOTE_L152RC/debug.cpp	Wed Oct 21 01:03:34 2015 +0000
+++ b/TARGET_MOTE_L152RC/debug.cpp	Mon Nov 16 23:52:45 2015 +0000
@@ -70,7 +70,12 @@
 
 void debug_done()
 {
+    volatile int i;
+    
     /* block until last bit sent out debug UART */
     while (!(USART2->SR & UART_FLAG_TC))
         __NOP();
+        
+    for (i = 0; i < 0x200; i++)
+        __nop();
 }
--- a/TARGET_MOTE_L152RC/hal.cpp	Wed Oct 21 01:03:34 2015 +0000
+++ b/TARGET_MOTE_L152RC/hal.cpp	Mon Nov 16 23:52:45 2015 +0000
@@ -235,8 +235,9 @@
     //printf("%x cr:%06x isr:%04x %d\r\n", RtcHandle.Instance->WUTR, RtcHandle.Instance->CR, RtcHandle.Instance->ISR, deep_sleep);
     //debug_done();
 
-    if (deep_sleep)
+    if (deep_sleep) {
         debug_done();   // wait here if debug still printing
+    }
 
     if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&RtcHandle, RTC_FLAG_WUTF) == 0) {
         // set gpio for sleep
--- a/lmic.cpp	Wed Oct 21 01:03:34 2015 +0000
+++ b/lmic.cpp	Mon Nov 16 23:52:45 2015 +0000
@@ -11,7 +11,7 @@
 
 //! \file
 #include "lmic.h"
-#include "debug.h"  // tmp wbr
+#include "debug.h"
 
 #if !defined(MINRX_SYMS)
 #define MINRX_SYMS 5
@@ -802,6 +802,13 @@
 #endif /* JOIN_REQ_DEBUG */  
     if( chnl < 64 ) {
         LMIC.freq = US915_125kHz_UPFBASE + chnl*US915_125kHz_UPFSTEP;
+
+        if (LMIC.opmode & OP_JOINING) {
+            /* use max allowed power for joining */
+            if (LMIC.txpow <  LMIC.txpow_limit)
+                LMIC.txpow = LMIC.txpow_limit;
+        }
+
 #ifdef JOIN_REQ_DEBUG
     printf("%d (125khz)\r\n", LMIC.freq);
 #endif /* JOIN_REQ_DEBUG */    
@@ -919,9 +926,15 @@
 
 static void initJoinLoop (void) {
     LMIC.chRnd = 0;
+#ifdef CHNL_HYBRID
+    LMIC.joinBlockChnl = 0;
+    LMIC.joinBlock = CHNL_HYBRID;
+    LMIC.txChnl = LMIC.joinBlock << 3;
+#else
     LMIC.txChnl = 0;
     LMIC.joinBlockChnl = 0;
     LMIC.joinBlock = 0;
+#endif
     LMIC.datarate = DR_SF10;
     LMIC.adrTxPow = LMIC.txpow_limit;
     ASSERT((LMIC.opmode & OP_NEXTCHNL)==0);
@@ -1162,8 +1175,9 @@
 
     // We heard from network
     LMIC.adrChanged = LMIC.rejoinCnt = 0;
-    if( LMIC.adrAckReq != LINK_CHECK_OFF )
+    if( LMIC.adrAckReq != LINK_CHECK_OFF ) {
         LMIC.adrAckReq = LINK_CHECK_INIT;
+    }
 
     // Process OPTS
     int m = LMIC.rssi - RSSI_OFF - getSensitivity(LMIC.rps);
@@ -1427,7 +1441,7 @@
 
     if( LMIC.dataLen == 0 ) {
       nojoinframe:
-        if( (LMIC.opmode & OP_JOINING) == 0 ) {
+        /* keep retrying re-joining after failed attempt -- if( (LMIC.opmode & OP_JOINING) == 0 ) {
             ASSERT((LMIC.opmode & OP_REJOIN) != 0);
             // REJOIN attempt for roaming
             LMIC.opmode &= ~(OP_REJOIN|OP_TXRXPEND);
@@ -1435,7 +1449,7 @@
                 LMIC.rejoinCnt++;
             reportEvent(EV_REJOIN_FAILED);
             return 1;
-        }
+        }*/
         LMIC.opmode &= ~OP_TXRXPEND;
         ostime_t delay = nextJoinState();
         EV(devCond, DEBUG, (e_.reason = EV::devCond_t::NO_JACC,
@@ -1461,7 +1475,6 @@
                            e_.info   = dlen < 4 ? 0 : mic,
                            e_.info2  = hdr + (dlen<<8)));
       badframe:
-        printf("pja badframe dlen:%d, hdr:%02x\r\n", dlen, hdr);
         if( (LMIC.txrxFlags & TXRX_DNW1) != 0 )
             return 0;
         goto nojoinframe;
@@ -1689,7 +1702,6 @@
 
     if( LMIC.txCnt == 0 ) {
         LMIC.seqnoUp += 1;
-        //printf("seqnoUp inc %d\r\n", LMIC.seqnoUp);
         DO_DEVDB(LMIC.seqnoUp,seqnoUp);
     } else {
         EV(devCond, INFO, (e_.reason = EV::devCond_t::RE_TX,
@@ -1891,8 +1903,9 @@
             // Nothing received - implies no port
             LMIC.txrxFlags = TXRX_NOPORT;
         }
-        if( LMIC.adrAckReq != LINK_CHECK_OFF )
+        if( LMIC.adrAckReq != LINK_CHECK_OFF ) {
             LMIC.adrAckReq += 1;
+        }
         LMIC.dataBeg = LMIC.dataLen = 0;
       txcomplete:
         LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND);
@@ -2011,8 +2024,9 @@
 // Decide what to do next for the MAC layer of a device
 static void engineUpdate (void) {
     // Check for ongoing state: scan or TX/RX transaction
-    if( (LMIC.opmode & (OP_SCAN|OP_TXRXPEND|OP_SHUTDOWN)) != 0 ) 
+    if( (LMIC.opmode & (OP_SCAN|OP_TXRXPEND|OP_SHUTDOWN)) != 0 ) {
         return;
+    }
 
     if( LMIC.devaddr == 0 && (LMIC.opmode & OP_JOINING) == 0 ) {
         LMIC_startJoining();
@@ -2028,7 +2042,7 @@
         ASSERT( now + RX_RAMPUP - LMIC.bcnRxtime <= 0 );
         rxtime = LMIC.bcnRxtime - RX_RAMPUP;
     }
-
+    
     if( (LMIC.opmode & (OP_JOINING|OP_REJOIN|OP_TXDATA|OP_POLL)) != 0 ) {
         // Need to TX some data...
         // Assuming txChnl points to channel which first becomes available again.
@@ -2062,7 +2076,8 @@
                 u1_t ftype;
                 if( (LMIC.opmode & OP_REJOIN) != 0 ) {
                     txdr = lowerDR(txdr, LMIC.rejoinCnt);
-                    ftype = HDR_FTYPE_REJOIN;
+                    //ftype = HDR_FTYPE_REJOIN;
+                    ftype = HDR_FTYPE_JREQ;
                 } else {
                     ftype = HDR_FTYPE_JREQ;
                 }
--- a/oslmic.cpp	Wed Oct 21 01:03:34 2015 +0000
+++ b/oslmic.cpp	Mon Nov 16 23:52:45 2015 +0000
@@ -103,3 +103,4 @@
         }
     }
 }
+
--- a/oslmic.h	Wed Oct 21 01:03:34 2015 +0000
+++ b/oslmic.h	Mon Nov 16 23:52:45 2015 +0000
@@ -207,6 +207,4 @@
 u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len);
 #endif
 
-
-
 #endif // _oslmic_h_
--- a/radio.cpp	Wed Oct 21 01:03:34 2015 +0000
+++ b/radio.cpp	Mon Nov 16 23:52:45 2015 +0000
@@ -425,7 +425,6 @@
 static const u1_t   rfo_table[11] = { 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 9 }; 
 
 static void configPower () {
-    printf("txpow:%d ", LMIC.txpow);
 #ifdef CFG_sx1276_radio
     // no boost used for now
     s1_t pw = (s1_t)LMIC.txpow;
@@ -449,7 +448,6 @@
         PaSelect = 0x80;    // use PA_BOOST 
         writeReg(RegPaConfig, PaSelect | boost_table[LMIC.txpow]);
     }
-    //printf("PaConfig:%02x\r\n", readReg(RegPaConfig));
     
 #else
 #error Missing CFG_sx1272_radio/CFG_sx1276_radio