From 76c8b7fa24ea6c1bba84d7116b12dc0e4c5cacf6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 30 Dec 2010 16:41:38 -0800 Subject: usrp2: implemented get time last pps renamed the enum for the pps time added calls to single and multi wrappers set time unknown pps now simpler removed peek64 stuff from host + fw please test --- host/lib/usrp/multi_usrp.cpp | 29 +++++++++++++++++------------ host/lib/usrp/single_usrp.cpp | 6 +++++- host/lib/usrp/usrp2/fw_common.h | 5 ++--- host/lib/usrp/usrp2/mboard_impl.cpp | 24 +++++++++++++++--------- host/lib/usrp/usrp2/usrp2_iface.cpp | 14 -------------- host/lib/usrp/usrp2/usrp2_iface.hpp | 9 --------- host/lib/usrp/usrp2/usrp2_regs.cpp | 6 ++++-- host/lib/usrp/usrp2/usrp2_regs.hpp | 6 ++++-- host/lib/usrp/usrp_e100/mboard_impl.cpp | 2 +- 9 files changed, 48 insertions(+), 53 deletions(-) (limited to 'host/lib') diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 876f1a3fc..2245983ee 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -117,26 +117,31 @@ public: return _mboard(0)[MBOARD_PROP_TIME_NOW].as(); } + time_spec_t get_time_last_pps(void){ + return _mboard(0)[MBOARD_PROP_TIME_PPS].as(); + } + void set_time_next_pps(const time_spec_t &time_spec){ for (size_t m = 0; m < get_num_mboards(); m++){ - _mboard(m)[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; + _mboard(m)[MBOARD_PROP_TIME_PPS] = time_spec; } } void set_time_unknown_pps(const time_spec_t &time_spec){ - std::cout << "Set time with unknown pps edge:" << std::endl; - std::cout << " 1) set times next pps (race condition)" << std::endl; - set_time_next_pps(time_spec); - boost::this_thread::sleep(boost::posix_time::seconds(1)); - - std::cout << " 2) catch seconds rollover at pps edge" << std::endl; - time_t last_secs = 0, curr_secs = 0; - while(curr_secs == last_secs){ - last_secs = curr_secs; - curr_secs = get_time_now().get_full_secs(); + std::cout << " 1) catch time transition at pps edge" << std::endl; + time_spec_t time_start = get_time_now(); + time_spec_t time_start_last_pps = get_time_last_pps(); + while(true){ + if (get_time_last_pps() != time_start_last_pps) break; + if ((get_time_now() - time_start) > time_spec_t(1.1)){ + throw std::runtime_error( + "The time at the last PPS has not changed.\n" + "Board 0 may not be getting a PPS signal.\n" + ); + } } - std::cout << " 3) set times next pps (synchronously)" << std::endl; + std::cout << " 2) set times next pps (synchronously)" << std::endl; set_time_next_pps(time_spec); boost::this_thread::sleep(boost::posix_time::seconds(1)); diff --git a/host/lib/usrp/single_usrp.cpp b/host/lib/usrp/single_usrp.cpp index a0456d1f0..12730929a 100644 --- a/host/lib/usrp/single_usrp.cpp +++ b/host/lib/usrp/single_usrp.cpp @@ -106,12 +106,16 @@ public: return _mboard()[MBOARD_PROP_TIME_NOW].as(); } + time_spec_t get_time_last_pps(void){ + return _mboard()[MBOARD_PROP_TIME_PPS].as(); + } + void set_time_now(const time_spec_t &time_spec){ _mboard()[MBOARD_PROP_TIME_NOW] = time_spec; } void set_time_next_pps(const time_spec_t &time_spec){ - _mboard()[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; + _mboard()[MBOARD_PROP_TIME_PPS] = time_spec; } void issue_stream_cmd(const stream_cmd_t &stream_cmd){ diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index a9c39e650..5637987f2 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -125,9 +125,8 @@ typedef struct{ struct { __stdint(uint32_t) addr; __stdint(uint32_t) data; - __stdint(uint32_t) addrhi; - __stdint(uint32_t) datahi; - __stdint(uint8_t) num_bytes; //1, 2, 4, 8 + __stdint(uint64_t) _pad; + __stdint(uint8_t) num_bytes; //1, 2, 4 } poke_args; struct { __stdint(uint8_t) dev; diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 766ea993c..d97fd1dcd 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -279,15 +279,21 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; - case MBOARD_PROP_TIME_NOW:{ - usrp2_iface::pair64 time64( - _iface->peek64(_iface->regs.time64_secs_rb, _iface->regs.time64_ticks_rb) - ); - val = time_spec_t( - time64.first, time64.second, get_master_clock_freq() - ); - } + case MBOARD_PROP_TIME_NOW: while(true){ + uint32_t secs = _iface->peek32(_iface->regs.time64_secs_rb_imm); + uint32_t ticks = _iface->peek32(_iface->regs.time64_ticks_rb_imm); + if (secs != _iface->peek32(_iface->regs.time64_secs_rb_imm)) continue; + val = time_spec_t(secs, ticks, get_master_clock_freq()); return; + } + + case MBOARD_PROP_TIME_PPS: while(true){ + uint32_t secs = _iface->peek32(_iface->regs.time64_secs_rb_pps); + uint32_t ticks = _iface->peek32(_iface->regs.time64_ticks_rb_pps); + if (secs != _iface->peek32(_iface->regs.time64_secs_rb_pps)) continue; + val = time_spec_t(secs, ticks, get_master_clock_freq()); + return; + } case MBOARD_PROP_RX_SUBDEV_SPEC: val = _rx_subdev_spec; @@ -321,7 +327,7 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ set_time_spec(val.as(), true); return; - case MBOARD_PROP_TIME_NEXT_PPS: + case MBOARD_PROP_TIME_PPS: set_time_spec(val.as(), false); return; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index ffbe8eedb..dcb25dc54 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -93,20 +93,6 @@ public: return this->peek(addr); } - pair64 peek64(boost::uint32_t addrlo, boost::uint32_t addrhi){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO); - out_data.data.poke_args.addr = htonl(addrlo); - out_data.data.poke_args.addrhi = htonl(addrhi); - out_data.data.poke_args.num_bytes = sizeof(boost::uint64_t); - - //send and recv - usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); - return pair64(ntohl(in_data.data.poke_args.data), ntohl(in_data.data.poke_args.datahi)); - } - /*********************************************************************** * SPI **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index af3ed6c9f..2b4378ddf 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -37,7 +37,6 @@ class usrp2_iface : public uhd::i2c_iface, boost::noncopyable{ public: typedef boost::shared_ptr sptr; - typedef std::pair pair64; /*! * Make a new usrp2 interface with the control transport. @@ -53,14 +52,6 @@ public: */ virtual usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &data) = 0; - /*! - * Read a dual register (64 bits) - * \param addrlo the address for the low-32 bits - * \param addrhi the address for the high-32 bits - * \return a pair of 32 bit integers lo, hi - */ - virtual pair64 peek64(boost::uint32_t addrlo, boost::uint32_t addrhi) = 0; - /*! * Write a register (32 bits) * \param addr the address diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index dd0433816..a566dbce7 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -57,9 +57,11 @@ usrp2_regs_t usrp2_get_regs(bool use_n2xx_map) { x.time64_flags = sr_addr(misc_output_base, x.sr_time64 + 2); x.time64_imm = sr_addr(misc_output_base, x.sr_time64 + 3); x.time64_tps = sr_addr(misc_output_base, x.sr_time64 + 4); - x.time64_secs_rb = bp_base + 4*10; - x.time64_ticks_rb = bp_base + 4*11; + x.time64_secs_rb_imm = bp_base + 4*10; + x.time64_ticks_rb_imm = bp_base + 4*11; x.compat_num_rb = bp_base + 4*12; + x.time64_secs_rb_pps = bp_base + 4*14; + x.time64_ticks_rb_pps = bp_base + 4*15; x.dsp_tx_freq = sr_addr(misc_output_base, x.sr_tx_dsp + 0); x.dsp_tx_scale_iq = sr_addr(misc_output_base, x.sr_tx_dsp + 1); x.dsp_tx_interp_rate = sr_addr(misc_output_base, x.sr_tx_dsp + 2); diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 9936d634a..7014c192e 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -57,8 +57,10 @@ typedef struct { int time64_flags; // flags -- see chart below int time64_imm; // set immediate (0=latch on next pps, 1=latch immediate, default=0) int time64_tps; // ticks per second rollover count - int time64_secs_rb; - int time64_ticks_rb; + int time64_secs_rb_imm; + int time64_ticks_rb_imm; + int time64_secs_rb_pps; + int time64_ticks_rb_pps; int compat_num_rb; int dsp_tx_freq; int dsp_tx_scale_iq; diff --git a/host/lib/usrp/usrp_e100/mboard_impl.cpp b/host/lib/usrp/usrp_e100/mboard_impl.cpp index fe26cd63d..c056bf3ea 100644 --- a/host/lib/usrp/usrp_e100/mboard_impl.cpp +++ b/host/lib/usrp/usrp_e100/mboard_impl.cpp @@ -150,7 +150,7 @@ void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){ return; case MBOARD_PROP_TIME_NOW: - case MBOARD_PROP_TIME_NEXT_PPS:{ + case MBOARD_PROP_TIME_PPS:{ time_spec_t time_spec = val.as(); _iface->poke32(UE_REG_TIME64_TICKS, time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate())); boost::uint32_t imm_flags = (key.as() == MBOARD_PROP_TIME_NOW)? 1 : 0; -- cgit v1.2.3