From df18f5933adba355e114e44b0b09b92f8ea4d5a3 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 18 Sep 2018 01:38:02 -0700 Subject: [PATCH 1/4] adding first version of the pbchsim. so far only freq domain signal generated. not all regression tests done (had to touch some header files) --- cmake_targets/CMakeLists.txt | 12 +- cmake_targets/build_oai | 8 +- .../CMakeLists.txt | 1 + common/utils/LOG/log.h | 10 +- openair1/PHY/INIT/nr_init.c | 6 +- openair1/PHY/NR_TRANSPORT/nr_pbch.c | 3 +- openair1/PHY/defs_NR.h | 6 +- openair1/SCHED_NR/sched_nr.h | 1 + openair1/SIMULATION/NR_PHY/pbchsim.c | 462 ++++++++++++++++++ .../NR_UE_PHY/unit_tests/src/pbch_test.c | 19 +- openair1/SIMULATION/TOOLS/sim.h | 2 +- targets/RT/USER/nr-softmodem.c | 2 - 12 files changed, 502 insertions(+), 30 deletions(-) rename cmake_targets/{lte-simulators => phy_simulators}/CMakeLists.txt (94%) create mode 100644 openair1/SIMULATION/NR_PHY/pbchsim.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index c0a17fe18a..a3557762fd 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -543,7 +543,9 @@ set (CONFIG_SOURCES ) set (CONFIG_LIBCONFIG_SOURCES ${CONFIG_ROOTDIR}/libconfig/config_libconfig.c - ) + ) +add_library(CONFIG_LIB ${CONFIG_SOURCES}) +set(CONFIG_LIBRARIES CONFIG_LIB) add_library(params_libconfig MODULE ${CONFIG_LIBCONFIG_SOURCES} ) target_link_libraries(params_libconfig config) # shared library loader @@ -2517,10 +2519,14 @@ target_link_libraries (dlsim_tm4 ) add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c) -target_link_libraries(polartest m SIMU PHY PHY_NR PHY_COMMON -lm ${ATLAS_LIBRARIES}) +target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) add_executable(ldpctest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c) -target_link_libraries(ldpctest m SIMU PHY PHY_NR ${ATLAS_LIBRARIES}) +target_link_libraries(ldpctest SIMU PHY PHY_NR m ${ATLAS_LIBRARIES}) + +add_executable(nr_pbchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pbchsim.c ) +target_link_libraries(nr_pbchsim -Wl,--start-group UTIL SIMU PHY PHY_COMMON PHY_NR SCHED_NR_LIB ${CONFIG_LIBRARIES} -Wl,--end-group m pthread dl ${ATLAS_LIBRARIES}) + foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 9a83d784ce..9c90166e52 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -671,7 +671,7 @@ function main() { fi if [ "$SIMUS_PHY" = "1" -o "$SIMUS_CORE" = "1" ] ; then - cd $OPENAIR_DIR/cmake_targets/lte-simulators + cd $OPENAIR_DIR/cmake_targets/phy_simulators [ "$CLEAN" = "1" ] && rm -rf build mkdir -p build cd build @@ -687,11 +687,11 @@ function main() { simlist="dlsim ulsim polartest ldpctest" for f in $simlist ; do compilations \ - lte-simulators $f \ + phy_simulators $f \ $f $dbin/$f.$REL done compilations \ - lte-simulators coding \ + phy_simulators coding \ libcoding.so $dbin/libcoding.so fi @@ -703,7 +703,7 @@ function main() { simlist="secu_knas_encrypt_eia1 secu_kenb aes128_ctr_encrypt aes128_ctr_decrypt secu_knas_encrypt_eea2 secu_knas secu_knas_encrypt_eea1 kdf aes128_cmac_encrypt secu_knas_encrypt_eia2" for f in $simlist ; do compilations \ - lte-simulators test_$f \ + phy_simulators test_$f \ test_$f $dbin/test_$f.$REL done fi diff --git a/cmake_targets/lte-simulators/CMakeLists.txt b/cmake_targets/phy_simulators/CMakeLists.txt similarity index 94% rename from cmake_targets/lte-simulators/CMakeLists.txt rename to cmake_targets/phy_simulators/CMakeLists.txt index b7e83a92a0..83b292eed5 100644 --- a/cmake_targets/lte-simulators/CMakeLists.txt +++ b/cmake_targets/phy_simulators/CMakeLists.txt @@ -9,4 +9,5 @@ set(MU_RECIEVER False) set(NAS_UE False) set(MESSAGE_CHART_GENERATOR False) set(RRC_ASN1_VERSION "Rel14") +set(T_TRACER False) include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt) diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 3864ad53c7..f9025adbe1 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -345,10 +345,10 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int /* define variable only used in LOG macro's */ # define LOG_VAR(A,B) A B # else /* T_TRACER: remove all debugging and tracing messages, except errors */ -# define LOG_I(c, x...) /* */ -# define LOG_W(c, x...) /* */ -# define LOG_E(c, x...) /* */ -# define LOG_D(c, x...) /* */ +# define LOG_I(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)/* */ +# define LOG_W(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ; } while(0)/* */ +# define LOG_E(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ; } while(0)/* */ +# define LOG_D(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ; } while(0)/* */ # define LOG_T(c, x...) /* */ # define LOG_F(c, x...) /* */ # define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) @@ -356,7 +356,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int # define LOG_DEBUG_END } # define LOG_M_BEGIN(D) if (0) { # define LOG_M_END } -# define LOG_M(file, vector, data, len, dec, format) +# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) # define LOG_VAR(A,B) # endif /* T_TRACER */ /* avoid warnings for variables only used in LOG macro's but set outside debug section */ diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 1d087d118f..5e9ec52623 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -298,7 +298,7 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB) free_and_zero(srs_vars[UE_id].srs_ch_estimates_time); } //UE_id - free_ul_ref_sigs(); + //free_ul_ref_sigs(); for (UE_id=0; UE_idframe_parms; nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config; @@ -370,7 +370,7 @@ void install_schedule_handlers(IF_Module_t *if_inst) gNB->configured = 1; LOG_I(PHY,"gNB configured\n"); -}*/ +} void nr_phy_config_request(NR_PHY_Config_t *phy_config) diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c index 1e761ea0bb..70cd80c47e 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c @@ -39,7 +39,8 @@ //#define DEBUG_PBCH_ENCODING //#define DEBUG_PBCH_DMRS -extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT]; +//extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT]; +#include "PHY/NR_REFSIG/nr_mod_table.h" int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, int32_t **txdataF, diff --git a/openair1/PHY/defs_NR.h b/openair1/PHY/defs_NR.h index b705ef4c2e..80d3cd978a 100644 --- a/openair1/PHY/defs_NR.h +++ b/openair1/PHY/defs_NR.h @@ -19,9 +19,10 @@ * contact@openairinterface.org */ -/*#ifndef __INIT_DEFS_NR__H__ +#ifndef __INIT_DEFS_NR__H__ #define __INIT_DEFS_NR__H__ +/* #define _GNU_SOURCE #include #include @@ -44,6 +45,7 @@ #include "defs.h" #include "assertions.h"*/ #include "impl_defs_nr.h" +#include "defs_nr_common.h" #define MAX_NUM_SUBCARRIER_SPACING 5 @@ -58,6 +60,7 @@ #define MOD_TABLE_SIZE_SHORT 6 #define MOD_TABLE_BPSK_OFFSET 1 + /* typedef enum { NR_MU_0=0, NR_MU_1, @@ -93,6 +96,7 @@ typedef struct { uint32_t samples_per_frame_wCP; } NR_DL_FRAME_PARMS; + */ /// Top-level PHY Data Structure for gNB typedef struct PHY_VARS_gNB_s { diff --git a/openair1/SCHED_NR/sched_nr.h b/openair1/SCHED_NR/sched_nr.h index 79cc0c2ae0..8c8ef9007d 100644 --- a/openair1/SCHED_NR/sched_nr.h +++ b/openair1/SCHED_NR/sched_nr.h @@ -36,6 +36,7 @@ lte_subframe_t nr_subframe_select (nfapi_nr_config_request_t *cfg, unsigned char subframe); void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp); void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, gNB_rxtx_proc_t *proc, int do_meas); +void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe); void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx); void nr_feptx_ofdm(RU_t *ru); void nr_feptx_ofdm_2thread(RU_t *ru); diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c new file mode 100644 index 0000000000..841be57e18 --- /dev/null +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -0,0 +1,462 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include +#include +#include +#include +#include +#include + +#include "SIMULATION/TOOLS/sim.h" +#include "SIMULATION/RF/rf.h" +#include "PHY/types.h" +#include "PHY/defs_nr_common.h" +#include "PHY/defs_nr_UE.h" +#include "PHY/defs_gNB.h" + +#include "PHY/INIT/phy_init.h" +#include "SCHED_NR/sched_nr.h" + +#include "common/ran_context.h" + +PHY_VARS_gNB *gNB; +PHY_VARS_NR_UE *UE; +RAN_CONTEXT_t RC; + + +double cpuf; + +// dummy functions +int nfapi_mode=0; +int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { return(0);} +int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { return(0); } + +int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { return(0); } + +int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { return(0); } + +int oai_nfapi_nr_dl_config_req(nfapi_nr_dl_config_request_t *dl_config_req) {return(0);} + +uint32_t from_earfcn(int eutra_bandP,uint32_t dl_earfcn) {return(0);} +int32_t get_uldl_offset(int eutra_bandP) {return(0);} + +NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} + +void exit_fun(const char *s) { exit(-1); } + +int main(int argc, char **argv) +{ + + char c; + + int i,l,aa; + double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1; + uint8_t snr1set=0; + int **txdata,**txdata1,**txdata2; + double **s_re,**s_im,**s_re1,**s_im1,**s_re2,**s_im2,**r_re,**r_im,**r_re1,**r_im1,**r_re2,**r_im2; + double iqim = 0.0; + unsigned char pbch_pdu[6]; + // int sync_pos, sync_pos_slot; + // FILE *rx_frame_file; + FILE *output_fd = NULL; + uint8_t write_output_file=0; + //int result; + int freq_offset; + // int subframe_offset; + // char fname[40], vname[40]; + int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti; + uint8_t transmission_mode = 1,n_tx=1,n_rx=1; + uint16_t Nid_cell=0; + + int n_frames=1; + channel_desc_t *gNB2UE; + uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; + uint8_t extended_prefix_flag=0; + int8_t interf1=-21,interf2=-21; + + FILE *input_fd=NULL,*pbch_file_fd=NULL; + char input_val_str[50],input_val_str2[50]; + // double input_val1,input_val2; + // uint16_t amask=0; + uint8_t frame_mod4,num_pdcch_symbols = 0; + uint16_t NB_RB=25; + + SCM_t channel_model=AWGN;//Rayleigh1_anticorr; + + //DCI_ALLOC_t dci_alloc[8]; + uint8_t abstraction_flag=0;//,calibration_flag=0; + double pbch_sinr; + int pbch_tx_ant; + uint8_t N_RB_DL=106,mu=1; + + unsigned char frame_type = 0; + unsigned char pbch_phase = 0; + + int frame=0,subframe=0; + int frame_length_complex_samples; + int frame_length_complex_samples_no_prefix; + NR_DL_FRAME_PARMS *frame_parms; + + cpuf = get_cpu_freq_GHz(); + + if ( load_configmodule(argc,argv) == 0) { + exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); + } + + logInit(); + + while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:dP:")) != -1) { + switch (c) { + case 'f': + write_output_file=1; + output_fd = fopen(optarg,"w"); + + if (output_fd==NULL) { + printf("Error opening %s\n",optarg); + exit(-1); + } + + break; + + case 'd': + frame_type = 1; + break; + + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; + + case 'B': + channel_model=SCM_B; + break; + + case 'C': + channel_model=SCM_C; + break; + + case 'D': + channel_model=SCM_D; + break; + + case 'E': + channel_model=EPA; + break; + + case 'F': + channel_model=EVA; + break; + + case 'G': + channel_model=ETU; + break; + + default: + msg("Unsupported channel model!\n"); + exit(-1); + } + + break; + + case 'i': + interf1=atoi(optarg); + break; + + case 'j': + interf2=atoi(optarg); + break; + + case 'n': + n_frames = atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; + + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; + + /* + case 't': + Td= atof(optarg); + break; + */ + case 'p': + extended_prefix_flag=1; + break; + + /* + case 'r': + ricean_factor = pow(10,-.1*atof(optarg)); + if (ricean_factor>1) { + printf("Ricean factor must be between 0 and 1\n"); + exit(-1); + } + break; + */ + case 'x': + transmission_mode=atoi(optarg); + + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } + + break; + + case 'y': + n_tx=atoi(optarg); + + if ((n_tx==0) || (n_tx>2)) { + msg("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } + + break; + + case 'z': + n_rx=atoi(optarg); + + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } + + break; + + case 'A': + abstraction_flag=1; + ntrials=10000; + msg("Running Abstraction test\n"); + pbch_file_fd=fopen(optarg,"r"); + + if (pbch_file_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } + + break; + + // case 'C': + // calibration_flag=1; + // msg("Running Abstraction calibration for Bias removal\n"); + // break; + case 'N': + Nid_cell = atoi(optarg); + break; + + case 'R': + N_RB_DL = atoi(optarg); + break; + + case 'F': + input_fd = fopen(optarg,"r"); + + if (input_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } + + break; + + case 'P': + pbch_phase = atoi(optarg); + + if (pbch_phase>3) + printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); + + break; + + default: + case 'h': + printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", + argv[0]); + printf("-h This message\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; + } + } + + s_re = malloc(2*sizeof(double*)); + s_im = malloc(2*sizeof(double*)); + s_re1 = malloc(2*sizeof(double*)); + s_im1 = malloc(2*sizeof(double*)); + s_re2 = malloc(2*sizeof(double*)); + s_im2 = malloc(2*sizeof(double*)); + r_re = malloc(2*sizeof(double*)); + r_im = malloc(2*sizeof(double*)); + r_re1 = malloc(2*sizeof(double*)); + r_im1 = malloc(2*sizeof(double*)); + r_re2 = malloc(2*sizeof(double*)); + r_im2 = malloc(2*sizeof(double*)); + + gNB2UE = new_channel_desc_scm(n_tx, + n_rx, + channel_model, + 61.44e6, //N_RB2sampling_rate(N_RB_DL), + 40e6, //N_RB2channel_bandwidth(N_RB_DL), + 0, + 0, + 0); + + if (gNB2UE==NULL) { + msg("Problem generating channel model. Exiting.\n"); + exit(-1); + } + + RC.gNB = (PHY_VARS_gNB***) malloc(sizeof(PHY_VARS_gNB **)); + RC.gNB[0] = (PHY_VARS_gNB**) malloc(sizeof(PHY_VARS_gNB *)); + RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB)); + gNB = RC.gNB[0][0]; + frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH) + + //NR_PHY_Config_t *phy_config = malloc(sizeof(NR_PHY_Config_t)); + nr_phy_config_request_sim(gNB); + phy_init_nr_gNB(gNB,0,0); + + frame_length_complex_samples = frame_parms->samples_per_subframe; + frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP; + + for (i=0; i<2; i++) { + + s_re[i] = malloc(frame_length_complex_samples*sizeof(double)); + bzero(s_re[i],frame_length_complex_samples*sizeof(double)); + s_im[i] = malloc(frame_length_complex_samples*sizeof(double)); + bzero(s_im[i],frame_length_complex_samples*sizeof(double)); + + r_re[i] = malloc(frame_length_complex_samples*sizeof(double)); + bzero(r_re[i],frame_length_complex_samples*sizeof(double)); + r_im[i] = malloc(frame_length_complex_samples*sizeof(double)); + bzero(r_im[i],frame_length_complex_samples*sizeof(double)); + } + + + if (pbch_file_fd!=NULL) { + load_pbch_desc(pbch_file_fd); + } + + if (input_fd==NULL) { + nr_common_signal_procedures (gNB,frame,subframe); + } + + LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); + + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1); + + + + + // multipath channel + /* + for (i=0; inb_antennas_tx; aa++) { + s_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); + s_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); + } + } + */ + + for (SNR=snr0; SNRframe_parms.ofdm_symbol_size/(double)(12*NB_RB)) - SNR; + + if (n_frames==1) + printf("sigma2_dB %f (SNR %f dB) tx_lev_dB %f,%f,%f\n",sigma2_dB,SNR, + 10*log10((double)tx_lev), + 10*log10((double)tx_lev1), + 10*log10((double)tx_lev2)); + + //AWGN + sigma2 = pow(10,sigma2_dB/10); + + + //printf("n_trial %d\n",n_trials); + for (i=0; inb_antennas_rx; aa++) { + + ((short*) UE->common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + } + } + + } //noise trials + + } // NSR + + for (i=0; i<2; i++) { + free(s_re[i]); + free(s_im[i]); + free(r_re[i]); + free(r_im[i]); + } + + free(s_re); + free(s_im); + free(r_re); + free(r_im); + + + if (write_output_file) + fclose(output_fd); + + return(n_errors); + +} + + + diff --git a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c index f1913f0371..fc5360848c 100644 --- a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c +++ b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c @@ -39,9 +39,10 @@ typedef int nfapi_nr_pfcch_commonSearchSpaces_t; #include "../nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h" #include "PHY/defs_nr_UE.h" -#include "PHY/INIT/init_extern.h" #include "PHY/phy_extern_nr_ue.h" -#include "PHY/NR_TRANSPORT/nr_transport.h" +#include "PHY/INIT/init_extern.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "PHY/NR_REFSIG/ss_pbch_nr.h" #include "PHY/NR_REFSIG/pss_nr.h" @@ -222,7 +223,7 @@ void set_sequence_sss(PHY_VARS_NR_UE *PHY_vars_UE, int offset, int slot_offset) } #else - insert_sss_nr(&tmp, frame_parms); + insert_sss_nr(tmp, frame_parms); #endif } @@ -393,7 +394,7 @@ int main(int argc, char *argv[]) int size_test_position; /* this is a pointer to the function in charge of the test */ - int (*p_test_synchro_pss_sss)(PHY_VARS_NR_UE *PHY_vars_UE, int position_symbol, int sequence_number, test_t *test) = test_synchro_pss_sss; + int (*p_test_synchro_pss_sss)(PHY_VARS_NR_UE *PHY_vars_UE, int position_symbol, int sequence_number) = test_synchro_pss_sss_nr; #if 0 int Nid_cell[] = { (3*0+0), (3*71+0), (3*21+2), (3*21+2), (3*55+1), (3*111+2) }; @@ -413,21 +414,19 @@ int main(int argc, char *argv[]) size_test_position = sizeof(test_position)/sizeof(int); printf("***********************************\n"); - printf(" %s Test NR synchronisation \n", test.test_current); + printf(" %s Test NR synchroisation \n", test.test_current); printf("***********************************\n"); for (unsigned int index = 0; index < (sizeof(Nid_cell)/sizeof(int)); index++) { - PHY_vars_eNB->frame_parms.Nid_cell = Nid_cell[index]; - - Nid2 = GET_NID2(PHY_vars_eNB->frame_parms.Nid_cell); - Nid1 = GET_NID1(PHY_vars_eNB->frame_parms.Nid_cell); + Nid2 = GET_NID2(Nid_cell[index]); + Nid1 = GET_NID1(Nid_cell[index]); for (int position = 0; position < size_test_position; position++) { PHY_vars_UE->frame_parms.Nid_cell = (3 * N_ID_1_NUMBER) + N_ID_2_NUMBER; /* set to unvalid value */ - decoded_pbch = (*p_test_synchro_pss_sss)(PHY_vars_UE, test_position[position], Nid2, &test); /* return phase index which gives phase error from an array */ + decoded_pbch = (*p_test_synchro_pss_sss)(PHY_vars_UE, test_position[position], Nid2); /* return phase index which gives phase error from an array */ test.number_of_tests++; printf("\n%s ", test.test_current); diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h index bde7b92506..1cfc096a33 100644 --- a/openair1/SIMULATION/TOOLS/sim.h +++ b/openair1/SIMULATION/TOOLS/sim.h @@ -398,7 +398,7 @@ void multipath_tv_channel(channel_desc_t *desc, double N_RB2sampling_rate(uint16_t N_RB); double N_RB2channel_bandwidth(uint16_t N_RB); -#include "targets/RT/USER/rfsim.h" +//#include "targets/RT/USER/rfsim.h" void do_DL_sig(sim_t *sim, uint16_t subframe, diff --git a/targets/RT/USER/nr-softmodem.c b/targets/RT/USER/nr-softmodem.c index fa295e2894..6a741bf856 100644 --- a/targets/RT/USER/nr-softmodem.c +++ b/targets/RT/USER/nr-softmodem.c @@ -94,8 +94,6 @@ unsigned short config_frames[4] = {2,9,11,13}; // current status is that every UE has a DL scope for a SINGLE eNB (gnb_id=0) // at eNB 0, an UL scope for every UE -short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,23170,23170,-23170,-23170,23170,23170,23170,-23170,-23170,23170,-23170,-23170}; - FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX]; FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; From 0c66eb812009e71fa74b79f3d09706ab0ae2886b Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Thu, 20 Sep 2018 02:37:36 -0700 Subject: [PATCH 2/4] adding OFDM modulation --- cmake_targets/CMakeLists.txt | 2 +- openair1/PHY/INIT/nr_init.c | 2 +- openair1/PHY/MODULATION/modulation_common.h | 2 + openair1/PHY/NR_REFSIG/nr_dmrs_rx.c | 2 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 142 +++++++++++--------- 5 files changed, 84 insertions(+), 66 deletions(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index a3557762fd..4af5bf82f4 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2525,7 +2525,7 @@ add_executable(ldpctest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c) target_link_libraries(ldpctest SIMU PHY PHY_NR m ${ATLAS_LIBRARIES}) add_executable(nr_pbchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pbchsim.c ) -target_link_libraries(nr_pbchsim -Wl,--start-group UTIL SIMU PHY PHY_COMMON PHY_NR SCHED_NR_LIB ${CONFIG_LIBRARIES} -Wl,--end-group m pthread dl ${ATLAS_LIBRARIES}) +target_link_libraries(nr_pbchsim -Wl,--start-group UTIL SIMU PHY PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB ${CONFIG_LIBRARIES} -Wl,--end-group m pthread dl ${ATLAS_LIBRARIES}) foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 5e9ec52623..94486c48e9 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -92,7 +92,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, int i, UE_id; - LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured", gNB->Mod_id, __FUNCTION__); + LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__); gNB->total_dlsch_bitrate = 0; gNB->total_transmitted_bits = 0; diff --git a/openair1/PHY/MODULATION/modulation_common.h b/openair1/PHY/MODULATION/modulation_common.h index 2ac0dc23b3..f550eeca5f 100644 --- a/openair1/PHY/MODULATION/modulation_common.h +++ b/openair1/PHY/MODULATION/modulation_common.h @@ -22,6 +22,7 @@ #ifndef __MODULATION_COMMON__H__ #define __MODULATION_COMMON__H__ #include "PHY/defs_common.h" +#include "PHY/defs_nr_common.h" /** @addtogroup _PHY_MODULATION_ * @{ */ @@ -48,6 +49,7 @@ void PHY_ofdm_mod(int *input, void normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,LTE_DL_FRAME_PARMS *frame_parms); +void nr_normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,NR_DL_FRAME_PARMS *frame_parms); void do_OFDM_mod(int32_t **txdataF, int32_t **txdata, uint32_t frame,uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms); diff --git a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c index e2ca70d82f..9ad263ac80 100644 --- a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c +++ b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c @@ -41,7 +41,7 @@ #include "refsig_defs_ue.h" #include "PHY/defs_nr_UE.h" -#include "nr_mod_table.h" +//#include "nr_mod_table.h" #include "log.h" /*Table 7.4.1.1.2-1/2 from 38.211 */ diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 841be57e18..4b90dce15c 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -36,6 +36,8 @@ #include "PHY/INIT/phy_init.h" #include "SCHED_NR/sched_nr.h" +#include "PHY/MODULATION/modulation_common.h" + #include "common/ran_context.h" PHY_VARS_gNB *gNB; @@ -63,16 +65,19 @@ NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} void exit_fun(const char *s) { exit(-1); } +// needed for some functions +PHY_VARS_NR_UE * PHY_vars_UE_g[1][1]={NULL}; + int main(int argc, char **argv) { char c; int i,l,aa; - double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1; + double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1=2.0; uint8_t snr1set=0; - int **txdata,**txdata1,**txdata2; - double **s_re,**s_im,**s_re1,**s_im1,**s_re2,**s_im2,**r_re,**r_im,**r_re1,**r_im1,**r_re2,**r_im2; + int **txdata; + double **s_re,**s_im,**r_re,**r_im; double iqim = 0.0; unsigned char pbch_pdu[6]; // int sync_pos, sync_pos_slot; @@ -83,11 +88,10 @@ int main(int argc, char **argv) int freq_offset; // int subframe_offset; // char fname[40], vname[40]; - int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti; + int trial,n_trials=1,n_errors,n_errors2,n_alamouti; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; - int n_frames=1; channel_desc_t *gNB2UE; uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; uint8_t extended_prefix_flag=0; @@ -95,15 +99,12 @@ int main(int argc, char **argv) FILE *input_fd=NULL,*pbch_file_fd=NULL; char input_val_str[50],input_val_str2[50]; - // double input_val1,input_val2; - // uint16_t amask=0; + uint8_t frame_mod4,num_pdcch_symbols = 0; uint16_t NB_RB=25; SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - //DCI_ALLOC_t dci_alloc[8]; - uint8_t abstraction_flag=0;//,calibration_flag=0; double pbch_sinr; int pbch_tx_ant; uint8_t N_RB_DL=106,mu=1; @@ -115,7 +116,8 @@ int main(int argc, char **argv) int frame_length_complex_samples; int frame_length_complex_samples_no_prefix; NR_DL_FRAME_PARMS *frame_parms; - + nfapi_nr_config_request_t *gNB_config; + cpuf = get_cpu_freq_GHz(); if ( load_configmodule(argc,argv) == 0) { @@ -123,6 +125,7 @@ int main(int argc, char **argv) } logInit(); + randominit(0); while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:dP:")) != -1) { switch (c) { @@ -187,7 +190,7 @@ int main(int argc, char **argv) break; case 'n': - n_frames = atoi(optarg); + n_trials = atoi(optarg); break; case 's': @@ -251,23 +254,6 @@ int main(int argc, char **argv) break; - case 'A': - abstraction_flag=1; - ntrials=10000; - msg("Running Abstraction test\n"); - pbch_file_fd=fopen(optarg,"r"); - - if (pbch_file_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } - - break; - - // case 'C': - // calibration_flag=1; - // msg("Running Abstraction calibration for Bias removal\n"); - // break; case 'N': Nid_cell = atoi(optarg); break; @@ -323,19 +309,6 @@ int main(int argc, char **argv) } } - s_re = malloc(2*sizeof(double*)); - s_im = malloc(2*sizeof(double*)); - s_re1 = malloc(2*sizeof(double*)); - s_im1 = malloc(2*sizeof(double*)); - s_re2 = malloc(2*sizeof(double*)); - s_im2 = malloc(2*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); - r_re1 = malloc(2*sizeof(double*)); - r_im1 = malloc(2*sizeof(double*)); - r_re2 = malloc(2*sizeof(double*)); - r_im2 = malloc(2*sizeof(double*)); - gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, @@ -354,15 +327,24 @@ int main(int argc, char **argv) RC.gNB[0] = (PHY_VARS_gNB**) malloc(sizeof(PHY_VARS_gNB *)); RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB)); gNB = RC.gNB[0][0]; + gNB_config = &gNB->gNB_config; frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH) + frame_parms->nb_antennas_tx = n_tx; + frame_parms->nb_antennas_rx = n_rx; + frame_parms->N_RB_DL = N_RB_DL; - //NR_PHY_Config_t *phy_config = malloc(sizeof(NR_PHY_Config_t)); nr_phy_config_request_sim(gNB); phy_init_nr_gNB(gNB,0,0); frame_length_complex_samples = frame_parms->samples_per_subframe; frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP; + s_re = malloc(2*sizeof(double*)); + s_im = malloc(2*sizeof(double*)); + r_re = malloc(2*sizeof(double*)); + r_im = malloc(2*sizeof(double*)); + txdata = malloc(2*sizeof(int*)); + for (i=0; i<2; i++) { s_re[i] = malloc(frame_length_complex_samples*sizeof(double)); @@ -374,34 +356,65 @@ int main(int argc, char **argv) bzero(r_re[i],frame_length_complex_samples*sizeof(double)); r_im[i] = malloc(frame_length_complex_samples*sizeof(double)); bzero(r_im[i],frame_length_complex_samples*sizeof(double)); - } + txdata[i] = malloc(frame_length_complex_samples*sizeof(int)); + bzero(r_re[i],frame_length_complex_samples*sizeof(int)); + + } if (pbch_file_fd!=NULL) { load_pbch_desc(pbch_file_fd); } + + //configure UE + UE = malloc(sizeof(PHY_VARS_NR_UE)); + memcpy(&UE->frame_parms,frame_parms,sizeof(NR_DL_FRAME_PARMS)); + phy_init_nr_top(frame_parms); + if (init_nr_ue_signal(UE, 1, 0) != 0) + { + printf("Error at UE NR initialisation\n"); + exit(-1); + } + + + // generate signal if (input_fd==NULL) { nr_common_signal_procedures (gNB,frame,subframe); } LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); - if (gNB->frame_parms.nb_antennas_tx>1) LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1); + //TODO: loop over slots + for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { + if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { + PHY_ofdm_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + frame_parms->ofdm_symbol_size, + 12, + frame_parms->nb_prefix_samples, + CYCLIC_PREFIX); + } else { + nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + 14, + frame_parms); + } + } + + LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1); - - // multipath channel - /* for (i=0; inb_antennas_tx; aa++) { - s_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); - s_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); + r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); + r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); } } - */ for (SNR=snr0; SNRframe_parms.ofdm_symbol_size/(double)(12*NB_RB)) - SNR; - - if (n_frames==1) - printf("sigma2_dB %f (SNR %f dB) tx_lev_dB %f,%f,%f\n",sigma2_dB,SNR, - 10*log10((double)tx_lev), - 10*log10((double)tx_lev1), - 10*log10((double)tx_lev2)); + // multipath channel + //multipath_channel(gNB2UE,s_re,s_im,r_re,r_im,frame_length_complex_samples,0); //AWGN + sigma2_dB = SNR; sigma2 = pow(10,sigma2_dB/10); - - - //printf("n_trial %d\n",n_trials); for (i=0; inb_antennas_rx; aa++) { @@ -433,9 +437,20 @@ int main(int argc, char **argv) ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } + + if (n_trials==1) { + LOG_M("rxsig0.m","rxs0", UE->common_vars.rxdata[0],frame_length_complex_samples,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1); + } } //noise trials + printf("SNR %f : n_errors = %d/%d\n", SNR,n_errors,n_trials); + + if (n_trials==1) + break; + } // NSR for (i=0; i<2; i++) { @@ -443,13 +458,14 @@ int main(int argc, char **argv) free(s_im[i]); free(r_re[i]); free(r_im[i]); + free(txdata[i]); } free(s_re); free(s_im); free(r_re); free(r_im); - + free(txdata); if (write_output_file) fclose(output_fd); From 8c2df1d34f844216265b7033a1a113e9ac3eafe0 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 25 Sep 2018 03:39:30 -0700 Subject: [PATCH 3/4] moving set_default_frame_parms_single() from nr-uesoftmodem to nr_init_ue.c to avoid having to include nr-uesoftmodem.c in the compilation of the nr_pbchsim --- openair1/PHY/INIT/nr_init_ue.c | 61 ++++++++++++++++++++++++++++++++ targets/RT/USER/nr-uesoftmodem.c | 60 ------------------------------- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index a060e4259f..b70c90791f 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -977,3 +977,64 @@ void phy_init_nr_top(NR_DL_FRAME_PARMS *frame_parms) //set_taus_seed(1328); } + +void set_default_frame_parms_single(nfapi_nr_config_request_t *config, NR_DL_FRAME_PARMS *frame_parms) { + + //int CC_id; + + //for (CC_id=0; CC_idsubframe_config.numerology_index_mu.value =1; + config->subframe_config.duplex_mode.value = 1; //FDD + config->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL + config->rf_config.dl_carrier_bandwidth.value = 106; + config->rf_config.ul_carrier_bandwidth.value = 106; + config->rf_config.tx_antenna_ports.value = 1; + config->rf_config.rx_antenna_ports.value = 1; + config->sch_config.physical_cell_id.value = 0; + + frame_parms->frame_type = FDD; + frame_parms->tdd_config = 3; + //frame_parms[CC_id]->tdd_config_S = 0; + frame_parms->N_RB_DL = 100; + frame_parms->N_RB_UL = 100; + frame_parms->Ncp = NORMAL; + //frame_parms[CC_id]->Ncp_UL = NORMAL; + frame_parms->Nid_cell = 0; + //frame_parms[CC_id]->num_MBSFN_config = 0; + frame_parms->nb_antenna_ports_eNB = 1; + frame_parms->nb_antennas_tx = 1; + frame_parms->nb_antennas_rx = 1; + + //frame_parms[CC_id]->nushift = 0; + + ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; + //frame_parms[CC_id]->phich_config_common.phich_duration = normal; + + // UL RS Config + /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0 + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; + + frame_parms[CC_id]->pusch_config_common.n_SB = 1; + frame_parms[CC_id]->pusch_config_common.hoppingMode = 0; + frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0; + frame_parms[CC_id]->pusch_config_common.enable64QAM = 0; + + frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/ + + // NR: Init to legacy LTE 20Mhz params + frame_parms->numerology_index = 0; + frame_parms->ttis_per_subframe = 1; + frame_parms->slots_per_tti = 2; + + //} + +} diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c index e53bf1f030..2345a30fc4 100644 --- a/targets/RT/USER/nr-uesoftmodem.c +++ b/targets/RT/USER/nr-uesoftmodem.c @@ -634,66 +634,6 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { } -void set_default_frame_parms_single(nfapi_nr_config_request_t *config, NR_DL_FRAME_PARMS *frame_parms) { - - //int CC_id; - - //for (CC_id=0; CC_idsubframe_config.numerology_index_mu.value =1; - config->subframe_config.duplex_mode.value = 1; //FDD - config->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL - config->rf_config.dl_carrier_bandwidth.value = 106; - config->rf_config.ul_carrier_bandwidth.value = 106; - config->rf_config.tx_antenna_ports.value = 1; - config->rf_config.rx_antenna_ports.value = 1; - config->sch_config.physical_cell_id.value = 0; - - frame_parms->frame_type = FDD; - frame_parms->tdd_config = 3; - //frame_parms[CC_id]->tdd_config_S = 0; - frame_parms->N_RB_DL = 100; - frame_parms->N_RB_UL = 100; - frame_parms->Ncp = NORMAL; - //frame_parms[CC_id]->Ncp_UL = NORMAL; - frame_parms->Nid_cell = 0; - //frame_parms[CC_id]->num_MBSFN_config = 0; - frame_parms->nb_antenna_ports_eNB = 1; - frame_parms->nb_antennas_tx = 1; - frame_parms->nb_antennas_rx = 1; - - //frame_parms[CC_id]->nushift = 0; - - ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; - //frame_parms[CC_id]->phich_config_common.phich_duration = normal; - - // UL RS Config - /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0 - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; - - frame_parms[CC_id]->pusch_config_common.n_SB = 1; - frame_parms[CC_id]->pusch_config_common.hoppingMode = 0; - frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0; - frame_parms[CC_id]->pusch_config_common.enable64QAM = 0; - - frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/ - - // NR: Init to legacy LTE 20Mhz params - frame_parms->numerology_index = 0; - frame_parms->ttis_per_subframe = 1; - frame_parms->slots_per_tti = 2; - - //} - -} void init_openair0(void); void init_openair0() { From 0613a01f8dd837bff153d7b82a7c8d85e3ac5ebb Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 25 Sep 2018 03:41:04 -0700 Subject: [PATCH 4/4] WIP: mostly debug messages --- openair1/PHY/NR_TRANSPORT/nr_pss.c | 6 +++--- openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 6 ++++-- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 15 +++++++++++---- openair1/PHY/NR_UE_TRANSPORT/pss_nr.c | 14 ++------------ openair1/PHY/phy_extern_nr_ue.h | 2 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 8 ++++++++ targets/RT/USER/nr-ru.c | 4 ++-- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_pss.c b/openair1/PHY/NR_TRANSPORT/nr_pss.c index 3c4f296cd6..1f653038a6 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pss.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pss.c @@ -22,7 +22,7 @@ #include "PHY/NR_TRANSPORT/nr_transport.h" -//#define NR_PSS_DEBUG +#define NR_PSS_DEBUG int nr_generate_pss( int16_t *d_pss, int32_t **txdataF, @@ -52,7 +52,7 @@ int nr_generate_pss( int16_t *d_pss, } #ifdef NR_PSS_DEBUG - write_output("d_pss.m", "d_pss", (void*)d_pss, NR_PSS_LENGTH, 1, 1); + write_output("d_pss.m", "d_pss", (void*)d_pss, NR_PSS_LENGTH, 1, 0); #endif /// Resource mapping @@ -75,7 +75,7 @@ int nr_generate_pss( int16_t *d_pss, } #ifdef NR_PSS_DEBUG - write_output("pss_0.m", "pss_0", (void*)txdataF[0][2*l*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size, 1, 1); + write_output("pss_0.m", "pss_0", (void*)&txdataF[0][2*l*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size, 1, 1); #endif return 0; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 0937fa6036..7acc0d082d 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -197,13 +197,15 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) * sync_pos SS/PBCH block */ cnt++; - if (cnt >100){ - cnt =0; + if (1){ + cnt =0; /* process pss search on received buffer */ sync_pos = pss_synchro_nr(ue, NO_RATE_CHANGE); sync_pos_slot = (frame_parms->samples_per_tti>>1) - 3*(frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples); + sync_pos = sync_pos_slot+frame_parms->nb_prefix_samples; + if (sync_pos >= frame_parms->nb_prefix_samples) sync_pos2 = sync_pos - frame_parms->nb_prefix_samples; else diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index dd25d4639b..7efadfb9fd 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -35,7 +35,7 @@ #include "PHY/sse_intrin.h" //#include "SIMULATION/TOOLS/sim.h" -//#define DEBUG_PBCH 1 +#define DEBUG_PBCH 1 //#define DEBUG_PBCH_ENCODING #ifdef OPENAIR2 @@ -247,6 +247,9 @@ void nr_pbch_channel_compensation(int **rxdataF_ext, uint8_t output_shift) { + short conjugate[8]__attribute__((aligned(16))) = {-1,1,-1,1,-1,1,-1,1}; + short conjugate2[8]__attribute__((aligned(16))) = {1,-1,1,-1,1,-1,1,-1}; + uint16_t rb,nb_rb=20; uint8_t aatx,aarx; #if defined(__x86_64__) || defined(__i386__) @@ -552,8 +555,10 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, for (symbol=5; symbol<8; symbol++) { +#ifdef DEBUG_PBCH //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF); - //write_output("rxdataF0_pbch.m","rxF0pbch",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,frame_parms->ofdm_symbol_size*4,2,1); + write_output("rxdataF0_pbch.m","rxF0pbch",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,frame_parms->ofdm_symbol_size*4,2,1); +#endif nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF, nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id], @@ -583,8 +588,10 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, symbol, log2_maxh); // log2_maxh+I0_shift - //write_output("rxdataF_comp.m","rxFcomp",nr_ue_pbch_vars->rxdataF_comp,180,2,1); - +#ifdef DEBUG_PBCH + write_output("rxdataF_comp.m","rxFcomp",nr_ue_pbch_vars->rxdataF_comp,180,2,1); +#endif + /*if (frame_parms->nb_antennas_rx > 1) pbch_detection_mrc(frame_parms, nr_ue_pbch_vars->rxdataF_comp, diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c index 32f906c1d9..969fe1b1e5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c @@ -57,6 +57,8 @@ * *********************************************************************/ +#define DBG_PSS_NR + void *get_idft(int ofdm_symbol_size) { void (*idft)(int16_t *,int16_t *, int); @@ -791,18 +793,6 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain /* Correlation computation is based on a a dot product which is realized thank to SIMS extensions */ for (n=0; n < length; n+=4) { -#ifdef RTAI_ENABLED - - // This is necessary since the sync takes a long time and it seems to block all other threads thus screwing up RTAI. If we pause it for a little while during its execution we give RTAI a chance to catch up with its other tasks. - if ((n%frame_parms->samples_per_subframe == 0) && (n>0) && (openair_daq_vars.sync_state==0)) { -#ifdef DEBUG_PHY - msg("[SYNC TIME] pausing for 1000ns, n=%d\n",n); -#endif - rt_sleep(nano2count(1000)); - } - -#endif - for (int pss_index = 0; pss_index < NUMBER_PSS_SEQUENCE; pss_index++) { pss_corr_ue[pss_index][n] = 0; /* clean correlation for position n */ diff --git a/openair1/PHY/phy_extern_nr_ue.h b/openair1/PHY/phy_extern_nr_ue.h index 253c5b7fb9..2fa9ef511e 100644 --- a/openair1/PHY/phy_extern_nr_ue.h +++ b/openair1/PHY/phy_extern_nr_ue.h @@ -32,7 +32,7 @@ extern char fmageren_name2[512]; extern unsigned int RX_DMA_BUFFER[4][NB_ANTENNAS_RX]; extern unsigned int TX_DMA_BUFFER[4][NB_ANTENNAS_TX]; -#include "PHY/LTE_TRANSPORT/transport_extern.h" +//#include "PHY/LTE_TRANSPORT/transport_extern.h" extern int number_of_cards; diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 4b90dce15c..1d91510304 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -117,6 +117,8 @@ int main(int argc, char **argv) int frame_length_complex_samples_no_prefix; NR_DL_FRAME_PARMS *frame_parms; nfapi_nr_config_request_t *gNB_config; + + int ret; cpuf = get_cpu_freq_GHz(); @@ -309,6 +311,9 @@ int main(int argc, char **argv) } } + if (snr1set==0) + snr1 = snr0+10; + gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, @@ -443,6 +448,9 @@ int main(int argc, char **argv) if (gNB->frame_parms.nb_antennas_tx>1) LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1); } + + ret = nr_initial_sync(UE, normal_txrx); + printf("nr_initial_sync1 returns %d\n",ret); } //noise trials diff --git a/targets/RT/USER/nr-ru.c b/targets/RT/USER/nr-ru.c index f0b7a766af..8cacda5880 100644 --- a/targets/RT/USER/nr-ru.c +++ b/targets/RT/USER/nr-ru.c @@ -806,10 +806,10 @@ void tx_rf(RU_t *ru) { for (i=0; inb_tx; i++) txp[i] = (void*)&ru->common.txdata[i][(proc->subframe_tx*fp->samples_per_subframe)-sf_extension]; - /*if (proc->subframe_tx == 0){ + if (proc->subframe_tx == 0){ write_output("txdataF_frame.m","txdataF_frame",&ru->common.txdataF_BF[i],fp->samples_per_subframe_wCP, 1, 1); write_output("txdata_frame.m","txdata_frame",&ru->common.txdata[i],fp->samples_per_subframe, 1, 1); - }*/ + } VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (proc->timestamp_tx-ru->openair0_cfg.tx_sample_advance)&0xffffffff ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );