nr_ru_procedures.c 10.2 KB
Newer Older
Guy De Souza's avatar
Guy De Souza committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file ru_procedures.c
 * \brief Implementation of RU procedures
 * \author R. Knopp, F. Kaltenberger, N. Nikaein, X. Foukas
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr, x.foukas@sms.ed.ac.uk
 * \note
 * \warning
 */

33 34
#include "PHY/defs_gNB.h"
#include "PHY/phy_extern.h"
Guy De Souza's avatar
Guy De Souza committed
35 36
#include "sched_nr.h"
#include "PHY/MODULATION/modulation_common.h"
Guy De Souza's avatar
Guy De Souza committed
37 38 39 40

#include "PHY/LTE_TRANSPORT/if4_tools.h"
#include "PHY/LTE_TRANSPORT/if5_tools.h"

41 42
#include "LAYER2/MAC/mac_extern.h"
#include "LAYER2/MAC/mac.h"
43
#include "common/utils/LOG/log.h"
Laurent's avatar
Laurent committed
44
#include "common/utils/system.h"
45
#include "common/utils/LOG/vcd_signal_dumper.h"
Guy De Souza's avatar
Guy De Souza committed
46 47 48 49 50 51 52 53 54 55 56 57 58

#include "T.h"

#include "assertions.h"
#include "msc.h"

#include <time.h>
// RU OFDM Modulator gNodeB

extern openair0_config_t openair0_cfg[MAX_CARDS];

extern int oai_exit;

Sravan Chintareddy's avatar
Sravan Chintareddy committed
59 60
void nr_feptx0(RU_t *ru,int tti_tx,int first_symbol, int num_symbols) 
{
Guy De Souza's avatar
Guy De Souza committed
61

62
  NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms;
Guy De Souza's avatar
Guy De Souza committed
63

Sravan Chintareddy's avatar
Sravan Chintareddy committed
64 65
  int mu=3;      ////// src572 just used to see if it works

66
  unsigned int aa,slot_offset,slot_offsetF;
67
  int slot = tti_tx;
Sravan Chintareddy's avatar
Sravan Chintareddy committed
68 69
  
  // fprintf(stderr, "\n $$$### In function nr_feptx0 fp->ofdm_symbol_size = %d , num_symbols = %d,fp->nb_prefix_samples = %d ,(fp->Ncp == 1) = %d, slot = %d $$$###\n", fp->ofdm_symbol_size,num_symbols,fp->nb_prefix_samples,fp->Ncp,slot);   //----src572 
Guy De Souza's avatar
Guy De Souza committed
70

71
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+(first_symbol!=0?1:0) , 1 );
Guy De Souza's avatar
Guy De Souza committed
72

73 74
  slot_offset  = slot*fp->samples_per_slot;
  slot_offsetF = first_symbol*fp->ofdm_symbol_size;
Guy De Souza's avatar
Guy De Souza committed
75

76 77 78
  if (first_symbol>0) slot_offset += (fp->ofdm_symbol_size*first_symbol) + (fp->nb_prefix_samples0) + (fp->nb_prefix_samples*(first_symbol-1));

  LOG_D(PHY,"SFN/SF:RU:TX:%d/%d Generating slot %d (first_symbol %d num_symbols %d)\n",ru->proc.frame_tx, ru->proc.tti_tx,slot,first_symbol,num_symbols);
Guy De Souza's avatar
Guy De Souza committed
79

Sravan Chintareddy's avatar
Sravan Chintareddy committed
80 81 82 83 84 85 86 87 88 89
  for (aa=0; aa<ru->nb_tx; aa++) 
  {
     if (fp->Ncp == 1) 
     {
         // fprintf(stderr, "\n $$$###  Entering if(fp->Ncp == 1) %d ###$$$ \n", fp->Ncp );  ///----src572
         PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot_offsetF], (int*)&ru->common.txdata[aa][slot_offset],
                		   fp->ofdm_symbol_size,
                		   num_symbols,
                		   fp->nb_prefix_samples,
                		   CYCLIC_PREFIX);
