nr_ru_procedures.c 7.44 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 44
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
Guy De Souza's avatar
Guy De Souza committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

#include "T.h"

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

#include <time.h>

#include "targets/RT/USER/rt_wrapper.h"

// RU OFDM Modulator gNodeB

extern openair0_config_t openair0_cfg[MAX_CARDS];

extern int oai_exit;

void nr_feptx0(RU_t *ru,int slot) {

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

  unsigned int aa,slot_offset;
Guy De Souza's avatar
Guy De Souza committed
66
  int slot_sizeF = fp->ofdm_symbol_size * fp->symbols_per_slot;
Guy De Souza's avatar
Guy De Souza committed
67 68 69 70 71 72 73
  int subframe = ru->proc.subframe_tx;


  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+slot , 1 );

  slot_offset = subframe*fp->samples_per_subframe + (slot*(fp->samples_per_subframe / fp->slots_per_subframe));

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

  for (aa=0; aa<ru->nb_tx; aa++) {
77 78 79 80 81 82 83 84 85
    if (fp->Ncp == 1) {
      PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot*slot_sizeF],
		     (int*)&ru->common.txdata[aa][slot_offset],
                     fp->ofdm_symbol_size,
                     12,
                     fp->nb_prefix_samples,
                     CYCLIC_PREFIX);
    }
    else {
Guy De Souza's avatar
Guy De Souza committed
86 87 88 89
     nr_normal_prefix_mod(&ru->common.txdataF_BF[aa][slot*slot_sizeF],
                       (int*)&ru->common.txdata[aa][slot_offset],
                       fp->symbols_per_slot,
                       fp);
90
    }
Guy De Souza's avatar
Guy De Souza committed
91 92 93 94 95 96
  }
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+slot , 0);
}

void nr_feptx_ofdm_2thread(RU_t *ru) {

97
  NR_DL_FRAME_PARMS *fp=ru->nr_frame_parms;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
98
  nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
99 100 101 102 103 104 105 106 107
  RU_proc_t *proc = &ru->proc;
  struct timespec wait;
  int subframe = ru->proc.subframe_tx;

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

  start_meas(&ru->ofdm_mod_stats);

Guy De Souza's avatar
Guy De Souza committed
108
  if (nr_subframe_select(cfg,subframe) == SF_UL) return;
Guy De Souza's avatar
Guy De Souza committed
109

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

Guy De Souza's avatar
Guy De Souza committed
115 116
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 1 );

Guy De Souza's avatar
Guy De Souza committed
117
  if (nr_subframe_select(cfg,subframe)==SF_DL) {
Guy De Souza's avatar
Guy De Souza committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    // If this is not an S-subframe
    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;
    
    
    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;
    }
    
    pthread_mutex_unlock( &proc->mutex_feptx );
  }

  // call first slot in this thread
  nr_feptx0(ru,0);
Guy De Souza's avatar
Guy De Souza committed
146
  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
147 148 149

  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
150 151
  //write_output

Guy De Souza's avatar
Guy De Souza committed
152 153 154 155
  stop_meas(&ru->ofdm_mod_stats);

}

Guy De Souza's avatar
Guy De Souza committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
static void *nr_feptx_thread(void *param) {

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

  thread_top_init("nr_feptx_thread",0,870000,1000000,1000000);

  while (!oai_exit) {

    if (wait_on_condition(&proc->mutex_feptx,&proc->cond_feptx,&proc->instance_cnt_feptx,"NR feptx thread")<0) break;
    nr_feptx0(ru,1);
    if (release_thread(&proc->mutex_feptx,&proc->instance_cnt_feptx,"NR feptx thread")<0) break;

    if (pthread_cond_signal(&proc->cond_feptx) != 0) {
      printf("[gNB] ERROR pthread_cond_signal for NR feptx thread exit\n");
      exit_fun( "ERROR pthread_cond_signal" );
      return NULL;
    }
  }
  return(NULL);
}

Guy De Souza's avatar
Guy De Souza committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191
void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx) {

  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);

  pthread_create(&proc->pthread_feptx, attr_feptx, nr_feptx_thread, (void*)ru);


}

192 193
// is this supposed to generate a slot or a subframe???
// seems to be hardcoded to numerology 1 (2 slots=1 subframe)
Guy De Souza's avatar
Guy De Souza committed
194 195
void nr_feptx_ofdm(RU_t *ru) {
     
196
  NR_DL_FRAME_PARMS *fp=ru->nr_frame_parms;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
197
  nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
198

199
  unsigned int aa=0,slot=0;
Guy De Souza's avatar
Guy De Souza committed
200 201 202
  int slot_sizeF = (fp->ofdm_symbol_size)*
                   ((cfg->subframe_config.dl_cyclic_prefix_type.value == 1) ? 12 : 14);
  int subframe = ru->proc.subframe_tx;
203
  int *txdata = &ru->common.txdata[aa][subframe*fp->samples_per_subframe];
Guy De Souza's avatar
Guy De Souza committed
204 205

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

208 209 210 211
  // 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],
	   (void*)ru->gNB_list[0]->common_vars.txdataF[aa], fp->samples_per_subframe_wCP*sizeof(int32_t));
Guy De Souza's avatar
Guy De Souza committed
212

Guy De Souza's avatar
Guy De Souza committed
213 214
  if ((nr_subframe_select(cfg,subframe)==SF_DL)||
      ((nr_subframe_select(cfg,subframe)==SF_S))) {
Guy De Souza's avatar
Guy De Souza committed
215 216
    //    LOG_D(HW,"Frame %d: Generating slot %d\n",frame,next_slot);

217 218
    for (slot=0; slot<fp->slots_per_subframe;slot++)
      nr_feptx0(ru,slot);
Guy De Souza's avatar
Guy De Souza committed
219 220

  }
221

Guy De Souza's avatar
Guy De Souza committed
222
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 0 );
223 224 225 226 227 228
  stop_meas(&ru->ofdm_mod_stats);

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

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