From 59a5663d6c64a13aee5642271e4b1303d6db98d6 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Sun, 28 Sep 2014 19:20:48 +0000
Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5810
 818b1a75-f10b-46b9-bf7c-635c3b92a50f

---
 openair1/PHY/LTE_TRANSPORT/dci_tools.c        | 54 ++++++++++++++-----
 openair1/PHY/LTE_TRANSPORT/phich.c            |  1 +
 openair1/PHY/LTE_TRANSPORT/ulsch_modulation.c |  6 +--
 openair1/SCHED/phy_procedures_lte_common.c    |  2 +-
 openair1/SCHED/phy_procedures_lte_eNb.c       | 13 +++--
 5 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index df6ddd50c35..8a274f2ca71 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -4199,14 +4199,17 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
     if (ulsch->harq_processes[harq_pid]->first_tx==1) {
       //      ulsch->harq_processes[harq_pid]->Ndi                                   = 1;
       ulsch->harq_processes[harq_pid]->first_tx=0;
+      ulsch->harq_processes[harq_pid]->round = 0;
     }
     else {
       if (ulsch->harq_processes[harq_pid]->DCINdi!=ndi) { // new SDU opportunity
 	//	ulsch->harq_processes[harq_pid]->Ndi = 1;
 	ulsch->harq_processes[harq_pid]->DCINdi= ndi;
+	ulsch->harq_processes[harq_pid]->round = 0;
       }
       else {
 	//	ulsch->harq_processes[harq_pid]->Ndi = 0;
+	//	ulsch->harq_processes[harq_pid->round++;  // This is done in phich RX
       }
     }
     ulsch->harq_processes[harq_pid]->n_DMRS                                = cshift;     
@@ -4237,8 +4240,6 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
     else if(cshift == 7)
       ulsch->harq_processes[harq_pid]->n_DMRS2 = 9;
 
-    LOG_D(PHY,"[UE %d][PUSCH %d] Frame %d, subframe %d : Programming PUSCH with n_DMRS2 %d (cshift %d)\n",
-	  phy_vars_ue->Mod_id,harq_pid,phy_vars_ue->frame_rx,subframe,ulsch->harq_processes[harq_pid]->n_DMRS2,cshift);
 
     //reserved for cooperative communication
     /*
@@ -4400,15 +4401,24 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
       // msg("ulsch: saving pmi for DL %x\n",pmi2hex_2Ar1(((wideband_cqi_rank1_2A_5MHz *)ulsch->o)->pmi));
       dlsch[0]->pmi_alloc = ((wideband_cqi_rank1_2A_5MHz *)ulsch->o)->pmi;
     */
-    /*
-      if (frame_parms->frame_type == TDD) 
-      // 2bits if together with SR
-      // 1 bit if ACK only?
-      // check dai business
-      ulsch->harq_processes[harq_pid]->O_ACK                                 = 1; //(dai+1)&3;
-      else 
-    */  ulsch->harq_processes[harq_pid]->O_ACK                                 = 1;
-    
+
+        // check this (see comment in generate_ue_ulsch_params_from_dci)
+    if (frame_parms->frame_type == FDD) {
+      int dl_subframe = (subframe<4) ? (subframe+6) : (subframe-4);
+      if (phy_vars_ue->dlsch_ue[eNB_id][0]->harq_ack[dl_subframe].send_harq_status>0) { // we have downlink transmission
+	ulsch->harq_processes[harq_pid]->O_ACK = 1;
+      }
+      else {
+	ulsch->harq_processes[harq_pid]->O_ACK = 0;
+      }
+    } else {
+      if (ulsch->bundling)
+	ulsch->harq_processes[harq_pid]->O_ACK = (dai == 3)? 0 : 1;
+      else
+	ulsch->harq_processes[harq_pid]->O_ACK = (dai+1)&3;
+      
+      //      ulsch->harq_processes[harq_pid]->V_UL_DAI = dai+1;
+    }
 
     ulsch->beta_offset_cqi_times8                = beta_cqi[phy_vars_ue->pusch_config_dedicated[eNB_id].betaOffset_CQI_Index];//18;
     ulsch->beta_offset_ri_times8                 = beta_ri[phy_vars_ue->pusch_config_dedicated[eNB_id].betaOffset_RI_Index];//10;
@@ -4449,6 +4459,9 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
       //      ulsch->harq_processes[harq_pid]->round++;
     }
 
+    LOG_D(PHY,"[UE %d][PUSCH %d] Frame %d, subframe %d : Programming PUSCH with n_DMRS2 %d (cshift %d), nb_rb %d, first_rb %d, round %d, rv %d\n",
+	  phy_vars_ue->Mod_id,harq_pid,phy_vars_ue->frame_rx,subframe,ulsch->harq_processes[harq_pid]->n_DMRS2,cshift,ulsch->harq_processes[harq_pid]->nb_rb,ulsch->harq_processes[harq_pid]->first_rb,ulsch->harq_processes[harq_pid]->round,ulsch->harq_processes[harq_pid]->rvidx);
+
     // ulsch->n_DMRS2 = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cshift;
 
 #ifdef DEBUG_DCI
@@ -4754,9 +4767,22 @@ int generate_eNB_ulsch_params_from_dci(void *dci_pdu,
       ulsch->uci_format                            = HLC_subband_cqi_nopmi;
     }
 
