From b6e2f0e0c9e57e28bc28af9703dd6c578c102460 Mon Sep 17 00:00:00 2001 From: Sagar Parsawar Date: Wed, 18 May 2022 16:50:35 +0200 Subject: [PATCH] gps time sync improvements --- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 5d5e6820ff..b4d7ba0410 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -201,10 +201,21 @@ static int sync_to_gps(openair0_device *device) { LOG_W(HW,"WARNING: GPS not locked - time will not be accurate until locked\n"); } + //wait for next pps + uhd::time_spec_t last = s->usrp->get_time_last_pps(); + uhd::time_spec_t next = s->usrp->get_time_last_pps(); + while(next == last) { + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); + last = next; + next = s->usrp->get_time_last_pps(); + } + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); + //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)); + //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