diff --git a/lib/include/srslte/phy/common/timestamp.h b/lib/include/srslte/phy/common/timestamp.h index 266520975..c64e50331 100644 --- a/lib/include/srslte/phy/common/timestamp.h +++ b/lib/include/srslte/phy/common/timestamp.h @@ -58,7 +58,7 @@ SRSLTE_API int srslte_timestamp_add(srslte_timestamp_t* t, time_t full_secs, dou SRSLTE_API int srslte_timestamp_sub(srslte_timestamp_t* t, time_t full_secs, double frac_secs); -SRSLTE_API double srslte_timestamp_real(srslte_timestamp_t* t); +SRSLTE_API double srslte_timestamp_real(const srslte_timestamp_t* t); SRSLTE_API bool srslte_timestamp_iszero(const srslte_timestamp_t* t); diff --git a/lib/src/phy/channel/rlf.c b/lib/src/phy/channel/rlf.c index 422da8d71..0b30392b2 100644 --- a/lib/src/phy/channel/rlf.c +++ b/lib/src/phy/channel/rlf.c @@ -34,11 +34,19 @@ void srslte_channel_rlf_execute(srslte_channel_rlf_t* q, uint32_t nsamples, const srslte_timestamp_t* ts) { - uint32_t period_ms = q->t_on_ms + q->t_off_ms; - double full_secs_ms = (ts->full_secs * 1000) % period_ms; - double frac_secs_ms = (ts->frac_secs * 1000); - double time_ms = full_secs_ms + frac_secs_ms; + // Caulculate full period in MS + uint64_t period_ms = q->t_on_ms + q->t_off_ms; + // Convert seconds to ms and reduce it into 32 bit + uint32_t full_secs_ms = (uint32_t)((ts->full_secs * 1000UL) % period_ms); + + // Convert Fractional seconds into ms and convert it to integer + uint32_t frac_secs_ms = (uint32_t)round(ts->frac_secs * 1000); + + // Add full seconds and fractional performing period module + uint32_t time_ms = (full_secs_ms + frac_secs_ms) % period_ms; + + // Decide whether enables or disables channel if (time_ms < q->t_on_ms) { srslte_vec_sc_prod_cfc(in, 1.0f, out, nsamples); } else { @@ -49,4 +57,4 @@ void srslte_channel_rlf_execute(srslte_channel_rlf_t* q, void srslte_channel_rlf_free(srslte_channel_rlf_t* q) { // Do nothing -} \ No newline at end of file +} diff --git a/lib/src/phy/common/timestamp.c b/lib/src/phy/common/timestamp.c index 0e750dc27..44694b1d8 100644 --- a/lib/src/phy/common/timestamp.c +++ b/lib/src/phy/common/timestamp.c @@ -103,7 +103,7 @@ int srslte_timestamp_sub(srslte_timestamp_t* t, time_t full_secs, double frac_se return ret; } -double srslte_timestamp_real(srslte_timestamp_t* t) +double srslte_timestamp_real(const srslte_timestamp_t* t) { return t->frac_secs + t->full_secs; }