From 75693e00c2d23ff700fa599712ceb242a8965062 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 8 Oct 2017 06:05:36 -0700 Subject: [PATCH 01/73] Capture RSSI scan changes --- src/lmic/config.h | 11 ++++- src/lmic/lmic_config_preconditions.h | 10 ++++ src/lmic/oslmic.h | 9 ++++ src/lmic/radio.c | 73 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/lmic/config.h b/src/lmic/config.h index 3a86f036..cd0f3218 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -27,7 +27,12 @@ //#define CFG_in866 1 #if CFG_LMIC_REGION_MASK == 0 -# warning Target RF configuration not defined, assuming CFG_eu868 +# ifdef CFG_as923jp // if user defines this special symbol, treat as as923 +# define CFG_as923 1 +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP +# else +# warning Target RF configuration not defined, assuming CFG_eu868 +# endif # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK # error You can define at most one of CFG_... variables @@ -35,6 +40,10 @@ # error The selected CFG_... region is not supported yet. #endif +#ifndef LMIC_COUNTRY_CODE +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE +#endif + #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif diff --git a/src/lmic/lmic_config_preconditions.h b/src/lmic/lmic_config_preconditions.h index cd925003..52ec4771 100644 --- a/src/lmic/lmic_config_preconditions.h +++ b/src/lmic/lmic_config_preconditions.h @@ -72,6 +72,16 @@ Revision history: #define LMIC_REGION_kr921 8 #define LMIC_REGION_in866 9 +// country codes for comparison. These values are chosen from the 2-letter domain suffixes (which +// I think are ISO standardized) +#define LMIC_COUNTRY_CODE_C(c1, c2) ((c1) * 256 + (c2)) + +// this special code means "no country code defined" +#define LMIC_COUNTRY_CODE_NONE 0 + +// specific countries. Only the ones that are known in the code are defined. +#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('j', 'p') + // include the file that the user is really supposed to edit. But for really strange // ports, this can be suppressed #ifndef ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 9e190333..069e4f71 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -96,6 +96,15 @@ u1_t radio_rand1 (void); #define DEFINE_LMIC struct lmic_t LMIC #define DECLARE_LMIC extern struct lmic_t LMIC +typedef struct oslmic_radio_rssi_s oslmic_radio_rssi_t; + +struct oslmic_radio_rssi_s { + s2_t min_rssi; + s2_t max_rssi; + s2_t mean_rssi; + u2_t n_rssi; +}; + int radio_init (void); void radio_irq_handler (u1_t dio); void os_init (void); diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 43ec5596..a7af1a05 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -195,7 +195,17 @@ #define RXLORA_RXMODE_RSSI_REG_MODEM_CONFIG2 0x74 #endif +//----------------------------------------- +// Parameters for RSSI monitoring +#define SX127X_FREQ_LF_MAX 525000000 // per datasheet 6.3 +// per datasheet 5.5.3: +#define SX127X_RSSI_ADJUST_LF -164 // add to rssi value to get dB (LF) +#define SX127X_RSSI_ADJUST_HF -157 // add to rssi value to get dB (HF) + +// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because +// datasheet is unclear). +#define SX127X_RX_POWER_UP us2osticks(500) // delay this long to let the receiver power up. // ---------------------------------------- // Constants for radio registers @@ -787,6 +797,69 @@ u1_t radio_rssi () { return r; } +// monitor rssi for specified number of ostime_t ticks, and return statistics +// This puts the radio into RX continuous mode, waits long enough for the +// oscillators to start and the PLL to lock, and then measures for the specified +// period of time. The radio is then returned to idel. +// +// RSSI returned is expressed in units of dB, and is offset according to the +// current radio setting per section 5.5.5 of Semtech 1276 datasheet. +s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { + uint8_t rssiMax, rssiMin; + uint16_t rssiSum; + uint16_t rssiN; + + int rssiAdjust; + ostime_t tBegin; + + rxlora(RXMODE_SCAN); + + tBegin = os_getTime(); + + // while we're waiting for the PLLs to spin up, determine which + // band we're in and choose the base RSSI. + if (LMIC.freq > SX127X_FREQ_LF_MAX) { + rssiAdjust = SX127X_RSSI_ADJUST_LF; + } + else { + rssiAdjust = SX127X_RSSI_ADJUST_HF; + } + + // zero the results + rssiMax = 255; + rssiMin = 0; + rssiSum = 0; + rssiN = 0; + + // wait for PLLs + while ((os_getTime() - tBegin) < SX127X_RX_POWER_UP) { + // nothing + } + + // scan for the desired time. + tBegin = os_getTime(); + rssiMax = 0; + do { + u1_t rssiNow = readReg(LORARegRssiValue); + + if (rssiMax < rssiNow) + rssiMax = rssiNow; + if (rssiNow < rssiMin) + rssiMin = rssiNow; + rssiSum += rssiNow; + ++rssiN; + } while ((os_getTime() - tBegin) < nTicks); + + // put radio back to sleep + opmode(OPMODE_SLEEP); + + // compute the results + pRssi->max_rssi = (s2_t) (rssiMax + rssiAdjust); + pRssi->min_rssi = (s2_t) (rssiMin + rssiAdjust); + pRssi->mean_rssi = (s2_t) (rssiAdjust + ((rssiSum + (rssiN >> 1)) / rssiN)); + pRssi->n_rssi = rssiN; +} + static CONST_TABLE(u2_t, LORA_RXDONE_FIXUP)[] = { [FSK] = us2osticks(0), // ( 0 ticks) [SF7] = us2osticks(0), // ( 0 ticks) From ae6ea57b1dca4bfda1fa645092e3178dbe97150e Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:34:53 -0400 Subject: [PATCH 02/73] Correct definition, add prototype for the RSSI monitor function --- src/lmic/oslmic.h | 5 +++-- src/lmic/radio.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 069e4f71..1cef61bf 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -73,6 +73,8 @@ typedef struct rxsched_t rxsched_t; typedef struct bcninfo_t bcninfo_t; typedef const u1_t* xref2cu1_t; typedef u1_t* xref2u1_t; +typedef s4_t ostime_t; + #define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t #define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t #define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t @@ -112,6 +114,7 @@ int os_init_ex (const void *pPinMap); void os_runloop (void); void os_runloop_once (void); u1_t radio_rssi (void); +void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi); //================================================================================ @@ -129,8 +132,6 @@ u1_t radio_rssi (void); #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long. #endif -typedef s4_t ostime_t; - #if !HAS_ostick_conv #define us2osticks(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC) / 1000000)) #define ms2osticks(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC) / 1000)) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index a7af1a05..28ca8285 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -804,7 +804,7 @@ u1_t radio_rssi () { // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. -s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { +void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { uint8_t rssiMax, rssiMin; uint16_t rssiSum; uint16_t rssiN; From c88dec5654f5f9013b57435116df07dde66f523d Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:36:45 -0400 Subject: [PATCH 03/73] fix commentary --- examples/raw-feather/raw-feather.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 618bd189..271c7400 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -203,7 +203,9 @@ void setup() { // guides the responder through all the channels, powers, ramps // the transmit power from min to max, and measures the RSSI and SNR. // Even more amazing would be a scheme where the controller could - // handle multiple nodes; in that case we'd have a + // handle multiple nodes; in that case we'd have a way to do + // production test and qualification. However, using an RWC5020A + // is a much better use of development time. const static bool fDownlink = true; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; From 5a04d3f56c8288b127c979e57149c3f786574940 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:41:57 -0400 Subject: [PATCH 04/73] Add check for unsupported band --- examples/raw-feather/raw-feather.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 271c7400..a8c0c70d 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -242,6 +242,8 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#else +# error Unsupported LMIC regional configuration. #endif // disable RX IQ inversion From 360fdf707aa49d40d96dc29b0c91ea6338907e8f Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:43:45 -0400 Subject: [PATCH 05/73] Change to test of downlink channel 3 and DR4 --- examples/raw-feather/raw-feather.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index a8c0c70d..ac0b6120 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -206,7 +206,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static bool fDownlink = true; + const static bool fDownlink = false; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; uint32_t uBandwidth; @@ -236,9 +236,9 @@ void setup() { // Use a suitable spreading factor if (uBandwidth < 500) - LMIC.datarate = DR_SF10; // DR0 + LMIC.datarate = US915_DR_SF7; // DR4 else - LMIC.datarate = DR_SF12CR; // DR8 + LMIC.datarate = US915_DR_SF12CR; // DR8 // default tx power for US: 21 dBm LMIC.txpow = 21; From f4be1c093259597b44f63af45760deb192c42492 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:44:25 -0400 Subject: [PATCH 06/73] Check and display RSSI prior to transmit --- examples/raw-feather/raw-feather.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index ac0b6120..047b6237 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -69,6 +69,7 @@ Revision history: // https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc #define TX_INTERVAL 2000 // milliseconds +#define RX_RSSI_INTERVAL 100 // milliseconds // Pin mapping for Adafruit Feather M0 LoRa const lmic_pinmap lmic_pins = { @@ -97,8 +98,19 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { + oslmic_radio_rssi_t rssi; os_radio(RADIO_RST); // Stop RX first delay(1); // Wait a bit, without this os_radio below asserts, apparently because the state hasn't changed yet + + // if requested, scan RSSI (LBT). On a Feather, it's about 42 us/sample. + if (RX_RSSI_INTERVAL > 0) { + radio_monitor_rssi(ms2osticks(RX_RSSI_INTERVAL), &rssi); + Serial.print("RSSI results (dB): min: "); Serial.print(rssi.min_rssi); + Serial.print(" max: "); Serial.print(rssi.max_rssi); + Serial.print(" mean: "); Serial.print(rssi.mean_rssi); + Serial.print(" n: "); Serial.println(rssi.n_rssi); + } + LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; From 556f3f3abe6258f80552a38c5c88a3a3de87d2bc Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:38:49 -0500 Subject: [PATCH 07/73] Change the RFU bits for DN2P_ANS to F8 per LoRaWAN 1.0.2 --- src/lmic/lorabase.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lmic/lorabase.h b/src/lmic/lorabase.h index 12cb34b2..af261053 100644 --- a/src/lmic/lorabase.h +++ b/src/lmic/lorabase.h @@ -483,7 +483,8 @@ enum { MCMD_LADR_ANS_CHACK = 0x01, // 0=unknown channel enabled }; enum { - MCMD_DN2P_ANS_RFU = 0xFC, // RFU bits + MCMD_DN2P_ANS_RFU = 0xF8, // RFU bits + MCMD_DN2P_ANS_RX1DrOffsetAck = 0x04, // 0=dr2 not allowed MCMD_DN2P_ANS_DRACK = 0x02, // 0=unknown data rate MCMD_DN2P_ANS_CHACK = 0x01, // 0=unknown channel enabled }; From 8293a336c693dc48f14ffd73abb53ccad95e2718 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:42:00 -0500 Subject: [PATCH 08/73] Improve handling of rx1DrOffset, switch order of response per 1.0.2 --- src/lmic/lmic.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 262848f0..653112eb 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -593,15 +593,20 @@ scan_mac_cmds( case MCMD_DN2P_SET: { #if !defined(DISABLE_MCMD_DN2P_SET) dr_t dr = (dr_t)(opts[oidx+1] & 0x0F); + u1_t rx1DrOffset = (u1_t)((opts[oidx+1] & 0x70) >> 4); u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]); LMIC.dn2Ans = 0x80; // answer pending if( validDR(dr) ) LMIC.dn2Ans |= MCMD_DN2P_ANS_DRACK; if( freq != 0 ) LMIC.dn2Ans |= MCMD_DN2P_ANS_CHACK; - if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK) ) { + if (rx1DrOffset <= 3) + LMIC.dn2Ans |= MCMD_DN2P_ANS_RX1DrOffsetAck; + + if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK| MCMD_DN2P_ANS_RX1DrOffsetAck) ) { LMIC.dn2Dr = dr; LMIC.dn2Freq = freq; + LMIC.rx1DrOffset = rx1DrOffset; DO_DEVDB(LMIC.dn2Dr,dn2Dr); DO_DEVDB(LMIC.dn2Freq,dn2Freq); } @@ -1197,14 +1202,6 @@ static void buildDataFrame (void) { LMIC.dutyCapAns = 0; } #endif // !DISABLE_MCMD_DCAP_REQ -#if !defined(DISABLE_MCMD_DN2P_SET) - if( LMIC.dn2Ans ) { - LMIC.frame[end+0] = MCMD_DN2P_ANS; - LMIC.frame[end+1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; - end += 2; - LMIC.dn2Ans = 0; - } -#endif // !DISABLE_MCMD_DN2P_SET if( LMIC.devsAns ) { // answer to device status LMIC.frame[end+0] = MCMD_DEVS_ANS; LMIC.frame[end+1] = os_getBattLevel(); @@ -1229,6 +1226,14 @@ static void buildDataFrame (void) { LMIC.adrAckReq = 0; LMIC.adrChanged = 0; } +#if !defined(DISABLE_MCMD_DN2P_SET) + if (LMIC.dn2Ans) { + LMIC.frame[end + 0] = MCMD_DN2P_ANS; + LMIC.frame[end + 1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; + end += 2; + LMIC.dn2Ans = 0; + } +#endif // !DISABLE_MCMD_DN2P_SET #if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING) if( LMIC.pingSetAns != 0 ) { LMIC.frame[end+0] = MCMD_PING_ANS; From 8ef00152f77f7e2f5599b8bc38450483f8692634 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 8 Oct 2017 06:05:36 -0700 Subject: [PATCH 09/73] Capture RSSI scan changes --- src/lmic/config.h | 11 ++++- src/lmic/lmic_config_preconditions.h | 10 ++++ src/lmic/oslmic.h | 9 ++++ src/lmic/radio.c | 73 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/lmic/config.h b/src/lmic/config.h index 3a86f036..cd0f3218 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -27,7 +27,12 @@ //#define CFG_in866 1 #if CFG_LMIC_REGION_MASK == 0 -# warning Target RF configuration not defined, assuming CFG_eu868 +# ifdef CFG_as923jp // if user defines this special symbol, treat as as923 +# define CFG_as923 1 +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP +# else +# warning Target RF configuration not defined, assuming CFG_eu868 +# endif # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK # error You can define at most one of CFG_... variables @@ -35,6 +40,10 @@ # error The selected CFG_... region is not supported yet. #endif +#ifndef LMIC_COUNTRY_CODE +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE +#endif + #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif diff --git a/src/lmic/lmic_config_preconditions.h b/src/lmic/lmic_config_preconditions.h index cd925003..52ec4771 100644 --- a/src/lmic/lmic_config_preconditions.h +++ b/src/lmic/lmic_config_preconditions.h @@ -72,6 +72,16 @@ Revision history: #define LMIC_REGION_kr921 8 #define LMIC_REGION_in866 9 +// country codes for comparison. These values are chosen from the 2-letter domain suffixes (which +// I think are ISO standardized) +#define LMIC_COUNTRY_CODE_C(c1, c2) ((c1) * 256 + (c2)) + +// this special code means "no country code defined" +#define LMIC_COUNTRY_CODE_NONE 0 + +// specific countries. Only the ones that are known in the code are defined. +#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('j', 'p') + // include the file that the user is really supposed to edit. But for really strange // ports, this can be suppressed #ifndef ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 9e190333..069e4f71 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -96,6 +96,15 @@ u1_t radio_rand1 (void); #define DEFINE_LMIC struct lmic_t LMIC #define DECLARE_LMIC extern struct lmic_t LMIC +typedef struct oslmic_radio_rssi_s oslmic_radio_rssi_t; + +struct oslmic_radio_rssi_s { + s2_t min_rssi; + s2_t max_rssi; + s2_t mean_rssi; + u2_t n_rssi; +}; + int radio_init (void); void radio_irq_handler (u1_t dio); void os_init (void); diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 43ec5596..a7af1a05 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -195,7 +195,17 @@ #define RXLORA_RXMODE_RSSI_REG_MODEM_CONFIG2 0x74 #endif +//----------------------------------------- +// Parameters for RSSI monitoring +#define SX127X_FREQ_LF_MAX 525000000 // per datasheet 6.3 +// per datasheet 5.5.3: +#define SX127X_RSSI_ADJUST_LF -164 // add to rssi value to get dB (LF) +#define SX127X_RSSI_ADJUST_HF -157 // add to rssi value to get dB (HF) + +// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because +// datasheet is unclear). +#define SX127X_RX_POWER_UP us2osticks(500) // delay this long to let the receiver power up. // ---------------------------------------- // Constants for radio registers @@ -787,6 +797,69 @@ u1_t radio_rssi () { return r; } +// monitor rssi for specified number of ostime_t ticks, and return statistics +// This puts the radio into RX continuous mode, waits long enough for the +// oscillators to start and the PLL to lock, and then measures for the specified +// period of time. The radio is then returned to idel. +// +// RSSI returned is expressed in units of dB, and is offset according to the +// current radio setting per section 5.5.5 of Semtech 1276 datasheet. +s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { + uint8_t rssiMax, rssiMin; + uint16_t rssiSum; + uint16_t rssiN; + + int rssiAdjust; + ostime_t tBegin; + + rxlora(RXMODE_SCAN); + + tBegin = os_getTime(); + + // while we're waiting for the PLLs to spin up, determine which + // band we're in and choose the base RSSI. + if (LMIC.freq > SX127X_FREQ_LF_MAX) { + rssiAdjust = SX127X_RSSI_ADJUST_LF; + } + else { + rssiAdjust = SX127X_RSSI_ADJUST_HF; + } + + // zero the results + rssiMax = 255; + rssiMin = 0; + rssiSum = 0; + rssiN = 0; + + // wait for PLLs + while ((os_getTime() - tBegin) < SX127X_RX_POWER_UP) { + // nothing + } + + // scan for the desired time. + tBegin = os_getTime(); + rssiMax = 0; + do { + u1_t rssiNow = readReg(LORARegRssiValue); + + if (rssiMax < rssiNow) + rssiMax = rssiNow; + if (rssiNow < rssiMin) + rssiMin = rssiNow; + rssiSum += rssiNow; + ++rssiN; + } while ((os_getTime() - tBegin) < nTicks); + + // put radio back to sleep + opmode(OPMODE_SLEEP); + + // compute the results + pRssi->max_rssi = (s2_t) (rssiMax + rssiAdjust); + pRssi->min_rssi = (s2_t) (rssiMin + rssiAdjust); + pRssi->mean_rssi = (s2_t) (rssiAdjust + ((rssiSum + (rssiN >> 1)) / rssiN)); + pRssi->n_rssi = rssiN; +} + static CONST_TABLE(u2_t, LORA_RXDONE_FIXUP)[] = { [FSK] = us2osticks(0), // ( 0 ticks) [SF7] = us2osticks(0), // ( 0 ticks) From 326f5138d8c8b3f094b541f1bc2fe79242e4d425 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:34:53 -0400 Subject: [PATCH 10/73] Correct definition, add prototype for the RSSI monitor function --- src/lmic/oslmic.h | 5 +++-- src/lmic/radio.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 069e4f71..1cef61bf 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -73,6 +73,8 @@ typedef struct rxsched_t rxsched_t; typedef struct bcninfo_t bcninfo_t; typedef const u1_t* xref2cu1_t; typedef u1_t* xref2u1_t; +typedef s4_t ostime_t; + #define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t #define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t #define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t @@ -112,6 +114,7 @@ int os_init_ex (const void *pPinMap); void os_runloop (void); void os_runloop_once (void); u1_t radio_rssi (void); +void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi); //================================================================================ @@ -129,8 +132,6 @@ u1_t radio_rssi (void); #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long. #endif -typedef s4_t ostime_t; - #if !HAS_ostick_conv #define us2osticks(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC) / 1000000)) #define ms2osticks(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC) / 1000)) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index a7af1a05..28ca8285 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -804,7 +804,7 @@ u1_t radio_rssi () { // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. -s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { +void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { uint8_t rssiMax, rssiMin; uint16_t rssiSum; uint16_t rssiN; From f608d457d58510bae577dfb94ebaf9d188449108 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:36:45 -0400 Subject: [PATCH 11/73] fix commentary --- examples/raw-feather/raw-feather.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 618bd189..271c7400 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -203,7 +203,9 @@ void setup() { // guides the responder through all the channels, powers, ramps // the transmit power from min to max, and measures the RSSI and SNR. // Even more amazing would be a scheme where the controller could - // handle multiple nodes; in that case we'd have a + // handle multiple nodes; in that case we'd have a way to do + // production test and qualification. However, using an RWC5020A + // is a much better use of development time. const static bool fDownlink = true; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; From 35af2593a609e4008acfbca1d04c98cf9ddec3e8 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:41:57 -0400 Subject: [PATCH 12/73] Add check for unsupported band --- examples/raw-feather/raw-feather.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 271c7400..a8c0c70d 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -242,6 +242,8 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#else +# error Unsupported LMIC regional configuration. #endif // disable RX IQ inversion From 87bae9776aecc91960ef9a38a28f8dcc99b21e15 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:43:45 -0400 Subject: [PATCH 13/73] Change to test of downlink channel 3 and DR4 --- examples/raw-feather/raw-feather.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index a8c0c70d..ac0b6120 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -206,7 +206,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static bool fDownlink = true; + const static bool fDownlink = false; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; uint32_t uBandwidth; @@ -236,9 +236,9 @@ void setup() { // Use a suitable spreading factor if (uBandwidth < 500) - LMIC.datarate = DR_SF10; // DR0 + LMIC.datarate = US915_DR_SF7; // DR4 else - LMIC.datarate = DR_SF12CR; // DR8 + LMIC.datarate = US915_DR_SF12CR; // DR8 // default tx power for US: 21 dBm LMIC.txpow = 21; From 6e4d65336abfe6e26b3933f589194b89a5a50379 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:44:25 -0400 Subject: [PATCH 14/73] Check and display RSSI prior to transmit --- examples/raw-feather/raw-feather.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index ac0b6120..047b6237 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -69,6 +69,7 @@ Revision history: // https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc #define TX_INTERVAL 2000 // milliseconds +#define RX_RSSI_INTERVAL 100 // milliseconds // Pin mapping for Adafruit Feather M0 LoRa const lmic_pinmap lmic_pins = { @@ -97,8 +98,19 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { + oslmic_radio_rssi_t rssi; os_radio(RADIO_RST); // Stop RX first delay(1); // Wait a bit, without this os_radio below asserts, apparently because the state hasn't changed yet + + // if requested, scan RSSI (LBT). On a Feather, it's about 42 us/sample. + if (RX_RSSI_INTERVAL > 0) { + radio_monitor_rssi(ms2osticks(RX_RSSI_INTERVAL), &rssi); + Serial.print("RSSI results (dB): min: "); Serial.print(rssi.min_rssi); + Serial.print(" max: "); Serial.print(rssi.max_rssi); + Serial.print(" mean: "); Serial.print(rssi.mean_rssi); + Serial.print(" n: "); Serial.println(rssi.n_rssi); + } + LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; From 5c0e0de1044d2aa0c9039f518bda801a7dd7b574 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:38:49 -0500 Subject: [PATCH 15/73] Change the RFU bits for DN2P_ANS to F8 per LoRaWAN 1.0.2 --- src/lmic/lorabase.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lmic/lorabase.h b/src/lmic/lorabase.h index 7368329f..3e57a9cd 100644 --- a/src/lmic/lorabase.h +++ b/src/lmic/lorabase.h @@ -483,7 +483,8 @@ enum { MCMD_LADR_ANS_CHACK = 0x01, // 0=unknown channel enabled }; enum { - MCMD_DN2P_ANS_RFU = 0xFC, // RFU bits + MCMD_DN2P_ANS_RFU = 0xF8, // RFU bits + MCMD_DN2P_ANS_RX1DrOffsetAck = 0x04, // 0=dr2 not allowed MCMD_DN2P_ANS_DRACK = 0x02, // 0=unknown data rate MCMD_DN2P_ANS_CHACK = 0x01, // 0=unknown channel enabled }; From 88caafc4f09619cab9c2df9fd6b9e1aff4134d16 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:42:00 -0500 Subject: [PATCH 16/73] Improve handling of rx1DrOffset, switch order of response per 1.0.2 --- src/lmic/lmic.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 10039b97..022dcdf1 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -615,15 +615,20 @@ scan_mac_cmds( case MCMD_DN2P_SET: { #if !defined(DISABLE_MCMD_DN2P_SET) dr_t dr = (dr_t)(opts[oidx+1] & 0x0F); + u1_t rx1DrOffset = (u1_t)((opts[oidx+1] & 0x70) >> 4); u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]); LMIC.dn2Ans = 0x80; // answer pending if( validDR(dr) ) LMIC.dn2Ans |= MCMD_DN2P_ANS_DRACK; if( freq != 0 ) LMIC.dn2Ans |= MCMD_DN2P_ANS_CHACK; - if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK) ) { + if (rx1DrOffset <= 3) + LMIC.dn2Ans |= MCMD_DN2P_ANS_RX1DrOffsetAck; + + if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK| MCMD_DN2P_ANS_RX1DrOffsetAck) ) { LMIC.dn2Dr = dr; LMIC.dn2Freq = freq; + LMIC.rx1DrOffset = rx1DrOffset; DO_DEVDB(LMIC.dn2Dr,dn2Dr); DO_DEVDB(LMIC.dn2Freq,dn2Freq); } @@ -1223,14 +1228,6 @@ static void buildDataFrame (void) { LMIC.dutyCapAns = 0; } #endif // !DISABLE_MCMD_DCAP_REQ -#if !defined(DISABLE_MCMD_DN2P_SET) - if( LMIC.dn2Ans ) { - LMIC.frame[end+0] = MCMD_DN2P_ANS; - LMIC.frame[end+1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; - end += 2; - LMIC.dn2Ans = 0; - } -#endif // !DISABLE_MCMD_DN2P_SET if( LMIC.devsAns ) { // answer to device status LMIC.frame[end+0] = MCMD_DEVS_ANS; LMIC.frame[end+1] = os_getBattLevel(); @@ -1255,6 +1252,14 @@ static void buildDataFrame (void) { LMIC.adrAckReq = 0; LMIC.adrChanged = 0; } +#if !defined(DISABLE_MCMD_DN2P_SET) + if (LMIC.dn2Ans) { + LMIC.frame[end + 0] = MCMD_DN2P_ANS; + LMIC.frame[end + 1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; + end += 2; + LMIC.dn2Ans = 0; + } +#endif // !DISABLE_MCMD_DN2P_SET #if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING) if( LMIC.pingSetAns != 0 ) { LMIC.frame[end+0] = MCMD_PING_ANS; From a0ffe52ff46a771287b03f8de105dbadbe20490e Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:49:02 -0500 Subject: [PATCH 17/73] Add LBT support, and set it up for Japan --- examples/raw-feather/raw-feather.ino | 40 +++++++++++++++++---------- src/lmic/config.h | 11 ++++---- src/lmic/lmic.h | 5 ++++ src/lmic/lmic_as923.c | 6 ++++ src/lmic/lorabase_as923.h | 3 ++ src/lmic/radio.c | 41 ++++++++++++++++++++++++---- 6 files changed, 81 insertions(+), 25 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 047b6237..fb586e03 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -98,19 +98,6 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { - oslmic_radio_rssi_t rssi; - os_radio(RADIO_RST); // Stop RX first - delay(1); // Wait a bit, without this os_radio below asserts, apparently because the state hasn't changed yet - - // if requested, scan RSSI (LBT). On a Feather, it's about 42 us/sample. - if (RX_RSSI_INTERVAL > 0) { - radio_monitor_rssi(ms2osticks(RX_RSSI_INTERVAL), &rssi); - Serial.print("RSSI results (dB): min: "); Serial.print(rssi.min_rssi); - Serial.print(" max: "); Serial.print(rssi.max_rssi); - Serial.print(" mean: "); Serial.print(rssi.mean_rssi); - Serial.print(" n: "); Serial.println(rssi.n_rssi); - } - LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; @@ -254,14 +241,39 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#elif defined(CFG_as923) +// make it easier for test, by pull the parameters up to the top of the +// block. Ideally, we'd use the serial port to drive this; or have +// a voting protocol where one side is elected the controller and +// guides the responder through all the channels, powers, ramps +// the transmit power from min to max, and measures the RSSI and SNR. +// Even more amazing would be a scheme where the controller could +// handle multiple nodes; in that case we'd have a way to do +// production test and qualification. However, using an RWC5020A +// is a much better use of development time. + const static uint8_t kChannel = 1; + uint32_t uBandwidth; + + LMIC.freq = AS923_F1 + kChannel * 200000; + uBandwidth = 125; + + // Use a suitable spreading factor + if (uBandwidth == 125) + LMIC.datarate = AS923_DR_SF7; // DR7 + else + LMIC.datarate = AS923_DR_SF7B; // DR8 + + // default tx power for US: 21 dBm + LMIC.txpow = 16; #else # error Unsupported LMIC regional configuration. #endif + // disable RX IQ inversion LMIC.noRXIQinversion = true; - // This sets CR 4/5, BW125 (except for EU DR_SF7B, which uses BW250) + // This sets CR 4/5, BW125 (except for EU/AS923 DR_SF7B, which uses BW250) LMIC.rps = updr2rps(LMIC.datarate); Serial.print("Frequency: "); Serial.print(LMIC.freq / 1000000); diff --git a/src/lmic/config.h b/src/lmic/config.h index cd0f3218..4fccc320 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -27,12 +27,6 @@ //#define CFG_in866 1 #if CFG_LMIC_REGION_MASK == 0 -# ifdef CFG_as923jp // if user defines this special symbol, treat as as923 -# define CFG_as923 1 -# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP -# else -# warning Target RF configuration not defined, assuming CFG_eu868 -# endif # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK # error You can define at most one of CFG_... variables @@ -44,6 +38,11 @@ # define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE #endif +// if the country code is japan, then the region must be AS923 +#if LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP && CFG_region != LMIC_REGION_as923 +# error "If country code is JP, then region must be AS923" +#endif + #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index 2145e1f3..0b902809 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -207,6 +207,11 @@ struct lmic_t { // Radio settings TX/RX (also accessed by HAL) ostime_t txend; ostime_t rxtime; + + // LBT info + ostime_t lbt_ticks; // ticks to listen + s1_t lbt_dbmax; // max permissible dB on our channle (eg -80) + u4_t freq; s1_t rssi; s1_t snr; diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 13b9d31a..33b1017e 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -179,6 +179,12 @@ void LMICas923_initDefaultChannels(bit_t join) { LMIC.bands[BAND_CENTI].txpow = AS923_TX_EIRP_MAX_DBM; LMIC.bands[BAND_CENTI].lastchnl = os_getRndU1() % MAX_CHANNELS; LMIC.bands[BAND_CENTI].avail = os_getTime(); + + // if this is japan, set LBT mode + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { + LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; + } } bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) { diff --git a/src/lmic/lorabase_as923.h b/src/lmic/lorabase_as923.h index aa5e62e3..dbd936ac 100644 --- a/src/lmic/lorabase_as923.h +++ b/src/lmic/lorabase_as923.h @@ -74,4 +74,7 @@ enum { DR_PAGE_AS923 = 0x10 * (LMIC_REGION_as923 - 1) }; enum { AS923_LMIC_REGION_EIRP = 1 }; // region uses EIRP +enum { AS923JP_LBT_MS = 100 }; // milliseconds of LBT time +enum { AS923JP_LBT_DB_MAX = -80 }; // maximum channel strength + #endif /* _lorabase_as923_h_ */ \ No newline at end of file diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 28ca8285..7e68adb4 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -203,7 +203,7 @@ #define SX127X_RSSI_ADJUST_LF -164 // add to rssi value to get dB (LF) #define SX127X_RSSI_ADJUST_HF -157 // add to rssi value to get dB (HF) -// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because +// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because // datasheet is unclear). #define SX127X_RX_POWER_UP us2osticks(500) // delay this long to let the receiver power up. @@ -555,7 +555,39 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { + oslmic_radio_rssi_t rssi; + ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP ); + + if (LMIC.lbt_ticks > 0) { + radio_monitor_rssi(LMIC.lbt_ticks, &rssi); + + if (rssi.max_rssi >= LMIC.lbt_dbmax) { +#if LMIC_DEBUG_LEVEL > 0 + u1_t sf = getSf(LMIC.rps) + 6; // 1 == SF7 + u1_t bw = getBw(LMIC.rps); + u1_t cr = getCr(LMIC.rps); + LMIC_DEBUG_PRINTF("%lu: freq=%lu, SF=%d, BW=%d, CR=4/%d, interfering signal %d > %d dB\n", + os_getTime(), LMIC.freq, bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), + cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), + rssi.max_rssi, + LMIC.lbt_dbmax + ) +#endif + // complete the request by scheduling the job + os_setCallback(&LMIC.osjob, LMIC.osjob.func); + return; + } + +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%lu: freq=%lu, interfering signal %d < %d dB\n", + os_getTime(), LMIC.freq, + rssi.max_rssi, + LMIC.lbt_dbmax + ) +#endif + } + if(getSf(LMIC.rps) == FSK) { // FSK modem txfsk(); } else { // LoRa modem @@ -798,9 +830,9 @@ u1_t radio_rssi () { } // monitor rssi for specified number of ostime_t ticks, and return statistics -// This puts the radio into RX continuous mode, waits long enough for the +// This puts the radio into RX continuous mode, waits long enough for the // oscillators to start and the PLL to lock, and then measures for the specified -// period of time. The radio is then returned to idel. +// period of time. The radio is then returned to idle. // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. @@ -820,8 +852,7 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { rssiAdjust = SX127X_RSSI_ADJUST_LF; - } - else { + } else { rssiAdjust = SX127X_RSSI_ADJUST_HF; } From 41f6701d0653e098db797a4c9725482ce64a4b30 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:49:38 -0500 Subject: [PATCH 18/73] Ignore vs code context --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b743c003..0b8a5dc4 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ Release *.vcxproj.filters __vm .vs +.vscode + From cd858f02e0b8c27e87bf75cbdeaca72fca126f5a Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:50:19 -0500 Subject: [PATCH 19/73] For this branch only, switch to AS923/Japan --- project_config/lmic_project_config.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index eb608dac..e9e1d938 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -1,8 +1,9 @@ // project-specific definitions for otaa sensor //#define CFG_eu868 1 -#define CFG_us915 1 +//#define CFG_us915 1 //#define CFG_au921 1 -//#define CFG_as923 1 +#define CFG_as923 1 +#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS From d492546e7ce11bd2b5412867a59c59fb22ae600f Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 10:09:03 -0500 Subject: [PATCH 20/73] Fix syntax error in debug print --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 7e68adb4..ec9b53cf 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -572,7 +572,7 @@ static void starttx () { cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), rssi.max_rssi, LMIC.lbt_dbmax - ) + ); #endif // complete the request by scheduling the job os_setCallback(&LMIC.osjob, LMIC.osjob.func); From 5e683109ec21ee220af0dea2ce3700cac489c1bd Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 11:17:51 -0500 Subject: [PATCH 21/73] Restore missing os_radio(RADIO_RST) before tx --- examples/raw-feather/raw-feather.ino | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index fb586e03..b1d935c7 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -98,10 +98,20 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { + // the radio is probably in RX mode; stop it. + os_radio(RADIO_RST); + // wait a bit so the radio can come out of RX mode + delay(1); + + // prepare data LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; + + // set completion function. LMIC.osjob.func = func; + + // start the transmission os_radio(RADIO_TX); Serial.println("TX"); } From 892d0770882122e9285abae5e7f5c4d061839c30 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:08:32 -0500 Subject: [PATCH 22/73] fix typo in debug print --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index ec9b53cf..0e619541 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -584,7 +584,7 @@ static void starttx () { os_getTime(), LMIC.freq, rssi.max_rssi, LMIC.lbt_dbmax - ) + ); #endif } From 1d30833ed411c96e86ee37fcece434c7af8aa8f1 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:09:08 -0500 Subject: [PATCH 23/73] add a suitable print function for debugging --- examples/raw-feather/raw-feather.ino | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index b1d935c7..fb1d2d1b 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -50,6 +50,9 @@ Revision history: #include #include +#include +#include + // we formerly would check this configuration; but now there is a flag, // in the LMIC, LMIC.noRXIQinversion; // if we set that during init, we get the same effect. If @@ -92,6 +95,26 @@ void os_getDevKey (u1_t* buf) { } void onEvent (ev_t ev) { } +extern "C" { +void lmic_printf(const char *fmt, ...); +}; + +void lmic_printf(const char *fmt, ...) { + if (! Serial.dtr()) + return; + + char buf[256]; + va_list ap; + + va_start(ap, fmt); + (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap); + va_end(ap); + + // in case we overflowed: + buf[sizeof(buf) - 1] = '\0'; + if (Serial.dtr()) Serial.print(buf); +} + osjob_t txjob; osjob_t timeoutjob; static void tx_func (osjob_t* job); From cee852ab5abc167b1996043f2398e47902ca7068 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:09:47 -0500 Subject: [PATCH 24/73] Set debug level to 2 and use a suitable printf function --- project_config/lmic_project_config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index e9e1d938..08dcf403 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -7,3 +7,5 @@ //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS +#define LMIC_DEBUG_LEVEL 2 +#define LMIC_DEBUG_PRINTF_FN lmic_printf From 581c73e903b7b9e3f088dde68b32486efccc6e63 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 13:07:55 -0500 Subject: [PATCH 25/73] Add init/reset routines for LMIC and set JP LBT params --- src/lmic/lmic.c | 1 + src/lmic/lmic_as923.c | 13 +++++++++++++ src/lmic/lmic_bandplan.h | 3 +++ src/lmic/lmic_bandplan_as923.h | 16 ++++++++++++++++ src/lmic/lmic_eu_like.h | 3 +++ src/lmic/lmic_us_like.h | 2 ++ 6 files changed, 38 insertions(+) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 022dcdf1..a42f4f08 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -1871,6 +1871,7 @@ void LMIC_reset (void) { void LMIC_init (void) { LMIC.opmode = OP_SHUTDOWN; + LMICbandplan_init(); } diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 33b1017e..9417ddaf 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -179,7 +179,10 @@ void LMICas923_initDefaultChannels(bit_t join) { LMIC.bands[BAND_CENTI].txpow = AS923_TX_EIRP_MAX_DBM; LMIC.bands[BAND_CENTI].lastchnl = os_getRndU1() % MAX_CHANNELS; LMIC.bands[BAND_CENTI].avail = os_getTime(); +} +void +LMICas923_init(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); @@ -187,6 +190,16 @@ void LMICas923_initDefaultChannels(bit_t join) { } } +void +LMICas923_resetDefaultChannels(void) { + // if this is japan, set LBT mode + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { + LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; + } +} + + bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) { if (bandidx != BAND_CENTI) return 0; //band_t* b = &LMIC.bands[bandidx]; diff --git a/src/lmic/lmic_bandplan.h b/src/lmic/lmic_bandplan.h index 6aa2c743..0c3c5036 100644 --- a/src/lmic/lmic_bandplan.h +++ b/src/lmic/lmic_bandplan.h @@ -140,6 +140,9 @@ # error "LMICbandplan_nextJoinTime() not defined by bandplan" #endif +#if !defined(LMICbandplan_init) +# error "LMICbandplan_init() not defined by bandplan" +#endif // // Things common to lmic.c code // diff --git a/src/lmic/lmic_bandplan_as923.h b/src/lmic/lmic_bandplan_as923.h index 10dd2224..50017f29 100644 --- a/src/lmic/lmic_bandplan_as923.h +++ b/src/lmic/lmic_bandplan_as923.h @@ -52,6 +52,22 @@ LMICas923_isValidBeacon1(const uint8_t *d) { #undef LMICbandplan_isValidBeacon1 #define LMICbandplan_isValidBeacon1(pFrame) LMICas923_isValidBeacon1(pFrame) +// override default for LMICbandplan_resetDefaultChannels +void +LMICas923_resetDefaultChannels(void); + +#undef LMICbandplan_resetDefaultChannels +#define LMICbandplan_resetDefaultChannels() \ + LMICas923_resetDefaultChannels() + +// override default for LMICbandplan_init +void LMICas923_init(void); + +#undef LMICbandplan_init +#define LMICbandplan_init() \ + LMICas923_init() + + // override default for LMICbandplan_isFSK() #undef LMICbandplan_isFSK #define LMICbandplan_isFSK() (/* TX datarate */LMIC.rxsyms == AS923_DR_FSK) diff --git a/src/lmic/lmic_eu_like.h b/src/lmic/lmic_eu_like.h index e6ea820e..f147790d 100644 --- a/src/lmic/lmic_eu_like.h +++ b/src/lmic/lmic_eu_like.h @@ -92,4 +92,7 @@ static inline ostime_t LMICeulike_nextJoinTime(ostime_t now) { } #define LMICbandplan_nextJoinTime(now) LMICeulike_nextJoinTime(now) +#define LMICbandplan_init() \ + do { /* nothing */ } while (0) + #endif // _lmic_eu_like_h_ diff --git a/src/lmic/lmic_us_like.h b/src/lmic/lmic_us_like.h index 7a35b208..66bc549a 100644 --- a/src/lmic/lmic_us_like.h +++ b/src/lmic/lmic_us_like.h @@ -94,5 +94,7 @@ static inline ostime_t LMICeulike_nextJoinTime(ostime_t now) { } #define LMICbandplan_nextJoinTime(now) LMICeulike_nextJoinTime(now) +#define LMICbandplan_init() \ + do { /* nothing */ } while (0) #endif // _lmic_us_like_h_ From 5a0a1d48563685c1cfd40b4822e254a7e75c5220 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 13:26:38 -0500 Subject: [PATCH 26/73] Add debug prints, don't ASSERT() if not idle w/ starttx() --- src/lmic/radio.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 0e619541..9177f00f 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -556,10 +556,28 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { oslmic_radio_rssi_t rssi; + u1_t const rOpMode = readReg(RegOpMode); - ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP ); + // originally, this code ASSERT()ed, but asserts are both bad and + // blunt instruments. If we see that we're not in sleep mode, + // force sleep (because we might have to switch modes) + if ((rOpMode & OPMODE_MASK) != OPMODE_SLEEP) { +#if LMIC_DEBUG_LEVEL > 0 + LMIC_DEBUG_PRINTF("?%s: OPMODE != OPMODE_SLEEP: %#02x\n", __func__, rOpMode); +#endif + opmode(OPMODE_SLEEP); + ostime_t tBegin = os_getTime(); + while (os_getTime() - tBegin < ms2osticks(1)) + /* idle */; + } if (LMIC.lbt_ticks > 0) { +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", + os_getTime(), + LMIC.lbt_ticks + ); +#endif radio_monitor_rssi(LMIC.lbt_ticks, &rssi); if (rssi.max_rssi >= LMIC.lbt_dbmax) { From 13537046946deecc14cc8c3e03a29b21ecf7948c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 23 Jan 2018 00:47:10 -0500 Subject: [PATCH 27/73] Switch to microsec resolution for JP LBT, and restrucrue wait loop --- src/lmic/lmic_as923.c | 4 ++-- src/lmic/lorabase_as923.h | 4 ++-- src/lmic/radio.c | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 9417ddaf..f1e4b101 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -185,7 +185,7 @@ void LMICas923_init(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { - LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; } } @@ -194,7 +194,7 @@ void LMICas923_resetDefaultChannels(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { - LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; } } diff --git a/src/lmic/lorabase_as923.h b/src/lmic/lorabase_as923.h index dbd936ac..2b95249c 100644 --- a/src/lmic/lorabase_as923.h +++ b/src/lmic/lorabase_as923.h @@ -74,7 +74,7 @@ enum { DR_PAGE_AS923 = 0x10 * (LMIC_REGION_as923 - 1) }; enum { AS923_LMIC_REGION_EIRP = 1 }; // region uses EIRP -enum { AS923JP_LBT_MS = 100 }; // milliseconds of LBT time +enum { AS923JP_LBT_US = 125 }; // microseconds of LBT time enum { AS923JP_LBT_DB_MAX = -80 }; // maximum channel strength -#endif /* _lorabase_as923_h_ */ \ No newline at end of file +#endif /* _lorabase_as923_h_ */ diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 9177f00f..37535e29 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -555,7 +555,6 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { - oslmic_radio_rssi_t rssi; u1_t const rOpMode = readReg(RegOpMode); // originally, this code ASSERT()ed, but asserts are both bad and @@ -566,12 +565,11 @@ static void starttx () { LMIC_DEBUG_PRINTF("?%s: OPMODE != OPMODE_SLEEP: %#02x\n", __func__, rOpMode); #endif opmode(OPMODE_SLEEP); - ostime_t tBegin = os_getTime(); - while (os_getTime() - tBegin < ms2osticks(1)) - /* idle */; + hal_waitUntil(os_getTime() + ms2osticks(1)); } if (LMIC.lbt_ticks > 0) { + oslmic_radio_rssi_t rssi; #if LMIC_DEBUG_LEVEL > 1 LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", os_getTime(), @@ -586,7 +584,10 @@ static void starttx () { u1_t bw = getBw(LMIC.rps); u1_t cr = getCr(LMIC.rps); LMIC_DEBUG_PRINTF("%lu: freq=%lu, SF=%d, BW=%d, CR=4/%d, interfering signal %d > %d dB\n", - os_getTime(), LMIC.freq, bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), + os_getTime(), + LMIC.freq, + sf, + bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), rssi.max_rssi, LMIC.lbt_dbmax @@ -861,11 +862,10 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { int rssiAdjust; ostime_t tBegin; + int notDone; rxlora(RXMODE_SCAN); - tBegin = os_getTime(); - // while we're waiting for the PLLs to spin up, determine which // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { @@ -881,14 +881,14 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { rssiN = 0; // wait for PLLs - while ((os_getTime() - tBegin) < SX127X_RX_POWER_UP) { - // nothing - } + hal_waitUntil(os_getTime() + SX127X_RX_POWER_UP); // scan for the desired time. tBegin = os_getTime(); rssiMax = 0; do { + ostime_t now; + u1_t rssiNow = readReg(LORARegRssiValue); if (rssiMax < rssiNow) @@ -897,7 +897,13 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { rssiMin = rssiNow; rssiSum += rssiNow; ++rssiN; - } while ((os_getTime() - tBegin) < nTicks); + now = os_getTime(); + notDone = now - (tBegin + nTicks) < 0; +// LMIC_DEBUG_PRINTF("%s: now: %d tBegin+nTicks: %ld notDone: %d\n", +// __func__, +// now, tBegin + nTicks, notDone +// ); + } while (notDone); // put radio back to sleep opmode(OPMODE_SLEEP); From c983d32903c31542d7a44be2c839d89224b69c40 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 22:54:36 -0500 Subject: [PATCH 28/73] Fix comparison so we get right adjust constants --- src/lmic/radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 37535e29..fe7cf632 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -869,9 +869,9 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { // while we're waiting for the PLLs to spin up, determine which // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { - rssiAdjust = SX127X_RSSI_ADJUST_LF; - } else { rssiAdjust = SX127X_RSSI_ADJUST_HF; + } else { + rssiAdjust = SX127X_RSSI_ADJUST_LF; } // zero the results From e115d1457a3be16e2e3a6405d925e30bb562e41d Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 22:55:03 -0500 Subject: [PATCH 29/73] remove dead code for debug --- src/lmic/radio.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index fe7cf632..220acca4 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -899,10 +899,6 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { ++rssiN; now = os_getTime(); notDone = now - (tBegin + nTicks) < 0; -// LMIC_DEBUG_PRINTF("%s: now: %d tBegin+nTicks: %ld notDone: %d\n", -// __func__, -// now, tBegin + nTicks, notDone -// ); } while (notDone); // put radio back to sleep From 16177b38203b4fa258ec582a998a7124ff9de94c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 23:20:02 -0500 Subject: [PATCH 30/73] Add rssi_cal field; make raw-feather adapt automatically to board in use --- examples/raw-feather/raw-feather.ino | 23 +++++++++++++++++++++-- src/hal/hal.cpp | 4 ++++ src/hal/hal.h | 17 +++++++++++------ src/lmic/hal.h | 5 +++++ src/lmic/radio.c | 1 + 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index fb1d2d1b..bf4487fa 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -74,14 +74,33 @@ Revision history: #define TX_INTERVAL 2000 // milliseconds #define RX_RSSI_INTERVAL 100 // milliseconds -// Pin mapping for Adafruit Feather M0 LoRa +// Pin mapping for Adafruit Feather M0 LoRa, etc. +#if defined(ARDUINO_SAMD_FEATHER_M0) const lmic_pinmap lmic_pins = { .nss = 8, .rxtx = LMIC_UNUSED_PIN, .rst = 4, .dio = {3, 6, LMIC_UNUSED_PIN}, + .rxtx_rx_active = 0, + .rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB + .spi_freq = 8000000, }; - +#elif defined(ARDUINO_CATENA_4551) +const lmic_pinmap lmic_pins = { + .nss = 7, + .rxtx = 29, + .rst = 8, + .dio = { 25, // DIO0 (IRQ) is D25 + 26, // DIO1 is D26 + 27, // DIO2 is D27 + }, + .rxtx_rx_active = 1, + .rssi_cal = 10, + .spi_freq = 8000000 // 8MHz +}; +#else +# error "Unknown target" +#endif // These callbacks are only used in over-the-air activation, so they are // left empty here (we cannot leave them out completely unless diff --git a/src/hal/hal.cpp b/src/hal/hal.cpp index d9aede92..74a23c7a 100644 --- a/src/hal/hal.cpp +++ b/src/hal/hal.cpp @@ -61,6 +61,10 @@ void hal_pin_rst (u1_t val) { } } +s1_t hal_getRssiCal (void) { + return plmic_pins->rssi_cal; +} + #if !defined(LMIC_USE_INTERRUPTS) static void hal_interrupt_init() { pinMode(plmic_pins->dio[0], INPUT); diff --git a/src/hal/hal.h b/src/hal/hal.h index f40e19f2..c5ea1007 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -12,13 +12,18 @@ static const int NUM_DIO = 3; +// be careful of alignment below. struct lmic_pinmap { - u1_t nss; - u1_t rxtx; - u1_t rst; - u1_t dio[NUM_DIO]; - u1_t rxtx_rx_active; - u4_t spi_freq; + u1_t nss; // byte 0: pin for select + u1_t rxtx; // byte 1: pin for rx/tx control + u1_t rst; // byte 2: pin for reset + u1_t dio[NUM_DIO]; // bytes 3..5: pins for DIO0, DOI1, DIO2 + // true if we must set rxtx for rx_active, false for tx_active + u1_t rxtx_rx_active; // byte 6: polarity of rxtx active + s1_t rssi_cal; // byte 7: cal in dB -- added to RSSI + // measured prior to decision. + // Must include noise guardband! + u4_t spi_freq; // bytes 8..11: SPI freq in Hz. }; // Use this for any unused pins. diff --git a/src/lmic/hal.h b/src/lmic/hal.h index b69e4fb4..562b4283 100644 --- a/src/lmic/hal.h +++ b/src/lmic/hal.h @@ -105,6 +105,11 @@ u1_t hal_checkTimer (u4_t targettime); */ void hal_failed (const char *file, u2_t line); +/* + * get the calibration value for radio_rssi + */ +s1_t hal_getRssiCal (void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 220acca4..c4c04fa5 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -873,6 +873,7 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { } else { rssiAdjust = SX127X_RSSI_ADJUST_LF; } + rssiAdjust += hal_getRssiCal(); // zero the results rssiMax = 255; From d26650ac3646d3c91e6c3ac6d971d5ed1e9ffab6 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 8 Oct 2017 06:05:36 -0700 Subject: [PATCH 31/73] Capture RSSI scan changes --- src/lmic/config.h | 11 ++++- src/lmic/lmic_config_preconditions.h | 10 ++++ src/lmic/oslmic.h | 9 ++++ src/lmic/radio.c | 73 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/lmic/config.h b/src/lmic/config.h index 3a86f036..cd0f3218 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -27,7 +27,12 @@ //#define CFG_in866 1 #if CFG_LMIC_REGION_MASK == 0 -# warning Target RF configuration not defined, assuming CFG_eu868 +# ifdef CFG_as923jp // if user defines this special symbol, treat as as923 +# define CFG_as923 1 +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP +# else +# warning Target RF configuration not defined, assuming CFG_eu868 +# endif # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK # error You can define at most one of CFG_... variables @@ -35,6 +40,10 @@ # error The selected CFG_... region is not supported yet. #endif +#ifndef LMIC_COUNTRY_CODE +# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE +#endif + #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif diff --git a/src/lmic/lmic_config_preconditions.h b/src/lmic/lmic_config_preconditions.h index cd925003..52ec4771 100644 --- a/src/lmic/lmic_config_preconditions.h +++ b/src/lmic/lmic_config_preconditions.h @@ -72,6 +72,16 @@ Revision history: #define LMIC_REGION_kr921 8 #define LMIC_REGION_in866 9 +// country codes for comparison. These values are chosen from the 2-letter domain suffixes (which +// I think are ISO standardized) +#define LMIC_COUNTRY_CODE_C(c1, c2) ((c1) * 256 + (c2)) + +// this special code means "no country code defined" +#define LMIC_COUNTRY_CODE_NONE 0 + +// specific countries. Only the ones that are known in the code are defined. +#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('j', 'p') + // include the file that the user is really supposed to edit. But for really strange // ports, this can be suppressed #ifndef ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 9e190333..069e4f71 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -96,6 +96,15 @@ u1_t radio_rand1 (void); #define DEFINE_LMIC struct lmic_t LMIC #define DECLARE_LMIC extern struct lmic_t LMIC +typedef struct oslmic_radio_rssi_s oslmic_radio_rssi_t; + +struct oslmic_radio_rssi_s { + s2_t min_rssi; + s2_t max_rssi; + s2_t mean_rssi; + u2_t n_rssi; +}; + int radio_init (void); void radio_irq_handler (u1_t dio); void os_init (void); diff --git a/src/lmic/radio.c b/src/lmic/radio.c index c3114e1b..505e9991 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -195,7 +195,17 @@ #define RXLORA_RXMODE_RSSI_REG_MODEM_CONFIG2 0x74 #endif +//----------------------------------------- +// Parameters for RSSI monitoring +#define SX127X_FREQ_LF_MAX 525000000 // per datasheet 6.3 +// per datasheet 5.5.3: +#define SX127X_RSSI_ADJUST_LF -164 // add to rssi value to get dB (LF) +#define SX127X_RSSI_ADJUST_HF -157 // add to rssi value to get dB (HF) + +// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because +// datasheet is unclear). +#define SX127X_RX_POWER_UP us2osticks(500) // delay this long to let the receiver power up. // ---------------------------------------- // Constants for radio registers @@ -791,6 +801,69 @@ u1_t radio_rssi () { return r; } +// monitor rssi for specified number of ostime_t ticks, and return statistics +// This puts the radio into RX continuous mode, waits long enough for the +// oscillators to start and the PLL to lock, and then measures for the specified +// period of time. The radio is then returned to idel. +// +// RSSI returned is expressed in units of dB, and is offset according to the +// current radio setting per section 5.5.5 of Semtech 1276 datasheet. +s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { + uint8_t rssiMax, rssiMin; + uint16_t rssiSum; + uint16_t rssiN; + + int rssiAdjust; + ostime_t tBegin; + + rxlora(RXMODE_SCAN); + + tBegin = os_getTime(); + + // while we're waiting for the PLLs to spin up, determine which + // band we're in and choose the base RSSI. + if (LMIC.freq > SX127X_FREQ_LF_MAX) { + rssiAdjust = SX127X_RSSI_ADJUST_LF; + } + else { + rssiAdjust = SX127X_RSSI_ADJUST_HF; + } + + // zero the results + rssiMax = 255; + rssiMin = 0; + rssiSum = 0; + rssiN = 0; + + // wait for PLLs + while ((os_getTime() - tBegin) < SX127X_RX_POWER_UP) { + // nothing + } + + // scan for the desired time. + tBegin = os_getTime(); + rssiMax = 0; + do { + u1_t rssiNow = readReg(LORARegRssiValue); + + if (rssiMax < rssiNow) + rssiMax = rssiNow; + if (rssiNow < rssiMin) + rssiMin = rssiNow; + rssiSum += rssiNow; + ++rssiN; + } while ((os_getTime() - tBegin) < nTicks); + + // put radio back to sleep + opmode(OPMODE_SLEEP); + + // compute the results + pRssi->max_rssi = (s2_t) (rssiMax + rssiAdjust); + pRssi->min_rssi = (s2_t) (rssiMin + rssiAdjust); + pRssi->mean_rssi = (s2_t) (rssiAdjust + ((rssiSum + (rssiN >> 1)) / rssiN)); + pRssi->n_rssi = rssiN; +} + static CONST_TABLE(u2_t, LORA_RXDONE_FIXUP)[] = { [FSK] = us2osticks(0), // ( 0 ticks) [SF7] = us2osticks(0), // ( 0 ticks) From 02392b2cb91c6673f4b47acaef1b9b5203d260a4 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:34:53 -0400 Subject: [PATCH 32/73] Correct definition, add prototype for the RSSI monitor function --- src/lmic/oslmic.h | 5 +++-- src/lmic/radio.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 069e4f71..1cef61bf 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -73,6 +73,8 @@ typedef struct rxsched_t rxsched_t; typedef struct bcninfo_t bcninfo_t; typedef const u1_t* xref2cu1_t; typedef u1_t* xref2u1_t; +typedef s4_t ostime_t; + #define TYPEDEF_xref2rps_t typedef rps_t* xref2rps_t #define TYPEDEF_xref2rxsched_t typedef rxsched_t* xref2rxsched_t #define TYPEDEF_xref2chnldef_t typedef chnldef_t* xref2chnldef_t @@ -112,6 +114,7 @@ int os_init_ex (const void *pPinMap); void os_runloop (void); void os_runloop_once (void); u1_t radio_rssi (void); +void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi); //================================================================================ @@ -129,8 +132,6 @@ u1_t radio_rssi (void); #error Illegal OSTICKS_PER_SEC - must be in range [10000:64516]. One tick must be 15.5us .. 100us long. #endif -typedef s4_t ostime_t; - #if !HAS_ostick_conv #define us2osticks(us) ((ostime_t)( ((int64_t)(us) * OSTICKS_PER_SEC) / 1000000)) #define ms2osticks(ms) ((ostime_t)( ((int64_t)(ms) * OSTICKS_PER_SEC) / 1000)) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 505e9991..124cf19d 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -808,7 +808,7 @@ u1_t radio_rssi () { // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. -s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { +void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { uint8_t rssiMax, rssiMin; uint16_t rssiSum; uint16_t rssiN; From 4280a09d05c339d7374d65474e3f5228f0718838 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:36:45 -0400 Subject: [PATCH 33/73] fix commentary --- examples/raw-feather/raw-feather.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 82b2f84c..de57f6ae 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -227,7 +227,9 @@ void setup() { // guides the responder through all the channels, powers, ramps // the transmit power from min to max, and measures the RSSI and SNR. // Even more amazing would be a scheme where the controller could - // handle multiple nodes; in that case we'd have a + // handle multiple nodes; in that case we'd have a way to do + // production test and qualification. However, using an RWC5020A + // is a much better use of development time. const static bool fDownlink = true; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; From f0793d2cc8efdba44f6b2853625b9049ff50127f Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:41:57 -0400 Subject: [PATCH 34/73] Add check for unsupported band --- examples/raw-feather/raw-feather.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index de57f6ae..8dc95fd5 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -266,6 +266,8 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#else +# error Unsupported LMIC regional configuration. #endif // disable RX IQ inversion From 0553b0f62900e9c931b4b94e48b34c809056234a Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:43:45 -0400 Subject: [PATCH 35/73] Change to test of downlink channel 3 and DR4 --- examples/raw-feather/raw-feather.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 8dc95fd5..dacfaca7 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -230,7 +230,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static bool fDownlink = true; + const static bool fDownlink = false; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; uint32_t uBandwidth; @@ -260,9 +260,9 @@ void setup() { // Use a suitable spreading factor if (uBandwidth < 500) - LMIC.datarate = DR_SF10; // DR0 + LMIC.datarate = US915_DR_SF7; // DR4 else - LMIC.datarate = DR_SF12CR; // DR8 + LMIC.datarate = US915_DR_SF12CR; // DR8 // default tx power for US: 21 dBm LMIC.txpow = 21; From defd4e629898e85ea663a79fc7d8144e50948042 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:44:25 -0400 Subject: [PATCH 36/73] Check and display RSSI prior to transmit --- examples/raw-feather/raw-feather.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index dacfaca7..4051589e 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -72,6 +72,7 @@ Revision history: // https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc #define TX_INTERVAL 2000 // milliseconds +#define RX_RSSI_INTERVAL 100 // milliseconds #ifdef ARDUINO_ARCH_SAMD // Pin mapping for Adafruit Feather M0 LoRa @@ -118,8 +119,19 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { + oslmic_radio_rssi_t rssi; os_radio(RADIO_RST); // Stop RX first delay(1); // Wait a bit, without this os_radio below asserts, apparently because the state hasn't changed yet + + // if requested, scan RSSI (LBT). On a Feather, it's about 42 us/sample. + if (RX_RSSI_INTERVAL > 0) { + radio_monitor_rssi(ms2osticks(RX_RSSI_INTERVAL), &rssi); + Serial.print("RSSI results (dB): min: "); Serial.print(rssi.min_rssi); + Serial.print(" max: "); Serial.print(rssi.max_rssi); + Serial.print(" mean: "); Serial.print(rssi.mean_rssi); + Serial.print(" n: "); Serial.println(rssi.n_rssi); + } + LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; From 5087facdabadd1333477ec13329db541845414ab Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:38:49 -0500 Subject: [PATCH 37/73] Change the RFU bits for DN2P_ANS to F8 per LoRaWAN 1.0.2 --- src/lmic/lorabase.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lmic/lorabase.h b/src/lmic/lorabase.h index 7368329f..3e57a9cd 100644 --- a/src/lmic/lorabase.h +++ b/src/lmic/lorabase.h @@ -483,7 +483,8 @@ enum { MCMD_LADR_ANS_CHACK = 0x01, // 0=unknown channel enabled }; enum { - MCMD_DN2P_ANS_RFU = 0xFC, // RFU bits + MCMD_DN2P_ANS_RFU = 0xF8, // RFU bits + MCMD_DN2P_ANS_RX1DrOffsetAck = 0x04, // 0=dr2 not allowed MCMD_DN2P_ANS_DRACK = 0x02, // 0=unknown data rate MCMD_DN2P_ANS_CHACK = 0x01, // 0=unknown channel enabled }; From 16f6efacda96d739f168f97621fa4adf94658964 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 11 Nov 2017 17:42:00 -0500 Subject: [PATCH 38/73] Improve handling of rx1DrOffset, switch order of response per 1.0.2 --- src/lmic/lmic.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 10039b97..022dcdf1 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -615,15 +615,20 @@ scan_mac_cmds( case MCMD_DN2P_SET: { #if !defined(DISABLE_MCMD_DN2P_SET) dr_t dr = (dr_t)(opts[oidx+1] & 0x0F); + u1_t rx1DrOffset = (u1_t)((opts[oidx+1] & 0x70) >> 4); u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]); LMIC.dn2Ans = 0x80; // answer pending if( validDR(dr) ) LMIC.dn2Ans |= MCMD_DN2P_ANS_DRACK; if( freq != 0 ) LMIC.dn2Ans |= MCMD_DN2P_ANS_CHACK; - if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK) ) { + if (rx1DrOffset <= 3) + LMIC.dn2Ans |= MCMD_DN2P_ANS_RX1DrOffsetAck; + + if( LMIC.dn2Ans == (0x80|MCMD_DN2P_ANS_DRACK|MCMD_DN2P_ANS_CHACK| MCMD_DN2P_ANS_RX1DrOffsetAck) ) { LMIC.dn2Dr = dr; LMIC.dn2Freq = freq; + LMIC.rx1DrOffset = rx1DrOffset; DO_DEVDB(LMIC.dn2Dr,dn2Dr); DO_DEVDB(LMIC.dn2Freq,dn2Freq); } @@ -1223,14 +1228,6 @@ static void buildDataFrame (void) { LMIC.dutyCapAns = 0; } #endif // !DISABLE_MCMD_DCAP_REQ -#if !defined(DISABLE_MCMD_DN2P_SET) - if( LMIC.dn2Ans ) { - LMIC.frame[end+0] = MCMD_DN2P_ANS; - LMIC.frame[end+1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; - end += 2; - LMIC.dn2Ans = 0; - } -#endif // !DISABLE_MCMD_DN2P_SET if( LMIC.devsAns ) { // answer to device status LMIC.frame[end+0] = MCMD_DEVS_ANS; LMIC.frame[end+1] = os_getBattLevel(); @@ -1255,6 +1252,14 @@ static void buildDataFrame (void) { LMIC.adrAckReq = 0; LMIC.adrChanged = 0; } +#if !defined(DISABLE_MCMD_DN2P_SET) + if (LMIC.dn2Ans) { + LMIC.frame[end + 0] = MCMD_DN2P_ANS; + LMIC.frame[end + 1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU; + end += 2; + LMIC.dn2Ans = 0; + } +#endif // !DISABLE_MCMD_DN2P_SET #if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING) if( LMIC.pingSetAns != 0 ) { LMIC.frame[end+0] = MCMD_PING_ANS; From d66b06cabc1ce90c596f4b34ebbb855ce58461c6 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 8 Oct 2017 06:05:36 -0700 Subject: [PATCH 39/73] Capture RSSI scan changes --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 124cf19d..505e9991 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -808,7 +808,7 @@ u1_t radio_rssi () { // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. -void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { +s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { uint8_t rssiMax, rssiMin; uint16_t rssiSum; uint16_t rssiN; From 81bf57f1f36ffced08b2e14d663b5daa2737f164 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:34:53 -0400 Subject: [PATCH 40/73] Correct definition, add prototype for the RSSI monitor function --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 505e9991..124cf19d 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -808,7 +808,7 @@ u1_t radio_rssi () { // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. -s2_t radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { +void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { uint8_t rssiMax, rssiMin; uint16_t rssiSum; uint16_t rssiN; From 10bffa2655cdb96d482f1b59653a53489102cfe2 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:36:45 -0400 Subject: [PATCH 41/73] fix commentary --- examples/raw-feather/raw-feather.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 4051589e..591e4bd8 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -242,7 +242,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static bool fDownlink = false; + const static bool fDownlink = true; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; uint32_t uBandwidth; From 01c503a7dfd422bb1fffbc62a027f4348758488c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Oct 2017 23:43:45 -0400 Subject: [PATCH 42/73] Change to test of downlink channel 3 and DR4 --- examples/raw-feather/raw-feather.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 591e4bd8..4051589e 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -242,7 +242,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static bool fDownlink = true; + const static bool fDownlink = false; const static uint8_t kDownlinkChannel = 3; const static uint8_t kUplinkChannel = 8 + 3; uint32_t uBandwidth; From dba7a1131a1b66381040ad32f3ff69d5785e0657 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:49:02 -0500 Subject: [PATCH 43/73] Add LBT support, and set it up for Japan --- examples/raw-feather/raw-feather.ino | 40 +++++++++++++++++---------- src/lmic/config.h | 11 ++++---- src/lmic/lmic.h | 5 ++++ src/lmic/lmic_as923.c | 6 ++++ src/lmic/lorabase_as923.h | 3 ++ src/lmic/radio.c | 41 ++++++++++++++++++++++++---- 6 files changed, 81 insertions(+), 25 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 4051589e..776eac04 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -119,19 +119,6 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { - oslmic_radio_rssi_t rssi; - os_radio(RADIO_RST); // Stop RX first - delay(1); // Wait a bit, without this os_radio below asserts, apparently because the state hasn't changed yet - - // if requested, scan RSSI (LBT). On a Feather, it's about 42 us/sample. - if (RX_RSSI_INTERVAL > 0) { - radio_monitor_rssi(ms2osticks(RX_RSSI_INTERVAL), &rssi); - Serial.print("RSSI results (dB): min: "); Serial.print(rssi.min_rssi); - Serial.print(" max: "); Serial.print(rssi.max_rssi); - Serial.print(" mean: "); Serial.print(rssi.mean_rssi); - Serial.print(" n: "); Serial.println(rssi.n_rssi); - } - LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; @@ -278,14 +265,39 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#elif defined(CFG_as923) +// make it easier for test, by pull the parameters up to the top of the +// block. Ideally, we'd use the serial port to drive this; or have +// a voting protocol where one side is elected the controller and +// guides the responder through all the channels, powers, ramps +// the transmit power from min to max, and measures the RSSI and SNR. +// Even more amazing would be a scheme where the controller could +// handle multiple nodes; in that case we'd have a way to do +// production test and qualification. However, using an RWC5020A +// is a much better use of development time. + const static uint8_t kChannel = 1; + uint32_t uBandwidth; + + LMIC.freq = AS923_F1 + kChannel * 200000; + uBandwidth = 125; + + // Use a suitable spreading factor + if (uBandwidth == 125) + LMIC.datarate = AS923_DR_SF7; // DR7 + else + LMIC.datarate = AS923_DR_SF7B; // DR8 + + // default tx power for US: 21 dBm + LMIC.txpow = 16; #else # error Unsupported LMIC regional configuration. #endif + // disable RX IQ inversion LMIC.noRXIQinversion = true; - // This sets CR 4/5, BW125 (except for EU DR_SF7B, which uses BW250) + // This sets CR 4/5, BW125 (except for EU/AS923 DR_SF7B, which uses BW250) LMIC.rps = updr2rps(LMIC.datarate); Serial.print("Frequency: "); Serial.print(LMIC.freq / 1000000); diff --git a/src/lmic/config.h b/src/lmic/config.h index cd0f3218..4fccc320 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -27,12 +27,6 @@ //#define CFG_in866 1 #if CFG_LMIC_REGION_MASK == 0 -# ifdef CFG_as923jp // if user defines this special symbol, treat as as923 -# define CFG_as923 1 -# define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP -# else -# warning Target RF configuration not defined, assuming CFG_eu868 -# endif # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK # error You can define at most one of CFG_... variables @@ -44,6 +38,11 @@ # define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE #endif +// if the country code is japan, then the region must be AS923 +#if LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP && CFG_region != LMIC_REGION_as923 +# error "If country code is JP, then region must be AS923" +#endif + #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index 2145e1f3..0b902809 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -207,6 +207,11 @@ struct lmic_t { // Radio settings TX/RX (also accessed by HAL) ostime_t txend; ostime_t rxtime; + + // LBT info + ostime_t lbt_ticks; // ticks to listen + s1_t lbt_dbmax; // max permissible dB on our channle (eg -80) + u4_t freq; s1_t rssi; s1_t snr; diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 13b9d31a..33b1017e 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -179,6 +179,12 @@ void LMICas923_initDefaultChannels(bit_t join) { LMIC.bands[BAND_CENTI].txpow = AS923_TX_EIRP_MAX_DBM; LMIC.bands[BAND_CENTI].lastchnl = os_getRndU1() % MAX_CHANNELS; LMIC.bands[BAND_CENTI].avail = os_getTime(); + + // if this is japan, set LBT mode + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { + LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; + } } bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) { diff --git a/src/lmic/lorabase_as923.h b/src/lmic/lorabase_as923.h index aa5e62e3..dbd936ac 100644 --- a/src/lmic/lorabase_as923.h +++ b/src/lmic/lorabase_as923.h @@ -74,4 +74,7 @@ enum { DR_PAGE_AS923 = 0x10 * (LMIC_REGION_as923 - 1) }; enum { AS923_LMIC_REGION_EIRP = 1 }; // region uses EIRP +enum { AS923JP_LBT_MS = 100 }; // milliseconds of LBT time +enum { AS923JP_LBT_DB_MAX = -80 }; // maximum channel strength + #endif /* _lorabase_as923_h_ */ \ No newline at end of file diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 124cf19d..9cd7b325 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -203,7 +203,7 @@ #define SX127X_RSSI_ADJUST_LF -164 // add to rssi value to get dB (LF) #define SX127X_RSSI_ADJUST_HF -157 // add to rssi value to get dB (HF) -// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because +// per datasheet 2.5.2 (but note that we ought to ask Semtech to confirm, because // datasheet is unclear). #define SX127X_RX_POWER_UP us2osticks(500) // delay this long to let the receiver power up. @@ -559,7 +559,39 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { + oslmic_radio_rssi_t rssi; + ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP ); + + if (LMIC.lbt_ticks > 0) { + radio_monitor_rssi(LMIC.lbt_ticks, &rssi); + + if (rssi.max_rssi >= LMIC.lbt_dbmax) { +#if LMIC_DEBUG_LEVEL > 0 + u1_t sf = getSf(LMIC.rps) + 6; // 1 == SF7 + u1_t bw = getBw(LMIC.rps); + u1_t cr = getCr(LMIC.rps); + LMIC_DEBUG_PRINTF("%lu: freq=%lu, SF=%d, BW=%d, CR=4/%d, interfering signal %d > %d dB\n", + os_getTime(), LMIC.freq, bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), + cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), + rssi.max_rssi, + LMIC.lbt_dbmax + ) +#endif + // complete the request by scheduling the job + os_setCallback(&LMIC.osjob, LMIC.osjob.func); + return; + } + +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%lu: freq=%lu, interfering signal %d < %d dB\n", + os_getTime(), LMIC.freq, + rssi.max_rssi, + LMIC.lbt_dbmax + ) +#endif + } + if(getSf(LMIC.rps) == FSK) { // FSK modem txfsk(); } else { // LoRa modem @@ -802,9 +834,9 @@ u1_t radio_rssi () { } // monitor rssi for specified number of ostime_t ticks, and return statistics -// This puts the radio into RX continuous mode, waits long enough for the +// This puts the radio into RX continuous mode, waits long enough for the // oscillators to start and the PLL to lock, and then measures for the specified -// period of time. The radio is then returned to idel. +// period of time. The radio is then returned to idle. // // RSSI returned is expressed in units of dB, and is offset according to the // current radio setting per section 5.5.5 of Semtech 1276 datasheet. @@ -824,8 +856,7 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { rssiAdjust = SX127X_RSSI_ADJUST_LF; - } - else { + } else { rssiAdjust = SX127X_RSSI_ADJUST_HF; } From 332a2e13eff457337015ff4c12ad0496a735591a Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:49:38 -0500 Subject: [PATCH 44/73] Ignore vs code context --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f8afde11..9cd777e9 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,5 @@ Release vs-readme.txt __vm .vs -*.sln - -# files from vscode .vscode + From b3c6e4680d2ae2fa30d4027f113623d2ed3c3b3a Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 20 Jan 2018 20:50:19 -0500 Subject: [PATCH 45/73] For this branch only, switch to AS923/Japan --- project_config/lmic_project_config.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index eb608dac..e9e1d938 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -1,8 +1,9 @@ // project-specific definitions for otaa sensor //#define CFG_eu868 1 -#define CFG_us915 1 +//#define CFG_us915 1 //#define CFG_au921 1 -//#define CFG_as923 1 +#define CFG_as923 1 +#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS From 3653f1837f7eefda3d896d6cdbeaf48bc81a52a4 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 10:09:03 -0500 Subject: [PATCH 46/73] Fix syntax error in debug print --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 9cd7b325..1cb09a19 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -576,7 +576,7 @@ static void starttx () { cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), rssi.max_rssi, LMIC.lbt_dbmax - ) + ); #endif // complete the request by scheduling the job os_setCallback(&LMIC.osjob, LMIC.osjob.func); From 4810fe359d4fca7c22310ea489b1e32841b163d4 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 11:17:51 -0500 Subject: [PATCH 47/73] Restore missing os_radio(RADIO_RST) before tx --- examples/raw-feather/raw-feather.ino | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 776eac04..32b6bf81 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -119,10 +119,20 @@ static void tx_func (osjob_t* job); // Transmit the given string and call the given function afterwards void tx(const char *str, osjobcb_t func) { + // the radio is probably in RX mode; stop it. + os_radio(RADIO_RST); + // wait a bit so the radio can come out of RX mode + delay(1); + + // prepare data LMIC.dataLen = 0; while (*str) LMIC.frame[LMIC.dataLen++] = *str++; + + // set completion function. LMIC.osjob.func = func; + + // start the transmission os_radio(RADIO_TX); Serial.println("TX"); } From f8535ed42eb8fbf5d2e813a1bf4584749e281f47 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:08:32 -0500 Subject: [PATCH 48/73] fix typo in debug print --- src/lmic/radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 1cb09a19..a5ea5ee8 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -588,7 +588,7 @@ static void starttx () { os_getTime(), LMIC.freq, rssi.max_rssi, LMIC.lbt_dbmax - ) + ); #endif } From ac8d78bb7c71006ac68a83dc944fa1d4c9f3b172 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:09:08 -0500 Subject: [PATCH 49/73] add a suitable print function for debugging --- examples/raw-feather/raw-feather.ino | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 32b6bf81..5a566bb2 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -53,6 +53,9 @@ Revision history: #include #include +#include +#include + // we formerly would check this configuration; but now there is a flag, // in the LMIC, LMIC.noRXIQinversion; // if we set that during init, we get the same effect. If @@ -113,6 +116,26 @@ void os_getDevKey (u1_t* buf) { } void onEvent (ev_t ev) { } +extern "C" { +void lmic_printf(const char *fmt, ...); +}; + +void lmic_printf(const char *fmt, ...) { + if (! Serial.dtr()) + return; + + char buf[256]; + va_list ap; + + va_start(ap, fmt); + (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap); + va_end(ap); + + // in case we overflowed: + buf[sizeof(buf) - 1] = '\0'; + if (Serial.dtr()) Serial.print(buf); +} + osjob_t txjob; osjob_t timeoutjob; static void tx_func (osjob_t* job); From b4efe8788da54f5fd42311a4cc8d8d432b181167 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 12:09:47 -0500 Subject: [PATCH 50/73] Set debug level to 2 and use a suitable printf function --- project_config/lmic_project_config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index e9e1d938..08dcf403 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -7,3 +7,5 @@ //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS +#define LMIC_DEBUG_LEVEL 2 +#define LMIC_DEBUG_PRINTF_FN lmic_printf From cfaf439c141286785668fa4ba7990881aea05995 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 13:07:55 -0500 Subject: [PATCH 51/73] Add init/reset routines for LMIC and set JP LBT params --- src/lmic/lmic.c | 1 + src/lmic/lmic_as923.c | 13 +++++++++++++ src/lmic/lmic_bandplan.h | 3 +++ src/lmic/lmic_bandplan_as923.h | 16 ++++++++++++++++ src/lmic/lmic_eu_like.h | 3 +++ src/lmic/lmic_us_like.h | 2 ++ 6 files changed, 38 insertions(+) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 022dcdf1..a42f4f08 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -1871,6 +1871,7 @@ void LMIC_reset (void) { void LMIC_init (void) { LMIC.opmode = OP_SHUTDOWN; + LMICbandplan_init(); } diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 33b1017e..9417ddaf 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -179,7 +179,10 @@ void LMICas923_initDefaultChannels(bit_t join) { LMIC.bands[BAND_CENTI].txpow = AS923_TX_EIRP_MAX_DBM; LMIC.bands[BAND_CENTI].lastchnl = os_getRndU1() % MAX_CHANNELS; LMIC.bands[BAND_CENTI].avail = os_getTime(); +} +void +LMICas923_init(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); @@ -187,6 +190,16 @@ void LMICas923_initDefaultChannels(bit_t join) { } } +void +LMICas923_resetDefaultChannels(void) { + // if this is japan, set LBT mode + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { + LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; + } +} + + bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) { if (bandidx != BAND_CENTI) return 0; //band_t* b = &LMIC.bands[bandidx]; diff --git a/src/lmic/lmic_bandplan.h b/src/lmic/lmic_bandplan.h index 6aa2c743..0c3c5036 100644 --- a/src/lmic/lmic_bandplan.h +++ b/src/lmic/lmic_bandplan.h @@ -140,6 +140,9 @@ # error "LMICbandplan_nextJoinTime() not defined by bandplan" #endif +#if !defined(LMICbandplan_init) +# error "LMICbandplan_init() not defined by bandplan" +#endif // // Things common to lmic.c code // diff --git a/src/lmic/lmic_bandplan_as923.h b/src/lmic/lmic_bandplan_as923.h index 10dd2224..50017f29 100644 --- a/src/lmic/lmic_bandplan_as923.h +++ b/src/lmic/lmic_bandplan_as923.h @@ -52,6 +52,22 @@ LMICas923_isValidBeacon1(const uint8_t *d) { #undef LMICbandplan_isValidBeacon1 #define LMICbandplan_isValidBeacon1(pFrame) LMICas923_isValidBeacon1(pFrame) +// override default for LMICbandplan_resetDefaultChannels +void +LMICas923_resetDefaultChannels(void); + +#undef LMICbandplan_resetDefaultChannels +#define LMICbandplan_resetDefaultChannels() \ + LMICas923_resetDefaultChannels() + +// override default for LMICbandplan_init +void LMICas923_init(void); + +#undef LMICbandplan_init +#define LMICbandplan_init() \ + LMICas923_init() + + // override default for LMICbandplan_isFSK() #undef LMICbandplan_isFSK #define LMICbandplan_isFSK() (/* TX datarate */LMIC.rxsyms == AS923_DR_FSK) diff --git a/src/lmic/lmic_eu_like.h b/src/lmic/lmic_eu_like.h index e6ea820e..f147790d 100644 --- a/src/lmic/lmic_eu_like.h +++ b/src/lmic/lmic_eu_like.h @@ -92,4 +92,7 @@ static inline ostime_t LMICeulike_nextJoinTime(ostime_t now) { } #define LMICbandplan_nextJoinTime(now) LMICeulike_nextJoinTime(now) +#define LMICbandplan_init() \ + do { /* nothing */ } while (0) + #endif // _lmic_eu_like_h_ diff --git a/src/lmic/lmic_us_like.h b/src/lmic/lmic_us_like.h index 7a35b208..66bc549a 100644 --- a/src/lmic/lmic_us_like.h +++ b/src/lmic/lmic_us_like.h @@ -94,5 +94,7 @@ static inline ostime_t LMICeulike_nextJoinTime(ostime_t now) { } #define LMICbandplan_nextJoinTime(now) LMICeulike_nextJoinTime(now) +#define LMICbandplan_init() \ + do { /* nothing */ } while (0) #endif // _lmic_us_like_h_ From 5e30c235eb71c7ce9922b2db646b3712b1d68124 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 22 Jan 2018 13:26:38 -0500 Subject: [PATCH 52/73] Add debug prints, don't ASSERT() if not idle w/ starttx() --- src/lmic/radio.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index a5ea5ee8..a118de34 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -560,10 +560,28 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { oslmic_radio_rssi_t rssi; + u1_t const rOpMode = readReg(RegOpMode); - ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP ); + // originally, this code ASSERT()ed, but asserts are both bad and + // blunt instruments. If we see that we're not in sleep mode, + // force sleep (because we might have to switch modes) + if ((rOpMode & OPMODE_MASK) != OPMODE_SLEEP) { +#if LMIC_DEBUG_LEVEL > 0 + LMIC_DEBUG_PRINTF("?%s: OPMODE != OPMODE_SLEEP: %#02x\n", __func__, rOpMode); +#endif + opmode(OPMODE_SLEEP); + ostime_t tBegin = os_getTime(); + while (os_getTime() - tBegin < ms2osticks(1)) + /* idle */; + } if (LMIC.lbt_ticks > 0) { +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", + os_getTime(), + LMIC.lbt_ticks + ); +#endif radio_monitor_rssi(LMIC.lbt_ticks, &rssi); if (rssi.max_rssi >= LMIC.lbt_dbmax) { From 9f8f82bff7deb8928f90155f25c56d3a5e6963a5 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 23 Jan 2018 00:47:10 -0500 Subject: [PATCH 53/73] Switch to microsec resolution for JP LBT, and restrucrue wait loop --- src/lmic/lmic_as923.c | 4 ++-- src/lmic/lorabase_as923.h | 4 ++-- src/lmic/radio.c | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 9417ddaf..f1e4b101 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -185,7 +185,7 @@ void LMICas923_init(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { - LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; } } @@ -194,7 +194,7 @@ void LMICas923_resetDefaultChannels(void) { // if this is japan, set LBT mode if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) { - LMIC.lbt_ticks = ms2osticks(AS923JP_LBT_MS); + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; } } diff --git a/src/lmic/lorabase_as923.h b/src/lmic/lorabase_as923.h index dbd936ac..2b95249c 100644 --- a/src/lmic/lorabase_as923.h +++ b/src/lmic/lorabase_as923.h @@ -74,7 +74,7 @@ enum { DR_PAGE_AS923 = 0x10 * (LMIC_REGION_as923 - 1) }; enum { AS923_LMIC_REGION_EIRP = 1 }; // region uses EIRP -enum { AS923JP_LBT_MS = 100 }; // milliseconds of LBT time +enum { AS923JP_LBT_US = 125 }; // microseconds of LBT time enum { AS923JP_LBT_DB_MAX = -80 }; // maximum channel strength -#endif /* _lorabase_as923_h_ */ \ No newline at end of file +#endif /* _lorabase_as923_h_ */ diff --git a/src/lmic/radio.c b/src/lmic/radio.c index a118de34..24536d45 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -559,7 +559,6 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { - oslmic_radio_rssi_t rssi; u1_t const rOpMode = readReg(RegOpMode); // originally, this code ASSERT()ed, but asserts are both bad and @@ -570,12 +569,11 @@ static void starttx () { LMIC_DEBUG_PRINTF("?%s: OPMODE != OPMODE_SLEEP: %#02x\n", __func__, rOpMode); #endif opmode(OPMODE_SLEEP); - ostime_t tBegin = os_getTime(); - while (os_getTime() - tBegin < ms2osticks(1)) - /* idle */; + hal_waitUntil(os_getTime() + ms2osticks(1)); } if (LMIC.lbt_ticks > 0) { + oslmic_radio_rssi_t rssi; #if LMIC_DEBUG_LEVEL > 1 LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", os_getTime(), @@ -590,7 +588,10 @@ static void starttx () { u1_t bw = getBw(LMIC.rps); u1_t cr = getCr(LMIC.rps); LMIC_DEBUG_PRINTF("%lu: freq=%lu, SF=%d, BW=%d, CR=4/%d, interfering signal %d > %d dB\n", - os_getTime(), LMIC.freq, bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), + os_getTime(), + LMIC.freq, + sf, + bw == BW125 ? 125 : (bw == BW250 ? 250 : 500), cr == CR_4_5 ? 5 : (cr == CR_4_6 ? 6 : (cr == CR_4_7 ? 7 : 8)), rssi.max_rssi, LMIC.lbt_dbmax @@ -865,11 +866,10 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { int rssiAdjust; ostime_t tBegin; + int notDone; rxlora(RXMODE_SCAN); - tBegin = os_getTime(); - // while we're waiting for the PLLs to spin up, determine which // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { @@ -885,14 +885,14 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { rssiN = 0; // wait for PLLs - while ((os_getTime() - tBegin) < SX127X_RX_POWER_UP) { - // nothing - } + hal_waitUntil(os_getTime() + SX127X_RX_POWER_UP); // scan for the desired time. tBegin = os_getTime(); rssiMax = 0; do { + ostime_t now; + u1_t rssiNow = readReg(LORARegRssiValue); if (rssiMax < rssiNow) @@ -901,7 +901,13 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { rssiMin = rssiNow; rssiSum += rssiNow; ++rssiN; - } while ((os_getTime() - tBegin) < nTicks); + now = os_getTime(); + notDone = now - (tBegin + nTicks) < 0; +// LMIC_DEBUG_PRINTF("%s: now: %d tBegin+nTicks: %ld notDone: %d\n", +// __func__, +// now, tBegin + nTicks, notDone +// ); + } while (notDone); // put radio back to sleep opmode(OPMODE_SLEEP); From 830d5fe2a9250a0be3bc0ada82b4231752cd77d0 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 22:54:36 -0500 Subject: [PATCH 54/73] Fix comparison so we get right adjust constants --- src/lmic/radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 24536d45..d6c89c39 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -873,9 +873,9 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { // while we're waiting for the PLLs to spin up, determine which // band we're in and choose the base RSSI. if (LMIC.freq > SX127X_FREQ_LF_MAX) { - rssiAdjust = SX127X_RSSI_ADJUST_LF; - } else { rssiAdjust = SX127X_RSSI_ADJUST_HF; + } else { + rssiAdjust = SX127X_RSSI_ADJUST_LF; } // zero the results From 5e7ae6177dc8adce98e219d3ee2a534b33df10db Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 22:55:03 -0500 Subject: [PATCH 55/73] remove dead code for debug --- src/lmic/radio.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index d6c89c39..7b53d95e 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -903,10 +903,6 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { ++rssiN; now = os_getTime(); notDone = now - (tBegin + nTicks) < 0; -// LMIC_DEBUG_PRINTF("%s: now: %d tBegin+nTicks: %ld notDone: %d\n", -// __func__, -// now, tBegin + nTicks, notDone -// ); } while (notDone); // put radio back to sleep From 28dc5a65a9a4e6322af5280d801e5c36d11b2861 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Wed, 24 Jan 2018 23:20:02 -0500 Subject: [PATCH 56/73] Add rssi_cal field; make raw-feather adapt automatically to board in use --- examples/raw-feather/raw-feather.ino | 35 ++++++++++++++-------------- src/hal/hal.cpp | 4 ++++ src/hal/hal.h | 17 +++++++++----- src/lmic/hal.h | 5 ++++ src/lmic/radio.c | 1 + 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 5a566bb2..c9b7db0f 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -77,33 +77,34 @@ Revision history: #define TX_INTERVAL 2000 // milliseconds #define RX_RSSI_INTERVAL 100 // milliseconds -#ifdef ARDUINO_ARCH_SAMD -// Pin mapping for Adafruit Feather M0 LoRa +// Pin mapping for Adafruit Feather M0 LoRa, etc. +#if defined(ARDUINO_SAMD_FEATHER_M0) const lmic_pinmap lmic_pins = { .nss = 8, .rxtx = LMIC_UNUSED_PIN, .rst = 4, .dio = {3, 6, LMIC_UNUSED_PIN}, + .rxtx_rx_active = 0, + .rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB + .spi_freq = 8000000, }; -#endif - -#ifdef ARDUINO_ARCH_STM32 -// Pin mapping for Catena 4551 Feather M0 LoRa +#elif defined(ARDUINO_CATENA_4551) const lmic_pinmap lmic_pins = { - .nss = D7, // chip select is D7 - .rxtx = D29, // RXTX is D29 - .rst = D8, // NRESET is D8 - - .dio = {D25, // DIO0 (IRQ) is D25 - D26, // DIO1 is D26 - D27, // DIO2 is D27 - }, - .rxtx_rx_active = 1, - .spi_freq = 8000000 /* 8MHz */ + .nss = 7, + .rxtx = 29, + .rst = 8, + .dio = { 25, // DIO0 (IRQ) is D25 + 26, // DIO1 is D26 + 27, // DIO2 is D27 + }, + .rxtx_rx_active = 1, + .rssi_cal = 10, + .spi_freq = 8000000 // 8MHz }; +#else +# error "Unknown target" #endif - // These callbacks are only used in over-the-air activation, so they are // left empty here (we cannot leave them out completely unless // DISABLE_JOIN is set in config.h, otherwise the linker will complain). diff --git a/src/hal/hal.cpp b/src/hal/hal.cpp index d9aede92..74a23c7a 100644 --- a/src/hal/hal.cpp +++ b/src/hal/hal.cpp @@ -61,6 +61,10 @@ void hal_pin_rst (u1_t val) { } } +s1_t hal_getRssiCal (void) { + return plmic_pins->rssi_cal; +} + #if !defined(LMIC_USE_INTERRUPTS) static void hal_interrupt_init() { pinMode(plmic_pins->dio[0], INPUT); diff --git a/src/hal/hal.h b/src/hal/hal.h index f40e19f2..c5ea1007 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -12,13 +12,18 @@ static const int NUM_DIO = 3; +// be careful of alignment below. struct lmic_pinmap { - u1_t nss; - u1_t rxtx; - u1_t rst; - u1_t dio[NUM_DIO]; - u1_t rxtx_rx_active; - u4_t spi_freq; + u1_t nss; // byte 0: pin for select + u1_t rxtx; // byte 1: pin for rx/tx control + u1_t rst; // byte 2: pin for reset + u1_t dio[NUM_DIO]; // bytes 3..5: pins for DIO0, DOI1, DIO2 + // true if we must set rxtx for rx_active, false for tx_active + u1_t rxtx_rx_active; // byte 6: polarity of rxtx active + s1_t rssi_cal; // byte 7: cal in dB -- added to RSSI + // measured prior to decision. + // Must include noise guardband! + u4_t spi_freq; // bytes 8..11: SPI freq in Hz. }; // Use this for any unused pins. diff --git a/src/lmic/hal.h b/src/lmic/hal.h index b69e4fb4..562b4283 100644 --- a/src/lmic/hal.h +++ b/src/lmic/hal.h @@ -105,6 +105,11 @@ u1_t hal_checkTimer (u4_t targettime); */ void hal_failed (const char *file, u2_t line); +/* + * get the calibration value for radio_rssi + */ +s1_t hal_getRssiCal (void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 7b53d95e..8597e642 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -877,6 +877,7 @@ void radio_monitor_rssi(ostime_t nTicks, oslmic_radio_rssi_t *pRssi) { } else { rssiAdjust = SX127X_RSSI_ADJUST_LF; } + rssiAdjust += hal_getRssiCal(); // zero the results rssiMax = 255; From 304de5e213acb7e2b43579c6726efcf34f0ec737 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 17:48:48 -0400 Subject: [PATCH 57/73] Fix #63: add reference to standard, standard case --- src/lmic/lmic_config_preconditions.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lmic/lmic_config_preconditions.h b/src/lmic/lmic_config_preconditions.h index 52ec4771..35e2011d 100644 --- a/src/lmic/lmic_config_preconditions.h +++ b/src/lmic/lmic_config_preconditions.h @@ -72,15 +72,19 @@ Revision history: #define LMIC_REGION_kr921 8 #define LMIC_REGION_in866 9 -// country codes for comparison. These values are chosen from the 2-letter domain suffixes (which -// I think are ISO standardized) +// Some regions have country-specific overrides. For generality, we specify +// country codes using the LMIC_COUNTY_CODE_C() macro These values are chosen +// from the 2-letter domain suffixes standardized by ISO-3166-1 alpha2 (see +// https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). They are therefore +// 16-bit constants. By convention, we use UPPER-CASE letters, thus +// LMIC_COUNTRY_CODE('J', 'P'), not ('j', 'p'). #define LMIC_COUNTRY_CODE_C(c1, c2) ((c1) * 256 + (c2)) // this special code means "no country code defined" #define LMIC_COUNTRY_CODE_NONE 0 -// specific countries. Only the ones that are known in the code are defined. -#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('j', 'p') +// specific countries. Only the ones that are needed by the code are defined. +#define LMIC_COUNTRY_CODE_JP LMIC_COUNTRY_CODE_C('J', 'P') // include the file that the user is really supposed to edit. But for really strange // ports, this can be suppressed From efbd92a82d26878df165c2964c091c7bf5accc24 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 17:50:24 -0400 Subject: [PATCH 58/73] Clean up commentary --- src/lmic/config.h | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/lmic/config.h b/src/lmic/config.h index 4fccc320..17509078 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -3,29 +3,22 @@ // In the original LMIC code, these config values were defined on the // gcc commandline. Since Arduino does not allow easily modifying the -// compiler commandline, use this file to load project defaults and then fall back. -// Note that you should not edit this file, because then your changes will -// be applied to a globally-distributed file. Instead, create an -// lmic_project_config.h file. +// compiler commandline unless you modify the BSP, you have two choices: +// +// - edit {libraries}/arduino-lmic/project_config/lmic_project_config.h; +// - use a BSP like the MCCI Arduino BSPs, which get the configuration +// from the boards.txt file through a menu option. +// +// You definitely should not edit this file. +// set up preconditions, and load configuration if needed. #ifndef _LMIC_CONFIG_PRECONDITIONS_H_ # include "lmic_config_preconditions.h" #endif -// if you're editing this file directly (and not editing the project-config file -// referenced from the pre-conditions file), then uncomment exactly one of the -// following to select the operating bandplan - -//#define CFG_eu868 1 -//#define CFG_us915 1 -//#define CFG_cn783 1 // not yet -//#define CFG_eu433 1 // not yet -//#define CFG_au921 1 -//#define CFG_cn490 1 // not yet -//#define CFG_as923 1 -//#define CFG_kr921 1 // not yet -//#define CFG_in866 1 +// check post-conditions. +// make sure that we have exactly one target region defined. #if CFG_LMIC_REGION_MASK == 0 # define CFG_eu868 1 #elif (CFG_LMIC_REGION_MASK & (-CFG_LMIC_REGION_MASK)) != CFG_LMIC_REGION_MASK @@ -34,15 +27,17 @@ # error The selected CFG_... region is not supported yet. #endif +// make sure that LMIC_COUNTRY_CODE is defined. #ifndef LMIC_COUNTRY_CODE # define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_NONE #endif -// if the country code is japan, then the region must be AS923 +// if the country code is Japan, then the region must be AS923 #if LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP && CFG_region != LMIC_REGION_as923 # error "If country code is JP, then region must be AS923" #endif +// check for internal consistency #if !(CFG_LMIC_EU_like || CFG_LMIC_US_like) # error "Internal error: Neither EU-like nor US-like!" #endif @@ -52,6 +47,9 @@ //#define CFG_sx1272_radio 1 // This is the SX1276/SX1277/SX1278/SX1279 radio, which is also used on // the HopeRF RFM95 boards. +//#define CFG_sx1276_radio 1 + +// ensure that a radio is defined. #if ! (defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio)) # warning Target radio not defined, assuming CFG_sx1276_radio #define CFG_sx1276_radio 1 From 05e46baf2c8de27687e799f75a854b5e17ae7b92 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 17:54:01 -0400 Subject: [PATCH 59/73] Synchronize with master --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9cd777e9..f8afde11 100644 --- a/.gitignore +++ b/.gitignore @@ -40,5 +40,7 @@ Release vs-readme.txt __vm .vs -.vscode +*.sln +# files from vscode +.vscode From a704b6e79aee4830b23bbfe37f14e81a202de7db Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 18:16:55 -0400 Subject: [PATCH 60/73] Synch with master and clean up --- examples/raw-feather/raw-feather.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index c9b7db0f..fd66b7a9 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -263,9 +263,21 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. + + // set fDownlink true to use a downlink channel; false + // to use an uplink channel. Generally speaking, uplink + // is more interesting, because you can prove that gateways + // *should* be able to hear you. const static bool fDownlink = false; + + // the downlink channel to be used. const static uint8_t kDownlinkChannel = 3; + + // the uplink channel to be used. const static uint8_t kUplinkChannel = 8 + 3; + + // this is automatically set to the proper bandwidth in kHz, + // based on the selected channel. uint32_t uBandwidth; if (! fDownlink) From 43e308f1927485545c9470247207d5872ddb9374 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 18:17:47 -0400 Subject: [PATCH 61/73] Clean up prior to sync with master --- src/lmic/lmic.h | 2 +- src/lmic/radio.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index 0b902809..62e34406 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -210,7 +210,7 @@ struct lmic_t { // LBT info ostime_t lbt_ticks; // ticks to listen - s1_t lbt_dbmax; // max permissible dB on our channle (eg -80) + s1_t lbt_dbmax; // max permissible dB on our channel (eg -80) u4_t freq; s1_t rssi; diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 8597e642..673bbd76 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -562,7 +562,7 @@ static void starttx () { u1_t const rOpMode = readReg(RegOpMode); // originally, this code ASSERT()ed, but asserts are both bad and - // blunt instruments. If we see that we're not in sleep mode, + // blunt instruments. If we see that we're not in sleep mode, // force sleep (because we might have to switch modes) if ((rOpMode & OPMODE_MASK) != OPMODE_SLEEP) { #if LMIC_DEBUG_LEVEL > 0 @@ -575,7 +575,7 @@ static void starttx () { if (LMIC.lbt_ticks > 0) { oslmic_radio_rssi_t rssi; #if LMIC_DEBUG_LEVEL > 1 - LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", + LMIC_DEBUG_PRINTF("%lu: scan RSSI for %u osticks\n", os_getTime(), LMIC.lbt_ticks ); From faf3bc1eabc938b3ed9fa898b08ed8a9c47fb77e Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 18:25:33 -0400 Subject: [PATCH 62/73] Set project_config back to defaults --- project_config/lmic_project_config.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index 08dcf403..eb608dac 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -1,11 +1,8 @@ // project-specific definitions for otaa sensor //#define CFG_eu868 1 -//#define CFG_us915 1 +#define CFG_us915 1 //#define CFG_au921 1 -#define CFG_as923 1 -#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP +//#define CFG_as923 1 //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS -#define LMIC_DEBUG_LEVEL 2 -#define LMIC_DEBUG_PRINTF_FN lmic_printf From 1aafca50ae3f5050c05567b76d028e30711b2ba7 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 18:26:20 -0400 Subject: [PATCH 63/73] Add example of how to select Japan country --- project_config/lmic_project_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index eb608dac..7c19d39e 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -1,8 +1,9 @@ -// project-specific definitions for otaa sensor +// project-specific definitions //#define CFG_eu868 1 #define CFG_us915 1 //#define CFG_au921 1 //#define CFG_as923 1 +// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP */ //#define CFG_in866 1 #define CFG_sx1276_radio 1 //#define LMIC_USE_INTERRUPTS From 1b765cbe35fa8f0314a4c4798b59696f5fba5cf6 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 23:21:19 -0400 Subject: [PATCH 64/73] Specify lorawan_region for travis ci --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2dd1effa..fd39d9ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ install: # - arduino --install-boards mcci:stm32 script: - - arduino --verify --board mcci:samd:mcci_catena_4450 $PWD/examples/raw-feather/raw-feather.ino - - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450 $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=us915 $PWD/examples/raw-feather/raw-feather.ino + - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino # - arduino --pref "build.verbose=true" --verify --board mcci:stm32:Catena:pnum=CATENA_4551 $PWD/examples/raw-feather/raw-feather.ino From 6bdf9dcb8b5a7ba9e0b06e54f7234a982bded529 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Fri, 1 Jun 2018 23:41:52 -0400 Subject: [PATCH 65/73] .travis: Try saving prefs to obviate specifying all board opts --- .travis.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index fd39d9ee..dd963c1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ before_install: - mv arduino-1.8.5 $HOME/arduino_ide - ln -s $PWD $HOME/arduino_ide/libraries/Test_Library - export PATH="$HOME/arduino_ide:$PATH" + # keep args for these aligned for any common options. first is board name, second is region. + - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" + - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" - arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json" --save-prefs install: @@ -19,7 +22,11 @@ install: # - arduino --install-boards mcci:stm32 script: - - arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=us915 $PWD/examples/raw-feather/raw-feather.ino + - "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)" + - "echo $(_samdopts) $(_samdopts '' projcfg)" + - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - -# - arduino --pref "build.verbose=true" --verify --board mcci:stm32:Catena:pnum=CATENA_4551 $PWD/examples/raw-feather/raw-feather.ino + - arduino --board $(_samdopts) --save-prefs + - arduino --verify $PWD/examples/raw-feather/raw-feather.ino + - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino +# - arduino --pref "build.verbose=true" --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino From 5b94b9d38f7a123642eaf2188e0799025ad5107b Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 00:18:17 -0400 Subject: [PATCH 66/73] Further travis experimentation --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd963c1d..ec4932aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ before_install: # keep args for these aligned for any common options. first is board name, second is region. - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" + - function _projcfg { printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_%s 1\n#define CFG_sx1276_radio 1\n' ${1:-us915} ${2:-sx1276} > $PWD/project_config/lmic_project_config.h ; } - arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json" --save-prefs install: @@ -26,7 +27,5 @@ script: - "echo $(_samdopts) $(_samdopts '' projcfg)" - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - - arduino --board $(_samdopts) --save-prefs - - arduino --verify $PWD/examples/raw-feather/raw-feather.ino - - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - _projcfg us915 sx1272 && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino # - arduino --pref "build.verbose=true" --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino From 90b6ce35aac67865686b59a52f90c888d6365907 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 00:37:13 -0400 Subject: [PATCH 67/73] Further travis tests --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ec4932aa..f51a298b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ before_install: - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" - function _projcfg { printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_%s 1\n#define CFG_sx1276_radio 1\n' ${1:-us915} ${2:-sx1276} > $PWD/project_config/lmic_project_config.h ; } + - 'function _expect_failure { if [ $? -eq 0 ]; then echo "Suceeded, but should have failed!" ; return 1 ; else echo "Failed, as expected"; return 0 ; fi ; }' - arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json" --save-prefs install: @@ -26,6 +27,8 @@ script: - "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)" - "echo $(_samdopts) $(_samdopts '' projcfg)" - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino - - printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_sx1276_radio 1\n#define CFG_us915 1\n' > $PWD/project_config/lmic_project_config.h && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - _projcfg us915 sx1276 && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - _projcfg us915 sx1272 && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - _projcfg us915 sx1234 && if arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; then echo "should have failed!" ; false ; else echo "error (as expected) - passed" ; fi + - _projcfg us915 sx1234 && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure ; } # - arduino --pref "build.verbose=true" --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino From 39a17df7f14e20569cc031fd8c7fa5071d5b3549 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 00:54:18 -0400 Subject: [PATCH 68/73] Further travis tests (forcing failure) --- .travis.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f51a298b..2b5d16b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,8 @@ before_install: # keep args for these aligned for any common options. first is board name, second is region. - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" - - function _projcfg { printf '#define COMPILE_REGRESSION_TEST 1\n#define CFG_%s 1\n#define CFG_sx1276_radio 1\n' ${1:-us915} ${2:-sx1276} > $PWD/project_config/lmic_project_config.h ; } - - 'function _expect_failure { if [ $? -eq 0 ]; then echo "Suceeded, but should have failed!" ; return 1 ; else echo "Failed, as expected"; return 0 ; fi ; }' + - function _projcfg { for i in "$@" ; do printf '#define %s 1\n' "$i" ; done > $PWD/project_config/lmic_project_config.h ; } + - 'function _expect_failure { if [ $? -eq 0 ]; then echo "Suceeded, but should have failed!" ; echo project_config/lmic_project_config.h ; cat $PWD/project_config/lmic_project_config.h ; return 1 ; else echo "Failed, as expected"; return 0 ; fi ; }' - arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json" --save-prefs install: @@ -27,8 +27,13 @@ script: - "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)" - "echo $(_samdopts) $(_samdopts '' projcfg)" - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino - - _projcfg us915 sx1276 && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - - _projcfg us915 sx1272 && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - - _projcfg us915 sx1234 && if arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; then echo "should have failed!" ; false ; else echo "error (as expected) - passed" ; fi - - _projcfg us915 sx1234 && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure ; } +# +# some tests using the projcfg file that should pass + - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1272_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino +# +# some tests that should fail. + - _projcfg CFG_us915 CFG_sx1272_radio && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure; } + - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1272_radio CFG_sx1276_radio && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure; } +# # - arduino --pref "build.verbose=true" --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino From f60cd76dc85c8bbc44ea8fbdaf7b4b81d73a6ba2 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 01:18:29 -0400 Subject: [PATCH 69/73] Enable testing of STM32L0 BSP --- .travis.yml | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b5d16b9..8761ef63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,28 +12,57 @@ before_install: - mv arduino-1.8.5 $HOME/arduino_ide - ln -s $PWD $HOME/arduino_ide/libraries/Test_Library - export PATH="$HOME/arduino_ide:$PATH" - # keep args for these aligned for any common options. first is board name, second is region. + # + # functions to generate the board settings for SAMD, STM32L0, ... + # keep args for these aligned for any common options. $1 is always board name, $2 is region. + # + # Changes to the BSP may break this build, sorry! + # - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" + # + # Put one or more arguments into lmic_project_config.h as `#define $i\n` - function _projcfg { for i in "$@" ; do printf '#define %s 1\n' "$i" ; done > $PWD/project_config/lmic_project_config.h ; } + # + # Handy macro to deal with expected failures. - 'function _expect_failure { if [ $? -eq 0 ]; then echo "Suceeded, but should have failed!" ; echo project_config/lmic_project_config.h ; cat $PWD/project_config/lmic_project_config.h ; return 1 ; else echo "Failed, as expected"; return 0 ; fi ; }' + # + # modify the board manager preferences to point to our BSPs. - arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json" --save-prefs install: - arduino --install-boards mcci:samd -# - arduino --install-boards mcci:stm32 + - arduino --install-boards mcci:stm32 script: - "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)" - "echo $(_samdopts) $(_samdopts '' projcfg)" - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_samdopts '' eu868) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_samdopts '' au921) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_samdopts '' as923) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_samdopts '' as923jp) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_samdopts '' in866) $PWD/examples/raw-feather/raw-feather.ino + # # some tests using the projcfg file that should pass - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1272_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + # -# some tests that should fail. +# some tests that should generate build failures. +# +# COMPILE_REGRESSION_TEST must be defined for ttn-otaa-feather-us915 - _projcfg CFG_us915 CFG_sx1272_radio && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure; } +# +# Only one radio may be defined - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1272_radio CFG_sx1276_radio && { arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino ; _expect_failure; } + + +# +# *** TESTS FOR STM32L0 / Catena 4551 **** +# make sure you install the BSP above. # -# - arduino --pref "build.verbose=true" --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino + - arduino --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino + +### end of file ### \ No newline at end of file From 3dba35d235b6d6943b7ec0011ba346f3ef0c4b3c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 02:28:43 -0400 Subject: [PATCH 70/73] Fix #65: add au921, in866, as923jp variants --- examples/raw-feather/raw-feather.ino | 87 +++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index fd66b7a9..6e9b2663 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -311,6 +311,64 @@ void setup() { // default tx power for US: 21 dBm LMIC.txpow = 21; +#elif defined(CFG_au921) + // make it easier for test, by pull the parameters up to the top of the + // block. Ideally, we'd use the serial port to drive this; or have + // a voting protocol where one side is elected the controller and + // guides the responder through all the channels, powers, ramps + // the transmit power from min to max, and measures the RSSI and SNR. + // Even more amazing would be a scheme where the controller could + // handle multiple nodes; in that case we'd have a way to do + // production test and qualification. However, using an RWC5020A + // is a much better use of development time. + + // set fDownlink true to use a downlink channel; false + // to use an uplink channel. Generally speaking, uplink + // is more interesting, because you can prove that gateways + // *should* be able to hear you. + const static bool fDownlink = false; + + // the downlink channel to be used. + const static uint8_t kDownlinkChannel = 3; + + // the uplink channel to be used. + const static uint8_t kUplinkChannel = 8 + 3; + + // this is automatically set to the proper bandwidth in kHz, + // based on the selected channel. + uint32_t uBandwidth; + + if (! fDownlink) + { + if (kUplinkChannel < 64) + { + LMIC.freq = AU921_125kHz_UPFBASE + + kUplinkChannel * AU921_125kHz_UPFSTEP; + uBandwidth = 125; + } + else + { + LMIC.freq = AU921_500kHz_UPFBASE + + (kUplinkChannel - 64) * AU921_500kHz_UPFSTEP; + uBandwidth = 500; + } + } + else + { + // downlink channel + LMIC.freq = AU921_500kHz_DNFBASE + + kDownlinkChannel * AU921_500kHz_DNFSTEP; + uBandwidth = 500; + } + + // Use a suitable spreading factor + if (uBandwidth < 500) + LMIC.datarate = AU921_DR_SF7; // DR4 + else + LMIC.datarate = AU921_DR_SF12CR; // DR8 + + // default tx power for AU: 30 dBm + LMIC.txpow = 30; #elif defined(CFG_as923) // make it easier for test, by pull the parameters up to the top of the // block. Ideally, we'd use the serial port to drive this; or have @@ -321,7 +379,7 @@ void setup() { // handle multiple nodes; in that case we'd have a way to do // production test and qualification. However, using an RWC5020A // is a much better use of development time. - const static uint8_t kChannel = 1; + const static uint8_t kChannel = 0; uint32_t uBandwidth; LMIC.freq = AS923_F1 + kChannel * 200000; @@ -333,8 +391,33 @@ void setup() { else LMIC.datarate = AS923_DR_SF7B; // DR8 - // default tx power for US: 21 dBm + // default tx power for AS: 21 dBm LMIC.txpow = 16; + + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) + { + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); + LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; + } +#elif defined(CFG_in866) +// make it easier for test, by pull the parameters up to the top of the +// block. Ideally, we'd use the serial port to drive this; or have +// a voting protocol where one side is elected the controller and +// guides the responder through all the channels, powers, ramps +// the transmit power from min to max, and measures the RSSI and SNR. +// Even more amazing would be a scheme where the controller could +// handle multiple nodes; in that case we'd have a way to do +// production test and qualification. However, using an RWC5020A +// is a much better use of development time. + const static uint8_t kChannel = 0; + uint32_t uBandwidth; + + LMIC.freq = IN866_F1 + kChannel * 200000; + uBandwidth = 125; + + LMIC.datarate = IN866_DR_SF7; // DR7 + // default tx power for IN: 30 dBm + LMIC.txpow = IN866_TX_EIRP_MAX_DBM; #else # error Unsupported LMIC regional configuration. #endif From 187b8c776f96f4b04e12711f0f5a3344a2a6645e Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 02:30:52 -0400 Subject: [PATCH 71/73] de-tabify --- examples/raw-feather/raw-feather.ino | 136 +++++++++++++-------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index 6e9b2663..d32054b3 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -5,33 +5,33 @@ Module: raw-feather.ino Function: - Slightly improved Raw test example, for Adafruit Feather M0 LoRa + Slightly improved Raw test example, for Adafruit Feather M0 LoRa Version: - V0.7.0 Tue Jan 23 2018 10:25:50 chwon Edit level 2 + V0.7.0 Tue Jan 23 2018 10:25:50 chwon Edit level 2 Copyright notice: - This file copyright (C) 2017, 2018 by + This file copyright (C) 2017, 2018 by - MCCI Corporation - 3520 Krums Corners Road - Ithaca, NY 14850 + MCCI Corporation + 3520 Krums Corners Road + Ithaca, NY 14850 - An unpublished work. All rights reserved. + An unpublished work. All rights reserved. - This file is proprietary information, and may not be disclosed or - copied without the prior permission of MCCI Corporation. + This file is proprietary information, and may not be disclosed or + copied without the prior permission of MCCI Corporation. Author: - Matthijs Kooijman 2015 - Terry Moore, MCCI Corporation April 2017 + Matthijs Kooijman 2015 + Terry Moore, MCCI Corporation April 2017 Revision history: 0.5.0 Sat Apr 1 2017 22:26:22 tmm - Module created. + Module created. 0.7.0 Tue Jan 23 2018 10:25:50 chwon - Add Catena 4551 platform support. + Add Catena 4551 platform support. */ @@ -122,19 +122,19 @@ void lmic_printf(const char *fmt, ...); }; void lmic_printf(const char *fmt, ...) { - if (! Serial.dtr()) - return; + if (! Serial.dtr()) + return; - char buf[256]; - va_list ap; + char buf[256]; + va_list ap; - va_start(ap, fmt); - (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); + va_start(ap, fmt); + (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap); + va_end(ap); - // in case we overflowed: - buf[sizeof(buf) - 1] = '\0'; - if (Serial.dtr()) Serial.print(buf); + // in case we overflowed: + buf[sizeof(buf) - 1] = '\0'; + if (Serial.dtr()) Serial.print(buf); } osjob_t txjob; @@ -281,27 +281,27 @@ void setup() { uint32_t uBandwidth; if (! fDownlink) - { - if (kUplinkChannel < 64) - { - LMIC.freq = US915_125kHz_UPFBASE + - kUplinkChannel * US915_125kHz_UPFSTEP; - uBandwidth = 125; - } - else - { - LMIC.freq = US915_500kHz_UPFBASE + - (kUplinkChannel - 64) * US915_500kHz_UPFSTEP; - uBandwidth = 500; - } - } + { + if (kUplinkChannel < 64) + { + LMIC.freq = US915_125kHz_UPFBASE + + kUplinkChannel * US915_125kHz_UPFSTEP; + uBandwidth = 125; + } + else + { + LMIC.freq = US915_500kHz_UPFBASE + + (kUplinkChannel - 64) * US915_500kHz_UPFSTEP; + uBandwidth = 500; + } + } else - { - // downlink channel - LMIC.freq = US915_500kHz_DNFBASE + - kDownlinkChannel * US915_500kHz_DNFSTEP; - uBandwidth = 500; - } + { + // downlink channel + LMIC.freq = US915_500kHz_DNFBASE + + kDownlinkChannel * US915_500kHz_DNFSTEP; + uBandwidth = 500; + } // Use a suitable spreading factor if (uBandwidth < 500) @@ -339,27 +339,27 @@ void setup() { uint32_t uBandwidth; if (! fDownlink) - { - if (kUplinkChannel < 64) - { - LMIC.freq = AU921_125kHz_UPFBASE + - kUplinkChannel * AU921_125kHz_UPFSTEP; - uBandwidth = 125; - } - else - { - LMIC.freq = AU921_500kHz_UPFBASE + - (kUplinkChannel - 64) * AU921_500kHz_UPFSTEP; - uBandwidth = 500; - } - } + { + if (kUplinkChannel < 64) + { + LMIC.freq = AU921_125kHz_UPFBASE + + kUplinkChannel * AU921_125kHz_UPFSTEP; + uBandwidth = 125; + } + else + { + LMIC.freq = AU921_500kHz_UPFBASE + + (kUplinkChannel - 64) * AU921_500kHz_UPFSTEP; + uBandwidth = 500; + } + } else - { - // downlink channel - LMIC.freq = AU921_500kHz_DNFBASE + - kDownlinkChannel * AU921_500kHz_DNFSTEP; - uBandwidth = 500; - } + { + // downlink channel + LMIC.freq = AU921_500kHz_DNFBASE + + kDownlinkChannel * AU921_500kHz_DNFSTEP; + uBandwidth = 500; + } // Use a suitable spreading factor if (uBandwidth < 500) @@ -394,11 +394,11 @@ void setup() { // default tx power for AS: 21 dBm LMIC.txpow = 16; - if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) - { - LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); + if (LMIC_COUNTRY_CODE == LMIC_COUNTRY_CODE_JP) + { + LMIC.lbt_ticks = us2osticks(AS923JP_LBT_US); LMIC.lbt_dbmax = AS923JP_LBT_DB_MAX; - } + } #elif defined(CFG_in866) // make it easier for test, by pull the parameters up to the top of the // block. Ideally, we'd use the serial port to drive this; or have @@ -415,7 +415,7 @@ void setup() { LMIC.freq = IN866_F1 + kChannel * 200000; uBandwidth = 125; - LMIC.datarate = IN866_DR_SF7; // DR7 + LMIC.datarate = IN866_DR_SF7; // DR7 // default tx power for IN: 30 dBm LMIC.txpow = IN866_TX_EIRP_MAX_DBM; #else From 586eb34acf4038cfa1bb165ff205b46dab505bc0 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 02:34:00 -0400 Subject: [PATCH 72/73] Extend testing, cater to the limitations of V1.1.0 BSP --- .travis.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8761ef63..59608426 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_install: # Changes to the BSP may break this build, sorry! # - "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }" - - "function _stm32l0opts { echo mcci:stm32:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" + - "function _stm32l0opts { echo mcci:stm32:Catena:pnum=${1:-CATENA_4551}:opt=${3:-osstd}:xserial=${4:-generic}:usb=${5:-none}:upload_method=${6:-STLink} ; }" # # Put one or more arguments into lmic_project_config.h as `#define $i\n` - function _projcfg { for i in "$@" ; do printf '#define %s 1\n' "$i" ; done > $PWD/project_config/lmic_project_config.h ; } @@ -35,11 +35,17 @@ install: - arduino --install-boards mcci:stm32 script: +# +# show the output of the config commands for reference. - "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)" - "echo $(_samdopts) $(_samdopts '' projcfg)" + +# +# test each of the regions. - arduino --verify --board $(_samdopts '' us915) $PWD/examples/raw-feather/raw-feather.ino - arduino --verify --board $(_samdopts '' eu868) $PWD/examples/raw-feather/raw-feather.ino - - arduino --verify --board $(_samdopts '' au921) $PWD/examples/raw-feather/raw-feather.ino +# V1.1.0 of the samd bsp doesn't support au921 correctly -- test with projcfg +# - arduino --verify --board $(_samdopts '' au921) $PWD/examples/raw-feather/raw-feather.ino - arduino --verify --board $(_samdopts '' as923) $PWD/examples/raw-feather/raw-feather.ino - arduino --verify --board $(_samdopts '' as923jp) $PWD/examples/raw-feather/raw-feather.ino - arduino --verify --board $(_samdopts '' in866) $PWD/examples/raw-feather/raw-feather.ino @@ -48,6 +54,7 @@ script: # some tests using the projcfg file that should pass - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino - _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1272_radio && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino + - _projcfg CFG_au921 CFG_sx1276_radio && arduino --verify --board $(_samdopts '' projcfg) $PWD/examples/raw-feather/raw-feather.ino # # some tests that should generate build failures. @@ -62,7 +69,7 @@ script: # # *** TESTS FOR STM32L0 / Catena 4551 **** # make sure you install the BSP above. -# +# - arduino --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino ### end of file ### \ No newline at end of file From f813db139094f881f043baea68015bd4ed65a386 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 2 Jun 2018 02:44:49 -0400 Subject: [PATCH 73/73] Disable STM32L0 platform tests for now --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59608426..d6d5f630 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_install: install: - arduino --install-boards mcci:samd - - arduino --install-boards mcci:stm32 +# - arduino --install-boards mcci:stm32 script: # @@ -70,6 +70,6 @@ script: # *** TESTS FOR STM32L0 / Catena 4551 **** # make sure you install the BSP above. # - - arduino --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino +# - arduino --verify --board $(_stm32l0opts) $PWD/examples/raw-feather/raw-feather.ino ### end of file ### \ No newline at end of file