-    // check this (see comment in generate_ue_ulsch_params_from_dci)
-    ulsch->harq_processes[harq_pid]->O_ACK                                 = 1; //(dai+1)&3;
-
+    if (frame_parms->frame_type == FDD) {
+      int dl_subframe = (subframe<4) ? (subframe+6) : (subframe-4);
+      if (phy_vars_eNB->dlsch_eNB[UE_id][0]->subframe_tx[dl_subframe]>0) { // we have downlink transmission
+	ulsch->harq_processes[harq_pid]->O_ACK = 1;
+      }
+      else {
+	ulsch->harq_processes[harq_pid]->O_ACK = 0;
+      }
+    } else {
+      if (ulsch->bundling)
+	ulsch->harq_processes[harq_pid]->O_ACK = (dai == 3)? 0 : 1;
+      else
+	ulsch->harq_processes[harq_pid]->O_ACK = (dai+1)&3;
+      
+      ulsch->harq_processes[harq_pid]->V_UL_DAI = dai+1;
+    }
 
     ulsch->beta_offset_cqi_times8                = beta_cqi[phy_vars_eNB->pusch_config_dedicated[UE_id].betaOffset_CQI_Index];//18;
     ulsch->beta_offset_ri_times8                 = beta_ri[phy_vars_eNB->pusch_config_dedicated[UE_id].betaOffset_RI_Index];//10;
diff --git a/openair1/PHY/LTE_TRANSPORT/phich.c b/openair1/PHY/LTE_TRANSPORT/phich.c
index 2058d2ee897..1c092e92989 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich.c
@@ -1307,6 +1307,7 @@ void rx_phich(PHY_VARS_UE *phy_vars_ue,
     }
     ulsch->harq_processes[harq_pid]->subframe_scheduling_flag =0;
     ulsch->harq_processes[harq_pid]->status = IDLE;
+    ulsch->harq_processes[harq_pid]->round  = 0;
     // inform MAC?
     phy_vars_ue->ulsch_ue_Msg3_active[eNB_id] = 0;
   }
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/ulsch_modulation.c
index a09d50a3b36..b8acf3dbc9d 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_modulation.c
@@ -338,7 +338,7 @@ void ulsch_modulation(mod_sym_t **txdataF,
 
   int re_offset,re_offset0,i,Msymb,j,k,nsymb,Msc_PUSCH,l;
   //  uint8_t harq_pid = (rag_flag == 1) ? 0 : subframe2harq_pid_tdd(frame_parms->tdd_config,subframe);
-  uint8_t harq_pid = subframe2harq_pid(frame_parms,((subframe==0)?1:0)+frame,subframe);
+  uint8_t harq_pid = subframe2harq_pid(frame_parms,frame,subframe);
   uint8_t Q_m;
   mod_sym_t *txptr;
   uint32_t symbol_offset;
@@ -366,12 +366,12 @@ void ulsch_modulation(mod_sym_t **txdataF,
   nb_rb = ulsch->harq_processes[harq_pid]->nb_rb;
 
   if (nb_rb == 0) {
-    msg("ulsch_modulation.c: Illegal nb_rb %d\n",nb_rb);
+    msg("ulsch_modulation.c: Frame %d, Subframe %d Illegal nb_rb %d\n",frame,subframe,nb_rb);
     return;
   }
 
   if (first_rb >25 ) {
-    msg("ulsch_modulation.c: Illegal first_rb %d\n",first_rb);
+    msg("ulsch_modulation.c: Frame %d, Subframe %d Illegal first_rb %d\n",frame,subframe,first_rb);
     return;
   }
 
diff --git a/openair1/SCHED/phy_procedures_lte_common.c b/openair1/SCHED/phy_procedures_lte_common.c
index 6c909ff6248..e6369aa50a8 100755
--- a/openair1/SCHED/phy_procedures_lte_common.c
+++ b/openair1/SCHED/phy_procedures_lte_common.c
@@ -325,7 +325,7 @@ uint8_t get_ack(LTE_DL_FRAME_PARMS *frame_parms,
   uint8_t status=0;
   uint8_t subframe_dl;
 
-  printf("get_ack: SF %d\n",subframe);
+  //  printf("get_ack: SF %d\n",subframe);
   if (frame_parms->frame_type == FDD) {
     if (subframe < 4)
       subframe_dl = subframe + 6;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 0c0dd49a8b7..4fc32498c83 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -2930,7 +2930,7 @@ void phy_procedures_eNB_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
 			     i,
 			     sched_subframe,
 			     0, // control_only_flag
-			     0, //Nbundled, to be updated!!!!
+			     phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->V_UL_DAI, 
 			     0);  
       }
 #ifdef PHY_ABSTRACTION
@@ -3131,7 +3131,8 @@ void phy_procedures_eNB_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
 			    frame,
 			    phy_vars_eNB->ulsch_eNB[i]->rnti,
 			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
-			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
+			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
+			    harq_pid);
 	  /*
 	    mac_xface->terminate_ra_proc(phy_vars_eNB->Mod_id,
 	    frame,
@@ -3191,7 +3192,8 @@ void phy_procedures_eNB_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
 			    frame,
 			    phy_vars_eNB->ulsch_eNB[i]->rnti,
 			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
-			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
+			    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
+			    harq_pid);
 	  //}
 	  /*
 	    else {
@@ -3582,7 +3584,7 @@ void phy_procedures_eNB_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
 			     i,
 			     sched_subframe,
 			     0, // control_only_flag
-			     0,  //Nbundled, to be updated!!!!
+			     phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->V_UL_DAI, 
 			     0);  
       }
 #ifdef PHY_ABSTRACTION
@@ -3660,7 +3662,8 @@ void phy_procedures_eNB_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
 			      frame,
 			      phy_vars_eNB->ulsch_eNB[i]->rnti,
 			      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
-			      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
+			      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
+			      harq_pid);
 	    phy_vars_eNB->cba_last_reception[i%num_active_cba_groups]=1;//(subframe);
 	  } else {
 	    LOG_N(PHY,"[eNB %d] Frame %d subframe %d : CBA collision detected for UE%d for group %d, set the SR for this UE \n ",
-- 
GitLab