From 9e2a7d45925ed7a751252f2b65dff201be1fb731 Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 4 Jun 2021 14:38:40 +0100 Subject: [PATCH] bugfix,tpc: only cap PUSCH TPC when PHR is negative. I also extended TPC unit test --- srsenb/hdr/stack/mac/sched_ue_ctrl/tpc.h | 14 ++++++++------ srsenb/test/mac/sched_tpc_test.cc | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/srsenb/hdr/stack/mac/sched_ue_ctrl/tpc.h b/srsenb/hdr/stack/mac/sched_ue_ctrl/tpc.h index cadfe2aab..0c7df3634 100644 --- a/srsenb/hdr/stack/mac/sched_ue_ctrl/tpc.h +++ b/srsenb/hdr/stack/mac/sched_ue_ctrl/tpc.h @@ -173,10 +173,9 @@ private: // more time required before sending next TPC return encode_tpc_delta(0); } - if (last_phr < 0 and not ch_snr.phr_flag) { - // negative PHR - logger.info( - "TPC: rnti=0x%x, %s command=-1 due to PHR=%d < 0", rnti, cc == PUSCH_CODE ? "PUSCH" : "PUCCH", last_phr); + if (cc == PUSCH_CODE and last_phr < 0 and not ch_snr.phr_flag) { + // if negative PHR and PUSCH + logger.info("TPC: rnti=0x%x, PUSCH command=0 due to PHR=%d<0", rnti, last_phr); ch_snr.phr_flag = true; return encode_tpc_delta(-1); } @@ -185,8 +184,11 @@ private: float diff = target_snr_dB - ch_snr.snr_avg.value(); diff -= ch_snr.win_tpc_values.value() + ch_snr.acc_tpc_values; if (diff >= 1) { - diff = std::min(diff, (float)std::max(last_phr, 0)); // low PHR places a cap on TPC - ch_snr.pending_delta = diff > 3 ? 3 : 1; + ch_snr.pending_delta = diff > 3 ? 3 : 1; + if (cc == PUSCH_CODE and static_cast(ch_snr.pending_delta) > last_phr) { + // cap PUSCH TPC when PHR is low + ch_snr.pending_delta = last_phr > 1 ? 1 : 0; + } ch_snr.last_tpc_tti_count = tti_count; } else if (diff <= -1) { ch_snr.pending_delta = -1; diff --git a/srsenb/test/mac/sched_tpc_test.cc b/srsenb/test/mac/sched_tpc_test.cc index 1bd28d559..914cd36e3 100644 --- a/srsenb/test/mac/sched_tpc_test.cc +++ b/srsenb/test/mac/sched_tpc_test.cc @@ -71,6 +71,25 @@ int test_finite_target_snr() TESTASSERT(sum_pucch > 0 and sum_pucch <= -snr_diff); } + // TEST: PHR is negative. Checks: + // - one TPC should be sent to decrease power. No more TPCs != 0 should be sent until the next PHR + snr_diff = -10; + tpcfsm.set_snr(target_snr + snr_diff, tpc::PUSCH_CODE); + tpcfsm.set_snr(target_snr + snr_diff, tpc::PUCCH_CODE); + for (uint32_t i = 0; i < 3; ++i) { + tpcfsm.set_phr(-2, 1); + tpcfsm.new_tti(); + TESTASSERT(decode_tpc(tpcfsm.encode_pusch_tpc()) == -1); + TESTASSERT(decode_tpc(tpcfsm.encode_pucch_tpc()) == 3); // PUCCH doesnt get affected by neg PHR + for (uint32_t j = 0; j < 100; ++j) { + tpcfsm.new_tti(); + TESTASSERT(decode_tpc(tpcfsm.encode_pusch_tpc()) == 0); + } + } + tpcfsm.set_phr(20, 1); + tpcfsm.new_tti(); + TESTASSERT(decode_tpc(tpcfsm.encode_pusch_tpc()) == 3); + return SRSRAN_SUCCESS; }