ru_procedures.c 17.5 KB
Newer Older
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
 * 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.0  (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
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"

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

#ifdef EMOS
#include "SCHED/phy_procedures_emos.h"
#endif

#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/defs.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"

#include "T.h"

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

#include <time.h>
Raymond Knopp's avatar
Raymond Knopp committed
56

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

Raymond Knopp's avatar
Raymond Knopp committed
59 60
// RU OFDM Modulator, used in IF4p5 RRU, RCC/RAU with IF5, eNodeB

61 62
extern openair0_config_t openair0_cfg[MAX_CARDS];

63 64 65 66 67 68
extern int oai_exit;


void feptx0(RU_t *ru,int slot) {

  LTE_DL_FRAME_PARMS *fp = &ru->frame_parms;
69
  //int dummy_tx_b[7680*2] __attribute__((aligned(32)));
70 71

  unsigned int aa,slot_offset;
Cedric Roux's avatar
Cedric Roux committed
72
  int i, tx_offset;
73 74 75 76
  int slot_sizeF = (fp->ofdm_symbol_size)*
                   ((fp->Ncp==1) ? 6 : 7);
  int subframe = ru->proc.subframe_tx;

77 78 79

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+slot , 1 );

80 81
  slot_offset = subframe*fp->samples_per_tti + (slot*(fp->samples_per_tti>>1));

82
  //LOG_D(PHY,"SFN/SF:RU:TX:%d/%d Generating slot %d\n",ru->proc.frame_tx, ru->proc.subframe_tx,slot);
83 84 85

  for (aa=0; aa<ru->nb_tx; aa++) {
    if (fp->Ncp == EXTENDED) PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot*slot_sizeF],
86 87 88 89 90
					                      (int*)&ru->common.txdata[aa][slot_offset],
					                      fp->ofdm_symbol_size,
					                      6,
					                      fp->nb_prefix_samples,
					                      CYCLIC_PREFIX);
91
    else                     normal_prefix_mod(&ru->common.txdataF_BF[aa][slot*slot_sizeF],
92 93 94
					                           (int*)&ru->common.txdata[aa][slot_offset],
					                           7,
					                           fp);
95
    
96
   /* 
97 98
    len = fp->samples_per_tti>>1;

99
    
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    if ((slot_offset+len)>(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti)) {
      tx_offset = (int)slot_offset;
      txdata = (int16_t*)&ru->common.txdata[aa][tx_offset];
      len2 = -tx_offset+LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
      for (i=0; i<(len2<<1); i++) {
	txdata[i] = ((int16_t*)dummy_tx_b)[i];
      }
      txdata = (int16_t*)&ru->common.txdata[aa][0];
      for (j=0; i<(len<<1); i++,j++) {
	txdata[j++] = ((int16_t*)dummy_tx_b)[i];
      }
    }
    else {
      tx_offset = (int)slot_offset;
      txdata = (int16_t*)&ru->common.txdata[aa][tx_offset];
115
      memcpy((void*)txdata,(void*)dummy_tx_b,len<<2);   
116
    }
117
*/
118 119
    // TDD: turn on tx switch N_TA_offset before by setting buffer in these samples to 0    
    if ((slot == 0) &&
120 121 122 123 124 125
        (fp->frame_type == TDD) && 
        ((fp->tdd_config==0) ||
         (fp->tdd_config==1) ||
         (fp->tdd_config==2) ||
         (fp->tdd_config==6)) &&  
        ((subframe==0) || (subframe==5))) {
126 127 128 129 130 131 132 133 134 135 136 137
      for (i=0; i<ru->N_TA_offset; i++) {
	tx_offset = (int)slot_offset+i-ru->N_TA_offset/2;
	if (tx_offset<0)
	  tx_offset += LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
	
	if (tx_offset>=(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti))
	  tx_offset -= LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
	
	ru->common.txdata[aa][tx_offset] = 0x00000000;
      }
    }
  }
138
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM+slot , 0);
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
}

static void *feptx_thread(void *param) {

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

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

  while (!oai_exit) {

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

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



  return(NULL);
}

void feptx_ofdm_2thread(RU_t *ru) {

  LTE_DL_FRAME_PARMS *fp=&ru->frame_parms;
  RU_proc_t *proc = &ru->proc;
  struct timespec wait;
  int subframe = ru->proc.subframe_tx;

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

176
  start_meas(&ru->ofdm_mod_stats);
177 178 179

  if (subframe_select(fp,subframe) == SF_UL) return;

180 181
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 1 );

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  if (subframe_select(fp,subframe)==SF_DL) {
    // 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
  feptx0(ru,0);
  wait_on_busy_condition(&proc->mutex_feptx,&proc->cond_feptx,&proc->instance_cnt_feptx,"feptx thread");  

213 214
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 0 );

215
  stop_meas(&ru->ofdm_mod_stats);
216 217 218

}

