lte-enb.c 47.7 KB
Newer Older
1 2 3 4 5
/*
 * 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
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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
 */
21 22 23 24 25 26 27 28 29 30 31

/*! \file lte-enb.c
 * \brief Top-level threads for eNodeB
 * \author R. Knopp, F. Kaltenberger, Navid Nikaein
 * \date 2012
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
 * \note
 * \warning
 */
32

knopp's avatar
knopp committed
33 34
#define _GNU_SOURCE
#include <pthread.h>
35

36

37 38
#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all

39 40
#include "rt_wrapper.h"

41
#include "assertions.h"
42

43 44 45

#include "PHY/types.h"

46 47 48 49 50 51
#include "PHY/INIT/phy_init.h"

#include "PHY/defs_eNB.h"
#include "SCHED/sched_eNB.h"
#include "PHY/LTE_TRANSPORT/transport_proto.h"

52 53 54 55 56 57 58
#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all

#include "../../ARCH/COMMON/common_lib.h"

//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all

59
#include "PHY/LTE_TRANSPORT/if4_tools.h"
60
#include "PHY/LTE_TRANSPORT/if5_tools.h"
61

62 63 64 65 66 67 68 69
#include "PHY/phy_extern.h"


#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_extern.h"
#include "LAYER2/MAC/mac_proto.h"
#include "RRC/LTE/rrc_extern.h"
#include "PHY_INTERFACE/phy_interface.h"
70
#include "common/utils/LOG/log.h"
71 72 73
#include "UTIL/OTG/otg_tx.h"
#include "UTIL/OTG/otg_externs.h"
#include "UTIL/MATH/oml.h"
74
#include "common/utils/LOG/vcd_signal_dumper.h"
75 76
#include "UTIL/OPT/opt.h"
#include "enb_config.h"
77

78 79

#ifndef OPENAIR2
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
80
  #include "UTIL/OTG/otg_extern.h"
81 82 83
#endif

#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
84 85 86 87 88 89
  #if defined(ENABLE_USE_MME)
    #include "s1ap_eNB.h"
    #ifdef PDCP_USE_NETLINK
      #include "SIMULATION/ETH_TRANSPORT/proto.h"
    #endif
  #endif
90 91
#endif

Rohit Gupta's avatar
bugfix  
Rohit Gupta committed
92 93
#include "T.h"

94 95 96 97 98 99 100 101 102 103
//#define DEBUG_THREADS 1

//#define USRP_DEBUG 1
struct timing_info_t {
  //unsigned int frame, hw_slot, last_slot, next_slot;
  RTIME time_min, time_max, time_avg, time_last, time_now;
  //unsigned int mbox0, mbox1, mbox2, mbox_target;
  unsigned int n_samples;
} timing_info;

104 105
// Fix per CC openair rf/if device update
// extern openair0_device openair0;
106

knopp's avatar
knopp committed
107

108
#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
109 110
  extern volatile int             start_eNB;
  extern volatile int             start_UE;
111 112 113
#endif
extern volatile int                    oai_exit;

Cedric Roux's avatar
Cedric Roux committed
114
extern int transmission_mode;
115

116 117
extern int oaisim_flag;

118 119 120
//uint16_t sf_ahead=4;
extern uint16_t sf_ahead;

121

122
//pthread_t                       main_eNB_thread;
123 124 125

time_stats_t softmodem_stats_mt; // main thread
time_stats_t softmodem_stats_hw; //  hw acquisition
knopp's avatar
knopp committed
126
time_stats_t softmodem_stats_rxtx_sf; // total tx time
127
time_stats_t nfapi_meas; // total tx time
128
time_stats_t softmodem_stats_rx_sf; // total rx time
129 130 131 132 133 134 135 136 137

/* mutex, cond and variable to serialize phy proc TX calls
 * (this mechanism may be relaxed in the future for better
 * performances)
 */
static struct {
  pthread_mutex_t  mutex_phy_proc_tx;
  pthread_cond_t   cond_phy_proc_tx;
  volatile uint8_t phy_proc_CC_id;
138
} sync_phy_proc;
139

140 141
extern double cpuf;

142

143
void init_eNB(int,int);
144
void stop_eNB(int nb_inst);
145

Wang Tsu-Han's avatar
Wang Tsu-Han committed
146
int wakeup_tx(PHY_VARS_eNB *eNB);
147
int wakeup_txfh(L1_rxtx_proc_t *proc,PHY_VARS_eNB *eNB);
148
void wakeup_prach_eNB(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
149
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
150
  void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
151
#endif
152

153 154 155 156 157 158
extern uint8_t nfapi_mode;
extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset);

//#define TICK_TO_US(ts) (ts.diff)
#define TICK_TO_US(ts) (ts.trials==0?0:ts.diff/ts.trials)
knopp's avatar
knopp committed
159

160

