lmic fork for Senet NAMote

Dependents:   Senet NAMote

Fork of lmic_MOTE_L152RC_2 by Dave Kjendal

Revision:
16:d5c50bdab1f1
Parent:
9:83ae7f34e88c
--- a/radio.cpp	Fri Sep 02 14:08:20 2016 +0000
+++ b/radio.cpp	Tue Nov 01 13:20:56 2016 -0400
@@ -119,7 +119,8 @@
 // #define RegAgcThresh3                              0x46 // common
 // #define RegPllHop                                  0x4B // common
 // #define RegTcxo                                    0x58 // common
-#define RegPaDac                                   0x5A // common
+//#define RegPaDac                                   0x5A // common
+#define RegPaDac                                   0x4d // common
 // #define RegPll                                     0x5C // common
 // #define RegPllLowPn                                0x5E // common
 // #define RegFormerTemp                              0x6C // common
@@ -418,13 +419,15 @@
 14 17.8 31.1    33.7
 15 18.4 31.1    33.7
 */
-//                     txpow:   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14  15  16  17  18  19
+//                           txpow:   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14  15  16  17  18  19
 static const u1_t boost_table[20] = { 0, 0, 0, 0, 0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15 };
 
-//                     txpow:  20 21 22 23 24 25 26 27 28 29 30
-static const u1_t   rfo_table[11] = { 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 9 }; 
+//           (LowPower Ext PA)txpow:  20 21 22 23 24 25 26 27 28 29 30
+static const u1_t   rfo_table[11] = { 0, 1, 1, 2, 2, 3, 4, 5, 6, 8, 9 }; 
 
 static void configPower () {
+    if(LMIC.txpow > 30)
+        LMIC.txpow = 30;
 #ifdef CFG_sx1276_radio
     // no boost used for now
     s1_t pw = (s1_t)LMIC.txpow;
@@ -441,13 +444,22 @@
 
     /* NA-mote TX power config: */
     if (LMIC.txpow > 19) {
+        // DLK::Set the OCP correctly (default)
+        writeReg(RegPaDac,0x84); // Normal power configuration
+        writeReg(RegOcp,0x2B); // default - OCP enabled, OCP < 15 or 120 mA max
+
         PaSelect = 0x00;    // use RFO
         writeReg(RegPaConfig, PaSelect | rfo_table[LMIC.txpow-20]);
-        pd2 = 0;
+        pd2 = 0; // Low Power External PA
     } else {
+        // DLK::Set the OCP correctly
+        writeReg(RegOcp,0x30); // higher power - OCP enabled, OCP = 16 or 130 mA max
+        writeReg(RegPaDac,0x87); // high power +20 dBm
+
         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
@@ -764,6 +776,7 @@
 // called by hal ext IRQ handler
 // (radio goes to stanby mode after tx/rx operations)
 void radio_irq_handler (u1_t dio) {
+
     ostime_t now = os_getTime();
     if( (readReg(RegOpMode) & OPMODE_LORA) != 0) { // LORA modem
         u1_t flags = readReg(LORARegIrqFlags);
@@ -824,6 +837,7 @@
 }
 
 void os_radio (u1_t mode) {
+
     hal_disableIRQs();
     switch (mode) {
       case RADIO_RST: