From 846268fdd317ef2ed53f898de5c2b6842ac49b3e Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Tue, 20 Mar 2018 18:02:52 +0100
Subject: [PATCH] bug fix for qpsk modulation

---
 openair1/PHY/LTE_TRANSPORT/dci.c              |  4 +--
 openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c | 29 +++++++++++--------
 openair1/SCHED/phy_procedures_lte_eNb.c       |  1 +
 openair2/LAYER2/MAC/eNB_scheduler_bch.c       |  1 +
 targets/RT/USER/lte-enb.c                     |  4 +--
 targets/RT/USER/lte-ru.c                      | 12 ++++----
 6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dci.c b/openair1/PHY/LTE_TRANSPORT/dci.c
index ded49d1c73..16d0e9d100 100755
--- a/openair1/PHY/LTE_TRANSPORT/dci.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci.c
@@ -2265,7 +2265,7 @@ uint8_t generate_dci_top(uint8_t num_pdcch_symbols,
   y[0] = &yseq0[0];
   y[1] = &yseq1[0];
 
-#if 1
+#if 0
   // reset all bits to <NIL>, here we set <NIL> elements as 2
   // memset(e, 2, DCI_BITS_MAX);
   // here we interpret NIL as a random QPSK sequence. That makes power estimation easier.
@@ -2276,7 +2276,7 @@ uint8_t generate_dci_top(uint8_t num_pdcch_symbols,
   /* clear all bits, the above code may generate too much false detections
    * (not sure about this, to be checked somehow)
    */
-  // memset(e, 0, DCI_BITS_MAX);
+  memset(e, 0, DCI_BITS_MAX);
 
   e_ptr = e;
 
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index 5aec52240b..989d56cf6d 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -2289,7 +2289,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
   amp_rho_b = (int16_t)(((int32_t)amp*dlsch1->sqrt_rho_b)>>13);
   }
 
-  if(mod_order0 == 2)
+  /*if(mod_order0 == 2)
   {
     for(i=0;i<2;i++)
     {
@@ -2297,7 +2297,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
       qpsk_table_b0[i] = (int16_t)(((int32_t)qpsk_table[i]*amp_rho_b)>>15);
     }
   }
-  else if (mod_order0 == 4)
+  else*/ if (mod_order0 == 4)
     for (i=0;i<4; i++) {
       qam16_table_a0[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_a)>>15);
       qam16_table_b0[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_b)>>15);
@@ -2308,14 +2308,14 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
       qam64_table_b0[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_b)>>15);
     }
 
-  if (mod_order1 == 2)
+  /*if (mod_order1 == 2)
   {
     for (i=0; i<2; i++) {
       qpsk_table_a1[i] = (int16_t)(((int32_t)qpsk_table[i]*amp_rho_a)>>15);
       qpsk_table_b1[i] = (int16_t)(((int32_t)qpsk_table[i]*amp_rho_b)>>15);
     }
   }
-  else if (mod_order1 == 4)
+  else*/ if (mod_order1 == 4)
     for (i=0; i<4; i++) {
       qam16_table_a1[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_a)>>15);
       qam16_table_b1[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_b)>>15);