161
static inline int rxtx(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, char *thread_name) {
knopp's avatar
knopp committed
162
  start_meas(&softmodem_stats_rxtx_sf);
163
  //L1_rxtx_proc_t *L1_proc_tx = &eNB->proc.L1_proc_tx;
164

165 166
  // *******************************************************************

167
#if defined(PRE_SCD_THREAD)
168
    RU_t *ru = RC.ru[0];
169
#endif
170

171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  if (nfapi_mode == 1) {
    // I am a PNF and I need to let nFAPI know that we have a (sub)frame tick
    uint16_t frame = proc->frame_rx;
    uint16_t subframe = proc->subframe_rx;
    //add_subframe(&frame, &subframe, 4);
    //oai_subframe_ind(proc->frame_tx, proc->subframe_tx);
    //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) - NOT CALLED ********\n", frame, subframe);
    start_meas(&nfapi_meas);
    oai_subframe_ind(frame, subframe);
    stop_meas(&nfapi_meas);

    if (eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus||
        eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs ||
        eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs ||
        eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles ||
        eNB->UL_INFO.cqi_ind.number_of_cqis
       ) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
188 189 190 191 192 193 194 195
      LOG_D(PHY, "UL_info[rx_ind:%05d:%d harqs:%05d:%d crcs:%05d:%d preambles:%05d:%d cqis:%d] RX:%04d%d TX:%04d%d num_pdcch_symbols:%d\n",
            NFAPI_SFNSF2DEC(eNB->UL_INFO.rx_ind.sfn_sf),   eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus,
            NFAPI_SFNSF2DEC(eNB->UL_INFO.harq_ind.sfn_sf), eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs,
            NFAPI_SFNSF2DEC(eNB->UL_INFO.crc_ind.sfn_sf),  eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs,
            NFAPI_SFNSF2DEC(eNB->UL_INFO.rach_ind.sfn_sf), eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles,
            eNB->UL_INFO.cqi_ind.number_of_cqis,
            proc->frame_rx, proc->subframe_rx,
            proc->frame_tx, proc->subframe_tx, eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols);
196 197 198 199 200 201 202 203
    }
  }

  if (nfapi_mode == 1 && eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols == 0) {
    LOG_E(PHY, "eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols == 0");
    return 0;
  }

knopp's avatar
knopp committed
204 205
  // ****************************************
  // Common RX procedures subframe n
Cedric Roux's avatar
Cedric Roux committed
206 207
  T(T_ENB_PHY_DL_TICK, T_INT(eNB->Mod_id), T_INT(proc->frame_tx), T_INT(proc->subframe_tx));

208
  // if this is IF5 or 3GPP_eNB
209
  if (eNB && eNB->RU_list && eNB->RU_list[0] && eNB->RU_list[0]->function < NGFI_RAU_IF4p5) {
210
    wakeup_prach_eNB(eNB,NULL,proc->frame_rx,proc->subframe_rx);
211
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
212 213 214
    wakeup_prach_eNB_br(eNB,NULL,proc->frame_rx,proc->subframe_rx);
#endif
  }
Wang Tsu-Han's avatar
Wang Tsu-Han committed
215 216 217

  release_UE_in_freeList(eNB->Mod_id);

knopp's avatar
knopp committed
218
  // UE-specific RX processing for subframe n
219
  if (nfapi_mode == 0 || nfapi_mode == 1) {
220
    phy_procedures_eNB_uespec_RX(eNB, proc);
221
  }
222

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
223 224
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER, 1 );

225 226 227 228
#if defined(PRE_SCD_THREAD)
    if (nfapi_mode == 2){
      new_dlsch_ue_select_tbl_in_use = dlsch_ue_select_tbl_in_use;
      dlsch_ue_select_tbl_in_use = !dlsch_ue_select_tbl_in_use;
229 230 231 232 233 234 235

// L2-emulator can work only one eNB.
//      memcpy(&pre_scd_eNB_UE_stats,&RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.eNB_UE_stats, sizeof(eNB_UE_STATS)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
//      memcpy(&pre_scd_activeUE, &RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.active, sizeof(boolean_t)*NUMBER_OF_UE_MAX);
      memcpy(&pre_scd_eNB_UE_stats,&RC.mac[0]->UE_list.eNB_UE_stats, sizeof(eNB_UE_STATS)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
      memcpy(&pre_scd_activeUE, &RC.mac[0]->UE_list.active, sizeof(boolean_t)*NUMBER_OF_UE_MAX);

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
      if (pthread_mutex_lock(&ru->proc.mutex_pre_scd)!= 0) {
          LOG_E( PHY, "[eNB] error locking proc mutex for eNB pre scd\n");
          exit_fun("error locking mutex_time");
      }

      ru->proc.instance_pre_scd++;

      if (ru->proc.instance_pre_scd == 0) {
          if (pthread_cond_signal(&ru->proc.cond_pre_scd) != 0) {
              LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB pre scd\n" );
              exit_fun( "ERROR pthread_cond_signal cond_pre_scd" );
          }
      }else{
          LOG_E( PHY, "[eNB] frame %d subframe %d rxtx busy instance_pre_scd %d\n",
                 proc->frame_rx,proc->subframe_rx,ru->proc.instance_pre_scd );
      }

      if (pthread_mutex_unlock(&ru->proc.mutex_pre_scd)!= 0) {
          LOG_E( PHY, "[eNB] error unlocking mutex_pre_scd mutex for eNB pre scd\n");
          exit_fun("error unlocking mutex_pre_scd");
      }
    }
#endif

260
  pthread_mutex_lock(&eNB->UL_INFO_mutex);
261 262 263 264 265
  eNB->UL_INFO.frame     = proc->frame_rx;
  eNB->UL_INFO.subframe  = proc->subframe_rx;
  eNB->UL_INFO.module_id = eNB->Mod_id;
  eNB->UL_INFO.CC_id     = eNB->CC_id;
  eNB->if_inst->UL_indication(&eNB->UL_INFO);
266
  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
267 268
  /* this conflict resolution may be totally wrong, to be tested */
  /* CONFLICT RESOLUTION: BEGIN */
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
269 270
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER, 0 );

