From 5679e4a3b32beeadd220169aea3c3c1d59e4bee8 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 22 Mar 2022 11:10:07 +0100 Subject: [PATCH 1/4] making SFN dependent on GPS time (when available) --- executables/nr-ru.c | 9 ++++++++- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 0240de87bc..394118d5a9 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -604,6 +604,7 @@ void *emulatedRF_thread(void *param) { void rx_rf(RU_t *ru,int *frame,int *slot) { RU_proc_t *proc = &ru->proc; NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + openair0_config_t *cfg = &ru->openair0_cfg; void *rxp[ru->nb_rx]; unsigned int rxs; int i; @@ -653,7 +654,13 @@ void rx_rf(RU_t *ru,int *frame,int *slot) { } } - proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_subframe*10))&1023; + //compute system frame number (SFN) according to O-RAN-WG4-CUS.0-v02.00 (using alpha=beta=0) + // this assumes that the USRP has been synchronized to the GPS time + // OAI uses timestamps in sample time stored in int64_t, but it will fit in double precision for many years to come. + double gps_sec = ((double) ts)/cfg->sample_rate; + proc->frame_rx = ((int64_t) (gps_sec/0.01)) & 1023; + + //proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_subframe*10))&1023; proc->tti_rx = fp->get_slot_from_timestamp(proc->timestamp_rx,fp); // synchronize first reception to frame 0 subframe 0 LOG_D(PHY,"RU %d/%d TS %llu , frame %d, slot %d.%d / %d\n", diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index fdc1f4289e..2c880ed919 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -203,8 +203,8 @@ static int sync_to_gps(openair0_device *device) { //Set to GPS time uhd::time_spec_t gps_time = uhd::time_spec_t(time_t(s->usrp->get_mboard_sensor("gps_time", mboard).to_int())); - //s->usrp->set_time_next_pps(gps_time+1.0, mboard); - s->usrp->set_time_next_pps(uhd::time_spec_t(0.0)); + s->usrp->set_time_next_pps(gps_time+1.0, mboard); + //s->usrp->set_time_next_pps(uhd::time_spec_t(0.0)); //Wait for it to apply //The wait is 2 seconds because N-Series has a known issue where //the time at the last PPS does not properly update at the PPS edge @@ -215,10 +215,10 @@ static int sync_to_gps(openair0_device *device) { uhd::time_spec_t time_last_pps = s->usrp->get_time_last_pps(mboard); std::cout << "USRP time: " << (boost::format("%0.9f") % time_last_pps.get_real_secs()) << std::endl; std::cout << "GPSDO time: " << (boost::format("%0.9f") % gps_time.get_real_secs()) << std::endl; - //if (gps_time.get_real_secs() == time_last_pps.get_real_secs()) - // std::cout << std::endl << "SUCCESS: USRP time synchronized to GPS time" << std::endl << std::endl; - //else - // std::cerr << std::endl << "ERROR: Failed to synchronize USRP time to GPS time" << std::endl << std::endl; + if (gps_time.get_real_secs() == time_last_pps.get_real_secs()) + std::cout << std::endl << "SUCCESS: USRP time synchronized to GPS time" << std::endl << std::endl; + else + std::cerr << std::endl << "ERROR: Failed to synchronize USRP time to GPS time" << std::endl << std::endl; } if (num_gps_locked == num_mboards and num_mboards > 1) { From 984830505bcfb676c3ddcb4daac8c4dddde651aa Mon Sep 17 00:00:00 2001 From: Sagar Parsawar Date: Mon, 28 Mar 2022 10:58:32 +0200 Subject: [PATCH 2/4] 256-bit alignment fix in trx_usrp_write/trx_usrp_write_thread functions --- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 2c880ed919..6b52407a70 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -402,7 +402,14 @@ static int trx_usrp_write(openair0_device *device, for (int j=0; j Date: Mon, 28 Mar 2022 12:08:48 +0200 Subject: [PATCH 3/4] adding case for 8 bit alignment in usrp rx --- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 6b52407a70..855453ec8b 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -405,7 +405,7 @@ static int trx_usrp_write(openair0_device *device, if ((((uintptr_t) buff[i])&0x1F)==0) { buff_tx[i][j] = _mm256_slli_epi16(((__m256i *)buff[i])[j],4); } - else + else { ((__m128i *)buff_tx[i])[2*j] = _mm_slli_epi16(((__m128i *)buff[i])[2*j],4); ((__m128i *)buff_tx[i])[2*j+1] = _mm_slli_epi16(((__m128i *)buff[i])[2*j+1],4); @@ -696,10 +696,15 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp if ((((uintptr_t) buff[i])&0x1F)==0) { ((__m256i *)buff[i])[j] = _mm256_srai_epi16(buff_tmp[i][j],rxshift); - } else { + } else if ((((uintptr_t) buff[i])&0x0F)==0) { ((__m128i *)buff[i])[2*j] = _mm_srai_epi16(((__m128i *)buff_tmp[i])[2*j],rxshift); ((__m128i *)buff[i])[2*j+1] = _mm_srai_epi16(((__m128i *)buff_tmp[i])[2*j+1],rxshift); - } + } else { + ((__m64 *)buff[i])[4*j] = _mm_srai_pi16 (((__m64 *)buff_tmp[i])[4*j],rxshift); + ((__m64 *)buff[i])[4*j+1] = _mm_srai_pi16 (((__m64 *)buff_tmp[i])[4*j+1],rxshift); + ((__m64 *)buff[i])[4*j+2] = _mm_srai_pi16 (((__m64 *)buff_tmp[i])[4*j+2],rxshift); + ((__m64 *)buff[i])[4*j+3] = _mm_srai_pi16 (((__m64 *)buff_tmp[i])[4*j+3],rxshift); + } #else ((__m128i *)buff[i])[j] = _mm_srai_epi16(buff_tmp[i][j],rxshift); From f85ccaa007ab4f88fdde6b3c7a5765e4449647ee Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 28 Mar 2022 12:22:11 +0200 Subject: [PATCH 4/4] Revert "making SFN dependent on GPS time (when available)" This reverts commit 5679e4a3b32beeadd220169aea3c3c1d59e4bee8. --- executables/nr-ru.c | 9 +-------- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 394118d5a9..0240de87bc 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -604,7 +604,6 @@ void *emulatedRF_thread(void *param) { void rx_rf(RU_t *ru,int *frame,int *slot) { RU_proc_t *proc = &ru->proc; NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; - openair0_config_t *cfg = &ru->openair0_cfg; void *rxp[ru->nb_rx]; unsigned int rxs; int i; @@ -654,13 +653,7 @@ void rx_rf(RU_t *ru,int *frame,int *slot) { } } - //compute system frame number (SFN) according to O-RAN-WG4-CUS.0-v02.00 (using alpha=beta=0) - // this assumes that the USRP has been synchronized to the GPS time - // OAI uses timestamps in sample time stored in int64_t, but it will fit in double precision for many years to come. - double gps_sec = ((double) ts)/cfg->sample_rate; - proc->frame_rx = ((int64_t) (gps_sec/0.01)) & 1023; - - //proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_subframe*10))&1023; + proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_subframe*10))&1023; proc->tti_rx = fp->get_slot_from_timestamp(proc->timestamp_rx,fp); // synchronize first reception to frame 0 subframe 0 LOG_D(PHY,"RU %d/%d TS %llu , frame %d, slot %d.%d / %d\n", diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 855453ec8b..365957cad5 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -203,8 +203,8 @@ static int sync_to_gps(openair0_device *device) { //Set to GPS time uhd::time_spec_t gps_time = uhd::time_spec_t(time_t(s->usrp->get_mboard_sensor("gps_time", mboard).to_int())); - s->usrp->set_time_next_pps(gps_time+1.0, mboard); - //s->usrp->set_time_next_pps(uhd::time_spec_t(0.0)); + //s->usrp->set_time_next_pps(gps_time+1.0, mboard); + s->usrp->set_time_next_pps(uhd::time_spec_t(0.0)); //Wait for it to apply //The wait is 2 seconds because N-Series has a known issue where //the time at the last PPS does not properly update at the PPS edge @@ -215,10 +215,10 @@ static int sync_to_gps(openair0_device *device) { uhd::time_spec_t time_last_pps = s->usrp->get_time_last_pps(mboard); std::cout << "USRP time: " << (boost::format("%0.9f") % time_last_pps.get_real_secs()) << std::endl; std::cout << "GPSDO time: " << (boost::format("%0.9f") % gps_time.get_real_secs()) << std::endl; - if (gps_time.get_real_secs() == time_last_pps.get_real_secs()) - std::cout << std::endl << "SUCCESS: USRP time synchronized to GPS time" << std::endl << std::endl; - else - std::cerr << std::endl << "ERROR: Failed to synchronize USRP time to GPS time" << std::endl << std::endl; + //if (gps_time.get_real_secs() == time_last_pps.get_real_secs()) + // std::cout << std::endl << "SUCCESS: USRP time synchronized to GPS time" << std::endl << std::endl; + //else + // std::cerr << std::endl << "ERROR: Failed to synchronize USRP time to GPS time" << std::endl << std::endl; } if (num_gps_locked == num_mboards and num_mboards > 1) {