Use precise T1000-E dual-profile timing
This commit is contained in:
1 parent
960936183c
commit
d66b9336a9
11 files changed
+142
-74
No files matched your search
+10
-13
@@ -42,8 +42,9 @@ class RadioProfiles {
|
||||
static constexpr uint16_t MaxPreamble = 65528;
|
||||
static constexpr uint16_t MaxAutomaticPreamble = 128;
|
||||
// Successful RX-to-RX hops self-test the board-specific switch allowance.
|
||||
// Packet receptions can extend a visit; these budgets describe an idle scan.
|
||||
static constexpr uint32_t LoopBudgetUs = 300;
|
||||
// Packet receptions can extend a visit. No fixed loop allowance is added to
|
||||
// the self-tested, guarded switch time in the idle-scan timing model.
|
||||
static constexpr uint32_t LoopBudgetUs = 0;
|
||||
static constexpr uint8_t SwitchTestSamplesPerDirection = 4;
|
||||
|
||||
struct ChirpTiming {
|
||||
@@ -148,21 +149,17 @@ class RadioProfiles {
|
||||
return isfinite(symbol) && symbol > 0 && symbol <= UINT32_MAX / symbols
|
||||
? (uint32_t)ceil(symbols * symbol) : 0;
|
||||
}
|
||||
static double preambleForVisits(const RadioProfileParams& p, const RadioProfileParams& other,
|
||||
bool slow, double own_us, double other_us, double overhead_us) {
|
||||
static double preambleForVisits(const RadioProfileParams& p, bool slow,
|
||||
double own_us, double other_us, double overhead_us) {
|
||||
const double symbol = symbolUs(p);
|
||||
if (symbol <= 0) return 32;
|
||||
double result = slow ? roundPreamble(2.0 * (own_us + other_us + overhead_us) / symbol)
|
||||
return slow ? roundPreamble(2.0 * (own_us + other_us + overhead_us) / symbol)
|
||||
: roundPreamble((other_us + overhead_us) / symbol + 2 * AcquisitionSymbols);
|
||||
// Production V4/XIAO empirical floor; retain prior measured margin.
|
||||
if (!slow && p.sf == 8 && p.bw == 500 && other.sf == 7 && other.bw == 62.5f && result < 88)
|
||||
result = 88;
|
||||
return result;
|
||||
}
|
||||
// A two-profile idle-scan timing policy, NOT a fitted zero-loss model.
|
||||
// Use a 4.6-symbol minimum on both profiles. Reserve
|
||||
// two return opportunities on the slow profile, and blind time + 16
|
||||
// acquisition symbols on the fast one. The 4.6/300-us pair bench received
|
||||
// acquisition symbols on the fast one. The 4.6-symbol pair bench received
|
||||
// 197/200: a sweep fitting inside 32 is not a guarantee of acquisition.
|
||||
// Explicit visit times let diagnostics account for the actual scheduler,
|
||||
// including a longer fast visit selected by an explicit slow preamble.
|
||||
@@ -180,8 +177,8 @@ class RadioProfiles {
|
||||
t.switch_us = switch_us; t.loop_us = loop_us;
|
||||
const double overhead = 2.0 * switch_us + loop_us;
|
||||
t.cycle_us = double(t.listen_us[0]) + t.listen_us[1] + overhead;
|
||||
t.preamble[0] = preambleForVisits(a, b, t.slow == 0, t.listen_us[0], t.listen_us[1], overhead);
|
||||
t.preamble[1] = preambleForVisits(b, a, t.slow == 1, t.listen_us[1], t.listen_us[0], overhead);
|
||||
t.preamble[0] = preambleForVisits(a, t.slow == 0, t.listen_us[0], t.listen_us[1], overhead);
|
||||
t.preamble[1] = preambleForVisits(b, t.slow == 1, t.listen_us[1], t.listen_us[0], overhead);
|
||||
t.valid = true;
|
||||
return t;
|
||||
}
|
||||
@@ -190,7 +187,7 @@ class RadioProfiles {
|
||||
// Keep the hot retune path to one profile's calculation; the full
|
||||
// validated diagnostic structure is only needed by CLI/reporting.
|
||||
const uint8_t slow = slowerProfile();
|
||||
return preambleForVisits(params(profile), params(profile ^ 1), profile == slow,
|
||||
return preambleForVisits(params(profile), profile == slow,
|
||||
minimumListenUs(params(profile), profile == slow), minimumListenUs(params(profile ^ 1), (profile ^ 1) == slow),
|
||||
2.0 * switchBudgetUs() + LoopBudgetUs);
|
||||
}
|
||||
|
||||
@@ -528,9 +528,10 @@ bool RadioProfileCLI::handle(const char* command, char* reply, size_t capacity,
|
||||
radio_->profilePreamble(0), radio_->profilePreamble(1));
|
||||
else if (!t.valid) snprintf(reply, capacity, "Error: timing unavailable");
|
||||
else {
|
||||
snprintf(reply, capacity, "> chirps=%.2f,%.2f; need=%.0f,%.0f; switch=%luus; loop=%luus (estimate)",
|
||||
snprintf(reply, capacity, "> chirps=%.2f,%.2f; need=%.0f,%.0f; switch=%luus; loop=%luus%s",
|
||||
t.listen_us[0] / t.symbol_us[0], t.listen_us[1] / t.symbol_us[1],
|
||||
t.preamble[0], t.preamble[1], (unsigned long)t.switch_us, (unsigned long)t.loop_us);
|
||||
t.preamble[0], t.preamble[1], (unsigned long)t.switch_us,
|
||||
(unsigned long)t.loop_us, t.loop_us ? " (estimate)" : "");
|
||||
size_t used = strlen(reply);
|
||||
if (used < capacity) snprintf(reply + used, capacity - used, "; test=%u/%u,%u/%u%s",
|
||||
p.switch_test_samples[0], RadioProfiles::SwitchTestSamplesPerDirection,
|
||||
|
||||
@@ -21,6 +21,39 @@
|
||||
|
||||
static volatile uint8_t state = STATE_IDLE;
|
||||
|
||||
// The Adafruit nRF52 core's micros() falls back to 1024 Hz RTOS ticks when
|
||||
// DWT is disabled. A sub-millisecond retune then appears to take exactly
|
||||
// 977 us (or 1953 us across two ticks), making the learned switch allowance
|
||||
// and scan dwell inaccurate. RTC2 is otherwise unused on the T1000-E and
|
||||
// provides a continuous 32768 Hz clock without changing micros() globally or
|
||||
// holding the high-frequency clock on for this measurement.
|
||||
static uint32_t profileTimestamp() {
|
||||
#if defined(T1000_E) && defined(NRF52_PLATFORM)
|
||||
static bool started = false;
|
||||
if (!started) {
|
||||
NRF_RTC2->TASKS_STOP = 1;
|
||||
NRF_RTC2->PRESCALER = 0;
|
||||
NRF_RTC2->TASKS_CLEAR = 1;
|
||||
NRF_RTC2->TASKS_START = 1;
|
||||
started = true;
|
||||
}
|
||||
return NRF_RTC2->COUNTER;
|
||||
#else
|
||||
return micros();
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t profileElapsedUs(uint32_t since, uint32_t now) {
|
||||
#if defined(T1000_E) && defined(NRF52_PLATFORM)
|
||||
// RTC2 is 24-bit and wraps every 512 seconds. Active scanning samples it
|
||||
// many times per second; a freshly configured profile gets a new visit stamp.
|
||||
const uint32_t ticks = (now - since) & 0x00ffffffUL;
|
||||
return static_cast<uint32_t>((uint64_t(ticks) * 15625 + 511) >> 9);
|
||||
#else
|
||||
return now - since;
|
||||
#endif
|
||||
}
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is transmitted by the module
|
||||
static
|
||||
@@ -33,6 +66,7 @@ void setFlag(void) {
|
||||
}
|
||||
|
||||
void RadioLibWrapper::begin() {
|
||||
(void) profileTimestamp();
|
||||
#ifdef USE_CC310_HW_CRYPTO
|
||||
// Initialize CryptoCell once from normal task context. The session helper
|
||||
// still initializes lazily if an earlier crypto operation runs first.
|
||||
@@ -254,7 +288,7 @@ mesh::RadioParamApplyResult RadioLibWrapper::trySetParams(float freq, float bw,
|
||||
}
|
||||
}
|
||||
|
||||
_profile_visit_us = micros();
|
||||
_profile_visit_stamp = profileTimestamp();
|
||||
return success ? mesh::RadioParamApplyResult::APPLIED : mesh::RadioParamApplyResult::FAILED;
|
||||
}
|
||||
|
||||
@@ -287,7 +321,7 @@ mesh::RadioParamApplyResult RadioLibWrapper::tuneProfile(uint8_t profile) {
|
||||
if (!_profile_refresh_required && _active_profile == profile && _profile_generation == _profiles.generation[profile]
|
||||
&& _physical_preamble == preamble) return mesh::RadioParamApplyResult::APPLIED;
|
||||
if (!validateProfile(p)) return mesh::RadioParamApplyResult::FAILED;
|
||||
const uint32_t started = micros();
|
||||
const uint32_t started = profileTimestamp();
|
||||
beginProfileRetune(isInRecvMode() && !_rx_ps_armed && !_rx_ps_enabled);
|
||||
const uint8_t resume = beginReconfigure();
|
||||
if (resume > 1) {
|
||||
@@ -330,16 +364,17 @@ mesh::RadioParamApplyResult RadioLibWrapper::tuneProfile(uint8_t profile) {
|
||||
if (restored) endReconfigure(resume);
|
||||
if (!restored || (resume && !isInRecvMode())) _profile_refresh_required = true;
|
||||
}
|
||||
_profile_visit_us = micros();
|
||||
_profile_visit_stamp = profileTimestamp();
|
||||
// A profile retune re-enters RX on a different tuple. Do not read its
|
||||
// instantaneous RSSI until the chip family's settle interval has elapsed.
|
||||
if (applied && _nf_refresh_requested) {
|
||||
_nf_sample_from = millis() + NF_CALIB_SETTLE_MS;
|
||||
}
|
||||
const uint32_t elapsed = _profile_visit_us - started;
|
||||
const uint32_t elapsed = profileElapsedUs(started, _profile_visit_stamp);
|
||||
if (elapsed > _profiles.longest_switch_us) _profiles.longest_switch_us = elapsed;
|
||||
// Learn the actual board's RX-to-RX retune cost on the first four good hops
|
||||
// in each direction. Deferred and rolled-back operations are not samples.
|
||||
// Require four good RX-to-RX hops in each direction before using the budget,
|
||||
// then continue raising the observed maximum as later good hops run.
|
||||
// Deferred and rolled-back operations are not samples.
|
||||
if (applied && resume && old_profile != profile) {
|
||||
_profiles.sampleSwitch(old_profile, profile, elapsed);
|
||||
}
|
||||
@@ -442,13 +477,13 @@ void RadioLibWrapper::serviceProfileScan() {
|
||||
&& visit_us < NF_CALIB_SETTLE_MS * 1000UL) {
|
||||
visit_us = NF_CALIB_SETTLE_MS * 1000UL;
|
||||
}
|
||||
if ((uint32_t)(micros() - _profile_visit_us) >= visit_us) target ^= 1;
|
||||
if (profileElapsedUs(_profile_visit_stamp, profileTimestamp()) >= visit_us) target ^= 1;
|
||||
}
|
||||
const auto result = tuneProfile(target);
|
||||
if (restart_scan && result == mesh::RadioParamApplyResult::APPLIED) {
|
||||
_profile_scan_generation[0] = _profiles.generation[0];
|
||||
_profile_scan_generation[1] = _profiles.generation[1];
|
||||
_profile_visit_us = micros();
|
||||
_profile_visit_stamp = profileTimestamp();
|
||||
}
|
||||
if (result == mesh::RadioParamApplyResult::FAILED) {
|
||||
// Retry a rejected or failing profile at a bounded rate; retain primary RX.
|
||||
@@ -1046,7 +1081,7 @@ void RadioLibWrapper::startRecv() {
|
||||
int err = startReceiveMode();
|
||||
if (err == RADIOLIB_ERR_NONE) {
|
||||
// A very short frame may complete while startReceiveMode() returns.
|
||||
_profile_visit_us = micros();
|
||||
_profile_visit_stamp = profileTimestamp();
|
||||
// Retain that RX interrupt instead of overwriting it with software state.
|
||||
noInterrupts();
|
||||
state = (state & STATE_INT_READY) | STATE_RX;
|
||||
|
||||
@@ -81,7 +81,7 @@ protected:
|
||||
uint16_t _physical_preamble = 0;
|
||||
uint32_t _profile_generation = 0;
|
||||
uint32_t _profile_scan_generation[2] = {};
|
||||
uint32_t _profile_visit_us = 0;
|
||||
uint32_t _profile_visit_stamp = 0;
|
||||
uint32_t _profile_retry_at = 0;
|
||||
bool _profile_rxps_suspended = false;
|
||||
bool _profile_saved_rxps = false;
|
||||
|
||||
Reference in new issue
Block a user