From 23a04bf3ed4c4745492c5316d8921ecba1fb6499 Mon Sep 17 00:00:00 2001 From: 211217613 Date: Thu, 23 Jun 2016 20:35:46 -0500 Subject: Close file handlers the python way, changed var bytes to out_bytes --- firmware/fx2/utils/build_eeprom.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/firmware/fx2/utils/build_eeprom.py b/firmware/fx2/utils/build_eeprom.py index 76502b923..9180bf1a0 100755 --- a/firmware/fx2/utils/build_eeprom.py +++ b/firmware/fx2/utils/build_eeprom.py @@ -45,8 +45,8 @@ def build_eeprom_image (filename, rev): the EZ-USB FX2 Technical Reference Manual """ # get the code we want to run - f = open(filename, 'rb') - bytes = f.read() + with open(filename, 'rb') as f: + out_bytes = f.read() devid = 4 #for compatibility start_addr = 0 #prove me wrong @@ -72,8 +72,8 @@ def build_eeprom_image (filename, rev): # 4 byte header that indicates where to load # the immediately follow code bytes. code_header = [ - msb (len (bytes)), - lsb (len (bytes)), + msb (len (out_bytes)), + lsb (len (out_bytes)), msb (start_addr), lsb (start_addr) ] @@ -87,7 +87,7 @@ def build_eeprom_image (filename, rev): 0x00 ] - image = rom_header + code_header + [ord(c) for c in bytes] + trailer + image = rom_header + code_header + [ord(c) for c in out_bytes] + trailer assert (len (image) <= 256) return image @@ -111,6 +111,6 @@ if __name__ == '__main__': image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev)) - f = open(outfile, 'wb') - f.write(str(image)) - f.close() + # Opening in binary mode -> why converting image to str + with open(outfile, 'wb') as f: + f.write( str(image) ) \ No newline at end of file -- cgit v1.2.3 From e1139b25429f41092bef76584dbd5912014b8768 Mon Sep 17 00:00:00 2001 From: michael-west Date: Mon, 27 Jun 2016 10:48:29 -0700 Subject: Octoclock: Fix firmware version compatibility --- host/include/uhd/usrp_clock/octoclock_eeprom.hpp | 4 +++- host/lib/usrp_clock/octoclock/common.h | 4 ++-- host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp | 9 +++++---- .../usrp_clock/octoclock/octoclock_image_loader.cpp | 10 +++++----- host/lib/usrp_clock/octoclock/octoclock_impl.cpp | 20 ++++++++++---------- host/lib/usrp_clock/octoclock/octoclock_impl.hpp | 3 ++- host/lib/usrp_clock/octoclock/octoclock_uart.cpp | 13 +++++++------ host/lib/usrp_clock/octoclock/octoclock_uart.hpp | 5 +++-- host/utils/octoclock_firmware_burner.cpp | 14 +++++++------- 9 files changed, 44 insertions(+), 38 deletions(-) diff --git a/host/include/uhd/usrp_clock/octoclock_eeprom.hpp b/host/include/uhd/usrp_clock/octoclock_eeprom.hpp index a521000dd..aaa6296ae 100644 --- a/host/include/uhd/usrp_clock/octoclock_eeprom.hpp +++ b/host/include/uhd/usrp_clock/octoclock_eeprom.hpp @@ -40,8 +40,9 @@ public: /*! * Make a new OctoClock EEPROM handler. * \param transport the UDP transport to the OctoClock + * \param proto_ver firmware protocol version */ - octoclock_eeprom_t(transport::udp_simple::sptr transport); + octoclock_eeprom_t(transport::udp_simple::sptr transport, boost::uint32_t proto_ver); /*! * Write the contents of this object to the EEPROM. @@ -50,6 +51,7 @@ public: private: transport::udp_simple::sptr xport; + boost::uint32_t _proto_ver; void _load(); void _store() const; diff --git a/host/lib/usrp_clock/octoclock/common.h b/host/lib/usrp_clock/octoclock/common.h index 191b93d36..43c098e81 100644 --- a/host/lib/usrp_clock/octoclock/common.h +++ b/host/lib/usrp_clock/octoclock/common.h @@ -25,8 +25,8 @@ */ #ifdef __cplusplus -#define UHD_OCTOCLOCK_SEND_AND_RECV(xport, pkt_code, pkt_out, len, data) do {\ - pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; \ +#define UHD_OCTOCLOCK_SEND_AND_RECV(xport, fw_version, pkt_code, pkt_out, len, data) do {\ + pkt_out.proto_ver = fw_version; \ pkt_out.code = pkt_code; \ xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \ len = xport->recv(boost::asio::buffer(data), 2);\ diff --git a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp index 8ac38011d..b39bc4b52 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp @@ -50,7 +50,7 @@ void octoclock_eeprom_t::_load(){ pkt_out.sequence = boost::uint32_t(std::rand()); size_t len = 0; - UHD_OCTOCLOCK_SEND_AND_RECV(xport, SEND_EEPROM_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(xport, _proto_ver, SEND_EEPROM_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_EEPROM_ACK, pkt_out, pkt_in, len)){ //MAC address byte_vector_t mac_bytes(eeprom_in->mac_addr, eeprom_in->mac_addr+6); @@ -144,7 +144,7 @@ void octoclock_eeprom_t::_store() const { eeprom_out->revision = (*this)["revision"][0]-'0'; } - UHD_OCTOCLOCK_SEND_AND_RECV(xport, BURN_EEPROM_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(xport, _proto_ver, BURN_EEPROM_CMD, pkt_out, len, octoclock_data); if(not UHD_OCTOCLOCK_PACKET_MATCHES(BURN_EEPROM_SUCCESS_ACK, pkt_out, pkt_in, len)) throw uhd::runtime_error("Error writing to OctoClock EEPROM."); } @@ -156,8 +156,9 @@ octoclock_eeprom_t::octoclock_eeprom_t(void){ /* NOP */ } -octoclock_eeprom_t::octoclock_eeprom_t(udp_simple::sptr transport){ - xport = transport; +octoclock_eeprom_t::octoclock_eeprom_t(udp_simple::sptr transport, uint32_t proto_ver) : + xport(transport), _proto_ver(proto_ver) +{ _load(); } diff --git a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp index e12256c15..3f89a9263 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp @@ -178,7 +178,7 @@ static void octoclock_setup_session(octoclock_session_t &session, octoclock_packet_t pkt_out; const octoclock_packet_t* pkt_in = reinterpret_cast(session.data_in); size_t len = 0; - UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, OCTOCLOCK_QUERY_CMD, pkt_out, len, session.data_in); + UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, OCTOCLOCK_FW_COMPAT_NUM, OCTOCLOCK_QUERY_CMD, pkt_out, len, session.data_in); if(UHD_OCTOCLOCK_PACKET_MATCHES(OCTOCLOCK_QUERY_ACK, pkt_out, pkt_in, len)){ session.starting_firmware_version = uhd::htonx(pkt_in->proto_ver); } else { @@ -244,7 +244,7 @@ static void octoclock_burn(octoclock_session_t &session){ std::cout << " -- Preparing OctoClock for firmware load..." << std::flush; pkt_out.len = session.image.size(); pkt_out.crc = session.crc; - UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, PREPARE_FW_BURN_CMD, pkt_out, len, session.data_in); + UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, OCTOCLOCK_FW_COMPAT_NUM, PREPARE_FW_BURN_CMD, pkt_out, len, session.data_in); if(UHD_OCTOCLOCK_PACKET_MATCHES(FW_BURN_READY_ACK, pkt_out, pkt_in, len)){ std::cout << "successful." << std::endl; } @@ -265,7 +265,7 @@ static void octoclock_burn(octoclock_session_t &session){ memset(pkt_out.data, 0, OCTOCLOCK_BLOCK_SIZE); memcpy((char*)pkt_out.data, &session.image[pkt_out.addr], OCTOCLOCK_BLOCK_SIZE); - UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, FILE_TRANSFER_CMD, pkt_out, len, session.data_in); + UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, OCTOCLOCK_FW_COMPAT_NUM, FILE_TRANSFER_CMD, pkt_out, len, session.data_in); if(not UHD_OCTOCLOCK_PACKET_MATCHES(FILE_TRANSFER_ACK, pkt_out, pkt_in, len)){ std::cout << std::endl; throw uhd::runtime_error("Failed to load firmware."); @@ -299,7 +299,7 @@ static void octoclock_verify(octoclock_session_t &session){ memcpy((char*)image_part, &session.image[pkt_out.addr], OCTOCLOCK_BLOCK_SIZE); cmp_len = std::min(OCTOCLOCK_BLOCK_SIZE, session.image.size() - size_t(pkt_out.addr)); - UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, READ_FW_CMD, pkt_out, len, session.data_in); + UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, OCTOCLOCK_FW_COMPAT_NUM, READ_FW_CMD, pkt_out, len, session.data_in); if(UHD_OCTOCLOCK_PACKET_MATCHES(READ_FW_ACK, pkt_out, pkt_in, len)){ if(memcmp(pkt_in->data, image_part, cmp_len)){ std::cout << std::endl; @@ -325,7 +325,7 @@ static void octoclock_finalize(octoclock_session_t &session){ size_t len = 0; std::cout << " -- Finalizing firmware load..." << std::flush; - UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, FINALIZE_BURNING_CMD, pkt_out, len, session.data_in); + UHD_OCTOCLOCK_SEND_AND_RECV(session.fw_xport, OCTOCLOCK_FW_COMPAT_NUM, FINALIZE_BURNING_CMD, pkt_out, len, session.data_in); if(UHD_OCTOCLOCK_PACKET_MATCHES(FINALIZE_BURNING_ACK, pkt_out, pkt_in, len)){ std::cout << "successful." << std::endl; } diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp index 4f70a8273..15d919272 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp @@ -138,7 +138,7 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ new_addr["addr"], BOOST_STRINGIZE(OCTOCLOCK_UDP_CTRL_PORT) ); - UHD_OCTOCLOCK_SEND_AND_RECV(ctrl_xport, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(ctrl_xport, OCTOCLOCK_FW_COMPAT_NUM, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(OCTOCLOCK_QUERY_ACK, pkt_out, pkt_in, len)){ //If the OctoClock is in its bootloader, don't ask for details if(pkt_in->proto_ver == OCTOCLOCK_BOOTLOADER_PROTO_VER){ @@ -149,7 +149,7 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ new_addr["type"] = "octoclock"; if(pkt_in->proto_ver >= OCTOCLOCK_FW_MIN_COMPAT_NUM and pkt_in->proto_ver <= OCTOCLOCK_FW_COMPAT_NUM) { - octoclock_eeprom_t oc_eeprom(ctrl_xport); + octoclock_eeprom_t oc_eeprom(ctrl_xport, pkt_in->proto_ver); new_addr["name"] = oc_eeprom["name"]; new_addr["serial"] = oc_eeprom["serial"]; } else { @@ -226,21 +226,21 @@ octoclock_impl::octoclock_impl(const device_addr_t &_device_addr){ //////////////////////////////////////////////////////////////////// // Check the firmware compatibility number //////////////////////////////////////////////////////////////////// - boost::uint32_t fw_version = _get_fw_version(oc); - if(fw_version < OCTOCLOCK_FW_MIN_COMPAT_NUM or fw_version > OCTOCLOCK_FW_COMPAT_NUM){ + _proto_ver = _get_fw_version(oc); + if(_proto_ver < OCTOCLOCK_FW_MIN_COMPAT_NUM or _proto_ver > OCTOCLOCK_FW_COMPAT_NUM){ throw uhd::runtime_error(str(boost::format( "\n\nPlease update your OctoClock's firmware.\n" "Expected firmware compatibility number %d, but got %d:\n" "The firmware build is not compatible with the host code build.\n\n" "%s\n" - ) % int(OCTOCLOCK_FW_COMPAT_NUM) % int(fw_version) % _get_images_help_message(addr))); + ) % int(OCTOCLOCK_FW_COMPAT_NUM) % int(_proto_ver) % _get_images_help_message(addr))); } - _tree->create(oc_path / "fw_version").set(boost::lexical_cast(int(fw_version))); + _tree->create(oc_path / "fw_version").set(boost::lexical_cast(int(_proto_ver))); //////////////////////////////////////////////////////////////////// // Set up EEPROM //////////////////////////////////////////////////////////////////// - _oc_dict[oc].eeprom = octoclock_eeprom_t(_oc_dict[oc].ctrl_xport); + _oc_dict[oc].eeprom = octoclock_eeprom_t(_oc_dict[oc].ctrl_xport, _proto_ver); _tree->create(oc_path / "eeprom") .set(_oc_dict[oc].eeprom) .subscribe(boost::bind(&octoclock_impl::_set_eeprom, this, oc, _1)); @@ -272,7 +272,7 @@ octoclock_impl::octoclock_impl(const device_addr_t &_device_addr){ _get_state(oc); if(_oc_dict[oc].state.gps_detected){ try{ - _oc_dict[oc].gps = gps_ctrl::make(octoclock_make_uart_iface(_oc_dict[oc].gpsdo_xport)); + _oc_dict[oc].gps = gps_ctrl::make(octoclock_make_uart_iface(_oc_dict[oc].gpsdo_xport, _proto_ver)); if(_oc_dict[oc].gps and _oc_dict[oc].gps->gps_detected()){ BOOST_FOREACH(const std::string &name, _oc_dict[oc].gps->get_sensors()){ @@ -339,7 +339,7 @@ boost::uint32_t octoclock_impl::_get_fw_version(const std::string &oc){ boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast(octoclock_data); - UHD_OCTOCLOCK_SEND_AND_RECV(_oc_dict[oc].ctrl_xport, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(_oc_dict[oc].ctrl_xport, OCTOCLOCK_FW_COMPAT_NUM, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(OCTOCLOCK_QUERY_ACK, pkt_out, pkt_in, len)){ return pkt_in->proto_ver; } @@ -355,7 +355,7 @@ void octoclock_impl::_get_state(const std::string &oc){ boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast(octoclock_data); - UHD_OCTOCLOCK_SEND_AND_RECV(_oc_dict[oc].ctrl_xport, SEND_STATE_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(_oc_dict[oc].ctrl_xport, _proto_ver, SEND_STATE_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_STATE_ACK, pkt_out, pkt_in, len)){ const octoclock_state_t *state = reinterpret_cast(pkt_in->data); _oc_dict[oc].state = *state; diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.hpp b/host/lib/usrp_clock/octoclock/octoclock_impl.hpp index 453e75ec5..2c74b9b03 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.hpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2014 Ettus Research LLC +// Copyright 2014,2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -57,6 +57,7 @@ private: }; uhd::dict _oc_dict; boost::uint32_t _sequence; + boost::uint32_t _proto_ver; void _set_eeprom(const std::string &oc, const uhd::usrp_clock::octoclock_eeprom_t &oc_eeprom); diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp index e0a9f08cf..bc2c9b60a 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp @@ -41,12 +41,13 @@ using namespace uhd::transport; (NUM_WRAPS_EQUAL && _state.pos > _device_state.pos)) namespace uhd{ - octoclock_uart_iface::octoclock_uart_iface(udp_simple::sptr udp): uart_iface(){ + octoclock_uart_iface::octoclock_uart_iface(udp_simple::sptr udp, uint32_t proto_ver): uart_iface(){ _udp = udp; _state.num_wraps = 0; _state.pos = 0; _device_state.num_wraps = 0; _device_state.pos = 0; + _proto_ver = proto_ver; // To avoid replicating sequence numbers between sessions _sequence = boost::uint32_t(std::rand()); size_t len = 0; @@ -59,7 +60,7 @@ namespace uhd{ boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast(octoclock_data); - UHD_OCTOCLOCK_SEND_AND_RECV(_udp, SEND_POOLSIZE_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(_udp, _proto_ver, SEND_POOLSIZE_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_POOLSIZE_ACK, pkt_out, pkt_in, len)){ _poolsize = pkt_in->poolsize; _cache.resize(_poolsize); @@ -79,7 +80,7 @@ namespace uhd{ boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast(octoclock_data); - UHD_OCTOCLOCK_SEND_AND_RECV(_udp, HOST_SEND_TO_GPSDO_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(_udp, _proto_ver, HOST_SEND_TO_GPSDO_CMD, pkt_out, len, octoclock_data); if(not UHD_OCTOCLOCK_PACKET_MATCHES(HOST_SEND_TO_GPSDO_ACK, pkt_out, pkt_in, len)){ throw uhd::runtime_error("Failed to send commands to GPSDO."); } @@ -120,7 +121,7 @@ namespace uhd{ if(STATES_EQUAL or LOCAL_STATE_AHEAD){ pkt_out.sequence = uhd::htonx(++_sequence); - UHD_OCTOCLOCK_SEND_AND_RECV(_udp, SEND_GPSDO_CACHE_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(_udp, _proto_ver, SEND_GPSDO_CACHE_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_GPSDO_CACHE_ACK, pkt_out, pkt_in, len)){ memcpy(&_cache[0], pkt_in->data, _poolsize); _device_state = pkt_in->state; @@ -158,7 +159,7 @@ namespace uhd{ return ch; } - uart_iface::sptr octoclock_make_uart_iface(udp_simple::sptr udp){ - return uart_iface::sptr(new octoclock_uart_iface(udp)); + uart_iface::sptr octoclock_make_uart_iface(udp_simple::sptr udp, uint32_t proto_ver){ + return uart_iface::sptr(new octoclock_uart_iface(udp, proto_ver)); } } diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp index d7a77288f..360e53625 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp @@ -31,7 +31,7 @@ namespace uhd{ class octoclock_uart_iface : public uhd::uart_iface{ public: - octoclock_uart_iface(uhd::transport::udp_simple::sptr udp); + octoclock_uart_iface(uhd::transport::udp_simple::sptr udp, uint32_t proto_ver); ~octoclock_uart_iface(void) {}; void write_uart(const std::string &buf); @@ -46,12 +46,13 @@ private: std::vector _cache; std::string _rxbuff; boost::uint32_t _sequence; + boost::uint32_t _proto_ver; void _update_cache(); char _getchar(); }; -uart_iface::sptr octoclock_make_uart_iface(uhd::transport::udp_simple::sptr udp); +uart_iface::sptr octoclock_make_uart_iface(uhd::transport::udp_simple::sptr udp, uint32_t proto_ver); } diff --git a/host/utils/octoclock_firmware_burner.cpp b/host/utils/octoclock_firmware_burner.cpp index 326985df5..7bf1057ee 100644 --- a/host/utils/octoclock_firmware_burner.cpp +++ b/host/utils/octoclock_firmware_burner.cpp @@ -123,7 +123,7 @@ void print_image_loader_warning(const std::string &fw_path, const po::variables_ << uhd_image_loader << std::endl << std::endl << "************************************************************************************************" << std::endl - << std::endl; + << std::endl; } /* @@ -144,7 +144,7 @@ device_addrs_t bootloader_find(const std::string &ip_addr){ boost::system_time comm_timeout = boost::get_system_time() + boost::posix_time::milliseconds(3000); while(boost::get_system_time() < comm_timeout){ - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, OCTOCLOCK_QUERY_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(OCTOCLOCK_QUERY_ACK, pkt_out, pkt_in, len) and pkt_in->proto_ver == OCTOCLOCK_BOOTLOADER_PROTO_VER){ addrs.push_back(device_addr_t()); @@ -181,7 +181,7 @@ void burn_firmware(udp_simple::sptr udp_transport){ //Tell OctoClock not to jump to application, wait for us instead std::cout << "Telling OctoClock to prepare for firmware download..." << std::flush; - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, PREPARE_FW_BURN_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, PREPARE_FW_BURN_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(FW_BURN_READY_ACK, pkt_out, pkt_in, len)) std::cout << "ready." << std::endl; else{ std::cout << std::endl; @@ -206,7 +206,7 @@ void burn_firmware(udp_simple::sptr udp_transport){ bool success = false; while(num_tries <= 5){ - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, FILE_TRANSFER_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, FILE_TRANSFER_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(FILE_TRANSFER_ACK, pkt_out, pkt_in, len)){ success = true; break; @@ -240,7 +240,7 @@ void verify_firmware(udp_simple::sptr udp_transport){ std::cout << "\r * Progress: " << int(double(i)/double(num_blocks)*100) << "% (" << (i+1) << "/" << num_blocks << " blocks)" << std::flush; - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, READ_FW_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, READ_FW_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(READ_FW_ACK, pkt_out, pkt_in, len)){ if(memcmp((void*)(pkt_in->data), &firmware_image[i*BLOCK_SIZE], std::min(int(firmware_size-current_pos), BLOCK_SIZE))){ @@ -266,7 +266,7 @@ bool reset_octoclock(const std::string &ip_addr){ pkt_out.sequence = uhd::htonx(std::rand()); size_t len; - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, RESET_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, RESET_CMD, pkt_out, len, octoclock_data); if(not UHD_OCTOCLOCK_PACKET_MATCHES(RESET_ACK, pkt_out, pkt_in, len)){ std::cout << std::endl; if(hex) fs::remove(actual_firmware_path); @@ -283,7 +283,7 @@ void finalize(udp_simple::sptr udp_transport){ pkt_out.sequence = uhd::htonx(std::rand()); size_t len = 0; - UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, FINALIZE_BURNING_CMD, pkt_out, len, octoclock_data); + UHD_OCTOCLOCK_SEND_AND_RECV(udp_transport, OCTOCLOCK_FW_COMPAT_NUM, FINALIZE_BURNING_CMD, pkt_out, len, octoclock_data); if(not UHD_OCTOCLOCK_PACKET_MATCHES(FINALIZE_BURNING_ACK, pkt_out, pkt_in, len)){ std::cout << std::endl; if(hex) fs::remove(actual_firmware_path); -- cgit v1.2.3 From e1dec92e3c142a6b4846834afad99185b73189c6 Mon Sep 17 00:00:00 2001 From: michael-west Date: Tue, 28 Jun 2016 17:09:53 -0700 Subject: Octoclock: Fixed issues related to missing strings from GPSDO. - Corrected case when num_wraps overflowed - Added limit to cache age --- host/lib/usrp_clock/octoclock/octoclock_uart.cpp | 38 ++++++++++++++++-------- host/lib/usrp_clock/octoclock/octoclock_uart.hpp | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp index bc2c9b60a..221a7e471 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp @@ -37,8 +37,7 @@ using namespace uhd::transport; #define NUM_WRAPS_EQUAL (_state.num_wraps == _device_state.num_wraps) #define POS_EQUAL (_state.pos == _device_state.pos) #define STATES_EQUAL (NUM_WRAPS_EQUAL && POS_EQUAL) -#define LOCAL_STATE_AHEAD (_state.num_wraps > _device_state.num_wraps || \ - (NUM_WRAPS_EQUAL && _state.pos > _device_state.pos)) +#define MAX_CACHE_AGE 256 //seconds namespace uhd{ octoclock_uart_iface::octoclock_uart_iface(udp_simple::sptr udp, uint32_t proto_ver): uart_iface(){ @@ -88,10 +87,15 @@ namespace uhd{ std::string octoclock_uart_iface::read_uart(double timeout){ std::string result; - + bool first_time = true; boost::system_time exit_time = boost::get_system_time() + boost::posix_time::milliseconds(long(timeout*1e3)); while(boost::get_system_time() < exit_time){ + if (first_time) + first_time = false; + else + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + _update_cache(); for(char ch = _getchar(); ch != 0; ch = _getchar()){ @@ -105,7 +109,6 @@ namespace uhd{ return result; } } - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); } return result; @@ -119,35 +122,44 @@ namespace uhd{ boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast(octoclock_data); - if(STATES_EQUAL or LOCAL_STATE_AHEAD){ + if(STATES_EQUAL){ + boost::system_time time = boost::get_system_time(); + boost::posix_time::time_duration age = time - _last_cache_update; + bool cache_expired = (age > boost::posix_time::seconds(MAX_CACHE_AGE)); + pkt_out.sequence = uhd::htonx(++_sequence); UHD_OCTOCLOCK_SEND_AND_RECV(_udp, _proto_ver, SEND_GPSDO_CACHE_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_GPSDO_CACHE_ACK, pkt_out, pkt_in, len)){ memcpy(&_cache[0], pkt_in->data, _poolsize); _device_state = pkt_in->state; + _last_cache_update = time; } boost::uint8_t delta_wraps = (_device_state.num_wraps - _state.num_wraps); - if(delta_wraps > 1 or - ((delta_wraps == 1) and (_device_state.pos >= _state.pos))){ + if(cache_expired or delta_wraps > 1 or + ((delta_wraps == 1) and (_device_state.pos > _state.pos))){ - _state.pos = (_device_state.pos+1) % _poolsize; + _state.pos = _device_state.pos; _state.num_wraps = (_device_state.num_wraps-1); + _rxbuff.clear(); - while((_cache[_state.pos] != '\n') and (_state.pos != _device_state.pos)){ + while((_cache[_state.pos] != '\n')){ + _state.pos = (_state.pos+1) % _poolsize; + //We may have wrapped around locally + if(_state.pos == 0) _state.num_wraps++; + if(STATES_EQUAL) break; + } + if (_cache[_state.pos] == '\n'){ _state.pos = (_state.pos+1) % _poolsize; //We may have wrapped around locally if(_state.pos == 0) _state.num_wraps++; } - if (_cache[_state.pos] == '\n') _state.pos = (_state.pos+1) % _poolsize; - //We may have wrapped around locally - if(_state.pos == 0) _state.num_wraps++; } } } char octoclock_uart_iface::_getchar(){ - if(STATES_EQUAL or LOCAL_STATE_AHEAD){ + if(STATES_EQUAL){ return 0; } diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp index 360e53625..d3a9738c4 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp @@ -47,6 +47,7 @@ private: std::string _rxbuff; boost::uint32_t _sequence; boost::uint32_t _proto_ver; + boost::system_time _last_cache_update; void _update_cache(); char _getchar(); -- cgit v1.2.3 From 7872bad482b6edc8b57e7a6b92eb483b179d5d42 Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Sun, 17 Jul 2016 16:03:58 +0200 Subject: docs: added UBX to list of calibratable daughterboards --- host/docs/calibration.dox | 1 + 1 file changed, 1 insertion(+) diff --git a/host/docs/calibration.dox b/host/docs/calibration.dox index 02ad41699..b4454aa24 100644 --- a/host/docs/calibration.dox +++ b/host/docs/calibration.dox @@ -33,6 +33,7 @@ utilities: - WBX Series transceiver boards - SBX Series transceiver boards - CBX Series transceiver boards +- UBX Series transceiver boards \subsection calibration_self_utils Calibration Utilities -- cgit v1.2.3 From 39127b6e4cd5e8d1fc4f27c0ef7d002545f4cf8d Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 27 Jul 2016 10:30:56 -0700 Subject: usrp_e3x0.dox: Example cmake line should enable GPSD for E310. (#1170) Signed-off-by: Philip Balister --- host/docs/usrp_e3x0.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/docs/usrp_e3x0.dox b/host/docs/usrp_e3x0.dox index 1a94e6c7e..fdaea80e2 100644 --- a/host/docs/usrp_e3x0.dox +++ b/host/docs/usrp_e3x0.dox @@ -135,7 +135,7 @@ have custom UHD modifications. -# Setup your environment as described in \ref e3x0_sdk_usage -# Type the following in the build directory (assuming a build in host/build): - $ cmake -DCMAKE_TOOLCHAIN_FILE=../host/cmake/Toolchains/oe-sdk_cross.cmake -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_E300=ON .. + $ cmake -DCMAKE_TOOLCHAIN_FILE=../host/cmake/Toolchains/oe-sdk_cross.cmake -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_E300=ON -DENABLE_GPSD=ON .. $ make For instructions on building UHD on a PC to interact with your E-Series device, follow these instructions: \ref e3x0_uhd_build -- cgit v1.2.3 From 2bf61143605a075583def1038fdcbb9e62f4c244 Mon Sep 17 00:00:00 2001 From: michael-west Date: Thu, 14 Jul 2016 16:29:53 -0700 Subject: WBX: Make frequencies <100 MHz work for v2 and v3 boards when reference clock <100 MHz (i.e. on X300) --- host/lib/usrp/dboard/db_wbx_version2.cpp | 17 ++++++++++------- host/lib/usrp/dboard/db_wbx_version3.cpp | 21 ++++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/host/lib/usrp/dboard/db_wbx_version2.cpp b/host/lib/usrp/dboard/db_wbx_version2.cpp index 93047fb7a..03c8f37e9 100644 --- a/host/lib/usrp/dboard/db_wbx_version2.cpp +++ b/host/lib/usrp/dboard/db_wbx_version2.cpp @@ -196,10 +196,9 @@ double wbx_base::wbx_version2::set_lo_freq(dboard_iface::unit_t unit, double tar double reference_freq = self_base->get_iface()->get_clock_rate(unit); //The mixer has a divide-by-2 stage on the LO port so the synthesizer - //frequency must 2x the target frequency + //frequency must 2x the target frequency. This introduces a 180 degree + //phase ambiguity double synth_target_freq = target_freq * 2; - //TODO: Document why the following has to be true - bool div_resync_enabled = (target_freq > reference_freq); adf4350_regs_t::prescaler_t prescaler = synth_target_freq > 3e9 ? adf4350_regs_t::PRESCALER_8_9 : adf4350_regs_t::PRESCALER_4_5; @@ -211,9 +210,13 @@ double wbx_base::wbx_version2::set_lo_freq(dboard_iface::unit_t unit, double tar tuning_constraints.int_range = uhd::range_t(prescaler_to_min_int_div[prescaler], 4095); tuning_constraints.pfd_freq_max = 25e6; tuning_constraints.rf_divider_range = uhd::range_t(1, 16); - //When divider resync is enabled, a 180 deg phase error is introduced when syncing - //multiple WBX boards. Switching to fundamental mode works arounds this issue. - tuning_constraints.feedback_after_divider = div_resync_enabled; + //The feedback of the divided frequency must be disabled whenever the target frequency + //divided by the minimum PFD frequency cannot meet the minimum integer divider (N) value. + //If it is disabled, additional phase ambiguity will be introduced. With a minimum PFD + //frequency of 10 MHz, synthesizer frequencies below 230 MHz (LO frequencies below 115 MHz) + //will have too much ambiguity to synchronize. + tuning_constraints.feedback_after_divider = + (int(synth_target_freq / 10e6) >= prescaler_to_min_int_div[prescaler]); double synth_actual_freq = 0; adf435x_tuning_settings tuning_settings = tune_adf435x_synth( @@ -240,7 +243,7 @@ double wbx_base::wbx_version2::set_lo_freq(dboard_iface::unit_t unit, double tar regs.feedback_select = tuning_constraints.feedback_after_divider ? adf4350_regs_t::FEEDBACK_SELECT_DIVIDED : adf4350_regs_t::FEEDBACK_SELECT_FUNDAMENTAL; - regs.clock_div_mode = div_resync_enabled ? + regs.clock_div_mode = tuning_constraints.feedback_after_divider ? adf4350_regs_t::CLOCK_DIV_MODE_RESYNC_ENABLE : adf4350_regs_t::CLOCK_DIV_MODE_FAST_LOCK; regs.prescaler = prescaler; diff --git a/host/lib/usrp/dboard/db_wbx_version3.cpp b/host/lib/usrp/dboard/db_wbx_version3.cpp index 6927ae4e4..a559a7b14 100644 --- a/host/lib/usrp/dboard/db_wbx_version3.cpp +++ b/host/lib/usrp/dboard/db_wbx_version3.cpp @@ -62,7 +62,7 @@ static int tx_pga0_gain_to_iobits(double &gain){ (attn_code & 8 ? 0 : TX_ATTN_8) | (attn_code & 4 ? 0 : TX_ATTN_4) | (attn_code & 2 ? 0 : TX_ATTN_2) | - (attn_code & 1 ? 0 : TX_ATTN_1) + (attn_code & 1 ? 0 : TX_ATTN_1) ) & TX_ATTN_MASK; UHD_LOGV(often) << boost::format( @@ -227,14 +227,13 @@ double wbx_base::wbx_version3::set_lo_freq(dboard_iface::unit_t unit, double tar double reference_freq = self_base->get_iface()->get_clock_rate(unit); //The mixer has a divide-by-2 stage on the LO port so the synthesizer - //frequency must 2x the target frequency + //frequency must 2x the target frequency. This introduces a 180 degree + //phase ambiguity double synth_target_freq = target_freq * 2; - //TODO: Document why the following has to be true - bool div_resync_enabled = (target_freq > reference_freq); adf4350_regs_t::prescaler_t prescaler = synth_target_freq > 3e9 ? adf4350_regs_t::PRESCALER_8_9 : adf4350_regs_t::PRESCALER_4_5; - + adf435x_tuning_constraints tuning_constraints; tuning_constraints.force_frac0 = is_int_n; tuning_constraints.band_sel_freq_max = 100e3; @@ -242,9 +241,13 @@ double wbx_base::wbx_version3::set_lo_freq(dboard_iface::unit_t unit, double tar tuning_constraints.int_range = uhd::range_t(prescaler_to_min_int_div[prescaler], 4095); tuning_constraints.pfd_freq_max = 25e6; tuning_constraints.rf_divider_range = uhd::range_t(1, 16); - //When divider resync is enabled, a 180 deg phase error is introduced when syncing - //multiple WBX boards. Switching to fundamental mode works arounds this issue. - tuning_constraints.feedback_after_divider = div_resync_enabled; + //The feedback of the divided frequency must be disabled whenever the target frequency + //divided by the minimum PFD frequency cannot meet the minimum integer divider (N) value. + //If it is disabled, additional phase ambiguity will be introduced. With a minimum PFD + //frequency of 10 MHz, synthesizer frequencies below 230 MHz (LO frequencies below 115 MHz) + //will have too much ambiguity to synchronize. + tuning_constraints.feedback_after_divider = + (int(synth_target_freq / 10e6) >= prescaler_to_min_int_div[prescaler]); double synth_actual_freq = 0; adf435x_tuning_settings tuning_settings = tune_adf435x_synth( @@ -271,7 +274,7 @@ double wbx_base::wbx_version3::set_lo_freq(dboard_iface::unit_t unit, double tar regs.feedback_select = tuning_constraints.feedback_after_divider ? adf4350_regs_t::FEEDBACK_SELECT_DIVIDED : adf4350_regs_t::FEEDBACK_SELECT_FUNDAMENTAL; - regs.clock_div_mode = div_resync_enabled ? + regs.clock_div_mode = tuning_constraints.feedback_after_divider ? adf4350_regs_t::CLOCK_DIV_MODE_RESYNC_ENABLE : adf4350_regs_t::CLOCK_DIV_MODE_FAST_LOCK; regs.prescaler = prescaler; -- cgit v1.2.3 From 4503c7e6287e4204af946c9aa6e669f76c9b8289 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 29 Jun 2016 15:30:43 -0700 Subject: cmake: "make uninstall" now removes symlinks (CMake 2.8.1 and above) --- host/cmake/cmake_uninstall.cmake.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/host/cmake/cmake_uninstall.cmake.in b/host/cmake/cmake_uninstall.cmake.in index 6031a6ca9..b4d731a14 100644 --- a/host/cmake/cmake_uninstall.cmake.in +++ b/host/cmake/cmake_uninstall.cmake.in @@ -17,6 +17,17 @@ FOREACH(file ${files}) IF(NOT "${rm_retval}" STREQUAL 0) MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") ENDIF(NOT "${rm_retval}" STREQUAL 0) + ELSEIF(NOT "${CMAKE_VERSION}" STRLESS "2.8.1") + IF(IS_SYMLINK "$ENV{DESTDIR}${file}") + EXEC_PROGRAM( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + IF(NOT "${rm_retval}" STREQUAL 0) + MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + ENDIF(NOT "${rm_retval}" STREQUAL 0) + ENDIF(IS_SYMLINK "$ENV{DESTDIR}${file}") ELSE(EXISTS "$ENV{DESTDIR}${file}") MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") ENDIF(EXISTS "$ENV{DESTDIR}${file}") -- cgit v1.2.3