271
  if(oai_exit) return(-1);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
272 273

  if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
274
#ifndef PHY_TX_THREAD
275
    phy_procedures_eNB_TX(eNB, proc, 1);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
276
#endif
277
  }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
278

Wang Tsu-Han's avatar
Wang Tsu-Han committed
279 280 281
  /* CONFLICT RESOLUTION: what about this release_thread call, has it to be done? if yes, where? */
  //if (release_thread(&proc->mutex_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) return(-1);
  /* CONFLICT RESOLUTION: END */
knopp's avatar
knopp committed
282
  stop_meas( &softmodem_stats_rxtx_sf );
283
  LOG_D(PHY,"%s() Exit proc[rx:%d%d tx:%d%d]\n", __FUNCTION__, proc->frame_rx, proc->subframe_rx, proc->frame_tx, proc->subframe_tx);
284
  LOG_D(PHY, "rxtx:%lld nfapi:%lld tx:%lld rx:%lld prach:%lld ofdm:%lld ",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
285 286 287 288 289 290
        softmodem_stats_rxtx_sf.p_time, nfapi_meas.p_time,
        TICK_TO_US(eNB->phy_proc_tx),
        TICK_TO_US(eNB->phy_proc_rx),
        TICK_TO_US(eNB->rx_prach),
        TICK_TO_US(eNB->ofdm_mod_stats)
       );
291
  LOG_D(PHY,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
292 293 294 295 296 297 298 299
        "dlsch[enc:%lld mod:%lld scr:%lld rm:%lld t:%lld i:%lld] rx_dft:%lld ",
        TICK_TO_US(eNB->dlsch_encoding_stats),
        TICK_TO_US(eNB->dlsch_modulation_stats),
        TICK_TO_US(eNB->dlsch_scrambling_stats),
        TICK_TO_US(eNB->dlsch_rate_matching_stats),
        TICK_TO_US(eNB->dlsch_turbo_encoding_stats),
        TICK_TO_US(eNB->dlsch_interleaving_stats),
        TICK_TO_US(eNB->rx_dft_stats));
300
  LOG_D(PHY," ulsch[ch:%lld freq:%lld dec:%lld demod:%lld ru:%lld ",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
301 302 303 304 305
        TICK_TO_US(eNB->ulsch_channel_estimation_stats),
        TICK_TO_US(eNB->ulsch_freq_offset_estimation_stats),
        TICK_TO_US(eNB->ulsch_decoding_stats),
        TICK_TO_US(eNB->ulsch_demodulation_stats),
        TICK_TO_US(eNB->ulsch_rate_unmatching_stats));
306
  LOG_D(PHY, "td:%lld dei:%lld dem:%lld llr:%lld tci:%lld ",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
307 308 309 310 311 312 313 314 315 316 317 318 319
        TICK_TO_US(eNB->ulsch_turbo_decoding_stats),
        TICK_TO_US(eNB->ulsch_deinterleaving_stats),
        TICK_TO_US(eNB->ulsch_demultiplexing_stats),
        TICK_TO_US(eNB->ulsch_llr_stats),
        TICK_TO_US(eNB->ulsch_tc_init_stats));
  LOG_D(PHY, "tca:%lld tcb:%lld tcg:%lld tce:%lld l1:%lld l2:%lld]\n\n",
        TICK_TO_US(eNB->ulsch_tc_alpha_stats),
        TICK_TO_US(eNB->ulsch_tc_beta_stats),
        TICK_TO_US(eNB->ulsch_tc_gamma_stats),
        TICK_TO_US(eNB->ulsch_tc_ext_stats),
        TICK_TO_US(eNB->ulsch_tc_intl1_stats),
        TICK_TO_US(eNB->ulsch_tc_intl2_stats)
       );
