From 524d1b4c9d002ebeb0b6555892870afd50c8d510 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Tue, 26 Aug 2014 09:32:40 +0000
Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5757
 818b1a75-f10b-46b9-bf7c-635c3b92a50f

---
 openair1/PHY/LTE_TRANSPORT/dci_tools.c      |  7 +++++--
 openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c |  5 +++--
 openair1/PHY/defs.h                         |  8 ++++++++
 openair1/SCHED/phy_procedures_lte_common.c  |  6 +++++-
 openair1/SCHED/phy_procedures_lte_eNb.c     |  6 +++---
 openair1/SCHED/phy_procedures_lte_ue.c      | 18 ++++++++++++------
 6 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 84463c1bbe..6a75675edb 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -2877,6 +2877,9 @@ int generate_ue_dlsch_params_from_dci(uint8_t subframe,
     dlsch[0]->harq_processes[harq_pid]->mimo_mode = frame_parms->mode1_flag == 1 ?SISO : ALAMOUTI;
     dlsch[0]->harq_processes[harq_pid]->dl_power_off = 1; //no power offset
 
+    LOG_D(PHY,"UE (%x/%d): Subframe %d Format1A DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
+	  dlsch[0]->harq_processes[harq_pid]->first_tx,dlsch[0]->harq_processes[harq_pid]->status);
+
     if ((ndi!=dlsch[0]->harq_processes[harq_pid]->DCINdi)||  // DCI has been toggled or this is the first transmission
 	(dlsch[0]->harq_processes[harq_pid]->first_tx==1)) {
       dlsch[0]->harq_processes[harq_pid]->round = 0;
@@ -3000,8 +3003,8 @@ int generate_ue_dlsch_params_from_dci(uint8_t subframe,
     dlsch[0]->harq_processes[harq_pid]->mimo_mode   = (frame_parms->mode1_flag == 1) ? SISO : ALAMOUTI;
     dlsch[0]->harq_processes[harq_pid]->dl_power_off = 1; //no power offset
 
-    LOG_D(PHY,"Format1 DCI: ndi %d, old_ndi %d (first tx %d)\n",ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
-	  dlsch[0]->harq_processes[harq_pid]->first_tx);
+    LOG_D(PHY,"UE (%x/%d): Subframe %d Format1 DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
+	  dlsch[0]->harq_processes[harq_pid]->first_tx,dlsch[0]->harq_processes[harq_pid]->status);
 
     //    printf("Format1 DCI (UE, hard pid %d): ndi %d, old_ndi %d (first tx %d)\n",harq_pid,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
     //	  dlsch[0]->harq_processes[harq_pid]->first_tx);
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
index 6329a88e85..f5a488634b 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
@@ -409,7 +409,7 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
     dlsch->harq_ack[subframe].harq_id = harq_pid;
     dlsch->harq_ack[subframe].send_harq_status = 1;
     harq_process->round++;
-    //    msg("DLSCH: Setting NACK for subframe %d (pid %d, round %d)\n",subframe,harq_pid,harq_process->round);
+    LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
     if (harq_process->round >= dlsch->Mdlharq) {
       harq_process->status = SCH_IDLE;
     }
@@ -422,7 +422,8 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
     dlsch->harq_ack[subframe].ack = 1;
     dlsch->harq_ack[subframe].harq_id = harq_pid;
     dlsch->harq_ack[subframe].send_harq_status = 1;
-    //    msg("DLSCH decoding: Setting ACK for subframe %d (pid %d)\n",subframe,harq_pid);
+    LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
+
   }
   // Reassembly of Transport block here
   offset = 0;
diff --git a/openair1/PHY/defs.h b/openair1/PHY/defs.h
index f07757e65f..7417d6393e 100755
--- a/openair1/PHY/defs.h
+++ b/openair1/PHY/defs.h
@@ -354,6 +354,12 @@ typedef struct
   uint8_t Mod_id;
   uint8_t CC_id;
   uint8_t local_flag;
+  int instance_cnt_tx;
+  int instance_cnt_rx;
+  pthread_cond_t cond_tx;
+  pthread_cond_t cond_rx;
+  pthread_mutex_t mutex_tx;
+  pthread_mutex_t mutex_rx;
   uint32_t tx_total_gain_dB;
   uint32_t rx_total_gain_dB; ///this is a function of rx_gain_mode (and the corresponding gain) and the rx_gain of the card
   uint32_t rx_gain_max[4];
@@ -365,6 +371,8 @@ typedef struct
   int tx_total_RE;
   int8_t tx_power_max_dBm;
   uint32_t frame;
+  uint32_t frame_rx,frame_tx;
+  uint32_t slot_tx,slot_rx;
   uint8_t n_connected_eNB;
   uint8_t ho_initiated;
   uint8_t ho_triggered;
diff --git a/openair1/SCHED/phy_procedures_lte_common.c b/openair1/SCHED/phy_procedures_lte_common.c
index 2ad3a4e8d3..6c909ff624 100755
--- a/openair1/SCHED/phy_procedures_lte_common.c
+++ b/openair1/SCHED/phy_procedures_lte_common.c
@@ -321,10 +321,11 @@ uint8_t get_ack(LTE_DL_FRAME_PARMS *frame_parms,
 	   unsigned char subframe,
 	   unsigned char *o_ACK) {
 
-  //printf("get_ack: SF %d\n",subframe);
+
   uint8_t status=0;
   uint8_t subframe_dl;
 
+  printf("get_ack: SF %d\n",subframe);
   if (frame_parms->frame_type == FDD) {
     if (subframe < 4)
       subframe_dl = subframe + 6;
@@ -372,6 +373,7 @@ uint8_t get_ack(LTE_DL_FRAME_PARMS *frame_parms,
 	else if (harq_ack[6].send_harq_status == 1)
 	  o_ACK[0] = harq_ack[6].ack;
 	status = harq_ack[5].send_harq_status + (harq_ack[6].send_harq_status<<1);
+	printf("Subframe 2, TDD config 3: harq_ack[5] = %d (%d),harq_ack[6] = %d (%d)\n",harq_ack[5].ack,harq_ack[5].send_harq_status,harq_ack[6].ack,harq_ack[6].send_harq_status);
       }
       else if (subframe == 3) {   // ACK subframes 7 and 8
 	if (harq_ack[7].send_harq_status == 1) {
@@ -383,6 +385,7 @@ uint8_t get_ack(LTE_DL_FRAME_PARMS *frame_parms,
 	  o_ACK[0] = harq_ack[8].ack;
 
 	status = harq_ack[7].send_harq_status + (harq_ack[8].send_harq_status<<1);
+	printf("Subframe 3, TDD config 3: harq_ack[7] = %d,harq_ack[8] = %d\n",harq_ack[7].ack,harq_ack[8].ack);
 	//printf("status %d : o_ACK (%d,%d)\n", status,o_ACK[0],o_ACK[1]);
       }
       else if (subframe == 4) {  // ACK subframes 9 and 0
@@ -395,6 +398,7 @@ uint8_t get_ack(LTE_DL_FRAME_PARMS *frame_parms,
 	  o_ACK[0] = harq_ack[8].ack;
 
 	status = harq_ack[9].send_harq_status + (harq_ack[0].send_harq_status<<1);
+	printf("Subframe 4, TDD config 3: harq_ack[9] = %d,harq_ack[0] = %d\n",harq_ack[9].ack,harq_ack[0].ack);
       }
       else {
 	LOG_E(PHY,"phy_procedures_lte.c: get_ack, illegal subframe %d for tdd_config %d\n",
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 24b06d047e..bf2b917dee 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -2208,7 +2208,7 @@ void process_HARQ_feedback(uint8_t UE_id,
       //    but we have to adapt the code below.  For example, if only one out of 2 are scheduled, only 1 bit o_ACK is used
 
       dlsch_ACK[0] = phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->o_ACK[0];
-      dlsch_ACK[1] = phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->o_ACK[1];
+      dlsch_ACK[1] = (phy_vars_eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode == bundling)?phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->o_ACK[0]:phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->o_ACK[1];
       //      printf("UE %d: ACK %d,%d\n",UE_id,dlsch_ACK[0],dlsch_ACK[1]);
     }
 
@@ -2315,8 +2315,8 @@ void process_HARQ_feedback(uint8_t UE_id,
 	  if ( dlsch_ACK[mp]==0) {
 	    // Received NAK 
 #ifdef DEBUG_PHY_PROC	
-	    LOG_I(PHY,"[eNB %d][PDSCH %x/%d] NAK Received in round %d, requesting retransmission\n",phy_vars_eNB->Mod_id,
-		  dlsch->rnti,dl_harq_pid[m],dlsch_harq_proc->round);
+	    LOG_I(PHY,"[eNB %d][PDSCH %x/%d] M = %d, m= %d, mp=%d NAK Received in round %d, requesting retransmission\n",phy_vars_eNB->Mod_id,
+		  dlsch->rnti,dl_harq_pid[m],M,m,mp,dlsch_harq_proc->round);
 #endif
 	    
 	    //	    if (dlsch_harq_proc->round == 0)
diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
index 7a0c348ed3..f80719677d 100755
--- a/openair1/SCHED/phy_procedures_lte_ue.c
+++ b/openair1/SCHED/phy_procedures_lte_ue.c
@@ -2074,6 +2074,7 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
 #ifdef DEBUG_PHY_PROC
 	LOG_D(PHY,"[UE  %d] Generated UE DLSCH C_RNTI format %d\n",phy_vars_ue->Mod_id,dci_alloc_rx[i].format);
 	dump_dci(&phy_vars_ue->lte_frame_parms, &dci_alloc_rx[i]);
+	LOG_D(PHY,"[UE %d] *********** dlsch->active in subframe %d (%d)=> %d\n",phy_vars_ue->Mod_id,(last_slot>>1),last_slot,phy_vars_ue->dlsch_ue[eNB_id][0]->active); 
 #endif    
 	
 	// we received a CRNTI, so we're in PUSCH
@@ -2352,6 +2353,8 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
       n_symb = phy_vars_ue->lte_frame_parms.symbols_per_tti/2;
   }
   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+  LOG_D(PHY,"[UE %d] *********** dlsch->active in subframe %d (%d)=> %d\n",phy_vars_ue->Mod_id,(last_slot>>1),last_slot,phy_vars_ue->dlsch_ue[eNB_id][0]->active); 
   
   // This is normal processing (i.e. not MBSFN)
   // RX processing of symbols in last_slot
@@ -2426,7 +2429,7 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
               }
           }
           // trigger DLSCH decoding thread
-          if (!(last_slot%2)) // odd slots
+          if ((last_slot%2)==1) // odd slots
               phy_vars_ue->dlsch_ue[eNB_id][0]->active = 0;
       }
     }
@@ -2435,18 +2438,20 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
     // process last DLSCH symbols + invoke decoding
     if (((last_slot%2)==0) && (l==0)) {
       // Regular PDSCH
+
+      LOG_D(PHY,"[UE %d] dlsch->active in subframe %d => %d\n",phy_vars_ue->Mod_id,((last_slot>>1)+9)%10,phy_vars_ue->dlsch_ue[eNB_id][0]->active); 
       if (phy_vars_ue->dlsch_ue[eNB_id][0]->active == 1) {
 #ifndef DLSCH_THREAD //USER_MODE
 	harq_pid = phy_vars_ue->dlsch_ue[eNB_id][0]->current_harq_pid;
-	//printf("PDSCH active in subframe %d, harq_pid %d\n",(last_slot>>1)-1,harq_pid); 
+	LOG_D(PHY,"[UE %d] PDSCH active in subframe %d, harq_pid %d\n",phy_vars_ue->Mod_id,((last_slot>>1)+1)%10,harq_pid); 
 	if ((phy_vars_ue->transmission_mode[eNB_id] == 5) && 
 	    (phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->dl_power_off==0) &&
 	    (openair_daq_vars.use_ia_receiver ==1)) {
 	  dual_stream_UE = 1;
 	  eNB_id_i = phy_vars_ue->n_connected_eNB;
 	  i_mod = get_Qm(phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->mcs);
-      if (phy_vars_ue->frame%100==0) {
-          LOG_I(PHY,"using IA receiver\n");
+	  if (phy_vars_ue->frame%100==0) {
+	    LOG_I(PHY,"using IA receiver\n");
       }
 	}
 	else {
@@ -2541,9 +2546,9 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
 #endif
 	  }
 	  else {
-	    LOG_I(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d: Received DLSCH (rv %d,mcs %d,TBS %d)\n",
+	    LOG_I(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d (last_slot %d): Received DLSCH (rv %d,mcs %d,TBS %d)\n",
 		  phy_vars_ue->Mod_id,phy_vars_ue->dlsch_ue[eNB_id][0]->rnti,
-		  harq_pid,phy_vars_ue->frame,((last_slot>>1)==0)?9:(last_slot>>1)-1,
+		  harq_pid,phy_vars_ue->frame,((last_slot>>1)==0)?9:(last_slot>>1)-1,last_slot,
 		  phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->rvidx,
 		  phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->mcs,
 		  phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->TBS);
@@ -2943,6 +2948,7 @@ int lte_ue_pdcch_procedures(uint8_t eNB_id,uint8_t last_slot, PHY_VARS_UE *phy_v
 #ifndef DLSCH_THREAD
         if (phy_vars_ue->dlsch_ue[eNB_id][0]->active == 1)  {
             harq_pid = phy_vars_ue->dlsch_ue[eNB_id][0]->current_harq_pid;
+	    LOG_D(PHY,"[UE %d] PDSCH active in subframe %d (%d), harq_pid %d\n",phy_vars_ue->Mod_id,(last_slot>>1),last_slot,harq_pid); 
             if ((phy_vars_ue->transmission_mode[eNB_id] == 5) && 
                 (phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid]->dl_power_off==0) &&
                 (openair_daq_vars.use_ia_receiver ==1)) {
-- 
GitLab