90
    }
Sravan Chintareddy's avatar
Sravan Chintareddy committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    else 
    {
      //if (first_symbol==0) 
      if ((slot== 0) || slot ==((1<<mu)*10/2))       ////   -src572  
      {
        	// fprintf(stderr,"\n $$$###  Entering if((slot== 0 || slot == (1<<mu)*10/2)) %d ###$$$ \n", slot);  ///----src572
          PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot_offsetF],(int*)&ru->common.txdata[aa][slot_offset],
                             fp->ofdm_symbol_size,
                             1,
                             fp->nb_prefix_samples0,
                             CYCLIC_PREFIX);
        	PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot_offsetF+fp->ofdm_symbol_size],(int*)&ru->common.txdata[aa][slot_offset+fp->nb_prefix_samples0+fp->ofdm_symbol_size],
                             fp->ofdm_symbol_size,
                             num_symbols-1,
                             fp->nb_prefix_samples,
                             CYCLIC_PREFIX);
107
      }
Sravan Chintareddy's avatar
Sravan Chintareddy committed
108 109 110 111
      else 
      { 	
           // fprintf(stderr,"\n $$$### Entering else in slot %d  ###$$$ \n",slot);    ////----src572
           PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot_offsetF],(int*)&ru->common.txdata[aa][slot_offset],
112 113 114 115 116
                     fp->ofdm_symbol_size,
                     num_symbols,
                     fp->nb_prefix_samples,
                     CYCLIC_PREFIX);
      }
Sravan Chintareddy's avatar
Sravan Chintareddy committed
117
   }
Guy De Souza's avatar
Guy De Souza committed
118
  }
119
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+(first_symbol!=0?1:0), 0);
Guy De Souza's avatar
Guy De Souza committed
120 121
}

122
void nr_feptx_ofdm_2thread(RU_t *ru,int frame_tx,int tti_tx) {
Guy De Souza's avatar
Guy De Souza committed
123

124
  NR_DL_FRAME_PARMS *fp=ru->nr_frame_parms;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
125
  nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
126 127
  RU_proc_t *proc = &ru->proc;
  struct timespec wait;
128
  int slot = tti_tx;
Guy De Souza's avatar
Guy De Souza committed
129 130 131 132

  wait.tv_sec=0;
  wait.tv_nsec=5000000L;

Sravan Chintareddy's avatar
Sravan Chintareddy committed
133 134 135

  // fprintf(stderr, "\n $$$### In nr_feptx_ofdm_2thread \n" );     //----src572

Guy De Souza's avatar
Guy De Souza committed
136 137
  start_meas(&ru->ofdm_mod_stats);

138
  if (nr_slot_select(cfg,slot) == SF_UL) return;
Guy De Souza's avatar
Guy De Souza committed
139

Guy De Souza's avatar
Guy De Souza committed
140 141
  // this copy should be done in the precoding thread (currently inactive)
  for (int aa=0;aa<ru->nb_tx;aa++)
142
    memcpy((void*)ru->common.txdataF_BF[aa],
143

144
	   (void*)ru->gNB_list[0]->common_vars.txdataF[aa], fp->samples_per_slot_wCP*sizeof(int32_t));
Guy De Souza's avatar
Guy De Souza committed
145

Guy De Souza's avatar
Guy De Souza committed
146 147
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 1 );