219
void feptx_ofdm(RU_t *ru) {
Raymond Knopp's avatar
Raymond Knopp committed
220 221 222 223 224 225 226 227 228 229
     
  LTE_DL_FRAME_PARMS *fp=&ru->frame_parms;

  unsigned int aa,slot_offset, slot_offset_F;
  int dummy_tx_b[7680*4] __attribute__((aligned(32)));
  int i,j, tx_offset;
  int slot_sizeF = (fp->ofdm_symbol_size)*
                   ((fp->Ncp==1) ? 6 : 7);
  int len,len2;
  int16_t *txdata;
230 231
  int subframe = ru->proc.subframe_tx;

Raymond Knopp's avatar
Raymond Knopp committed
232 233
//  int CC_id = ru->proc.CC_id;

234
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 1 );
Raymond Knopp's avatar
Raymond Knopp committed
235

Cedric Roux's avatar
Cedric Roux committed
236
  slot_offset_F = 0;
Raymond Knopp's avatar
Raymond Knopp committed
237 238 239 240 241 242 243

  slot_offset = subframe*fp->samples_per_tti;

  if ((subframe_select(fp,subframe)==SF_DL)||
      ((subframe_select(fp,subframe)==SF_S))) {
    //    LOG_D(HW,"Frame %d: Generating slot %d\n",frame,next_slot);

244 245
    start_meas(&ru->ofdm_mod_stats);

Raymond Knopp's avatar
Raymond Knopp committed
246 247
    for (aa=0; aa<ru->nb_tx; aa++) {
      if (fp->Ncp == EXTENDED) {
248
        PHY_ofdm_mod(&ru->common.txdataF_BF[aa][0],
Raymond Knopp's avatar
Raymond Knopp committed
249 250 251 252 253
                     dummy_tx_b,
                     fp->ofdm_symbol_size,
                     6,
                     fp->nb_prefix_samples,
                     CYCLIC_PREFIX);
254
        PHY_ofdm_mod(&ru->common.txdataF_BF[aa][slot_sizeF],
Raymond Knopp's avatar
Raymond Knopp committed
255 256 257 258 259 260
                     dummy_tx_b+(fp->samples_per_tti>>1),
                     fp->ofdm_symbol_size,
                     6,
                     fp->nb_prefix_samples,
                     CYCLIC_PREFIX);
      } else {
261
        normal_prefix_mod(&ru->common.txdataF_BF[aa][slot_offset_F],
Raymond Knopp's avatar
Raymond Knopp committed
262 263 264 265 266
                          dummy_tx_b,
                          7,
                          fp);
	// if S-subframe generate first slot only
	if (subframe_select(fp,subframe) == SF_DL) 
267
	  normal_prefix_mod(&ru->common.txdataF_BF[aa][slot_offset_F+slot_sizeF],
Raymond Knopp's avatar
Raymond Knopp committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
			    dummy_tx_b+(fp->samples_per_tti>>1),
			    7,
			    fp);
      }

      // if S-subframe generate first slot only
      if (subframe_select(fp,subframe) == SF_S)
	len = fp->samples_per_tti>>1;
      else
	len = fp->samples_per_tti;
      /*
      for (i=0;i<len;i+=4) {
	dummy_tx_b[i] = 0x100;
	dummy_tx_b[i+1] = 0x01000000;
	dummy_tx_b[i+2] = 0xff00;
	dummy_tx_b[i+3] = 0xff000000;
	}*/
      
286 287 288
      if (slot_offset<0) {
	txdata = (int16_t*)&ru->common.txdata[aa][(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti)+tx_offset];
        len2 = -(slot_offset);
Raymond Knopp's avatar
Raymond Knopp committed
289 290
	len2 = (len2>len) ? len : len2;
	for (i=0; i<(len2<<1); i++) {
291
	  txdata[i] = ((int16_t*)dummy_tx_b)[i];
Raymond Knopp's avatar
Raymond Knopp committed
292 293
	}
	if (len2<len) {
294
	  txdata = (int16_t*)&ru->common.txdata[aa][0];
Raymond Knopp's avatar
Raymond Knopp committed
295
	  for (j=0; i<(len<<1); i++,j++) {
296
	    txdata[j++] = ((int16_t*)dummy_tx_b)[i];
Raymond Knopp's avatar
Raymond Knopp committed
297 298 299
	  }
	}
      }  
300 301 302
      else if ((slot_offset+len)>(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti)) {
	tx_offset = (int)slot_offset;
	txdata = (int16_t*)&ru->common.txdata[aa][tx_offset];
Raymond Knopp's avatar
Raymond Knopp committed
303 304
	len2 = -tx_offset+LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
	for (i=0; i<(len2<<1); i++) {
305
	  txdata[i] = ((int16_t*)dummy_tx_b)[i];
Raymond Knopp's avatar
Raymond Knopp committed
306
	}
307
	txdata = (int16_t*)&ru->common.txdata[aa][0];
Raymond Knopp's avatar
Raymond Knopp committed
308
	for (j=0; i<(len<<1); i++,j++) {
309
          txdata[j++] = ((int16_t*)dummy_tx_b)[i];
Raymond Knopp's avatar
Raymond Knopp committed
310 311 312
	}
      }
      else {
313
	//LOG_D(PHY,"feptx_ofdm: Writing to position %d\n",slot_offset);
314 315
	tx_offset = (int)slot_offset;
	txdata = (int16_t*)&ru->common.txdata[aa][tx_offset];
Raymond Knopp's avatar
Raymond Knopp committed
316 317

	for (i=0; i<(len<<1); i++) {
318
	  txdata[i] = ((int16_t*)dummy_tx_b)[i];
Raymond Knopp's avatar
Raymond Knopp committed
319 320 321 322 323 324 325 326 327 328 329
	}
      }
      
     // if S-subframe switch to RX in second subframe
      /*
     if (subframe_select(fp,subframe) == SF_S) {
       for (i=0; i<len; i++) {
	 ru->common_vars.txdata[0][aa][tx_offset++] = 0x00010001;
       }
     }
      */
330 331
     if ((fp->frame_type == TDD) && 
         ((fp->tdd_config==0) ||
332 333 334
	   (fp->tdd_config==1) ||
	   (fp->tdd_config==2) ||
	   (fp->tdd_config==6)) && 
335
	     ((subframe==0) || (subframe==5))) {
Raymond Knopp's avatar
Raymond Knopp committed
336 337 338
       // turn on tx switch N_TA_offset before
       //LOG_D(HW,"subframe %d, time to switch to tx (N_TA_offset %d, slot_offset %d) \n",subframe,ru->N_TA_offset,slot_offset);
       for (i=0; i<ru->N_TA_offset; i++) {
339
         tx_offset = (int)slot_offset+i-ru->N_TA_offset/2;
Raymond Knopp's avatar
Raymond Knopp committed
340 341 342 343 344 345
         if (tx_offset<0)
           tx_offset += LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
	 
         if (tx_offset>=(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti))
           tx_offset -= LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_tti;
	 
346
         ru->common.txdata[aa][tx_offset] = 0x00000000;
Raymond Knopp's avatar
Raymond Knopp committed
347 348
       }
     }
349
     stop_meas(&ru->ofdm_mod_stats);
350
     LOG_D(PHY,"feptx_ofdm (TXPATH): frame %d, subframe %d: txp (time %p) %d dB, txp (freq) %d dB\n",
Raymond Knopp's avatar
Raymond Knopp committed
351
	   ru->proc.frame_tx,subframe,txdata,dB_fixed(signal_energy((int32_t*)txdata,fp->samples_per_tti)),
352
	   dB_fixed(signal_energy_nodc(ru->common.txdataF_BF[aa],2*slot_sizeF)));
Raymond Knopp's avatar
Raymond Knopp committed
353 354
    }
  }
