srsue,sync: fix TTI gap calculation and reporting

The current TTI gap calculation assumes strict continuity
of radio time stamps, even when retuning, changing sample rate, etc.

This is certainly desireble but not necessaritly the case and may cause
issues when negative time gaps or too large gaps are detected and reported
to the stack.

this patch makes the assumption that valid TTI jumps are between 1ms
and 1s and that larger gaps are the result of screwed time-stamps
or too long radio operations.
master
Andre Puschmann 5 years ago
parent 5d92111586
commit 1e0c8ead4c

@ -167,6 +167,8 @@ private:
bool running = false;
bool is_overflow = false;
bool forced_rx_time_init = true; // Rx time sync after first receive from radio
// Objects for internal use
search search_p;
sfn_sync sfn_p;
@ -340,7 +342,6 @@ private:
bool started = false;
uint32_t tti = 0;
srslte_timestamp_t tti_ts = {};
srslte_timestamp_t radio_ts = {};
std::array<uint8_t, SRSLTE_BCH_PAYLOAD_LEN> mib = {};
uint32_t nof_workers = 0;
@ -352,6 +353,9 @@ private:
float dl_freq = -1;
float ul_freq = -1;
const static int MIN_TTI_JUMP = 1; // Time gap reported to stack after receiving subframe
const static int MAX_TTI_JUMP = 1000; // Maximum time gap tolerance in RF stream metadata
const uint8_t SYNC_CC_IDX = 0; ///< From the sync POV, the CC idx is always the first
};

@ -825,23 +825,40 @@ int sync::radio_recv_fnc(srslte::rf_buffer_t& data, uint32_t nsamples, srslte_ti
// Receive
if (radio_h->rx_now(data, nsamples, rx_time)) {
// Detect Radio Timestamp reset
if (srslte_timestamp_compare(rx_time, &radio_ts) < 0) {
srslte_timestamp_init(&radio_ts, 0, 0.0);
// check timestamp reset
if (forced_rx_time_init || srslte_timestamp_iszero(&tti_ts) || srslte_timestamp_compare(rx_time, &tti_ts) < 0) {
if (srslte_timestamp_compare(rx_time, &tti_ts) < 0) {
log_h->warning("SYNC: radio time seems to be going backwards (rx_time=%f, tti_ts=%f)\n",
srslte_timestamp_real(rx_time),
srslte_timestamp_real(&tti_ts));
// time-stamp will be set to rx time below and run_tti() will be called with MIN_TTI_JUMP
}
// init tti_ts with last rx time
log_h->debug("SYNC: Setting initial TTI time to %f\n", srslte_timestamp_real(rx_time));
srslte_timestamp_copy(&tti_ts, rx_time);
forced_rx_time_init = false;
}
srslte_timestamp_copy(&radio_ts, rx_time);
// Advance stack in time
if (srslte_timestamp_compare(rx_time, &tti_ts) > 0) {
uint32_t tti_jump = ceil((srslte_timestamp_real(rx_time) - srslte_timestamp_real(&tti_ts)) / 1.0e-3);
if (srslte_timestamp_compare(rx_time, &tti_ts) >= 0) {
srslte_timestamp_t temp = {};
srslte_timestamp_copy(&temp, rx_time);
srslte_timestamp_sub(&temp, tti_ts.full_secs, tti_ts.frac_secs);
int32_t tti_jump = static_cast<int32_t>(srslte_timestamp_uint64(&temp, 1e3));
tti_jump = SRSLTE_MAX(tti_jump, MIN_TTI_JUMP);
if (tti_jump > MAX_TTI_JUMP) {
log_h->warning("SYNC: TTI jump of %d limited to %d\n", tti_jump, MAX_TTI_JUMP);
tti_jump = SRSLTE_MIN(tti_jump, MAX_TTI_JUMP);
}
// Run stack
stack->run_tti(tti, tti_jump);
// Increase by the number of tti jumps detected
srslte_timestamp_add(&tti_ts, 0, tti_jump * 1.0e-3f);
}
// update timestamp
srslte_timestamp_copy(&tti_ts, rx_time);
if (channel_emulator && rx_time) {
channel_emulator->set_srate((uint32_t)current_srate);
channel_emulator->run(data.to_cf_t(), data.to_cf_t(), nsamples, *rx_time);

Loading…
Cancel
Save