diff options
-rw-r--r-- | firmware/microblaze/apps/txrx.c | 34 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 21 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 1 |
4 files changed, 55 insertions, 9 deletions
diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 2e13a99d0..d2497892b 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -201,20 +201,34 @@ void handle_udp_ctrl_packet( unsigned char *payload, int payload_len ){ //printf("Got ctrl packet #words: %d\n", (int)payload_len); + usrp2_ctrl_data_t *ctrl_data_in = (usrp2_ctrl_data_t *)payload; + uint32_t ctrl_data_in_id = ctrl_data_in->id; + + //ensure that the protocol versions match + if (payload_len >= sizeof(uint32_t) && ctrl_data_in->proto_ver != USRP2_PROTO_VERSION){ + printf("!Error in control packet handler: Expected protocol version %d, but got %d\n", + USRP2_PROTO_VERSION, ctrl_data_in->proto_ver + ); + ctrl_data_in_id = USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO; + } + + //ensure that this is not a short packet if (payload_len < sizeof(usrp2_ctrl_data_t)){ - //TODO send err packet - return; + printf("!Error in control packet handler: Expected payload length %d, but got %d\n", + (int)sizeof(usrp2_ctrl_data_t), payload_len + ); + ctrl_data_in_id = USRP2_CTRL_ID_HUH_WHAT; } - //setup the input and output data - usrp2_ctrl_data_t *ctrl_data_in = (usrp2_ctrl_data_t *)payload; + //setup the output data usrp2_ctrl_data_t ctrl_data_out = { + .proto_ver = USRP2_PROTO_VERSION, .id=USRP2_CTRL_ID_HUH_WHAT, .seq=ctrl_data_in->seq }; //handle the data based on the id - switch(ctrl_data_in->id){ + switch(ctrl_data_in_id){ /******************************************************************* * Addressing @@ -400,6 +414,15 @@ void handle_udp_ctrl_packet( ctrl_data_out.id = USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE; break; + /******************************************************************* + * Hardware Rev Numbers + ******************************************************************/ + case USRP2_CTRL_ID_WHATS_THE_HARDWARE_REV_NOS_BRO: + ctrl_data_out.data.hw_rev.major = u2_hw_rev_major; + ctrl_data_out.data.hw_rev.minor = u2_hw_rev_minor; + ctrl_data_out.id = USRP2_CTRL_ID_TAKE_THE_HARDWARE_REV_NOS_DUDE; + break; + default: ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT; @@ -572,6 +595,7 @@ main(void) print_mac_addr(ethernet_mac_addr()->addr); newline(); print_ip_addr(get_ip_addr()); newline(); + printf("Control protocol version: %d\n", USRP2_PROTO_VERSION); ethernet_register_link_changed_callback(link_changed_callback); ethernet_init(); diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index b25316217..640b37ec6 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -32,6 +32,10 @@ extern "C" { #define _SINS_ #endif +//defines the protocol version in this shared header +//increment this value when the protocol is changed +#define USRP2_PROTO_VERSION 1 + //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 @@ -78,21 +82,25 @@ typedef enum{ USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r', USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R', + USRP2_CTRL_ID_WHATS_THE_HARDWARE_REV_NOS_BRO = 'y', + USRP2_CTRL_ID_TAKE_THE_HARDWARE_REV_NOS_DUDE = 'Y', + USRP2_CTRL_ID_PEACE_OUT = '~' } usrp2_ctrl_id_t; typedef enum{ - USRP2_DIR_RX, - USRP2_DIR_TX + USRP2_DIR_RX = 'r', + USRP2_DIR_TX = 't' } usrp2_dir_which_t; typedef enum{ - USRP2_CLK_EDGE_RISE, - USRP2_CLK_EDGE_FALL + USRP2_CLK_EDGE_RISE = 'r', + USRP2_CLK_EDGE_FALL = 'f' } usrp2_clk_edge_t; typedef struct{ + _SINS_ uint32_t proto_ver; _SINS_ uint32_t id; _SINS_ uint32_t seq; union{ @@ -129,6 +137,11 @@ typedef struct{ _SINS_ uint32_t data; _SINS_ uint8_t num_bytes; //1, 2, 4 } poke_args; + struct { + _SINS_ uint8_t major; + _SINS_ uint8_t minor; + _SINS_ uint8_t _pad[2]; + } hw_rev; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 742c53a14..1b0dde1b4 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -97,6 +97,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.seq = htonl(++_ctrl_seq_num); _ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t))); @@ -104,6 +105,13 @@ public: while(true){ usrp2_ctrl_data_t in_data; size_t len = _ctrl_transport->recv(boost::asio::buffer(&in_data, sizeof(in_data))); + if(len >= sizeof(boost::uint32_t) and ntohl(in_data.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(in_data.proto_ver) + )); + } if (len >= sizeof(usrp2_ctrl_data_t) and ntohl(in_data.seq) == _ctrl_seq_num){ return in_data; } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 3bdc5bd02..0fa56c339 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -70,6 +70,7 @@ 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.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO); udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); |