355
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_OFDM , 0 );
Raymond Knopp's avatar
Raymond Knopp committed
356 357
}

358 359 360 361 362 363 364 365
void feptx_prec(RU_t *ru) {

  int l,i,aa;
  PHY_VARS_eNB **eNB_list = ru->eNB_list,*eNB;
  LTE_DL_FRAME_PARMS *fp;
  int32_t ***bw;
  int subframe = ru->proc.subframe_tx;

366 367
  if (ru->num_eNB == 1) {
    eNB = eNB_list[0];
368
    fp  = &eNB->frame_parms;
369
    
370 371
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_PREC , 1);

372 373 374 375
    for (aa=0;aa<ru->nb_tx;aa++)
      memcpy((void*)ru->common.txdataF_BF[aa],
	     (void*)&eNB->common_vars.txdataF[aa][subframe*fp->symbols_per_tti*fp->ofdm_symbol_size],
	     fp->symbols_per_tti*fp->ofdm_symbol_size*sizeof(int32_t));
376 377

    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPTX_PREC , 0);
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
  }
  else {
    for (i=0;i<ru->num_eNB;i++) {
      eNB = eNB_list[i];
      fp  = &eNB->frame_parms;
      bw  = ru->beam_weights[i];
      
      for (l=0;l<fp->symbols_per_tti;l++) {
	for (aa=0;aa<ru->nb_tx;aa++) {
	  beam_precoding(eNB->common_vars.txdataF,
			 ru->common.txdataF_BF,
			 fp,
			 bw,
			 subframe<<1,
			 l,
			 aa);
	}
395
      }
396
#if 0
397 398 399
      LOG_D(PHY,"feptx_prec: frame %d, subframe %d: txp (freq) %d dB\n",
	    ru->proc.frame_tx,subframe,
	    dB_fixed(signal_energy_nodc(ru->common.txdataF_BF[0],2*fp->symbols_per_tti*fp->ofdm_symbol_size)));
400
#endif
401 402 403
    }
  }
}
Raymond Knopp's avatar
Raymond Knopp committed
404 405 406

