From 7af605b247ee9331c29c23229252a101b7d40352 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 17 Jun 2011 13:01:07 -0700 Subject: UHD: GPS work. * Rewrote NMEA acquisition to be more general * Added GPS sensors instead of member fns for data access * GPS sensors added to mboard sensors to keep ABI compat * VITA time initialized to GPS time on init --- host/lib/usrp/usrp2/mboard_impl.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 6bf412a3e..3733915a2 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -174,6 +174,12 @@ usrp2_mboard_impl::usrp2_mboard_impl( _iface->poke32(U2_REG_RX_CTRL_CLEAR(i), 1); //resets sequence } //------------------------------------------------------------------ + + //initialize VITA time to GPS time + if(_gps_ctrl.get() and _gps_ctrl->gps_detected()) { + UHD_MSG(status) << "Setting device time to GPS time...\n"; + set_time_spec(time_spec_t(double(_gps_ctrl->get_sensor("gps_time").to_int()+1)), false); + } } usrp2_mboard_impl::~usrp2_mboard_impl(void){UHD_SAFE_CALL( @@ -375,7 +381,10 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_SENSOR_NAMES:{ prop_names_t names = boost::assign::list_of("mimo_locked")("ref_locked"); - if (_gps_ctrl.get()) names.push_back("gps_time"); + if (_gps_ctrl.get()) { + std::vector gs = _gps_ctrl->get_sensors(); + names.insert(names.end(), gs.begin(), gs.end()); + } val = names; } return; @@ -389,8 +398,8 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = sensor_value_t("Ref", this->get_ref_locked(), "locked", "unlocked"); return; } - else if(key.name == "gps_time" and _gps_ctrl.get()) { - val = sensor_value_t("GPS time", int(_gps_ctrl->get_epoch_time()), "seconds"); + else if(uhd::has(_gps_ctrl->get_sensors(), key.name) and _gps_ctrl.get()) { + val = _gps_ctrl->get_sensor(key.name); } else { UHD_THROW_PROP_GET_ERROR(); -- cgit v1.2.3 From 6f6364f73aad1262fdbe88ad97128f7844764c99 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 17 Jun 2011 15:09:16 -0700 Subject: UHD: implemented gps_locked sensor. usrp2 mboard doesn't init VITA time if time not valid. --- host/docs/sync.rst | 19 ++++--------------- host/docs/usrp2.rst | 5 ++--- host/lib/usrp/gps_ctrl.cpp | 22 ++++++++++++++++++++++ host/lib/usrp/usrp2/mboard_impl.cpp | 20 ++++++++++++++++---- 4 files changed, 44 insertions(+), 22 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/docs/sync.rst b/host/docs/sync.rst index 9284d8e33..3cb13fbf3 100644 --- a/host/docs/sync.rst +++ b/host/docs/sync.rst @@ -102,22 +102,11 @@ and the user can also parse this string to determine GPS time: usrp->set_time_next_pps(uhd::time_spec_t(gps_time+1)); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Method 3 - query the gps_time sensor +Method 3 - internal GPSDO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -This is a variant of method 2 for USRPs with internal GPSDOs. -The user can query the gps_time sensor to wait for the NMEA string. - -:: - - //wait for NMEA string from internal GPSDO - usrp->get_mboard_sensor("gps_time"); - usrp->set_time_next_pps(uhd::time_spec_t(0.0)); - - -- OR -- - - //wait for the NMEA string and set GPS time - const time_t gps_time = usrp->get_mboard_sensor("gps_time").to_int(); - usrp->set_time_next_pps(uhd::time_spec_t(gps_time+1)); +USRPs with internal GPSDOs properly configured will automatically +configure themselves to set the VITA time to current UTC time. See the +GPSDO application note for more details. ------------------------------------------------------------------------ Synchronizing channel phase diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst index 88b217f1b..fa811d0f6 100644 --- a/host/docs/usrp2.rst +++ b/host/docs/usrp2.rst @@ -349,9 +349,8 @@ Test the PPS input with the following app: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Internal GPSDO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -USRP-N2XX models can have an optional internal GPSDO. -To use the GPSDO with UHD, you must burn an EEPROM setting -so that UHD knows that the internal GPSDO was installed. +Please see the GPSDO application note for information on configuring and +using the internal GPSDO. **Installation instructions:** diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp index 55f46ffb3..2c2843877 100644 --- a/host/lib/usrp/gps_ctrl.cpp +++ b/host/lib/usrp/gps_ctrl.cpp @@ -184,6 +184,24 @@ public: return (gps_type != GPS_TYPE_NONE); } + bool locked(void) { + std::string reply = get_nmea("GPGGA"); + if(reply.size() <= 1) return false; + + boost::tokenizer > tok(reply); + std::vector toked; + + tok.assign(reply); + toked.assign(tok.begin(), tok.end()); + + if(toked.size() != 15) { + UHD_MSG(error) << "gps_locked: invalid GPGGA response"; + return false; + } + + return (toked[6] != "0"); //sorry, 2d fixes don't count =D + } + //return a list of supported sensors std::vector get_sensors(void) { std::vector ret; @@ -191,6 +209,7 @@ public: ret.push_back("gps_gprmc"); ret.push_back("gps_gpgsa"); ret.push_back("gps_time"); + ret.push_back("gps_locked"); return ret; } @@ -206,6 +225,9 @@ public: else if(key == "gps_time") { return sensor_value_t("GPS epoch time", int(get_epoch_time()), "seconds"); } + else if(key == "gps_locked") { + return sensor_value_t("GPS lock status", locked(), "locked", "unlocked"); + } else { UHD_THROW_PROP_GET_ERROR(); } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 3733915a2..12fff96d0 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -149,7 +149,13 @@ usrp2_mboard_impl::usrp2_mboard_impl( (_mimo_clocking_mode_is_master?"master":"slave") << std::endl; //init the clock config - _clock_config = clock_config_t::internal(); + if(_iface->mb_eeprom["gpsdo"] == "internal" or + _iface->mb_eeprom["gpsdo"] == "external") { + _clock_config = clock_config_t::external(); + } + else { + _clock_config = clock_config_t::internal(); + } update_clock_config(); //init the codec before the dboard @@ -176,9 +182,15 @@ usrp2_mboard_impl::usrp2_mboard_impl( //------------------------------------------------------------------ //initialize VITA time to GPS time - if(_gps_ctrl.get() and _gps_ctrl->gps_detected()) { - UHD_MSG(status) << "Setting device time to GPS time...\n"; - set_time_spec(time_spec_t(double(_gps_ctrl->get_sensor("gps_time").to_int()+1)), false); + if( _gps_ctrl.get() + and _gps_ctrl->gps_detected()) { + if(_gps_ctrl->get_sensor("gps_locked").to_bool()) { + UHD_MSG(status) << "Setting device time to GPS time...\n"; + set_time_spec(time_spec_t(double(_gps_ctrl->get_sensor("gps_time").to_int()+1)), false); + } + else { + UHD_MSG(status) << "GPS not locked to satellites. Not initializing VITA time."; + } } } -- cgit v1.2.3 From 9101804e6b6d85b7cbdd582dba41c114358db407 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 17 Jun 2011 15:13:09 -0700 Subject: USRP2/N210: set VITA time even if GPS not locked. harmless to do so. --- host/lib/usrp/gps_ctrl.cpp | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp index 2c2843877..582334cae 100644 --- a/host/lib/usrp/gps_ctrl.cpp +++ b/host/lib/usrp/gps_ctrl.cpp @@ -199,7 +199,7 @@ public: return false; } - return (toked[6] != "0"); //sorry, 2d fixes don't count =D + return (toked[6] != "0"); } //return a list of supported sensors diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 12fff96d0..61ceb95ca 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -184,13 +184,8 @@ usrp2_mboard_impl::usrp2_mboard_impl( //initialize VITA time to GPS time if( _gps_ctrl.get() and _gps_ctrl->gps_detected()) { - if(_gps_ctrl->get_sensor("gps_locked").to_bool()) { - UHD_MSG(status) << "Setting device time to GPS time...\n"; - set_time_spec(time_spec_t(double(_gps_ctrl->get_sensor("gps_time").to_int()+1)), false); - } - else { - UHD_MSG(status) << "GPS not locked to satellites. Not initializing VITA time."; - } + UHD_MSG(status) << "Setting device time to GPS time...\n"; + set_time_spec(time_spec_t(double(_gps_ctrl->get_sensor("gps_time").to_int()+1)), false); } } -- cgit v1.2.3 From b7f6d905af5993f6c0b554777ab2a4559a36db15 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 20 Jun 2011 08:01:35 -0700 Subject: usrp2: fix typo w/ setting send frame size --- host/lib/usrp/usrp2/usrp2_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9947e71e7..b5e50507c 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -249,7 +249,7 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ //extract the user's requested MTU size or default mtu_result_t user_mtu; user_mtu.recv_mtu = size_t(device_addr.cast("recv_frame_size", udp_simple::mtu)); - user_mtu.send_mtu = size_t(device_addr.cast("recv_frame_size", udp_simple::mtu)); + user_mtu.send_mtu = size_t(device_addr.cast("send_frame_size", udp_simple::mtu)); try{ //calculate the minimum send and recv mtu of all devices -- cgit v1.2.3 From 25d6e39c6af61acde0616cf50178d40741c4eace Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 24 Jun 2011 16:20:33 -0700 Subject: usrp2: init the usrp2_ctrl_data_t to make valgrind happy --- host/lib/usrp/usrp2/usrp2_iface.cpp | 12 ++++++------ host/lib/usrp/usrp2/usrp2_impl.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index ec1a2e94c..6ba364b28 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -179,7 +179,7 @@ public: template T get_reg(boost::uint32_t addr, T data = 0){ //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO); out_data.data.reg_args.addr = htonl(addr); out_data.data.reg_args.data = htonl(boost::uint32_t(data)); @@ -207,7 +207,7 @@ public: ; //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); out_data.data.spi_args.dev = htonl(which_slave); out_data.data.spi_args.miso_edge = spi_edge_to_otw[config.miso_edge]; @@ -228,7 +228,7 @@ public: **********************************************************************/ void write_i2c(boost::uint8_t addr, const byte_vector_t &buf){ //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO); out_data.data.i2c_args.addr = addr; out_data.data.i2c_args.bytes = buf.size(); @@ -246,7 +246,7 @@ public: byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){ //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO); out_data.data.i2c_args.addr = addr; out_data.data.i2c_args.bytes = num_bytes; @@ -276,7 +276,7 @@ public: BOOST_FOREACH(std::string item, queue) { //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_HEY_WRITE_THIS_UART_FOR_ME_BRO); out_data.data.uart_args.dev = dev; out_data.data.uart_args.bytes = item.size(); @@ -298,7 +298,7 @@ public: std::string result; while(readlen == 20) { //while we keep receiving full packets //setup the out data - usrp2_ctrl_data_t out_data; + usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t(); out_data.id = htonl(USRP2_CTRL_ID_SO_LIKE_CAN_YOU_READ_THIS_UART_BRO); out_data.data.uart_args.dev = dev; out_data.data.uart_args.bytes = 20; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index b5e50507c..aa584ac8b 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -93,7 +93,7 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){ ); //send a hello control packet - usrp2_ctrl_data_t ctrl_data_out; + usrp2_ctrl_data_t ctrl_data_out = usrp2_ctrl_data_t(); ctrl_data_out.proto_ver = uhd::htonx(USRP2_FW_COMPAT_NUM); ctrl_data_out.id = uhd::htonx(USRP2_CTRL_ID_WAZZUP_BRO); udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); -- cgit v1.2.3