From 8bf9ba333f59fbc41332ef1792552c15ab1e0d91 Mon Sep 17 00:00:00 2001
From: knopp <knopp@mycompany.com>
Date: Mon, 22 Jun 2015 08:04:30 +0000
Subject: [PATCH] some bugfixes for PUSCH and PUCCH power control

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7617 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/LAYER2/MAC/eNB_scheduler_dlsch.c | 19 ++++++++++---------
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 14 ++++++++++----
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index e14cb43764..bee94680e4 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -1166,15 +1166,17 @@ schedule_ue_spec(
 	  // do PUCCH power control
           // this is the normalized RX power
 	  eNB_UE_stats =  mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
-	  if (eNB_UE_stats->Po_PUCCH_update == 1) { 
-	    eNB_UE_stats->Po_PUCCH_update = 0;
-	    normalized_rx_power = eNB_UE_stats->Po_PUCCH_dBm; 
-	    target_rx_power = mac_xface->get_target_pucch_rx_power(module_idP,CC_id) + 10;
+	  normalized_rx_power = eNB_UE_stats->Po_PUCCH_dBm; 
+	  target_rx_power = mac_xface->get_target_pucch_rx_power(module_idP,CC_id) + 10;
 	    
           // this assumes accumulated tpc
 	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
-	    if (((((UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe)%10240)+10)<(frameP*10+subframeP))
-		|| (((UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe)%10240)>(frameP*10+subframeP))) {
+	  int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
+          if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
+	      ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
+	    if (eNB_UE_stats->Po_PUCCH_update == 1) { 
+	      eNB_UE_stats->Po_PUCCH_update = 0;
+
 	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame=frameP;
 	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe=subframeP;
 	      if (normalized_rx_power>(target_rx_power+1)) {
@@ -1189,11 +1191,10 @@ schedule_ue_spec(
 	      LOG_I(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
 		    module_idP,frameP, subframeP,harq_pid,tpc,
 		    tpc_accumulated,normalized_rx_power,target_rx_power);
-	    } // time to do TPC update 
+	    } // Po_PUCCH has been updated 
 	    else {
 	      tpc = 1; //0
-	    }
-	  } // Po_PUCCH has been updated 
+	    } // time to do TPC update 
 	  else {
 	    tpc = 1; //0
 	  }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index 6acb98cd14..80aa679d41 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -755,7 +755,10 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
 
           // this assumes accumulated tpc
 	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
-          if (((UE_template->pusch_tpc_tx_frame*10+UE_template->pusch_tpc_tx_subframe)%10240)<(frameP*10+subframeP+10)) {
+	  int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame*10+UE_template->pusch_tpc_tx_subframe;
+          if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
+	      ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
+	    {
 	    UE_template->pusch_tpc_tx_frame=frameP;
 	    UE_template->pusch_tpc_tx_subframe=subframeP;
             if (normalized_rx_power>(target_rx_power+1)) {
@@ -767,13 +770,16 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
             } else {
               tpc = 1; //0
             }
-	    LOG_I(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
-		  module_idP,frameP,subframeP,harq_pid,tpc,
-		  tpc_accumulated,normalized_rx_power,target_rx_power);
           } else {
             tpc = 1; //0
           }
 
+	  if (tpc!=1) {
+	    LOG_I(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
+		  module_idP,frameP,subframeP,harq_pid,tpc,
+		  tpc_accumulated,normalized_rx_power,target_rx_power);
+	  }
+
           // new transmission
           if (round==0) {
 
-- 
GitLab