148 149
  if (nr_slot_select(cfg,slot)==SF_DL) {
    // If this is not an S-tti
Guy De Souza's avatar
Guy De Souza committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163
    if (pthread_mutex_timedlock(&proc->mutex_feptx,&wait) != 0) {
      printf("[RU] ERROR pthread_mutex_lock for feptx thread (IC %d)\n", proc->instance_cnt_feptx);
      exit_fun( "error locking mutex_feptx" );
      return;
    }
    
    if (proc->instance_cnt_feptx==0) {
      printf("[RU] FEPtx thread busy\n");
      exit_fun("FEPtx thread busy");
      pthread_mutex_unlock( &proc->mutex_feptx );
      return;
    }
    
    ++proc->instance_cnt_feptx;
164 165 166 167
    // slot to pass to worker thread
    proc->slot_feptx = slot;
    pthread_mutex_unlock( &proc->mutex_feptx );
  
Guy De Souza's avatar
Guy De Souza committed
168 169 170 171 172 173 174 175 176
    
    if (pthread_cond_signal(&proc->cond_feptx) != 0) {
      printf("[RU] ERROR pthread_cond_signal for feptx thread\n");
      exit_fun( "ERROR pthread_cond_signal" );
      return;
    }
    
  }

177
  // call first half-slot in this thread
178
  nr_feptx0(ru,slot,0,fp->symbols_per_slot>>1);
Guy De Souza's avatar
Guy De Souza committed
179
  wait_on_busy_condition(&proc->mutex_feptx,&proc->cond_feptx,&proc->instance_cnt_feptx,"NR feptx thread");
Guy De Souza's avatar
Guy De Souza committed
180 181 182

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 0 );

Guy De Souza's avatar
Guy De Souza committed
183 184
  //write_output

Guy De Souza's avatar
Guy De Souza committed
185 186 187 188
  stop_meas(&ru->ofdm_mod_stats);

}

Guy De Souza's avatar
Guy De Souza committed
189 190 191 192 193 194 195 196 197
static void *nr_feptx_thread(void *param) {

  RU_t *ru = (RU_t *)param;
  RU_proc_t *proc  = &ru->proc;


  while (!oai_exit) {

    if (wait_on_condition(&proc->mutex_feptx,&proc->cond_feptx,&proc->instance_cnt_feptx,"NR feptx thread")<0) break;
198
    int slot=proc->slot_feptx;
Guy De Souza's avatar
Guy De Souza committed
199 200
    if (release_thread(&proc->mutex_feptx,&proc->instance_cnt_feptx,"NR feptx thread")<0) break;

Sravan Chintareddy's avatar
Sravan Chintareddy committed
201 202 203 204 205
    // fprintf(stderr, "\n $$$$$#### In thread nr_feptx_thread  calling %s #####$$$\n","nr_feptx0" );     //--src572

    // fprintf(stderr, " \n $$$### slot =%d ,ru->nr_frame_parms->symbols_per_slot>>1 = %d ,ru->nr_frame_parms->symbols_per_slot>>1 = %d )  $$$### ", ru,slot,ru->nr_frame_parms->symbols_per_slot>>1,ru->nr_frame_parms->symbols_per_slot>>1);    ////---src572

    nr_feptx0(ru,slot,ru->nr_frame_parms->symbols_per_slot>>1,ru->nr_frame_parms->symbols_per_slot>>1);   //---src572 why same parameter ntwo times????
206

Guy De Souza's avatar
Guy De Souza committed
207
    if (pthread_cond_signal(&proc->cond_feptx) != 0) {
208
      LOG_E(PHY,"[gNB] ERROR pthread_cond_signal for NR feptx thread exit\n");
Guy De Souza's avatar
Guy De Souza committed
209 210 211 212 213 214 215
      exit_fun( "ERROR pthread_cond_signal" );
      return NULL;
    }
  }
  return(NULL);
}

Laurent's avatar
Laurent committed
216
void nr_init_feptx_thread(RU_t *ru) {
Guy De Souza's avatar
Guy De Souza committed
217 218 219 220 221 222 223 224

  RU_proc_t *proc = &ru->proc;

  proc->instance_cnt_feptx         = -1;
    
  pthread_mutex_init( &proc->mutex_feptx, NULL);
  pthread_cond_init( &proc->cond_feptx, NULL);

laurent's avatar
laurent committed
225
  threadCreate(&proc->pthread_feptx, nr_feptx_thread, (void*)ru, "feptx", -1, OAI_PRIORITY_RT);
Guy De Souza's avatar
Guy De Souza committed
226

Sravan Chintareddy's avatar
Sravan Chintareddy committed
227 228
  // fprintf(stderr, "\n $$$$$#### created %s #####$$$\n","nr_feptx_thread" );     //--src572

Guy De Souza's avatar
Guy De Souza committed
229 230 231

}

