From bd59192bd4eceaf86b60d91651e6b0bf11c2274e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 21 Oct 2010 12:27:49 -0700 Subject: usrp2: handle real overflow packets in host, reload continuous stream cmd, remove firmware handling --- firmware/microblaze/apps/txrx_uhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'firmware/microblaze') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 1dd6e80ac..dd43059a3 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -536,7 +536,7 @@ main(void) } if (pending & PIC_OVERRUN_INT){ - dbsm_handle_rx_overrun(&dsp_rx_sm); + //dbsm_handle_rx_overrun(&dsp_rx_sm); pic_regs->pending = PIC_OVERRUN_INT; // clear pending interrupt // FIXME Figure out how to handle this robustly. -- cgit v1.2.3 From 8a695c06848dfd254d372e661aa00c2c8d6184a1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 22 Oct 2010 11:05:27 -0700 Subject: usrp2: fw sends gratuitous arp on link-up --- firmware/microblaze/apps/txrx_uhd.c | 10 ++- firmware/microblaze/lib/Makefile.inc | 1 + firmware/microblaze/lib/eth_addrs.c | 119 ++++++++++++++++++++++++++++++++++ firmware/microblaze/lib/net_common.c | 16 +++++ firmware/microblaze/lib/net_common.h | 2 + firmware/microblaze/usrp2/Makefile.am | 3 +- firmware/microblaze/usrp2/ethernet.c | 99 ---------------------------- 7 files changed, 147 insertions(+), 103 deletions(-) create mode 100644 firmware/microblaze/lib/eth_addrs.c (limited to 'firmware/microblaze') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 1dd6e80ac..098542bc8 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -422,6 +422,7 @@ link_changed_callback(int speed) link_is_up = speed != 0; hal_set_leds(link_is_up ? LED_RJ45 : 0x0, LED_RJ45); printf("\neth link changed: speed = %d\n", speed); + if (link_is_up) send_gratuitous_arp(); } static void setup_network(void){ @@ -479,15 +480,18 @@ main(void) printf("FPGA compatibility number: %d\n", USRP2_FPGA_COMPAT_NUM); printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM); - ethernet_register_link_changed_callback(link_changed_callback); - ethernet_init(); - + //1) register the addresses into the network stack register_mac_addr(ethernet_mac_addr()); register_ip_addr(get_ip_addr()); + //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); + //3) setup ethernet hardware to bring the link up + ethernet_register_link_changed_callback(link_changed_callback); + ethernet_init(); + // initialize double buffering state machine for ethernet -> DSP Tx dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0, diff --git a/firmware/microblaze/lib/Makefile.inc b/firmware/microblaze/lib/Makefile.inc index a576d1ccb..2b5685d3f 100644 --- a/firmware/microblaze/lib/Makefile.inc +++ b/firmware/microblaze/lib/Makefile.inc @@ -26,6 +26,7 @@ COMMON_SRCS = \ $(top_srcdir)/lib/clocks.c \ $(top_srcdir)/lib/dbsm.c \ $(top_srcdir)/lib/eeprom.c \ + $(top_srcdir)/lib/eth_addrs.c \ $(top_srcdir)/lib/eth_mac.c \ $(top_srcdir)/lib/_exit.c \ $(top_srcdir)/lib/exit.c \ diff --git a/firmware/microblaze/lib/eth_addrs.c b/firmware/microblaze/lib/eth_addrs.c new file mode 100644 index 000000000..d7c1e0394 --- /dev/null +++ b/firmware/microblaze/lib/eth_addrs.c @@ -0,0 +1,119 @@ +/* + * Copyright 2010 Ettus Research LLC + * Copyright 2007 Free Software Foundation, Inc. + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ethernet.h" +#include "memory_map.h" +#include "nonstdio.h" +#include +#include "i2c.h" +#include "usrp2/fw_common.h" + +static bool +unprogrammed(const void *t, size_t len) +{ + int i; + uint8_t *p = (uint8_t *)t; + bool all_zeros = true; + bool all_ones = true; + for (i = 0; i < len; i++){ + all_zeros &= p[i] == 0x00; + all_ones &= p[i] == 0xff; + } + return all_ones | all_zeros; +} + +//////////////////// MAC Addr Stuff /////////////////////// + +static int8_t src_mac_addr_initialized = false; +static eth_mac_addr_t src_mac_addr = {{ + 0x00, 0x50, 0xC2, 0x85, 0x3f, 0xff + }}; + +const eth_mac_addr_t * +ethernet_mac_addr(void) +{ + if (!src_mac_addr_initialized){ // fetch from eeprom + src_mac_addr_initialized = true; + + // if we're simulating, don't read the EEPROM model, it's REALLY slow + if (hwconfig_simulation_p()) + return &src_mac_addr; + + eth_mac_addr_t tmp; + bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, &tmp, sizeof(tmp)); + if (!ok || unprogrammed(&tmp, sizeof(tmp))){ + // use the default + } + else + src_mac_addr = tmp; + } + + return &src_mac_addr; +} + +bool +ethernet_set_mac_addr(const eth_mac_addr_t *t) +{ + bool ok = eeprom_write(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, t, sizeof(eth_mac_addr_t)); + if (ok){ + src_mac_addr = *t; + src_mac_addr_initialized = true; + //eth_mac_set_addr(t); //this breaks the link + } + + return ok; +} + +//////////////////// IP Addr Stuff /////////////////////// + +static int8_t src_ip_addr_initialized = false; +static struct ip_addr src_ip_addr = { + (192 << 24 | 168 << 16 | 10 << 8 | 2 << 0) +}; + + +const struct ip_addr *get_ip_addr(void) +{ + if (!src_ip_addr_initialized){ // fetch from eeprom + src_ip_addr_initialized = true; + + // if we're simulating, don't read the EEPROM model, it's REALLY slow + if (hwconfig_simulation_p()) + return &src_ip_addr; + + struct ip_addr tmp; + bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, &tmp, sizeof(tmp)); + if (!ok || unprogrammed(&tmp, sizeof(tmp))){ + // use the default + } + else + src_ip_addr = tmp; + } + + return &src_ip_addr; +} + +bool set_ip_addr(const struct ip_addr *t){ + bool ok = eeprom_write(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, t, sizeof(struct ip_addr)); + if (ok){ + src_ip_addr = *t; + src_ip_addr_initialized = true; + } + + return ok; +} diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 6c9509c92..beaaa5948 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -351,6 +351,22 @@ send_arp_reply(struct arp_eth_ipv4 *req, eth_mac_addr_t our_mac) send_pkt(t, ETHERTYPE_ARP, &reply, sizeof(reply), 0, 0, 0, 0); } +void send_gratuitous_arp(void){ + struct arp_eth_ipv4 req _AL4; + req.ar_hrd = ARPHRD_ETHER; + req.ar_pro = ETHERTYPE_IPV4; + req.ar_hln = sizeof(eth_mac_addr_t); + req.ar_pln = sizeof(struct ip_addr); + req.ar_op = ARPOP_REQUEST; + memcpy(req.ar_sha, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); + memcpy(req.ar_sip, get_ip_addr(), sizeof(struct ip_addr)); + memset(req.ar_tha, 0x00, sizeof(eth_mac_addr_t)); + memcpy(req.ar_tip, get_ip_addr(), sizeof(struct ip_addr)); + + //send the request with a broadcast ethernet mac address + eth_mac_addr_t t; memset(&t, 0xff, sizeof(t)); + send_pkt(t, ETHERTYPE_ARP, &req, sizeof(req), 0, 0, 0, 0); +} static void handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 112669b46..3040e5ef3 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -47,4 +47,6 @@ void send_udp_pkt(int src_port, struct socket_address dst, void handle_eth_packet(uint32_t *p, size_t nlines); +void send_gratuitous_arp(void); + #endif /* INCLUDED_NET_COMMON_H */ diff --git a/firmware/microblaze/usrp2/Makefile.am b/firmware/microblaze/usrp2/Makefile.am index 8da013980..ba426b75c 100644 --- a/firmware/microblaze/usrp2/Makefile.am +++ b/firmware/microblaze/usrp2/Makefile.am @@ -22,10 +22,11 @@ AM_CFLAGS = \ AM_LDFLAGS = \ $(COMMON_LFLAGS) \ - libusrp2.a \ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x0050 \ -Wl,-defsym -Wl,_STACK_SIZE=3072 +LDADD = libusrp2.a + ######################################################################## # USRP2 specific library and programs ######################################################################## diff --git a/firmware/microblaze/usrp2/ethernet.c b/firmware/microblaze/usrp2/ethernet.c index d60d7dc4c..5d4654bda 100644 --- a/firmware/microblaze/usrp2/ethernet.c +++ b/firmware/microblaze/usrp2/ethernet.c @@ -16,16 +16,12 @@ */ #include "ethernet.h" -#include "memory_map.h" #include "eth_phy.h" #include "eth_mac.h" #include "eth_mac_regs.h" #include "pic.h" #include "hal_io.h" #include "nonstdio.h" -#include -#include "i2c.h" -#include "usrp2/fw_common.h" #define VERBOSE 1 @@ -269,101 +265,6 @@ ethernet_init(void) eth_mac_miim_write(PHY_CTRL, t | MII_CR_RESTART_AUTO_NEG); } -static bool -unprogrammed(const void *t, size_t len) -{ - int i; - uint8_t *p = (uint8_t *)t; - bool all_zeros = true; - bool all_ones = true; - for (i = 0; i < len; i++){ - all_zeros &= p[i] == 0x00; - all_ones &= p[i] == 0xff; - } - return all_ones | all_zeros; -} - -//////////////////// MAC Addr Stuff /////////////////////// - -static int8_t src_mac_addr_initialized = false; -static eth_mac_addr_t src_mac_addr = {{ - 0x00, 0x50, 0xC2, 0x85, 0x3f, 0xff - }}; - -const eth_mac_addr_t * -ethernet_mac_addr(void) -{ - if (!src_mac_addr_initialized){ // fetch from eeprom - src_mac_addr_initialized = true; - - // if we're simulating, don't read the EEPROM model, it's REALLY slow - if (hwconfig_simulation_p()) - return &src_mac_addr; - - eth_mac_addr_t tmp; - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, &tmp, sizeof(tmp)); - if (!ok || unprogrammed(&tmp, sizeof(tmp))){ - // use the default - } - else - src_mac_addr = tmp; - } - - return &src_mac_addr; -} - -bool -ethernet_set_mac_addr(const eth_mac_addr_t *t) -{ - bool ok = eeprom_write(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, t, sizeof(eth_mac_addr_t)); - if (ok){ - src_mac_addr = *t; - src_mac_addr_initialized = true; - //eth_mac_set_addr(t); //this breaks the link - } - - return ok; -} - -//////////////////// IP Addr Stuff /////////////////////// - -static int8_t src_ip_addr_initialized = false; -static struct ip_addr src_ip_addr = { - (192 << 24 | 168 << 16 | 10 << 8 | 2 << 0) -}; - - -const struct ip_addr *get_ip_addr(void) -{ - if (!src_ip_addr_initialized){ // fetch from eeprom - src_ip_addr_initialized = true; - - // if we're simulating, don't read the EEPROM model, it's REALLY slow - if (hwconfig_simulation_p()) - return &src_ip_addr; - - struct ip_addr tmp; - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, &tmp, sizeof(tmp)); - if (!ok || unprogrammed(&tmp, sizeof(tmp))){ - // use the default - } - else - src_ip_addr = tmp; - } - - return &src_ip_addr; -} - -bool set_ip_addr(const struct ip_addr *t){ - bool ok = eeprom_write(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, t, sizeof(struct ip_addr)); - if (ok){ - src_ip_addr = *t; - src_ip_addr_initialized = true; - } - - return ok; -} - int ethernet_check_errors(void) { -- cgit v1.2.3 From c8cb4bcadc32e59e98fc2901eb94830f600d5d28 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Nov 2010 19:39:57 -0700 Subject: usrp2: implemented mboard eeprom into usrp2 mboard --- firmware/microblaze/lib/u2_init.c | 11 ---- firmware/microblaze/lib/u2_init.h | 3 -- host/include/uhd/usrp/mboard_eeprom.hpp | 23 ++++---- host/include/uhd/usrp/mboard_props.hpp | 3 +- host/lib/usrp/mboard_eeprom.cpp | 93 ++++++++++++++++++--------------- host/lib/usrp/usrp2/fw_common.h | 4 +- host/lib/usrp/usrp2/mboard_impl.cpp | 66 ++++++----------------- host/lib/usrp/usrp2/usrp2_impl.hpp | 15 +++--- 8 files changed, 87 insertions(+), 131 deletions(-) (limited to 'firmware/microblaze') diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 8d666b76b..c9b4beb2b 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -28,16 +28,6 @@ #include "usrp2/fw_common.h" #include "nonstdio.h" -unsigned char u2_hw_rev_major; -unsigned char u2_hw_rev_minor; - -static inline void -get_hw_rev(void) -{ - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_LSB, &u2_hw_rev_minor, 1); - ok &= eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, &u2_hw_rev_major, 1); -} - /* * We ought to arrange for this to be called before main, but for now, * we require that the user's main call u2_init as the first thing... @@ -60,7 +50,6 @@ u2_init(void) pic_init(); // progammable interrupt controller i2c_init(); hal_enable_ints(); - get_hw_rev(); bp_init(); // buffer pool diff --git a/firmware/microblaze/lib/u2_init.h b/firmware/microblaze/lib/u2_init.h index 334791189..848bd88de 100644 --- a/firmware/microblaze/lib/u2_init.h +++ b/firmware/microblaze/lib/u2_init.h @@ -20,9 +20,6 @@ #include -extern unsigned char u2_hw_rev_major; -extern unsigned char u2_hw_rev_minor; - /*! * one-time init */ diff --git a/host/include/uhd/usrp/mboard_eeprom.hpp b/host/include/uhd/usrp/mboard_eeprom.hpp index 0d57105b9..3bb05c0a8 100644 --- a/host/include/uhd/usrp/mboard_eeprom.hpp +++ b/host/include/uhd/usrp/mboard_eeprom.hpp @@ -21,24 +21,18 @@ #include #include #include -#include -#include #include namespace uhd{ namespace usrp{ /*! - * The motherboard EEPROM class: + * The motherboard EEPROM object: * Knows how to read and write the EEPROM for various USRPs. * The class inherits from a string, string dictionary. * Use the dictionary interface to get and set values. * Commit to the EEPROM to save changed settings. */ - class UHD_API mboard_eeprom_t: boost::noncopyable, - public uhd::dict - { - public: - typedef boost::shared_ptr sptr; + struct UHD_API mboard_eeprom_t : uhd::dict{ //! Possible EEPROM maps types enum map_type{ @@ -48,14 +42,17 @@ namespace uhd{ namespace usrp{ /*! * Make a new mboard EEPROM handler. - * \param map the map type enum * \param iface the interface to i2c - * \return a new mboard EEPROM object + * \param map the map type enum */ - static sptr make(map_type map, i2c_iface &iface); + mboard_eeprom_t(i2c_iface &iface, map_type map); - //! Write the contents of this object to the EEPROM. - virtual void commit(void) = 0; + /*! + * Write the contents of this object to the EEPROM. + * \param iface the interface to i2c + * \param map the map type enum + */ + void commit(i2c_iface &iface, map_type map); }; diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index 0f250f439..df94d1678 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -44,7 +44,8 @@ namespace uhd{ namespace usrp{ MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t MBOARD_PROP_TIME_NOW = 't', //rw, time_spec_t MBOARD_PROP_TIME_NEXT_PPS = 'T', //wo, time_spec_t - MBOARD_PROP_STREAM_CMD = 's' //wo, stream_cmd_t + MBOARD_PROP_STREAM_CMD = 's', //wo, stream_cmd_t + MBOARD_PROP_EEPROM_MAP = 'M' //wr, mboard_eeprom_t::sptr }; }} //namespace diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index d05be11e6..78b4122bb 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -67,8 +67,8 @@ static const uhd::dict USRP_NXXX_OFFSETS = boost::a ("mac-addr", 0x02) ("ip-addr", 0x02 + sizeof(mac_addr_t)) //leave space here for other addresses (perhaps) - ("name", 0x18) - ("serial", 0x18 + NAME_MAX_LEN) + ("serial", 0x18) + ("name", 0x18 + SERIAL_LEN) ; static void load_nxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ @@ -86,15 +86,15 @@ static void load_nxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ std::copy(iface.read_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], 4), ip_addr_bytes); mb_eeprom["ip-addr"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string(); - //extract the name - mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], NAME_MAX_LEN - )); - //extract the serial mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["serial"], SERIAL_LEN )); + + //extract the name + mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( + NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], NAME_MAX_LEN + )); } static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ @@ -116,61 +116,68 @@ static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ std::copy(boost::asio::ip::address_v4::from_string(mb_eeprom["ip-addr"]).to_bytes(), ip_addr_bytes); iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], ip_addr_bytes); - //store the name - iface.write_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], - string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) - ); - //store the serial iface.write_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["serial"], string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) ); + + //store the name + iface.write_eeprom( + NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], + string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) + ); } /*********************************************************************** * Implementation of BXXX load/store **********************************************************************/ -//TODO +static const boost::uint8_t BXXX_EEPROM_ADDR = 0x50; -static void load_bxxx(mboard_eeprom_t &, i2c_iface &){ - +static const uhd::dict USRP_BXXX_OFFSETS = boost::assign::map_list_of + ("serial", 0xf8) + ("name", 0xf8 + SERIAL_LEN) +; + +static void load_bxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ + //extract the serial + mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], SERIAL_LEN + )); + + //extract the name + mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["name"], NAME_MAX_LEN + )); } -static void store_bxxx(const mboard_eeprom_t &, i2c_iface &){ - +static void store_bxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ + //store the serial + iface.write_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], + string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) + ); + + //store the name + iface.write_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["name"], + string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) + ); } /*********************************************************************** * Implementation of mboard eeprom **********************************************************************/ -class mboard_eeprom_impl : public mboard_eeprom_t{ -public: - mboard_eeprom_impl(map_type map, i2c_iface &iface): - _map(map), _iface(iface) - { - switch(_map){ - case MAP_NXXX: load_nxxx(*this, _iface); break; - case MAP_BXXX: load_bxxx(*this, _iface); break; - } +mboard_eeprom_t::mboard_eeprom_t(i2c_iface &iface, map_type map){ + switch(map){ + case MAP_NXXX: load_nxxx(*this, iface); break; + case MAP_BXXX: load_bxxx(*this, iface); break; } +} - void commit(void){ - switch(_map){ - case MAP_NXXX: store_nxxx(*this, _iface); break; - case MAP_BXXX: store_bxxx(*this, _iface); break; - } +void mboard_eeprom_t::commit(i2c_iface &iface, map_type map){ + switch(map){ + case MAP_NXXX: store_nxxx(*this, iface); break; + case MAP_BXXX: store_bxxx(*this, iface); break; } - -private: - map_type _map; - i2c_iface &_iface; -}; - -/*********************************************************************** - * Factory function for mboard eeprom - **********************************************************************/ -mboard_eeprom_t::sptr mboard_eeprom_t::make(map_type map, i2c_iface &iface){ - return sptr(new mboard_eeprom_impl(map, iface)); } diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index e812e1221..4c46bbb1d 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -55,8 +55,8 @@ extern "C" { //////////////////////////////////////////////////////////////////////// // EEPROM Layout //////////////////////////////////////////////////////////////////////// -#define USRP2_EE_MBOARD_REV_LSB 0x00 //1 byte -#define USRP2_EE_MBOARD_REV_MSB 0x01 //1 byte +//#define USRP2_EE_MBOARD_REV_LSB 0x00 //1 byte +//#define USRP2_EE_MBOARD_REV_MSB 0x01 //1 byte #define USRP2_EE_MBOARD_MAC_ADDR 0x02 //6 bytes #define USRP2_EE_MBOARD_IP_ADDR 0x0C //uint32, big-endian diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index a0e6adfad..e7d8aeef6 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -22,11 +22,7 @@ #include #include #include -#include -#include #include -#include -#include #include using namespace uhd; @@ -41,15 +37,10 @@ usrp2_mboard_impl::usrp2_mboard_impl( size_t recv_frame_size ): _index(index), - _recv_frame_size(recv_frame_size) + _recv_frame_size(recv_frame_size), + _iface(usrp2_iface::make(ctrl_transport)), + _mboard_eeprom(mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_NXXX)) { - //make a new interface for usrp2 stuff - _iface = usrp2_iface::make(ctrl_transport); - - //extract the mboard rev numbers - _rev_lo = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_LSB, 1).at(0); - _rev_hi = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, 1).at(0); - //contruct the interfaces to mboard perifs _clock_ctrl = usrp2_clock_ctrl::make(_iface); _codec_ctrl = usrp2_codec_ctrl::make(_iface); @@ -192,35 +183,14 @@ static const std::string dboard_name = "0"; void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ named_prop_t key = named_prop_t::extract(key_); - //handle the other props - if (key_.type() == typeid(std::string)){ - if (key.as() == "mac-addr"){ - byte_vector_t bytes = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, 6); - val = mac_addr_t::from_bytes(bytes).to_string(); - return; - } - - if (key.as() == "ip-addr"){ - boost::asio::ip::address_v4::bytes_type bytes; - std::copy(_iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, 4), bytes); - val = boost::asio::ip::address_v4(bytes).to_string(); - return; - } - } - //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = str(boost::format("usrp2 mboard%d - rev %d:%d") % _index % _rev_hi % _rev_lo); + val = str(boost::format("usrp2 mboard%d - rev %s") % _index % _mboard_eeprom["rev"]); return; - case MBOARD_PROP_OTHERS:{ - prop_names_t others = boost::assign::list_of - ("mac-addr") - ("ip-addr") - ; - val = others; - } + case MBOARD_PROP_OTHERS: + val = prop_names_t(); return; case MBOARD_PROP_RX_DBOARD: @@ -281,6 +251,10 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = _tx_subdev_spec; return; + case MBOARD_PROP_EEPROM_MAP: + val = _mboard_eeprom; + return; + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -289,21 +263,6 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ * MBoard Set Properties **********************************************************************/ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ - //handle the other props - if (key.type() == typeid(std::string)){ - if (key.as() == "mac-addr"){ - byte_vector_t bytes = mac_addr_t::from_string(val.as()).to_bytes(); - _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, bytes); - return; - } - - if (key.as() == "ip-addr"){ - byte_vector_t bytes(4); - std::copy(boost::asio::ip::address_v4::from_string(val.as()).to_bytes(), bytes); - _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, bytes); - return; - } - } //handle the get request conditioned on the key switch(key.as()){ @@ -347,6 +306,11 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ )); return; + case MBOARD_PROP_EEPROM_MAP: + _mboard_eeprom = val.as(); + _mboard_eeprom.commit(*_iface, mboard_eeprom_t::MAP_NXXX); + return; + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 558726a2b..7b1a2b1eb 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -29,10 +29,11 @@ #include #include #include +#include #include #include #include -#include //mtu +#include #include #include #include @@ -94,20 +95,20 @@ public: private: size_t _index; - int _rev_hi, _rev_lo; const size_t _recv_frame_size; - //properties for this mboard - void get(const wax::obj &, wax::obj &); - void set(const wax::obj &, const wax::obj &); - uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec; - //interfaces usrp2_iface::sptr _iface; usrp2_clock_ctrl::sptr _clock_ctrl; usrp2_codec_ctrl::sptr _codec_ctrl; usrp2_serdes_ctrl::sptr _serdes_ctrl; + //properties for this mboard + void get(const wax::obj &, wax::obj &); + void set(const wax::obj &, const wax::obj &); + uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec; + uhd::usrp::mboard_eeprom_t _mboard_eeprom; + //rx and tx dboard methods and objects uhd::usrp::dboard_manager::sptr _dboard_manager; uhd::usrp::dboard_iface::sptr _dboard_iface; -- cgit v1.2.3 From fcf9f6ba329df2538286aabe20dd26628fc4ab43 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Nov 2010 20:38:25 -0700 Subject: usrp2: move mboard eeprom instance into iface to the clock control can access it --- firmware/microblaze/lib/eth_addrs.c | 6 ++++++ host/include/uhd/usrp/mboard_eeprom.hpp | 3 +++ host/lib/usrp/mboard_eeprom.cpp | 4 ++++ host/lib/usrp/usrp2/clock_ctrl.cpp | 5 +++-- host/lib/usrp/usrp2/fw_common.h | 8 -------- host/lib/usrp/usrp2/mboard_impl.cpp | 11 +++++------ host/lib/usrp/usrp2/usrp2_iface.cpp | 3 +++ host/lib/usrp/usrp2/usrp2_iface.hpp | 4 ++++ host/lib/usrp/usrp2/usrp2_impl.hpp | 2 -- 9 files changed, 28 insertions(+), 18 deletions(-) (limited to 'firmware/microblaze') diff --git a/firmware/microblaze/lib/eth_addrs.c b/firmware/microblaze/lib/eth_addrs.c index d7c1e0394..c6320e4fa 100644 --- a/firmware/microblaze/lib/eth_addrs.c +++ b/firmware/microblaze/lib/eth_addrs.c @@ -23,6 +23,12 @@ #include "i2c.h" #include "usrp2/fw_common.h" +//////////////////////////////////////////////////////////////////////// +// EEPROM Layout +//////////////////////////////////////////////////////////////////////// +#define USRP2_EE_MBOARD_MAC_ADDR 0x02 //6 bytes +#define USRP2_EE_MBOARD_IP_ADDR 0x0C //uint32, big-endian + static bool unprogrammed(const void *t, size_t len) { diff --git a/host/include/uhd/usrp/mboard_eeprom.hpp b/host/include/uhd/usrp/mboard_eeprom.hpp index 3bb05c0a8..bc3f1f8c9 100644 --- a/host/include/uhd/usrp/mboard_eeprom.hpp +++ b/host/include/uhd/usrp/mboard_eeprom.hpp @@ -40,6 +40,9 @@ namespace uhd{ namespace usrp{ MAP_BXXX }; + //! Make a new empty mboard eeprom + mboard_eeprom_t(void); + /*! * Make a new mboard EEPROM handler. * \param iface the interface to i2c diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 78b4122bb..a19210206 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -168,6 +168,10 @@ static void store_bxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ /*********************************************************************** * Implementation of mboard eeprom **********************************************************************/ +mboard_eeprom_t::mboard_eeprom_t(void){ + /* NOP */ +} + mboard_eeprom_t::mboard_eeprom_t(i2c_iface &iface, map_type map){ switch(map){ case MAP_NXXX: load_nxxx(*this, iface); break; diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 1e1c9b7b8..232f3b32a 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -20,6 +20,7 @@ #include "usrp2_regs.hpp" //spi slave constants #include #include +#include #include using namespace uhd; @@ -83,8 +84,8 @@ public: } void enable_mimo_clock_out(bool enb){ - //FIXME TODO put this revision read in a common place - boost::uint8_t rev_hi = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, 1).at(0); + boost::uint16_t rev = boost::lexical_cast(_iface->mb_eeprom["rev"]); + boost::uint8_t rev_hi = boost::uint8_t(rev >> 8); //calculate the low and high dividers size_t divider = size_t(this->get_master_clock_rate()/10e6); diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 4c46bbb1d..4ff31ddfd 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -52,14 +52,6 @@ extern "C" { #define USRP2_I2C_ADDR_TX_DB (USRP2_I2C_DEV_EEPROM | 0x4) #define USRP2_I2C_ADDR_RX_DB (USRP2_I2C_DEV_EEPROM | 0x5) -//////////////////////////////////////////////////////////////////////// -// EEPROM Layout -//////////////////////////////////////////////////////////////////////// -//#define USRP2_EE_MBOARD_REV_LSB 0x00 //1 byte -//#define USRP2_EE_MBOARD_REV_MSB 0x01 //1 byte -#define USRP2_EE_MBOARD_MAC_ADDR 0x02 //6 bytes -#define USRP2_EE_MBOARD_IP_ADDR 0x0C //uint32, big-endian - typedef enum{ USRP2_CTRL_ID_HUH_WHAT = ' ', //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index e49ac717e..079f096cb 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -38,8 +38,7 @@ usrp2_mboard_impl::usrp2_mboard_impl( ): _index(index), _recv_frame_size(recv_frame_size), - _iface(usrp2_iface::make(ctrl_transport)), - _mboard_eeprom(mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_NXXX)) + _iface(usrp2_iface::make(ctrl_transport)) { //contruct the interfaces to mboard perifs _clock_ctrl = usrp2_clock_ctrl::make(_iface); @@ -194,7 +193,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = str(boost::format("usrp2 mboard%d - rev %s") % _index % _mboard_eeprom["rev"]); + val = str(boost::format("usrp2 mboard%d - rev %s") % _index % _iface->mb_eeprom["rev"]); return; case MBOARD_PROP_OTHERS: @@ -260,7 +259,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_EEPROM_MAP: - val = _mboard_eeprom; + val = _iface->mb_eeprom; return; default: UHD_THROW_PROP_GET_ERROR(); @@ -315,8 +314,8 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ return; case MBOARD_PROP_EEPROM_MAP: - _mboard_eeprom = val.as(); - _mboard_eeprom.commit(*_iface, mboard_eeprom_t::MAP_NXXX); + _iface->mb_eeprom = val.as(); + _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_NXXX); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 2d450bfc6..eb2685efa 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -28,6 +28,7 @@ #include using namespace uhd; +using namespace uhd::usrp; using namespace uhd::transport; /*! @@ -58,6 +59,8 @@ public: "The fpga build is not compatible with the host code build." ) % int(USRP2_FPGA_COMPAT_NUM) % fpga_compat_num)); } + + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_NXXX); } ~usrp2_iface_impl(void){ diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 12fd4730a..bf36cbf6e 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -102,6 +103,9 @@ public: size_t num_bits, bool readback ) = 0; + + //motherboard eeprom map structure + uhd::usrp::mboard_eeprom_t mb_eeprom; }; #endif /* INCLUDED_USRP2_IFACE_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 0a56ec788..71f52878c 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -110,7 +109,6 @@ private: void get(const wax::obj &, wax::obj &); void set(const wax::obj &, const wax::obj &); uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec; - uhd::usrp::mboard_eeprom_t _mboard_eeprom; //rx and tx dboard methods and objects uhd::usrp::dboard_manager::sptr _dboard_manager; -- cgit v1.2.3