From 30cc9c1c66a749484a6c0842dc6f2d5669127319 Mon Sep 17 00:00:00 2001
From: WANG Tsu-Han <wangts@eurecom.fr>
Date: Wed, 22 Aug 2018 15:36:43 +0200
Subject: [PATCH] adding half fill mechanism into accelorated modulation

---
 openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c | 213 +++++++++++++-----
 openair2/LAYER2/MAC/eNB_scheduler_phytest.c   |   6 +-
 2 files changed, 161 insertions(+), 58 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index 0bd28b6827..19fefc845e 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -165,10 +165,19 @@ int allocate_REs_in_RB_no_pilots_QPSK_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
+
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re;
 
   if (skip_dc == 0) {
-    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
-         re<12;
+    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
+         re<last_re;
          re++,x0p+=2,tti_offset++) {
 
       qpsk_table_offset_re=x0p[0];
@@ -199,8 +208,16 @@ int allocate_REs_in_RB_no_pilots_QPSK_siso(PHY_VARS_eNB* phy_vars_eNB,
       ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qpsk_table_offset_im];
     }
   }
-  *re_allocated = *re_allocated + 12;
-  *jj=*jj + 24;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 6;
+    *jj=*jj + 12;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 12;
+    *jj=*jj + 24;
+  }
 
     return(0);
 }
@@ -238,12 +255,20 @@ int allocate_REs_in_RB_pilots_QPSK_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
 
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re+P1_SHIFT[0];
 
   if (skip_dc == 0) {
     //    printf("pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
-    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
-         re<12;
+    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
+         re<last_re;
          x0p+=2) {
 
       qpsk_table_offset_re=x0p[0];
@@ -280,8 +305,16 @@ int allocate_REs_in_RB_pilots_QPSK_siso(PHY_VARS_eNB* phy_vars_eNB,
       re+=P1_SHIFT[re+1];
     }
   }
-  *re_allocated = *re_allocated + 10;
-  *jj=*jj + 20;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 5;
+    *jj=*jj + 10;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 10;
+    *jj=*jj + 20;
+  }
 
   return(0);
 }
@@ -317,10 +350,19 @@ int allocate_REs_in_RB_no_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
+
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re;
 
   if (skip_dc == 0) {
-    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
-         re<12;
+    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
+         re<last_re;
          re++,x0p+=4,tti_offset++) {
 
       qam16_table_offset_re=TWO[x0p[0]];
@@ -357,8 +399,16 @@ int allocate_REs_in_RB_no_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
       ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
     }
   }
-  *re_allocated = *re_allocated + 12;
-  *jj=*jj + 48;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 6;
+    *jj=*jj + 24;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 12;
+    *jj=*jj + 48;
+  }
 
     return(0);
 }
@@ -396,12 +446,21 @@ int allocate_REs_in_RB_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
+
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re+P1_SHIFT[0];
 
 
   if (skip_dc == 0) {
     //    LOG_I(PHY,"pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
-    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
-         re<12;
+    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
+         re<last_re;
          x0p+=4) {
 
       qam16_table_offset_re=TWO[x0p[0]];
@@ -444,8 +503,16 @@ int allocate_REs_in_RB_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
       re+=P1_SHIFT[re+1];
     }
   }
-  *re_allocated = *re_allocated + 10;
-  *jj=*jj + 40;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 5;
+    *jj=*jj + 20;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 10;
+    *jj=*jj + 40;
+  }
 
   return(0);
 }