void fep0(RU_t *ru,int slot) {

407 408
  RU_proc_t *proc       = &ru->proc;
  LTE_DL_FRAME_PARMS *fp = &ru->frame_parms;
Raymond Knopp's avatar
Raymond Knopp committed
409 410 411 412
  int l;

  //  printf("fep0: slot %d\n",slot);

413 414
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPRX+slot, 1);

Raymond Knopp's avatar
Raymond Knopp committed
415 416
  remove_7_5_kHz(ru,(slot&1)+(proc->subframe_rx<<1));
  for (l=0; l<fp->symbols_per_tti/2; l++) {
417
    slot_fep_ul(ru,
Raymond Knopp's avatar
Raymond Knopp committed
418
		l,
419
		(slot&1),
Raymond Knopp's avatar
Raymond Knopp committed
420 421 422
		0
		);
  }
423
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPRX+slot, 0);
Raymond Knopp's avatar
Raymond Knopp committed
424 425 426 427 428 429 430
}



static void *fep_thread(void *param) {

  RU_t *ru = (RU_t *)param;
431
  RU_proc_t *proc  = &ru->proc;
432 433 434

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

Raymond Knopp's avatar
Raymond Knopp committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
  while (!oai_exit) {

    if (wait_on_condition(&proc->mutex_fep,&proc->cond_fep,&proc->instance_cnt_fep,"fep thread")<0) break;  
    fep0(ru,0);
    if (release_thread(&proc->mutex_fep,&proc->instance_cnt_fep,"fep thread")<0) break;

    if (pthread_cond_signal(&proc->cond_fep) != 0) {
      printf("[eNB] ERROR pthread_cond_signal for fep thread exit\n");
      exit_fun( "ERROR pthread_cond_signal" );
      return NULL;
    }
  }



  return(NULL);
}

453 454 455 456 457 458 459 460 461 462 463 464 465 466
void 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, feptx_thread, (void*)ru);


}

467
void init_fep_thread(RU_t *ru,pthread_attr_t *attr_fep) {
Raymond Knopp's avatar
Raymond Knopp committed
468

469
  RU_proc_t *proc = &ru->proc;
Raymond Knopp's avatar
Raymond Knopp committed
470 471 472 473 474 475

  proc->instance_cnt_fep         = -1;
    
  pthread_mutex_init( &proc->mutex_fep, NULL);
  pthread_cond_init( &proc->cond_fep, NULL);

476
  pthread_create(&proc->pthread_fep, attr_fep, fep_thread, (void*)ru);
Raymond Knopp's avatar
Raymond Knopp committed
477 478 479 480 481


}
void ru_fep_full_2thread(RU_t *ru) {

482
  RU_proc_t *proc = &ru->proc;
Raymond Knopp's avatar
Raymond Knopp committed
483 484 485

  struct timespec wait;

486 487 488 489 490 491 492
  LTE_DL_FRAME_PARMS *fp=&ru->frame_parms;

  if ((fp->frame_type == TDD) &&
     (subframe_select(fp,proc->subframe_rx) != SF_UL)) return;

  if (ru->idx == 0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPRX, 1 );

Raymond Knopp's avatar
Raymond Knopp committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
  wait.tv_sec=0;
  wait.tv_nsec=5000000L;

  start_meas(&ru->ofdm_demod_stats);

  if (pthread_mutex_timedlock(&proc->mutex_fep,&wait) != 0) {
    printf("[RU] ERROR pthread_mutex_lock for fep thread (IC %d)\n", proc->instance_cnt_fep);
    exit_fun( "error locking mutex_fep" );
    return;
  }

  if (proc->instance_cnt_fep==0) {
    printf("[RU] FEP thread busy\n");
    exit_fun("FEP thread busy");
    pthread_mutex_unlock( &proc->mutex_fep );
    return;
  }
  
  ++proc->instance_cnt_fep;


  if (pthread_cond_signal(&proc->cond_fep) != 0) {
    printf("[RU] ERROR pthread_cond_signal for fep thread\n");
    exit_fun( "ERROR pthread_cond_signal" );
    return;
  }
  
  pthread_mutex_unlock( &proc->mutex_fep );

  // call second slot in this symbol
  fep0(ru,1);

  wait_on_busy_condition(&proc->mutex_fep,&proc->cond_fep,&proc->instance_cnt_fep,"fep thread");  

  stop_meas(&ru->ofdm_demod_stats);
}



