diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-11 11:18:50 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-11 11:18:50 -0700 |
commit | 9503c5101007ba1261b8d23ee6a17305bbaa6f2a (patch) | |
tree | 1bd68ede7048f2199eeffdb5f700dd53e26f8f78 /host | |
parent | e581e0af0ab0387b03e20c5eadec157bcbb777ca (diff) | |
parent | 9e419c7b7f35062ceb2ed4e508cadb163067593f (diff) | |
download | uhd-9503c5101007ba1261b8d23ee6a17305bbaa6f2a.tar.gz uhd-9503c5101007ba1261b8d23ee6a17305bbaa6f2a.tar.bz2 uhd-9503c5101007ba1261b8d23ee6a17305bbaa6f2a.zip |
Merge branch 'changes'
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 6 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 24 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_regs.hpp | 1 | ||||
-rwxr-xr-x | host/utils/usrp2_card_burner.py | 40 | ||||
-rwxr-xr-x | host/utils/usrp2_card_burner_gui.py | 4 |
6 files changed, 54 insertions, 23 deletions
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index c4dabf5bc..a781c1a21 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -32,9 +32,9 @@ extern "C" { #define __stdint(type) type #endif -//defines the protocol version in this shared header -//increment this value when the protocol is changed -#define USRP2_PROTO_VERSION 5 +//fpga and firmware compatibility numbers +#define USRP2_FPGA_COMPAT_NUM 1 +#define USRP2_FW_COMPAT_NUM 5 //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index a21157d76..4124221ef 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "usrp2_regs.hpp" #include "usrp2_iface.hpp" #include <uhd/utils/assert.hpp> #include <uhd/types/dict.hpp> @@ -22,6 +23,7 @@ #include <boost/foreach.hpp> #include <boost/asio.hpp> //used for htonl and ntohl #include <boost/assign/list_of.hpp> +#include <boost/format.hpp> #include <stdexcept> #include <algorithm> @@ -47,6 +49,15 @@ public: **********************************************************************/ usrp2_iface_impl(udp_simple::sptr ctrl_transport){ _ctrl_transport = ctrl_transport; + + //check the fpga compatibility number + const boost::uint32_t fpga_compat_num = this->peek32(U2_REG_COMPAT_NUM_RB); + if (fpga_compat_num != USRP2_FPGA_COMPAT_NUM){ + throw std::runtime_error(str(boost::format( + "Expected fpga compatibility number %d, but got %d:\n" + "The fpga build is not compatible with the host code build." + ) % int(USRP2_FPGA_COMPAT_NUM) % fpga_compat_num)); + } } ~usrp2_iface_impl(void){ @@ -168,7 +179,7 @@ public: //fill in the seq number and send usrp2_ctrl_data_t out_copy = out_data; - out_copy.proto_ver = htonl(USRP2_PROTO_VERSION); + out_copy.proto_ver = htonl(USRP2_FW_COMPAT_NUM); out_copy.seq = htonl(++_ctrl_seq_num); _ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t))); @@ -177,12 +188,11 @@ public: const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem); while(true){ size_t len = _ctrl_transport->recv(boost::asio::buffer(usrp2_ctrl_data_in_mem), CONTROL_TIMEOUT_MS); - if(len >= sizeof(boost::uint32_t) and ntohl(ctrl_data_in->proto_ver) != USRP2_PROTO_VERSION){ - throw std::runtime_error(str( - boost::format("Expected protocol version %d, but got %d\n" - "The firmware build does not match the host code build." - ) % int(USRP2_PROTO_VERSION) % ntohl(ctrl_data_in->proto_ver) - )); + if(len >= sizeof(boost::uint32_t) and ntohl(ctrl_data_in->proto_ver) != USRP2_FW_COMPAT_NUM){ + throw std::runtime_error(str(boost::format( + "Expected protocol compatibility number %d, but got %d:\n" + "The firmware build is not compatible with the host code build." + ) % int(USRP2_FW_COMPAT_NUM) % ntohl(ctrl_data_in->proto_ver))); } if (len >= sizeof(usrp2_ctrl_data_t) and ntohl(ctrl_data_in->seq) == _ctrl_seq_num){ return *ctrl_data_in; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 2c314c085..21f411afe 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -97,7 +97,7 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ //send a hello control packet usrp2_ctrl_data_t ctrl_data_out; - ctrl_data_out.proto_ver = htonl(USRP2_PROTO_VERSION); + ctrl_data_out.proto_ver = htonl(USRP2_FW_COMPAT_NUM); ctrl_data_out.id = htonl(USRP2_CTRL_ID_WAZZUP_BRO); udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index cc9094ae7..9d306090b 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -107,6 +107,7 @@ #define U2_REG_TIME64_SECS_RB (0xCC00 + 4*10) #define U2_REG_TIME64_TICKS_RB (0xCC00 + 4*11) +#define U2_REG_COMPAT_NUM_RB (0xCC00 + 4*12) //pps flags (see above) #define U2_FLAG_TIME64_PPS_NEGEDGE (0 << 0) diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py index d47a4f5f4..1db5e59ce 100755 --- a/host/utils/usrp2_card_burner.py +++ b/host/utils/usrp2_card_burner.py @@ -21,6 +21,7 @@ import tempfile import subprocess import urllib import optparse +import math import os import re @@ -59,6 +60,14 @@ def get_dd_path(): return dd_path return 'dd' +def int_ceil_div(num, den): + return int(math.ceil(float(num)/float(den))) + +def get_tmp_file(): + tmp = tempfile.mkstemp() + os.close(tmp[0]) + return tmp[1] + ######################################################################## # list possible devices ######################################################################## @@ -136,10 +145,12 @@ def get_raw_device_hints(): # write and verify with dd ######################################################################## def verify_image(image_file, device_file, offset): - #create a temporary file to store the readback - tmp = tempfile.mkstemp() - os.close(tmp[0]) - tmp_file = tmp[1] + #create a temporary file to store the readback image + tmp_file = get_tmp_file() + + #read the image data + img_data = open(image_file, 'rb').read() + count = int_ceil_div(len(img_data), SECTOR_SIZE) #execute a dd subprocess verbose = command( @@ -148,24 +159,33 @@ def verify_image(image_file, device_file, offset): "if=%s"%device_file, "skip=%d"%(offset/SECTOR_SIZE), "bs=%d"%SECTOR_SIZE, - "count=%d"%(MAX_FILE_SIZE/SECTOR_SIZE), + "count=%d"%count, ) - #read in the image and readback - img_data = open(image_file, 'rb').read() - tmp_data = open(tmp_file, 'rb').read(len(img_data)) - #verfy the data + tmp_data = open(tmp_file, 'rb').read(len(img_data)) if img_data != tmp_data: return 'Verification Failed:\n%s'%verbose return 'Verification Passed:\n%s'%verbose def write_image(image_file, device_file, offset): + #create a temporary file to store the padded image + tmp_file = get_tmp_file() + + #write the padded image data + img_data = open(image_file, 'rb').read() + count = int_ceil_div(len(img_data), SECTOR_SIZE) + pad_len = SECTOR_SIZE*count - len(img_data) + pad_str = ''.join([chr(0)]*pad_len) #zero-padding + open(tmp_file, 'wb').write(img_data + pad_str) + + #execute a dd subprocess verbose = command( get_dd_path(), - "if=%s"%image_file, + "if=%s"%tmp_file, "of=%s"%device_file, "seek=%d"%(offset/SECTOR_SIZE), "bs=%d"%SECTOR_SIZE, + "count=%d"%count, ) try: #exec the sync command (only works on linux) diff --git a/host/utils/usrp2_card_burner_gui.py b/host/utils/usrp2_card_burner_gui.py index 61fbadbe3..58b7a514a 100755 --- a/host/utils/usrp2_card_burner_gui.py +++ b/host/utils/usrp2_card_burner_gui.py @@ -17,7 +17,7 @@ # import usrp2_card_burner #import implementation -import Tkinter, Tkconstants, tkFileDialog, tkFont, tkMessageBox +import Tkinter, tkFileDialog, tkFont, tkMessageBox import os class BinFileEntry(Tkinter.Frame): @@ -53,7 +53,7 @@ class BinFileEntry(Tkinter.Frame): class DeviceEntryWidget(Tkinter.Frame): """ - Simple entry widget for getting the raw device name. + Simple entry widget for getting the raw device name. Combines a label, entry, and helpful text box with hints. """ |