knopp's avatar
knopp committed
320 321 322
  return(0);
}

323

Wang Tsu-Han's avatar
Wang Tsu-Han committed
324
static void* L1_thread_tx(void* param) {
325

326 327
  L1_proc_t *eNB_proc  = (L1_proc_t*)param;
  L1_rxtx_proc_t *proc = &eNB_proc->L1_proc_tx;
328 329
  PHY_VARS_eNB *eNB = RC.eNB[0][proc->CC_id];
  char thread_name[100];
Wang Tsu-Han's avatar
Wang Tsu-Han committed
330
  sprintf(thread_name,"TXnp4_%d\n",&eNB->proc.L1_proc == proc ? 0 : 1);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
331
  thread_top_init(thread_name,1,470000,500000,500000);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
332

333
  //wait_sync("tx_thread");
334 335

  while (!oai_exit) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
336
    if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break;
337
    if (oai_exit) break;  
338 339 340 341 342 343

    // *****************************************
    // TX processing for subframe n+4
    // run PHY TX procedures the one after the other for all CCs to avoid race conditions
    // (may be relaxed in the future for performance reasons)
    // *****************************************
344 345 346 347
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_TX1_ENB,proc->subframe_tx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_RX1_ENB,proc->subframe_rx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX1_ENB,proc->frame_tx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX1_ENB,proc->frame_rx);
348
    phy_procedures_eNB_TX(eNB, proc, 1);
349

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
350

Wang Tsu-Han's avatar
Wang Tsu-Han committed
351
    pthread_mutex_lock( &proc->mutex );
352
    proc->instance_cnt = -1;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
353

354
    // the thread can now be woken up
Wang Tsu-Han's avatar
Wang Tsu-Han committed
355
    if (pthread_cond_signal(&proc->cond) != 0) {
356 357 358
      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
      exit_fun( "ERROR pthread_cond_signal" );
    }
Wang Tsu-Han's avatar
Wang Tsu-Han committed
359
    pthread_mutex_unlock( &proc->mutex );
Wang Tsu-Han's avatar
Wang Tsu-Han committed
360
    wakeup_txfh(proc,eNB);
361 362 363 364 365
  }

  return 0;
}

366
/*!
knopp's avatar
knopp committed
367
 * \brief The RX UE-specific and TX thread of eNB.
368
 * \param param is a \ref L1_proc_t structure which contains the info what to process.
369 370
 * \returns a pointer to an int. The storage is not on the heap and must not be freed.
 */
371

Wang Tsu-Han's avatar
Wang Tsu-Han committed
372
static void* L1_thread( void* param ) {
Sandeep Kumar's avatar
Sandeep Kumar committed
373

knopp's avatar
knopp committed
374
  static int eNB_thread_rxtx_status;
375 376
  //L1_proc_t *eNB_proc  = (L1_proc_t*)param;
  L1_rxtx_proc_t *proc;
377 378 379

  // Working
  if(nfapi_mode ==2){
380
    proc = (L1_rxtx_proc_t*)param;
381 382
  }
  else{
383 384
    L1_proc_t *eNB_proc  = (L1_proc_t*)param;
    proc = &eNB_proc->L1_proc;
385 386
  }

387
  PHY_VARS_eNB *eNB = RC.eNB[0][proc->CC_id];
388

knopp's avatar
knopp committed
389
  char thread_name[100];
390 391
  cpu_set_t cpuset;
  CPU_ZERO(&cpuset);
392
  // set default return value
knopp's avatar
knopp committed
393
  eNB_thread_rxtx_status = 0;
394

Wang Tsu-Han's avatar
Wang Tsu-Han committed
395
  sprintf(thread_name,"RXn_TXnp4_%d\n",&eNB->proc.L1_proc == proc ? 0 : 1);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
396 397 398
  thread_top_init(thread_name,1,470000,500000,500000);
  pthread_setname_np( pthread_self(),"rxtx processing");
  LOG_I(PHY,"thread rxtx created id=%ld\n", syscall(__NR_gettid));
399 400

  while (!oai_exit) {
knopp's avatar
knopp committed
401
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 0 );
402
    T(T_ENB_MASTER_TICK, T_INT(0), T_INT(proc->frame_rx), T_INT(proc->subframe_rx));
403

Wang Tsu-Han's avatar
Wang Tsu-Han committed
404
    if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break;
405

406
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_CPUID_ENB_THREAD_RXTX,sched_getcpu());
knopp's avatar
knopp committed
407
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 1 );
408 409 410 411
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_TX0_ENB,proc->subframe_tx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_RX0_ENB,proc->subframe_rx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_ENB,proc->frame_tx);
    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_ENB,proc->frame_rx);
412

413 414
    if (oai_exit) break;

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
415
    if (eNB->CC_id==0) {
416
      if (rxtx(eNB,proc,thread_name) < 0) break;
417
    }