@@ -2444,11 +2444,11 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
     switch (mod_order0) {
     case 2:
-      //qam_table_s0 = NULL;
-      if (pilots) {
+      qam_table_s0 = NULL;
+      /*if (pilots) {
         qam_table_s0 = qpsk_table_b0;
 #ifdef NEW_ALLOC_RE
-        /* TODO: remove this code? */
+        // TODO: remove this code? //
         allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
           allocate_REs_in_RB_pilots_QPSK_siso :
           allocate_REs_in_RB;
@@ -2457,13 +2457,13 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
       else {
         qam_table_s0 = qpsk_table_a0;
 #ifdef NEW_ALLOC_RE
-        /* TODO: remove this code? */
+        // TODO: remove this code? //
         allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
           allocate_REs_in_RB_no_pilots_QPSK_siso :
           allocate_REs_in_RB;
 #endif
 
-      }
+      }*/
       break;
     case 4:
       if (pilots) {
@@ -2512,12 +2512,17 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
     switch (mod_order1) {
     case 2:
-      if (pilots) {
+      qam_table_s1 = NULL;
+#ifdef NEW_ALLOC_RE
+        /* TODO: remove this code? */
+      allocate_REs = allocate_REs_in_RB;
+#endif
+      /*if (pilots) {
         qam_table_s1 = qpsk_table_b1;
       }
       else {
         qam_table_s1 = qpsk_table_a1;
-      }
+      }*/
       break;
     case 4:
       if (pilots) {
@@ -2593,7 +2598,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
                                rb);
 
 
-      allocate_REs(phy_vars_eNB,
+      allocate_REs_in_RB(phy_vars_eNB,
                          txdataF,
                          &jj,
                          &jj2,
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 31b327f992..b5c8ddf7be 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -551,6 +551,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
         else
         {
           // generate pdsch
+//printf("%d.%d pdsch_procedures ue rnti %d\n", frame, subframe, dlsch0->rnti);///////////////////////////////////**********************
           pdsch_procedures(eNB,
               proc,
               harq_pid,
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index de4641fac6..f12702fbb8 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -787,6 +787,7 @@ schedule_SI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 		eNB->eNB_stats[CC_id].bcch_buffer = bcch_sdu_length;
 		eNB->eNB_stats[CC_id].total_bcch_buffer += bcch_sdu_length;
 		eNB->eNB_stats[CC_id].bcch_mcs = mcs;
+//printf("SI %d.%d\n", frameP, subframeP);/////////////////////////////////////////******************************
 	    } else {
 
 		//LOG_D(MAC,"[eNB %d] Frame %d : BCCH not active \n",Mod_id,frame);
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 5d2f79a45b..54c6ddeb30 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -240,7 +240,7 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
   if(get_nprocs() >= 8){
     wakeup_tx(eNB,eNB->proc.ru_proc);
   }
-  else if(get_nprocs() > 4){
+  else if(get_nprocs() >= 4){
   
     phy_procedures_eNB_TX(eNB, proc, no_relay, NULL, 1);
     wakeup_txfh(proc,eNB->proc.ru_proc);
@@ -1041,7 +1041,7 @@ void kill_eNB_proc(int inst) {
       pthread_mutex_lock(&proc_rxtx[i].mutex_rxtx);
       proc_rxtx[i].instance_cnt_rxtx = 0;
       proc_rxtx[i].pipe_ready = 0;
-      pthread_cond_signal( &proc_rxtx[i].cond_rxtx );
+      pthread_cond_signal(&proc_rxtx[i].cond_rxtx);
       pthread_mutex_unlock(&proc_rxtx[i].mutex_rxtx);
     }
     proc->instance_cnt_prach = 0;
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 795635ce9d..642655804d 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -1181,7 +1181,7 @@ void wakeup_eNBs(RU_t *ru) {
   LOG_D(PHY,"wakeup_eNBs (num %d) for RU %d ru->eNB_top:%p\n",ru->num_eNB,ru->idx, ru->eNB_top);
 
 
-  if (ru->num_eNB==1 && ru->eNB_top!=0 && get_nprocs() <= 4) {
+  if (ru->num_eNB==1 && ru->eNB_top!=0 && get_nprocs() < 4) {
     // call eNB function directly
   
     char string[20];
@@ -1645,7 +1645,7 @@ static void* ru_thread( void* param ) {
     // wakeup all eNB processes waiting for this RU
     if (ru->num_eNB>0) wakeup_eNBs(ru);
     
-    if(get_nprocs() <= 4){
+    if(get_nprocs() < 4){
       // do TX front-end processing if needed (precoding and/or IDFTs)
       if (ru->feptx_prec) ru->feptx_prec(ru);
       
@@ -1859,7 +1859,7 @@ void init_RU_proc(RU_t *ru) {
   if(emulate_rf)
     pthread_create( &proc->pthread_emulateRF, attr_emulateRF, emulatedRF_thread, (void*)proc );
 
-  if (get_nprocs() > 4)
+  if (get_nprocs() >= 4)
     pthread_create( &proc->pthread_FH1, attr_FH1, ru_thread_tx, (void*)ru );
 
   if (ru->function == NGFI_RRU_IF4p5) {
@@ -1958,7 +1958,7 @@ void kill_RU_proc(int inst)
       pthread_join(proc->pthread_asynch_rxtx, NULL);
     }
   }
-  if (get_nprocs() >= 2 && fepw) {
+  if (get_nprocs() > 2 && fepw) {
     if (ru->feprx) {
       pthread_mutex_lock(&proc->mutex_fep);
       proc->instance_cnt_fep = 0;
@@ -2250,8 +2250,8 @@ void set_function_spec_param(RU_t *ru)
     }
     else if (ru->function == eNodeB_3GPP) {
       ru->do_prach             = 0;                       // no prach processing in RU
-      ru->feprx                = (get_nprocs()<=2) ? fep_full : ru_fep_full_2thread;                // RX DFTs
-      ru->feptx_ofdm           = (get_nprocs()<=2) ? feptx_ofdm : feptx_ofdm_2thread;              // this is fep with idft and precoding
+      ru->feprx                = (get_nprocs()<=2 || !fepw) ? fep_full : ru_fep_full_2thread;                // RX DFTs
+      ru->feptx_ofdm           = (get_nprocs()<=2 || !fepw) ? feptx_ofdm : feptx_ofdm_2thread;              // this is fep with idft and precoding
       ru->feptx_prec           = feptx_prec;              // this is fep with idft and precoding
       ru->fh_north_in          = NULL;                    // no incoming fronthaul from north
       ru->fh_north_out         = NULL;                    // no outgoing fronthaul to north
-- 
GitLab