532
void fep_full(RU_t *ru) {
Raymond Knopp's avatar
Raymond Knopp committed
533

534
  RU_proc_t *proc = &ru->proc;
Raymond Knopp's avatar
Raymond Knopp committed
535
  int l;
536
  LTE_DL_FRAME_PARMS *fp=&ru->frame_parms;
Raymond Knopp's avatar
Raymond Knopp committed
537

538 539
  if ((fp->frame_type == TDD) && 
     (subframe_select(fp,proc->subframe_rx) != SF_UL)) return;
Raymond Knopp's avatar
Raymond Knopp committed
540

541 542
  start_meas(&ru->ofdm_demod_stats);
  if (ru->idx == 0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPRX, 1 );
Raymond Knopp's avatar
Raymond Knopp committed
543 544 545 546

  remove_7_5_kHz(ru,proc->subframe_rx<<1);
  remove_7_5_kHz(ru,1+(proc->subframe_rx<<1));
  for (l=0; l<fp->symbols_per_tti/2; l++) {
547
    slot_fep_ul(ru,
Raymond Knopp's avatar
Raymond Knopp committed
548
		l,
549
		0,
Raymond Knopp's avatar
Raymond Knopp committed
550 551
		0
		);
552
    slot_fep_ul(ru,
Raymond Knopp's avatar
Raymond Knopp committed
553
		l,
554
		1,
Raymond Knopp's avatar
Raymond Knopp committed
555 556 557
		0
		);
  }
558
  if (ru->idx == 0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_RU_FEPRX, 0 );
Raymond Knopp's avatar
Raymond Knopp committed
559 560 561 562 563 564 565 566
  stop_meas(&ru->ofdm_demod_stats);
  
  
}


void do_prach_ru(RU_t *ru) {

567 568
  RU_proc_t *proc = &ru->proc;
  LTE_DL_FRAME_PARMS *fp=&ru->frame_parms;
Raymond Knopp's avatar
Raymond Knopp committed
569 570

  // check if we have to detect PRACH first
571
  if (is_prach_subframe(fp,proc->frame_prach,proc->subframe_prach)>0) { 
572
    //accept some delay in processing - up to 5ms
Raymond Knopp's avatar
Raymond Knopp committed
573 574
    int i;
    for (i = 0; i < 10 && proc->instance_cnt_prach == 0; i++) {
575 576
      LOG_W(PHY,"Frame %d Subframe %d, PRACH thread busy (IC %d)!!\n", proc->frame_prach,proc->subframe_prach,
	    proc->instance_cnt_prach);
Raymond Knopp's avatar
Raymond Knopp committed
577 578 579 580 581 582 583 584 585
      usleep(500);
    }
    if (proc->instance_cnt_prach == 0) {
      exit_fun( "PRACH thread busy" );
      return;
    }
    
    // wake up thread for PRACH RX
    if (pthread_mutex_lock(&proc->mutex_prach) != 0) {
586
      LOG_E( PHY, "ERROR pthread_mutex_lock for PRACH thread (IC %d)\n", proc->instance_cnt_prach );
Raymond Knopp's avatar
Raymond Knopp committed
587 588 589 590 591 592 593 594
      exit_fun( "error locking mutex_prach" );
      return;
    }
    
    ++proc->instance_cnt_prach;
    
    // the thread can now be woken up
    if (pthread_cond_signal(&proc->cond_prach) != 0) {
595
      LOG_E( PHY, "ERROR pthread_cond_signal for PRACH thread\n");
Raymond Knopp's avatar
Raymond Knopp committed
596 597 598 599 600 601 602 603
      exit_fun( "ERROR pthread_cond_signal" );
      return;
    }
    
    pthread_mutex_unlock( &proc->mutex_prach );
  }

}