Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX127x sx12xx_hal TSL2561
Revision 13:18de9ee3a461, committed 2017-07-08
- Comitter:
- dudmuck
- Date:
- Sat Jul 08 00:35:03 2017 +0000
- Parent:
- 12:ed33c53afcaf
- Child:
- 14:7ac0add1123e
- Commit message:
- gateway-tx debug input pin, discard timer error on missed beacon
Changed in this revision
| board/lora_config.h | Show annotated file Show diff for this revision Revisions of this file |
| mac/LoRaMac.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/board/lora_config.h Wed Jul 05 18:50:32 2017 +0000
+++ b/board/lora_config.h Sat Jul 08 00:35:03 2017 +0000
@@ -1,7 +1,7 @@
/* select radio chip to use */
//#define ENABLE_SX1276
-#define ENABLE_SX1272
+//#define ENABLE_SX1272
#ifdef TARGET_DISCO_L072CZ_LRWAN1
@@ -9,4 +9,5 @@
#undef ENABLE_SX1272
#endif
-#define SENSORS
\ No newline at end of file
+//#define SENSORS
+//#define DEBUG_GWTX_JUMPER PC_2
\ No newline at end of file
--- a/mac/LoRaMac.cpp Wed Jul 05 18:50:32 2017 +0000
+++ b/mac/LoRaMac.cpp Sat Jul 08 00:35:03 2017 +0000
@@ -279,6 +279,16 @@
LowPowerTimer lp_timer;
+#ifdef DEBUG_GWTX_JUMPER
+InterruptIn gwtx_pin(DEBUG_GWTX_JUMPER);
+unsigned int gwtx_rise_us;
+
+void gwtx_pin_callback()
+{
+ gwtx_rise_us = lp_timer.read_us();
+}
+#endif
+
/*!
* LoRaMac parameters
*/
@@ -376,7 +386,8 @@
unsigned int LastBeaconRx_us; // updated only at beacon reception
unsigned int LastBeaconStart_us; // updated at beacon reception and beacon reception timeout
unsigned int next_beacon_expected_us;
- int BeaconRxTimerError_us;
+ int last_BeaconRxTimerError_us;
+ int known_working_BeaconRxTimerError_us;
float symbol_period_secs;
@@ -882,16 +893,17 @@
unsigned int us_since_last = ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us;
//unsigned int intervals_since_last = (ThisBeaconRx_us / BEACON_INTERVAL_us) - (BeaconCtx.LastBeaconRx_us / BEACON_INTERVAL_us);
unsigned int intervals_since_last = us_since_last / BEACON_INTERVAL_us;
+ BeaconCtx.known_working_BeaconRxTimerError_us = BeaconCtx.last_BeaconRxTimerError_us;
/* get average of error history */
- BeaconCtx.BeaconRxTimerError_us = (ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us) % BEACON_INTERVAL_us;
+ BeaconCtx.last_BeaconRxTimerError_us = (ThisBeaconRx_us - BeaconCtx.LastBeaconRx_us) % BEACON_INTERVAL_us;
/* BeaconRxTimerError: positive means our clock is fast
* negative means our clock is slow */
- if (BeaconCtx.BeaconRxTimerError_us > (BEACON_INTERVAL_us/2))
- BeaconCtx.BeaconRxTimerError_us -= BEACON_INTERVAL_us; // negative value representing slow crystal
+ if (BeaconCtx.last_BeaconRxTimerError_us > (BEACON_INTERVAL_us/2))
+ BeaconCtx.last_BeaconRxTimerError_us -= BEACON_INTERVAL_us; // negative value representing slow crystal
if (intervals_since_last > 1) {
/* timer error is measured over more than one beacon period */
- BeaconCtx.BeaconRxTimerError_us /= intervals_since_last;
+ BeaconCtx.last_BeaconRxTimerError_us /= intervals_since_last;
}
if (BeaconCtx.state == BEACON_STATE_ACQ_ERROR) {
@@ -907,14 +919,17 @@
BeaconCtx.state = BEACON_STATE_ACQ_ERROR;
}
- isr_printf("err%d=%u-%u ", BeaconCtx.BeaconRxTimerError_us, ThisBeaconRx_us, BeaconCtx.LastBeaconRx_us);
+#ifdef DEBUG_GWTX_JUMPER
+ isr_printf("rx-before-gwtx:%d ", gwtx_rise_us - BeaconCtx.RxBeaconSetupAt_us);
+#endif /* DEBUG_GWTX_JUMPER */
+ isr_printf("err%d=%u-%u ", BeaconCtx.last_BeaconRxTimerError_us, ThisBeaconRx_us, BeaconCtx.LastBeaconRx_us);
isr_printf(" rx-before-tx:%d ", BeaconCtx.rx_precession_us);
BeaconCtx.LastBeaconRx_us = ThisBeaconRx_us;
BeaconCtx.LastBeaconStart_us = BeaconCtx.LastBeaconRx_us;
if (BeaconCtx.state == BEACON_STATE_LOCKED_) {
if (compensate_precession) {
- compensation = BeaconCtx.rx_precession_us - TARGET_PRECESSION_US + BeaconCtx.BeaconRxTimerError_us;
+ compensation = BeaconCtx.rx_precession_us - TARGET_PRECESSION_US + BeaconCtx.last_BeaconRxTimerError_us;
isr_printf(" comp%ld", compensation);
}
}
@@ -1127,7 +1142,8 @@
BeaconCtx.state = BEACON_STATE_FIRST_ACQ;
BeaconCtx.num_missed = 0;
BeaconCtx.rx_precession_us = 0;
- BeaconCtx.BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL;
+ BeaconCtx.last_BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL;
+ BeaconCtx.known_working_BeaconRxTimerError_us = -PPM_100_BEACON_INTERVAL;
BeaconCtx.symbol_period_secs = get_symbol_period(GetRxBandwidth(LORAMAC_DEFAULT_DATARATE), Datarates[LORAMAC_DEFAULT_DATARATE]);
// N-ms: slot resolution + minimum for preamble detector + 100ppm fast crystal rxing 12ms early
BeaconCtx.Precess_symbols = TARGET_PRECESSION_US * (BeaconCtx.symbol_period_secs);
@@ -1462,24 +1478,27 @@
if (expecting_beacon) {
/* generate simulated last beacon start */
- BeaconCtx.LastBeaconStart_us += BEACON_INTERVAL_us + BeaconCtx.BeaconRxTimerError_us;
+ BeaconCtx.LastBeaconStart_us += BEACON_INTERVAL_us + BeaconCtx.known_working_BeaconRxTimerError_us;
BeaconCtx.next_beacon_expected_us = BEACON_INTERVAL_us;
BeaconCtx.num_missed++;
unsigned now_us = lp_timer.read_us();
if (BeaconCtx.state == BEACON_STATE_FIRST_ACQ) {
BeaconCtx.next_beacon_expected_us -= 1000000;
- set_beacon_symbol_timeout(2.000);
+ set_beacon_symbol_timeou t(2.000);
} else {
- BeaconCtx.next_beacon_expected_us += BeaconCtx.BeaconRxTimerError_us;
+ BeaconCtx.next_beacon_expected_us += BeaconCtx.known_working_BeaconRxTimerError_us;
// for measurement resolution and temperature drift while missing beacons:
- BeaconCtx.next_beacon_expected_us -= 3000;
- set_beacon_symbol_timeout(BeaconCtx.SymbolTimeout_sec + 0.006);
+ BeaconCtx.next_beacon_expected_us -= 5000;
+ set_beacon_symbol_timeout(BeaconCtx.SymbolTimeout_sec + 0.010);
}
unsigned us_since_rx_setup = now_us - BeaconCtx.RxBeaconSetupAt_us;
BeaconCtx.timeout.attach_us(&OnRxBeaconSetup, BeaconCtx.next_beacon_expected_us - us_since_rx_setup);
-
- isr_printf("beacon-rx-timeout %u %u next in %uus (%u)\r\n", BeaconCtx.num_missed, BeaconCtx.SymbolTimeout, BeaconCtx.next_beacon_expected_us, us_since_rx_setup);
+
+#ifdef DEBUG_GWTX_JUMPER
+ isr_printf("rx-before-gwtx:%d ", gwtx_rise_us - BeaconCtx.RxBeaconSetupAt_us);
+#endif /* DEBUG_GWTX_JUMPER */
+ isr_printf("beacon-rx-timeout %u %u next in %uus (rxing for %u)\r\n", BeaconCtx.num_missed, BeaconCtx.SymbolTimeout, BeaconCtx.next_beacon_expected_us, us_since_rx_setup);
MlmeIndication.MlmeIndication = MLME_BEACON;
MlmeIndication.Status = LORAMAC_EVENT_INFO_STATUS_BEACON_LOST;
@@ -2281,6 +2300,10 @@
lp_timer.start();
RxWindowsParam = ComputeRxWindowParameters(LORAMAC_DEFAULT_DATARATE, LoRaMacParams.SystemMaxRxError);
+
+#ifdef DEBUG_GWTX_JUMPER
+ gwtx_pin.rise(&gwtx_pin_callback);
+#endif
return LORAMAC_STATUS_OK;
}