232 233
// is this supposed to generate a slot or a subframe???
// seems to be hardcoded to numerology 1 (2 slots=1 subframe)
234
void nr_feptx_ofdm(RU_t *ru,int frame_tx,int tti_tx) {
Guy De Souza's avatar
Guy De Souza committed
235
     
236
  NR_DL_FRAME_PARMS *fp=ru->nr_frame_parms;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
237
  nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
238

239
  unsigned int aa=0;
Guy De Souza's avatar
Guy De Souza committed
240 241
  int slot_sizeF = (fp->ofdm_symbol_size)*
                   ((cfg->subframe_config.dl_cyclic_prefix_type.value == 1) ? 12 : 14);
242
  int slot = tti_tx;
243
  int *txdata = &ru->common.txdata[aa][slot*fp->samples_per_slot];
Guy De Souza's avatar
Guy De Souza committed
244

Sravan Chintareddy's avatar
Sravan Chintareddy committed
245 246 247
  // fprintf(stderr, "\n $$$### In function nr_feptx_ofdm $$$####\n $$$$### The value of fp->Ncp = %d (cfg->subframe_config.dl_cyclic_prefix_type.value == 1) ? 12 : 14) * ofdm_symbol_size= %d , and slot_sizeF = %d in function nr_feptx_ofdm  $$$### \n", cfg->subframe_config.dl_cyclic_prefix_type.value,fp->ofdm_symbol_size,slot_sizeF);  //---src572


Guy De Souza's avatar
Guy De Souza committed
248
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 1 );
249
  start_meas(&ru->ofdm_mod_stats);
Guy De Souza's avatar
Guy De Souza committed
250

251 252 253
  // this copy should be done in the precoding thread (currently inactive)
  for (int aa=0;aa<ru->nb_tx;aa++)
    memcpy((void*)ru->common.txdataF_BF[aa],
254
	   (void*)ru->gNB_list[0]->common_vars.txdataF[aa], fp->samples_per_slot_wCP*sizeof(int32_t));
Guy De Souza's avatar
Guy De Souza committed
255

256
  if ((nr_slot_select(cfg,slot)==SF_DL)||
Sravan Chintareddy's avatar
Sravan Chintareddy committed
257 258
      ((nr_slot_select(cfg,slot)==SF_S))) 
  {
Guy De Souza's avatar
Guy De Souza committed
259 260
    //    LOG_D(HW,"Frame %d: Generating slot %d\n",frame,next_slot);

Sravan Chintareddy's avatar
Sravan Chintareddy committed
261
    // fprintf(stderr, "\n $$$### Calling nr_feptx0 fp->symbols_per_slot = %d, slot = %d $$$#### \n", fp->symbols_per_slot,slot);   ////----src572
262
    nr_feptx0(ru,slot,0,fp->symbols_per_slot);
Guy De Souza's avatar
Guy De Souza committed
263 264

  }
265

Guy De Souza's avatar
Guy De Souza committed
266
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 0 );
267 268
  stop_meas(&ru->ofdm_mod_stats);

269
  LOG_D(PHY,"feptx_ofdm (TXPATH): frame %d, slot %d: txp (time %p) %d dB, txp (freq) %d dB\n",
270
	frame_tx,slot,txdata,dB_fixed(signal_energy((int32_t*)txdata,fp->samples_per_slot)),
271 272
	dB_fixed(signal_energy_nodc(ru->common.txdataF_BF[aa],2*slot_sizeF)));

Guy De Souza's avatar
Guy De Souza committed
273
}