diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index cbe0cfd151103f3e1d97c561646222c22e820708..7f9a4d6494a6df4d93f22ad633d87fc2b77bf105 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2397,7 +2397,7 @@ add_executable(nr-uesoftmodem ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c - ${OPENAIR_DIR}/executables//nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/nr-uesoftmodem.c ${OPENAIR_DIR}/executables/nr-ue.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c @@ -2431,8 +2431,8 @@ add_executable(nr-uesoftmodem-nos1 ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c - ${OPENAIR_TARGETS}/RT/USER/nr-ue.c - ${OPENAIR_TARGETS}/RT/USER/nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/nr-ue.c + ${OPENAIR_DIR}/executables/nr-uesoftmodem.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c #${OPENAIR_TARGETS}/COMMON/create_tasks_ue.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index a92bdf11e443caa1e79ff8d63c8e26066acc5a9a..1124a26b72572a4d9c263a19bed64a7093a145e7 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -40,7 +40,7 @@ #include "assertions.h" #if defined(ENABLE_ITTI) -# include "intertask_interface.h" + #include "intertask_interface.h" #endif # include <pthread.h> @@ -75,16 +75,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL char *log_level_highlight_end[] = {LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */ -int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) -{ - +int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) { FILE *fp=NULL; int i; if (data == NULL) - return -1; - //printf("Writing %d elements of type %d to %s\n",length,format,fname); + return -1; + //printf("Writing %d elements of type %d to %s\n",length,format,fname); if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14) { fp = fopen(fname,"a+"); @@ -92,8 +90,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, fp = fopen(fname,"w+"); } - - if (fp== NULL) { printf("[OPENAIR][FILE OUTPUT] Cannot open file %s\n",fname); return(-1); @@ -102,121 +98,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) fprintf(fp,"%s = [",vname); - switch (format) { - case 0: // real 16-bit - - for (i=0; i<length; i+=dec) { - fprintf(fp,"%d\n",((short *)data)[i]); - } - - break; - - case 1: // complex 16-bit - case 13: - case 14: - case 15: - - for (i=0; i<length<<1; i+=(2*dec)) { - fprintf(fp,"%d + j*(%d)\n",((short *)data)[i],((short *)data)[i+1]); - - } - - - break; - - case 2: // real 32-bit - for (i=0; i<length; i+=dec) { - fprintf(fp,"%d\n",((int *)data)[i]); - } - - break; - - case 3: // complex 32-bit - for (i=0; i<length<<1; i+=(2*dec)) { - fprintf(fp,"%d + j*(%d)\n",((int *)data)[i],((int *)data)[i+1]); - } - - break; - - case 4: // real 8-bit - for (i=0; i<length; i+=dec) { - fprintf(fp,"%d\n",((char *)data)[i]); - } + case 0: // real 16-bit + for (i=0; i<length; i+=dec) { + fprintf(fp,"%d\n",((short *)data)[i]); + } - break; + break; - case 5: // complex 8-bit - for (i=0; i<length<<1; i+=(2*dec)) { - fprintf(fp,"%d + j*(%d)\n",((char *)data)[i],((char *)data)[i+1]); - } + case 1: // complex 16-bit + case 13: + case 14: + case 15: + for (i=0; i<length<<1; i+=(2*dec)) { + fprintf(fp,"%d + j*(%d)\n",((short *)data)[i],((short *)data)[i+1]); + } - break; + break; - case 6: // real 64-bit - for (i=0; i<length; i+=dec) { - fprintf(fp,"%lld\n",((long long*)data)[i]); - } + case 2: // real 32-bit + for (i=0; i<length; i+=dec) { + fprintf(fp,"%d\n",((int *)data)[i]); + } - break; + break; - case 7: // real double - for (i=0; i<length; i+=dec) { - fprintf(fp,"%g\n",((double *)data)[i]); - } + case 3: // complex 32-bit + for (i=0; i<length<<1; i+=(2*dec)) { + fprintf(fp,"%d + j*(%d)\n",((int *)data)[i],((int *)data)[i+1]); + } - break; + break; - case 8: // complex double - for (i=0; i<length<<1; i+=2*dec) { - fprintf(fp,"%g + j*(%g)\n",((double *)data)[i], ((double *)data)[i+1]); - } + case 4: // real 8-bit + for (i=0; i<length; i+=dec) { + fprintf(fp,"%d\n",((char *)data)[i]); + } - break; + break; - case 9: // real unsigned 8-bit - for (i=0; i<length; i+=dec) { - fprintf(fp,"%d\n",((unsigned char *)data)[i]); - } + case 5: // complex 8-bit + for (i=0; i<length<<1; i+=(2*dec)) { + fprintf(fp,"%d + j*(%d)\n",((char *)data)[i],((char *)data)[i+1]); + } - break; + break; + case 6: // real 64-bit + for (i=0; i<length; i+=dec) { + fprintf(fp,"%lld\n",((long long *)data)[i]); + } - case 10 : // case eren 16 bit complex : + break; - for (i=0; i<length<<1; i+=(2*dec)) { + case 7: // real double + for (i=0; i<length; i+=dec) { + fprintf(fp,"%g\n",((double *)data)[i]); + } - if((i < 2*(length-1)) && (i > 0)) - fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); - else if (i == 2*(length-1)) - fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); - else if (i == 0) - fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + break; + case 8: // complex double + for (i=0; i<length<<1; i+=2*dec) { + fprintf(fp,"%g + j*(%g)\n",((double *)data)[i], ((double *)data)[i+1]); + } + break; - } + case 9: // real unsigned 8-bit + for (i=0; i<length; i+=dec) { + fprintf(fp,"%d\n",((unsigned char *)data)[i]); + } - break; + break; - case 11 : //case eren 16 bit real for channel magnitudes: - for (i=0; i<length; i+=dec) { + case 10 : // case eren 16 bit complex : + for (i=0; i<length<<1; i+=(2*dec)) { + if((i < 2*(length-1)) && (i > 0)) + fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + else if (i == 2*(length-1)) + fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); + else if (i == 0) + fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + } - if((i <(length-1))&& (i > 0)) - fprintf(fp,"%d,",((short *)data)[i]); - else if (i == (length-1)) - fprintf(fp,"%d;",((short *)data)[i]); - else if (i == 0) - fprintf(fp,"\n%d,",((short *)data)[i]); - } + break; - printf("\n eren: length :%d",length); - break; + case 11 : //case eren 16 bit real for channel magnitudes: + for (i=0; i<length; i+=dec) { + if((i <(length-1))&& (i > 0)) + fprintf(fp,"%d,",((short *)data)[i]); + else if (i == (length-1)) + fprintf(fp,"%d;",((short *)data)[i]); + else if (i == 0) + fprintf(fp,"\n%d,",((short *)data)[i]); + } - case 12 : // case eren for log2_maxh real unsigned 8 bit - fprintf(fp,"%d \n",((unsigned char *)&data)[0]); - break; + printf("\n eren: length :%d",length); + break; + case 12 : // case eren for log2_maxh real unsigned 8 bit + fprintf(fp,"%d \n",((unsigned char *)&data)[0]); + break; } if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) { @@ -235,131 +218,141 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, void log_getconfig(log_t *g_log) { char *gloglevel = NULL; int consolelog ; - - paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC; paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)]; paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)]; - int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX); + if (ret <0) { - fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); - return; - } + fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); + return; + } -/* set LOG display options (enable/disable color, thread name, level ) */ + /* set LOG display options (enable/disable color, thread name, level ) */ for(int i=0; i<logparams_defaults[LOG_OPTIONS_IDX].numelt ; i++) { - for(int j=0; log_options[j].name != NULL ; j++) { - if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) { - g_log->flag = g_log->flag | log_options[j].value; - break; - } else if (log_options[j+1].name == NULL){ - fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); - exit(-1); - } - } - } - -/* build the parameter array for setting per component log level and infile options */ + for(int j=0; log_options[j].name != NULL ; j++) { + if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) { + g_log->flag = g_log->flag | log_options[j].value; + break; + } else if (log_options[j+1].name == NULL) { + fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); + exit(-1); + } + } + } + + /* build the parameter array for setting per component log level and infile options */ memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); + for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { if(g_log->log_component[i].name == NULL) { - g_log->log_component[i].name = malloc(16); - sprintf((char *)g_log->log_component[i].name,"comp%i?",i); - logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; - logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; + g_log->log_component[i].name = malloc(16); + sprintf((char *)g_log->log_component[i].name,"comp%i?",i); + logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; + logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; } + sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name); sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name); -/* workaround: all log options in existing configuration files use lower case component names - where component names include uppercase char in log.h.... */ - for (int j=0 ; j<strlen(logparams_level[i].optname); j++) - logparams_level[i].optname[j] = tolower(logparams_level[i].optname[j]); - for (int j=0 ; j<strlen(logparams_level[i].optname); j++) - logparams_logfile[i].optname[j] = tolower(logparams_logfile[i].optname[j]); -/* */ + + /* workaround: all log options in existing configuration files use lower case component names + where component names include uppercase char in log.h.... */ + for (int j=0 ; j<strlen(logparams_level[i].optname); j++) + logparams_level[i].optname[j] = tolower(logparams_level[i].optname[j]); + + for (int j=0 ; j<strlen(logparams_level[i].optname); j++) + logparams_logfile[i].optname[j] = tolower(logparams_logfile[i].optname[j]); + + /* */ logparams_level[i].defstrval = gloglevel; logparams_logfile[i].defuintval = 0; logparams_logfile[i].numelt = 0; logparams_level[i].numelt = 0; logparams_level[i].type = TYPE_STRING; logparams_logfile[i].type = TYPE_UINT; - logparams_logfile[i].paramflags = logparams_logfile[i].paramflags|PARAMFLAG_BOOL; - } -/* read the per component parameters */ - config_get( logparams_level, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); - config_get( logparams_logfile, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); -/* now set the log levels and infile option, according to what we read */ + } + + /* read the per component parameters */ + config_get( logparams_level, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); + config_get( logparams_logfile, MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); + + /* now set the log levels and infile option, according to what we read */ for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { g_log->log_component[i].level = map_str_to_int(log_level_names, *(logparams_level[i].strptr)); set_log(i, g_log->log_component[i].level); + if (*(logparams_logfile[i].uptr) == 1) - set_component_filelog(i); + set_component_filelog(i); } -/* build then read the debug and dump parameter array */ - for (int i=0;log_maskmap[i].name != NULL ; i++) { - sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); - sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); - logparams_debug[i].defuintval = 0; - logparams_debug[i].type = TYPE_UINT; - logparams_debug[i].paramflags = PARAMFLAG_BOOL; - logparams_debug[i].uptr = NULL; - logparams_debug[i].chkPptr = NULL; - logparams_debug[i].numelt = 0; - logparams_dump[i].defuintval = 0; - logparams_dump[i].type = TYPE_UINT; - logparams_dump[i].paramflags = PARAMFLAG_BOOL; - logparams_dump[i].uptr = NULL; - logparams_dump[i].chkPptr = NULL; - logparams_dump[i].numelt = 0; + /* build then read the debug and dump parameter array */ + for (int i=0; log_maskmap[i].name != NULL ; i++) { + sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); + sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); + logparams_debug[i].defuintval = 0; + logparams_debug[i].type = TYPE_UINT; + logparams_debug[i].paramflags = PARAMFLAG_BOOL; + logparams_debug[i].uptr = NULL; + logparams_debug[i].chkPptr = NULL; + logparams_debug[i].numelt = 0; + logparams_dump[i].defuintval = 0; + logparams_dump[i].type = TYPE_UINT; + logparams_dump[i].paramflags = PARAMFLAG_BOOL; + logparams_dump[i].uptr = NULL; + logparams_dump[i].chkPptr = NULL; + logparams_dump[i].numelt = 0; } - config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); - config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); -/* set the debug mask according to the debug parameters values */ + + config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1,CONFIG_STRING_LOG_PREFIX); + config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1,CONFIG_STRING_LOG_PREFIX); + + /* set the debug mask according to the debug parameters values */ for (int i=0; log_maskmap[i].name != NULL ; i++) { if (*(logparams_debug[i].uptr) ) - g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + if (*(logparams_dump[i].uptr) ) - g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; - } -/* log globally enabled/disabled */ + g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; + } + + /* log globally enabled/disabled */ set_glog_onlinelog(consolelog); } -int register_log_component(char *name, char *fext, int compidx) -{ -int computed_compidx=compidx; +int register_log_component(char *name, char *fext, int compidx) { + int computed_compidx=compidx; if (strlen(fext) > 3) { - fext[3]=0; /* limit log file extension to 3 chars */ + fext[3]=0; /* limit log file extension to 3 chars */ } + if (compidx < 0) { /* this is not a pre-defined component */ - for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { - if (g_log->log_component[i].name == NULL) { - computed_compidx=i; - break; - } + for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { + if (g_log->log_component[i].name == NULL) { + computed_compidx=i; + break; } + } } + if (computed_compidx >= 0 && computed_compidx <MAX_LOG_COMPONENTS) { - g_log->log_component[computed_compidx].name = strdup(name); - g_log->log_component[computed_compidx].stream = stdout; - g_log->log_component[computed_compidx].filelog = 0; - g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s */ - sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); + g_log->log_component[computed_compidx].name = strdup(name); + g_log->log_component[computed_compidx].stream = stdout; + g_log->log_component[computed_compidx].filelog = 0; + g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s */ + sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); } else { - fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); + fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); } -return computed_compidx; + + return computed_compidx; } -int logInit (void) -{ +int logInit (void) { int i; g_log = calloc(1, sizeof(log_t)); @@ -367,10 +360,8 @@ int logInit (void) perror ("cannot allocated memory for log generation module \n"); exit(EXIT_FAILURE); } - memset(g_log,0,sizeof(log_t)); - - + memset(g_log,0,sizeof(log_t)); register_log_component("PHY","log",PHY); register_log_component("MAC","log",MAC); register_log_component("OPT","log",OPT); @@ -386,143 +377,121 @@ int logInit (void) register_log_component("OTG_JITTER","dat",OTG_JITTER); register_log_component("OCG","",OCG); register_log_component("PERF","",PERF); - register_log_component("OIP","",OIP); - register_log_component("CLI","",CLI); - register_log_component("MSC","log",MSC); - register_log_component("OCM","log",OCM); - register_log_component("HW","",HW); - register_log_component("OSA","",OSA); - register_log_component("eRAL","",RAL_ENB); - register_log_component("mRAL","",RAL_UE); - register_log_component("ENB_APP","log",ENB_APP); - register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); - register_log_component("TMR","",TMR); - register_log_component("USIM","txt",USIM); - register_log_component("SIM","txt",SIM); - + register_log_component("OIP","",OIP); + register_log_component("CLI","",CLI); + register_log_component("MSC","log",MSC); + register_log_component("OCM","log",OCM); + register_log_component("HW","",HW); + register_log_component("OSA","",OSA); + register_log_component("eRAL","",RAL_ENB); + register_log_component("mRAL","",RAL_UE); + register_log_component("ENB_APP","log",ENB_APP); + register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); + register_log_component("TMR","",TMR); + register_log_component("USIM","txt",USIM); + register_log_component("SIM","txt",SIM); /* following log component are used for the localization*/ register_log_component("LOCALIZE","log",LOCALIZE); register_log_component("NAS","log",NAS); register_log_component("UDP","",UDP_); - - register_log_component("GTPV1U","",GTPU); - - register_log_component("S1AP","",S1AP); register_log_component("X2AP","",X2AP); - - register_log_component("SCTP","",SCTP); register_log_component("X2AP","",X2AP); register_log_component("LOADER","log",LOADER); register_log_component("ASN","log",ASN); - - for (int i=0 ; log_level_names[i].name != NULL ; i++) - g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name - - - - + g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name g_log->filelog_name = "/tmp/openair.log"; - log_getconfig(g_log); - - // set all unused component items to 0, they are for non predefined components for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); + memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); } - printf("log init done\n"); + printf("log init done\n"); return 0; } char *log_getthreadname(char *threadname, int bufsize) { + int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; -int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; - if (rt == 0) - { - return threadname; - } else { - return "thread?"; - } + if (rt == 0) { + return threadname; + } else { + return "thread?"; + } } static int log_header(char *log_buffer, int buffsize, int comp, int level,const char *format) { char threadname[PR_SET_NAME]; -return snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s", - log_level_highlight_end[level], - ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), - g_log->log_component[comp].name, - ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), - ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), - format, - log_level_highlight_end[level]); + return snprintf(log_buffer, buffsize, "%s%s[%s]%c %s %s%s", + log_level_highlight_end[level], + ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), + g_log->log_component[comp].name, + ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), + ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), + format, + log_level_highlight_end[level]); } -void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char* format, ... ) - { - char log_buffer[MAX_LOG_TOTAL]={0}; +void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, ... ) { + char log_buffer[MAX_LOG_TOTAL]= {0}; va_list args; - va_start(args, format); - - - - - log_header(log_buffer,MAX_LOG_TOTAL ,comp, level,format); + log_header(log_buffer,MAX_LOG_TOTAL,comp, level,format); g_log->log_component[comp].vprint(g_log->log_component[comp].stream,log_buffer, args); + fflush(g_log->log_component[comp].stream); va_end(args); - - } -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ) { -va_list args; -char *wbuf; +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ) { + va_list args; + char *wbuf; + + switch(datatype) { + case LOG_DUMP_DOUBLE: + wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); + break; + case LOG_DUMP_CHAR: + default: + wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); + break; + } - switch(datatype) { - case LOG_DUMP_DOUBLE: - wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); - break; - case LOG_DUMP_CHAR: - default: - wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); - break; + if (wbuf != NULL) { + va_start(args, format); + int pos=log_header(wbuf,MAX_LOG_TOTAL,component, OAILOG_INFO,""); + int pos2=vsprintf(wbuf+pos,format, args); + pos=pos+pos2; + va_end(args); + + for (int i=0; i<buffsize; i++) { + switch(datatype) { + case LOG_DUMP_DOUBLE: + pos = pos + sprintf(wbuf+pos,"%04.4lf ", (double)((double *)buffer)[i]); + break; + + case LOG_DUMP_CHAR: + default: + pos = pos + sprintf(wbuf+pos,"%02x ", (unsigned char)((unsigned char *)buffer)[i]); + break; + } } - if (wbuf != NULL) { - va_start(args, format); - int pos=log_header(wbuf,MAX_LOG_TOTAL ,component, OAILOG_INFO,""); - int pos2=vsprintf(wbuf+pos,format, args); - pos=pos+pos2; - va_end(args); - - for (int i=0; i<buffsize; i++) { - switch(datatype) { - case LOG_DUMP_DOUBLE: - pos = pos + sprintf(wbuf+pos,"%04.4lf ", (double)((double *)buffer)[i]); - break; - case LOG_DUMP_CHAR: - default: - pos = pos + sprintf(wbuf+pos,"%02x ", (unsigned char)((unsigned char *)buffer)[i]); - break; - } - } + sprintf(wbuf+pos,"\n"); g_log->log_component[component].print(g_log->log_component[component].stream,wbuf); free(wbuf); - } + } } -int set_log(int component, int level) -{ +int set_log(int component, int level) { /* Checking parameters */ DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); @@ -530,38 +499,34 @@ int set_log(int component, int level) OAILOG_ERR); if ( g_log->log_component[component].level != OAILOG_DISABLE ) - g_log->log_component[component].savedlevel = g_log->log_component[component].level; - g_log->log_component[component].level = level; + g_log->log_component[component].savedlevel = g_log->log_component[component].level; + g_log->log_component[component].level = level; return 0; } -void set_glog(int level) -{ +void set_glog(int level) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - set_log(c, level); + set_log(c, level); } - } -void set_glog_onlinelog(int enable) -{ +void set_glog_onlinelog(int enable) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - if ( enable ) { - g_log->log_component[c].level = g_log->log_component[c].savedlevel; - g_log->log_component[c].vprint = vfprintf; - g_log->log_component[c].print = fprintf; - g_log->log_component[c].stream = stdout; - } else { - g_log->log_component[c].level = OAILOG_DISABLE; - } - } + if ( enable ) { + g_log->log_component[c].level = g_log->log_component[c].savedlevel; + g_log->log_component[c].vprint = vfprintf; + g_log->log_component[c].print = fprintf; + g_log->log_component[c].stream = stdout; + } else { + g_log->log_component[c].level = OAILOG_DISABLE; + } + } } -void set_glog_filelog(int enable) -{ -static FILE *fptr; +void set_glog_filelog(int enable) { + static FILE *fptr; if ( enable ) { fptr = fopen(g_log->filelog_name,"w"); @@ -574,33 +539,35 @@ static FILE *fptr; } else { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { g_log->log_component[c].filelog = 0; + if (fptr != NULL) { fclose(fptr); } + g_log->log_component[c].stream = stdout; - } - } + } + } } -void set_component_filelog(int comp) -{ - if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { - g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - g_log->log_component[comp].filelog = 1; +void set_component_filelog(int comp) { + if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { + g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; + g_log->log_component[comp].filelog = 1; } -void close_component_filelog(int comp) -{ - g_log->log_component[comp].filelog = 0; - if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { - fclose(g_log->log_component[comp].stream); - g_log->log_component[comp].stream = stdout; - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - +void close_component_filelog(int comp) { + g_log->log_component[comp].filelog = 0; + + if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { + fclose(g_log->log_component[comp].stream); + g_log->log_component[comp].stream = stdout; + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; } /* @@ -608,8 +575,7 @@ void close_component_filelog(int comp) * with string value NULL */ /* map a string to an int. Takes a mapping array and a string as arg */ -int map_str_to_int(mapping *map, const char *str) -{ +int map_str_to_int(mapping *map, const char *str) { while (1) { if (map->name == NULL) { return(-1); @@ -624,8 +590,7 @@ int map_str_to_int(mapping *map, const char *str) } /* map an int to a string. Takes a mapping array and a value */ -char *map_int_to_str(mapping *map, int val) -{ +char *map_int_to_str(mapping *map, int val) { while (1) { if (map->name == NULL) { return NULL; @@ -639,8 +604,7 @@ char *map_int_to_str(mapping *map, int val) } } -int is_newline( char *str, int size) -{ +int is_newline( char *str, int size) { int i; for ( i = 0; i < size; i++ ) { @@ -653,85 +617,62 @@ int is_newline( char *str, int size) return 0; } -void logClean (void) -{ +void logClean (void) { int i; LOG_UI(PHY,"\n"); - - - for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - close_component_filelog(i); + close_component_filelog(i); } } - -#ifdef LOG_TEST -int main(int argc, char *argv[]) -{ +#ifdef LOG_TEST +int main(int argc, char *argv[]) { logInit(); - - test_log(); - return 1; } -int test_log(void) -{ +int test_log(void) { LOG_ENTER(MAC); // because the default level is DEBUG LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "1 debug MAC \n"); LOG_W(MAC, "1 warning MAC \n"); - set_log(EMU, OAILOG_INFO); set_log(MAC, OAILOG_WARNING); - LOG_I(EMU, "2 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_E(MAC, "2 error MAC\n"); LOG_D(MAC, "2 debug MAC \n"); LOG_W(MAC, "2 warning MAC \n"); LOG_I(MAC, "2 info MAC \n"); - - set_log(MAC, OAILOG_NOTICE); - LOG_ENTER(MAC); LOG_I(EMU, "3 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "3 debug MAC \n"); LOG_W(MAC, "3 warning MAC \n"); LOG_I(MAC, "3 info MAC \n"); - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_ENTER(MAC); LOG_I(EMU, "4 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "4 debug MAC \n"); LOG_W(MAC, "4 warning MAC \n"); LOG_I(MAC, "4 info MAC \n"); - - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_I(LOG, "5 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "5 debug MAC \n"); LOG_W(MAC, "5 warning MAC \n"); LOG_I(MAC, "5 info MAC \n"); - - set_log(MAC, LOG_TRACE); set_log(EMU, LOG_TRACE); - LOG_ENTER(MAC); LOG_I(LOG, "6 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); @@ -739,7 +680,6 @@ int test_log(void) LOG_W(MAC, "6 warning MAC \n"); LOG_I(MAC, "6 info MAC \n"); LOG_EXIT(MAC); - return 0; } #endif diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index db73bd7f5bc980b9f4c86d35336f0f9362e51455..8390c3af25a14e394826f5d5cf42fd2ddea5883e 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -45,14 +45,15 @@ #include <time.h> #include <stdint.h> #ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS + #define __STDC_FORMAT_MACROS #endif #include <inttypes.h> #ifndef _GNU_SOURCE -#define _GNU_SOURCE + #define _GNU_SOURCE #endif #include <pthread.h> #include "T.h" +#include <common/utils/utils.h> /*----------------------------------------------------------------------------*/ #ifdef __cplusplus @@ -127,11 +128,11 @@ extern "C" { /** @defgroup macros to identify a debug entity * @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged - * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro + * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro * is used to map a character string name to each debug bit, it allows to set or clear * the corresponding bit via the defined name, from the configuration or from the telnet * server. - * @brief + * @brief * @{*/ #define DEBUG_PRACH (1<<0) #define DEBUG_RU (1<<1) @@ -150,22 +151,22 @@ extern "C" { #define LOG_MASKMAP_INIT {\ - {"PRACH", DEBUG_PRACH},\ - {"RU", DEBUG_RU},\ - {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ - {"LTEESTIM", DEBUG_LTEESTIM},\ - {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ - {"ULSCH", DEBUG_ULSCH},\ - {"RRC", DEBUG_RRC},\ - {"PDCP", DEBUG_PDCP},\ - {"DFT", DEBUG_DFT},\ - {"ASN1", DEBUG_ASN1},\ - {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ - {"SECURITY", DEBUG_SECURITY},\ - {"NAS", DEBUG_NAS},\ - {"UE_TIMING", UE_TIMING},\ - {NULL,-1}\ -} + {"PRACH", DEBUG_PRACH},\ + {"RU", DEBUG_RU},\ + {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ + {"LTEESTIM", DEBUG_LTEESTIM},\ + {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ + {"ULSCH", DEBUG_ULSCH},\ + {"RRC", DEBUG_RRC},\ + {"PDCP", DEBUG_PDCP},\ + {"DFT", DEBUG_DFT},\ + {"ASN1", DEBUG_ASN1},\ + {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ + {"SECURITY", DEBUG_SECURITY},\ + {"NAS", DEBUG_NAS},\ + {"UE_TIMING", UE_TIMING},\ + {NULL,-1}\ + } @@ -178,51 +179,51 @@ extern "C" { typedef enum { - MIN_LOG_COMPONENTS = 0, - PHY = MIN_LOG_COMPONENTS, - MAC, - EMU, - SIM, - OCG, - OMG, - OPT, - OTG, - OTG_LATENCY, - OTG_LATENCY_BG, - OTG_GP, - OTG_GP_BG, - OTG_JITTER, - RLC, - PDCP, - RRC, - NAS, - PERF, - OIP, - CLI, - MSC, - OCM, - UDP_, - GTPU, - SPGW, - S1AP, - SCTP, - HW, - OSA, - RAL_ENB, - RAL_UE, - ENB_APP, - FLEXRAN_AGENT, - TMR, - USIM, - LOCALIZE, - X2AP, - GNB_APP, - NR_RRC, - NR_MAC, - NR_PHY, - LOADER, - ASN, - MAX_LOG_PREDEF_COMPONENTS, + MIN_LOG_COMPONENTS = 0, + PHY = MIN_LOG_COMPONENTS, + MAC, + EMU, + SIM, + OCG, + OMG, + OPT, + OTG, + OTG_LATENCY, + OTG_LATENCY_BG, + OTG_GP, + OTG_GP_BG, + OTG_JITTER, + RLC, + PDCP, + RRC, + NAS, + PERF, + OIP, + CLI, + MSC, + OCM, + UDP_, + GTPU, + SPGW, + S1AP, + SCTP, + HW, + OSA, + RAL_ENB, + RAL_UE, + ENB_APP, + FLEXRAN_AGENT, + TMR, + USIM, + LOCALIZE, + X2AP, + GNB_APP, + NR_RRC, + NR_MAC, + NR_PHY, + LOADER, + ASN, + MAX_LOG_PREDEF_COMPONENTS, } comp_name_t; @@ -231,42 +232,42 @@ comp_name_t; typedef struct { - char *name; /*!< \brief string name of item */ - int value; /*!< \brief integer value of mapping */ + char *name; /*!< \brief string name of item */ + int value; /*!< \brief integer value of mapping */ } mapping; typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap ); typedef int(*log_print_func_t)(FILE *stream, const char *format, ... ); typedef struct { - const char *name; - int level; - int savedlevel; - int flag; - int filelog; - char *filelog_name; - FILE *stream; - log_vprint_func_t vprint; - log_print_func_t print; - /* SR: make the log buffer component relative */ - char log_buffer[MAX_LOG_TOTAL]; + const char *name; + int level; + int savedlevel; + int flag; + int filelog; + char *filelog_name; + FILE *stream; + log_vprint_func_t vprint; + log_print_func_t print; + /* SR: make the log buffer component relative */ + char log_buffer[MAX_LOG_TOTAL]; } log_component_t; typedef struct { - log_component_t log_component[MAX_LOG_COMPONENTS]; - char level2string[NUM_LOG_LEVEL]; - int flag; - char* filelog_name; - uint64_t debug_mask; - uint64_t dump_mask; + log_component_t log_component[MAX_LOG_COMPONENTS]; + char level2string[NUM_LOG_LEVEL]; + int flag; + char *filelog_name; + uint64_t debug_mask; + uint64_t dump_mask; } log_t; #if defined(ENABLE_ITTI) typedef enum log_instance_type_e { - LOG_INSTANCE_UNKNOWN, - LOG_INSTANCE_ENB, - LOG_INSTANCE_UE, + LOG_INSTANCE_UNKNOWN, + LOG_INSTANCE_ENB, + LOG_INSTANCE_UE, } log_instance_type_t; void log_set_instance_type (log_instance_type_t instance); @@ -277,9 +278,9 @@ void log_set_instance_type (log_instance_type_t instance); log_t *g_log; #else #ifdef __cplusplus - extern "C" { +extern "C" { #endif -extern log_t *g_log; + extern log_t *g_log; #ifdef __cplusplus } #endif @@ -289,7 +290,7 @@ extern log_t *g_log; /*----------------------------------------------------------------------------*/ int logInit (void); void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7))); -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ); +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ); int set_log(int component, int level); void set_glog(int level); @@ -332,22 +333,22 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_CONFIG_DUMP_FORMAT "%s_dump" #define LOG_CONFIG_HELP_OPTIONS " list of comma separated options to enable log module behavior. Available options: \n"\ - " nocolor: disable color usage in log messages\n"\ - " level: add log level indication in log messages\n"\ - " thread: add threads names in log messages\n" - + " nocolor: disable color usage in log messages\n"\ + " level: add log level indication in log messages\n"\ + " thread: add threads names in log messages\n" + + - /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* LOG globalconfiguration parameters */ -/* optname help paramflags XXXptr defXXXval type numelt */ +/* LOG globalconfiguration parameters */ +/* optname help paramflags XXXptr defXXXval type numelt */ /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ #define LOG_GLOBALPARAMS_DESC { \ -{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ -} + {LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ + } #define LOG_OPTIONS_IDX 2 /*----------------------------------------------------------------------------------*/ @@ -359,23 +360,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_DUMP_DOUBLE 1 // debugging macros #define LOG_F LOG_I /* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */ -# if T_TRACER - /* per component, level dependant macros */ -# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) -# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) -# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) -# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) -# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) - /* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ +# if T_TRACER +/* per component, level dependant macros */ +# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) +# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) +# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) +# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) +# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) +/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ # define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0) /* */ # define nfapi_log(FILE, FNC, LN, COMP, LVL, F...) do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F) ;}} while (0) /* */ - /* bitmask dependant macros, to isolate debugging code */ +/* bitmask dependant macros, to isolate debugging code */ # define LOG_DEBUGFLAG(D) (g_log->debug_mask & D) - /* bitmask dependant macros, to generate debug file such as matlab file or message dump */ +/* bitmask dependant macros, to generate debug file such as matlab file or message dump */ # define LOG_DUMPFLAG(D) (g_log->dump_mask & D) # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */ - /* define variable only used in LOG macro's */ +/* 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...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)/* */ @@ -385,15 +386,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int # define LOG_T(c, x...) /* */ # define LOG_DUMPMSG(c, b, s, x...) /* */ -# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) +# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) # define LOG_DEBUGFLAG(D) ( 0 ) -# define LOG_DUMPFLAG(D) ( 0 ) +# define LOG_DUMPFLAG(D) ( 0 ) # 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 */ -#define GCC_NOTUSED __attribute__((unused)) -#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B +#define GCC_NOTUSED __attribute__((unused)) +#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B /* unfiltered macros, usefull for simulators or messages at init time, before log is configured */ #define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) @@ -425,78 +426,82 @@ static __inline__ uint64_t rdtsc(void) { extern double cpuf; -static inline uint64_t checkTCPU(int timeout, char * file, int line) { - static __thread uint64_t lastCPUTime=0; - static __thread uint64_t last=0; - uint64_t cur=rdtsc(); - struct timespec CPUt; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); - uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; - double microCycles=(double)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) { - //struct timespec ts; - //clock_gettime(CLOCK_MONOTONIC, &ts); - printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, - duration, timeout, (long long)CPUTime-lastCPUTime ); - } - last=cur; - lastCPUTime=CPUTime; - return cur; +static inline uint64_t checkTCPU(int timeout, char *file, int line) { + static __thread uint64_t lastCPUTime=0; + static __thread uint64_t last=0; + uint64_t cur=rdtsc(); + struct timespec CPUt; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); + uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; + double microCycles=(double)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) { + //struct timespec ts; + //clock_gettime(CLOCK_MONOTONIC, &ts); + printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, + duration, timeout, (long long)CPUTime-lastCPUTime ); + } + + last=cur; + lastCPUTime=CPUTime; + return cur; } -static inline unsigned long long checkT(int timeout, char * file, int line) { - static __thread unsigned long long last=0; - unsigned long long cur=rdtsc(); - int microCycles=(int)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) - printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, - duration, timeout); - last=cur; - return cur; +static inline unsigned long long checkT(int timeout, char *file, int line) { + static __thread unsigned long long last=0; + unsigned long long cur=rdtsc(); + int microCycles=(int)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) + printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, + duration, timeout); + + last=cur; + return cur; } typedef struct m { - uint64_t iterations; - uint64_t sum; - uint64_t maxArray[11]; + uint64_t iterations; + uint64_t sum; + uint64_t maxArray[11]; } Meas; -static inline void printMeas(char * txt, Meas *M, int period) { - if (M->iterations%period == 0 ) { - char txt2[512]; - sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" - PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", - txt, - M->sum/M->iterations, - M->iterations, - M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], - M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); +static inline void printMeas(char *txt, Meas *M, int period) { + if (M->iterations%period == 0 ) { + char txt2[512]; + sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" + PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", + txt, + M->sum/M->iterations, + M->iterations, + M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], + M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); #if DISABLE_LOG_X - printf("%s",txt2); + printf("%s",txt2); #else - LOG_W(PHY, "%s",txt2); + LOG_W(PHY, "%s",txt2); #endif - } + } } -static inline int cmpint(const void* a, const void* b) { - uint64_t* aa=(uint64_t*)a; - uint64_t* bb=(uint64_t*)b; - return (int)(*aa-*bb); +static inline int cmpint(const void *a, const void *b) { + uint64_t *aa=(uint64_t *)a; + uint64_t *bb=(uint64_t *)b; + return (int)(*aa-*bb); } -static inline void updateTimes(uint64_t start, Meas *M, int period, char * txt) { - if (start!=0) { - uint64_t end=rdtsc(); - long long diff=(end-start)/(cpuf*1000); - M->maxArray[0]=diff; - M->sum+=diff; - M->iterations++; - qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); - printMeas(txt,M,period); - } +static inline void updateTimes(uint64_t start, Meas *M, int period, char *txt) { + if (start!=0) { + uint64_t end=rdtsc(); + long long diff=(end-start)/(cpuf*1000); + M->maxArray[0]=diff; + M->sum+=diff; + M->iterations++; + qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); + printMeas(txt,M,period); + } } #define check(a) do { checkT(a,__FILE__,__LINE__); } while (0) diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h index 6f34508c5a9023b23d3b15e4be9b036c09b2b06a..aa0003fd8a3fec2ca009b5e484463edf7444647a 100644 --- a/common/utils/threadPool/thread-pool.h +++ b/common/utils/threadPool/thread-pool.h @@ -92,7 +92,7 @@ static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) if (nf->outF == NULL) nf->outF = msg; - if (nf->inF) + if (nf->inF != NULL) nf->inF->next = msg; nf->inF = msg; @@ -103,7 +103,7 @@ static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { mutexlock(nf->lockF); - while(!nf->outF) + while(nf->outF == NULL) condwait(nf->notifF, nf->lockF); notifiedFIFO_elt_t *ret=nf->outF; @@ -124,8 +124,12 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) { notifiedFIFO_elt_t *ret=nf->outF; - if (ret!=NULL) + if (ret!=NULL) { + if (nf->outF==nf->outF->next) + LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n"); + nf->outF=nf->outF->next; + } if (nf->outF==NULL) nf->inF=NULL; diff --git a/common/utils/utils.h b/common/utils/utils.h index cfe3df34b9356e02fe33e050198af154b415a472..11db07056e0f81b8440ec7888b86005f13633363 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -3,6 +3,9 @@ #include <stdint.h> #include <sys/types.h> +#ifdef __cplusplus +extern "C" { +#endif void *calloc_or_fail(size_t size); void *malloc_or_fail(size_t size); @@ -14,4 +17,17 @@ int hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int siz char *itoa(int i); +#define findInList(keY, result, list, element_type) {\ + int i;\ + for (i=0; i<sizeof(list)/sizeof(element_type) ; i++)\ + if (list[i].key==keY) {\ + result=list[i].val;\ + break;\ + }\ + AssertFatal(i < sizeof(list)/sizeof(element_type), "List %s doesn't contain %s\n",#list, #keY); \ + } +#ifdef __cplusplus +} +#endif + #endif diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 402c3796877479df9dc771a18601e34e922e4f8f..10ee53667e77e58af61da1fb97cd29ec9323a0f6 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -138,13 +138,9 @@ PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, { PHY_VARS_NR_UE *ue; - - if (frame_parms!=(NR_DL_FRAME_PARMS *)NULL) { // if we want to give initial frame parms, allocate the PHY_VARS_UE structure and put them in - ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); - memset(ue,0,sizeof(PHY_VARS_NR_UE)); - memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); - } else ue = PHY_vars_UE_g[UE_id][0]; - + ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); + memset(ue,0,sizeof(PHY_VARS_NR_UE)); + memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); ue->Mod_id = UE_id; ue->mac_enabled = 1; // initialize all signal buffers @@ -160,6 +156,7 @@ PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, */ typedef struct syncData_s { + UE_nr_rxtx_proc_t *proc; PHY_VARS_NR_UE *UE; } syncData_t; @@ -167,18 +164,13 @@ static void UE_synch(void *arg) { syncData_t *syncD=(syncData_t *) arg; int i, hw_slot_offset; PHY_VARS_NR_UE *UE = syncD->UE; - int current_band = 0; - int current_offset = 0; sync_mode_t sync_mode = pbch; int CC_id = UE->CC_id; int freq_offset=0; UE->is_synchronized = 0; if (UE->UE_scan == 0) { - int ind; - get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); - LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], oai_exit, openair0_cfg[0].rx_num_channels); @@ -197,7 +189,6 @@ static void UE_synch(void *arg) { sync_mode = pbch; } else { - current_band=0; LOG_E(PHY,"Fixme!\n"); /* for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { @@ -245,11 +236,10 @@ static void UE_synch(void *arg) { break; */ - case pbch: LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); - if (nr_initial_sync( UE, UE->mode ) == 0) { + if (nr_initial_sync( syncD->proc, UE, UE->mode ) == 0) { freq_offset = UE->common_vars.freq_offset; // frequency offset computed with pss in initial sync hw_slot_offset = (UE->rx_offset<<1) / UE->frame_parms.samples_per_slot; LOG_I(PHY,"Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", @@ -374,10 +364,14 @@ void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req; - UE_mac->scheduled_response.slot = proc->nr_tti_rx; + UE_mac->scheduled_response.ul_config = NULL; + UE_mac->scheduled_response.tx_request = NULL; + UE_mac->scheduled_response.module_id = UE->Mod_id; + UE_mac->scheduled_response.CC_id = 0; + UE_mac->scheduled_response.frame = proc->frame_rx; + UE_mac->scheduled_response.slot = proc->nr_tti_rx; nr_ue_scheduled_response(&UE_mac->scheduled_response); //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); - printf("Processing slot %d\n",proc->nr_tti_rx); #ifdef UE_SLOT_PARALLELISATION phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); #else @@ -548,10 +542,6 @@ void *UE_thread(void *arg) { AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); notifiedFIFO_t nf; initNotifiedFIFO(&nf); - bool syncRunning=false; - notifiedFIFO_elt_t *syncMsg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); - syncData_t *syncD=(syncData_t *)NotifiedFifoData(syncMsg); - syncD->UE=UE; int nbSlotProcessing=0; int thread_idx=0; notifiedFIFO_elt_t *processingMsg[RX_NB_TH]; @@ -562,8 +552,13 @@ void *UE_thread(void *arg) { tmp->UE=UE; } + bool syncRunning=false; + notifiedFIFO_elt_t *syncMsg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); + syncData_t *syncD=(syncData_t *)NotifiedFifoData(syncMsg); + syncD->UE=UE; + syncD->proc=&((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc; const int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; - int absolute_slot=-1; + int absolute_slot, decoded_frame_rx=INT_MAX, trashed_frames=0; while (!oai_exit) { if (!syncD->UE->is_synchronized) { @@ -572,11 +567,14 @@ void *UE_thread(void *arg) { if (res) { syncRunning=false; - } else + } else { trashFrame(UE, ×tamp); + trashed_frames++; + } } else { readFrame(UE, ×tamp); pushTpool(Tpool, syncMsg); + trashed_frames=0; syncRunning=true; } @@ -588,7 +586,6 @@ void *UE_thread(void *arg) { syncInFrame(UE, ×tamp); UE->rx_offset=0; UE->time_sync_cell=0; - //printf("first stream frame rx %d\n",UE->proc.proc_rxtx[0].frame_rx); // read in first symbol AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == UE->rfdevice.trx_read_func(&UE->rfdevice, @@ -596,12 +593,21 @@ void *UE_thread(void *arg) { (void **)UE->common_vars.rxdata, UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, UE->frame_parms.nb_antennas_rx),""); + // we have the decoded frame index in the return of the synch process + // and we shifted above to the first slot of next frame + // the synch thread proc context is hard linked to regular processing thread context, thread id = 0 + UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc); + // shift the frame index with all the frames we trashed meanwhile we perform the synch search + proc->decoded_frame_rx=(proc->decoded_frame_rx + trashed_frames) % MAX_FRAME_NUMBER; + decoded_frame_rx=proc->decoded_frame_rx; + // we do ++ first in the regular processing, so it will be 0; + absolute_slot=decoded_frame_rx*nb_slot_frame + nb_slot_frame -1; continue; } absolute_slot++; thread_idx = absolute_slot % RX_NB_TH; - int slot_nr=absolute_slot % nb_slot_frame; + int slot_nr = absolute_slot % nb_slot_frame; UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[thread_idx]))->proc); // update thread index for received subframe proc->nr_tti_rx= slot_nr; @@ -611,6 +617,7 @@ void *UE_thread(void *arg) { proc->subframe_tx=proc->nr_tti_rx; proc->frame_rx = ( absolute_slot/nb_slot_frame ) % MAX_FRAME_NUMBER; proc->frame_tx = ( (absolute_slot + DURATION_RX_TO_TX) /nb_slot_frame ) % MAX_FRAME_NUMBER; + proc->decoded_frame_rx=-1; LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, thread_idx); for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) @@ -671,21 +678,37 @@ void *UE_thread(void *arg) { proc->timestamp_tx = timestamp+ (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; + notifiedFIFO_elt_t *res; if (getenv("RFSIMULATOR")) { // FixMe: Wait previous thread is done, because race conditions seems too bad // in case of actual RF board, the overlap between threads mitigate the issue - while (!tryPullTpool(&nf, Tpool)) { - nbSlotProcessing--; + // We must receive one message, that proves the slot processing is done + while ((res=tryPullTpool(&nf, Tpool)) == NULL) usleep(200); - } + + nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; } - while (nbSlotProcessing >= RX_NB_TH && !tryPullTpool(&nf, Tpool)) { + while (nbSlotProcessing >= RX_NB_TH && (res=tryPullTpool(&nf, Tpool)) != NULL ) { nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; + usleep(200); } + if ( decoded_frame_rx != proc->frame_rx && + ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) + LOG_E(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", + decoded_frame_rx, proc->frame_rx); + pushTpool(Tpool, processingMsg[thread_idx]); } // while !oai_exit @@ -704,23 +727,29 @@ void init_UE(int nb_inst) { struct sched_param sched; sched.sched_priority = sched_get_priority_max(SCHED_RR)-1; pthread_attr_setschedparam(&attr, &sched); - + for (inst=0; inst < nb_inst; inst++) { - // UE->rfdevice.type = NONE_DEV; - //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); - PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); nr_l3_init_ue(); nr_l2_init_ue(); - mac_inst = get_mac_inst(0); + mac_inst = get_mac_inst(inst); mac_inst->if_module = UE->if_inst; - UE->if_inst->scheduled_response = nr_ue_scheduled_response; - UE->if_inst->phy_config_request = nr_ue_phy_config_request; + + // Initial bandwidth part configuration -- full carrier bandwidth + mac_inst->initial_bwp_dl.bwp_id = 0; + mac_inst->initial_bwp_dl.location = 0; + mac_inst->initial_bwp_dl.scs = UE->frame_parms.subcarrier_spacing; + mac_inst->initial_bwp_dl.N_RB = UE->frame_parms.N_RB_DL; + mac_inst->initial_bwp_dl.cyclic_prefix = UE->frame_parms.Ncp; + + mac_inst->initial_bwp_ul.bwp_id = 0; + mac_inst->initial_bwp_ul.location = 0; + mac_inst->initial_bwp_ul.scs = UE->frame_parms.subcarrier_spacing; + mac_inst->initial_bwp_ul.N_RB = UE->frame_parms.N_RB_UL; + mac_inst->initial_bwp_ul.cyclic_prefix = UE->frame_parms.Ncp; + 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); - //UE = PHY_vars_UE_g[inst][0]; AssertFatal(0 == pthread_create(&threads[inst], &attr, UE_thread, diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index e6a97c8f287f1488e4bfcc75de544013cadeeb49..24f8d4eb0d54fb97b42bae8fe88180ec6b0259b9 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -196,7 +196,6 @@ int rx_input_level_dBm; //int number_of_cards = 1; static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; int16_t node_synch_ref[MAX_NUM_CCs]; uint32_t target_dl_mcs = 28; //maximum allowed mcs @@ -528,14 +527,6 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { /* Set some default values that may be overwritten while reading options */ frame_parms[CC_id] = (NR_DL_FRAME_PARMS *) calloc(sizeof(NR_DL_FRAME_PARMS),1); - config[CC_id] = (nfapi_nr_config_request_t *) calloc(sizeof(nfapi_nr_config_request_t),1); - config[CC_id]->subframe_config.numerology_index_mu.value =1; - config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD - config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL - config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; - config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; - config[CC_id]->sch_config.physical_cell_id.value = 0; - frame_parms[CC_id]->eutra_band = 78; frame_parms[CC_id]->frame_type = FDD; frame_parms[CC_id]->tdd_config = 3; @@ -550,24 +541,7 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { frame_parms[CC_id]->nb_antennas_tx = 1; frame_parms[CC_id]->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[CC_id]->numerology_index = 0; frame_parms[CC_id]->ttis_per_subframe = 1; @@ -759,20 +733,6 @@ int main( int argc, char **argv ) { else UE[CC_id]->mac_enabled = 1; - if (UE[CC_id]->mac_enabled == 0) { //set default UL parameters for testing mode - for (int i=0; i<NUMBER_OF_CONNECTED_eNB_MAX; i++) { - //UE[CC_id]->pusch_config_dedicated[i] = malloc(sizeof(PUSCH_CONFIG_DEDICATED)); - //UE[CC_id]->scheduling_request_config[i] = malloc(sizeof(SCHEDULING_REQUEST_CONFIG)); - /*UE[CC_id]->pusch_config_dedicated[i].betaOffset_ACK_Index = beta_ACK; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_RI_Index = beta_RI; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_CQI_Index = beta_CQI; - - UE[CC_id]->scheduling_request_config[i].sr_PUCCH_ResourceIndex = 0; - UE[CC_id]->scheduling_request_config[i].sr_ConfigIndex = 7+(0%3); - UE[CC_id]->scheduling_request_config[i].dsr_TransMax = sr_n4;*/ - } - } - UE[CC_id]->UE_scan = UE_scan; UE[CC_id]->UE_scan_carrier = UE_scan_carrier; UE[CC_id]->UE_fo_compensation = UE_fo_compensation; diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index df6b2f7282ad4ebd8664892260a8da7dd35a641d..8bc07936f6b776741fb0b73cb9e60e7581fe5be4 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -28,6 +28,7 @@ #include "PHY/defs_nr_UE.h" #include "SIMULATION/ETH_TRANSPORT/proto.h" #include <threadPool/thread-pool.h> +#include <openair2/LAYER2/NR_MAC_gNB/mac_proto.h> #if defined(ENABLE_ITTI) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index 986d423034002439a3e725a485f02fe0cfd30a47..b2be51f6a246189fce57b98d380951180d135c08 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -597,7 +597,8 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c AssertFatal( pdsch, "pdsch==0" ); pdsch->pmi_ext = (uint8_t*)malloc16_clear( fp->N_RB_DL ); - pdsch->llr[0] = (int16_t*)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); + pdsch->llr[0] = (int16_t*)malloc16_clear( (8*(3*8*6144))*sizeof(int16_t) ); + pdsch->layer_llr[0] = (int16_t*)malloc16_clear( (8*(3*8*6144))*sizeof(int16_t) ); pdsch->llr128 = (int16_t**)malloc16_clear( sizeof(int16_t*) ); // FIXME! no further allocation for (int16_t*)pdsch->llr128 !!! expect SIGSEGV // FK, 11-3-2015: this is only as a temporary pointer, no memory is stored there @@ -607,6 +608,7 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c pdsch->rxdataF_uespec_pilots = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->rxdataF_comp0 = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->rho = (int32_t**)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) ); + pdsch->dl_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_bf_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_bf_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); @@ -628,6 +630,7 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c pdsch->rxdataF_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); pdsch->rxdataF_uespec_pilots[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->N_RB_DL*12); pdsch->rxdataF_comp0[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); + pdsch->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->ofdm_symbol_size*7*2); pdsch->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); pdsch->dl_bf_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->ofdm_symbol_size*7*2); pdsch->dl_bf_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); @@ -724,22 +727,6 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, } } - // Channel estimates - for (eNB_id=0; eNB_id<7; eNB_id++) { - for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id] = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates_time[eNB_id] = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); - } - - for (i=0; i<fp->nb_antennas_rx; i++) - for (j=0; j<4; j++) { - int idx = (j<<1) + i; - for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) ); - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates_time[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 ); - } - } - } // DLSCH for (eNB_id=0; eNB_id<ue->n_connected_eNB; eNB_id++) { @@ -766,7 +753,8 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { (*pdsch_vars_th)[th_id][eNB_id]->llr_shifts = (uint8_t*)malloc16_clear(7*2*fp->N_RB_DL*12); (*pdsch_vars_th)[th_id][eNB_id]->llr_shifts_p = (*pdsch_vars_th)[0][eNB_id]->llr_shifts; - (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*((3*8*8448)+12))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->layer_llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); (*pdsch_vars_th)[th_id][eNB_id]->llr128_2ndstream = (int16_t**)malloc16_clear( sizeof(int16_t*) ); (*pdsch_vars_th)[th_id][eNB_id]->rho = (int32_t**)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) ); } @@ -832,30 +820,32 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, (*pdcch_vars_th)[th_id][eNB_id]->rho = (int32_t**)malloc16( fp->nb_antennas_rx*sizeof(int32_t*) ); (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); - } - - for (i=0; i<fp->nb_antennas_rx; i++) { - //ue_pdcch_vars[eNB_id]->rho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(fp->N_RB_DL*12*7*2) ); - for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { - (*pdcch_vars_th)[th_id][eNB_id]->rho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(100*12*4) ); - } - for (j=0; j<4; j++) { //fp->nb_antennas_tx; j++) - int idx = (j<<1)+i; - // size_t num = 7*2*fp->N_RB_DL*12; - size_t num = 4*100*12; // 4 symbols, 100 PRBs, 12 REs per PRB - for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { + // Channel estimates + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_time = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); + + for (i=0; i<fp->nb_antennas_rx; i++) { + (*pdcch_vars_th)[th_id][eNB_id]->rho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(100*12*4) ); + for (j=0; j<4; j++) { + int idx = (j<<1) + i; + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) ); + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_time[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 ); + + // size_t num = 7*2*fp->N_RB_DL*12; + size_t num = 4*273*12; // 4 symbols, 100 PRBs, 12 REs per PRB (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_comp[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_rho_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); - } - } + } + } } // PBCH pbch_vars[eNB_id]->rxdataF_ext = (int32_t**)malloc16( fp->nb_antennas_rx*sizeof(int32_t*) ); pbch_vars[eNB_id]->rxdataF_comp = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); + pbch_vars[eNB_id]->dl_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pbch_vars[eNB_id]->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pbch_vars[eNB_id]->llr = (int16_t*)malloc16_clear( 1920 );// prach_vars[eNB_id]->prachF = (int16_t*)malloc16_clear( sizeof(int)*(7*2*sizeof(int)*(fp->ofdm_symbol_size*12)) ); @@ -867,6 +857,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, for (j=0; j<4; j++) {//fp->nb_antennas_tx;j++) { int idx = (j<<1)+i; pbch_vars[eNB_id]->rxdataF_comp[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*20*12*4 ); + pbch_vars[eNB_id]->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*7*2*sizeof(int)*(fp->ofdm_symbol_size) ); pbch_vars[eNB_id]->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*20*12*4 ); } } @@ -887,7 +878,8 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, if (abstraction_flag == 0) { for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) { //phy_init_lte_ue__PDSCH( (*pdsch_vars_th)[th_id][eNB_id], fp ); - (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*((3*8*8448)+12))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->layer_llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); } } else { //abstraction == 1 diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index a82880400217bca31c26c0a294b641fc980941bb..5c38ab3056689e436c5dd12116350ba4943bda69 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -245,13 +245,6 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, else fp->Lmax = 64; - // Initial bandwidth part configuration -- full carrier bandwidth - fp->initial_bwp_dl.bwp_id = 0; - fp->initial_bwp_dl.scs = fp->subcarrier_spacing; - fp->initial_bwp_dl.location = 0; - fp->initial_bwp_dl.N_RB = fp->N_RB_DL; - fp->initial_bwp_dl.cyclic_prefix = fp->Ncp; - fp->initial_bwp_dl.ofdm_symbol_size = fp->ofdm_symbol_size; return 0; } @@ -293,12 +286,6 @@ void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp) LOG_I(PHY,"fp->samples_per_frame_wCP=%d\n",fp->samples_per_frame_wCP); LOG_I(PHY,"fp->samples_per_subframe=%d\n",fp->samples_per_subframe); LOG_I(PHY,"fp->samples_per_frame=%d\n",fp->samples_per_frame); - LOG_I(PHY,"fp->initial_bwp_dl.bwp_id=%d\n",fp->initial_bwp_dl.bwp_id); - LOG_I(PHY,"fp->initial_bwp_dl.scs=%d\n",fp->initial_bwp_dl.scs); - LOG_I(PHY,"fp->initial_bwp_dl.N_RB=%d\n",fp->initial_bwp_dl.N_RB); - LOG_I(PHY,"fp->initial_bwp_dl.cyclic_prefix=%d\n",fp->initial_bwp_dl.cyclic_prefix); - LOG_I(PHY,"fp->initial_bwp_dl.location=%d\n",fp->initial_bwp_dl.location); - LOG_I(PHY,"fp->initial_bwp_dl.ofdm_symbol_size=%d\n",fp->initial_bwp_dl.ofdm_symbol_size); } diff --git a/openair1/PHY/MODULATION/modulation_UE.h b/openair1/PHY/MODULATION/modulation_UE.h index 63c3637886e8245eae25a612c26c209ec21ee682..2bb04bd43ae62f11c0598913460b0bde528079e2 100644 --- a/openair1/PHY/MODULATION/modulation_UE.h +++ b/openair1/PHY/MODULATION/modulation_UE.h @@ -52,8 +52,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *phy_vars_ue, unsigned char l, unsigned char Ns, int sample_offset, - int no_prefix, - NR_CHANNEL_EST_t channel); + int no_prefix); int slot_fep_mbsfn(PHY_VARS_UE *phy_vars_ue, unsigned char l, diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c index 6ce486e3a0747c7578112ab5b8c969b3c5d5e6fe..c6a6d93c185f64351179c84ede06a4986bbe6a05 100644 --- a/openair1/PHY/MODULATION/slot_fep_nr.c +++ b/openair1/PHY/MODULATION/slot_fep_nr.c @@ -35,16 +35,14 @@ #endif*/ int nr_slot_fep(PHY_VARS_NR_UE *ue, - unsigned char l, + unsigned char symbol, unsigned char Ns, int sample_offset, - int no_prefix, - NR_CHANNEL_EST_t channel) + int no_prefix) { NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; NR_UE_COMMON *common_vars = &ue->common_vars; unsigned char aa; - unsigned char symbol = l;//+((7-frame_parms->Ncp)*(Ns&1)); ///symbol within sub-frame unsigned int nb_prefix_samples; unsigned int nb_prefix_samples0; if (ue->is_synchronized) { @@ -60,19 +58,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, //int i; unsigned int frame_length_samples = frame_parms->samples_per_subframe * 10; unsigned int rx_offset; - NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[Ns]][0]; - uint16_t coreset_start_subcarrier = frame_parms->first_carrier_offset;//+((int)floor(frame_parms->ssb_start_subcarrier/NR_NB_SC_PER_RB)+pdcch_vars->coreset[0].rb_offset)*NR_NB_SC_PER_RB; - uint16_t nb_rb_coreset = 0; - uint16_t bwp_start_subcarrier = frame_parms->first_carrier_offset;//+516; - uint16_t nb_rb_pdsch = 50; - uint8_t p=0; - uint8_t l0 = pdcch_vars->coreset[0].duration; - uint64_t coreset_freq_dom = pdcch_vars->coreset[0].frequencyDomainResources; - for (int i = 0; i < 45; i++) { - if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> i) & 0x1) nb_rb_coreset++; - } - nb_rb_coreset = 6 * nb_rb_coreset; - //printf("corset duration %d nb_rb_coreset %d\n", l0, nb_rb_coreset); + void (*dft)(int16_t *,int16_t *, int); int tmp_dft_in[8192] __attribute__ ((aligned (32))); // This is for misalignment issues for 6 and 15 PRBs @@ -146,7 +132,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, nb_prefix_samples,nb_prefix_samples0,slot_offset,sample_offset,rx_offset,frame_length_samples); #endif - if (l==0) { + if (symbol==0) { if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) memcpy((short *)&common_vars->rxdata[aa][frame_length_samples], @@ -171,7 +157,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, #endif } } else { - rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// + + rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*symbol;// + // (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1); if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) @@ -206,68 +192,6 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, #endif } - if (ue->perfect_ce == 0) { - - switch(channel){ - case NR_PBCH_EST: - break; - - case NR_PDCCH_EST: - -#ifdef DEBUG_FEP - printf("PDCCH Channel estimation aatx %d, slot %d, symbol %d start_sc %d\n",aa,Ns,l,coreset_start_subcarrier); -#endif -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); -#endif - nr_pdcch_channel_estimation(ue,0, - Ns, - l, - symbol, - coreset_start_subcarrier, - nb_rb_coreset); -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); -#endif - - break; - - case NR_PDSCH_EST: -#ifdef DEBUG_FEP - printf("Channel estimation aatx %d, slot %d, symbol %d\n",aa,Ns,l); -#endif -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); -#endif - - ue->frame_parms.nushift = (p>>1)&1;; - - if (symbol ==l0) - nr_pdsch_channel_estimation(ue,0, - Ns, - p, - l, - symbol, - bwp_start_subcarrier, - nb_rb_pdsch); - -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); -#endif - - break; - - case NR_SSS_EST: - break; - - default: - LOG_E(PHY,"[UE][FATAL] Unknown channel format %d\n",channel); - return(-1); - break; - } - - } - #ifdef DEBUG_FEP printf("slot_fep: done\n"); #endif diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c index 06c0e30bde000d87ae471d32ba227437f1dbfc66..e4bec93ddf9b1ec1855fb149313de76894e2e1aa 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c @@ -46,7 +46,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m uint8_t bsize = pdcch_params->reg_bundle_size; uint8_t R = pdcch_params->interleaver_size; uint16_t N_reg = pdcch_params->n_rb * pdcch_params->n_symb; - uint16_t Y, N_cce, M_s_max, n_CI=0, tmp, C; + uint16_t Y, N_cce, M_s_max, n_CI=0, tmp, C=0; uint16_t n_RNTI = (pdcch_params->search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? pdcch_params->rnti:0; uint32_t A[3]={39827,39829,39839}; @@ -64,7 +64,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m } if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) { - AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %d, bsize %d R %d)\n", + AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n", N_reg, bsize, R); C = N_reg/(bsize*R); } diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c index a881ae539e776d6218a8d1f69487108fcd0680cc..48cd97809a882ae61df7b782a3b37edd8a24854d 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c @@ -233,7 +233,7 @@ printf("\n"); for (int q=0; q<rel15->nb_codewords; q++) memset((void*)scrambled_output[q], 0, (encoded_length>>5)*sizeof(uint32_t)); uint16_t n_RNTI = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? \ - ((pdcch_params.scrambling_id)?pdcch_params.rnti:0) : 0; + ((pdcch_params.scrambling_id==0)?pdcch_params.rnti:0) : 0; uint16_t Nid = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? \ pdcch_params.scrambling_id : config.sch_config.physical_cell_id.value; for (int q=0; q<rel15->nb_codewords; q++) diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c index f3cd1a29f30ce0f01425eed823ded7e3b553d0cf..24ca3d1ad6f007e04e347862d8ae06a7d39af55b 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c @@ -60,8 +60,8 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, temp = 0; for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) { - Re = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[(i<<1)]; - Im = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[1+(i<<1)]; + Re = ((int16_t*)ue->pdcch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time[aa])[(i<<1)]; + Im = ((int16_t*)ue->pdcch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time[aa])[1+(i<<1)]; temp += (Re*Re/2) + (Im*Im/2); } diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c index 917734f8ecd2cb8fe753b3457dccc3b656663de1..0ab83712d8e44863415a722f80a03bf140045cc0 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -22,12 +22,10 @@ #include <string.h> -//#include "defs.h" -//#include "SCHED/defs.h" -#include "PHY/defs_nr_UE.h" +#include "nr_estimation.h" #include "PHY/NR_REFSIG/refsig_defs_ue.h" #include "filt16a_32.h" -#include "T.h" + //#define DEBUG_PDSCH //#define DEBUG_PDCCH @@ -211,7 +209,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; uint8_t nushift; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pbch_vars[eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = ue->frame_parms.Nid_cell%4; @@ -413,7 +411,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol, unsigned short coreset_start_subcarrier, unsigned short nb_rb_coreset) @@ -428,7 +425,7 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; uint8_t nushift; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = 1; @@ -616,16 +613,16 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, break; } - if( (Ns== 1) && (l == 0)) + if( (Ns== 1) && (symbol == 0)) { // do ifft of channel estimate for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) for (p=0; p<ue->frame_parms.nb_antenna_ports_eNB; p++) { - if (ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset][(p<<1)+aarx]) + if (ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates[(p<<1)+aarx]) { - LOG_D(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns], l); - idft((int16_t*) &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset][(p<<1)+aarx][0], - (int16_t*) ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates_time[eNB_offset][(p<<1)+aarx],1); + LOG_D(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns], symbol); + idft((int16_t*) &ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates[(p<<1)+aarx][0], + (int16_t*) ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates_time[(p<<1)+aarx],1); } } } @@ -634,13 +631,12 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, } int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_offset, - unsigned char Ns, - unsigned short p, - unsigned char l, - unsigned char symbol, - unsigned short bwp_start_subcarrier, - unsigned short nb_rb_pdsch) + uint8_t eNB_offset, + unsigned char Ns, + unsigned short p, + unsigned char symbol, + unsigned short bwp_start_subcarrier, + unsigned short nb_rb_pdsch) { int pilot[1320] __attribute__((aligned(16))); unsigned char aarx; @@ -652,7 +648,7 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; uint8_t nushift; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pdsch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = (p>>1)&1; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 29400bbdc7ffb5e5ce254407ce2a8b72956b8463..1a4250028e54625f493ffec1955780977919f267 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -45,7 +45,6 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol, unsigned short coreset_start_subcarrier, unsigned short nb_rb_coreset); @@ -69,7 +68,6 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned short p, - unsigned char l, unsigned char symbol, unsigned short bwp_start_subcarrier, unsigned short nb_rb_pdsch); diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index e280fcbdf7701e2e87e7c892f7c359f2185e29f6..f01a5ef60a6d8bb7fd85cdd2c7010609832d834a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -843,7 +843,7 @@ int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue, printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in nr_pdcch_extract_rbs_single(rxdataF -> rxdataF_ext || dl_ch_estimates -> dl_ch_estimates_ext)\n"); #endif nr_pdcch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdcch_vars[eNB_id]->dl_ch_estimates, pdcch_vars[eNB_id]->rxdataF_ext, pdcch_vars[eNB_id]->dl_ch_estimates_ext, s, diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index c0671428971ab75f95037f7432e9e9c5b6857da6..47409d2102b6e799c4e389fe9faedbf51b6f6e36 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -52,7 +52,7 @@ //#define DEBUG_DCI #define NR_PDCCH_DCI_TOOLS -//#define NR_PDCCH_DCI_TOOLS_DEBUG +#define NR_PDCCH_DCI_TOOLS_DEBUG typedef unsigned __int128 uint128_t; @@ -95,11 +95,8 @@ int nr_extract_dci_info(PHY_VARS_NR_UE *ue, uint8_t dci_length, uint16_t rnti, uint64_t dci_pdu[2], - NR_DCI_INFO_EXTRACTED_t *nr_pdci_info_extracted, + fapi_nr_dci_pdu_rel15_t *nr_pdci_info_extracted, uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], - NR_DL_UE_HARQ_t *pdlsch0_harq, - NR_UE_DLSCH_t *pdlsch0, - NR_UE_ULSCH_t *ulsch0, NR_DCI_format_t dci_format, uint8_t nr_tti_rx, uint16_t n_RB_ULBWP, @@ -631,7 +628,7 @@ int nr_extract_dci_info(PHY_VARS_NR_UE *ue, case TB1_MCS: // 18 TB1_MCS: (field defined for -,-,-,format1_1,-,-,-,-) nr_pdci_info_extracted->tb1_mcs = (uint8_t)nr_dci_field(dci_pdu,dci_fields_sizes_format,dci_field); //(((((*(uint128_t *)dci_pdu) << (left_shift - dci_fields_sizes[dci_field][dci_format]))) & pdu_bitmap) >> (dci_length - dci_fields_sizes[dci_field][dci_format])); - if (nr_pdci_info_extracted->mcs < 29) pdlsch0_harq->mcs = nr_pdci_info_extracted->tb1_mcs; + //if (nr_pdci_info_extracted->mcs < 29) pdlsch0_harq->mcs = nr_pdci_info_extracted->tb1_mcs; #ifdef NR_PDCCH_DCI_TOOLS_DEBUG printf("\t\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_extract_dci_info) -> nr_pdci_info_extracted->tb1_mcs=%x\n",nr_pdci_info_extracted->tb1_mcs); #endif @@ -1025,98 +1022,50 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint16_t rnti, uint8_t dci_length, NR_DCI_format_t dci_format, - NR_UE_PDCCH *pdcch_vars, - NR_UE_PDSCH *pdsch_vars, - NR_UE_DLSCH_t **dlsch, - NR_UE_ULSCH_t *ulsch, NR_DL_FRAME_PARMS *frame_parms, PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated, - uint8_t beamforming_mode, uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], uint16_t n_RB_ULBWP, uint16_t n_RB_DLBWP, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES], - NR_DCI_INFO_EXTRACTED_t *nr_dci_info_extracted) + fapi_nr_dci_pdu_rel15_t *nr_dci_info_extracted) { /* * Note only format0_0 and format1_0 are implemented */ - //uint8_t harq_pid=0; uint8_t frame_type=frame_parms->frame_type; - //uint8_t tpmi=0; - NR_UE_DLSCH_t *dlsch0=NULL;//*dlsch1=NULL; - NR_DL_UE_HARQ_t *dlsch0_harq=NULL;//*dlsch1_harq=NULL; - NR_UE_ULSCH_t *ulsch0=NULL;//*ulsch1=NULL; - - - NR_DCI_INFO_EXTRACTED_t *ptr_nr_dci_info_extracted = nr_dci_info_extracted; - - uint8_t status=0; - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n", - dci_format,rnti,dci_length,dci_pdu[0],dci_pdu[1]); - #endif - + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_format,rnti,dci_length,dci_pdu[0],dci_pdu[1]); -// uint8_t dci_fields_sizes_format[NBR_NR_DCI_FIELDS] ={0}; -// for (int m=0; m<NBR_NR_DCI_FIELDS; m++) dci_fields_sizes_format[m]=dci_fields_sizes[m][dci_format]; -/* - dlsch0 = dlsch[0]; - dlsch0->active = 0; - if (dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format] != 0) { // 27 HARQ_PROCESS_NUMBER (27 is the position in dci_fields_sizes array for field HARQ_PROCESS_NUMBER) - //for (int i=0; i<=HARQ_PROCESS_NUMBER; i++) left_shift = left_shift + dci_fields_sizes[i][dci_format]; - nr_dci_info_extracted->harq_process_number = (uint8_t)nr_dci_field(dci_pdu,dci_fields_sizes_format,HARQ_PROCESS_NUMBER); - //(((((*(uint128_t *)dci_pdu) << (left_shift - dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format]))) & pdu_bitmap) >> (dci_length - dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format])); - //left_shift = 0; - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> nr_dci_info_extracted->harq_process_number=%x\n",nr_dci_info_extracted->harq_process_number); - for (int i=0; i<1000; i++) printf("%d",i); - #endif - } + memset(nr_dci_info_extracted,0,sizeof(*nr_dci_info_extracted)); + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Entering function nr_extract_dci_info(dci_format=%d) \n",dci_format); - dlsch0_harq = dlsch[0]->harq_processes[nr_dci_info_extracted->harq_process_number]; - ulsch0 = ulsch; - //printf("nr_dci_info_extracted.harq_process_number = %d\n",nr_dci_info_extracted.harq_process_number); - //printf("dlsch0 = %d\n",dlsch0); - //printf("dlsch0_harq = %d\n",dlsch0_harq); - - if (!dlsch[0]) return -1; - if (!ulsch) return -1; -*/ - memset(&nr_dci_info_extracted,0,sizeof(nr_dci_info_extracted)); -// printf("we reach this point\n"); - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Entering function nr_extract_dci_info(dci_format=%d) \n",dci_format); - #endif status = nr_extract_dci_info(ue, eNB_id, frame_type, dci_length, rnti, dci_pdu, - ptr_nr_dci_info_extracted,//&nr_dci_info_extracted, + nr_dci_info_extracted,//&nr_dci_info_extracted, dci_fields_sizes, - dlsch0_harq, - dlsch0, - ulsch0, dci_format, nr_tti_rx, n_RB_ULBWP, n_RB_DLBWP, crc_scrambled_values); - //printf("\n>>> inside nr_generate_ue_ul_dlsch_params_from_dci after nr_extract_dci_info: mcs=%d\n",nr_dci_info_extracted->mcs); - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - if(status == 0) { - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> bad DCI %d !!! \n",dci_format); - return(-1); - } - //printf("\n>>> inside nr_generate_ue_ul_dlsch_params_from_dci after nr_extract_dci_info: modified mcs=%d \n",nr_dci_info_extracted->mcs); - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Ending function nr_extract_dci_info()\n"); - #endif + + if(status == 0) { + LOG_W(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> bad DCI %d !!! \n",dci_format); + return(-1); + } + + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Ending function nr_extract_dci_info()\n"); + + //fill + return(0); } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index 19d8a1da214e75273d20492ea730cf6715ea7c6e..c99d2ea61be5101489b7af378047a02995dbfc5e 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -131,11 +131,15 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, unsigned short nb_rb_pdsch = 50; int16_t *pllr_symbol_cw0; int16_t *pllr_symbol_cw1; + int16_t *pllr_symbol_layer0; + int16_t *pllr_symbol_layer1; //int16_t *pllr_symbol_cw0_deint; //int16_t *pllr_symbol_cw1_deint; uint32_t llr_offset_symbol; //uint16_t bundle_L = 2; uint8_t l0 =2; + uint16_t n_tx=1, n_rx=1; + int32_t median[16]; switch (type) { case SI_PDSCH: @@ -279,7 +283,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #ifdef DEBUG_HARQ printf("Demod dlsch0_harq->pmi_alloc %d\n", dlsch0_harq->pmi_alloc); #endif -#if 0 + if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) { #ifdef DEBUG_DLSCH_MOD LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]); @@ -288,14 +292,16 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #if UE_TIMING_TRACE start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, @@ -307,42 +313,42 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, printf("\n"); #endif - if (rx_type >= rx_IC_single_stream) { if (eNB_id_i<ue->n_connected_eNB) // we are in TM5 - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id_i], + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id_i]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, dlsch0_harq->mimo_mode); else - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id_i]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, dlsch0_harq->mimo_mode); } - } else - -#endif - if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0 + } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0 //printf("start nr dlsch extract nr_tti_rx %d thread id %d \n", nr_tti_rx, ue->current_thread_id[nr_tti_rx]); nb_rb = nr_dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, @@ -418,8 +424,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #if UE_TIMING_TRACE start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif - aatx = frame_parms->nb_antenna_ports_eNB; - aarx = frame_parms->nb_antennas_rx; + n_tx = frame_parms->nb_antenna_ports_eNB; + n_rx = frame_parms->nb_antennas_rx; + nb_re= (symbol==l0)? (nb_rb*6):(nb_rb*12); nr_dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, @@ -466,36 +473,29 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, avgs = cmax(avgs,avg[(aatx<<1)+aarx]); pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1; - }/* + } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { - dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext, - frame_parms, - pdsch_vars[eNB_id]->pmi_ext, - avg_0, - avg_1, - symbol, - nb_rb, - dlsch0_harq->mimo_mode); - - LOG_D(PHY,"Channel Level TM34 avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0], - avg_1[0], rx_type, rx_standard, dlsch_demod_shift); - if (rx_type>rx_standard) { - avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; - avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; - pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); - pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); - // printf("dlsch_demod_shift %d\n", dlsch_demod_shift); - } - else { - avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift; - avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift; - pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); - pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); - } - } + nr_dlsch_channel_level_median(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + median, + n_tx, + n_rx, + 2*nb_re,// subcarriers Re Im + 0); + + for (aatx = 0; aatx < n_tx; ++aatx) + { + for (aarx = 0; aarx < n_rx; ++aarx) + { + avgs = cmax(avgs, median[aatx*n_rx + aarx]); + } + } + + pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1; // this might need to be tuned + + }/* else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6) if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext, @@ -629,22 +629,20 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, }*/ } -#if 0 else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ - dlsch_channel_compensation_TM34(frame_parms, - pdsch_vars[eNB_id], - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - dlsch1_harq->Qm, - harq_pid, - dlsch0_harq->round, - dlsch0_harq->mimo_mode, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh0, - pdsch_vars[eNB_id]->log2_maxh1); + nr_dlsch_channel_compensation_core(pdsch_vars[eNB_id]->rxdataF_ext, + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + pdsch_vars[eNB_id]->rxdataF_comp0, //rxdataF_comp + NULL, + n_tx, + n_rx, + dlsch0_harq->Qm, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, // subcarriers Re Im + 0); // we start from the beginning of the vector /* if (symbol == 5) { write_output("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM write_output("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 @@ -652,22 +650,23 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, write_output("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM } */ // compute correlation between signal and interference channels (rho12 and rho21) - dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22 - symbol, - nb_rb, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->log2_maxh0); + nr_dlsch_dual_stream_correlation_core(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + n_tx, + n_rx, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, + 0); //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] ); - //to be optimized (just take complex conjugate) - dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21 - symbol, - nb_rb, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->log2_maxh1); + nr_dlsch_dual_stream_correlation_core(&(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + n_tx, + n_rx, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, + 0); // printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext ); //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh); /* if (symbol == 5) { @@ -677,105 +676,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, write_output("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM } */ - } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6) - if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->pmi_ext, - frame_parms, - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - dlsch0_harq->dl_power_off); - - for (rb=0; rb<nb_rb; rb++) { - switch(pdsch_vars[eNB_id]->pmi_ext[rb]) { - case 0: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=1; - break; - case 1: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=0; - break; - case 2: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=3; - break; - case 3: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=2; - break; - } - // if (rb==0) - // printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]); - } - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext, - pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, - pdsch_vars[eNB_id_i]->dl_ch_mag0, - pdsch_vars[eNB_id_i]->dl_ch_magb0, - pdsch_vars[eNB_id_i]->rxdataF_comp0, - pdsch_vars[eNB_id_i]->pmi_ext, - frame_parms, - measurements, - eNB_id_i, - symbol, - i_mod, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - dlsch0_harq->dl_power_off); -#ifdef DEBUG_PHY - if (symbol==5) { - write_output("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); - write_output("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); - } -#endif - dlsch_dual_stream_correlation(frame_parms, - symbol, - nb_rb, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->log2_maxh); - } else if (dlsch0_harq->dl_power_off==1) { - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->pmi_ext, - frame_parms, - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - 1); - - } - - - } else if (dlsch0_harq->mimo_mode==TM7) { //TM7 - - nr_dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL, - frame_parms, - symbol, - first_symbol_flag, - get_Qm(dlsch0_harq->mcs), - nb_rb, - //9, - pdsch_vars[eNB_id]->log2_maxh, - measurements); // log2_maxh+I0_shift - } -#endif + } #if UE_TIMING_TRACE stop_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); @@ -790,39 +691,29 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif -#if 0 if (frame_parms->nb_antennas_rx > 1) { if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ // TM3 or TM4 - if (frame_parms->nb_antenna_ports_eNB == 2) { - dlsch_detection_mrc_TM34(frame_parms, - pdsch_vars[eNB_id], - harq_pid, - dlsch0_harq->round, - symbol, - nb_rb, - 1); + nr_dlsch_detection_mrc_core(pdsch_vars[eNB_id]->rxdataF_comp0, + NULL, + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + NULL, + NULL, + n_tx, + n_rx, + 2*nb_re, + 0); /* if (symbol == 5) { write_output("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM write_output("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 } */ - } - } else { - dlsch_detection_mrc(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id_i]->rxdataF_comp0, - pdsch_vars[eNB_id]->rho, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id_i]->dl_ch_mag0, - pdsch_vars[eNB_id_i]->dl_ch_magb0, - symbol, - nb_rb, - rx_type==rx_IC_single_stream); } } +#if 0 // printf("Combining"); if ((dlsch0_harq->mimo_mode == SISO) || ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) && @@ -878,12 +769,15 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol-1]; //pllr_symbol_cw0_deint = (int8_t*)pdsch_vars[eNB_id]->llr[0]; //pllr_symbol_cw1_deint = (int8_t*)pdsch_vars[eNB_id]->llr[1]; + pllr_symbol_layer0 = pdsch_vars[eNB_id]->layer_llr[0]; + pllr_symbol_layer1 = pdsch_vars[eNB_id]->layer_llr[1]; + pllr_symbol_layer0 += llr_offset_symbol; + pllr_symbol_layer1 += llr_offset_symbol; pllr_symbol_cw0 = pdsch_vars[eNB_id]->llr[0]; pllr_symbol_cw1 = pdsch_vars[eNB_id]->llr[1]; pllr_symbol_cw0 += llr_offset_symbol; pllr_symbol_cw1 += llr_offset_symbol; - nb_re= (symbol==l0)? (nb_rb*6):(nb_rb*12); pdsch_vars[eNB_id]->llr_offset[symbol] = nb_re*dlsch0_harq->Qm + llr_offset_symbol; /*LOG_I(PHY,"compute LLRs [symbol %d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %x @LLR Buff(symb) %x\n", @@ -929,7 +823,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, rxdataF_comp_ptr, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -938,7 +832,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -950,7 +844,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -960,7 +854,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -972,7 +866,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -982,7 +876,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1015,7 +909,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1025,7 +919,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1038,7 +932,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1049,7 +943,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1062,7 +956,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1073,7 +967,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1108,7 +1002,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1118,7 +1012,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1131,7 +1025,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1142,7 +1036,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1155,7 +1049,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - (int16_t*)pllr_symbol_cw0, + (int16_t*)pllr_symbol_layer0, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); @@ -1166,7 +1060,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pllr_symbol_cw1, + pllr_symbol_layer1, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); @@ -1222,6 +1116,13 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, //nr_dlsch_deinterleaving(symbol,bundle_L,(int16_t*)pllr_symbol_cw0,(int16_t*)pllr_symbol_cw0_deint, nb_rb_pdsch); + if (rx_type==rx_IC_dual_stream) { + nr_dlsch_layer_demapping(pdsch_vars[eNB_id]->llr, + dlsch[0]->harq_processes[harq_pid]->Nl, + dlsch[0]->harq_processes[harq_pid]->G, + pdsch_vars[eNB_id]->layer_llr); + } + #if UE_TIMING_TRACE stop_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #if DISABLE_LOG_X @@ -1382,10 +1283,10 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, // get channel amplitude if not QPSK mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); - mmtmpD0 = _mm_srai_epi32(mmtmpD0,(output_shift-2)); + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); - mmtmpD1 = _mm_srai_epi32(mmtmpD1,(output_shift-2)); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); @@ -1793,6 +1694,209 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, #endif } +void nr_dlsch_channel_compensation_core(int **rxdataF_ext, + int **dl_ch_estimates_ext, + int **dl_ch_mag, + int **dl_ch_magb, + int **rxdataF_comp, + int **rho, + unsigned char n_tx, + unsigned char n_rx, + unsigned char mod_order, + unsigned char output_shift, + int length, + int start_point) + +{ + + unsigned short ii; + int length_mod8 = 0; + int length2; + __m128i *dl_ch128,*dl_ch_mag128,*dl_ch_mag128b, *dl_ch128_2, *rxdataF128,*rxdataF_comp128,*rho128; + __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b; + int aatx = 0, aarx = 0; + + for (aatx=0; aatx<n_tx; aatx++) { + + if (mod_order == 4) { + QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10) + QAM_amp128b = _mm_setzero_si128(); + } else if (mod_order == 6) { + QAM_amp128 = _mm_set1_epi16(QAM64_n1); // + QAM_amp128b = _mm_set1_epi16(QAM64_n2); + } + + for (aarx=0; aarx<n_rx; aarx++) { + /* TODO: hack to be removed. There is crash for 1 antenna case, so + * for 1 antenna case, I put back the value 2 as it was before + * Elena's commit. + */ + int x = n_rx > 1 ? n_rx : 2; + + dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point]; + dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point]; + dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point]; + rxdataF128 = (__m128i *)&rxdataF_ext[aarx][start_point]; + rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point]; + + length_mod8 = length&7; + if (length_mod8 == 0){ + length2 = length>>3; + + for (ii=0; ii<length2; ++ii) { + if (mod_order>2) { + // get channel amplitude if not QPSK + + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + + mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + + mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); + + // store channel magnitude here in a new field of dlsch + + dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); + dl_ch_mag128b[0] = dl_ch_mag128[0]; + dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128); + dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1); + //print_ints("Re(ch):",(int16_t*)&mmtmpD0); + //print_shorts("QAM_amp:",(int16_t*)&QAM_amp128); + //print_shorts("mag:",(int16_t*)&dl_ch_mag128[0]); + dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0); + dl_ch_mag128b[1] = dl_ch_mag128[1]; + dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128); + dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1); + + dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b); + dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1); + + dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b); + dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1); + + } + + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]); + + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + // print_ints("im",&mmtmpD1); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + // print_ints("re(shift)",&mmtmpD0); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + // print_ints("im(shift)",&mmtmpD1); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); + rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + // print_shorts("rx:",rxdataF128); + // print_shorts("ch:",dl_ch128); + // print_shorts("pack:",rxdataF_comp128); + + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + + rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + // print_shorts("rx:",rxdataF128+1); + // print_shorts("ch:",dl_ch128+1); + //print_shorts("pack:",rxdataF_comp128+1); + + dl_ch128+=2; + dl_ch_mag128+=2; + dl_ch_mag128b+=2; + rxdataF128+=2; + rxdataF_comp128+=2; + } + }else { + printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n" + "need to adapt the code!\n"); + } + } + } + +/*This part of code makes sense only for processing in 2x2 blocks*/ + if (rho) { + + + for (aarx=0; aarx<n_rx; aarx++) { + rho128 = (__m128i *)&rho[aarx][start_point]; + dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][start_point]; + dl_ch128_2 = (__m128i *)&dl_ch_estimates_ext[2+aarx][start_point]; + + if (length_mod8 == 0){ + length2 = length>>3; + + for (ii=0; ii<length2; ++ii) { + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]); + // print_ints("re",&mmtmpD0); + + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + // print_ints("im",&mmtmpD1); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + // print_ints("re(shift)",&mmtmpD0); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + // print_ints("im(shift)",&mmtmpD1); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); + rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + + //print_shorts("rx:",dl_ch128_2); + //print_shorts("ch:",dl_ch128); + //print_shorts("pack:",rho128); + + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + + rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3); + dl_ch128+=2; + dl_ch128_2+=2; + rho128+=2; + } + }else { + printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n" + "need to adapt the code!\n"); + } + } + } + _mm_empty(); + _m_empty(); +} + void nr_dlsch_scale_channel(int **dl_ch_estimates_ext, NR_DL_FRAME_PARMS *frame_parms, @@ -1804,7 +1908,7 @@ void nr_dlsch_scale_channel(int **dl_ch_estimates_ext, #if defined(__x86_64__)||defined(__i386__) short rb, ch_amp; - unsigned char aatx,aarx,pilots=0,symbol_mod; + unsigned char aatx,aarx,pilots=0; __m128i *dl_ch128, ch_amp128; @@ -1817,7 +1921,7 @@ void nr_dlsch_scale_channel(int **dl_ch_estimates_ext, ch_amp = 1024*8; //((pilots) ? (dlsch_ue[0]->sqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a)); - LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol_mod,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); + LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp); ch_amp128 = _mm_set1_epi16(ch_amp); // Q3.13 @@ -1980,6 +2084,389 @@ void nr_dlsch_channel_level(int **dl_ch_estimates_ext, #endif } +void nr_dlsch_channel_level_median(int **dl_ch_estimates_ext, + int32_t *median, + int n_tx, + int n_rx, + int length, + int start_point) +{ + +#if defined(__x86_64__)||defined(__i386__) + + short ii; + int aatx,aarx; + int length2; + int max = 0, min=0; + int norm_pack; + __m128i *dl_ch128, norm128D; + + for (aatx=0; aatx<n_tx; aatx++){ + for (aarx=0; aarx<n_rx; aarx++) { + max = 0; + min = 0; + norm128D = _mm_setzero_si128(); + + dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][start_point]; + + length2 = length>>2; + + for (ii=0;ii<length2;ii++) { + norm128D = _mm_srai_epi32( _mm_madd_epi16(dl_ch128[0],dl_ch128[0]), 1); + //print_ints("norm128D",&norm128D[0]); + + norm_pack = ((int32_t*)&norm128D)[0] + + ((int32_t*)&norm128D)[1] + + ((int32_t*)&norm128D)[2] + + ((int32_t*)&norm128D)[3]; + + if (norm_pack > max) + max = norm_pack; + if (norm_pack < min) + min = norm_pack; + + dl_ch128+=1; + } + + median[aatx*n_rx + aarx] = (max+min)>>1; + + // printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); + } + } + + _mm_empty(); + _m_empty(); + +#elif defined(__arm__) + + short rb; + unsigned char aatx,aarx,nre=12,symbol_mod; + int32x4_t norm128D; + int16x4_t *dl_ch128; + + for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++){ + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { + max = 0; + min = 0; + norm128D = vdupq_n_s32(0); + + dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*n_rx + aarx][start_point]; + + length_mod8=length&3; + length2 = length>>2; + + for (ii=0;ii<length2;ii++) { + norm128D = vshrq_n_u32(vmull_s16(dl_ch128[0],dl_ch128[0]), 1); + norm_pack = ((int32_t*)&norm128D)[0] + + ((int32_t*)&norm128D)[1] + + ((int32_t*)&norm128D)[2] + + ((int32_t*)&norm128D)[3]; + + if (norm_pack > max) + max = norm_pack; + if (norm_pack < min) + min = norm_pack; + + dl_ch128+=1; + } + + median[aatx*n_rx + aarx] = (max+min)>>1; + + //printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); + } + } +#endif + +} + +void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, + int **dl_ch_estimates_ext_i, + int **dl_ch_rho_ext, + unsigned char n_tx, + unsigned char n_rx, + unsigned char output_shift, + int length, + int start_point) +{ +#if defined(__x86_64__)||defined(__i386__) + + __m128i *dl_ch128,*dl_ch128i,*dl_ch_rho128,mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3; + unsigned char aarx; + int ii, length2, length_mod8; + + + for (aarx=0; aarx<n_rx; aarx++) { + + dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][start_point]; + + if (dl_ch_estimates_ext_i == NULL) + dl_ch128i = (__m128i *)&dl_ch_estimates_ext[aarx + n_rx][start_point]; + else + dl_ch128i = (__m128i *)&dl_ch_estimates_ext_i[aarx][start_point]; + + dl_ch_rho128 = (__m128i *)&dl_ch_rho_ext[aarx][start_point]; + + length_mod8 = length&7; + + if (length_mod8 == 0){ + length2 = length>>3; + + for (ii=0; ii<length2; ++ii) { + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128i[0]); + // print_ints("re",&mmtmpD0); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[0]); + // print_ints("im",&mmtmpD1); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + // print_ints("re(shift)",&mmtmpD0); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + // print_ints("im(shift)",&mmtmpD1); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); + dl_ch_rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + // print_shorts("rho 0:",dl_ch_rho128); + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128i[1]); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[1]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + dl_ch_rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3); + + dl_ch128+=2; + dl_ch128i+=2; + dl_ch_rho128+=2; + } + + }else { + printf ("Channel Correlarion: Received number of subcarriers is not multiple of 8, \n" + "need to adapt the code!\n"); + } + + } + + _mm_empty(); + _m_empty(); + +#elif defined(__arm__) + +#endif +} + +void nr_dlsch_detection_mrc_core(int **rxdataF_comp, + int **rxdataF_comp_i, + int **rho, + int **rho_i, + int **dl_ch_mag, + int **dl_ch_magb, + int **dl_ch_mag_i, + int **dl_ch_magb_i, + unsigned char n_tx, + unsigned char n_rx, + int length, + int start_point) +{ + +#if defined(__x86_64__)||defined(__i386__) + + unsigned char aatx; + int i; + __m128i *rxdataF_comp128_0, *rxdataF_comp128_1, *rxdataF_comp128_2, *rxdataF_comp128_3; + __m128i *dl_ch_mag128_0, *dl_ch_mag128_1, *dl_ch_mag128_2, *dl_ch_mag128_3; + __m128i *dl_ch_mag128_0b, *dl_ch_mag128_1b, *dl_ch_mag128_2b, *dl_ch_mag128_3b; + __m128i *rho128_0, *rho128_1, *rho128_2, *rho128_3; + __m128i *rho128_i0, *rho128_i1, *rho128_i2, *rho128_i3; + int length_mod4 = 0; + int length2; + + if (n_rx>1) { + + for (aatx=0; aatx<n_tx; aatx++) { + + rxdataF_comp128_0 = (__m128i *)&rxdataF_comp[(aatx<<1)][start_point]; + rxdataF_comp128_1 = (__m128i *)&rxdataF_comp[(aatx<<1)+1][start_point]; + dl_ch_mag128_0 = (__m128i *)&dl_ch_mag[(aatx<<1)][start_point]; + dl_ch_mag128_1 = (__m128i *)&dl_ch_mag[(aatx<<1)+1][start_point]; + dl_ch_mag128_0b = (__m128i *)&dl_ch_magb[(aatx<<1)][start_point]; + dl_ch_mag128_1b = (__m128i *)&dl_ch_magb[(aatx<<1)+1][start_point]; + + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++i) { + rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1)); + dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1)); + dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1)); + } + } + } + + + if (rho) { + rho128_0 = (__m128i *) &rho[0][start_point]; + rho128_1 = (__m128i *) &rho[1][start_point]; + + if (n_tx == 4){ + rho128_2 = (__m128i *) &rho[2][start_point]; + rho128_3 = (__m128i *) &rho[3][start_point]; + } + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++i) { + rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1)); + if (n_tx == 4){ + rho128_2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_2[i],1),_mm_srai_epi16(rho128_3[i],1)); + } + } + } + } + + if (rho_i){ + rho128_i0 = (__m128i *) &rho_i[0][start_point]; + rho128_i1 = (__m128i *) &rho_i[1][start_point]; + if (n_tx == 4){ + rho128_i2 = (__m128i *) &rho_i[2][start_point]; + rho128_i3 = (__m128i *) &rho_i[3][start_point]; + } + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++i){ + rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1)); + if (n_tx == 4){ + rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i],1),_mm_srai_epi16(rho128_i3[i],1)); + } + } + } + } + + if (n_tx == 4){ + + rxdataF_comp128_0 = (__m128i *)&rxdataF_comp[0][start_point]; + rxdataF_comp128_1 = (__m128i *)&rxdataF_comp[2][start_point]; + rxdataF_comp128_2 = (__m128i *)&rxdataF_comp[4][start_point]; + rxdataF_comp128_3 = (__m128i *)&rxdataF_comp[6][start_point]; + + dl_ch_mag128_0 = (__m128i *)&dl_ch_mag[0][start_point]; + dl_ch_mag128_1 = (__m128i *)&dl_ch_mag[2][start_point]; + dl_ch_mag128_2 = (__m128i *)&dl_ch_mag[4][start_point]; + dl_ch_mag128_3 = (__m128i *)&dl_ch_mag[6][start_point]; + + dl_ch_mag128_0b = (__m128i *)&dl_ch_magb[0][start_point]; + dl_ch_mag128_1b = (__m128i *)&dl_ch_magb[2][start_point]; + dl_ch_mag128_2b = (__m128i *)&dl_ch_magb[4][start_point]; + dl_ch_mag128_3b = (__m128i *)&dl_ch_magb[6][start_point]; + + rho128_0 = (__m128i *)&rho[0][start_point]; + rho128_1 = (__m128i *)&rho[2][start_point]; + + rho128_i0 = (__m128i *)&rho_i[0][start_point]; + rho128_i1 = (__m128i *)&rho_i[2][start_point]; + + + if (length_mod4 == 0){ + + length2 = length>>2; + + for (i=0; i<length2; ++i) { + rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1)); + rxdataF_comp128_2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_2[i],1),_mm_srai_epi16(rxdataF_comp128_3[i],1)); + + dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1)); + dl_ch_mag128_2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_2[i],1),_mm_srai_epi16(dl_ch_mag128_3[i],1)); + + dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1)); + dl_ch_mag128_2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_2b[i],1),_mm_srai_epi16(dl_ch_mag128_3b[i],1)); + + rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1)); + + rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1)); + } + } + } + + } + + _mm_empty(); + _m_empty(); + +#elif defined(__arm__) + + unsigned char aatx; + int i; + int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1; + int length_mod4 = 0; + int length2; + int ii=0; + + if (n_rx>1) { + + for (aatx=0; aatx<n_tx; aatx++) { + + rxdataF_comp128_0 = (int16x8_t *)&rxdataF_comp[(aatx<<1)][start_point]; + rxdataF_comp128_1 = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][start_point]; + dl_ch_mag128_0 = (int16x8_t *)&dl_ch_mag[(aatx<<1)][start_point]; + dl_ch_mag128_1 = (int16x8_t *)&dl_ch_mag[(aatx<<1)+1][start_point]; + dl_ch_mag128_0b = (int16x8_t *)&dl_ch_magb[(aatx<<1)][start_point]; + dl_ch_mag128_1b = (int16x8_t *)&dl_ch_magb[(aatx<<1)+1][start_point]; + + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++ii) { + rxdataF_comp128_0[i] = vhaddq_s16(rxdataF_comp128_0[i],rxdataF_comp128_1[i]); + dl_ch_mag128_0[i] = vhaddq_s16(dl_ch_mag128_0[i],dl_ch_mag128_1[i]); + dl_ch_mag128_0b[i] = vhaddq_s16(dl_ch_mag128_0b[i],dl_ch_mag128_1b[i]); + } + } + + if (rho) { + rho128_0 = (int16x8_t *) &rho[0][start_point]; + rho128_1 = (int16x8_t *) &rho[1][start_point]; + + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++i) { + rho128_0[i] = vhaddq_s16(rho128_0[i],rho128_1[i]); + } + } + } + + if (rho_i){ + + rho128_i0 = (__m128i *) &rho_i[0][start_point]; + rho128_i1 = (__m128i *) &rho_i[1][start_point]; + + if (length_mod4 == 0){ + length2 = length>>2; + + for (i=0; i<length2; ++i) + rho128_i0[i] = vhaddq_s16(rho128_i0[i],rho128_i1[i]); + + } + } + } + + } + +#endif +} + //============================================================================================== // Extraction functions //============================================================================================== @@ -2085,6 +2572,135 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, return(nb_rb_pdsch/frame_parms->nb_antennas_rx); } +unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, + int **dl_ch_estimates, + int **rxdataF_ext, + int **dl_ch_estimates_ext, + unsigned short pmi, + unsigned char *pmi_ext, + unsigned int *rb_alloc, + unsigned char symbol, + unsigned short start_rb, + unsigned short nb_rb_pdsch, + unsigned char nr_tti_rx, + uint32_t high_speed_flag, + NR_DL_FRAME_PARMS *frame_parms, + MIMO_mode_t mimo_mode) { + + int prb,nb_rb=0; + unsigned short k; + //int prb_off,prb_off2; + int skip_half=0,l;//sss_symb,pss_symb=0,nsymb + int i,aarx; + int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; + int symbol_mod,pilots=0,j=0; + unsigned char *pmi_loc; + + pilots = (symbol==2) ? 1 : 0; //to updated from config + k = frame_parms->first_carrier_offset + 516; //0 + + //nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; + l=symbol; + + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { + + if (high_speed_flag==1) { + dl_ch0 = &dl_ch_estimates[aarx][symbol*(frame_parms->ofdm_symbol_size)]; + dl_ch1 = &dl_ch_estimates[2+aarx][symbol*(frame_parms->ofdm_symbol_size)]; + } else { + dl_ch0 = &dl_ch_estimates[aarx][0]; + dl_ch1 = &dl_ch_estimates[2+aarx][0]; + } + + pmi_loc = pmi_ext; + + // pointers to extracted RX signals and channel estimates + rxF_ext = &rxdataF_ext[aarx][symbol*(nb_rb_pdsch*12)]; + dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(nb_rb_pdsch*12)]; + dl_ch1_ext = &dl_ch_estimates_ext[2+aarx][symbol*(nb_rb_pdsch*12)]; + + for (prb=0; prb<frame_parms->N_RB_DL; prb++) { + skip_half=0; + + if ((frame_parms->N_RB_DL&1) == 0) { // even number of RBs + + // For second half of RBs skip DC carrier + if (k>=frame_parms->ofdm_symbol_size) { + rxF = &rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))]; + k=k-(frame_parms->ofdm_symbol_size); + } + + /* + if (mimo_mode <= PUSCH_PRECODING1) + *pmi_loc = (pmi>>((prb>>2)<<1))&3; + else + *pmi_loc=(pmi>>prb)&1;*/ + + // *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); + // pmi_loc++; + + + if (pilots == 0) { + + memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); + memcpy(dl_ch1_ext,dl_ch1,12*sizeof(int)); + memcpy(rxF_ext,rxF,12*sizeof(int)); + dl_ch0_ext +=12; + dl_ch1_ext +=12; + rxF_ext +=12; + } else { // pilots==1 + j=0; + for (i=0; i<12; i++) { + if ((i&1)!=frame_parms->nushift) { + rxF_ext[j]=rxF[i]; + // printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + dl_ch0_ext[j]=dl_ch0p[i]; + dl_ch1_ext[j++]=dl_ch1p[i]; + } + } + dl_ch0_ext+=6; + dl_ch1_ext+=6; + rxF_ext+=6; + } // pilots==1 + + dl_ch0+=12; + dl_ch1+=12; + rxF+=12; + k+=12; + } + } // for prb + } // for aarx + return(nb_rb/frame_parms->nb_antennas_rx); +} + +void nr_dlsch_layer_demapping(int16_t **llr_cw, + uint8_t Nl, + uint8_t mod_order, + uint16_t length, + int16_t **llr_layers) { + + switch (Nl) { + + case 1: + memcpy((void*)llr_layers[0], (void*)llr_cw[0], (length)*sizeof(int16_t)); + break; + + case 2: + case 3: + case 4: + for (int i=0; i<(length/Nl/mod_order); i++){ + for (int l=0; l<Nl; l++) { + for (int m=0; m<mod_order; m++){ + llr_cw[0][Nl*i+l*mod_order+m] = llr_layers[l][i*mod_order+m]; + } + } + } + break; + + default: + AssertFatal(0, "Not supported number of layers %d\n", Nl); + } +} //============================================================================================== #ifdef USER_MODE diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c index 9527bf10e9a7781e6d39f00a1e1491a1e80ffc7f..29f3ffd758c118b441a802ad774a11d8c91d9b8c 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c @@ -1137,12 +1137,12 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, short **llr16p) { - int16_t *rxF=(int16_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rho=(int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)]; + int16_t *rxF=(int16_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; + int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; + int16_t *rho=(int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; int len; - uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; + //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; if (first_symbol_flag == 1) { llr16 = (int16_t*)dlsch_llr; @@ -1152,18 +1152,10 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_qpsk_qpsk_llr: llr is null, symbol %d\n",symbol); - if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) { - // if symbol has pilots - if (frame_parms->nb_antenna_ports_eNB!=1) - // in 2 antenna ports we have 8 REs per symbol per RB - len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3); - else - // for 1 antenna port we have 10 REs per symbol per RB - len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6); - } else { - // symbol has no pilots - len = (nb_rb*12) - pbch_pss_sss_adjust; - } + if (symbol ==2) //to update from config + len = nb_rb*6; + else + len = nb_rb*12; // printf("nr_dlsch_qpsk_qpsk_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust); // printf("qpsk_qpsk: len %d, llr16 %p\n",len,llr16); @@ -2986,14 +2978,14 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t **llr16p) { - int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rho = (int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)]; + int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; + int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; + int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*nb_rb*12)]; + int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*nb_rb*12)]; + int16_t *rho = (int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; int len; - uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; + //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; // first symbol has different structure due to more pilots if (first_symbol_flag == 1) { @@ -3005,18 +2997,10 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_16qam_16qam_llr: llr is null, symbol %d\n",symbol); - if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) { - // if symbol has pilots - if (frame_parms->nb_antenna_ports_eNB!=1) - // in 2 antenna ports we have 8 REs per symbol per RB - len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3); - else - // for 1 antenna port we have 10 REs per symbol per RB - len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6); - } else { - // symbol has no pilots - len = (nb_rb*12) - pbch_pss_sss_adjust; - } + if (symbol ==2) //to update from config + len = nb_rb*6; + else + len = nb_rb*12; // printf("symbol %d: qam16_llr, len %d (llr16 %p)\n",symbol,len,llr16); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 40cbb0d23ef7813128c95f71147617228bac1f93..50c7bafbadc687826a4d88b7edefcc428ea9576e 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -102,7 +102,7 @@ void free_list(NR_UE_SSB *node) { } -int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) +int nr_pbch_detection(UE_nr_rxtx_proc_t * proc, PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) { NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; @@ -160,7 +160,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #endif ret = nr_rx_pbch(ue, - 0, + proc, ue->pbch_vars[0], frame_parms, 0, @@ -201,7 +201,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod char duplex_string[2][4] = {"FDD","TDD"}; char prefix_string[2][9] = {"NORMAL","EXTENDED"}; -int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) +int nr_initial_sync(UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, runmode_t mode) { int32_t sync_pos, sync_pos_frame; // k_ssb, N_ssb_crb, sync_pos2, @@ -296,8 +296,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) i, 0, ue->ssb_offset, - 0, - NR_PBCH_EST); + 0); #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"Calling sss detection (normal CP)\n"); @@ -309,7 +308,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) //nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,n_ssb_crb,0); nr_gold_pbch(ue); - ret = nr_pbch_detection(ue,1,mode); // start pbch detection at first symbol after pss + ret = nr_pbch_detection(proc, ue,1,mode); // start pbch detection at first symbol after pss if (ret == 0) { // sync at symbol ue->symbol_offset diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a50edecb2c8194817a1ef469a03ecc3e8e0a83d6..d23f1645345aa2633df8a750a2bd16727bc719b5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -410,7 +410,7 @@ unsigned char sign(int8_t x) { uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,7,29,25,27,5,8,24,9,10,11,12,13,1,4,3,14,15,16,17,2,26,18,19,20,21,22,6,23}; int nr_rx_pbch( PHY_VARS_NR_UE *ue, - int subframe_rx, + UE_nr_rxtx_proc_t *proc, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -448,15 +448,15 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, symbol_offset=0; #ifdef DEBUG_PBCH - //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF); + //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->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[0][(symbol_offset+1)*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size*3,1,1); + &nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].rxdataF[0][(symbol_offset+1)*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size*3,1,1); #endif // symbol refers to symbol within SSB. symbol_offset is the offset of the SSB wrt start of slot for (symbol=1; symbol<4; symbol++) { - 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], + nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].rxdataF, + nr_ue_pbch_vars->dl_ch_estimates, nr_ue_pbch_vars->rxdataF_ext, nr_ue_pbch_vars->dl_ch_estimates_ext, symbol, @@ -591,6 +591,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif ue->dl_indication.rx_ind = &ue->rx_ind; // hang on rx_ind instance + ue->dl_indication.proc=proc; //ue->rx_ind.sfn_slot = 0; //should be set by higher-1-layer, i.e. clean_and_set_if_instance() ue->rx_ind.rx_indication_body[0].pdu_type = FAPI_NR_RX_PDU_TYPE_MIB; ue->rx_ind.rx_indication_body[0].mib_pdu.pdu = &decoded_output[0]; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h index e1727c48477d37f95b7f80ce4697468d05cc644c..48cf637529e6ceac224ac46444c6d1c0c8fdbc76 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -753,18 +753,20 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, @param high_speed_flag @param frame_parms Pointer to frame descriptor */ -uint16_t dlsch_extract_rbs_dual(int32_t **rxdataF, - int32_t **dl_ch_estimates, - int32_t **rxdataF_ext, - int32_t **dl_ch_estimates_ext, - uint16_t pmi, - uint8_t *pmi_ext, - uint32_t *rb_alloc, - uint8_t symbol, - uint8_t subframe, - uint32_t high_speed_flag, - NR_DL_FRAME_PARMS *frame_parms, - MIMO_mode_t mimo_mode); +unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, + int **dl_ch_estimates, + int **rxdataF_ext, + int **dl_ch_estimates_ext, + unsigned short pmi, + unsigned char *pmi_ext, + unsigned int *rb_alloc, + unsigned char symbol, + unsigned short start_rb, + unsigned short nb_rb_pdsch, + unsigned char nr_tti_rx, + uint32_t high_speed_flag, + NR_DL_FRAME_PARMS *frame_parms, + MIMO_mode_t mimo_mode); /** \fn dlsch_extract_rbs_TM7(int32_t **rxdataF, int32_t **dl_bf_ch_estimates, @@ -826,6 +828,19 @@ void nr_dlsch_channel_compensation(int32_t **rxdataF_ext, uint8_t output_shift, PHY_NR_MEASUREMENTS *phy_measurements); +void nr_dlsch_channel_compensation_core(int **rxdataF_ext, + int **dl_ch_estimates_ext, + int **dl_ch_mag, + int **dl_ch_magb, + int **rxdataF_comp, + int **rho, + unsigned char n_tx, + unsigned char n_rx, + unsigned char mod_order, + unsigned char output_shift, + int length, + int start_point); + void nr_dlsch_deinterleaving(uint8_t symbol, uint16_t L, uint16_t *llr, @@ -881,6 +896,26 @@ void dlsch_channel_level_TM34_meas(int *ch00, int *avg_1, unsigned short nb_rb); +void nr_dlsch_channel_level_median(int **dl_ch_estimates_ext, + int32_t *median, + int n_tx, + int n_rx, + int length, + int start_point); + +void nr_dlsch_detection_mrc_core(int **rxdataF_comp, + int **rxdataF_comp_i, + int **rho, + int **rho_i, + int **dl_ch_mag, + int **dl_ch_magb, + int **dl_ch_mag_i, + int **dl_ch_magb_i, + unsigned char n_tx, + unsigned char n_rx, + int length, + int start_point); + void det_HhH(int32_t *after_mf_00, int32_t *after_mf_01, int32_t *after_mf_10, @@ -1137,7 +1172,7 @@ int rx_sss(PHY_VARS_NR_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uin \returns number of tx antennas or -1 if error */ int nr_rx_pbch( PHY_VARS_NR_UE *ue, - int subframe_rx, + UE_nr_rxtx_proc_t *proc, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -1145,7 +1180,8 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, MIMO_mode_t mimo_mode, uint32_t high_speed_flag); -int nr_pbch_detection(PHY_VARS_NR_UE *ue, +int nr_pbch_detection(UE_nr_rxtx_proc_t *proc, + PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode); @@ -1433,7 +1469,8 @@ void generate_RIV_tables(void); @param phy_vars_ue Pointer to UE variables @param mode current running mode */ -int nr_initial_sync(PHY_VARS_NR_UE *phy_vars_ue, runmode_t mode); +int nr_initial_sync(UE_nr_rxtx_proc_t *proc, + PHY_VARS_NR_UE *phy_vars_ue, runmode_t mode); /*! @@ -1731,16 +1768,31 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, uint32_t nr_get_G(uint16_t nb_rb, uint16_t nb_symb_sch,uint8_t nb_re_dmrs,uint16_t length_dmrs, uint8_t Qm, uint8_t Nl) ; uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, - short *dlsch_llr, - NR_DL_FRAME_PARMS *frame_parms, - NR_UE_DLSCH_t *dlsch, - NR_DL_UE_HARQ_t *harq_process, - uint32_t frame, - uint16_t nb_symb_sch, - uint8_t nr_tti_rx, - uint8_t harq_pid, - uint8_t is_crnti, + short *dlsch_llr, + NR_DL_FRAME_PARMS *frame_parms, + NR_UE_DLSCH_t *dlsch, + NR_DL_UE_HARQ_t *harq_process, + uint32_t frame, + uint16_t nb_symb_sch, + uint8_t nr_tti_rx, + uint8_t harq_pid, + uint8_t is_crnti, uint8_t llr8_flag); +int nr_extract_dci_info(PHY_VARS_NR_UE *ue, + uint8_t eNB_id, + lte_frame_type_t frame_type, + uint8_t dci_length, + uint16_t rnti, + uint64_t dci_pdu[2], + fapi_nr_dci_pdu_rel15_t *nr_pdci_info_extracted, + uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], + NR_DCI_format_t dci_format, + uint8_t nr_tti_rx, + uint16_t n_RB_ULBWP, + uint16_t n_RB_DLBWP, + uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES]); + + /**@}*/ #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index 885039c5925d828cdb4a2406e5993b7c886f2dce..2facd85babf3525981767cb88b13ec4e1cf031ab 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -277,7 +277,7 @@ typedef struct { /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) int16_t w[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; /// for abstraction soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) - double w_abs[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; + //double w_abs[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; /// soft bits for each received segment ("d"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) int16_t *d[MAX_NUM_NR_DLSCH_SEGMENTS]; /// LDPC processing buffers diff --git a/openair1/PHY/TOOLS/cdot_prod.c b/openair1/PHY/TOOLS/cdot_prod.c index 843a9605f11e229de07d4acfcffe1119dd43a1ce..d3e73ec28aa7d59e3c332bd26c2a25b9cff962e4 100644 --- a/openair1/PHY/TOOLS/cdot_prod.c +++ b/openair1/PHY/TOOLS/cdot_prod.c @@ -158,122 +158,6 @@ int32_t dot_product(int16_t *x, #endif } -int64_t dot_product64(int16_t *x, - int16_t *y, - uint32_t N, //must be a multiple of 8 - uint8_t output_shift) -{ - - uint32_t n; - -#if defined(__x86_64__) || defined(__i386__) - __m128i *x128,*y128,mmtmp1,mmtmp2,mmtmp3,mmcumul,mmcumul_re,mmcumul_im; - __m128i minus_i = _mm_set_epi16(-1,1,-1,1,-1,1,-1,1); - int64_t result; - - x128 = (__m128i*) x; - y128 = (__m128i*) y; - - mmcumul_re = _mm_setzero_si128(); - mmcumul_im = _mm_setzero_si128(); - - for (n=0; n<(N>>2); n++) { - -// printf("n=%d, x128=%p, y128=%p\n",n,x128,y128); - // print_shorts("x",&x128[0]); - // print_shorts("y",&y128[0]); - - // this computes Re(z) = Re(x)*Re(y) + Im(x)*Im(y) - mmtmp1 = _mm_madd_epi16(x128[0],y128[0]); - // print_ints("retmp",&mmtmp1); - // mmtmp1 contains real part of 4 consecutive outputs (32-bit) - // shift and accumulate results - mmtmp1 = _mm_srai_epi32(mmtmp1,output_shift); - mmcumul_re = _mm_add_epi32(mmcumul_re,mmtmp1); - //print_ints("re",&mmcumul_re); - - - // this computes Im(z) = Re(x)*Im(y) - Re(y)*Im(x) - mmtmp2 = _mm_shufflelo_epi16(y128[0],_MM_SHUFFLE(2,3,0,1)); - //print_shorts("y",&mmtmp2); - mmtmp2 = _mm_shufflehi_epi16(mmtmp2,_MM_SHUFFLE(2,3,0,1)); - //print_shorts("y",&mmtmp2); - mmtmp2 = _mm_sign_epi16(mmtmp2,minus_i); - // print_shorts("y",&mmtmp2); - - mmtmp3 = _mm_madd_epi16(x128[0],mmtmp2); - //print_ints("imtmp",&mmtmp3); - // mmtmp3 contains imag part of 4 consecutive outputs (32-bit) - // shift and accumulate results - mmtmp3 = _mm_srai_epi32(mmtmp3,output_shift); - mmcumul_im = _mm_add_epi32(mmcumul_im,mmtmp3); - //print_ints("im",&mmcumul_im); - - x128++; - y128++; - } - - // this gives Re Re Im Im - mmcumul = _mm_hadd_epi32(mmcumul_re,mmcumul_im); - //print_ints("cumul1",&mmcumul); - // this gives Re Im Re Im - mmcumul = _mm_hadd_epi32(mmcumul,mmcumul); - //print_ints("cumul2",&mmcumul); - - //mmcumul = _mm_srai_epi32(mmcumul,output_shift); - // extract the lower half - result = _mm_extract_epi64(mmcumul,0); - //printf("result: (%d,%d)\n",((int32_t*)&result)[0],((int32_t*)&result)[1]); - _mm_empty(); - _m_empty(); - - return(result); - -#elif defined(__arm__) - int16x4_t *x_128=(int16x4_t*)x; - int16x4_t *y_128=(int16x4_t*)y; - int32x4_t tmp_re,tmp_im; - int32x4_t tmp_re1,tmp_im1; - int32x4_t re_cumul,im_cumul; - int32x2_t re_cumul2,im_cumul2; - int32x4_t shift = vdupq_n_s32(-output_shift); - int32x2x2_t result2; - int16_t conjug[4]__attribute__((aligned(16))) = {-1,1,-1,1} ; - - re_cumul = vdupq_n_s32(0); - im_cumul = vdupq_n_s32(0); - - for (n=0; n<(N>>2); n++) { - - tmp_re = vmull_s16(*x_128++, *y_128++); - //tmp_re = [Re(x[0])Re(y[0]) Im(x[0])Im(y[0]) Re(x[1])Re(y[1]) Im(x[1])Im(y[1])] - tmp_re1 = vmull_s16(*x_128++, *y_128++); - //tmp_re1 = [Re(x1[1])Re(x2[1]) Im(x1[1])Im(x2[1]) Re(x1[1])Re(x2[2]) Im(x1[1])Im(x2[2])] - tmp_re = vcombine_s32(vpadd_s32(vget_low_s32(tmp_re),vget_high_s32(tmp_re)), - vpadd_s32(vget_low_s32(tmp_re1),vget_high_s32(tmp_re1))); - //tmp_re = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2]) Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] - - tmp_im = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); - //tmp_im = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] - tmp_im1 = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); - //tmp_im1 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] - tmp_im = vcombine_s32(vpadd_s32(vget_low_s32(tmp_im),vget_high_s32(tmp_im)), - vpadd_s32(vget_low_s32(tmp_im1),vget_high_s32(tmp_im1))); - //tmp_im = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - - re_cumul = vqaddq_s32(re_cumul,vqshlq_s32(tmp_re,shift)); - im_cumul = vqaddq_s32(im_cumul,vqshlq_s32(tmp_im,shift)); - } - - re_cumul2 = vpadd_s32(vget_low_s32(re_cumul),vget_high_s32(re_cumul)); - im_cumul2 = vpadd_s32(vget_low_s32(im_cumul),vget_high_s32(im_cumul)); - re_cumul2 = vpadd_s32(re_cumul2,re_cumul2); - im_cumul2 = vpadd_s32(im_cumul2,im_cumul2); - result2 = vzip_s32(re_cumul2,im_cumul2); - return(vget_lane_s32(result2.val[0],0)); -#endif -} - #ifdef MAIN diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c index 3dd16ff0dad7c738379fbab06cc3be07b752692b..d1f1d1bea8ee07ceb10a99240d74cf58898bec34 100644 --- a/openair1/PHY/TOOLS/nr_phy_scope.c +++ b/openair1/PHY/TOOLS/nr_phy_scope.c @@ -590,8 +590,8 @@ void phy_scope_UE(FD_lte_phy_scope_ue *form, time = calloc(samples_per_frame,sizeof(float)); corr = calloc(samples_per_frame,sizeof(float)); - chest_t = (int16_t**) phy_vars_ue->common_vars.common_vars_rx_data_per_thread[phy_vars_ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id]; - chest_f = (int16_t**) phy_vars_ue->common_vars.common_vars_rx_data_per_thread[phy_vars_ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id]; + chest_t = (int16_t**) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time; + chest_f = (int16_t**) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates; pbch_llr = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->llr; pbch_comp = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->rxdataF_comp[0]; diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index b57fc7e9de222ee06a463da2f4954908cca8ac18..8ba2ac0d4088da02730872a132826f01613dc5da 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -354,10 +354,116 @@ int32_t dot_product(int16_t *x, uint32_t N, //must be a multiple of 8 uint8_t output_shift); -int64_t dot_product64(int16_t *x, +static inline int64_t dot_product64(int16_t *x, int16_t *y, uint32_t N, //must be a multiple of 8 - uint8_t output_shift); + uint8_t output_shift) +{ + +#if defined(__x86_64__) || defined(__i386__) + __m128i *x128,*y128,mmtmp1,mmtmp2,mmtmp3,mmcumul,mmcumul_re,mmcumul_im; + __m128i minus_i = _mm_set_epi16(-1,1,-1,1,-1,1,-1,1); + int64_t result; + + x128 = (__m128i*) x; + y128 = (__m128i*) y; + + mmcumul_re = _mm_setzero_si128(); + mmcumul_im = _mm_setzero_si128(); + + __m128i*end=x128+(N>>2); + for (__m128i* inPtr=x128; inPtr < end ; inPtr++) { + +// printf("n=%d, x128=%p, y128=%p\n",n,x128,y128); + // print_shorts("x",&x128[0]); + // print_shorts("y",&y128[0]); + + // this computes Re(z) = Re(x)*Re(y) + Im(x)*Im(y) + mmtmp1 = _mm_madd_epi16(*inPtr,*y128); + // print_ints("retmp",&mmtmp1); + // mmtmp1 contains real part of 4 consecutive outputs (32-bit) + // shift and accumulate results + mmtmp1 = _mm_srai_epi32(mmtmp1,output_shift); + mmcumul_re = _mm_add_epi32(mmcumul_re,mmtmp1); + //print_ints("re",&mmcumul_re); + + + // this computes Im(z) = Re(x)*Im(y) - Re(y)*Im(x) + mmtmp2 = _mm_shufflelo_epi16(*y128,_MM_SHUFFLE(2,3,0,1)); + //print_shorts("y",&mmtmp2); + mmtmp2 = _mm_shufflehi_epi16(mmtmp2,_MM_SHUFFLE(2,3,0,1)); + //print_shorts("y",&mmtmp2); + mmtmp2 = _mm_sign_epi16(mmtmp2,minus_i); + // print_shorts("y",&mmtmp2); + + mmtmp3 = _mm_madd_epi16(*inPtr,mmtmp2); + //print_ints("imtmp",&mmtmp3); + // mmtmp3 contains imag part of 4 consecutive outputs (32-bit) + // shift and accumulate results + mmtmp3 = _mm_srai_epi32(mmtmp3,output_shift); + mmcumul_im = _mm_add_epi32(mmcumul_im,mmtmp3); + //print_ints("im",&mmcumul_im); + y128++; + } + + // this gives Re Re Im Im + mmcumul = _mm_hadd_epi32(mmcumul_re,mmcumul_im); + //print_ints("cumul1",&mmcumul); + // this gives Re Im Re Im + mmcumul = _mm_hadd_epi32(mmcumul,mmcumul); + //print_ints("cumul2",&mmcumul); + + //mmcumul = _mm_srai_epi32(mmcumul,output_shift); + // extract the lower half + result = _mm_extract_epi64(mmcumul,0); + //printf("result: (%d,%d)\n",((int32_t*)&result)[0],((int32_t*)&result)[1]); + + return(result); + +#elif defined(__arm__) + int16x4_t *x_128=(int16x4_t*)x; + int16x4_t *y_128=(int16x4_t*)y; + int32x4_t tmp_re,tmp_im; + int32x4_t tmp_re1,tmp_im1; + int32x4_t re_cumul,im_cumul; + int32x2_t re_cumul2,im_cumul2; + int32x4_t shift = vdupq_n_s32(-output_shift); + int32x2x2_t result2; + int16_t conjug[4]__attribute__((aligned(16))) = {-1,1,-1,1} ; + + re_cumul = vdupq_n_s32(0); + im_cumul = vdupq_n_s32(0); + + for (n=0; n<(N>>2); n++) { + + tmp_re = vmull_s16(*x_128++, *y_128++); + //tmp_re = [Re(x[0])Re(y[0]) Im(x[0])Im(y[0]) Re(x[1])Re(y[1]) Im(x[1])Im(y[1])] + tmp_re1 = vmull_s16(*x_128++, *y_128++); + //tmp_re1 = [Re(x1[1])Re(x2[1]) Im(x1[1])Im(x2[1]) Re(x1[1])Re(x2[2]) Im(x1[1])Im(x2[2])] + tmp_re = vcombine_s32(vpadd_s32(vget_low_s32(tmp_re),vget_high_s32(tmp_re)), + vpadd_s32(vget_low_s32(tmp_re1),vget_high_s32(tmp_re1))); + //tmp_re = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2]) Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] + + tmp_im = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); + //tmp_im = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] + tmp_im1 = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); + //tmp_im1 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] + tmp_im = vcombine_s32(vpadd_s32(vget_low_s32(tmp_im),vget_high_s32(tmp_im)), + vpadd_s32(vget_low_s32(tmp_im1),vget_high_s32(tmp_im1))); + //tmp_im = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] + + re_cumul = vqaddq_s32(re_cumul,vqshlq_s32(tmp_re,shift)); + im_cumul = vqaddq_s32(im_cumul,vqshlq_s32(tmp_im,shift)); + } + + re_cumul2 = vpadd_s32(vget_low_s32(re_cumul),vget_high_s32(re_cumul)); + im_cumul2 = vpadd_s32(vget_low_s32(im_cumul),vget_high_s32(im_cumul)); + re_cumul2 = vpadd_s32(re_cumul2,re_cumul2); + im_cumul2 = vpadd_s32(im_cumul2,im_cumul2); + result2 = vzip_s32(re_cumul2,im_cumul2); + return(vget_lane_s32(result2.val[0],0)); +#endif +} void dft12(int16_t *x,int16_t *y); void dft24(int16_t *x,int16_t *y,uint8_t scale_flag); diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index f447c6895eda255d2fc4253dc481a427c2ae11a2..1ea5814e8d1592bf90b89e2796b6329f33d76093 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -157,109 +157,6 @@ #include "targets/ARCH/COMMON/common_lib.h" -#include "NR_IF_Module.h" - -/// Context data structure for RX/TX portion of subframe processing -typedef struct { - /// index of the current UE RX/TX proc - int proc_id; - /// Component Carrier index - uint8_t CC_id; - /// timestamp transmitted to HW - openair0_timestamp timestamp_tx; - //#ifdef UE_NR_PHY_DEMO - /// NR TTI index within subframe_tx [0 .. ttis_per_subframe - 1] to act upon for transmission - int nr_tti_tx; - /// NR TTI index within subframe_rx [0 .. ttis_per_subframe - 1] to act upon for reception - int nr_tti_rx; - //#endif - /// subframe to act upon for transmission - int subframe_tx; - /// subframe to act upon for reception - int subframe_rx; - /// frame to act upon for transmission - int frame_tx; - /// frame to act upon for reception - int frame_rx; - /// \brief Instance count for RXn-TXnp4 processing thread. - /// \internal This variable is protected by \ref mutex_rxtx. - int instance_cnt_rxtx; - /// pthread structure for RXn-TXnp4 processing thread - pthread_t pthread_rxtx; - /// pthread attributes for RXn-TXnp4 processing thread - pthread_attr_t attr_rxtx; - /// condition variable for tx processing thread - pthread_cond_t cond_rxtx; - /// mutex for RXn-TXnp4 processing thread - pthread_mutex_t mutex_rxtx; - /// scheduling parameters for RXn-TXnp4 thread - struct sched_param sched_param_rxtx; - - /// internal This variable is protected by ref mutex_fep_slot1. - //int instance_cnt_slot0_dl_processing; - int instance_cnt_slot1_dl_processing; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_slot1_dl_processing; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_slot1_dl_processing; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_slot1_dl_processing; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_slot1_dl_processing; - //int instance_cnt_slot0_dl_processing; - int instance_cnt_dlsch_td; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_dlsch_td; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_dlsch_td; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_dlsch_td; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_dlsch_td; - // - uint8_t chan_est_pilot0_slot1_available; - uint8_t chan_est_slot1_available; - uint8_t llr_slot1_available; - uint8_t dci_slot0_available; - uint8_t first_symbol_available; - uint8_t decoder_thread_available; - uint8_t decoder_main_available; - uint8_t decoder_switch; - int counter_decoder; - uint8_t channel_level; - int eNB_id; - int harq_pid; - int llr8_flag; - /// scheduling parameters for fep_slot1 thread - struct sched_param sched_param_fep_slot1; - - int sub_frame_start; - int sub_frame_step; - unsigned long long gotIQs; - uint8_t decoder_thread_available1; - int instance_cnt_dlsch_td1; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_dlsch_td1; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_dlsch_td1; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_dlsch_td1; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_dlsch_td1; - int dci_err_cnt; -} UE_nr_rxtx_proc_t; /// Context data structure for eNB subframe processing typedef struct { @@ -378,17 +275,6 @@ typedef struct { /// - second index: symbol [0..28*ofdm_symbol_size[ int32_t **rxdataF; - /// \brief Hold the channel estimates in frequency domain. - /// - first index: eNB id [0..6] (hard coded) - /// - second index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx - /// - third index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ - int32_t **dl_ch_estimates[7]; - - /// \brief Hold the channel estimates in time domain (used for tracking). - /// - first index: eNB id [0..6] (hard coded) - /// - second index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx - /// - third index: samples? [0..2*ofdm_symbol_size[ - int32_t **dl_ch_estimates_time[7]; } NR_UE_COMMON_PER_THREAD; typedef struct { @@ -438,6 +324,10 @@ typedef struct { /// - third index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - fourth index: ? [0..168*N_RB_DL[ int32_t **rxdataF_comp1[8][8]; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; /// \brief Downlink channel estimates extracted in PRBS. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ @@ -489,6 +379,8 @@ typedef struct { /// - first index: ? [0..1] (hard coded) /// - second index: ? [0..1179743] (hard coded) int16_t *llr[2]; + /// Pointers to layer llr vectors (4 layers). + int16_t *layer_llr[4]; /// \f$\log_2(\max|H_i|^2)\f$ int16_t log2_maxh; /// \f$\log_2(\max|H_i|^2)\f$ //this is for TM3-4 layer1 channel compensation @@ -830,6 +722,14 @@ typedef struct { /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ int32_t **rxdataF_comp; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; + /// \brief Hold the channel estimates in time domain (used for tracking). + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..2*ofdm_symbol_size[ + int32_t **dl_ch_estimates_time; /// \brief Pointers to extracted channel estimates of PDCCH symbols. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ @@ -897,6 +797,10 @@ typedef struct { /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..287] (hard coded) int32_t **rxdataF_comp; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; /// \brief Pointers to downlink channel estimates in frequency-domain extracted in PRBS. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..287] (hard coded) @@ -956,6 +860,9 @@ typedef struct UE_NR_SCAN_INFO_s { int32_t freq_offset_Hz[3][10]; } UE_NR_SCAN_INFO_t; + +#include "NR_IF_Module.h" + /// Top-level PHY Data Structure for UE typedef struct { /// \brief Module ID indicator for this instance @@ -1015,7 +922,7 @@ typedef struct { /// UE FAPI DCI request nr_dcireq_t dcireq; - // CHECK if we need those as they are also included in dl_indictation + // pointers to the next 2 strcutres are also included in dl_indictation /// UE FAPI indication for DLSCH reception fapi_nr_rx_indication_t rx_ind; /// UE FAPI indication for DCI reception diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index a589f555ff2c21c0c2272de596446e51f6a0b325..6adb2271e2af41a3e3bec7c34a2e3872d2b30ad8 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -161,8 +161,6 @@ typedef struct NR_BWP_PARMS { uint8_t location; /// Bandwidth in PRB uint16_t N_RB; - /// Size of FFT/IFFT - uint16_t ofdm_symbol_size; /// Cyclic prefix uint8_t cyclic_prefix; /// RBG params @@ -315,10 +313,6 @@ typedef struct NR_DL_FRAME_PARMS { /// PBCH polar encoder params t_nrPolar_params pbch_polar_params; - //BWP params - NR_BWP_PARMS initial_bwp_dl; - NR_BWP_PARMS initial_bwp_ul; - } NR_DL_FRAME_PARMS; #define KHz (1000UL) diff --git a/openair1/PHY/thread_NR_UE.h b/openair1/PHY/thread_NR_UE.h new file mode 100644 index 0000000000000000000000000000000000000000..cba7a5ae41729f04859cb8fc197d64a05c15c6e2 --- /dev/null +++ b/openair1/PHY/thread_NR_UE.h @@ -0,0 +1,78 @@ +#ifndef __thread_NR_UE__ +#define __thread_NR_UE__ +#include <pthread.h> +#include <targets/ARCH/COMMON/common_lib.h> +/// Context data structure for RX/TX portion of subframe processing +typedef struct { + /// index of the current UE RX/TX proc + int proc_id; + /// Component Carrier index + uint8_t CC_id; + /// timestamp transmitted to HW + openair0_timestamp timestamp_tx; + //#ifdef UE_NR_PHY_DEMO + /// NR TTI index within subframe_tx [0 .. ttis_per_subframe - 1] to act upon for transmission + int nr_tti_tx; + /// NR TTI index within subframe_rx [0 .. ttis_per_subframe - 1] to act upon for reception + int nr_tti_rx; + //#endif + /// subframe to act upon for transmission + int subframe_tx; + /// subframe to act upon for reception + int subframe_rx; + /// frame to act upon for transmission + int frame_tx; + /// frame to act upon for reception + int frame_rx; + int decoded_frame_rx; + /// internal This variable is protected by ref mutex_fep_slot1. + //int instance_cnt_slot0_dl_processing; + int instance_cnt_slot1_dl_processing; + /// pthread descriptor fep_slot1 thread + //pthread_t pthread_slot0_dl_processing; + pthread_t pthread_slot1_dl_processing; + /// pthread attributes for fep_slot1 processing thread + // pthread_attr_t attr_slot0_dl_processing; + pthread_attr_t attr_slot1_dl_processing; + /// condition variable for UE fep_slot1 thread; + //pthread_cond_t cond_slot0_dl_processing; + pthread_cond_t cond_slot1_dl_processing; + /// mutex for UE synch thread + //pthread_mutex_t mutex_slot0_dl_processing; + pthread_mutex_t mutex_slot1_dl_processing; + //int instance_cnt_slot0_dl_processing; + int instance_cnt_dlsch_td; + /// pthread descriptor fep_slot1 thread + //pthread_t pthread_slot0_dl_processing; + pthread_t pthread_dlsch_td; + /// pthread attributes for fep_slot1 processing thread + // pthread_attr_t attr_slot0_dl_processing; + pthread_attr_t attr_dlsch_td; + /// condition variable for UE fep_slot1 thread; + //pthread_cond_t cond_slot0_dl_processing; + pthread_cond_t cond_dlsch_td; + /// mutex for UE synch thread + uint8_t chan_est_pilot0_slot1_available; + uint8_t chan_est_slot1_available; + uint8_t llr_slot1_available; + uint8_t dci_slot0_available; + uint8_t first_symbol_available; + uint8_t decoder_thread_available; + uint8_t decoder_main_available; + uint8_t decoder_switch; + int counter_decoder; + uint8_t channel_level; + int eNB_id; + int harq_pid; + int llr8_flag; + /// scheduling parameters for fep_slot1 thread + struct sched_param sched_param_fep_slot1; + + int sub_frame_start; + int sub_frame_step; + unsigned long long gotIQs; + uint8_t decoder_thread_available1; + int dci_err_cnt; +} UE_nr_rxtx_proc_t; + +#endif diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 66eb0fada71c9056031c21f71c6b5fa281ab5e91..71ef6039f3a06a2e8c54ba1516273abdd1ed71fe 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -32,9 +32,6 @@ #include "PHY/defs_gNB.h" #include "PHY/phy_extern.h" -#include "PHY/LTE_TRANSPORT/transport_proto.h" -#include "SCHED/sched_eNB.h" -#include "SCHED/sched_common.h" #include "SCHED_NR/sched_nr.h" #include "nfapi_nr_interface.h" diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 7c17987980053d2d7df7f001afdb185809c3a70d..7db71ba916aeea2200e9d8176c99e1ab891bee33 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -55,7 +55,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ // Note: we have to handle the thread IDs for this. To be revisited completely. NR_UE_PDCCH *pdcch_vars2 = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0]; NR_UE_DLSCH_t *dlsch0 = PHY_vars_UE_g[module_id][cc_id]->dlsch[thread_id][0][0]; - NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[0]; + NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[thread_id][0][0]; NR_DL_FRAME_PARMS frame_parms = PHY_vars_UE_g[module_id][cc_id]->frame_parms; PRACH_RESOURCES_t *prach_resources = PHY_vars_UE_g[module_id][cc_id]->prach_resources[0]; @@ -106,32 +106,24 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ uint8_t current_harq_pid = dlsch_config_pdu->harq_process_nbr; dlsch0->current_harq_pid = current_harq_pid; dlsch0->active = 1; + dlsch0->rnti = dl_config->dl_config_list[i].dlsch_config_pdu.rnti; //dlsch0->harq_processes[0]->mcs = &dlsch_config_pdu->mcs; - NR_DL_UE_HARQ_t dlsch0_harq = *(dlsch0->harq_processes[current_harq_pid]); + NR_DL_UE_HARQ_t *dlsch0_harq = dlsch0->harq_processes[current_harq_pid]; - //dlsch0->harq_processes[current_harq_pid]->nb_rb = dlsch_config_pdu->number_rbs; - - dlsch0_harq.nb_rb = dlsch_config_pdu->number_rbs; - dlsch0_harq.start_rb = dlsch_config_pdu->start_rb; - dlsch0_harq.nb_symbols = dlsch_config_pdu->number_symbols; - dlsch0_harq.start_symbol = dlsch_config_pdu->start_symbol; - dlsch0_harq.mcs = dlsch_config_pdu->mcs; - dlsch0_harq.DCINdi = dlsch_config_pdu->ndi; - dlsch0_harq.rvidx = dlsch_config_pdu->rv; - dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; - dlsch0_harq.harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; - dlsch0_harq.harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; - printf(">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq.mcs); - //for (int j = 0 ; j<1000; j++) printf("\nk = %d",j); - -#if 0 - dlsch0->harq_processes[current_harq_pid]->mcs = dlsch_config_pdu->mcs; + dlsch0_harq->nb_rb = dlsch_config_pdu->number_rbs; + dlsch0_harq->start_rb = dlsch_config_pdu->start_rb; + dlsch0_harq->nb_symbols = dlsch_config_pdu->number_symbols; + dlsch0_harq->start_symbol = dlsch_config_pdu->start_symbol; + dlsch0_harq->mcs = dlsch_config_pdu->mcs; + dlsch0_harq->DCINdi = dlsch_config_pdu->ndi; + dlsch0_harq->rvidx = dlsch_config_pdu->rv; dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; - //pdlsch0->rnti = rnti; -#endif + dlsch0_harq->harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; + dlsch0_harq->harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; + printf(">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq->mcs); } } }else{ @@ -251,7 +243,7 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ } } - + return 0; } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index b61b57dc74fc84ba95971a49fcf967e30e0412be..c83074d8a254f2b6b7f97680930666b496d25bb8 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -119,6 +119,7 @@ uint8_t nr_dci_decoding_procedure(int s, format_found_t *format_found, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES]); +/* int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint8_t eNB_id, int frame, @@ -139,7 +140,7 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint16_t n_RB_DLBWP, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES], NR_DCI_INFO_EXTRACTED_t *nr_dci_info_extracted); - +*/ #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706) extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; @@ -2824,7 +2825,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_IN); //LOG_I(PHY,"[UE %d] Frame %d, Trying PBCH %d (NidCell %d, eNB_id %d)\n",ue->Mod_id,frame_rx,pbch_phase,ue->frame_parms.Nid_cell,eNB_id); - ret = nr_rx_pbch(ue, proc->subframe_rx, + ret = nr_rx_pbch(ue, proc, ue->pbch_vars[eNB_id], &ue->frame_parms, eNB_id, @@ -3150,7 +3151,6 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * #endif ue->dci_ind.number_of_dcis = dci_cnt; - ue->dl_indication.dci_ind = &ue->dci_ind; // hang on rx_ind instance for (int i=0; i<dci_cnt; i++) { /* @@ -3178,12 +3178,41 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * } if ((dci_alloc_rx[i].format == format1_1)){ // This format not implemented at a first time. FIXME } - NR_DCI_INFO_EXTRACTED_t nr_dci_info_extracted; - #ifdef NR_PDCCH_SCHED_DEBUG - printf("<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Entering function nr_generate_ue_ul_dlsch_params_from_dci with eNB_id=%d dci_cnt=%d\n", - eNB_id, - dci_cnt); - #endif + + + uint8_t status=0; + + LOG_D(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_alloc_rx[i].format,dci_alloc_rx[i].rnti,dci_alloc_rx[i].dci_length,dci_alloc_rx[i].dci_pdu[0],dci_alloc_rx[i].dci_pdu[1]); + + memset(&ue->dci_ind.dci_list[i].dci,0,sizeof(fapi_nr_dci_pdu_rel15_t)); + + ue->dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti; + ue->dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format; + ue->dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE; + ue->dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L; + + status = nr_extract_dci_info(ue, + eNB_id, + ue->frame_parms.frame_type, + dci_alloc_rx[i].dci_length, + dci_alloc_rx[i].rnti, + dci_alloc_rx[i].dci_pdu, + &ue->dci_ind.dci_list[i].dci, + dci_fields_sizes_cnt[i], + dci_alloc_rx[i].format, + nr_tti_rx, + pdcch_vars2->n_RB_BWP[nb_searchspace_active], + pdcch_vars2->n_RB_BWP[nb_searchspace_active], + crc_scrambled_values); + + if(status == 0) { + LOG_W(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> bad DCI %d !!! \n",dci_alloc_rx[i].format); + return(-1); + } + + LOG_D(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> Ending function nr_extract_dci_info()\n"); + + /* nr_generate_ue_ul_dlsch_params_from_dci(ue, eNB_id, frame_rx, @@ -3204,18 +3233,22 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * pdcch_vars2->n_RB_BWP[nb_searchspace_active], crc_scrambled_values, &nr_dci_info_extracted); + */ - ue->dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti; - ue->dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format; - ue->dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE; - ue->dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L; - memcpy(&ue->dci_ind.dci_list[i].dci, &nr_dci_info_extracted, sizeof(fapi_nr_dci_pdu_rel15_t) ); } // end for loop dci_cnt - // TODO: check where should we send up this message. - //ue->if_inst->dl_indication(&ue->dl_indication); - + // fill dl_indication message + ue->dl_indication.module_id = ue->Mod_id; + ue->dl_indication.cc_id = ue->CC_id; + ue->dl_indication.gNB_index = eNB_id; + ue->dl_indication.frame = frame_rx; + ue->dl_indication.slot = nr_tti_rx; + ue->dl_indication.rx_ind = NULL; //no data, only dci for now + ue->dl_indication.dci_ind = &ue->dci_ind; + + // send to mac + ue->if_inst->dl_indication(&ue->dl_indication); #if UE_TIMING_TRACE stop_meas(&ue->dlsch_rx_pdcch_stats); @@ -3563,54 +3596,40 @@ void copy_harq_proc_struct(NR_DL_UE_HARQ_t *harq_processes_dest, NR_DL_UE_HARQ_t memcpy(harq_ack_dest, current_harq_ack, sizeof(nr_harq_status_t)); }*/ -void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, PDSCH_t pdsch, NR_UE_DLSCH_t *dlsch0, NR_UE_DLSCH_t *dlsch1, int s0, int s1) { +void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, PDSCH_t pdsch, NR_UE_DLSCH_t *dlsch0, NR_UE_DLSCH_t *dlsch1) { int nr_tti_rx = proc->nr_tti_rx; int m; - int harq_pid; int i_mod,eNB_id_i,dual_stream_UE; int first_symbol_flag=0; if (dlsch0->active == 0) return; - for (m=s0;m<=s1;m++) { - - if (dlsch0 && (!dlsch1)) { - harq_pid = dlsch0->current_harq_pid; - LOG_D(PHY,"[UE %d] PDSCH type %d active in nr_tti_rx %d, harq_pid %d Symbol %d\n",ue->Mod_id,pdsch,nr_tti_rx,harq_pid,m); - - if ((pdsch==PDSCH) && - (ue->transmission_mode[eNB_id] == 5) && - (dlsch0->harq_processes[harq_pid]->dl_power_off==0) && - (ue->use_ia_receiver ==1)) { - dual_stream_UE = 1; - eNB_id_i = ue->n_connected_eNB; - i_mod = dlsch0->harq_processes[harq_pid]->Qm; - - } - else if((pdsch==PDSCH) && (ue->transmission_mode[eNB_id]==3)) - { - dual_stream_UE = rx_IC_dual_stream; - eNB_id_i = eNB_id; - i_mod = 0; - } - else { - dual_stream_UE = 0; - eNB_id_i = eNB_id+1; - i_mod = 0; - } + if (dlsch0 && (!dlsch1)) { + int harq_pid = dlsch0->current_harq_pid; + uint16_t pdsch_start_rb = dlsch0->harq_processes[harq_pid]->start_rb; + uint16_t pdsch_nb_rb = dlsch0->harq_processes[harq_pid]->nb_rb; + uint16_t s0 = dlsch0->harq_processes[harq_pid]->start_symbol; + uint16_t s1 = dlsch0->harq_processes[harq_pid]->nb_symbols; + + LOG_D(PHY,"[UE %d] PDSCH type %d active in nr_tti_rx %d, harq_pid %d, rb_start %d, nb_rb %d, symbol_start %d, nb_symbols %d\n",ue->Mod_id,pdsch,nr_tti_rx,harq_pid,pdsch_start_rb,pdsch_nb_rb,s0,s1); + + for (m=s0;m<=s1;m++) { + + if (m==s0) + nr_pdsch_channel_estimation(ue, + 0 /*eNB_id*/, + nr_tti_rx, + 0 /*p*/, + m, + ue->frame_parms.first_carrier_offset+pdsch_start_rb*12, + pdsch_nb_rb); + - //TM7 UE specific channel estimation here!!! - if (ue->transmission_mode[eNB_id]==7) { - if (ue->frame_parms.Ncp==0) { - //if ((m==3) || (m==6) || (m==9) || (m==12)) - //LOG_D(PHY,"[UE %d] dlsch->active in nr_tti_rx %d => %d, l=%d\n",phy_vars_ue->Mod_id,nr_tti_rx,phy_vars_ue->dlsch_ue[eNB_id][0]->active, l); - //lte_dl_bf_channel_estimation(ue,eNB_id,0,nr_tti_rx*2+(m>6?1:0),5,m); - } else { - LOG_E(PHY,"[UE %d]Beamforming channel estimation not supported yet for TM7 extented CP.\n",ue->Mod_id); - } - } + dual_stream_UE = 0; + eNB_id_i = eNB_id+1; + i_mod = 0; if ((m==s0) && (m<3)) first_symbol_flag = 1; @@ -4320,9 +4339,23 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); */ + uint8_t coreset_start=0, coreset_start_set=0; + uint16_t coreset_count = 0; + uint64_t coreset_freq_dom = pdcch_vars->coreset[0].frequencyDomainResources; + for (int i = 0; i < 45; i++) { + if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> (44-i)) & 0x1) { + if (!coreset_start_set) { + coreset_start = i; + coreset_start_set = 1; + } + coreset_count++; + } + } + uint16_t coreset_nb_rb = 6 * coreset_count; + uint16_t coreset_start_rb = 6 * coreset_start; + #ifdef NR_PDCCH_SCHED nr_gold_pdcch(ue,0, 2); - LOG_D(PHY," ------ --> PDCCH ChannelComp/LLR Frame.slot %d.%d ------ \n", frame_rx%1024, nr_tti_rx); for (uint16_t l=0; l<nb_symb_pdcch; l++) { @@ -4335,8 +4368,15 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN l, nr_tti_rx, 0, - 0, - NR_PDCCH_EST); + 0); + + nr_pdcch_channel_estimation(ue,0, + nr_tti_rx, + l, + ue->frame_parms.first_carrier_offset+coreset_start_rb*12, + coreset_nb_rb); + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT); #if UE_TIMING_TRACE stop_meas(&ue->ofdm_demod_stats); @@ -4379,8 +4419,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN m, //to be updated from higher layer nr_tti_rx, 0, - 0, - NR_PDSCH_EST); + 0); //printf("phy procedure pdsch start measurement\n"); nr_ue_measurement_procedures(m,ue,proc,eNB_id,(nr_tti_rx<<1),mode); @@ -4403,12 +4442,13 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, PDSCH, ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], - NULL, - nb_symb_pdcch, //ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (nb_symb_sch+nb_symb_pdcch-1)); //ue->frame_parms.symbols_per_tti>>1, + NULL); /* - write_output("rxF_ext.m","rxFe",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_ext[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); + write_output("rxF.m","rxF",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF[0][0],ue->frame_parms.ofdm_symbol_size*14,1,1); + write_output("rxF_ch.m","rxFch",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->dl_ch_estimates[0][0],ue->frame_parms.ofdm_symbol_size*14,1,1); + write_output("rxF_ch_ext.m","rxFche",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->dl_ch_estimates_ext[0][2*50*12],50*12,1,1); + write_output("rxF_ext.m","rxFe",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_ext[0][0],50*12*14,1,1); write_output("rxF_comp.m","rxFc",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_comp0[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); write_output("rxF_llr.m","rxFllr",ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->llr[0],(nb_symb_sch-1)*50*12+50*6,1,0); */ @@ -4424,9 +4464,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, SI_PDSCH, ue->dlsch_SI[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT); } @@ -4438,9 +4477,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, P_PDSCH, ue->dlsch_p[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT); } @@ -4452,9 +4490,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, RA_PDSCH, ue->dlsch_ra[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT); } @@ -4472,8 +4509,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN (ue->symbol_offset+i), //mu=1 case B nr_tti_rx, 0, - 0, - NR_PBCH_EST); + 0); #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); @@ -4553,9 +4589,7 @@ start_meas(&ue->generic_stat); eNB_id, SI_PDSCH, ue->dlsch_SI[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, proc, @@ -4576,9 +4610,7 @@ start_meas(&ue->generic_stat); eNB_id, P_PDSCH, ue->dlsch_p[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, @@ -4599,9 +4631,7 @@ start_meas(&ue->generic_stat); eNB_id, RA_PDSCH, ue->dlsch_ra[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, proc, diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1416905696afb8981d3cfd4bc82b537873f592e6..b95ea7502e60ab390f3bbf416175f561a7e53fee 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -45,11 +45,14 @@ #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED_NR/sched_nr.h" +#include "SCHED_NR/fapi_nr_l1.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" #include "LAYER2/NR_MAC_UE/mac_extern.h" +#include "LAYER2/NR_MAC_UE/mac_proto.h" +#include "LAYER2/NR_MAC_gNB/mac_proto.h" #include "NR_PHY_INTERFACE/NR_IF_Module.h" #include "NR_UE_PHY_INTERFACE/NR_IF_Module.h" @@ -77,8 +80,8 @@ int32_t get_uldl_offset(int nr_bandP) {return(0);} NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} -int8_t dummy_nr_ue_dl_indication(nr_downlink_indication_t *dl_info){return(0);} -int8_t dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} +int dummy_nr_ue_dl_indication(nr_downlink_indication_t *dl_info){return(0);} +int dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) { return(SF_DL);} @@ -111,7 +114,7 @@ void config_common(int Mod_idP, // needed for some functions PHY_VARS_NR_UE ***PHY_vars_UE_g; -uint16_t conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; +short conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; int main(int argc, char **argv) { @@ -510,7 +513,7 @@ int main(int argc, char **argv) gNB_mac = RC.nrmac[0]; config_common(0,0,Nid_cell,78,ssb_pattern,(uint64_t)3640000000L,N_RB_DL); - config_nr_mib(0,0,1,kHz30,0,0,0,0); + config_nr_mib(0,0,1,kHz30,0,0,0,0,0); nr_l2_init_ue(); UE_mac = get_mac_inst(0); @@ -524,7 +527,7 @@ int main(int argc, char **argv) UE->if_inst->ul_indication = dummy_nr_ue_ul_indication; - //mac->if_module = nr_ue_if_module_init(0); + UE_mac->if_module = nr_ue_if_module_init(0); // generate signal @@ -611,11 +614,19 @@ int main(int argc, char **argv) carrier.sizeof_MIB = do_MIB_NR(&carrier,0,ssb_SubcarrierOffset,pdcch_ConfigSIB1,30,2); nr_rrc_mac_config_req_ue(0,0,0,carrier.mib.message.choice.mib,NULL,NULL,NULL); - fapi_nr_dl_config_request_t dl_config; + + // Initial bandwidth part configuration -- full carrier bandwidth + UE_mac->initial_bwp_dl.bwp_id = 0; + UE_mac->initial_bwp_dl.location = 0; + UE_mac->initial_bwp_dl.scs = UE->frame_parms.subcarrier_spacing; + UE_mac->initial_bwp_dl.N_RB = UE->frame_parms.N_RB_DL; + UE_mac->initial_bwp_dl.cyclic_prefix = UE->frame_parms.Ncp; + + fapi_nr_dl_config_request_t *dl_config = &UE_mac->dl_config_request; // Type0 PDCCH search space - dl_config.number_pdus = 1; - dl_config.dl_config_list[0].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.rnti = 0x1234; // to be set + dl_config->number_pdus = 1; + dl_config->dl_config_list[0].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.rnti = 0x1234; uint64_t mask = 0x0; uint16_t num_rbs=24; @@ -626,16 +637,16 @@ int main(int argc, char **argv) mask = mask >> 1; mask = mask | 0x100000000000; } - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.frequency_domain_resource = mask; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.rb_offset = rb_offset; // additional parameter other than coreset + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.frequency_domain_resource = mask; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.rb_offset = rb_offset; // additional parameter other than coreset - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.duration = num_symbols; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_mapping_type =CCE_REG_MAPPING_TYPE_NON_INTERLEAVED; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_reg_bundle_size = 0; // L 38.211 7.3.2.2 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_interleaver_size = 0; // R 38.211 7.3.2.2 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_shift_index = cell_id; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.pdcch_dmrs_scrambling_id = cell_id; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.duration = num_symbols; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_mapping_type =CCE_REG_MAPPING_TYPE_NON_INTERLEAVED; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_reg_bundle_size = 0; // L 38.211 7.3.2.2 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_interleaver_size = 0; // R 38.211 7.3.2.2 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_shift_index = cell_id; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.pdcch_dmrs_scrambling_id = cell_id; uint32_t number_of_search_space_per_slot=1; uint32_t first_symbol_index=0; @@ -644,15 +655,23 @@ int main(int argc, char **argv) coreset_duration = num_symbols * number_of_search_space_per_slot; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[0] = table_38213_10_1_1_c2[0]; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[1] = table_38213_10_1_1_c2[1]; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[2] = table_38213_10_1_1_c2[2]; // CCE aggregation level = 4 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[3] = table_38213_10_1_1_c2[3]; // CCE aggregation level = 8 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[4] = table_38213_10_1_1_c2[4]; // CCE aggregation level = 16 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; - - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = N_RB_DL; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[0] = table_38213_10_1_1_c2[0]; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[1] = table_38213_10_1_1_c2[1]; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[2] = table_38213_10_1_1_c2[2]; // CCE aggregation level = 4 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[3] = table_38213_10_1_1_c2[3]; // CCE aggregation level = 8 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[4] = table_38213_10_1_1_c2[4]; // CCE aggregation level = 16 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; + + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = N_RB_DL; + + UE_mac->scheduled_response.dl_config = dl_config; + UE_mac->scheduled_response.ul_config = NULL; + UE_mac->scheduled_response.tx_request = NULL; + UE_mac->scheduled_response.module_id = 0; + UE_mac->scheduled_response.CC_id = 0; + UE_mac->scheduled_response.frame = frame; + UE_mac->scheduled_response.slot = slot; for (SNR=snr0; SNR<snr1; SNR+=.2) { @@ -684,7 +703,8 @@ int main(int argc, char **argv) LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1); } if (UE->is_synchronized == 0) { - ret = nr_initial_sync(UE, normal_txrx); + UE_nr_rxtx_proc_t proc={0}; + ret = nr_initial_sync(&proc, UE, normal_txrx); printf("nr_initial_sync1 returns %d\n",ret); if (ret<0) n_errors++; } @@ -695,7 +715,6 @@ int main(int argc, char **argv) UE_proc.nr_tti_rx= slot; UE_proc.subframe_rx = slot; - UE_mac->scheduled_response.dl_config = &dl_config; nr_ue_scheduled_response(&UE_mac->scheduled_response); printf("Running phy procedures UE RX %d.%d\n",frame,slot); diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index e4ff2f48d7b449a939edf6ebf54f08e2690ae182..61d4c486f5e51d1afed3c92ee8099b0926719dfe 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -600,7 +600,8 @@ int main(int argc, char **argv) } if (UE->is_synchronized == 0) { - ret = nr_initial_sync(UE, normal_txrx); + UE_nr_rxtx_proc_t proc={0}; + ret = nr_initial_sync(&proc, UE, normal_txrx); printf("nr_initial_sync1 returns %d\n",ret); if (ret<0) n_errors++; } @@ -616,14 +617,14 @@ int main(int argc, char **argv) i, 0, 0, - 0, - NR_PBCH_EST); + 0); nr_pbch_channel_estimation(UE,0,0,i,i-(UE->symbol_offset+1),ssb_index%8,n_hf); } + UE_nr_rxtx_proc_t proc={0}; ret = nr_rx_pbch(UE, - 0, + &proc, UE->pbch_vars[0], frame_parms, 0, diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 4f69c4db189d669e448edd61638599109d315339..f196293ea0890a44070c7c989b072cd4bb4ab984 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -57,6 +57,8 @@ #include "fapi_nr_ue_interface.h" #include "NR_IF_Module.h" +#include "PHY/defs_nr_common.h" + #define NB_NR_UE_MAC_INST 1 typedef enum { @@ -64,44 +66,42 @@ typedef enum { SFN_C_MOD_2_EQ_1 } SFN_C_TYPE; + /*!\brief Top level UE MAC structure */ typedef struct { - - //// MAC config - NR_DRX_Config_t *drx_Config; - NR_SchedulingRequestConfig_t *schedulingRequestConfig; - NR_BSR_Config_t *bsr_Config; - NR_TAG_Config_t *tag_Config; - NR_PHR_Config_t *phr_Config; - NR_RNTI_Value_t *cs_RNTI; - NR_MIB_t *mib; - - /// Type0-PDCCH seach space - fapi_nr_dl_config_dci_dl_pdu_rel15_t type0_pdcch_dci_config; - uint32_t type0_pdcch_ss_mux_pattern; - SFN_C_TYPE type0_pdcch_ss_sfn_c; - uint32_t type0_pdcch_ss_n_c; - uint32_t type0_pdcch_consecutive_slots; - - /// Random access parameter - uint16_t ra_rnti; - - - //// FAPI-like interface message - fapi_nr_tx_request_t tx_request; - fapi_nr_ul_config_request_t ul_config_request; - fapi_nr_dl_config_request_t dl_config_request; - - - - /// Interface module instances - nr_ue_if_module_t *if_module; - nr_scheduled_response_t scheduled_response; - nr_phy_config_t phy_config; - - - - + + //// MAC config + NR_DRX_Config_t *drx_Config; + NR_SchedulingRequestConfig_t *schedulingRequestConfig; + NR_BSR_Config_t *bsr_Config; + NR_TAG_Config_t *tag_Config; + NR_PHR_Config_t *phr_Config; + NR_RNTI_Value_t *cs_RNTI; + NR_MIB_t *mib; + + /// Type0-PDCCH seach space + fapi_nr_dl_config_dci_dl_pdu_rel15_t type0_pdcch_dci_config; + uint32_t type0_pdcch_ss_mux_pattern; + SFN_C_TYPE type0_pdcch_ss_sfn_c; + uint32_t type0_pdcch_ss_n_c; + uint32_t type0_pdcch_consecutive_slots; + + /// Random access parameter + uint16_t ra_rnti; + + //BWP params + NR_BWP_PARMS initial_bwp_dl; + NR_BWP_PARMS initial_bwp_ul; + + //// FAPI-like interface message + fapi_nr_tx_request_t tx_request; + fapi_nr_ul_config_request_t ul_config_request; + fapi_nr_dl_config_request_t dl_config_request; + + /// Interface module instances + nr_ue_if_module_t *if_module; + nr_scheduled_response_t scheduled_response; + nr_phy_config_t phy_config; } NR_UE_MAC_INST_t; typedef enum seach_space_mask_e { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 23792337761a955c8699f3c92fb4949875ab67a3..c338920397764f6554e07702ed6a58c4a0c09097 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -35,6 +35,7 @@ #include "mac_defs.h" #include "mac.h" +#include <openair1/PHY/defs_nr_UE.h> /**\brief decode mib pdu in NR_UE, from if_module ul_ind with P7 tx_ind message \param module_id module id @@ -46,6 +47,7 @@ \param pdu_length length of pdu \param cell_id cell id */ int8_t nr_ue_decode_mib( + UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, uint8_t gNB_index, diff --git a/openair2/LAYER2/NR_MAC_UE/mac_vars.c b/openair2/LAYER2/NR_MAC_UE/mac_vars.c index b2b1fa0ed1a6fc02f5ea9cdf23480c66366dfbcd..95dea61a4588578de1cf15ea2348501cca1b14bb 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_vars.c +++ b/openair2/LAYER2/NR_MAC_UE/mac_vars.c @@ -90,7 +90,7 @@ const float table_38213_13_12_c3[16] = { 1, 0.5f, 1, 0.5f, 1, 0.5f, 0.5f, 0.5f const int32_t table_38213_10_1_1_c2[5] = { 0, 0, 4, 2, 1 }; - +/* #define mu_pusch 1 // definition table j Table 6.1.2.1.1-4 #define j ((mu_pusch==3)?3:(mu_pusch==2)?2:1) @@ -131,4 +131,5 @@ const int32_t table_38213_10_1_1_c2[5] = { 0, 0, 4, 2, 1 }; {0,2,4}, // row index 14 {0,4,7}, // row index 15 {0,8,4} // row index 16 - }; \ No newline at end of file + }; +*/ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 7110a35331597195cd6a3f01ae968dc32ee53e6a..b4a06ddb664af0d16de79319327d03efe56d2216 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -186,13 +186,14 @@ int8_t nr_ue_process_dlsch(module_id_t module_id, int cc_id, uint8_t gNB_index, ul_config->ul_config_list[ul_config->number_pdus].pucch_config_pdu.twoPUCCH_PC_AdjustmentStates = 0; } - if(mac->if_module != NULL && mac->if_module->ul_indication != NULL){ - mac->if_module->dl_indication(&mac->scheduled_response); + if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL){ + mac->if_module->scheduled_response(&mac->scheduled_response); } return 0; } int8_t nr_ue_decode_mib( + UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, uint8_t gNB_index, @@ -235,12 +236,12 @@ int8_t nr_ue_decode_mib( #ifdef DEBUG_MIB printf("system frame number(6 MSB bits): %d\n", mac->mib->systemFrameNumber.buf[0]); printf("system frame number(with LSB): %d\n", (int)frame); - printf("subcarrier spacing: %d\n", (int)mac->mib->subCarrierSpacingCommon); + printf("subcarrier spacing (0=15or60, 1=30or120): %d\n", (int)mac->mib->subCarrierSpacingCommon); printf("ssb carrier offset(with MSB): %d\n", (int)ssb_subcarrier_offset); - printf("dmrs type A position: %d\n", (int)mac->mib->dmrs_TypeA_Position); + printf("dmrs type A position (0=pos2,1=pos3): %d\n", (int)mac->mib->dmrs_TypeA_Position); printf("pdcch config sib1: %d\n", (int)mac->mib->pdcch_ConfigSIB1); - printf("cell barred: %d\n", (int)mac->mib->cellBarred); - printf("intra frequency reselection: %d\n", (int)mac->mib->intraFreqReselection); + printf("cell barred (0=barred,1=notBarred): %d\n", (int)mac->mib->cellBarred); + printf("intra frequency reselection (0=allowed,1=notAllowed): %d\n", (int)mac->mib->intraFreqReselection); printf("half frame bit(extra bits): %d\n", (int)half_frame_bit); printf("ssb index(extra bits): %d\n", (int)ssb_index); #endif @@ -594,6 +595,7 @@ int8_t nr_ue_decode_mib( if(mac->if_module != NULL && mac->if_module->phy_config_request != NULL){ mac->if_module->phy_config_request(&mac->phy_config); } + proc->decoded_frame_rx=frame; //} return 0; } @@ -660,9 +662,10 @@ NR_UE_L2_STATE_t nr_ue_scheduler( dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15 = mac->type0_pdcch_dci_config; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; + /* dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti = 0xaaaa; // to be set dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106; // to be set - /* + printf("nr_ue_scheduler Type0 PDCCH with rnti %x, BWP %d\n", dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti, dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP); @@ -1122,19 +1125,19 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( fapi_nr_ul_config_pusch_pdu_rel15_t *ulsch_config_pdu, fapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_config_pdu, uint8_t time_domain_ind, - long dmrs_typeA_pos + long dmrs_typeA_pos //0=pos2,1=pos3 ){ uint8_t k_offset=0; uint8_t sliv_S=0; uint8_t sliv_L=0; uint8_t table_5_1_2_1_1_2_time_dom_res_alloc_A[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?12:11}, // row index 1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?10:9}, // row index 2 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?9:8}, // row index 3 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?7:6}, // row index 4 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?5:4}, // row index 5 - {0,(dmrs_typeA_pos == 2)?9:10,(dmrs_typeA_pos == 2)?4:4}, // row index 6 - {0,(dmrs_typeA_pos == 2)?4:6, (dmrs_typeA_pos == 2)?4:4}, // row index 7 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?12:11}, // row index 1 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?10:9}, // row index 2 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?9:8}, // row index 3 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?7:6}, // row index 4 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?5:4}, // row index 5 + {0,(dmrs_typeA_pos == 0)?9:10,(dmrs_typeA_pos == 0)?4:4}, // row index 6 + {0,(dmrs_typeA_pos == 0)?4:6, (dmrs_typeA_pos == 0)?4:4}, // row index 7 {0,5,7}, // row index 8 {0,5,2}, // row index 9 {0,9,2}, // row index 10 @@ -1146,13 +1149,13 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4} // row index 16 }; uint8_t table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?6:5}, // row index 1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?10:9}, // row index 2 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?9:8}, // row index 3 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?7:6}, // row index 4 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?5:4}, // row index 5 - {0,(dmrs_typeA_pos == 2)?6:8, (dmrs_typeA_pos == 2)?4:2}, // row index 6 - {0,(dmrs_typeA_pos == 2)?4:6, (dmrs_typeA_pos == 2)?4:4}, // row index 7 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?6:5}, // row index 1 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?10:9}, // row index 2 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?9:8}, // row index 3 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?7:6}, // row index 4 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?5:4}, // row index 5 + {0,(dmrs_typeA_pos == 0)?6:8, (dmrs_typeA_pos == 0)?4:2}, // row index 6 + {0,(dmrs_typeA_pos == 0)?4:6, (dmrs_typeA_pos == 0)?4:4}, // row index 7 {0,5,6}, // row index 8 {0,5,2}, // row index 9 {0,9,2}, // row index 10 @@ -1177,7 +1180,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4}, // row index 11 {0,10,4}, // row index 12 {0,2,7}, // row index 13 - {0,(dmrs_typeA_pos == 2)?2:3,(dmrs_typeA_pos == 2)?12:11}, // row index 14 + {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {1,2,4}, // row index 15 {0,0,0} // row index 16 }; @@ -1195,7 +1198,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4}, // row index 11 {0,10,4}, // row index 12 {0,2,7}, // row index 13 - {0,(dmrs_typeA_pos == 2)?2:3,(dmrs_typeA_pos == 2)?12:11}, // row index 14 + {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {0,0,6}, // row index 15 {0,2,6} // row index 16 }; @@ -1243,9 +1246,9 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( * TS 38.214 subclause 5.1.2.1 Resource allocation in time domain (downlink) */ if(dlsch_config_pdu != NULL){ - k_offset = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][0]; - sliv_S = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][1]; - sliv_L = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][2]; + k_offset = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][0]; + sliv_S = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][1]; + sliv_L = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][2]; // k_offset = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][0]; // sliv_S = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][1]; // sliv_L = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][2]; @@ -1262,9 +1265,9 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( * TS 38.214 subclause 6.1.2.1 Resource allocation in time domain (uplink) */ if(ulsch_config_pdu != NULL){ - k_offset = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][0]; - sliv_S = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][1]; - sliv_L = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][2]; + k_offset = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][0]; + sliv_S = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][1]; + sliv_L = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][2]; // k_offset = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][0]; // sliv_S = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][1]; // sliv_L = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][2]; @@ -1281,10 +1284,12 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request; - const uint16_t n_RB_ULBWP = 106; - const uint16_t n_RB_DLBWP = 106; + + //const uint16_t n_RB_DLBWP = dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP; //make sure this has been set + const uint16_t n_RB_DLBWP = mac->initial_bwp_dl.N_RB; + const uint16_t n_RB_ULBWP = mac->initial_bwp_ul.N_RB; -printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); + printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d (DL BWP %d, UL BWP %d)\n",dci_format,n_RB_DLBWP,n_RB_ULBWP); switch(dci_format){ case format0_0: @@ -1741,8 +1746,6 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); /* PDSCH_TO_HARQ_FEEDBACK_TIME_IND (only if CRC scrambled by C-RNTI or CS-RNTI or new-RNTI)*/ dlsch_config_pdu_1_0->pdsch_to_harq_feedback_time_ind = dci->pdsch_to_harq_feedback_time_ind; - dl_config->number_pdus = dl_config->number_pdus + 1; - printf("\n>>> (nr_ue_procedures.c) rnti=%d dl_config->number_pdus=%d\n", dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.rnti, dl_config->number_pdus); @@ -1767,17 +1770,11 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); dlsch_config_pdu_1_0->pdsch_to_harq_feedback_time_ind); dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; - + dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; + printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); - if(mac->if_module != NULL && mac->if_module->dl_indication != NULL) - //printf(">>> mac->if_module->dl_indication(&mac->phy_config); \n"); - //for (int k=0;k<1000;k++) printf(">>> %d ",k); - //mac->if_module->dl_indication(&mac->dl_info); - //mac->if_module->dl_indication(&mac->dl_config_request); - mac->if_module->dl_indication(&mac->phy_config); - - + dl_config->number_pdus = dl_config->number_pdus + 1; break; case format1_1: @@ -1959,14 +1956,13 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); /* DMRS_SEQ_INI */ //FIXME!!! - dl_config->number_pdus = dl_config->number_pdus + 1; - + dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; + dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); - if(mac->if_module != NULL && mac->if_module->dl_indication != NULL) - mac->if_module->dl_indication(&mac->phy_config); - + dl_config->number_pdus = dl_config->number_pdus + 1; + break; case format2_0: @@ -1986,7 +1982,6 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); } - if(rnti == SI_RNTI){ }else if(rnti == mac->ra_rnti){ diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index 1e5150c93f4e95c0aa96023212fa63639c8ea0f7..def897433ea6604fb390b32d9c23ed62067690bd 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -385,19 +385,18 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, // Note: This should not be done in the MAC! for (int ii=0; ii<MAX_MOBILES_PER_GNB; ii++) { - LTE_eNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii]; + NR_gNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii][0]; if((ulsch != NULL) && (ulsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_ulsch UE %x \n", rnti); - clean_eNb_ulsch(ulsch); + LOG_W(MAC, "TODO: clean_eNb_ulsch UE %x \n", rnti); + //clean_eNb_ulsch(ulsch); } } for (int ii=0; ii<MAX_MOBILES_PER_GNB; ii++) { NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0]; if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - LOG_E(PHY,"Calling with wrong paramter type\n"); - clean_eNb_dlsch(dlsch); + LOG_W(MAC, "TODO: clean_eNb_dlsch UE %x \n", rnti); + //clean_eNb_dlsch(dlsch); } } diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 6f0bd9d595aa6bf8db6b9b131fdbec6784521a97..97a417fea1da2d28b0c94b32fa571da893dbebd7 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -67,6 +67,10 @@ void nr_schedule_css_dlsch_phytest(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP); +void nr_schedule_uss_dlsch_phytest(module_id_t module_idP, + frame_t frameP, + sub_frame_t slotP); + void nr_configure_css_dci_initial(nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params, nr_scs_e scs_common, @@ -108,4 +112,14 @@ uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn); uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw); +void config_nr_mib(int Mod_idP, + int CC_idP, + int p_gNBP, + int subCarrierSpacingCommon, + uint32_t ssb_SubcarrierOffset, + int dmrs_TypeA_Position, + uint32_t pdcch_ConfigSIB1, + int cellBarred, + int intraFreqReselection); + #endif /*__LAYER2_NR_MAC_PROTO_H__*/ diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index e391cc67b9964b739bf38f6618127eff88c2fe38..a8b314426240af03b03e004b6e2fdbf5441a8b44 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -34,6 +34,7 @@ #include "mac_proto.h" #include "assertions.h" #include "LAYER2/NR_MAC_UE/mac_extern.h" +#include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include <stdio.h> @@ -42,9 +43,10 @@ static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES]; // L2 Abstraction Layer -int handle_bcch_bch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){ +int handle_bcch_bch(UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){ - return nr_ue_decode_mib( module_id, + return nr_ue_decode_mib( proc, + module_id, cc_id, gNB_index, additional_bits, @@ -126,16 +128,26 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ uint32_t ret_mask = 0x0; module_id_t module_id = dl_info->module_id; NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - - // clean up scheduled_response structure - + fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request; + + dl_config->number_pdus = 0; + ul_config->number_pdus = 0; + //hook up pointers + mac->scheduled_response.dl_config = dl_config; + mac->scheduled_response.ul_config = ul_config; + mac->scheduled_response.tx_request = &mac->tx_request; + mac->scheduled_response.module_id = dl_info->module_id; + mac->scheduled_response.CC_id = dl_info->cc_id; + mac->scheduled_response.frame = dl_info->frame; + mac->scheduled_response.slot = dl_info->slot; if(dl_info->dci_ind != NULL){ printf("[L2][IF MODULE][DL INDICATION][DCI_IND]\n"); for(i=0; i<dl_info->dci_ind->number_of_dcis; ++i){ printf(">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis); fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci; - /* + ret_mask |= (handle_dci( dl_info->module_id, dl_info->cc_id, @@ -143,7 +155,7 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ dci, (dl_info->dci_ind->dci_list+i)->rnti, (dl_info->dci_ind->dci_list+i)->dci_format)) << FAPI_NR_DCI_IND; - */ + /*switch((dl_info->dci_ind->dci_list+i)->dci_type){ case FAPI_NR_DCI_TYPE_0_0: @@ -197,7 +209,8 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ for(i=0; i<dl_info->rx_ind->number_pdus; ++i){ switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){ case FAPI_NR_RX_PDU_TYPE_MIB: - ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, + ret_mask |= (handle_bcch_bch( dl_info->proc, + dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.pdu, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.additional_bits, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_index, @@ -244,8 +257,8 @@ nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){ nr_ue_if_module_inst[module_id]->cc_mask=0; nr_ue_if_module_inst[module_id]->current_frame = 0; nr_ue_if_module_inst[module_id]->current_slot = 0; - nr_ue_if_module_inst[module_id]->phy_config_request = NULL; - nr_ue_if_module_inst[module_id]->scheduled_response = NULL; + nr_ue_if_module_inst[module_id]->phy_config_request = nr_ue_phy_config_request; + nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response; nr_ue_if_module_inst[module_id]->dl_indication = nr_ue_dl_indication; nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication; } @@ -264,6 +277,7 @@ int nr_ue_if_module_kill(uint32_t module_id) { int nr_ue_dcireq(nr_dcireq_t *dcireq) { fapi_nr_dl_config_request_t *dl_config=&dcireq->dl_config_req; + NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); // Type0 PDCCH search space dl_config->number_pdus = 1; @@ -305,7 +319,7 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq) { dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; - dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = UE_mac->initial_bwp_dl.N_RB; return 0; diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h index 0ecba9736d5e4bf15239069e10154684e08f3298..c1c85227491927b665676af811dfb7ce16b82471 100755 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h @@ -34,6 +34,7 @@ #define __NR_IF_MODULE_H__ #include "platform_types.h" +#include <openair1/PHY/thread_NR_UE.h> #include "fapi_nr_ue_interface.h" @@ -64,6 +65,7 @@ typedef struct { frame_t frame; /// slot int slot; + UE_nr_rxtx_proc_t * proc; /// NR UE FAPI-like P7 message, direction: L1 to L2 /// data reception indication structure @@ -209,7 +211,7 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq); \param ssb_index SSB index within 0 - (L_ssb-1) corresponding to 38.331 ch.13 parameter i \param ssb_length corresponding to L1 parameter L_ssb \param cell_id cell id */ -int handle_bcch_bch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id); +int handle_bcch_bch(UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id); // TODO check /**\brief handle BCCH-DL-SCH message from dl_indication diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c deleted file mode 100644 index 362300d4d76776ee085f43d91143727c816e3ea5..0000000000000000000000000000000000000000 --- a/targets/RT/USER/nr-ue.c +++ /dev/null @@ -1,1175 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file lte-ue.c - * \brief threads and support functions for real-time LTE UE target - * \author R. Knopp, F. Kaltenberger, Navid Nikaein - * \date 2015 - * \version 0.1 - * \company Eurecom - * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr - * \note - * \warning - */ -#include "nr-uesoftmodem.h" - -#include "rt_wrapper.h" - -#include "LAYER2/NR_MAC_UE/mac.h" -//#include "RRC/LTE/rrc_extern.h" -#include "PHY_INTERFACE/phy_interface_extern.h" - -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "fapi_nr_ue_l1.h" -#include "PHY/phy_extern_nr_ue.h" -#include "PHY/INIT/phy_init.h" -#include "PHY/MODULATION/modulation_UE.h" -#include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "RRC/NR_UE/rrc_proto.h" - -//#ifndef NO_RAT_NR -#include "SCHED_NR/phy_frame_config_nr.h" -//#endif -#include "SCHED_NR_UE/defs.h" - -#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" - -#include "common/utils/LOG/log.h" -#include "common/utils/LOG/vcd_signal_dumper.h" - -#include "T.h" - -#ifdef XFORMS - #include "PHY/TOOLS/nr_phy_scope.h" - - extern char do_forms; -#endif - - -extern double cpuf; -//static nfapi_nr_config_request_t config_t; -//static nfapi_nr_config_request_t* config =&config_t; - -/* - * NR SLOT PROCESSING SEQUENCE - * - * Processing occurs with following steps for connected mode: - * - * - Rx samples for a slot are received, - * - PDCCH processing (including DCI extraction for downlink and uplink), - * - PDSCH processing (including transport blocks decoding), - * - PUCCH/PUSCH (transmission of acknowledgements, CSI, ... or data). - * - * Time between reception of the slot and related transmission depends on UE processing performance. - * It is defined by the value NR_UE_CAPABILITY_SLOT_RX_TO_TX. - * - * In NR, network gives the duration between Rx slot and Tx slot in the DCI: - * - for reception of a PDSCH and its associated acknowledgment slot (with a PUCCH or a PUSCH), - * - for reception of an uplink grant and its associated PUSCH slot. - * - * So duration between reception and it associated transmission depends on its transmission slot given in the DCI. - * NR_UE_CAPABILITY_SLOT_RX_TO_TX means the minimum duration but higher duration can be given by the network because UE can support it. - * -* Slot k -* -------+------------+-------- -* Frame | Tx samples | -* Subframe | buffer | -* Slot n -------+------------+-------- -* ------ +------------+-------- | -* | Rx samples | | -* | buffer | | -* -------+------------+-------- | -* | | -* V | -* +------------+ | -* | PDCCH | | -* | processing | | -* +------------+ | -* | | | -* | v | -* | +------------+ | -* | | PDSCH | | -* | | processing | decoding result | -* | +------------+ -> ACK/NACK of PDSCH | -* | | | -* | v | -* | +-------------+------------+ | -* | | PUCCH/PUSCH | Tx samples | | -* | | processing | transfer | | -* | +-------------+------------+ | -* | | -* |/___________________________________________________________\| -* \ duration between reception and associated transmission / -* -* Remark: processing is done slot by slot, it can be distribute on different threads which are executed in parallel. -* This is an architecture optimization in order to cope with real time constraints. -* By example, for LTE, subframe processing is spread over 4 different threads. -* - */ - -#ifndef NO_RAT_NR - #define DURATION_RX_TO_TX (NR_UE_CAPABILITY_SLOT_RX_TO_TX) /* for NR this will certainly depends to such UE capability which is not yet defined */ -#else - #define DURATION_RX_TO_TX (4) /* For LTE, this duration is fixed to 4 and it is linked to LTE standard for both modes FDD/TDD */ -#endif - -#define FRAME_PERIOD 100000000ULL -#define DAQ_PERIOD 66667ULL -#define FIFO_PRIORITY 40 - -typedef enum { - pss=0, - pbch=1, - si=2 -} sync_mode_t; - -void init_UE_threads(PHY_VARS_NR_UE *UE); -void *UE_thread(void *arg); -void init_UE(int nb_inst); - -int32_t **rxdata; -int32_t **txdata; - -#define SAIF_ENABLED - -#ifdef SAIF_ENABLED - uint64_t g_ue_rx_thread_busy = 0; -#endif - - -PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, - uint8_t UE_id, - uint8_t abstraction_flag) - -{ - PHY_VARS_NR_UE *ue; - - if (frame_parms!=(NR_DL_FRAME_PARMS *)NULL) { // if we want to give initial frame parms, allocate the PHY_VARS_UE structure and put them in - ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); - memset(ue,0,sizeof(PHY_VARS_NR_UE)); - memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); - } else ue = PHY_vars_UE_g[UE_id][0]; - - ue->Mod_id = UE_id; - ue->mac_enabled = 1; - // initialize all signal buffers - init_nr_ue_signal(ue,1,abstraction_flag); - // intialize transport - init_nr_ue_transport(ue,abstraction_flag); - return(ue); -} - -void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char *name) { -#ifdef DEADLINE_SCHEDULER - - if (sched_runtime!=0) { - struct sched_attr attr= {0}; - attr.size = sizeof(attr); - attr.sched_policy = SCHED_DEADLINE; - attr.sched_runtime = sched_runtime; - attr.sched_deadline = sched_deadline; - attr.sched_period = 0; - AssertFatal(sched_setattr(0, &attr, 0) == 0, - "[SCHED] %s thread: sched_setattr failed %s \n", name, strerror(errno)); - LOG_I(HW,"[SCHED][eNB] %s deadline thread %lu started on CPU %d\n", - name, (unsigned long)gettid(), sched_getcpu()); - } - -#else - - if (CPU_COUNT(cpuset) > 0) - AssertFatal( 0 == pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), cpuset), ""); - - struct sched_param sp; - sp.sched_priority = sched_fifo; - AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO,&sp)==0, - "Can't set thread priority, Are you root?\n"); - /* Check the actual affinity mask assigned to the thread */ - cpu_set_t *cset=CPU_ALLOC(CPU_SETSIZE); - - if (0 == pthread_getaffinity_np(pthread_self(), CPU_ALLOC_SIZE(CPU_SETSIZE), cset)) { - char txt[512]= {0}; - - for (int j = 0; j < CPU_SETSIZE; j++) - if (CPU_ISSET(j, cset)) - sprintf(txt+strlen(txt), " %d ", j); - - printf("CPU Affinity of thread %s is %s\n", name, txt); - } - - CPU_FREE(cset); -#endif - // Lock memory from swapping. This is a process wide call (not constraint to this thread). - mlockall(MCL_CURRENT | MCL_FUTURE); - pthread_setname_np( pthread_self(), name ); - // LTS: this sync stuff should be wrong - printf("waiting for sync (%s)\n",name); - pthread_mutex_lock(&sync_mutex); - printf("Locked sync_mutex, waiting (%s)\n",name); - - while (sync_var<0) - pthread_cond_wait(&sync_cond, &sync_mutex); - - pthread_mutex_unlock(&sync_mutex); - printf("started %s as PID: %ld\n",name, gettid()); -} - -void init_UE(int nb_inst) { - int inst; - NR_UE_MAC_INST_t *mac_inst; - - for (inst=0; inst < nb_inst; inst++) { - // UE->rfdevice.type = NONE_DEV; - //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); - PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); - PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); - nr_l3_init_ue(); - nr_l2_init_ue(); - mac_inst = get_mac_inst(0); - mac_inst->if_module = UE->if_inst; - UE->if_inst->scheduled_response = nr_ue_scheduled_response; - UE->if_inst->phy_config_request = nr_ue_phy_config_request; - 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); - //UE = PHY_vars_UE_g[inst][0]; - AssertFatal(0 == pthread_create(&UE->proc.pthread_ue, - &UE->proc.attr_ue, - UE_thread, - (void *)UE), ""); - } - - 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 -} - -/*! - * \brief This is the UE synchronize thread. - * It performs band scanning and synchonization. - * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ -static void *UE_thread_synch(void *arg) { - - static int __thread UE_thread_synch_retval; - int i, hw_slot_offset; - PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; - int current_band = 0; - int current_offset = 0; - lte_frame_type_t current_type; - sync_mode_t sync_mode = pbch; - int CC_id = UE->CC_id; - int freq_offset=0; - char threadname[128]; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - if ( threads.sync != -1 ) - CPU_SET(threads.sync, &cpuset); - - // this thread priority must be lower that the main acquisition thread - sprintf(threadname, "sync UE %d", UE->Mod_id); - init_thread(100000, 500000, FIFO_PRIORITY-1, &cpuset, threadname); - UE->is_synchronized = 0; - - printf("UE_scan %d\n",UE->UE_scan); - - if (UE->UE_scan == 0) { - - get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); - - LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", - downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], - oai_exit, openair0_cfg[0].rx_num_channels); - - for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - - if (uplink_frequency_offset[CC_id][i] != 0) // - openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_FDD; - else //FDD - openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_TDD; - } - - sync_mode = pbch; - } else { - current_band=0; - LOG_E(PHY,"Fixme!\n"); - /* - for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { - downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[CC_id].dl_min; - uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = - bands_to_scan.band_info[CC_id].ul_min-bands_to_scan.band_info[CC_id].dl_min; - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; - } - */ - } - - // AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); - - while (oai_exit==0) { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - - while (UE->proc.instance_cnt_synch < 0) - // the thread waits here most of the time - pthread_cond_wait( &UE->proc.cond_synch, &UE->proc.mutex_synch ); - - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - switch (sync_mode) { - /* - case pss: - LOG_I(PHY,"[SCHED][UE] Scanning band %d (%d), freq %u\n",bands_to_scan.band_info[current_band].band, current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); - //lte_sync_timefreq(UE,current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); - current_offset += 20000000; // increase by 20 MHz - - if (current_offset > bands_to_scan.band_info[current_band].dl_max-bands_to_scan.band_info[current_band].dl_min) { - current_band++; - current_offset=0; - } - - if (current_band==bands_to_scan.nbands) { - current_band=0; - oai_exit=1; - } - - for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { - downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].dl_min+current_offset; - uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].ul_min-bands_to_scan.band_info[0].dl_min + current_offset; - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; - - if (UE->UE_scan_carrier) { - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - } - } - - break; - */ - case pbch: -#if DISABLE_LOG_X - printf("[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); -#else - LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); -#endif - - if (nr_initial_sync( UE, UE->mode ) == 0) { - //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (10*UE->frame_parms.samples_per_slot), 1, 1); - freq_offset = UE->common_vars.freq_offset; // frequency offset computed with pss in initial sync - hw_slot_offset = (UE->rx_offset<<1) / UE->frame_parms.samples_per_slot; - printf("Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", - hw_slot_offset, - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset, - UE->UE_scan_carrier ); - - // rerun with new cell parameters and frequency-offset - for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; - - if (freq_offset >= 0) - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] += abs(freq_offset); - else - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] -= abs(freq_offset); - - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i]+uplink_frequency_offset[CC_id][i]; - downlink_frequency[CC_id][i] = openair0_cfg[CC_id].rx_freq[i]; - } - - // reconfigure for potentially different bandwidth - switch(UE->frame_parms.N_RB_DL) { - case 6: - openair0_cfg[UE->rf_map.card].sample_rate =1.92e6; - openair0_cfg[UE->rf_map.card].rx_bw =.96e6; - openair0_cfg[UE->rf_map.card].tx_bw =.96e6; - // openair0_cfg[0].rx_gain[0] -= 12; - break; - - case 25: - openair0_cfg[UE->rf_map.card].sample_rate =7.68e6; - openair0_cfg[UE->rf_map.card].rx_bw =2.5e6; - openair0_cfg[UE->rf_map.card].tx_bw =2.5e6; - // openair0_cfg[0].rx_gain[0] -= 6; - break; - - case 50: - openair0_cfg[UE->rf_map.card].sample_rate =15.36e6; - openair0_cfg[UE->rf_map.card].rx_bw =5.0e6; - openair0_cfg[UE->rf_map.card].tx_bw =5.0e6; - // openair0_cfg[0].rx_gain[0] -= 3; - break; - - case 100: - openair0_cfg[UE->rf_map.card].sample_rate=30.72e6; - openair0_cfg[UE->rf_map.card].rx_bw=10.0e6; - openair0_cfg[UE->rf_map.card].tx_bw=10.0e6; - // openair0_cfg[0].rx_gain[0] -= 0; - break; - } - - if (UE->mode != loop_through_memory) { - UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); - //UE->rfdevice.trx_set_gains_func(&openair0,&openair0_cfg[0]); - //UE->rfdevice.trx_stop_func(&UE->rfdevice); - // sleep(1); - //nr_init_frame_parms_ue(&UE->frame_parms); - /*if (UE->rfdevice.trx_start_func(&UE->rfdevice) != 0 ) { - LOG_E(HW,"Could not start the device\n"); - oai_exit=1; - }*/ - } - - if (UE->UE_scan_carrier == 1) { - UE->UE_scan_carrier = 0; - } else { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - UE->is_synchronized = 1; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - if( UE->mode == rx_dump_frame ) { - FILE *fd; - - if ((UE->proc.proc_rxtx[0].frame_rx&1) == 0) { // this guarantees SIB1 is present - if ((fd = fopen("rxsig_frame0.dat","w")) != NULL) { - fwrite((void *)&UE->common_vars.rxdata[0][0], - sizeof(int32_t), - 10*UE->frame_parms.samples_per_subframe, - fd); - LOG_I(PHY,"Dummping Frame ... bye bye \n"); - fclose(fd); - exit(0); - } else { - LOG_E(PHY,"Cannot open file for writing\n"); - exit(0); - } - } else { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - UE->is_synchronized = 0; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - } - } - } - } else { - // initial sync failed - // calculate new offset and try again - if (UE->UE_scan_carrier == 1) { - if (freq_offset >= 0) - freq_offset += 100; - - freq_offset *= -1; - - if (abs(freq_offset) > 7500) { - LOG_I( PHY, "[initial_sync] No cell synchronization found, abandoning\n" ); - FILE *fd; - - if ((fd = fopen("rxsig_frame0.dat","w"))!=NULL) { - fwrite((void *)&UE->common_vars.rxdata[0][0], - sizeof(int32_t), - 10*UE->frame_parms.samples_per_subframe, - fd); - LOG_I(PHY,"Dummping Frame ... bye bye \n"); - fclose(fd); - exit(0); - } - - //mac_xface->macphy_exit("No cell synchronization found, abandoning"); new mac - return &UE_thread_synch_retval; // not reached - } - } - -#if DISABLE_LOG_X - printf("[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n", - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset ); -#else - LOG_I(PHY, "[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n", - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset ); -#endif - - for (i=0; i<openair0_cfg[UE->rf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+freq_offset; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]+freq_offset; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; - - if (UE->UE_scan_carrier==1) - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - } - - if (UE->mode != loop_through_memory) - UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); - }// initial_sync=0 - - break; - - case si: - default: - break; - } - -#if 0 //defined XFORMS - - if (do_forms) { - extern FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; - phy_scope_UE(form_ue[0], - PHY_vars_UE_g[0][0], - 0,0,1); - } - -#endif - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - // indicate readiness - UE->proc.instance_cnt_synch--; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_THREAD_SYNCH, 0 ); - } // while !oai_exit - - return &UE_thread_synch_retval; -} - -void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { - // Process Rx data for one sub-frame - if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_DOWNLINK_SLOT) { - //clean previous FAPI MESSAGE - UE->rx_ind.number_pdus = 0; - UE->dci_ind.number_of_dcis = 0; - //clean previous FAPI MESSAGE - // call L2 for DL_CONFIG (DCI) - UE->dcireq.module_id = UE->Mod_id; - UE->dcireq.gNB_index = 0; - UE->dcireq.cc_id = 0; - UE->dcireq.frame = proc->frame_rx; - UE->dcireq.slot = proc->nr_tti_rx; - nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later - NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); - UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req; - UE_mac->scheduled_response.slot = proc->nr_tti_rx; - nr_ue_scheduled_response(&UE_mac->scheduled_response); - //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); - printf("Processing slot %d\n",proc->nr_tti_rx); -#ifdef UE_SLOT_PARALLELISATION - phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); -#else - phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode); - // printf(">>> nr_ue_pdcch_procedures ended\n"); -#endif - } - - if (UE->mac_enabled==1) { - // trigger L2 to run ue_scheduler thru IF module - // [TODO] mapping right after NR initial sync - if(UE->if_inst != NULL && UE->if_inst->ul_indication != NULL) { - UE->ul_indication.module_id = 0; - UE->ul_indication.gNB_index = 0; - UE->ul_indication.cc_id = 0; - UE->ul_indication.frame = proc->frame_rx; - UE->ul_indication.slot = proc->nr_tti_rx; - UE->if_inst->ul_indication(&UE->ul_indication); - } - } -} - -/*! - * \brief This is the UE thread for RX subframe n and TX subframe n+4. - * This thread performs the phy_procedures_UE_RX() on every received slot. - * then, if TX is enabled it performs TX for n+4. - * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ - -static void *UE_thread_rxn_txnp4(void *arg) { - struct nr_rxtx_thread_data *rtd = arg; - UE_nr_rxtx_proc_t *proc = rtd->proc; - PHY_VARS_NR_UE *UE = rtd->UE; - //proc->counter_decoder = 0; - proc->instance_cnt_rxtx=-1; - proc->subframe_rx=proc->sub_frame_start; - proc->dci_err_cnt=0; - char threadname[256]; - sprintf(threadname,"UE_%d_proc_%d", UE->Mod_id, proc->sub_frame_start); - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - char timing_proc_name[256]; - sprintf(timing_proc_name,"Delay to process sub-frame proc %d",proc->sub_frame_start); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.one != -1 ) - CPU_SET(threads.one, &cpuset); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.two != -1 ) - CPU_SET(threads.two, &cpuset); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.three != -1 ) - CPU_SET(threads.three, &cpuset); - - //CPU_SET(threads.three, &cpuset); - init_thread(900000,1000000, FIFO_PRIORITY-1, &cpuset, - threadname); - - while (!oai_exit) { - AssertFatal( 0 == pthread_mutex_lock(&proc->mutex_rxtx), "[SCHED][UE] error locking mutex for UE RXTX\n" ); - - while (proc->instance_cnt_rxtx < 0) { - // most of the time, the thread is waiting here - pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); - } - - AssertFatal ( 0== pthread_mutex_unlock(&proc->mutex_rxtx), "[SCHED][UE] error unlocking mutex for UE RXn_TXnp4\n" ); - processSubframeRX(UE, proc); - //printf(">>> mac ended\n"); - // Prepare the future Tx data -#if 0 -#ifndef NO_RAT_NR - - if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_UPLINK_SLOT) -#else - if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_UL) || - (UE->frame_parms.frame_type == FDD) ) -#endif - if (UE->mode != loop_through_memory) - phy_procedures_nrUE_TX(UE,proc,0,0,UE->mode,no_relay); - - //phy_procedures_UE_TX(UE,proc,0,0,UE->mode,no_relay); -#endif -#if 0 - - if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_S) && - (UE->frame_parms.frame_type == TDD)) - if (UE->mode != loop_through_memory) - //phy_procedures_UE_S_TX(UE,0,0,no_relay); - updateTimes(current, &t3, 10000, timing_proc_name); - -#endif - AssertFatal( 0 == pthread_mutex_lock(&proc->mutex_rxtx), "[SCHED][UE] error locking mutex for UE RXTX\n" ); - proc->instance_cnt_rxtx--; -#if BASIC_SIMULATOR - - if (pthread_cond_signal(&proc->cond_rxtx) != 0) abort(); - -#endif - AssertFatal (0 == pthread_mutex_unlock(&proc->mutex_rxtx), "[SCHED][UE] error unlocking mutex for UE RXTX\n" ); - } - - // thread finished - free(arg); - return NULL; -} - -void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - void *rxp[NB_ANTENNAS_RX]; - - for(int x=0; x<10; x++) { - for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) - rxp[i] = ((void *)&UE->common_vars.rxdata[i][0]) + 4*x*UE->frame_parms.samples_per_subframe; - - AssertFatal( UE->frame_parms.samples_per_subframe == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - rxp, - UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx), "readFrame error"); - } - -} - -void trashFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - void *dummy_rx[UE->frame_parms.nb_antennas_rx]; - - for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) - dummy_rx[i]=malloc16(UE->frame_parms.samples_per_subframe*4); - - for (int sf=0; sf<NR_NUMBER_OF_SUBFRAMES_PER_FRAME; sf++) { - //printf("Reading dummy sf %d\n",sf); - AssertFatal( UE->frame_parms.samples_per_subframe == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - dummy_rx, - UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx), "trashFrame error"); - //usleep(500); // this sleep improves in the case of simulated RF and doesn't harm with true radio - } - - for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) - free(dummy_rx[i]); -} - -void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - if (UE->no_timing_correction==0) { - LOG_I(PHY,"Resynchronizing RX by %d samples (mode = %d)\n",UE->rx_offset,UE->mode); - - for ( int size=UE->rx_offset ; size > 0 ; size -= UE->frame_parms.samples_per_subframe ) { - int unitTransfer=size>UE->frame_parms.samples_per_subframe ? UE->frame_parms.samples_per_subframe : size ; - AssertFatal(unitTransfer == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - (void **)UE->common_vars.rxdata, - unitTransfer, - UE->frame_parms.nb_antennas_rx),"syncInFrame error"); - } - } -} - -int computeSamplesShift(PHY_VARS_NR_UE *UE) { - if ( getenv("RFSIMULATOR") != 0) { - LOG_E(PHY,"SET rx_offset %d \n",UE->rx_offset); - //UE->rx_offset_diff=0; - return 0; - } - - // compute TO compensation that should be applied for this frame - if ( UE->rx_offset < 5*UE->frame_parms.samples_per_slot && - UE->rx_offset > 0 ) - return -1 ; - - if ( UE->rx_offset > 5*UE->frame_parms.samples_per_slot && - UE->rx_offset < 10*UE->frame_parms.samples_per_slot ) - return 1; - - return 0; -} - -/*! - * \brief This is the main UE thread. - * This thread controls the other three UE threads: - * - UE_thread_rxn_txnp4 (even subframes) - * - UE_thread_rxn_txnp4 (odd subframes) - * - UE_thread_synch - * \param arg unused - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ - -void *UE_thread(void *arg) { - PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; - // int tx_enabled = 0; - openair0_timestamp timestamp; - void *rxp[NB_ANTENNAS_RX], *txp[NB_ANTENNAS_TX]; - int start_rx_stream = 0; - int i; - char threadname[128]; - int th_id; - const uint16_t table_sf_slot[20] = {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9}; - - for (int i=0; i< RX_NB_TH_MAX; i++ ) - UE->proc.proc_rxtx[i].counter_decoder = 0; - - static uint8_t thread_idx = 0; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - if ( threads.main != -1 ) - CPU_SET(threads.main, &cpuset); - - sprintf(threadname, "Main UE %d", UE->Mod_id); - init_thread(100000, 500000, FIFO_PRIORITY, &cpuset,threadname); - - if ((oaisim_flag == 0) && (UE->mode !=loop_through_memory)) - AssertFatal(0== openair0_device_load(&(UE->rfdevice), &openair0_cfg[0]), ""); - - UE->rfdevice.host_type = RAU_HOST; - init_UE_threads(UE); -#ifdef NAS_UE - //MessageDef *message_p; - //message_p = itti_alloc_new_message(TASK_NAS_UE, INITIALIZE_MESSAGE); - //itti_send_msg_to_task (TASK_NAS_UE, UE->Mod_id + NB_eNB_INST, message_p); -#endif - int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; - int slot_nr=-1; - - //int cumulated_shift=0; - if ((oaisim_flag == 0) && (UE->mode != loop_through_memory)) - AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); - - while (!oai_exit) { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - int instance_cnt_synch = UE->proc.instance_cnt_synch; - int is_synchronized = UE->is_synchronized; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - if (is_synchronized == 0) { -#if BASIC_SIMULATOR - - while (!((instance_cnt_synch = UE->proc.instance_cnt_synch) < 0)) { - printf("ue sync not ready\n"); - usleep(500*1000); - } - -#endif - - if (UE->mode != loop_through_memory) { - if (instance_cnt_synch < 0) { // we can invoke the synch - // grab 10 ms of signal and wakeup synch thread - readFrame(UE, ×tamp); - AssertFatal( 0 == pthread_mutex_lock(&UE->proc.mutex_synch), ""); - AssertFatal( 0 == ++UE->proc.instance_cnt_synch, "[SCHED][UE] UE sync thread busy!!\n" ); - AssertFatal( 0 == pthread_cond_signal(&UE->proc.cond_synch), ""); - AssertFatal( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - } else { - // grab 10 ms of signal into dummy buffer to wait result of sync detection - trashFrame(UE, ×tamp); - } - } - - continue; - } - - if (start_rx_stream==0) { - start_rx_stream=1; - - if (UE->mode != loop_through_memory) { - syncInFrame(UE, ×tamp); - UE->rx_offset=0; - UE->time_sync_cell=0; - UE->proc.proc_rxtx[0].frame_rx++; - - //UE->proc.proc_rxtx[1].frame_rx++; - for (th_id=1; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].frame_rx = UE->proc.proc_rxtx[0].frame_rx; - } - - //printf("first stream frame rx %d\n",UE->proc.proc_rxtx[0].frame_rx); - // read in first symbol - AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - (void **)UE->common_vars.rxdata, - UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, - UE->frame_parms.nb_antennas_rx),"first symbol read error"); - //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0), 1, 1); - //nr_slot_fep(UE,0, 0, 0, 1, NR_PDCCH_EST); - } //UE->mode != loop_through_memory - else - rt_sleep_ns(1000*1000); - - continue; - } - - thread_idx++; - thread_idx%=RX_NB_TH; - //printf("slot_nr %d nb slot frame %d\n",slot_nr, nb_slot_frame); - slot_nr++; - slot_nr %= nb_slot_frame; - UE_nr_rxtx_proc_t *proc = &UE->proc.proc_rxtx[thread_idx]; - // update thread index for received subframe - UE->current_thread_id[slot_nr] = thread_idx; -#if BASIC_SIMULATOR - - for (int t = 0; t < RX_NB_TH; t++) { - UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[t]; - pthread_mutex_lock(&proc->mutex_rxtx); - - while (proc->instance_cnt_rxtx >= 0) pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); - - pthread_mutex_unlock(&proc->mutex_rxtx); - } - -#endif - LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, UE->current_thread_id[slot_nr]); - proc->nr_tti_rx=slot_nr; - proc->subframe_rx=table_sf_slot[slot_nr]; - proc->frame_tx = proc->frame_rx; - proc->nr_tti_tx= slot_nr + DURATION_RX_TO_TX; - - if (proc->nr_tti_tx > nb_slot_frame) { - proc->frame_tx = (proc->frame_tx + 1)%MAX_FRAME_NUMBER; - proc->nr_tti_tx %= nb_slot_frame; - } - - if(slot_nr == 0) { - UE->proc.proc_rxtx[0].frame_rx++; - - //UE->proc.proc_rxtx[1].frame_rx++; - for (th_id=1; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].frame_rx = UE->proc.proc_rxtx[0].frame_rx; - } - } - - if (UE->mode != loop_through_memory) { - for (i=0; i<UE->frame_parms.nb_antennas_rx; i++) - rxp[i] = (void *)&UE->common_vars.rxdata[i][UE->frame_parms.ofdm_symbol_size+ - UE->frame_parms.nb_prefix_samples0+ - slot_nr*UE->frame_parms.samples_per_slot]; - - for (i=0; i<UE->frame_parms.nb_antennas_tx; i++) - txp[i] = (void *)&UE->common_vars.txdata[i][((slot_nr+2)%NR_NUMBER_OF_SUBFRAMES_PER_FRAME)*UE->frame_parms.samples_per_slot]; - - int readBlockSize, writeBlockSize; - - if (slot_nr<(nb_slot_frame - 1)) { - readBlockSize=UE->frame_parms.samples_per_slot; - writeBlockSize=UE->frame_parms.samples_per_slot; - } else { - UE->rx_offset_diff = computeSamplesShift(UE); - readBlockSize=UE->frame_parms.samples_per_slot - - UE->frame_parms.ofdm_symbol_size - - UE->frame_parms.nb_prefix_samples0 - - UE->rx_offset_diff; - writeBlockSize=UE->frame_parms.samples_per_slot - - UE->rx_offset_diff; - } - - AssertFatal(readBlockSize == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - rxp, - readBlockSize, - UE->frame_parms.nb_antennas_rx),"read error"); - AssertFatal( writeBlockSize == - UE->rfdevice.trx_write_func(&UE->rfdevice, - timestamp+ - (2*UE->frame_parms.samples_per_slot) - - UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0 - - openair0_cfg[0].tx_sample_advance, - txp, - writeBlockSize, - UE->frame_parms.nb_antennas_tx, - 1),"write error"); - - if( slot_nr==(nb_slot_frame-1)) { - // read in first symbol of next frame and adjust for timing drift - int first_symbols=writeBlockSize-readBlockSize; - - if ( first_symbols > 0 ) - AssertFatal(first_symbols == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - (void **)UE->common_vars.rxdata, - first_symbols, - UE->frame_parms.nb_antennas_rx),"first symbols read error"); - else - LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols); - } - - pickTime(gotIQs); - // operate on thread sf mod 2 - AssertFatal(pthread_mutex_lock(&proc->mutex_rxtx) ==0,""); -#ifdef SAIF_ENABLED - - if (!(proc->frame_rx%4000)) { - printf("frame_rx=%d rx_thread_busy=%ld - rate %8.3f\n", - proc->frame_rx, g_ue_rx_thread_busy, - (float)g_ue_rx_thread_busy/(proc->frame_rx*10+1)*100.0); - fflush(stdout); - } - -#endif - - //UE->proc.proc_rxtx[0].gotIQs=readTime(gotIQs); - //UE->proc.proc_rxtx[1].gotIQs=readTime(gotIQs); - for (th_id=0; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].gotIQs=readTime(gotIQs); - } - - proc->subframe_tx=proc->nr_tti_rx; - proc->timestamp_tx = timestamp+ - (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- - UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; - proc->instance_cnt_rxtx++; - LOG_D( PHY, "[SCHED][UE %d] UE RX instance_cnt_rxtx %d subframe %d !!\n", UE->Mod_id, proc->instance_cnt_rxtx,proc->subframe_rx); - - if (proc->instance_cnt_rxtx != 0) { -#ifdef SAIF_ENABLED - g_ue_rx_thread_busy++; -#endif - - if ( getenv("RFSIMULATOR") != NULL ) { - do { - AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, ""); - usleep(100); - AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, ""); - } while ( proc->instance_cnt_rxtx >= 0); - } else - LOG_E( PHY, "[SCHED][UE %d] !! UE RX thread busy (IC %d)!!\n", UE->Mod_id, proc->instance_cnt_rxtx); - - AssertFatal( proc->instance_cnt_rxtx <= 4, "[SCHED][UE %d] !!! UE instance_cnt_rxtx > 2 (IC %d) (Proc %d)!!", - UE->Mod_id, proc->instance_cnt_rxtx, - UE->current_thread_id[slot_nr]); - } - - AssertFatal (pthread_cond_signal(&proc->cond_rxtx) ==0,""); - AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) ==0,""); - // initRefTimes(t1); - // initStaticTime(lastTime); - // updateTimes(lastTime, &t1, 20000, "Delay between two IQ acquisitions (case 1)"); - // pickStaticTime(lastTime); - } //UE->mode != loop_through_memory - else { - processSubframeRX(UE,proc); - getchar(); - } // else loop_through_memory - } // while !oai_exit - - return NULL; -} - -/*! - * \brief Initialize the UE theads. - * Creates the UE threads: - * - UE_thread_rxtx0 - * - UE_thread_rxtx1 - * - UE_thread_synch - * - UE_thread_fep_slot0 - * - UE_thread_fep_slot1 - * - UE_thread_dlsch_proc_slot0 - * - UE_thread_dlsch_proc_slot1 - * and the locking between them. - */ -void init_UE_threads(PHY_VARS_NR_UE *UE) { - struct nr_rxtx_thread_data *rtd; - pthread_attr_init (&UE->proc.attr_ue); - pthread_attr_setstacksize(&UE->proc.attr_ue,8192);//5*PTHREAD_STACK_MIN); - pthread_mutex_init(&UE->proc.mutex_synch,NULL); - pthread_cond_init(&UE->proc.cond_synch,NULL); - UE->proc.instance_cnt_synch = -1; - - // the threads are not yet active, therefore access is allowed without locking - for (int i=0; i<RX_NB_TH; i++) { - rtd = calloc(1, sizeof(struct nr_rxtx_thread_data)); - - if (rtd == NULL) abort(); - - rtd->UE = UE; - rtd->proc = &UE->proc.proc_rxtx[i]; - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_rxtx,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_rxtx,NULL); - UE->proc.proc_rxtx[i].sub_frame_start=i; - UE->proc.proc_rxtx[i].sub_frame_step=RX_NB_TH; - printf("Init_UE_threads rtd %d proc %d nb_threads %d i %d\n",rtd->proc->sub_frame_start, UE->proc.proc_rxtx[i].sub_frame_start,RX_NB_TH, i); - pthread_create(&UE->proc.proc_rxtx[i].pthread_rxtx, NULL, UE_thread_rxn_txnp4, rtd); -#ifdef UE_DLSCH_PARALLELISATION - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_dlsch_td,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_dlsch_td,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_dlsch_td,NULL,nr_dlsch_decoding_2thread0, rtd); - //thread 2 - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_dlsch_td1,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_dlsch_td1,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_dlsch_td1,NULL,nr_dlsch_decoding_2thread1, rtd); -#endif -#ifdef UE_SLOT_PARALLELISATION - //pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_slot0_dl_processing,NULL); - //pthread_cond_init(&UE->proc.proc_rxtx[i].cond_slot0_dl_processing,NULL); - //pthread_create(&UE->proc.proc_rxtx[i].pthread_slot0_dl_processing,NULL,UE_thread_slot0_dl_processing, rtd); - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_slot1_dl_processing,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_slot1_dl_processing,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_slot1_dl_processing,NULL,UE_thread_slot1_dl_processing, rtd); -#endif - } - - pthread_create(&UE->proc.pthread_synch,NULL,UE_thread_synch,(void *)UE); -} - - -#ifdef OPENAIR2 - /* - void fill_ue_band_info(void) { - - UE_EUTRA_Capability_t *UE_EUTRA_Capability = UE_rrc_inst[0].UECap->UE_EUTRA_Capability; - int i,j; - - bands_to_scan.nbands = UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.count; - - for (i=0; i<bands_to_scan.nbands; i++) { - - for (j=0; j<sizeof (eutra_bands) / sizeof (eutra_bands[0]); j++) - if (eutra_bands[j].band == UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.array[i]->bandEUTRA) { - memcpy(&bands_to_scan.band_info[i], - &eutra_bands[j], - sizeof(eutra_band_t)); - - printf("Band %d (%lu) : DL %u..%u Hz, UL %u..%u Hz, Duplex %s \n", - bands_to_scan.band_info[i].band, - UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.array[i]->bandEUTRA, - bands_to_scan.band_info[i].dl_min, - bands_to_scan.band_info[i].dl_max, - bands_to_scan.band_info[i].ul_min, - bands_to_scan.band_info[i].ul_max, - (bands_to_scan.band_info[i].frame_type==FDD) ? "FDD" : "TDD"); - break; - } - } - }*/ -#endif - -/* -int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg) { - - int i, CC_id; - NR_DL_FRAME_PARMS *frame_parms; - openair0_rf_map *rf_map; - - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - rf_map = &phy_vars_ue[CC_id]->rf_map; - - AssertFatal( phy_vars_ue[CC_id] !=0, ""); - frame_parms = &(phy_vars_ue[CC_id]->frame_parms); - - // replace RX signal buffers with mmaped HW versions - rxdata = (int32_t**)malloc16( frame_parms->nb_antennas_rx*sizeof(int32_t*) ); - txdata = (int32_t**)malloc16( frame_parms->nb_antennas_tx*sizeof(int32_t*) ); - - for (i=0; i<frame_parms->nb_antennas_rx; i++) { - LOG_I(PHY, "Mapping UE CC_id %d, rx_ant %d, freq %u on card %d, chain %d\n", - CC_id, i, downlink_frequency[CC_id][i], rf_map->card, rf_map->chain+i ); - free( phy_vars_ue[CC_id]->common_vars.rxdata[i] ); - rxdata[i] = (int32_t*)malloc16_clear( 307200*sizeof(int32_t) ); - phy_vars_ue[CC_id]->common_vars.rxdata[i] = rxdata[i]; // what about the "-N_TA_offset" ? // N_TA offset for TDD - } - - for (i=0; i<frame_parms->nb_antennas_tx; i++) { - LOG_I(PHY, "Mapping UE CC_id %d, tx_ant %d, freq %u on card %d, chain %d\n", - CC_id, i, downlink_frequency[CC_id][i], rf_map->card, rf_map->chain+i ); - free( phy_vars_ue[CC_id]->common_vars.txdata[i] ); - txdata[i] = (int32_t*)malloc16_clear( 307200*sizeof(int32_t) ); - phy_vars_ue[CC_id]->common_vars.txdata[i] = txdata[i]; - } - - // rxdata[x] points now to the same memory region as phy_vars_ue[CC_id]->common_vars.rxdata[x] - // txdata[x] points now to the same memory region as phy_vars_ue[CC_id]->common_vars.txdata[x] - // be careful when releasing memory! - // because no "release_ue_buffers"-function is available, at least rxdata and txdata memory will leak (only some bytes) - } - return 0; -} -*/ diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c deleted file mode 100644 index 226010a1dbe9b5e8367202a0782ef3f1a08d1025..0000000000000000000000000000000000000000 --- a/targets/RT/USER/nr-uesoftmodem.c +++ /dev/null @@ -1,1262 +0,0 @@ -/* - * 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 - */ - - -#define _GNU_SOURCE /* See feature_test_macros(7) */ -#include <sched.h> - -#include "T.h" -#include "rt_wrapper.h" - -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "assertions.h" -#include "msc.h" - -#include "PHY/types.h" -#include "PHY/defs_nr_UE.h" -#include "common/ran_context.h" -#include "common/config/config_userapi.h" -#include "common/utils/load_module_shlib.h" -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "../../ARCH/COMMON/common_lib.h" -#include "../../ARCH/ETHERNET/USERSPACE/LIB/if_defs.h" - -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "PHY/phy_vars_nr_ue.h" -#include "PHY/LTE_TRANSPORT/transport_vars.h" -#include "SCHED/sched_common_vars.h" -#include "PHY/MODULATION/modulation_vars.h" -//#include "../../SIMU/USER/init_lte.h" - -#include "LAYER2/MAC/mac.h" -#include "LAYER2/MAC/mac_vars.h" -#include "LAYER2/MAC/mac_proto.h" -#include "RRC/LTE/rrc_vars.h" -#include "PHY_INTERFACE/phy_interface_vars.h" - -#ifdef SMBV -#include "PHY/TOOLS/smbv.h" -unsigned short config_frames[4] = {2,9,11,13}; -#endif -#include "common/utils/LOG/log.h" -#include "common/utils/LOG/vcd_signal_dumper.h" - -#include "UTIL/OPT/opt.h" -#include "enb_config.h" -//#include "PHY/TOOLS/time_meas.h" - -#ifndef OPENAIR2 -#include "UTIL/OTG/otg_vars.h" -#endif - -#if defined(ENABLE_ITTI) -#include "intertask_interface.h" -#include "create_tasks.h" -#endif - -#include "PHY/INIT/phy_init.h" -#include "system.h" -#include "stats.h" -#ifdef XFORMS -#include "PHY/TOOLS/nr_phy_scope.h" -//#include "stats.h" -// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0) -// at eNB 0, an UL scope for every UE -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; -char title[255]; -//unsigned char scope_enb_num_ue = 2; -static pthread_t forms_thread; //xforms -#endif //XFORMS -#include "nr-uesoftmodem.h" - -RAN_CONTEXT_t RC; - -pthread_cond_t sync_cond; -pthread_mutex_t sync_mutex; -int sync_var=-1; //!< protected by mutex \ref sync_mutex. - -uint16_t runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100] -uint16_t runtime_phy_tx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100] - -#if defined(ENABLE_ITTI) -volatile int start_eNB = 0; -volatile int start_UE = 0; -#endif -volatile int oai_exit = 0; - -static clock_source_t clock_source = internal; -static int wait_for_sync = 0; - -unsigned int mmapped_dma=0; -int single_thread_flag=1; - -int threequarter_fs=0; - -uint32_t downlink_frequency[MAX_NUM_CCs][4]; -int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; - -extern int16_t nr_dlsch_demod_shift; - - -//static char *conf_config_file_name = NULL; - -#if defined(ENABLE_ITTI) -static char *itti_dump_file = NULL; -#endif - -int UE_scan = 0; -int UE_scan_carrier = 0; -int UE_fo_compensation = 0; -runmode_t mode = normal_txrx; - -FILE *input_fd=NULL; - - -#if MAX_NUM_CCs == 1 -rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain}}; -double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0}}; -double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0}}; -#else -rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain},{max_gain,max_gain,max_gain,max_gain}}; -double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0},{20,0,0,0}}; -double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0},{20,0,0,0}}; -#endif - -double rx_gain_off = 0.0; - -double sample_rate=30.72e6; -double bw = 10.0e6; - -static int tx_max_power[MAX_NUM_CCs] = {0}; - -char rf_config_file[1024]; - -int chain_offset=0; -int phy_test = 0; -uint8_t usim_test = 0; - -uint8_t dci_Format = 0; -uint8_t agregation_Level =0xFF; - -uint8_t nb_antenna_tx = 1; -uint8_t nb_antenna_rx = 1; - -char ref[128] = "internal"; -char channels[128] = "0"; - -char *parallel_config = NULL; -char *worker_config = NULL; - -static THREAD_STRUCT thread_struct; -void set_parallel_conf(char *parallel_conf) -{ - if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; - printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); -} -void set_worker_conf(char *worker_conf) -{ - if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; - else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; - printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); -} -PARALLEL_CONF_t get_thread_parallel_conf(void) -{ - return thread_struct.parallel_conf; -} -WORKER_CONF_t get_thread_worker_conf(void) -{ - return thread_struct.worker_conf; -} -int rx_input_level_dBm; - -//static int online_log_messages=0; - -#ifdef XFORMS -extern int otg_enabled; -int do_forms=0; -#else -int otg_enabled; -#endif -//int number_of_cards = 1; - -static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; -int16_t node_synch_ref[MAX_NUM_CCs]; - -uint32_t target_dl_mcs = 28; //maximum allowed mcs -uint32_t target_ul_mcs = 20; -uint32_t timing_advance = 0; -uint8_t exit_missed_slots=1; -uint64_t num_missed_slots=0; // counter for the number of missed slots - -extern PHY_VARS_NR_UE* init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, - uint8_t UE_id, - uint8_t abstraction_flag); - -int transmission_mode=1; -int numerology = 0; - -/* -int16_t glog_level = LOG_INFO; -int16_t glog_verbosity = LOG_MED; -int16_t hw_log_level = LOG_INFO; -int16_t hw_log_verbosity = LOG_MED; -int16_t phy_log_level = LOG_INFO; -int16_t phy_log_verbosity = LOG_MED; -int16_t mac_log_level = LOG_INFO; -int16_t mac_log_verbosity = LOG_MED; -int16_t rlc_log_level = LOG_INFO; -int16_t rlc_log_verbosity = LOG_MED; -int16_t pdcp_log_level = LOG_INFO; -int16_t pdcp_log_verbosity = LOG_MED; -int16_t rrc_log_level = LOG_INFO; -int16_t rrc_log_verbosity = LOG_MED; -int16_t opt_log_level = LOG_INFO; -int16_t opt_log_verbosity = LOG_MED; - -# if defined(ENABLE_USE_MME) -int16_t gtpu_log_level = LOG_DEBUG; -int16_t gtpu_log_verbosity = LOG_MED; -int16_t udp_log_level = LOG_DEBUG; -int16_t udp_log_verbosity = LOG_MED; -#endif -#if defined (ENABLE_SECURITY) -int16_t osa_log_level = LOG_INFO; -int16_t osa_log_verbosity = LOG_MED; -#endif -*/ - -char *rrh_UE_ip = "127.0.0.1"; -int rrh_UE_port = 51000; - -/* flag set by eNB conf file to specify if the radio head is local or remote (default option is local) */ -//uint8_t local_remote_radio = BBU_LOCAL_RADIO_HEAD; -/* struct for ethernet specific parameters given in eNB conf file */ -//eth_params_t *eth_params; - -openair0_config_t openair0_cfg[MAX_CARDS]; - -double cpuf; - -char uecap_xer[1024],uecap_xer_in=0; - -int oaisim_flag=0; -int emulate_rf = 0; - -threads_t threads = {-1,-1,-1,-1,-1,-1,-1,-1}; -int threads_offset = 0; - -char* usrp_args=NULL; -char* usrp_clksrc=NULL; - -/* forward declarations */ -void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); - - -/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed - * this is very hackish - find a proper solution - */ -uint8_t abstraction_flag=0; - -/*---------------------BMC: timespec helpers -----------------------------*/ - -struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; -struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; - -struct timespec clock_difftime(struct timespec start, struct timespec end) { - struct timespec temp; - if ((end.tv_nsec-start.tv_nsec)<0) { - temp.tv_sec = end.tv_sec-start.tv_sec-1; - temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; - } else { - temp.tv_sec = end.tv_sec-start.tv_sec; - temp.tv_nsec = end.tv_nsec-start.tv_nsec; - } - return temp; -} - -void print_difftimes(void) { -#ifdef DEBUG - printf("difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); -#else - LOG_I(HW,"difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); -#endif -} - -void update_difftimes(struct timespec start, struct timespec end) { - struct timespec diff_time = { .tv_sec = 0, .tv_nsec = 0 }; - int changed = 0; - diff_time = clock_difftime(start, end); - if ((min_diff_time.tv_nsec == 0) || (diff_time.tv_nsec < min_diff_time.tv_nsec)) { - min_diff_time.tv_nsec = diff_time.tv_nsec; - changed = 1; - } - if ((max_diff_time.tv_nsec == 0) || (diff_time.tv_nsec > max_diff_time.tv_nsec)) { - max_diff_time.tv_nsec = diff_time.tv_nsec; - changed = 1; - } -#if 1 - if (changed) print_difftimes(); -#endif -} - -/*------------------------------------------------------------------------*/ - -unsigned int build_rflocal(int txi, int txq, int rxi, int rxq) { - return (txi + (txq<<6) + (rxi<<12) + (rxq<<18)); -} -unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) { - return (dcoff_i_rxfe + (dcoff_q_rxfe<<8)); -} - -#if !defined(ENABLE_ITTI) -void signal_handler(int sig) { - void *array[10]; - size_t size; - - if (sig==SIGSEGV) { - // get void*'s for all entries on the stack - size = backtrace(array, 10); - - // print out all the frames to stderr - fprintf(stderr, "Error: signal %d:\n", sig); - backtrace_symbols_fd(array, size, 2); - exit(-1); - } else { - printf("trying to exit gracefully...\n"); - oai_exit = 1; - } -} -#endif -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KBLU "\x1B[34m" -#define RESET "\033[0m" - - -void exit_function(const char* file, const char* function, const int line, const char* s) -{ - - int CC_id; - - if (s != NULL) { - printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s); - } - - oai_exit = 1; - - if (PHY_vars_UE_g && PHY_vars_UE_g[0]) { - for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - if (PHY_vars_UE_g[0][CC_id] && PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func) - PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][CC_id]->rfdevice); - } - } - -#if defined(ENABLE_ITTI) - sleep(1); //allow lte-softmodem threads to exit first - itti_terminate_tasks (TASK_UNKNOWN); -#endif -} - -#ifdef XFORMS - - -void reset_stats(FL_OBJECT *button, long arg) { - //int i,j,k; - /*PHY_VARS_eNB *phy_vars_eNB = PHY_vars_eNB_g[0][0]; - - for (i=0; i<NUMBER_OF_UE_MAX; i++) { - for (k=0; k<8; k++) { //harq_processes - for (j=0; j<phy_vars_eNB->dlsch[i][0]->Mlimit; j++) { - phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0; - phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0; - phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0; - } - - phy_vars_eNB->UE_stats[i].dlsch_l2_errors[k]=0; - phy_vars_eNB->UE_stats[i].ulsch_errors[k]=0; - phy_vars_eNB->UE_stats[i].ulsch_consecutive_errors=0; - - for (j=0; j<phy_vars_eNB->ulsch[i]->Mlimit; j++) { - phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts_last[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_round_errors[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_round_fer[k][j]=0; - } - } - - phy_vars_eNB->UE_stats[i].dlsch_sliding_cnt=0; - phy_vars_eNB->UE_stats[i].dlsch_NAK_round0=0; - phy_vars_eNB->UE_stats[i].dlsch_mcs_offset=0; - }*/ -} - -static void *scope_thread(void *arg) { - char stats_buffer[16384]; -# ifdef ENABLE_XFORMS_WRITE_STATS - FILE *UE_stats, *eNB_stats; -# endif - //int len = 0; - struct sched_param sched_param; - //int UE_id, CC_id; - //int ue_cnt=0; - - sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1; - sched_setscheduler(0, SCHED_FIFO,&sched_param); - - printf("Scope thread has priority %d\n",sched_param.sched_priority); - -# ifdef ENABLE_XFORMS_WRITE_STATS - - UE_stats = fopen("UE_stats.txt", "w"); - -#endif - - while (!oai_exit) { - //len = dump_ue_stats (PHY_vars_UE_g[0][0], &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0],stats_buffer, 0, mode,rx_input_level_dBm); - //fl_set_object_label(form_stats->stats_text, stats_buffer); - //fl_clear_browser(form_stats->stats_text); - //fl_add_browser_line(form_stats->stats_text, stats_buffer); - - //if (PHY_vars_UE_g[0][0]->is_synchronized == 1) - phy_scope_UE(form_ue[0], - PHY_vars_UE_g[0][0], - 0,0,1); - //else it is done in the synch thread - - //printf("doing forms\n"); - //usleep(100000); // 100 ms - sleep(0.1); - } - - // printf("%s",stats_buffer); - -# ifdef ENABLE_XFORMS_WRITE_STATS - - if (UE_stats) { - rewind (UE_stats); - fwrite (stats_buffer, 1, len, UE_stats); - fclose (UE_stats); - } - -# endif - - pthread_exit((void*)arg); -} -#endif - - - - -#if defined(ENABLE_ITTI) -void *l2l1_task(void *arg) { - MessageDef *message_p = NULL; - int result; - - itti_set_task_real_time(TASK_L2L1); - itti_mark_task_ready(TASK_L2L1); - - - do { - // Wait for a message - itti_receive_msg (TASK_L2L1, &message_p); - - switch (ITTI_MSG_ID(message_p)) { - case TERMINATE_MESSAGE: - oai_exit=1; - itti_exit_task (); - break; - - case ACTIVATE_MESSAGE: - start_UE = 1; - break; - - case DEACTIVATE_MESSAGE: - start_UE = 0; - break; - - case MESSAGE_TEST: - LOG_I(EMU, "Received %s\n", ITTI_MSG_NAME(message_p)); - break; - - default: - LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p)); - break; - } - - result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - } while(!oai_exit); - - return NULL; -} -#endif - -int16_t dlsch_demod_shift; - -static void get_options(void) { - int CC_id; - int tddflag, nonbiotflag; - char *loopfile=NULL; - int dumpframe=0; - uint32_t online_log_messages; - uint32_t glog_level, glog_verbosity; - uint32_t start_telnetsrv; - - paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; - paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; - - config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); - - if (strlen(in_path) > 0) { - opt_type = OPT_PCAP; - opt_enabled=1; - printf("Enabling OPT for PCAP with the following file %s \n",in_path); - } - if (strlen(in_ip) > 0) { - opt_enabled=1; - opt_type = OPT_WIRESHARK; - printf("Enabling OPT for wireshark for local interface"); - } - - config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); - if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { - set_glog_onlinelog(online_log_messages); - } - if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { - set_glog(glog_level); - } - - if (start_telnetsrv) { - load_module_shlib("telnetsrv",NULL,0,NULL); - } - - paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC; - paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; - - - config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL); - config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL); - if (loopfile != NULL) { - printf("Input file for hardware emulation: %s\n",loopfile); - mode=loop_through_memory; - input_fd = fopen(loopfile,"r"); - AssertFatal(input_fd != NULL,"Please provide a valid input file\n"); - } - - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERX_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue; - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXMED_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_med; - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXBYP_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_byp; - if (cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) > 0) mode = debug_prach; - if (cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) > 0) mode = no_L2_connect; - if (cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) > 0) mode = calib_prach_tx; - if (dumpframe > 0) mode = rx_dump_frame; - - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - frame_parms[CC_id]->dl_CarrierFreq = downlink_frequency[0][0]; - } - UE_scan=0; - - - if (tddflag > 0) { - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) - frame_parms[CC_id]->frame_type = TDD; - } - - /*if (frame_parms[0]->N_RB_DL !=0) { - if ( frame_parms[0]->N_RB_DL < 6 ) { - frame_parms[0]->N_RB_DL = 6; - printf ( "%i: Invalid number of ressource blocks, adjusted to 6\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 100 ) { - frame_parms[0]->N_RB_DL = 100; - printf ( "%i: Invalid number of ressource blocks, adjusted to 100\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 50 && frame_parms[0]->N_RB_DL < 100 ) { - frame_parms[0]->N_RB_DL = 50; - printf ( "%i: Invalid number of ressource blocks, adjusted to 50\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 25 && frame_parms[0]->N_RB_DL < 50 ) { - frame_parms[0]->N_RB_DL = 25; - printf ( "%i: Invalid number of ressource blocks, adjusted to 25\n",frame_parms[0]->N_RB_DL); - } - UE_scan = 0; - frame_parms[0]->N_RB_UL=frame_parms[0]->N_RB_DL; - for (CC_id=1; CC_id<MAX_NUM_CCs; CC_id++) { - frame_parms[CC_id]->N_RB_DL=frame_parms[0]->N_RB_DL; - frame_parms[CC_id]->N_RB_UL=frame_parms[0]->N_RB_UL; - } - }*/ - - - for (CC_id=1;CC_id<MAX_NUM_CCs;CC_id++) { - tx_max_power[CC_id]=tx_max_power[0]; - rx_gain[0][CC_id] = rx_gain[0][0]; - tx_gain[0][CC_id] = tx_gain[0][0]; - } - -#if T_TRACER - paramdef_t cmdline_ttraceparams[] =CMDLINE_TTRACEPARAMS_DESC ; - config_process_cmdline( cmdline_ttraceparams,sizeof(cmdline_ttraceparams)/sizeof(paramdef_t),NULL); -#endif - - if ( !(CONFIG_ISFLAGSET(CONFIG_ABORT)) && (!(CONFIG_ISFLAGSET(CONFIG_NOOOPT))) ) { - // Here the configuration file is the XER encoded UE capabilities - // Read it in and store in asn1c data structures - sprintf(uecap_xer,"%stargets/PROJECTS/GENERIC-LTE-EPC/CONF/UE_config.xml",getenv("OPENAIR_HOME")); - printf("%s\n",uecap_xer); - uecap_xer_in=1; - } /* UE with config file */ - -} - -#if T_TRACER -int T_nowait = 0; /* by default we wait for the tracer */ -int T_port = 2021; /* default port to listen to to wait for the tracer */ -int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */ -#endif - -void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { - - int CC_id; - - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - frame_parms[CC_id] = (NR_DL_FRAME_PARMS*) malloc(sizeof(NR_DL_FRAME_PARMS)); - /* Set some default values that may be overwritten while reading options */ - frame_parms[CC_id] = (NR_DL_FRAME_PARMS*) malloc(sizeof(NR_DL_FRAME_PARMS)); - config[CC_id] = (nfapi_nr_config_request_t*) malloc(sizeof(nfapi_nr_config_request_t)); - config[CC_id]->subframe_config.numerology_index_mu.value =1; - config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD - config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL - config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; - config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; - config[CC_id]->sch_config.physical_cell_id.value = 0; - frame_parms[CC_id]->eutra_band = 78; - frame_parms[CC_id]->frame_type = FDD; - frame_parms[CC_id]->tdd_config = 3; - //frame_parms[CC_id]->tdd_config_S = 0; - frame_parms[CC_id]->N_RB_DL = 106; - frame_parms[CC_id]->N_RB_UL = 106; - frame_parms[CC_id]->Ncp = NORMAL; - //frame_parms[CC_id]->Ncp_UL = NORMAL; - frame_parms[CC_id]->Nid_cell = 0; - //frame_parms[CC_id]->num_MBSFN_config = 0; - frame_parms[CC_id]->nb_antenna_ports_eNB = 1; - frame_parms[CC_id]->nb_antennas_tx = 1; - frame_parms[CC_id]->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[CC_id]->numerology_index = 0; - frame_parms[CC_id]->ttis_per_subframe = 1; - frame_parms[CC_id]->slots_per_tti = 2; - - } - -} - -void init_openair0(void); -void init_openair0() { - - int card; - int i; - - for (card=0; card<MAX_CARDS; card++) { - - openair0_cfg[card].mmapped_dma=mmapped_dma; - openair0_cfg[card].configFilename = NULL; - - if(frame_parms[0]->N_RB_DL == 106) { - if (numerology==0) { - if (frame_parms[0]->threequarter_fs) { - openair0_cfg[card].sample_rate=23.04e6; - openair0_cfg[card].samples_per_frame = 230400; - openair0_cfg[card].tx_bw = 10e6; - openair0_cfg[card].rx_bw = 10e6; - } else { - openair0_cfg[card].sample_rate=30.72e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 10e6; - openair0_cfg[card].rx_bw = 10e6; - } - } else if (numerology==1) { - openair0_cfg[card].sample_rate=61.44e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 20e6; - openair0_cfg[card].rx_bw = 20e6; - } else if (numerology==2) { - openair0_cfg[card].sample_rate=122.88e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 40e6; - openair0_cfg[card].rx_bw = 40e6; - } else { - LOG_E(PHY,"Unsupported numerology!\n"); - exit(-1); - } - } else if(frame_parms[0]->N_RB_DL == 50) { - openair0_cfg[card].sample_rate=15.36e6; - openair0_cfg[card].samples_per_frame = 153600; - openair0_cfg[card].tx_bw = 5e6; - openair0_cfg[card].rx_bw = 5e6; - } else if (frame_parms[0]->N_RB_DL == 25) { - openair0_cfg[card].sample_rate=7.68e6; - openair0_cfg[card].samples_per_frame = 76800; - openair0_cfg[card].tx_bw = 2.5e6; - openair0_cfg[card].rx_bw = 2.5e6; - } else if (frame_parms[0]->N_RB_DL == 6) { - openair0_cfg[card].sample_rate=1.92e6; - openair0_cfg[card].samples_per_frame = 19200; - openair0_cfg[card].tx_bw = 1.5e6; - openair0_cfg[card].rx_bw = 1.5e6; - } - - if (frame_parms[0]->frame_type==TDD) - openair0_cfg[card].duplex_mode = duplex_mode_TDD; - else //FDD - openair0_cfg[card].duplex_mode = duplex_mode_FDD; - - printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card, - PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx, - PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); - openair0_cfg[card].Mod_id = 0; - - openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL; - - openair0_cfg[card].clock_source = clock_source; - - - openair0_cfg[card].tx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx); - openair0_cfg[card].rx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); - - for (i=0; i<4; i++) { - - if (i<openair0_cfg[card].tx_num_channels) - openair0_cfg[card].tx_freq[i] = downlink_frequency[0][i]+uplink_frequency_offset[0][i]; - else - openair0_cfg[card].tx_freq[i]=0.0; - - if (i<openair0_cfg[card].rx_num_channels) - openair0_cfg[card].rx_freq[i] = downlink_frequency[0][i]; - else - openair0_cfg[card].rx_freq[i]=0.0; - - openair0_cfg[card].autocal[i] = 1; - openair0_cfg[card].tx_gain[i] = tx_gain[0][i]; - openair0_cfg[card].rx_gain[i] = PHY_vars_UE_g[0][0]->rx_total_gain_dB - rx_gain_off; - - - openair0_cfg[card].configFilename = rf_config_file; - printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n", - card,i, openair0_cfg[card].tx_gain[i], - openair0_cfg[card].rx_gain[i], - openair0_cfg[card].tx_freq[i], - openair0_cfg[card].rx_freq[i]); - } - - if (usrp_args) openair0_cfg[card].sdr_addrs = usrp_args; - if (usrp_clksrc) { - if (strcmp(usrp_clksrc, "internal") == 0) { - openair0_cfg[card].clock_source = internal; - LOG_D(PHY, "USRP clock source set as internal\n"); - } else if (strcmp(usrp_clksrc, "external") == 0) { - openair0_cfg[card].clock_source = external; - LOG_D(PHY, "USRP clock source set as external\n"); - } else if (strcmp(usrp_clksrc, "gpsdo") == 0) { - openair0_cfg[card].clock_source = gpsdo; - LOG_D(PHY, "USRP clock source set as gpsdo\n"); - } else { - openair0_cfg[card].clock_source = internal; - LOG_I(PHY, "USRP clock source unknown ('%s'). defaulting to internal\n", usrp_clksrc); - } - } else { - openair0_cfg[card].clock_source = internal; - LOG_I(PHY, "USRP clock source not specified. defaulting to internal\n"); - } - - } -} - -int main( int argc, char **argv ) { - int i;//j,k,aa,re; -#if defined (XFORMS) - void *status; -#endif - - int CC_id; - uint8_t abstraction_flag=0; - //uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2; - -#if defined (XFORMS) - int ret; -#endif - - PHY_VARS_NR_UE *UE[MAX_NUM_CCs]; - - start_background_system(); - if ( load_configmodule(argc,argv) == NULL) { - exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); - } - CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); - -#ifdef DEBUG_CONSOLE - setvbuf(stdout, NULL, _IONBF, 0); - setvbuf(stderr, NULL, _IONBF, 0); -#endif - - set_default_frame_parms(frame_parms); - - mode = normal_txrx; - memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS); - - memset(tx_max_power,0,sizeof(int)*MAX_NUM_CCs); - - set_latency_target(); - - // initialize logging - logInit(); - - - // get options and fill parameters from configuration file - get_options (); //Command-line options, enb_properties - -#if T_TRACER - T_Config_Init(); -#endif - - //randominit (0); - set_taus_seed (0); - - printf("configuring for UE\n"); - - //if (ouput_vcd) - // VCD_SIGNAL_DUMPER_INIT("/tmp/openair_dump_UE.vcd"); - - //if (opp_enabled ==1) { - // reset_opp_meas(); - //} - cpuf=get_cpu_freq_GHz(); - -#if defined(ENABLE_ITTI) - //log_set_instance_type (LOG_INSTANCE_UE); - - itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); - - // initialize mscgen log after ITTI - MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); -#endif - - if (opt_type != OPT_NONE) { - if (init_opt(in_path, in_ip) == -1) - LOG_E(OPT,"failed to run OPT \n"); - } - -#ifdef PDCP_USE_NETLINK - netlink_init(); -#if defined(PDCP_USE_NETLINK_QUEUES) - pdcp_netlink_init(); -#endif -#endif - -#if !defined(ENABLE_ITTI) - // to make a graceful exit when ctrl-c is pressed - signal(SIGSEGV, signal_handler); - signal(SIGINT, signal_handler); -#endif - - - check_clock(); - -#ifndef PACKAGE_VERSION -# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL" -#endif - - LOG_I(HW, "Version: %s\n", PACKAGE_VERSION); - - // init the parameters - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - - frame_parms[CC_id]->nb_antennas_tx = nb_antenna_tx; - frame_parms[CC_id]->nb_antennas_rx = nb_antenna_rx; - frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later - - LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); - - get_band(downlink_frequency[CC_id][0], &frame_parms[CC_id]->eutra_band, &uplink_frequency_offset[CC_id][0], &frame_parms[CC_id]->frame_type); - - //init_ul_hopping(frame_parms[CC_id]); - //phy_init_nr_top(frame_parms[CC_id]); - - //init prach for openair1 test - // prach_fmt = get_prach_fmt(frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->frame_type); - // N_ZC = (prach_fmt <4)?839:139; - } - - NB_UE_INST=1; - NB_INST=1; - PHY_vars_UE_g = malloc(sizeof(PHY_VARS_NR_UE**)); - PHY_vars_UE_g[0] = malloc(sizeof(PHY_VARS_NR_UE*)*MAX_NUM_CCs); - - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - printf("PHY_vars_UE_g[0][%d] = %p\n",CC_id,UE[CC_id]); - - printf("frame_parms %d\n",frame_parms[CC_id]->ofdm_symbol_size); - - nr_init_frame_parms_ue(frame_parms[CC_id],numerology,NORMAL,frame_parms[CC_id]->N_RB_DL,(frame_parms[CC_id]->N_RB_DL-20)>>1,0); - PHY_vars_UE_g[0][CC_id] = init_nr_ue_vars(frame_parms[CC_id], 0,abstraction_flag); - UE[CC_id] = PHY_vars_UE_g[0][CC_id]; - - if (phy_test==1) - UE[CC_id]->mac_enabled = 0; - else - UE[CC_id]->mac_enabled = 1; - - if (UE[CC_id]->mac_enabled == 0) { //set default UL parameters for testing mode - for (i=0; i<NUMBER_OF_CONNECTED_eNB_MAX; i++) { - //UE[CC_id]->pusch_config_dedicated[i] = malloc(sizeof(PUSCH_CONFIG_DEDICATED)); - - //UE[CC_id]->scheduling_request_config[i] = malloc(sizeof(SCHEDULING_REQUEST_CONFIG)); - - /*UE[CC_id]->pusch_config_dedicated[i].betaOffset_ACK_Index = beta_ACK; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_RI_Index = beta_RI; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_CQI_Index = beta_CQI; - - UE[CC_id]->scheduling_request_config[i].sr_PUCCH_ResourceIndex = 0; - UE[CC_id]->scheduling_request_config[i].sr_ConfigIndex = 7+(0%3); - UE[CC_id]->scheduling_request_config[i].dsr_TransMax = sr_n4;*/ - } - } - - UE[CC_id]->UE_scan = UE_scan; - UE[CC_id]->UE_scan_carrier = UE_scan_carrier; - UE[CC_id]->UE_fo_compensation = UE_fo_compensation; - UE[CC_id]->mode = mode; - printf("UE[%d]->mode = %d\n",CC_id,mode); - - for (uint8_t i=0; i<RX_NB_TH_MAX; i++) { - //UE[CC_id]->pdcch_vars[i][0]->agregationLevel = agregation_Level; - //UE[CC_id]->pdcch_vars[i][0]->dciFormat = dci_Format; - - /*compute_prach_seq(&UE[CC_id]->frame_parms.prach_config_common, - UE[CC_id]->frame_parms.frame_type, - UE[CC_id]->X_u);*/ - - if (UE[CC_id]->mac_enabled == 1) - UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1234; - else - UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1235; - } - - UE[CC_id]->rx_total_gain_dB = (int)rx_gain[CC_id][0] + rx_gain_off; - UE[CC_id]->tx_power_max_dBm = tx_max_power[CC_id]; - - if (frame_parms[CC_id]->frame_type==FDD) { - UE[CC_id]->N_TA_offset = 0; - } else { - if (frame_parms[CC_id]->N_RB_DL == 100) - UE[CC_id]->N_TA_offset = 624; - else if (frame_parms[CC_id]->N_RB_DL == 50) - UE[CC_id]->N_TA_offset = 624/2; - else if (frame_parms[CC_id]->N_RB_DL == 25) - UE[CC_id]->N_TA_offset = 624/4; - } - - } - - // printf("tx_max_power = %d -> amp %d\n",tx_max_power[0],get_tx_amp(tx_max_poHwer,tx_max_power)); - - - fill_modeled_runtime_table(runtime_phy_rx,runtime_phy_tx); - cpuf=get_cpu_freq_GHz(); - - - //dump_frame_parms(frame_parms[0]); - - init_openair0(); - - // default threads.main = 2 - // if there are enough processors, all others on subsequent CPUs - if (threads_offset>0) { - if (threads_offset+8<=get_nprocs()) { - if (threads.main<0) threads.main=threads_offset+1; - if (threads.sync<0) threads.sync=threads_offset+2; - if (threads.one<0) threads.one=threads_offset+3; - if (threads.two<0) threads.two=threads_offset+4; - if (threads.three<0) threads.three=threads_offset+5; - if (threads.slot1_proc_one<0) threads.slot1_proc_one=threads_offset+6; - if (threads.slot1_proc_two<0) threads.slot1_proc_two=threads_offset+7; - if (threads.slot1_proc_three<0) threads.slot1_proc_three=threads_offset+8; - } - else { - LOG_E(HW,"Not enough CPUs available (nprocs (=%d) >= threadmain (=%d) + 10)\n",get_nprocs(),threads_offset); - exit_fun("Error setting thread affinity\n"); - } - } - -#ifndef DEADLINE_SCHEDULER - - /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */ - - cpu_set_t cpuset; - int s; - char cpu_affinity[1024]; - CPU_ZERO(&cpuset); -#ifdef CPU_AFFINITY - int j; - if (get_nprocs()>=2) { - for (j = 2; j < get_nprocs(); j++) - CPU_SET(j, &cpuset); - - s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - if (s != 0) { - perror( "pthread_setaffinity_np"); - exit_fun("Error setting processor affinity"); - } - LOG_I(HW, "Setting the affinity of main function to all CPUs, for device library to use CPU 0 only!\n"); - } -#endif - - /* Check the actual affinity mask assigned to the thread */ - s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - if (s != 0) { - perror( "pthread_getaffinity_np"); - exit_fun("Error getting processor affinity "); - } - memset(cpu_affinity, 0 , sizeof(cpu_affinity)); - for (int j = 0; j < CPU_SETSIZE; j++) { - if (CPU_ISSET(j, &cpuset)) { - char temp[1024]; - sprintf(temp, " CPU_%d ", j); - strcat(cpu_affinity, temp); - } - } - LOG_I(HW, "CPU Affinity of main() function is... %s\n", cpu_affinity); -#endif - - - //openair0_cfg[0].log_level = glog_level; - - /*int eMBMS_active=0; - if (node_function[0] <= NGFI_RAU_IF4p5) { // don't initialize L2 for RRU - LOG_I(PHY,"Intializing L2\n"); - mac_xface = malloc(sizeof(MAC_xface)); - l2_init(frame_parms[0],eMBMS_active,(uecap_xer_in==1)?uecap_xer:NULL, - 0,// cba_group_active - 0); // HO flag - mac_xface->macphy_exit = &exit_fun; - } else if (node_function[0] == NGFI_RRU_IF4p5) { // Initialize PRACH in this case - - }*/ - - - -#if defined(ENABLE_ITTI) - - // don't create if node doesn't connect to RRC/S1/GTP - /*if (create_tasks(1) < 0) { - printf("cannot create ITTI tasks\n"); - exit(-1); // need a softer mode - }*/ - - printf("ITTI tasks created\n"); -#endif - - /*if (phy_test==0) { - if (UE_flag==1) { - printf("Filling UE band info\n"); - fill_ue_band_info(); - mac_xface->dl_phy_sync_success (0, 0, 0, 1); - } else if (node_function[0]>NGFI_RRU_IF4p5) - mac_xface->mrbch_phy_sync_failure (0, 0, 0); - }*/ - - // init UE_PF_PO and mutex lock - pthread_mutex_init(&ue_pf_po_mutex, NULL); - memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); - - - mlockall(MCL_CURRENT | MCL_FUTURE); - - pthread_cond_init(&sync_cond,NULL); - pthread_mutex_init(&sync_mutex, NULL); - - init_UE(1); - -#ifdef XFORMS - int UE_id; - int fl_argc=1; - - if (do_forms==1) { - // fl_initialize messes with argv and argc, so pretend to not pass any options - fl_initialize (&fl_argc, argv, NULL, 0, 0); - // restore the original command line args - // argv = fl_get_cmdline_args( &argc ); - //form_stats = create_form_stats_form(); - //fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); - UE_id = 0; - form_ue[UE_id] = create_lte_phy_scope_ue(); - sprintf (title, "NR DL SCOPE UE"); - fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); - - /* - if (openair_daq_vars.use_ia_receiver) { - fl_set_button(form_ue[UE_id]->button_0,1); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON"); - } else { - fl_set_button(form_ue[UE_id]->button_0,0); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); - }*/ - fl_set_button(form_ue[UE_id]->button_0,0); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); - - - ret = pthread_create(&forms_thread, NULL, scope_thread, NULL); - - if (ret == 0) - pthread_setname_np( forms_thread, "xforms" ); - - printf("Scope thread created, ret=%d\n",ret); - } - -#endif - - rt_sleep_ns(10*100000000ULL); - - number_of_cards = 1; - - for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - PHY_vars_UE_g[0][CC_id]->rf_map.card=0; - PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset; - } - - - for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { - -#if defined(OAI_USRP) || defined(OAI_ADRV9371_ZC706) - UE[CC_id]->hw_timing_advance = timing_advance; -#else - UE[CC_id]->hw_timing_advance = 160; -#endif - } - - - if (input_fd) { - printf("Reading in from file to antenna buffer %d\n",0); - if (fread(UE[0]->common_vars.rxdata[0], - sizeof(int32_t), - frame_parms[0]->samples_per_subframe*10, - input_fd) != frame_parms[0]->samples_per_subframe*10) - printf("error reading from file\n"); - } - - sleep(3); - - - printf("Sending sync to all threads\n"); - - pthread_mutex_lock(&sync_mutex); - sync_var=0; - pthread_cond_broadcast(&sync_cond); - pthread_mutex_unlock(&sync_mutex); - - // wait for end of program - printf("TYPE <CTRL-C> TO TERMINATE\n"); - //getchar(); - - /* -#if defined(ENABLE_ITTI) - printf("Entering ITTI signals handler\n"); - itti_wait_tasks_end(); - oai_exit=1; -#else - */ - - while (oai_exit==0) - rt_sleep_ns(100000000ULL); - - //#endif - - // stop threads -#ifdef XFORMS - printf("waiting for XFORMS thread\n"); - - if (do_forms==1) { - pthread_join(forms_thread,&status); - //fl_hide_form(form_stats->stats_form); - //fl_free_form(form_stats->stats_form); - fl_hide_form(form_ue[0]->lte_phy_scope_ue); - fl_free_form(form_ue[0]->lte_phy_scope_ue); - } - -#endif - - printf("stopping MODEM threads\n"); - - pthread_cond_destroy(&sync_cond); - pthread_mutex_destroy(&sync_mutex); - - - // *** Handle per CC_id openair0 - if (PHY_vars_UE_g[0][0]->rfdevice.trx_end_func) - PHY_vars_UE_g[0][0]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][0]->rfdevice); - - //if (ouput_vcd) - //VCD_SIGNAL_DUMPER_CLOSE(); - - if (opt_enabled == 1) - terminate_opt(); - - logClean(); - - return 0; -} diff --git a/targets/RT/USER/nr-uesoftmodem.h b/targets/RT/USER/nr-uesoftmodem.h deleted file mode 100644 index 7f96480b2bfe5be8969b5e67c1aa8c8e25af2baa..0000000000000000000000000000000000000000 --- a/targets/RT/USER/nr-uesoftmodem.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef NR_UESOFTMODEM_H -#define NR_UESOFTMODEM_H - -#define _GNU_SOURCE -#include <execinfo.h> -#include <fcntl.h> -#include <getopt.h> -#include <linux/sched.h> -#include "rt_wrapper.h" -#include <sched.h> -#include <signal.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syscall.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <sys/sysinfo.h> -#include <sys/types.h> -#include <unistd.h> - -#include <sys/sysinfo.h> -#include "rt_wrapper.h" -#include "../../ARCH/COMMON/common_lib.h" -#undef MALLOC -#include "assertions.h" -#include "msc.h" -#include "PHY/types.h" -#include "PHY/defs_nr_UE.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" - -#if defined(ENABLE_ITTI) -#if defined(ENABLE_USE_MME) -#include "s1ap_eNB.h" -#ifdef PDCP_USE_NETLINK -#include "SIMULATION/ETH_TRANSPORT/proto.h" -#endif -#endif -#endif - -/* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ -#define CONFIG_HLP_RFCFGF "Configuration file for front-end (e.g. LMS7002M)\n" -#define CONFIG_HLP_ULMAXE "set the eNodeB max ULSCH erros\n" -#define CONFIG_HLP_CALUER "set UE RX calibration\n" -#define CONFIG_HLP_CALUERM "" -#define CONFIG_HLP_CALUERB "" -#define CONFIG_HLP_DBGUEPR "UE run normal prach power ramping, but don't continue random-access\n" -#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_UERXG "set UE RX gain\n" -#define CONFIG_HLP_UERXGOFF "external UE amplifier offset\n" -#define CONFIG_HLP_UETXG "set UE TX gain\n" -#define CONFIG_HLP_UENANTR "set UE number of rx antennas\n" -#define CONFIG_HLP_UENANTT "set UE number of tx antennas\n" -#define CONFIG_HLP_UESCAN "set UE to scan around carrier\n" -#define CONFIG_HLP_UEFO "set UE to enable estimation and compensation of frequency offset\n" -#define CONFIG_HLP_DUMPFRAME "dump UE received frame to rxsig_frame0.dat and exit\n" -#define CONFIG_HLP_DLSHIFT "dynamic shift for LLR compuation for TM3/4 (default 0)\n" -#define CONFIG_HLP_UELOOP "get softmodem (UE) to loop through memory instead of acquiring from HW\n" -#define CONFIG_HLP_PHYTST "test UE phy layer, mac disabled\n" -#define CONFIG_HLP_DMAMAP "sets flag for improved EXMIMO UE performance\n" -#define CONFIG_HLP_EXCCLK "tells hardware to use an external clock reference\n" -#define CONFIG_HLP_USIM "use XOR autentication algo in case of test usim mode\n" -#define CONFIG_HLP_NOSNGLT "Disables single-thread mode in lte-softmodem\n" -#define CONFIG_HLP_TADV "Set timing_advance\n" -#define CONFIG_HLP_DLF "Set the downlink frequency for all component carriers\n" -#define CONFIG_HLP_CHOFF "Channel id offset\n" -#define CONFIG_HLP_SOFTS "Enable soft scope and L1 and L2 stats (Xforms)\n" -#define CONFIG_HLP_EXMCAL "Calibrate the EXMIMO borad, available files: exmimo2_2arxg.lime exmimo2_2brxg.lime \n" -#define CONFIG_HLP_ITTIL "Generate ITTI analyzser logs (similar to wireshark logs but with more details)\n" -#define CONFIG_HLP_DLMCS "Set the maximum downlink MCS\n" -#define CONFIG_HLP_STMON "Enable processing timing measurement of lte softmodem on per subframe basis \n" -#define CONFIG_HLP_PRB "Set the PRB, valid values: 6, 25, 50, 100 \n" -#define CONFIG_HLP_MSLOTS "Skip the missed slots/subframes \n" -#define CONFIG_HLP_ULMCS "Set the maximum uplink MCS\n" -#define CONFIG_HLP_TDD "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n" -#define CONFIG_HLP_UE "Set the lte softmodem as a UE\n" -#define CONFIG_HLP_L2MONW "Enable L2 wireshark messages on localhost \n" -#define CONFIG_HLP_L2MONP "Enable L2 pcap messages on localhost \n" -#define CONFIG_HLP_VCD "Enable VCD (generated file will is named openair_dump_eNB.vcd, read it with target/RT/USER/eNB.gtkw\n" -#define CONFIG_HLP_TQFS "Apply three-quarter of sampling frequency, 23.04 Msps to reduce the data rate on USB/PCIe transfers (only valid for 20 MHz)\n" -#define CONFIG_HLP_TPORT "tracer port\n" -#define CONFIG_HLP_NOTWAIT "don't wait for tracer, start immediately\n" -#define CONFIG_HLP_TNOFORK "to ease debugging with gdb\n" - -#define CONFIG_HLP_NUMEROLOGY "adding numerology for 5G\n" -#define CONFIG_HLP_EMULATE_RF "Emulated RF enabled(disable by defult)\n" -#define CONFIG_HLP_PARALLEL_CMD "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n" -#define CONFIG_HLP_WORKER_CMD "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n" - -#define CONFIG_HLP_DISABLNBIOT "disable nb-iot, even if defined in config\n" - -#define CONFIG_HLP_USRP_ARGS "set the arguments to identify USRP (same syntax as in UHD)\n" -#define CONFIG_HLP_USRP_CLK_SRC "USRP clock source: 'internal' or 'external'\n" - -/***************************************************************************************************************************************/ -/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument - when calling config_get or config_getlist functions */ - - -/*------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters defining UE running mode */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_UEMODEPARAMS_DESC { \ -{"calib-ue-rx", CONFIG_HLP_CALUER, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"calib-ue-rx-med", CONFIG_HLP_CALUERM, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"calib-ue-rx-byp", CONFIG_HLP_CALUERB, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"debug-ue-prach", CONFIG_HLP_DBGUEPR, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"no-L2-connect", CONFIG_HLP_NOL2CN, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"calib-prach-tx", CONFIG_HLP_CALPRACH, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"loop-memory", CONFIG_HLP_UELOOP, 0, strptr:&loopfile, defstrval:"iqs.in", TYPE_STRING,0}, \ -{"ue-dump-frame", CONFIG_HLP_DUMPFRAME, PARAMFLAG_BOOL, iptr:&dumpframe, defintval:0, TYPE_INT, 0}, \ -} -#define CMDLINE_CALIBUERX_IDX 0 -#define CMDLINE_CALIBUERXMED_IDX 1 -#define CMDLINE_CALIBUERXBYP_IDX 2 -#define CMDLINE_DEBUGUEPRACH_IDX 3 -#define CMDLINE_NOL2CONNECT_IDX 4 -#define CMDLINE_CALIBPRACHTX_IDX 5 -#define CMDLINE_MEMLOOP_IDX 6 -#define CMDLINE_DUMPMEMORY_IDX 7 -/*------------------------------------------------------------------------------------------------------------------------------------------*/ - - -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters specific to UE */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_UEPARAMS_DESC { \ -{"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:0, 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}, \ -{"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ -{"ue-fo-compensation", CONFIG_HLP_UEFO, PARAMFLAG_BOOL, iptr:&UE_fo_compensation, defintval:0, TYPE_INT, 0}, \ -{"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:90, TYPE_INT, 0}, \ -{"r" , CONFIG_HLP_PRB, 0, iptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT, 0}, \ -{"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"usrp-args", CONFIG_HLP_USRP_ARGS, 0, strptr:(char **)&usrp_args, defstrval:"type=b200", TYPE_STRING, 0}, \ -{"usrp-clksrc", CONFIG_HLP_USRP_CLK_SRC,0, strptr:(char **)&usrp_clksrc, defstrval:"internal", TYPE_STRING, 0} \ -} - -#define DEFAULT_DLF 2680000000 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters common to eNodeB and UE */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_PARAMS_DESC { \ -{"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&rf_config_file, defstrval:NULL, TYPE_STRING, sizeof(rf_config_file)}, \ -{"ulsch-max-errors", CONFIG_HLP_ULMAXE, 0, uptr:&ULSCH_max_consecutive_errors, defuintval:0, TYPE_UINT, 0}, \ -{"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&phy_test, defintval:0, TYPE_INT, 0}, \ -{"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&usim_test, defintval:0, TYPE_UINT8, 0}, \ -{"mmapped-dma", CONFIG_HLP_DMAMAP, PARAMFLAG_BOOL, uptr:&mmapped_dma, defintval:0, TYPE_INT, 0}, \ -{"external-clock", CONFIG_HLP_EXCCLK, PARAMFLAG_BOOL, uptr:&clock_source, defintval:0, TYPE_INT, 0}, \ -{"wait-for-sync", NULL, PARAMFLAG_BOOL, iptr:&wait_for_sync, defintval:0, TYPE_INT, 0}, \ -{"single-thread-disable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&single_thread_flag, defintval:1, TYPE_INT, 0}, \ -{"threadoffset", NULL, 0, iptr:&(threads_offset), defintval:0, TYPE_INT, 0}, \ -{"threadMain", NULL, 0, iptr:&(threads.main), defintval:-1, TYPE_INT, 0}, \ -{"threadSync", NULL, 0, iptr:&(threads.sync), defintval:-1, TYPE_INT, 0}, \ -{"threadOneSubframe", NULL, 0, iptr:&(threads.one), defintval:-1, TYPE_INT, 0}, \ -{"threadTwoSubframe", NULL, 0, iptr:&(threads.two), defintval:-1, TYPE_INT, 0}, \ -{"threadThreeSubframe", NULL, 0, iptr:&(threads.three), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcOne", NULL, 0, iptr:&(threads.slot1_proc_one), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcTwo", NULL, 0, iptr:&(threads.slot1_proc_two), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcThree", NULL, 0, iptr:&(threads.slot1_proc_three), defintval:-1, TYPE_INT, 0}, \ -{"nr-dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&nr_dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"A" , CONFIG_HLP_TADV, 0, uptr:&timing_advance, defintval:0, TYPE_UINT, 0}, \ -{"C" , CONFIG_HLP_DLF, 0, uptr:&(downlink_frequency[0][0]), defuintval:2680000000, TYPE_UINT, 0}, \ -{"a" , CONFIG_HLP_CHOFF, 0, iptr:&chain_offset, defintval:0, TYPE_INT, 0}, \ -{"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, iptr:&do_forms, defintval:0, TYPE_INT, 0}, \ -{"E" , CONFIG_HLP_TQFS, PARAMFLAG_BOOL, iptr:&threequarter_fs, defintval:0, TYPE_INT, 0}, \ -{"K" , CONFIG_HLP_ITTIL, PARAMFLAG_NOFREE, strptr:&itti_dump_file, defstrval:"/tmp/itti.dump", TYPE_STRING, 0}, \ -{"m" , CONFIG_HLP_DLMCS, 0, uptr:&target_dl_mcs, defintval:0, TYPE_UINT, 0}, \ -{"t" , CONFIG_HLP_ULMCS, 0, uptr:&target_ul_mcs, defintval:0, TYPE_UINT, 0}, \ -{"W" , CONFIG_HLP_L2MONW, 0, strptr:(char **)&in_ip, defstrval:"127.0.0.1", TYPE_STRING, sizeof(in_ip)}, \ -{"P" , CONFIG_HLP_L2MONP, 0, strptr:(char **)&in_path, defstrval:"/tmp/oai_opt.pcap", TYPE_STRING, sizeof(in_path)}, \ -{"q" , CONFIG_HLP_STMON, PARAMFLAG_BOOL, iptr:&opp_enabled, defintval:0, TYPE_INT, 0}, \ -{"S" , CONFIG_HLP_MSLOTS, PARAMFLAG_BOOL, u8ptr:&exit_missed_slots, defintval:1, TYPE_UINT8, 0}, \ -{"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, \ -{"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&numerology, defintval:0, TYPE_INT, 0}, \ -{"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&emulate_rf, defintval:0, TYPE_INT, 0}, \ -{"parallel-config", CONFIG_HLP_PARALLEL_CMD,0, strptr:(char **)¶llel_config, defstrval:NULL, TYPE_STRING, 0}, \ -{"worker-config", CONFIG_HLP_WORKER_CMD, 0, strptr:(char **)&worker_config, defstrval:NULL, TYPE_STRING, 0}, \ -{"nbiot-disable", CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL, iptr:&nonbiotflag, defintval:0, TYPE_INT, 0} \ -} - -#define CONFIG_HLP_FLOG "Enable online log \n" -#define CONFIG_HLP_LOGL "Set the global log level, valide options: (9:trace, 8/7:debug, 6:info, 4:warn, 3:error)\n" -#define CONFIG_HLP_LOGV "Set the global log verbosity \n" -#define CONFIG_HLP_TELN "Start embedded telnet server \n" -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters for LOG utility */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_LOGPARAMS_DESC { \ -{"R" , CONFIG_HLP_FLOG, 0, uptr:&online_log_messages, defintval:1, TYPE_INT, 0}, \ -{"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ -{"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \ -{"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ -} -#define CMDLINE_ONLINELOG_IDX 0 -#define CMDLINE_GLOGLEVEL_IDX 1 -#define CMDLINE_GLOGVERBO_IDX 2 -#define CMDLINE_STARTTELN_IDX 3 - - -extern int T_port; -extern int T_nowait; -extern int T_dont_fork; - - - -/***************************************************************************************************************************************/ - -extern pthread_cond_t sync_cond; -extern pthread_mutex_t sync_mutex; -extern int sync_var; - - -extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; -extern int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; - -extern int rx_input_level_dBm; -extern uint8_t exit_missed_slots; -extern uint64_t num_missed_slots; // counter for the number of missed slots - -extern int oaisim_flag; -extern volatile int oai_exit; - -extern openair0_config_t openair0_cfg[MAX_CARDS]; -extern pthread_cond_t sync_cond; -extern pthread_mutex_t sync_mutex; -extern int sync_var; -extern int transmission_mode; -extern double cpuf; - -#if defined(ENABLE_ITTI) -extern volatile int start_eNB; -extern volatile int start_UE; -#endif - -#include "threads_t.h" -extern threads_t threads; - -// In nr-ue.c -extern int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg); -extern void fill_ue_band_info(void); -extern void init_UE(int); -extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char * name); -extern void reset_opp_meas(void); -extern void print_opp_meas(void); - -#endif