diff options
author | Martin Braun <martin.braun@ettus.com> | 2016-06-17 14:35:17 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2016-06-17 14:35:17 -0700 |
commit | f693349f12a66cfad2159779757e2ea1d6d483be (patch) | |
tree | 1c335011ec094ab03b3faaf892792b60ed3b80c4 /host/lib/usrp_clock | |
parent | e103b5e67061c9b22cce2e36cf9b40a8213ecb82 (diff) | |
parent | 9cc4e16b77d074c8d416725ead1afb8898007eb3 (diff) | |
download | uhd-f693349f12a66cfad2159779757e2ea1d6d483be.tar.gz uhd-f693349f12a66cfad2159779757e2ea1d6d483be.tar.bz2 uhd-f693349f12a66cfad2159779757e2ea1d6d483be.zip |
Merge branch 'maint'
Diffstat (limited to 'host/lib/usrp_clock')
-rw-r--r-- | host/lib/usrp_clock/octoclock/common.h | 5 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp | 42 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_impl.cpp | 25 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_uart.cpp | 15 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_uart.hpp | 3 |
6 files changed, 64 insertions, 34 deletions
diff --git a/host/lib/usrp_clock/octoclock/common.h b/host/lib/usrp_clock/octoclock/common.h index 89fec9ce5..191b93d36 100644 --- a/host/lib/usrp_clock/octoclock/common.h +++ b/host/lib/usrp_clock/octoclock/common.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 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 @@ -46,7 +46,8 @@ extern "C" { // These values are placed in the octoclock_packet_t.proto_ver field #define OCTOCLOCK_BOOTLOADER_PROTO_VER 1234 -#define OCTOCLOCK_FW_COMPAT_NUM 3 +#define OCTOCLOCK_FW_MIN_COMPAT_NUM 2 +#define OCTOCLOCK_FW_COMPAT_NUM 4 // UDP ports assigned for different tasks #define OCTOCLOCK_UDP_CTRL_PORT 50000 diff --git a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp index 49d1a0442..8ac38011d 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2014-2015 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 @@ -46,7 +46,8 @@ void octoclock_eeprom_t::_load(){ const octoclock_fw_eeprom_t *eeprom_in = reinterpret_cast<const octoclock_fw_eeprom_t*>(pkt_in->data); octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + 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); @@ -94,7 +95,8 @@ void octoclock_eeprom_t::_store() const { const octoclock_packet_t *pkt_in = reinterpret_cast<const octoclock_packet_t *>(octoclock_data); octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + pkt_out.sequence = boost::uint32_t(std::rand()); pkt_out.len = sizeof(octoclock_fw_eeprom_t); size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp index fdb254024..e12256c15 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp @@ -1,5 +1,5 @@ // -// Copyright 2015 Ettus Research LLC +// Copyright 2015-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 @@ -59,9 +59,11 @@ typedef struct { std::string image_filepath; boost::uint16_t crc; boost::uint16_t num_blocks; + boost::uint32_t sequence; udp_simple::sptr ctrl_xport; udp_simple::sptr fw_xport; boost::uint8_t data_in[udp_simple::mtu]; + boost::uint32_t starting_firmware_version; std::vector<boost::uint8_t> image; } octoclock_session_t; @@ -169,6 +171,19 @@ static void octoclock_setup_session(octoclock_session_t &session, BOOST_STRINGIZE(OCTOCLOCK_UDP_CTRL_PORT)); session.fw_xport = udp_simple::make_connected(session.dev_addr["addr"], BOOST_STRINGIZE(OCTOCLOCK_UDP_FW_PORT)); + // To avoid replicating sequence numbers between sessions + session.sequence = boost::uint32_t(std::rand()); + + // Query OctoClock again to get compat number + octoclock_packet_t pkt_out; + const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); + size_t len = 0; + UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, 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<boost::uint32_t>(pkt_in->proto_ver); + } else { + throw uhd::runtime_error("Failed to communicate with OctoClock."); + } } static void octoclock_reset_into_bootloader(octoclock_session_t &session){ @@ -177,15 +192,18 @@ static void octoclock_reset_into_bootloader(octoclock_session_t &session){ if(session.dev_addr["type"] == "octoclock-bootloader") return; + // Force compat num to device's current, works around old firmware bug octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); - const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); - size_t len; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); + pkt_out.proto_ver = uhd::htonx<boost::uint32_t>(session.starting_firmware_version); + pkt_out.code = RESET_CMD; std::cout << " -- Resetting into bootloader..." << std::flush; - UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, RESET_CMD, pkt_out, len, session.data_in); - if(UHD_OCTOCLOCK_PACKET_MATCHES(RESET_ACK, pkt_out, pkt_in, len)){ + session.ctrl_xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \ + size_t len = session.ctrl_xport->recv(boost::asio::buffer(session.data_in), 2);\ + const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); + if(UHD_OCTOCLOCK_PACKET_MATCHES(RESET_ACK, pkt_out, pkt_in, len)){ // Make sure this device is now in its bootloader boost::this_thread::sleep(boost::posix_time::milliseconds(500)); uhd::device_addrs_t octoclocks = uhd::device::find( @@ -217,7 +235,7 @@ static void octoclock_burn(octoclock_session_t &session){ octoclock_reset_into_bootloader(session); octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); // Tell OctoClock to prepare for burn @@ -237,7 +255,7 @@ static void octoclock_burn(octoclock_session_t &session){ // Start burning for(size_t i = 0; i < session.num_blocks; i++){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); pkt_out.addr = i * OCTOCLOCK_BLOCK_SIZE; std::cout << str(boost::format("\r -- Loading firmware: %d%% (%d/%d blocks)") @@ -260,16 +278,16 @@ static void octoclock_burn(octoclock_session_t &session){ } static void octoclock_verify(octoclock_session_t &session){ - + octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; boost::uint8_t image_part[OCTOCLOCK_BLOCK_SIZE]; boost::uint16_t cmp_len = 0; for(size_t i = 0; i < session.num_blocks; i++){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); pkt_out.addr = i * OCTOCLOCK_BLOCK_SIZE; std::cout << str(boost::format("\r -- Verifying firmware load: %d%% (%d/%d blocks)") @@ -302,7 +320,7 @@ static void octoclock_verify(octoclock_session_t &session){ static void octoclock_finalize(octoclock_session_t &session){ octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp index 94e8b05d8..7ca83ddb1 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp @@ -110,7 +110,8 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ //Send a query packet octoclock_packet_t pkt_out; pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + pkt_out.sequence = boost::uint32_t(std::rand()); pkt_out.len = 0; pkt_out.code = OCTOCLOCK_QUERY_CMD; try{ @@ -144,12 +145,17 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ new_addr["type"] = "octoclock-bootloader"; octoclock_addrs.push_back(new_addr); } - else{ + else { new_addr["type"] = "octoclock"; - octoclock_eeprom_t oc_eeprom(ctrl_xport); - new_addr["name"] = oc_eeprom["name"]; - new_addr["serial"] = oc_eeprom["serial"]; + 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); + new_addr["name"] = oc_eeprom["name"]; + new_addr["serial"] = oc_eeprom["serial"]; + } else { + new_addr["name"] = ""; + new_addr["serial"] = ""; + } //Filter based on optional keys (if any) if( @@ -184,7 +190,8 @@ octoclock_impl::octoclock_impl(const device_addr_t &_device_addr){ UHD_MSG(status) << "Opening an OctoClock device..." << std::endl; _type = device::CLOCK; device_addrs_t device_args = separate_device_addr(_device_addr); - _sequence = std::rand(); + // To avoid replicating sequence numbers between sessions + _sequence = boost::uint32_t(std::rand()); //////////////////////////////////////////////////////////////////// // Initialize the property tree @@ -220,7 +227,7 @@ 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_COMPAT_NUM){ + if(fw_version < OCTOCLOCK_FW_MIN_COMPAT_NUM or fw_version > 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" @@ -325,7 +332,7 @@ void octoclock_impl::_set_eeprom(const std::string &oc, const octoclock_eeprom_t boost::uint32_t octoclock_impl::_get_fw_version(const std::string &oc){ octoclock_packet_t pkt_out; - pkt_out.sequence = _sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = 0; size_t len; @@ -341,7 +348,7 @@ boost::uint32_t octoclock_impl::_get_fw_version(const std::string &oc){ void octoclock_impl::_get_state(const std::string &oc){ octoclock_packet_t pkt_out; - pkt_out.sequence = _sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = 0; size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp index f366bac30..e0a9f08cf 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp @@ -1,5 +1,5 @@ // -// Copyright 2014-2015 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 @@ -47,11 +47,13 @@ namespace uhd{ _state.pos = 0; _device_state.num_wraps = 0; _device_state.pos = 0; + // To avoid replicating sequence numbers between sessions + _sequence = boost::uint32_t(std::rand()); size_t len = 0; //Get pool size from device octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint16_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(_sequence); pkt_out.len = 0; boost::uint8_t octoclock_data[udp_simple::mtu]; @@ -70,7 +72,7 @@ namespace uhd{ size_t len = 0; octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = to_send.size(); memcpy(pkt_out.data, to_send.c_str(), to_send.size()); @@ -111,14 +113,13 @@ namespace uhd{ void octoclock_uart_iface::_update_cache(){ octoclock_packet_t pkt_out; pkt_out.len = 0; - pkt_out.sequence = 0; size_t len = 0; boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast<octoclock_packet_t*>(octoclock_data); if(STATES_EQUAL or LOCAL_STATE_AHEAD){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); UHD_OCTOCLOCK_SEND_AND_RECV(_udp, 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); @@ -137,7 +138,7 @@ namespace uhd{ //We may have wrapped around locally if(_state.pos == 0) _state.num_wraps++; } - _state.pos = (_state.pos+1) % _poolsize; + if (_cache[_state.pos] == '\n') _state.pos = (_state.pos+1) % _poolsize; //We may have wrapped around locally if(_state.pos == 0) _state.num_wraps++; } @@ -145,7 +146,7 @@ namespace uhd{ } char octoclock_uart_iface::_getchar(){ - if(LOCAL_STATE_AHEAD){ + if(STATES_EQUAL or LOCAL_STATE_AHEAD){ return 0; } diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp index 05d1bb121..d7a77288f 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.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 @@ -45,6 +45,7 @@ private: gpsdo_cache_state_t _device_state; std::vector<boost::uint8_t> _cache; std::string _rxbuff; + boost::uint32_t _sequence; void _update_cache(); char _getchar(); |