diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 2de8298ffc5aa9cacf38bbea223bfa9d0b4f3c4e..4fb9b7c2333e072d60bfc5e4a5f68c10dc9da132 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -111,8 +111,6 @@ Options -t | --transport protocol ETHERNET , None Adds this trasport protocol support in compilation ---oaisim - Makes the oaisim simulator. Hardware will be defaulted to \"None\". --phy_simulators Makes the unitary tests Layer 1 simulators --core_simulators @@ -124,12 +122,12 @@ Options -V | --vcd Adds a debgging facility to the binary files: GUI with major internal synchronization events -x | --xforms - Adds a software oscilloscope feature to the produced binaries. If oaisim, then enable PRINT_STATS. + Adds a software oscilloscope feature to the produced binaries. --install-system-files Install OpenArInterface required files in Linux system (will ask root password) --noS1 - Compiles oaisim or lte-softmodem without S1 interface, using direct link to IP instead + Compiles lte-softmodem without S1 interface, using direct link to IP instead --verbose-compile Shows detailed compilation instructions in makefile --cflags_processor @@ -164,11 +162,8 @@ Options Generates a basic [1 UE + 1 eNB + no channel] simulator. See targets/ARCH/tcp_bridge/README.tcp_bridge_oai for documentation. Usage (first build): - oaisim (eNB + UE): ./build_oai -I --oaisim -x --install-system-files - Eurecom EXMIMO + COTS UE : ./build_oai -I --eNB -x --install-system-files NI/ETTUS B201 + COTS UE : ./build_oai -I --eNB -x --install-system-files -w USRP Usage (Regular): - oaisim : ./build_oai --oaisim -x Eurecom EXMIMO + OAI ENB : ./build_oai --eNB -x NI/ETTUS B201 + OAI ENB : ./build_oai --eNB -x -w USRP" } @@ -250,10 +245,6 @@ function main() { echo_info "Setting transport protocol to: $TP" fi shift 2;; - --oaisim) - oaisim=1 - echo_info "Will compile oaisim and drivers nasmesh, ..." - shift;; --phy_simulators) SIMUS_PHY=1 echo_info "Will compile dlsim, ulsim, ..." @@ -490,16 +481,6 @@ function main() { check_install_additional_tools fi - if [ "$oaisim" = "1" ] ; then - #to be discussed - # there is no RF device transport protocol - HW="None" - TP="ETHERNET" - - if [ "$XFORMS" == "True" ] ; then - PRINT_STATS="True" - fi - fi echo_info "3. building the compilation directives ..." @@ -689,123 +670,6 @@ function main() { cp $OPENAIR_DIR/cmake_targets/tools/init_exmimo2 $dbin fi - # oaisim compilation - ############### - if [ "$oaisim" = "1" ] ; then - dconf=$OPENAIR_DIR/targets/bin - if [ "$NOS1" = "1" ] ; then - oaisim_build_dir=oaisim_noS1_build_oai - oaisim_exec=oaisim_nos1 - else - oaisim_build_dir=oaisim_build_oai - oaisim_exec=oaisim - fi - - echo_info "Compiling $oaisim_exec ($oaisim_build_dir)" - cmake_file=$DIR/$oaisim_build_dir/CMakeLists.txt - cp $DIR/$oaisim_build_dir/CMakeLists.template $cmake_file - echo "set ( CMAKE_BUILD_TYPE $CMAKE_BUILD_TYPE )" >> $cmake_file - echo "set ( CFLAGS_PROCESSOR_USER \"$CFLAGS_PROCESSOR_USER\" )" >> $cmake_file - echo "set ( XFORMS $XFORMS )" >> $cmake_file - echo "set ( PRINT_STATS $PRINT_STATS )" >> $cmake_file - echo "set ( RRC_ASN1_VERSION \"${REL}\")" >> $cmake_file - echo "set ( ENABLE_VCD_FIFO $VCD_TIMING )" >> $cmake_file - echo "set ( T_TRACER $T_TRACER )" >> $cmake_file - echo "set ( UE_NAS_USE_TUN $UE_NAS_USE_TUN )" >> $cmake_file - echo 'include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)' >> $cmake_file - [ "$CLEAN" = "1" ] && rm -rf $DIR/$oaisim_build_dir/build - mkdir -p $DIR/$oaisim_build_dir/build - cd $DIR/$oaisim_build_dir/build - eval $CMAKE_CMD - compilations \ - $oaisim_build_dir $oaisim_exec \ - $oaisim_exec $dbin/$oaisim_exec.$REL - compilations \ - $oaisim_build_dir $config_libconfig_shlib \ - lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so - compilations \ - $oaisim_build_dir coding \ - libcoding.so $dbin/libcoding.so - - if [ "$NOS1" != "1" ] ; then - - [ "$CLEAN" = "1" ] && rm -rf $DIR/at_commands/build - echo_info "Compiling at_nas_ue" - mkdir -p $DIR/at_commands/build - cd $DIR/at_commands/build - eval $CMAKE_CMD - compilations \ - at_commands at_nas_ue \ - at_nas_ue $dbin/at_nas_ue - - # ue_ip driver compilation - echo_info "Compiling UE specific part (ue_ip driver and usim tools)" - compilations \ - oaisim_build_oai ue_ip \ - CMakeFiles/ue_ip/ue_ip.ko $dbin/ue_ip.ko - - [ "$CLEAN" = "1" ] && rm -rf $DIR/nas_sim_tools/build - mkdir -p $DIR/nas_sim_tools/build - cd $DIR/nas_sim_tools/build - eval $CMAKE_CMD - compilations \ - nas_sim_tools usim \ - usim $dbin/usim - compilations \ - nas_sim_tools nvram \ - nvram $dbin/nvram - compilations \ - nas_sim_tools conf2uedata \ - conf2uedata $dbin/conf2uedata - - # generate USIM data - if [ -f $dbin/conf2uedata ]; then - install_nas_tools $conf_nvram_path $gen_nvram_path - else - echo_warning "not generated UE NAS files: binaries not found" - fi - else - - compilations \ - $oaisim_build_dir rb_tool \ - rb_tool $dbin/rb_tool - - # nasmesh driver compilation - compilations \ - $oaisim_build_dir nasmesh \ - CMakeFiles/nasmesh/nasmesh.ko $dbin/nasmesh.ko - - #oai_nw_drv - #compilations \ - # $oaisim_build_dir oai_nw_drv \ - # CMakeFiles/oai_nw_drv/oai_nw_drv.ko $dbin/oai_nw_drv.ko - fi - - if [ "$TP" == "ETHERNET" ] ; then - compilations \ - $oaisim_build_dir oai_eth_transpro \ - liboai_eth_transpro.so $dbin/liboai_eth_transpro.so.$REL - ln -sf liboai_eth_transpro.so liboai_transpro.so - ln -sf $dbin/liboai_eth_transpro.so.$REL $dbin/liboai_transpro.so - echo_info "liboai_transpro.so is linked with ETHERNET library" - fi - - cmake_file=$DIR/oaisim_mme_build_oai/CMakeLists.txt - cp $DIR/oaisim_mme_build_oai/CMakeLists.template $cmake_file - echo "set ( CMAKE_BUILD_TYPE $CMAKE_BUILD_TYPE )" >> $cmake_file - echo "set ( XFORMS $XFORMS )" >> $cmake_file - echo "set ( RRC_ASN1_VERSION \"${REL}\")" >> $cmake_file - echo "set ( ENABLE_VCD_FIFO $VCD_TIMING )" >> $cmake_file - echo "set ( T_TRACER $T_TRACER )" >> $cmake_file - echo 'include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)' >> $cmake_file - #[ "$CLEAN" = "1" ] && rm -rf $DIR/oaisim_mme_build_oai/build - #mkdir -p $DIR/oaisim_mme_build_oai/build - #cd $DIR/oaisim_mme_build_oai/build - #eval $CMAKE_CMD - #compilations \ - # oaisim_mme_build_oai oaisim_mme \ - # oaisim_mme $dbin/oaisim_mme.$REL - fi # Telnet server compilation ##################### diff --git a/openair1/SIMULATION/TOOLS/channel_sim.c b/openair1/SIMULATION/TOOLS/channel_sim.c index 72fcac2299614f6b0bffd9d989c59718f2c8e858..ed3fbb0357f71195e1a3970027b2d78776a8618d 100644 --- a/openair1/SIMULATION/TOOLS/channel_sim.c +++ b/openair1/SIMULATION/TOOLS/channel_sim.c @@ -51,24 +51,10 @@ #define LOG_D(A,B,C...) printf(B,C) */ -int number_rb_ul; -int first_rbUL ; -extern Signal_buffers_t *signal_buffers_g; -double r_re_DL[NUMBER_OF_UE_MAX][2][30720]; -double r_im_DL[NUMBER_OF_UE_MAX][2][30720]; -double r_re_UL[NUMBER_OF_eNB_MAX][2][30720]; -double r_im_UL[NUMBER_OF_eNB_MAX][2][30720]; -int RU_output_mask[NUMBER_OF_UE_MAX]; -int UE_output_mask[NUMBER_OF_RU_MAX]; -pthread_mutex_t RU_output_mutex[NUMBER_OF_UE_MAX]; -pthread_mutex_t UE_output_mutex[NUMBER_OF_RU_MAX]; - -double ru_amp[NUMBER_OF_RU_MAX]; - -void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs], +void do_DL_sig(sim_t *sim, uint16_t subframe, uint32_t offset, uint32_t length, @@ -87,8 +73,8 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM uint32_t sf_offset; uint8_t hold_channel=0; - uint8_t nb_antennas_rx = RU2UE[0][0][CC_id]->nb_rx; // number of rx antennas at UE - uint8_t nb_antennas_tx = RU2UE[0][0][CC_id]->nb_tx; // number of tx antennas at eNB + uint8_t nb_antennas_rx = sim->RU2UE[0][0][CC_id]->nb_rx; // number of rx antennas at UE + uint8_t nb_antennas_tx = sim->RU2UE[0][0][CC_id]->nb_tx; // number of tx antennas at eNB double s_re0[30720]; double s_re1[30720]; @@ -119,15 +105,15 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM else hold_channel = 1; - pthread_mutex_lock(&RU_output_mutex[UE_id]); + pthread_mutex_lock(&sim->RU_output_mutex[UE_id]); - if (RU_output_mask[UE_id] == 0) { // This is the first eNodeB for this UE, clear the buffer + if (sim->RU_output_mask[UE_id] == 0) { // This is the first eNodeB for this UE, clear the buffer for (aa=0; aa<nb_antennas_rx; aa++) { - memset((void*)r_re_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double)); - memset((void*)r_im_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double)); + memset((void*)sim->r_re_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double)); + memset((void*)sim->r_im_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double)); } } - pthread_mutex_unlock(&RU_output_mutex[UE_id]); + pthread_mutex_unlock(&sim->RU_output_mutex[UE_id]); for (ru_id=0; ru_id<RC.nb_RU; ru_id++) { txdata = RC.ru[ru_id]->common.txdata; @@ -150,7 +136,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM 14, frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE 0, - &ru_amp[ru_id], + &sim->ru_amp[ru_id], frame_parms->N_RB_DL*12); } @@ -166,7 +152,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM 14, frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE 0, - &ru_amp[ru_id], + &sim->ru_amp[ru_id], frame_parms->N_RB_DL*12); tx_pwr = dac_fixed_gain(s_re, @@ -180,7 +166,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM 14, frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE 0, - &ru_amp[ru_id], + &sim->ru_amp[ru_id], frame_parms->N_RB_DL*12); } #ifdef DEBUG_SIM @@ -199,26 +185,26 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM 0)/(12.0*frame_parms->N_RB_DL); //RU2UE[eNB_id][UE_id]->path_loss_dB = 0; - multipath_channel(RU2UE[ru_id][UE_id][CC_id],s_re,s_im,r_re0,r_im0, + multipath_channel(sim->RU2UE[ru_id][UE_id][CC_id],s_re,s_im,r_re0,r_im0, length,hold_channel); #ifdef DEBUG_SIM - rx_pwr = signal_energy_fp2(RU2UE[ru_id][UE_id][CC_id]->ch[0], - RU2UE[ru_id][UE_id][CC_id]->channel_length)*RU2UE[ru_id][UE_id][CC_id]->channel_length; + rx_pwr = signal_energy_fp2(sim->RU2UE[ru_id][UE_id][CC_id]->ch[0], + sim->RU2UE[ru_id][UE_id][CC_id]->channel_length)*sim->RU2UE[ru_id][UE_id][CC_id]->channel_length; LOG_D(OCM,"[SIM][DL] Channel RU %d => UE %d (CCid %d): Channel gain %f dB (%f)\n",ru_id,UE_id,CC_id,10*log10(rx_pwr),rx_pwr); #endif #ifdef DEBUG_SIM - for (i=0; i<RU2UE[ru_id][UE_id][CC_id]->channel_length; i++) - LOG_D(OCM,"channel(%d,%d)[%d] : (%f,%f)\n",ru_id,UE_id,i,RU2UE[ru_id][UE_id][CC_id]->ch[0][i].x,RU2UE[ru_id][UE_id][CC_id]->ch[0][i].y); + for (i=0; i<sim->RU2UE[ru_id][UE_id][CC_id]->channel_length; i++) + LOG_D(OCM,"channel(%d,%d)[%d] : (%f,%f)\n",ru_id,UE_id,i,sim->RU2UE[ru_id][UE_id][CC_id]->ch[0][i].x,sim->RU2UE[ru_id][UE_id][CC_id]->ch[0][i].y); #endif LOG_D(OCM,"[SIM][DL] Channel RU %d => UE %d (CCid %d): tx_power %.1f dBm/RE, path_loss %1.f dB\n", ru_id,UE_id,CC_id, (double)frame_parms->pdsch_config_common.referenceSignalPower, - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB); + sim->RU2UE[ru_id][UE_id][CC_id]->path_loss_dB); #ifdef DEBUG_SIM rx_pwr = signal_energy_fp(r_re0,r_im0,nb_antennas_rx, @@ -233,13 +219,13 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM LOG_D(OCM,"[SIM][DL] UE %d : rx_pwr (noise) -132 dBm/RE (N0fs = %.1f dBm, N0B = %.1f dBm) for subframe %d\n", UE_id, - 10*log10(RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6)-174, - 10*log10(RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6*12*frame_parms->N_RB_DL/(double)frame_parms->ofdm_symbol_size)-174, + 10*log10(sim->RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6)-174, + 10*log10(sim->RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6*12*frame_parms->N_RB_DL/(double)frame_parms->ofdm_symbol_size)-174, subframe); #endif - if (RU2UE[ru_id][UE_id][CC_id]->first_run == 1) - RU2UE[ru_id][UE_id][CC_id]->first_run = 0; + if (sim->RU2UE[ru_id][UE_id][CC_id]->first_run == 1) + sim->RU2UE[ru_id][UE_id][CC_id]->first_run = 0; // RF model @@ -252,7 +238,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM r_im0, nb_antennas_rx, length, - 1e3/RU2UE[ru_id][UE_id][CC_id]->sampling_rate, // sampling time (ns) + 1e3/sim->RU2UE[ru_id][UE_id][CC_id]->sampling_rate, // sampling time (ns) (double)PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB - 66.227); // rx_gain (dB) (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later) #ifdef DEBUG_SIM @@ -266,21 +252,21 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM #endif - pthread_mutex_lock(&RU_output_mutex[UE_id]); + pthread_mutex_lock(&sim->RU_output_mutex[UE_id]); for (i=0; i<frame_parms->samples_per_tti; i++) { for (aa=0; aa<nb_antennas_rx; aa++) { - r_re_DL[UE_id][aa][i]+=r_re0[aa][i]; - r_im_DL[UE_id][aa][i]+=r_im0[aa][i]; + sim->r_re_DL[UE_id][aa][i]+=r_re0[aa][i]; + sim->r_im_DL[UE_id][aa][i]+=r_im0[aa][i]; } } - RU_output_mask[UE_id] |= (1<<ru_id); - if (RU_output_mask[UE_id] == (1<<RC.nb_RU)-1) { - RU_output_mask[UE_id]=0; + sim->RU_output_mask[UE_id] |= (1<<ru_id); + if (sim->RU_output_mask[UE_id] == (1<<RC.nb_RU)-1) { + sim->RU_output_mask[UE_id]=0; - double *r_re_p[2] = {r_re_DL[UE_id][0],r_re_DL[UE_id][1]}; - double *r_im_p[2] = {r_im_DL[UE_id][0],r_im_DL[UE_id][1]}; + double *r_re_p[2] = {sim->r_re_DL[UE_id][0],sim->r_re_DL[UE_id][1]}; + double *r_im_p[2] = {sim->r_im_DL[UE_id][0],sim->r_im_DL[UE_id][1]}; #ifdef DEBUG_SIM rx_pwr = signal_energy_fp(r_re_p,r_im_p,nb_antennas_rx,length<length_meas?length:length_meas,0)/(12.0*frame_parms->N_RB_DL); @@ -311,7 +297,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM #endif } // RU_output_mask - pthread_mutex_unlock(&RU_output_mutex[UE_id]); + pthread_mutex_unlock(&sim->RU_output_mutex[UE_id]); } // ru_id } @@ -319,7 +305,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM -void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs], +void do_UL_sig(sim_t *sim, uint16_t subframe,uint8_t abstraction_flag,LTE_DL_FRAME_PARMS *frame_parms, uint32_t frame,int ru_id,uint8_t CC_id) { @@ -327,8 +313,8 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM int32_t **txdata,**rxdata; uint8_t UE_id=0; - uint8_t nb_antennas_rx = UE2RU[0][0][CC_id]->nb_rx; // number of rx antennas at eNB - uint8_t nb_antennas_tx = UE2RU[0][0][CC_id]->nb_tx; // number of tx antennas at UE + uint8_t nb_antennas_rx = sim->UE2RU[0][0][CC_id]->nb_rx; // number of rx antennas at eNB + uint8_t nb_antennas_tx = sim->UE2RU[0][0][CC_id]->nb_tx; // number of tx antennas at UE double tx_pwr, rx_pwr; int32_t rx_pwr2; @@ -360,15 +346,15 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM r_re0[1] = r_re01; r_im0[1] = r_im01; - pthread_mutex_lock(&UE_output_mutex[ru_id]); + pthread_mutex_lock(&sim->UE_output_mutex[ru_id]); // Clear RX signal for eNB = eNB_id for (i=0; i<frame_parms->samples_per_tti; i++) { for (aa=0; aa<nb_antennas_rx; aa++) { - r_re_UL[ru_id][aa][i]=0.0; - r_im_UL[ru_id][aa][i]=0.0; + sim->r_re_UL[ru_id][aa][i]=0.0; + sim->r_im_UL[ru_id][aa][i]=0.0; } } - pthread_mutex_unlock(&UE_output_mutex[ru_id]); + pthread_mutex_unlock(&sim->UE_output_mutex[ru_id]); // Compute RX signal for eNB = eNB_id for (UE_id=0; UE_id<NB_UE_INST; UE_id++) { @@ -377,7 +363,7 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM AssertFatal(txdata != NULL,"txdata is null\n"); sf_offset = subframe*frame_parms->samples_per_tti; if (((double)PHY_vars_UE_g[UE_id][CC_id]->tx_power_dBm[subframe] + - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB) <= -125.0) { + sim->UE2RU[UE_id][ru_id][CC_id]->path_loss_dB) <= -125.0) { // don't simulate a UE that is too weak LOG_D(OCM,"[SIM][UL] ULPOWERS UE %d tx_pwr %d dBm (num_RE %d) for subframe %d (sf_offset %d)\n", UE_id, @@ -406,20 +392,20 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM subframe,sf_offset); - multipath_channel(UE2RU[UE_id][ru_id][CC_id],s_re,s_im,r_re0,r_im0, + multipath_channel(sim->UE2RU[UE_id][ru_id][CC_id],s_re,s_im,r_re0,r_im0, frame_parms->samples_per_tti,hold_channel); - rx_pwr = signal_energy_fp2(UE2RU[UE_id][ru_id][CC_id]->ch[0], - UE2RU[UE_id][ru_id][CC_id]->channel_length)*UE2RU[UE_id][ru_id][CC_id]->channel_length; + rx_pwr = signal_energy_fp2(sim->UE2RU[UE_id][ru_id][CC_id]->ch[0], + sim->UE2RU[UE_id][ru_id][CC_id]->channel_length)*sim->UE2RU[UE_id][ru_id][CC_id]->channel_length; LOG_D(OCM,"[SIM][UL] subframe %d Channel UE %d => RU %d : %f dB (hold %d,length %d, PL %f)\n",subframe,UE_id,ru_id,10*log10(rx_pwr), - hold_channel,UE2RU[UE_id][ru_id][CC_id]->channel_length, - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB); + hold_channel,sim->UE2RU[UE_id][ru_id][CC_id]->channel_length, + sim->UE2RU[UE_id][ru_id][CC_id]->path_loss_dB); rx_pwr = signal_energy_fp(r_re0,r_im0,nb_antennas_rx,frame_parms->samples_per_tti,0); LOG_D(OCM,"[SIM][UL] RU %d (%d/%d rx antennas) : rx_pwr %f dBm (tx_pwr - PL %f) for subframe %d, sptti %d\n", - ru_id,nb_antennas_rx,UE2RU[UE_id][ru_id][CC_id]->nb_rx,10*log10(rx_pwr),10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe])+UE2RU[UE_id][ru_id][CC_id]->path_loss_dB,subframe,frame_parms->samples_per_tti); + ru_id,nb_antennas_rx,sim->UE2RU[UE_id][ru_id][CC_id]->nb_rx,10*log10(rx_pwr),10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe])+sim->UE2RU[UE_id][ru_id][CC_id]->path_loss_dB,subframe,frame_parms->samples_per_tti); /* if (abs(10*log10(rx_pwr)-10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe])-UE2RU[UE_id][ru_id][CC_id]->path_loss_dB)>3) { write_output("txsig_re.m","s_re",s_re[0],frame_parms->samples_per_tti,1,7); @@ -429,23 +415,23 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM exit(-1); }*/ - if (UE2RU[UE_id][ru_id][CC_id]->first_run == 1) - UE2RU[UE_id][ru_id][CC_id]->first_run = 0; + if (sim->UE2RU[UE_id][ru_id][CC_id]->first_run == 1) + sim->UE2RU[UE_id][ru_id][CC_id]->first_run = 0; - pthread_mutex_lock(&UE_output_mutex[ru_id]); + pthread_mutex_lock(&sim->UE_output_mutex[ru_id]); for (aa=0; aa<nb_antennas_rx; aa++) { for (i=0; i<frame_parms->samples_per_tti; i++) { - r_re_UL[ru_id][aa][i]+=r_re0[aa][i]; - r_im_UL[ru_id][aa][i]+=r_im0[aa][i]; + sim->r_re_UL[ru_id][aa][i]+=r_re0[aa][i]; + sim->r_im_UL[ru_id][aa][i]+=r_im0[aa][i]; } } - pthread_mutex_unlock(&UE_output_mutex[ru_id]); + pthread_mutex_unlock(&sim->UE_output_mutex[ru_id]); } } //UE_id - double *r_re_p[2] = {r_re_UL[ru_id][0],r_re_UL[ru_id][1]}; - double *r_im_p[2] = {r_im_UL[ru_id][0],r_im_UL[ru_id][1]}; + double *r_re_p[2] = {sim->r_re_UL[ru_id][0],sim->r_re_UL[ru_id][1]}; + double *r_im_p[2] = {sim->r_im_UL[ru_id][0],sim->r_im_UL[ru_id][1]}; rx_pwr = signal_energy_fp(r_re_p,r_im_p,nb_antennas_rx,frame_parms->samples_per_tti,0); LOG_D(OCM,"[SIM][UL] RU %d (%d/%d rx antennas) : rx_pwr %f dBm (before RF) for subframe %d, gain %f\n", @@ -455,7 +441,7 @@ void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM r_im_p, nb_antennas_rx, frame_parms->samples_per_tti, - 1e3/UE2RU[0][ru_id][CC_id]->sampling_rate, // sampling time (ns) + 1e3/sim->UE2RU[0][ru_id][CC_id]->sampling_rate, // sampling time (ns) (double)RC.ru[ru_id]->max_rxgain-(double)RC.ru[ru_id]->att_rx - 66.227); // rx_gain (dB) (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later) #ifdef DEBUG_SIM diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h index f5b55dc29f1dbeea7e4f6d7d436c555dde5b003d..bde7b9250633858f8e628a0230d66dc7cfe0d197 100644 --- a/openair1/SIMULATION/TOOLS/sim.h +++ b/openair1/SIMULATION/TOOLS/sim.h @@ -22,7 +22,7 @@ #ifndef __SIMULATION_TOOLS_DEFS_H__ #define __SIMULATION_TOOLS_DEFS_H__ #include "PHY/defs_common.h" - +#include <pthread.h> /** @defgroup _numerical_ Useful Numerical Functions *@{ The present clause specifies several numerical functions for testing of digital communication systems. @@ -181,6 +181,31 @@ typedef enum { EPA_high, } SCM_t; +#include "platform_constants.h" + +typedef struct { + channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs]; + channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs]; + double r_re_DL[NUMBER_OF_UE_MAX][2][30720]; + double r_im_DL[NUMBER_OF_UE_MAX][2][30720]; + double r_re_UL[NUMBER_OF_eNB_MAX][2][30720]; + double r_im_UL[NUMBER_OF_eNB_MAX][2][30720]; + int RU_output_mask[NUMBER_OF_UE_MAX]; + int UE_output_mask[NUMBER_OF_RU_MAX]; + pthread_mutex_t RU_output_mutex[NUMBER_OF_UE_MAX]; + pthread_mutex_t UE_output_mutex[NUMBER_OF_RU_MAX]; + pthread_mutex_t subframe_mutex; + int subframe_ru_mask; + int subframe_UE_mask; + openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs]; + openair0_timestamp current_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs]; + openair0_timestamp last_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs]; + openair0_timestamp last_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs]; + double ru_amp[NUMBER_OF_RU_MAX]; + pthread_t rfsim_thread; +} sim_t; + + /** \brief This routine initializes a new channel descriptor \param nb_tx Number of TX antennas @@ -373,7 +398,9 @@ void multipath_tv_channel(channel_desc_t *desc, double N_RB2sampling_rate(uint16_t N_RB); double N_RB2channel_bandwidth(uint16_t N_RB); -void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs], +#include "targets/RT/USER/rfsim.h" + +void do_DL_sig(sim_t *sim, uint16_t subframe, uint32_t offset, uint32_t length, @@ -381,7 +408,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM uint8_t UE_id, int CC_id); -void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs], +void do_UL_sig(sim_t *sim, uint16_t subframe,uint8_t abstraction_flag,LTE_DL_FRAME_PARMS *frame_parms, uint32_t frame,int ru_id,uint8_t CC_id); diff --git a/openair2/LAYER2/MAC/rar_tools_ue.c b/openair2/LAYER2/MAC/rar_tools_ue.c index 7d24e4c0af31c5fd2a87ea13ec06427f08902d6f..44f0f51582c25090fe1cd3a5fee5243b7511f903 100644 --- a/openair2/LAYER2/MAC/rar_tools_ue.c +++ b/openair2/LAYER2/MAC/rar_tools_ue.c @@ -93,7 +93,7 @@ uint16_t ue_process_rar(const module_id_t module_idP, const int CC_id, const fra } LOG_I(MAC, - "[eNB %d][RAPROC] Frame %d Received RAR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for preamble %d/%d\n", + "[UE %d][RAPROC] Frame %d Received RAR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for preamble %d/%d\n", module_idP, frameP, *(uint8_t *) rarh, rar[0], rar[1], rar[2], rar[3], rar[4], rar[5], rarh->RAPID, preamble_index); #ifdef DEBUG_RAR diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h index 7669fb14502afa9e892296fff26ec46d01547efc..a109b1cee8ccf5fa2d5b8e0e087e14ebd1cfb7fa 100644 --- a/targets/RT/USER/lte-softmodem.h +++ b/targets/RT/USER/lte-softmodem.h @@ -53,6 +53,7 @@ #define CONFIG_HLP_CALPRACH "UE run normal prach with maximum power, but don't continue random-access\n" #define CONFIG_HLP_NOL2CN "bypass L2 and upper layers\n" #define CONFIG_HLP_SIML1 "activate RF simulator instead of HW\n" +#define CONFIG_HLP_NUMUE "number of UE instances\n" #define CONFIG_HLP_UERXG "set UE RX gain\n" #define CONFIG_HLP_UERXGOFF "external UE amplifier offset\n" #define CONFIG_HLP_UETXG "set UE TX gain\n" @@ -134,6 +135,7 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------*/ #define CMDLINE_UEPARAMS_DESC { \ {"siml1", CONFIG_HLP_SIML1, PARAMFLAG_BOOL, iptr:&simL1flag, defintval:0, TYPE_INT, 0}, \ +{"U", CONFIG_HLP_NUMUE, 0, u8ptr:&NB_UE_INST, defuintval:1, TYPE_UINT, 0}, \ {"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:130, TYPE_DOUBLE, 0}, \ {"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ {"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ @@ -290,7 +292,7 @@ extern void kill_te_thread(PHY_VARS_eNB *); extern void RCConfig_sim(void); extern void init_ocm(double,double); -extern void init_ue_devices(void); +extern void init_ue_devices(PHY_VARS_UE *); PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 22ccdd4cc646535d9efe4779d3f0f15b382b1280..531436d5867882627dff4a3e9bc112225a754725 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -254,7 +254,7 @@ void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in, int timing_correcti for (inst=0;inst<nb_inst;inst++) { if (PHY_vars_UE_g[inst]==NULL) PHY_vars_UE_g[inst] = (PHY_VARS_UE**)calloc(1+MAX_NUM_CCs,sizeof(PHY_VARS_UE*)); - + LOG_I(PHY,"Allocating UE context %d\n",inst); if (simL1flag == 0) PHY_vars_UE_g[inst][0] = init_ue_vars(NULL,inst,0); else { @@ -307,7 +307,7 @@ void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in, int timing_correcti UE->frame_parms.nb_antennas_tx = nb_tx; UE->frame_parms.nb_antennas_rx = nb_rx; - if (simL1flag == 1) init_ue_devices(); + if (simL1flag == 1) init_ue_devices(UE); LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); init_UE_threads(inst); @@ -327,14 +327,6 @@ void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in, int timing_correcti } printf("UE threads created by %ld\n", gettid()); -#if 0 -#if defined(ENABLE_USE_MME) - extern volatile int start_UE; - while (start_UE == 0) { - sleep(1); - } -#endif -#endif } // Panos: Initiating all UEs within a single set of threads for PHY_STUB. Future extensions -> multiple diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 4b52b41c1f26511bf49c79c821ab7631f6245895..d2190a2995d15e64989e6d9a500a144de30ea8df 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -817,7 +817,11 @@ int main( int argc, char **argv ) get_options (); - + printf("Running with %d UE instances\n",NB_UE_INST); + if (NB_UE_INST > 1 && simL1flag != 1) { + printf("Running with more than 1 UE instance and simL1 is not active, this will result in undefined behaviour for now, exiting.\n"); + abort(); + } printf("NFAPI_MODE value: %d \n", nfapi_mode); @@ -970,7 +974,7 @@ int main( int argc, char **argv ) init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface); } else { - init_UE(1,eMBMS_active,uecap_xer_in,0,phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0], + init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0], frame_parms[0]->nb_antennas_rx, frame_parms[0]->nb_antennas_tx); } diff --git a/targets/RT/USER/rfsim.c b/targets/RT/USER/rfsim.c index 09b520d8d5d28aa100942899adbdd72ab44e0ee8..d8e5fbc825413812193020c54f60b98ed7ab2717 100644 --- a/targets/RT/USER/rfsim.c +++ b/targets/RT/USER/rfsim.c @@ -57,24 +57,7 @@ extern PHY_VARS_UE ***PHY_vars_UE_g; // put all of these in a common structure after -channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs]; -channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs]; -double r_re_DL[NUMBER_OF_UE_MAX][2][30720]; -double r_im_DL[NUMBER_OF_UE_MAX][2][30720]; -double r_re_UL[NUMBER_OF_eNB_MAX][2][30720]; -double r_im_UL[NUMBER_OF_eNB_MAX][2][30720]; -int RU_output_mask[NUMBER_OF_UE_MAX]; -int UE_output_mask[NUMBER_OF_RU_MAX]; -pthread_mutex_t RU_output_mutex[NUMBER_OF_UE_MAX]; -pthread_mutex_t UE_output_mutex[NUMBER_OF_RU_MAX]; -pthread_mutex_t subframe_mutex; -int subframe_ru_mask=0,subframe_UE_mask=0; -openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs]; -openair0_timestamp current_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs]; -openair0_timestamp last_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs]; -openair0_timestamp last_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs]; -double ru_amp[NUMBER_OF_RU_MAX]; -pthread_t rfsim_thread; +sim_t sim; void init_ru_devices(void); @@ -96,32 +79,11 @@ void wait_RUs(void) // copy frame parameters from RU to UEs for (i=0;i<NB_UE_INST;i++) { -/* - PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL = RC.ru[0]->frame_parms.N_RB_DL; - PHY_vars_UE_g[i][0]->frame_parms.N_RB_UL = RC.ru[0]->frame_parms.N_RB_UL; - PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_tx = 1; - PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_rx = 1; - // set initially to 2, it will be revised after initial synchronization - PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB = 2; - PHY_vars_UE_g[i][0]->frame_parms.tdd_config = 1; - PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq = RC.ru[0]->frame_parms.dl_CarrierFreq; - PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq = RC.ru[0]->frame_parms.ul_CarrierFreq; - PHY_vars_UE_g[i][0]->frame_parms.eutra_band = RC.ru[0]->frame_parms.eutra_band; - LOG_I(PHY,"Initializing UE %d frame parameters from RU information: N_RB_DL %d, p %d, dl_Carrierfreq %u, ul_CarrierFreq %u, eutra_band %d\n", - i, - PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL, - PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB, - PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq, - PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq, - PHY_vars_UE_g[i][0]->frame_parms.eutra_band); - -*/ - - current_UE_rx_timestamp[i][0] = RC.ru[0]->frame_parms.samples_per_tti + RC.ru[0]->frame_parms.ofdm_symbol_size + RC.ru[0]->frame_parms.nb_prefix_samples0; + sim.current_UE_rx_timestamp[i][0] = RC.ru[0]->frame_parms.samples_per_tti + RC.ru[0]->frame_parms.ofdm_symbol_size + RC.ru[0]->frame_parms.nb_prefix_samples0; } - for (int ru_id=0;ru_id<RC.nb_RU;ru_id++) current_ru_rx_timestamp[ru_id][0] = RC.ru[ru_id]->frame_parms.samples_per_tti; + for (int ru_id=0;ru_id<RC.nb_RU;ru_id++) sim.current_ru_rx_timestamp[ru_id][0] = RC.ru[ru_id]->frame_parms.samples_per_tti; printf("RUs are ready, let's go\n"); } @@ -153,7 +115,7 @@ void RCConfig_sim(void) { static int nframes = 100000; - AssertFatal(0 == pthread_create(&rfsim_thread, + AssertFatal(0 == pthread_create(&sim.rfsim_thread, NULL, rfsim_top, (void*)&nframes), ""); @@ -207,31 +169,31 @@ int ru_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void ** int subframe; int sample_count=0; - *ptimestamp = last_ru_rx_timestamp[ru_id][CC_id]; + *ptimestamp = sim.last_ru_rx_timestamp[ru_id][CC_id]; LOG_D(SIM,"RU_trx_read nsamps %d TS(%llu,%llu) => subframe %d\n",nsamps, - (unsigned long long)current_ru_rx_timestamp[ru_id][CC_id], - (unsigned long long)last_ru_rx_timestamp[ru_id][CC_id], + (unsigned long long)sim.current_ru_rx_timestamp[ru_id][CC_id], + (unsigned long long)sim.last_ru_rx_timestamp[ru_id][CC_id], (int)((*ptimestamp/RC.ru[ru_id]->frame_parms.samples_per_tti)%10)); // if we're at a subframe boundary generate UL signals for this ru while (sample_count<nsamps) { - while (current_ru_rx_timestamp[ru_id][CC_id]< - (nsamps+last_ru_rx_timestamp[ru_id][CC_id])) { - LOG_D(SIM,"RU: current TS %"PRIi64", last TS %"PRIi64", sleeping\n",current_ru_rx_timestamp[ru_id][CC_id],last_ru_rx_timestamp[ru_id][CC_id]); + while (sim.current_ru_rx_timestamp[ru_id][CC_id]< + (nsamps+sim.last_ru_rx_timestamp[ru_id][CC_id])) { + LOG_D(SIM,"RU: current TS %"PRIi64", last TS %"PRIi64", sleeping\n",sim.current_ru_rx_timestamp[ru_id][CC_id],sim.last_ru_rx_timestamp[ru_id][CC_id]); usleep(500); } - subframe = (last_ru_rx_timestamp[ru_id][CC_id]/RC.ru[ru_id]->frame_parms.samples_per_tti)%10; + subframe = (sim.last_ru_rx_timestamp[ru_id][CC_id]/RC.ru[ru_id]->frame_parms.samples_per_tti)%10; if (subframe_select(&RC.ru[ru_id]->frame_parms,subframe) != SF_DL || RC.ru[ru_id]->frame_parms.frame_type == FDD) { LOG_D(SIM,"RU_trx_read generating UL subframe %d (Ts %llu, current TS %llu)\n", subframe,(unsigned long long)*ptimestamp, - (unsigned long long)current_ru_rx_timestamp[ru_id][CC_id]); + (unsigned long long)sim.current_ru_rx_timestamp[ru_id][CC_id]); - do_UL_sig(UE2RU, + do_UL_sig(&sim, subframe, 0, // abstraction_flag &RC.ru[ru_id]->frame_parms, @@ -239,7 +201,7 @@ int ru_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void ** ru_id, CC_id); } - last_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti; + sim.last_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti; sample_count += RC.ru[ru_id]->frame_parms.samples_per_tti; } @@ -257,14 +219,14 @@ int UE_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void ** int read_size; int sptti = PHY_vars_UE_g[UE_id][CC_id]->frame_parms.samples_per_tti; - *ptimestamp = last_UE_rx_timestamp[UE_id][CC_id]; + *ptimestamp = sim.last_UE_rx_timestamp[UE_id][CC_id]; - LOG_D(SIM,"UE %d DL simulation 0: UE_trx_read nsamps %d TS %llu (%llu, offset %d) antenna %d\n", + LOG_D(PHY,"UE %d DL simulation 0: UE_trx_read nsamps %d TS %llu (%llu, offset %d) antenna %d\n", UE_id, nsamps, - (unsigned long long)current_UE_rx_timestamp[UE_id][CC_id], - (unsigned long long)last_UE_rx_timestamp[UE_id][CC_id], - (int)(last_UE_rx_timestamp[UE_id][CC_id]%sptti), + (unsigned long long)sim.current_UE_rx_timestamp[UE_id][CC_id], + (unsigned long long)sim.last_UE_rx_timestamp[UE_id][CC_id], + (int)(sim.last_UE_rx_timestamp[UE_id][CC_id]%sptti), cc); @@ -274,49 +236,49 @@ int UE_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void ** read_size = sptti; while (sample_count<nsamps) { - LOG_D(SIM,"UE %d: DL simulation 1: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]); - while (current_UE_rx_timestamp[UE_id][CC_id] < - (last_UE_rx_timestamp[UE_id][CC_id]+read_size)) { - LOG_D(SIM,"UE %d: DL simulation 2: UE_trx_read : current TS %"PRIi64", last TS %"PRIi64", sleeping\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]); + LOG_D(SIM,"UE %d: DL simulation 1: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,sim.current_UE_rx_timestamp[UE_id][CC_id],sim.last_UE_rx_timestamp[UE_id][CC_id]); + while (sim.current_UE_rx_timestamp[UE_id][CC_id] < + (sim.last_UE_rx_timestamp[UE_id][CC_id]+read_size)) { + LOG_D(SIM,"UE %d: DL simulation 2: UE_trx_read : current TS %"PRIi64", last TS %"PRIi64", sleeping\n",UE_id,sim.current_UE_rx_timestamp[UE_id][CC_id],sim.last_UE_rx_timestamp[UE_id][CC_id]); usleep(500); } - LOG_D(SIM,"UE %d: DL simulation 3: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]); + LOG_D(SIM,"UE %d: DL simulation 3: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,sim.current_UE_rx_timestamp[UE_id][CC_id],sim.last_UE_rx_timestamp[UE_id][CC_id]); // if we cross a subframe-boundary - subframe = (last_UE_rx_timestamp[UE_id][CC_id]/sptti)%10; + subframe = (sim.last_UE_rx_timestamp[UE_id][CC_id]/sptti)%10; // tell top-level we are busy - pthread_mutex_lock(&subframe_mutex); - subframe_UE_mask|=(1<<UE_id); - LOG_D(SIM,"Setting UE_id %d mask to busy (%d)\n",UE_id,subframe_UE_mask); - pthread_mutex_unlock(&subframe_mutex); + pthread_mutex_lock(&sim.subframe_mutex); + sim.subframe_UE_mask|=(1<<UE_id); + LOG_D(SIM,"Setting UE_id %d mask to busy (%d)\n",UE_id,sim.subframe_UE_mask); + pthread_mutex_unlock(&sim.subframe_mutex); LOG_D(PHY,"UE %d: DL simulation 4: UE_trx_read generating DL subframe %d (Ts %llu, current TS %llu,nsamps %d)\n", UE_id,subframe,(unsigned long long)*ptimestamp, - (unsigned long long)current_UE_rx_timestamp[UE_id][CC_id], + (unsigned long long)sim.current_UE_rx_timestamp[UE_id][CC_id], nsamps); LOG_D(SIM,"UE %d: DL simulation 5: Doing DL simulation for %d samples starting in subframe %d at offset %d\n", UE_id,nsamps,subframe, - (int)(last_UE_rx_timestamp[UE_id][CC_id]%sptti)); + (int)(sim.last_UE_rx_timestamp[UE_id][CC_id]%sptti)); - do_DL_sig(RU2UE, + do_DL_sig(&sim, subframe, - last_UE_rx_timestamp[UE_id][CC_id]%sptti, + sim.last_UE_rx_timestamp[UE_id][CC_id]%sptti, sptti, 0, //abstraction_flag, &PHY_vars_UE_g[UE_id][CC_id]->frame_parms, UE_id, CC_id); - LOG_D(SIM,"UE %d: DL simulation 6: UE_trx_read @ TS %"PRIi64" (%"PRIi64")=> frame %d, subframe %d\n", - UE_id, current_UE_rx_timestamp[UE_id][CC_id], - last_UE_rx_timestamp[UE_id][CC_id], - (int)((last_UE_rx_timestamp[UE_id][CC_id]/(sptti*10))&1023), + LOG_D(PHY,"UE %d: DL simulation 6: UE_trx_read @ TS %"PRIi64" (%"PRIi64")=> frame %d, subframe %d\n", + UE_id, sim.current_UE_rx_timestamp[UE_id][CC_id], + sim.last_UE_rx_timestamp[UE_id][CC_id], + (int)((sim.last_UE_rx_timestamp[UE_id][CC_id]/(sptti*10))&1023), subframe); - last_UE_rx_timestamp[UE_id][CC_id] += read_size; + sim.last_UE_rx_timestamp[UE_id][CC_id] += read_size; sample_count += read_size; @@ -335,25 +297,25 @@ int ru_trx_write(openair0_device *device,openair0_timestamp timestamp, void **bu LTE_DL_FRAME_PARMS *frame_parms = &RC.ru[ru_id]->frame_parms; - pthread_mutex_lock(&subframe_mutex); - LOG_D(SIM,"[TXPATH] ru_trx_write: RU %d mask %d\n",ru_id,subframe_ru_mask); - pthread_mutex_unlock(&subframe_mutex); + pthread_mutex_lock(&sim.subframe_mutex); + LOG_D(SIM,"[TXPATH] ru_trx_write: RU %d mask %d\n",ru_id,sim.subframe_ru_mask); + pthread_mutex_unlock(&sim.subframe_mutex); // compute amplitude of TX signal from first symbol in subframe // note: assumes that the packet is an entire subframe - ru_amp[ru_id] = 0; + sim.ru_amp[ru_id] = 0; for (int aa=0; aa<RC.ru[ru_id]->nb_tx; aa++) { - ru_amp[ru_id] += (double)signal_energy((int32_t*)buff[aa],frame_parms->ofdm_symbol_size)/(12*frame_parms->N_RB_DL); + sim.ru_amp[ru_id] += (double)signal_energy((int32_t*)buff[aa],frame_parms->ofdm_symbol_size)/(12*frame_parms->N_RB_DL); } - ru_amp[ru_id] = sqrt(ru_amp[ru_id]); + sim.ru_amp[ru_id] = sqrt(sim.ru_amp[ru_id]); - LOG_D(PHY,"Setting amp for RU %d to %f (%d)\n",ru_id,ru_amp[ru_id], dB_fixed((double)signal_energy((int32_t*)buff[0],frame_parms->ofdm_symbol_size))); + LOG_D(PHY,"Setting amp for RU %d to %f (%d)\n",ru_id,sim.ru_amp[ru_id], dB_fixed((double)signal_energy((int32_t*)buff[0],frame_parms->ofdm_symbol_size))); // tell top-level we are done - pthread_mutex_lock(&subframe_mutex); - subframe_ru_mask|=(1<<ru_id); + pthread_mutex_lock(&sim.subframe_mutex); + sim.subframe_ru_mask|=(1<<ru_id); LOG_D(SIM,"Setting RU %d to busy\n",ru_id); - pthread_mutex_unlock(&subframe_mutex); + pthread_mutex_unlock(&sim.subframe_mutex); return(nsamps); } @@ -385,30 +347,25 @@ void init_ru_devices(){ ru->rfdevice.trx_stop_func = ru_trx_stop; ru->rfdevice.trx_set_freq_func = ru_trx_set_freq; ru->rfdevice.trx_set_gains_func = ru_trx_set_gains; - last_ru_rx_timestamp[ru_id][0] = 0; + sim.last_ru_rx_timestamp[ru_id][0] = 0; } } -void init_ue_devices() { - - AssertFatal(PHY_vars_UE_g!=NULL,"Top-level structure for UE is null\n"); - for (int UE_id=0;UE_id<NB_UE_INST;UE_id++) { - AssertFatal(PHY_vars_UE_g[UE_id]!=NULL,"UE %d context is not allocated\n",UE_id); - printf("Initializing UE %d\n",UE_id); - for (int CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) { - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.Mod_id = UE_id; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.CC_id = CC_id; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_start_func = UE_trx_start; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_read_func = UE_trx_read; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_write_func = UE_trx_write; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_end_func = UE_trx_end; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_stop_func = UE_trx_stop; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_set_freq_func = UE_trx_set_freq; - PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_set_gains_func = UE_trx_set_gains; - last_UE_rx_timestamp[UE_id][CC_id] = 0; - } - } +void init_ue_devices(PHY_VARS_UE *UE) { + + AssertFatal(UE!=NULL,"UE context is not allocated\n"); + printf("Initializing UE %d.%d\n",UE->Mod_id,UE->CC_id); + UE->rfdevice.Mod_id = UE->Mod_id; + UE->rfdevice.CC_id = UE->CC_id; + UE->rfdevice.trx_start_func = UE_trx_start; + UE->rfdevice.trx_read_func = UE_trx_read; + UE->rfdevice.trx_write_func = UE_trx_write; + UE->rfdevice.trx_end_func = UE_trx_end; + UE->rfdevice.trx_stop_func = UE_trx_stop; + UE->rfdevice.trx_set_freq_func = UE_trx_set_freq; + UE->rfdevice.trx_set_gains_func = UE_trx_set_gains; + sim.last_UE_rx_timestamp[UE->Mod_id][UE->CC_id] = 0; } void init_ocm(double snr_dB,double sinr_dB) @@ -430,7 +387,7 @@ void init_ocm(double snr_dB,double sinr_dB) LOG_I(PHY,"Initializing channel descriptors (RU %d, UE %d) for N_RB_DL %d\n",ru_id,UE_id, RC.ru[ru_id]->frame_parms.N_RB_DL); - RU2UE[ru_id][UE_id][CC_id] = + sim.RU2UE[ru_id][UE_id][CC_id] = new_channel_desc_scm(RC.ru[ru_id]->nb_tx, PHY_vars_UE_g[UE_id][CC_id]->frame_parms.nb_antennas_rx, AWGN, @@ -439,11 +396,11 @@ void init_ocm(double snr_dB,double sinr_dB) 0.0, 0, 0); - random_channel(RU2UE[ru_id][UE_id][CC_id],0); + random_channel(sim.RU2UE[ru_id][UE_id][CC_id],0); LOG_D(OCM,"[SIM] Initializing channel (%s) from UE %d to ru %d\n", "AWGN",UE_id, ru_id); - UE2RU[UE_id][ru_id][CC_id] = + sim.UE2RU[UE_id][ru_id][CC_id] = new_channel_desc_scm(PHY_vars_UE_g[UE_id][CC_id]->frame_parms.nb_antennas_tx, RC.ru[ru_id]->nb_rx, AWGN, @@ -453,24 +410,24 @@ void init_ocm(double snr_dB,double sinr_dB) 0, 0); - random_channel(UE2RU[UE_id][ru_id][CC_id],0); + random_channel(sim.UE2RU[UE_id][ru_id][CC_id],0); // to make channel reciprocal uncomment following line instead of previous. However this only works for SISO at the moment. For MIMO the channel would need to be transposed. //UE2RU[UE_id][ru_id] = RU2UE[ru_id][UE_id]; - AssertFatal(RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id); - AssertFatal(UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id); + AssertFatal(sim.RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id); + AssertFatal(sim.UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id); //pathloss: -132.24 dBm/15kHz RE + target SNR - eNB TX power per RE if (ru_id == (UE_id % RC.nb_RU)) { - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; } else { - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; } LOG_I(OCM,"Path loss from eNB %d to UE %d (CCid %d)=> %f dB (eNB TX %d, SNR %f)\n",ru_id,UE_id,CC_id, - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB, + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB, RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower,snr_dB); @@ -490,19 +447,19 @@ void update_ocm(double snr_dB,double sinr_dB) for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - AssertFatal(RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id); - AssertFatal(UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id); + AssertFatal(sim.RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id); + AssertFatal(sim.UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id); //pathloss: -132.24 dBm/15kHz RE + target SNR - eNB TX power per RE if (ru_id == (UE_id % RC.nb_RU)) { - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; } else { - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; - UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; + sim.UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower; } LOG_D(OCM,"Path loss from eNB %d to UE %d (CCid %d)=> %f dB (eNB TX %d, SNR %f)\n",ru_id,UE_id,CC_id, - RU2UE[ru_id][UE_id][CC_id]->path_loss_dB, + sim.RU2UE[ru_id][UE_id][CC_id]->path_loss_dB, RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower,snr_dB); } @@ -516,13 +473,13 @@ void init_channel_vars(void) int i; - memset(RU_output_mask,0,sizeof(int)*NUMBER_OF_UE_MAX); + memset(sim.RU_output_mask,0,sizeof(int)*NUMBER_OF_UE_MAX); for (i=0;i<NB_UE_INST;i++) - pthread_mutex_init(&RU_output_mutex[i],NULL); + pthread_mutex_init(&sim.RU_output_mutex[i],NULL); - memset(UE_output_mask,0,sizeof(int)*NUMBER_OF_RU_MAX); + memset(sim.UE_output_mask,0,sizeof(int)*NUMBER_OF_RU_MAX); for (i=0;i<RC.nb_RU;i++) - pthread_mutex_init(&UE_output_mutex[i],NULL); + pthread_mutex_init(&sim.UE_output_mutex[i],NULL); } @@ -544,32 +501,32 @@ void *rfsim_top(void *n_frames) { int all_done=0; while (all_done==0) { - pthread_mutex_lock(&subframe_mutex); + pthread_mutex_lock(&sim.subframe_mutex); - int subframe_ru_mask_local = (subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_UL) ? subframe_ru_mask : ((1<<RC.nb_RU)-1); - int subframe_UE_mask_local = (RC.ru[0]->frame_parms.frame_type == FDD || subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_DL) ? subframe_UE_mask : ((1<<NB_UE_INST)-1); - pthread_mutex_unlock(&subframe_mutex); + int subframe_ru_mask_local = (subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_UL) ? sim.subframe_ru_mask : ((1<<RC.nb_RU)-1); + int subframe_UE_mask_local = (RC.ru[0]->frame_parms.frame_type == FDD || subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_DL) ? sim.subframe_UE_mask : ((1<<NB_UE_INST)-1); + pthread_mutex_unlock(&sim.subframe_mutex); LOG_D(SIM,"Frame %d, Subframe %d, NB_RU %d, NB_UE %d: Checking masks %x,%x\n",frame,sf,RC.nb_RU,NB_UE_INST,subframe_ru_mask_local,subframe_UE_mask_local); if ((subframe_ru_mask_local == ((1<<RC.nb_RU)-1)) && (subframe_UE_mask_local == ((1<<NB_UE_INST)-1))) all_done=1; - else usleep(100); + else usleep(1500); } //clear subframe masks for next round - pthread_mutex_lock(&subframe_mutex); - subframe_ru_mask=0; - subframe_UE_mask=0; - pthread_mutex_unlock(&subframe_mutex); + pthread_mutex_lock(&sim.subframe_mutex); + sim.subframe_ru_mask=0; + sim.subframe_UE_mask=0; + pthread_mutex_unlock(&sim.subframe_mutex); // increment timestamps for (int ru_id=0;ru_id<RC.nb_RU;ru_id++) { - current_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti; - LOG_D(SIM,"RU %d/%d: TS %"PRIi64"\n",ru_id,CC_id,current_ru_rx_timestamp[ru_id][CC_id]); + sim.current_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti; + LOG_D(SIM,"RU %d/%d: TS %"PRIi64"\n",ru_id,CC_id,sim.current_ru_rx_timestamp[ru_id][CC_id]); } for (int UE_inst = 0; UE_inst<NB_UE_INST;UE_inst++) { - current_UE_rx_timestamp[UE_inst][CC_id] += PHY_vars_UE_g[UE_inst][CC_id]->frame_parms.samples_per_tti; - LOG_D(SIM,"UE %d/%d: TS %"PRIi64"\n",UE_inst,CC_id,current_UE_rx_timestamp[UE_inst][CC_id]); + sim.current_UE_rx_timestamp[UE_inst][CC_id] += PHY_vars_UE_g[UE_inst][CC_id]->frame_parms.samples_per_tti; + LOG_D(SIM,"UE %d/%d: TS %"PRIi64"\n",UE_inst,CC_id,sim.current_UE_rx_timestamp[UE_inst][CC_id]); } if (oai_exit == 1) return((void*)NULL); } diff --git a/targets/RT/USER/rfsim.h b/targets/RT/USER/rfsim.h index dca46e005b0526427c1668bb53e37c8031af17fc..47c542ce8192aa809478baaf473148712320af6d 100644 --- a/targets/RT/USER/rfsim.h +++ b/targets/RT/USER/rfsim.h @@ -18,11 +18,19 @@ * For more information about the OpenAirInterface (OAI) Software Alliance: * contact@openairinterface.org */ - +#ifndef __SIM__H__ +#define __SIM__H__ #include "lte-softmodem.h" +#include "openair1/SIMULATION/TOOLS/sim.h" +#include "platform_constants.h" +#include "common/ran_context.h" +#include "PHY/defs_UE.h" +#include "PHY/defs_eNB.h" void init_ocm(double snr_dB,double sinr_dB); void update_ocm(double snr_dB,double sinr_dB); void init_channel_vars(void); + +#endif