@@ -482,10 +549,19 @@ int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
+
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re;
 
   if (skip_dc == 0) {
 
-    x0p=&x0[*jj],tti_offset=symbol_offset+re_offset;
+    x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
 
     /*    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
          re<12;
@@ -521,36 +597,38 @@ int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
       ((int16_t *)&txdataF[0][tti_offset])[10]=qam_table_s0[qam64_table_offset_re];
       ((int16_t *)&txdataF[0][tti_offset])[11]=qam_table_s0[qam64_table_offset_im];
 
-      qam64_table_offset_re=(x0p[36]<<2)|(x0p[38]<<1)|x0p[40];
-      qam64_table_offset_im=(x0p[37]<<2)|(x0p[39]<<1)|x0p[41];
-      ((int16_t *)&txdataF[0][tti_offset])[12]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[13]=qam_table_s0[qam64_table_offset_im];
-
-      qam64_table_offset_re=(x0p[42]<<2)|(x0p[44]<<1)|x0p[46];
-      qam64_table_offset_im=(x0p[43]<<2)|(x0p[45]<<1)|x0p[47];
-      ((int16_t *)&txdataF[0][tti_offset])[14]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[15]=qam_table_s0[qam64_table_offset_im];
-
-      qam64_table_offset_re=(x0p[48]<<2)|(x0p[50]<<1)|x0p[52];
-      qam64_table_offset_im=(x0p[49]<<2)|(x0p[51]<<1)|x0p[53];
-      ((int16_t *)&txdataF[0][tti_offset])[16]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[17]=qam_table_s0[qam64_table_offset_im];
-
-      qam64_table_offset_re=(x0p[54]<<2)|(x0p[56]<<1)|x0p[58];
-      qam64_table_offset_im=(x0p[55]<<2)|(x0p[57]<<1)|x0p[59];
-      ((int16_t *)&txdataF[0][tti_offset])[18]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[19]=qam_table_s0[qam64_table_offset_im];
-
-      qam64_table_offset_re=(x0p[60]<<2)|(x0p[62]<<1)|x0p[64];
-      qam64_table_offset_im=(x0p[61]<<2)|(x0p[63]<<1)|x0p[65];
-      ((int16_t *)&txdataF[0][tti_offset])[20]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[21]=qam_table_s0[qam64_table_offset_im];
-
-      qam64_table_offset_re=(x0p[66]<<2)|(x0p[68]<<1)|x0p[70];
-      qam64_table_offset_im=(x0p[67]<<2)|(x0p[69]<<1)|x0p[71];
-      ((int16_t *)&txdataF[0][tti_offset])[22]=qam_table_s0[qam64_table_offset_re];
-      ((int16_t *)&txdataF[0][tti_offset])[23]=qam_table_s0[qam64_table_offset_im];
-
+      if(skip_half==0)
+      {
+        qam64_table_offset_re=(x0p[36]<<2)|(x0p[38]<<1)|x0p[40];
+        qam64_table_offset_im=(x0p[37]<<2)|(x0p[39]<<1)|x0p[41];
+        ((int16_t *)&txdataF[0][tti_offset])[12]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[13]=qam_table_s0[qam64_table_offset_im];
+
+        qam64_table_offset_re=(x0p[42]<<2)|(x0p[44]<<1)|x0p[46];
+        qam64_table_offset_im=(x0p[43]<<2)|(x0p[45]<<1)|x0p[47];
+        ((int16_t *)&txdataF[0][tti_offset])[14]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[15]=qam_table_s0[qam64_table_offset_im];
+
+        qam64_table_offset_re=(x0p[48]<<2)|(x0p[50]<<1)|x0p[52];
+        qam64_table_offset_im=(x0p[49]<<2)|(x0p[51]<<1)|x0p[53];
+        ((int16_t *)&txdataF[0][tti_offset])[16]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[17]=qam_table_s0[qam64_table_offset_im];
+
+       qam64_table_offset_re=(x0p[54]<<2)|(x0p[56]<<1)|x0p[58];
+        qam64_table_offset_im=(x0p[55]<<2)|(x0p[57]<<1)|x0p[59];
+        ((int16_t *)&txdataF[0][tti_offset])[18]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[19]=qam_table_s0[qam64_table_offset_im];
+
+        qam64_table_offset_re=(x0p[60]<<2)|(x0p[62]<<1)|x0p[64];
+        qam64_table_offset_im=(x0p[61]<<2)|(x0p[63]<<1)|x0p[65];
+        ((int16_t *)&txdataF[0][tti_offset])[20]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[21]=qam_table_s0[qam64_table_offset_im];
+
+        qam64_table_offset_re=(x0p[66]<<2)|(x0p[68]<<1)|x0p[70];
+        qam64_table_offset_im=(x0p[67]<<2)|(x0p[69]<<1)|x0p[71];
+        ((int16_t *)&txdataF[0][tti_offset])[22]=qam_table_s0[qam64_table_offset_re];
+        ((int16_t *)&txdataF[0][tti_offset])[23]=qam_table_s0[qam64_table_offset_im];
+      }
 
       //    }
   }
@@ -584,8 +662,16 @@ int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
     }
   }
 
-  *re_allocated = *re_allocated + 12;
-  *jj=*jj + 72;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 6;
+    *jj=*jj + 36;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 12;
+    *jj=*jj + 72;
+  }
 
   return(0);
 }
@@ -623,12 +709,21 @@ int allocate_REs_in_RB_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
   uint32_t tti_offset;
   uint8_t re;
   uint8_t *x0p;
+  uint8_t first_re,last_re;
+
+  last_re=12;
+  first_re=0;
+  if (skip_half==1)
+    last_re=6;
+  else if (skip_half==2)
+    first_re=6;
+  re=first_re+P1_SHIFT[0];
 
 
   if (skip_dc == 0) {
     //    LOG_I(PHY,"pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
-    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
-         re<12;
+    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+re;
+         re<last_re;
          x0p+=6) {
 
       qam64_table_offset_re=FOUR[x0p[0]];
@@ -677,8 +772,16 @@ int allocate_REs_in_RB_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
       re+=P1_SHIFT[re+1];
     }
   }
-  *re_allocated = *re_allocated + 10;
-  *jj=*jj + 60;
+  if(skip_half!=0)
+  {
+    *re_allocated = *re_allocated + 5;
+    *jj=*jj + 30;
+  }
+  else
+  {
+    *re_allocated = *re_allocated + 10;
+    *jj=*jj + 60;
+  }
 
   return(0);
 }
@@ -2485,9 +2588,9 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
       skip_half = check_skiphalf(rb,subframe_offset,frame_parms,l,nsymb);
       skip_dc   = check_skip_dc(rb,frame_parms);
-      if(skip_half>0)
+      /*if(skip_half>0)
         allocate_REs = allocate_REs_in_RB;
-
+      */
 
      if (dlsch0) {
         if (dlsch0_harq->Nlayers>1) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_phytest.c b/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
index 71449e3cd4..19570c6e10 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
@@ -71,7 +71,7 @@ schedule_ue_spec_phy_test(
   uint16_t                       rnti      = 0x1235;
   uint32_t                       rb_alloc  = 0x1FFFFF;
   int32_t                        tpc       = 1;
-  int32_t                        mcs       = 28;
+  int32_t                        mcs       = 10;
   int32_t                        cqi       = 15;
   int32_t                        ndi       = (frameP*10+subframeP)/8;
   int32_t                        dai       = 0;
@@ -202,7 +202,7 @@ void schedule_ulsch_phy_test(module_id_t module_idP,frame_t frameP,sub_frame_t s
   int32_t           normalized_rx_power;
   int32_t           target_rx_power= 178;
   int               CC_id = 0;
-  int               nb_rb;
+  int               nb_rb = 24;
   int               N_RB_UL;
   eNB_MAC_INST      *mac = RC.mac[module_idP];
   COMMON_channels_t *cc  = &mac->common_channels[0];
@@ -319,7 +319,7 @@ void schedule_ulsch_phy_test(module_id_t module_idP,frame_t frameP,sub_frame_t s
 	  hi_dci0_req_body->number_of_dci++;
 	    
 	  ul_req_index = 0;
-            dlsch_flag = 0;
+          dlsch_flag = 0;
             for(ul_req_index = 0;ul_req_index < ul_req->number_of_pdus;ul_req_index++){
               if(ul_req->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE){
                 dlsch_flag = 1;
-- 
2.26.2