418

419
    if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT)              phy_procedures_eNB_TX(eNB, proc, 1);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
420
    if (release_thread(&proc->mutex,&proc->instance_cnt,thread_name)<0) break;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
421
    if (nfapi_mode!=2){
Wang Tsu-Han's avatar
Wang Tsu-Han committed
422
    	if(get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)      wakeup_tx(eNB);
423
    	else if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT)     wakeup_txfh(proc,eNB);
424
    }
knopp's avatar
knopp committed
425
  } // while !oai_exit
426

knopp's avatar
knopp committed
427
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 0 );
428
  LOG_D(PHY, " *** Exiting eNB thread RXn_TXnp4\n");
knopp's avatar
knopp committed
429 430
  eNB_thread_rxtx_status = 0;
  return &eNB_thread_rxtx_status;
431 432
}

Wang Tsu-Han's avatar
Wang Tsu-Han committed
433
void eNB_top(PHY_VARS_eNB *eNB, int frame_rx, int subframe_rx, char *string,RU_t *ru)
Cedric Roux's avatar
Cedric Roux committed
434
{
435 436
  L1_proc_t *proc           = &eNB->proc;
  L1_rxtx_proc_t *L1_proc = &proc->L1_proc;
knopp's avatar
knopp committed
437 438
  LTE_DL_FRAME_PARMS *fp = &ru->frame_parms;
  RU_proc_t *ru_proc=&ru->proc;
439 440
  proc->frame_rx    = frame_rx;
  proc->subframe_rx = subframe_rx;
knopp's avatar
knopp committed
441

Cedric Roux's avatar
Cedric Roux committed
442
  if (!oai_exit) {
443
    T(T_ENB_MASTER_TICK, T_INT(0), T_INT(proc->frame_rx), T_INT(proc->subframe_rx));
knopp's avatar
knopp committed
444

Wang Tsu-Han's avatar
Wang Tsu-Han committed
445 446 447 448 449
    L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
    L1_proc->frame_rx     = ru_proc->frame_rx;
    L1_proc->subframe_rx  = ru_proc->subframe_rx;
    L1_proc->frame_tx     = (L1_proc->subframe_rx > (9-sf_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx;
    L1_proc->subframe_tx  = (L1_proc->subframe_rx + sf_ahead)%10;
knopp's avatar
knopp committed
450

Wang Tsu-Han's avatar
Wang Tsu-Han committed
451 452 453 454
    if (rxtx(eNB,L1_proc,string) < 0) LOG_E(PHY,"eNB %d CC_id %d failed during execution\n",eNB->Mod_id,eNB->CC_id);
    ru_proc->timestamp_tx = L1_proc->timestamp_tx;
    ru_proc->subframe_tx  = L1_proc->subframe_tx;
    ru_proc->frame_tx     = L1_proc->frame_tx;
455
  }
knopp's avatar
knopp committed
456 457
}

458
int wakeup_txfh(L1_rxtx_proc_t *proc,PHY_VARS_eNB *eNB) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
459 460 461 462 463

  RU_t *ru;
  RU_proc_t *ru_proc;


464 465 466
  struct timespec wait;
  wait.tv_sec=0;
  wait.tv_nsec=5000000L;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
467

468
  if(wait_on_condition(&proc->mutex_RUs,&proc->cond_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
469
    LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", proc->frame_tx, proc->subframe_tx);
470 471
    return(-1);
  }
Wang Tsu-Han's avatar
Wang Tsu-Han committed
472 473 474
  pthread_mutex_lock(&eNB->proc.mutex_RU_tx);
  eNB->proc.RU_mask_tx = 0;
  pthread_mutex_unlock(&eNB->proc.mutex_RU_tx);
475
  if (release_thread(&proc->mutex_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) return(-1);
476

Wang Tsu-Han's avatar
Wang Tsu-Han committed
477 478 479 480 481 482 483 484 485 486 487 488 489
  for(int i=0; i<eNB->num_RU; i++)
  {
    ru      = eNB->RU_list[i];
    ru_proc = &ru->proc;
    if (ru_proc->instance_cnt_eNBs == 0) {
      LOG_E(PHY,"Frame %d, subframe %d: TX FH thread busy, dropping Frame %d, subframe %d\n", ru_proc->frame_tx, ru_proc->subframe_tx, proc->frame_rx, proc->subframe_rx);
      return(-1);
    }
    if (pthread_mutex_timedlock(&ru_proc->mutex_eNBs,&wait) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB TX1 thread %d (IC %d)\n", ru_proc->subframe_rx&1,ru_proc->instance_cnt_eNBs );
      exit_fun( "error locking mutex_eNB" );
      return(-1);
    }
490

491
    ru_proc->instance_cnt_eNBs = 0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
492 493 494
    ru_proc->timestamp_tx = proc->timestamp_tx;
    ru_proc->subframe_tx  = proc->subframe_tx;
    ru_proc->frame_tx     = proc->frame_tx;
495

496
  
Wang Tsu-Han's avatar
Wang Tsu-Han committed
497 498 499 500 501 502
    // the thread can now be woken up
    if (pthread_cond_signal(&ru_proc->cond_eNBs) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
      exit_fun( "ERROR pthread_cond_signal" );
      return(-1);
    }
503
  
Wang Tsu-Han's avatar
Wang Tsu-Han committed
504 505
    pthread_mutex_unlock( &ru_proc->mutex_eNBs );
  }
506 507 508 509

  return(0);
}

Wang Tsu-Han's avatar
Wang Tsu-Han committed
510
int wakeup_tx(PHY_VARS_eNB *eNB) {
511

512
  L1_proc_t *proc=&eNB->proc;
513

514 515
  L1_rxtx_proc_t *L1_proc_tx = &proc->L1_proc_tx;
  L1_rxtx_proc_t *L1_proc    = &proc->L1_proc;
516 517 518 519 520 521

  
  struct timespec wait;
  wait.tv_sec=0;
  wait.tv_nsec=5000000L;
  
522
  
Wang Tsu-Han's avatar
Wang Tsu-Han committed
523
  if (pthread_mutex_timedlock(&L1_proc_tx->mutex,&wait) != 0) {
524 525
    LOG_E(PHY, "[SCHED][eNB] ERROR locking mutex for eNB L1_thread_tx\n");
    exit_fun("ERROR pthread_lock");
526 527
    return(-1);
  }
528 529
  while(L1_proc_tx->instance_cnt == 0){
    pthread_cond_wait(&L1_proc_tx->cond,&L1_proc_tx->mutex);
530 531
  }

532
  L1_proc_tx->instance_cnt = 0;
533 534

  
Wang Tsu-Han's avatar
Wang Tsu-Han committed
535 536 537 538 539
  L1_proc_tx->subframe_rx   = L1_proc->subframe_rx;
  L1_proc_tx->frame_rx      = L1_proc->frame_rx;
  L1_proc_tx->subframe_tx   = L1_proc->subframe_tx;
  L1_proc_tx->frame_tx      = L1_proc->frame_tx;
  L1_proc_tx->timestamp_tx  = L1_proc->timestamp_tx;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
540

541
  // the thread can now be woken up
Wang Tsu-Han's avatar
Wang Tsu-Han committed
542
  if (pthread_cond_signal(&L1_proc_tx->cond) != 0) {
543
    LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
544 545 546 547
    exit_fun( "ERROR pthread_cond_signal" );
    return(-1);
  }
  
Wang Tsu-Han's avatar
Wang Tsu-Han committed
548
  pthread_mutex_unlock( &L1_proc_tx->mutex);
549 550
  return(0);
}
knopp's avatar
knopp committed
551

552 553
int wakeup_rxtx(PHY_VARS_eNB *eNB,RU_t *ru) {

554
  L1_proc_t *proc=&eNB->proc;
555
  RU_proc_t *ru_proc=&ru->proc;
556

557
  L1_rxtx_proc_t *L1_proc=&proc->L1_proc;
558
  
559
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
560 561
  int i;
  struct timespec wait;
562
  pthread_mutex_lock(&proc->mutex_RU);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
563 564

  for (i=0; i<eNB->num_RU; i++) {
565 566
    if (ru == eNB->RU_list[i]) {
      if ((proc->RU_mask&(1<<i)) > 0)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
567 568 569
        LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU %d (num_RU %d,mask %x) has not been served yet!\n",
              eNB->Mod_id,proc->frame_rx,proc->subframe_rx,ru->idx,eNB->num_RU,proc->RU_mask);

570 571 572
      proc->RU_mask |= (1<<i);
    }
  }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
573

574
  if (proc->RU_mask != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
575
    LOG_E(PHY,"Not all RUs have provided their info\n");
576 577
    pthread_mutex_unlock(&proc->mutex_RU);
    return(0);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
578
  } else { // all RUs have provided their information so continue on and wakeup eNB processing
579 580 581 582
    proc->RU_mask = 0;
    pthread_mutex_unlock(&proc->mutex_RU);
  }

583 584
  wait.tv_sec=0;
  wait.tv_nsec=5000000L;
585

Wang Tsu-Han's avatar
Wang Tsu-Han committed
586 587 588
    
  if (L1_proc->instance_cnt == 0) {
    LOG_E(PHY,"Frame %d, subframe %d: RXTX0 thread busy, dropping\n",L1_proc->frame_rx,L1_proc->subframe_rx);
589 590 591
    return(-1);
  }

Cedric Roux's avatar
Cedric Roux committed
592
  // wake up TX for subframe n+sf_ahead
593
  // lock the TX mutex and make sure the thread is ready
Wang Tsu-Han's avatar
Wang Tsu-Han committed
594 595
  if (pthread_mutex_timedlock(&L1_proc->mutex,&wait) != 0) {
    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB RXTX thread %d (IC %d)\n", L1_proc->subframe_rx&1,L1_proc->instance_cnt );
596 597 598
    exit_fun( "error locking mutex_rxtx" );
    return(-1);
  }
599

Wang Tsu-Han's avatar
Wang Tsu-Han committed
600
  ++L1_proc->instance_cnt;
601 602 603 604
  
  // We have just received and processed the common part of a subframe, say n. 
  // TS_rx is the last received timestamp (start of 1st slot), TS_tx is the desired 
  // transmitted timestamp of the next TX slot (first).
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
605
  // The last (TS_rx mod samples_per_frame) was n*samples_per_tti,
606 607
  // we want to generate subframe (n+sf_ahead), so TS_tx = TX_rx+sf_ahead*samples_per_tti,
  // and proc->subframe_tx = proc->subframe_rx+sf_ahead
Wang Tsu-Han's avatar
Wang Tsu-Han committed
608 609 610 611 612
  L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
  L1_proc->frame_rx     = ru_proc->frame_rx;
  L1_proc->subframe_rx  = ru_proc->subframe_rx;
  L1_proc->frame_tx     = (L1_proc->subframe_rx > (9-sf_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx;
  L1_proc->subframe_tx  = (L1_proc->subframe_rx + sf_ahead)%10;
613

614
  // the thread can now be woken up
Wang Tsu-Han's avatar
Wang Tsu-Han committed
615
  if (pthread_cond_signal(&L1_proc->cond) != 0) {
616 617 618 619 620
    LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB RXn-TXnp4 thread\n");
    exit_fun( "ERROR pthread_cond_signal" );
    return(-1);
  }

621
  pthread_mutex_unlock( &L1_proc->mutex);
622 623 624
  return(0);
}

625
void wakeup_prach_eNB(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe) {
knopp's avatar
knopp committed
626

627
  L1_proc_t *proc = &eNB->proc;
knopp's avatar
knopp committed
628
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
629
  int i;
knopp's avatar
knopp committed
630

631 632
  if (ru!=NULL) {
    pthread_mutex_lock(&proc->mutex_RU_PRACH);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
633 634

    for (i=0; i<eNB->num_RU; i++) {
635
      if (ru == eNB->RU_list[i]) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
636 637 638 639 640 641 642
        LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach,eNB->num_RU);

        if ((proc->RU_mask_prach&(1<<i)) > 0)
          LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
                eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach);

        proc->RU_mask_prach |= (1<<i);
643 644
      }
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
645

646 647
    if (proc->RU_mask_prach != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
      pthread_mutex_unlock(&proc->mutex_RU_PRACH);
knopp's avatar
knopp committed
648
      return;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
649
    } else { // all RUs have provided their information so continue on and wakeup eNB processing
650 651 652 653
      proc->RU_mask_prach = 0;
      pthread_mutex_unlock(&proc->mutex_RU_PRACH);
    }
  }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
654

knopp's avatar
knopp committed
655
  // check if we have to detect PRACH first
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
656
  if (is_prach_subframe(fp,frame,subframe)>0) {
657
    LOG_D(PHY,"Triggering prach processing, frame %d, subframe %d\n",frame,subframe);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
658

knopp's avatar
knopp committed
659
    if (proc->instance_cnt_prach == 0) {
660
      LOG_W(PHY,"[eNB] Frame %d Subframe %d, dropping PRACH\n", frame,subframe);
knopp's avatar
knopp committed
661 662
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
663

knopp's avatar
knopp committed
664 665 666 667 668 669
    // wake up thread for PRACH RX
    if (pthread_mutex_lock(&proc->mutex_prach) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB PRACH thread %d (IC %d)\n", proc->thread_index, proc->instance_cnt_prach);
      exit_fun( "error locking mutex_prach" );
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
670

knopp's avatar
knopp committed
671 672
    ++proc->instance_cnt_prach;
    // set timing for prach thread
673 674
    proc->frame_prach = frame;
    proc->subframe_prach = subframe;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
675

knopp's avatar
knopp committed
676 677 678 679 680 681
    // the thread can now be woken up
    if (pthread_cond_signal(&proc->cond_prach) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB PRACH thread %d\n", proc->thread_index);
      exit_fun( "ERROR pthread_cond_signal" );
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
682

knopp's avatar
knopp committed
683 684 685 686
    pthread_mutex_unlock( &proc->mutex_prach );
  }
}

687
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
688 689
void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe) {

690
  L1_proc_t *proc = &eNB->proc;
691 692 693 694 695
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
  int i;

  if (ru!=NULL) {
    pthread_mutex_lock(&proc->mutex_RU_PRACH_br);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
696 697

    for (i=0; i<eNB->num_RU; i++) {
698
      if (ru == eNB->RU_list[i]) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
699 700 701 702 703 704 705
        LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH BR (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach_br,eNB->num_RU);

        if ((proc->RU_mask_prach_br&(1<<i)) > 0)
          LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH BR) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
                eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach_br);

        proc->RU_mask_prach_br |= (1<<i);
706 707
      }
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
708

709 710
    if (proc->RU_mask_prach_br != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
      pthread_mutex_unlock(&proc->mutex_RU_PRACH_br);
knopp's avatar
knopp committed
711
      return;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
712
    } else { // all RUs have provided their information so continue on and wakeup eNB processing
713 714 715 716
      proc->RU_mask_prach_br = 0;
      pthread_mutex_unlock(&proc->mutex_RU_PRACH_br);
    }
  }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
717

718
  // check if we have to detect PRACH first
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
719
  if (is_prach_subframe(fp,frame,subframe)>0) {
720
    LOG_D(PHY,"Triggering prach br processing, frame %d, subframe %d\n",frame,subframe);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
721

722 723 724 725
    if (proc->instance_cnt_prach_br == 0) {
      LOG_W(PHY,"[eNB] Frame %d Subframe %d, dropping PRACH BR\n", frame,subframe);
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
726

727 728 729 730 731 732
    // wake up thread for PRACH RX
    if (pthread_mutex_lock(&proc->mutex_prach_br) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB PRACH thread %d (IC %d)\n", proc->thread_index, proc->instance_cnt_prach_br);
      exit_fun( "error locking mutex_prach" );
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
733

734 735 736 737
    ++proc->instance_cnt_prach_br;
    // set timing for prach thread
    proc->frame_prach_br = frame;
    proc->subframe_prach_br = subframe;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
738

739 740 741 742 743 744
    // the thread can now be woken up
    if (pthread_cond_signal(&proc->cond_prach_br) != 0) {
      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB PRACH BR thread %d\n", proc->thread_index);
      exit_fun( "ERROR pthread_cond_signal" );
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
745

746 747 748 749 750
    pthread_mutex_unlock( &proc->mutex_prach_br );
  }
}
#endif

Wang Tsu-Han's avatar
Wang Tsu-Han committed
751

752 753
/*!
 * \brief The prach receive thread of eNB.
754
 * \param param is a \ref L1_proc_t structure which contains the info what to process.
755 756
 * \returns a pointer to an int. The storage is not on the heap and must not be freed.
 */
757
static void *eNB_thread_prach( void *param ) {
758
  static int eNB_thread_prach_status;
759
  PHY_VARS_eNB *eNB= (PHY_VARS_eNB *)param;
760
  L1_proc_t *proc = &eNB->proc;
Raymond Knopp's avatar
Raymond Knopp committed
761

762 763
  // set default return value
  eNB_thread_prach_status = 0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
764
  thread_top_init("eNB_thread_prach",1,500000,1000000,20000000);
765

766
  //wait_sync("eNB_thread_prach");
767

Sandeep Kumar's avatar
Sandeep Kumar committed
768
  while (!oai_exit) {
knopp's avatar
knopp committed
769
    if (wait_on_condition(&proc->mutex_prach,&proc->cond_prach,&proc->instance_cnt_prach,"eNB_prach_thread") < 0) break;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
770

771
    if (oai_exit) break;
knopp's avatar
knopp committed
772 773

    LOG_D(PHY,"Running eNB prach procedures\n");
774
    prach_procedures(eNB
775
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
776
                     ,0
777
#endif
778
                    );
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
779

knopp's avatar
knopp committed
780
    if (release_thread(&proc->mutex_prach,&proc->instance_cnt_prach,"eNB_prach_thread") < 0) break;
Sandeep Kumar's avatar
Sandeep Kumar committed
781
  }
782

knopp's avatar
knopp committed
783
  LOG_I(PHY, "Exiting eNB thread PRACH\n");
784 785
  eNB_thread_prach_status = 0;
  return &eNB_thread_prach_status;
786 787
}

788
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
789 790
/*!
 * \brief The prach receive thread of eNB for BL/CE UEs.
791
 * \param param is a \ref L1_proc_t structure which contains the info what to process.
792 793
 * \returns a pointer to an int. The storage is not on the heap and must not be freed.
 */
794
static void *eNB_thread_prach_br( void *param ) {
795 796
  static int eNB_thread_prach_status;
  PHY_VARS_eNB *eNB= (PHY_VARS_eNB *)param;
797
  L1_proc_t *proc = &eNB->proc;
798 799 800

  // set default return value
  eNB_thread_prach_status = 0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
801
  thread_top_init("eNB_thread_prach_br",1,500000,1000000,20000000);
802 803 804

  while (!oai_exit) {
    if (wait_on_condition(&proc->mutex_prach_br,&proc->cond_prach_br,&proc->instance_cnt_prach_br,"eNB_prach_thread_br") < 0) break;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
805