From 7f01386f63850d9e13afb4033d1fae39f6a03764 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 18:36:10 -0700 Subject: uhd: replaced warning post with calls to UHD_MSG(warning) The message api can support warnings, error, and status messages. The default handler is to stdio, but the user can change this. --- host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'host/lib/usrp/usrp_e100/usrp_e100_impl.cpp') diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index fe839c409..3fa60232e 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -58,18 +57,16 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){ usrp_e100_iface::sptr iface = usrp_e100_iface::make(new_addr["node"]); new_addr["name"] = iface->mb_eeprom["name"]; new_addr["serial"] = iface->mb_eeprom["serial"]; - if ( - (not hint.has_key("name") or hint["name"] == new_addr["name"]) and - (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) - ){ - usrp_e100_addrs.push_back(new_addr); - } } catch(const std::exception &e){ - uhd::warning::post( - std::string("Ignoring discovered device\n") - + e.what() - ); + new_addr["name"] = ""; + new_addr["serial"] = ""; + } + if ( + (not hint.has_key("name") or hint["name"] == new_addr["name"]) and + (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) + ){ + usrp_e100_addrs.push_back(new_addr); } } -- cgit v1.2.3 From 805da3ef3d5b04dfa39587c531a3415b09d2ea5b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 19:13:33 -0700 Subject: usrp-e100: removed stdio prints from implementation --- host/lib/device.cpp | 4 +- host/lib/usrp/usrp_e100/clock_ctrl.cpp | 30 ++++++------ host/lib/usrp/usrp_e100/codec_ctrl.cpp | 10 ++-- host/lib/usrp/usrp_e100/fpga_downloader.cpp | 31 ++++++------ host/lib/usrp/usrp_e100/io_impl.cpp | 23 +++++---- host/lib/usrp/usrp_e100/mboard_impl.cpp | 11 +++-- host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 6 +-- .../usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp | 55 +++++++++++----------- 8 files changed, 88 insertions(+), 82 deletions(-) (limited to 'host/lib/usrp/usrp_e100/usrp_e100_impl.cpp') diff --git a/host/lib/device.cpp b/host/lib/device.cpp index b2b0238d2..84b4d5452 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include using namespace uhd; @@ -87,7 +87,7 @@ device_addrs_t device::find(const device_addr_t &hint){ ); } catch(const std::exception &e){ - std::cerr << "Device discovery error: " << e.what() << std::endl; + UHD_MSG(error) << "Device discovery error: " << e.what() << std::endl; } } diff --git a/host/lib/usrp/usrp_e100/clock_ctrl.cpp b/host/lib/usrp/usrp_e100/clock_ctrl.cpp index 2e3eb5cb9..65162dbeb 100644 --- a/host/lib/usrp/usrp_e100/clock_ctrl.cpp +++ b/host/lib/usrp/usrp_e100/clock_ctrl.cpp @@ -17,6 +17,8 @@ #include "clock_ctrl.hpp" #include "ad9522_regs.hpp" +#include +#include #include #include #include "usrp_e100_regs.hpp" //spi slave constants @@ -27,14 +29,12 @@ #include //gcd #include #include -#include using namespace uhd; /*********************************************************************** * Constants **********************************************************************/ -static const bool CLOCK_SETTINGS_DEBUG = false; static const bool ENABLE_THE_TEST_OUT = true; static const double REFERENCE_INPUT_RATE = 10e6; static const double DEFAULT_OUTPUT_RATE = 64e6; @@ -138,12 +138,12 @@ static clock_settings_type get_clock_settings(double rate){ cs.chan_divider /= cs.vco_divider; } - if (CLOCK_SETTINGS_DEBUG){ - std::cout << "gcd " << gcd << std::endl; - std::cout << "X " << X << std::endl; - std::cout << "Y " << Y << std::endl; - std::cout << cs.to_pp_string() << std::endl; - } + UHD_LOGV(always) + << "gcd " << gcd << std::endl + << "X " << X << std::endl + << "Y " << Y << std::endl + << cs.to_pp_string() << std::endl + ; //filter limits on the counters if (cs.vco_divider == 1) continue; @@ -153,7 +153,7 @@ static clock_settings_type get_clock_settings(double rate){ if (cs.b_counter >= (1<<13)) continue; if (cs.a_counter >= (1<<6)) continue; - std::cout << "USRP-E100 clock control: " << i << std::endl << cs.to_pp_string() << std::endl; + UHD_MSG(status) << "USRP-E100 clock control: " << i << std::endl << cs.to_pp_string() << std::endl; return cs; } } @@ -188,18 +188,18 @@ public: bool fpga_clock_initialized = false; try{ if (not _iface->mb_eeprom["mcr"].empty()){ - std::cout << "Read FPGA clock rate from EEPROM setting." << std::endl; + UHD_MSG(status) << "Read FPGA clock rate from EEPROM setting." << std::endl; const double master_clock_rate = boost::lexical_cast(_iface->mb_eeprom["mcr"]); - std::cout << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl; + UHD_MSG(status) << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl; this->set_fpga_clock_rate(master_clock_rate); fpga_clock_initialized = true; } } catch(const std::exception &e){ - std::cerr << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl; + UHD_MSG(error) << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl; } if (not fpga_clock_initialized){ //was not set... use the default rate - std::cout << boost::format("Initializing FPGA clock to %fMHz...") % (DEFAULT_OUTPUT_RATE/1e6) << std::endl; + UHD_MSG(status) << boost::format("Initializing FPGA clock to %fMHz...") % (DEFAULT_OUTPUT_RATE/1e6) << std::endl; this->set_fpga_clock_rate(DEFAULT_OUTPUT_RATE); } @@ -440,7 +440,7 @@ private: void send_reg(boost::uint16_t addr){ boost::uint32_t reg = _ad9522_regs.get_write_reg(addr); - //std::cout << "clock control write reg: " << std::hex << reg << std::endl; + UHD_LOGV(often) << "clock control write reg: " << std::hex << reg << std::endl; _iface->write_spi( UE_SPI_SS_AD9522, spi_config_t::EDGE_RISE, @@ -467,7 +467,7 @@ private: if (_ad9522_regs.vco_calibration_finished) return; boost::this_thread::sleep(boost::posix_time::milliseconds(10)); } - std::cerr << "USRP-E100 clock control: VCO calibration timeout" << std::endl; + UHD_MSG(error) << "USRP-E100 clock control: VCO calibration timeout" << std::endl; } void send_all_regs(void){ diff --git a/host/lib/usrp/usrp_e100/codec_ctrl.cpp b/host/lib/usrp/usrp_e100/codec_ctrl.cpp index 50442546a..c2f2712e3 100644 --- a/host/lib/usrp/usrp_e100/codec_ctrl.cpp +++ b/host/lib/usrp/usrp_e100/codec_ctrl.cpp @@ -17,6 +17,7 @@ #include "codec_ctrl.hpp" #include "ad9862_regs.hpp" +#include #include #include #include @@ -25,12 +26,9 @@ #include #include "usrp_e100_regs.hpp" //spi slave constants #include -#include using namespace uhd; -static const bool codec_debug = false; - const gain_range_t usrp_e100_codec_ctrl::tx_pga_gain_range(-20, 0, double(0.1)); const gain_range_t usrp_e100_codec_ctrl::rx_pga_gain_range(0, 20, 1); @@ -268,7 +266,7 @@ void usrp_e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){ **********************************************************************/ void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){ boost::uint32_t reg = _ad9862_regs.get_write_reg(addr); - if (codec_debug) std::cout << "codec control write reg: " << std::hex << reg << std::endl; + UHD_LOGV(often) << "codec control write reg: " << std::hex << reg << std::endl; _iface->write_spi( UE_SPI_SS_AD9862, spi_config_t::EDGE_RISE, @@ -278,13 +276,13 @@ void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){ void usrp_e100_codec_ctrl_impl::recv_reg(boost::uint8_t addr){ boost::uint32_t reg = _ad9862_regs.get_read_reg(addr); - if (codec_debug) std::cout << "codec control read reg: " << std::hex << reg << std::endl; + UHD_LOGV(often) << "codec control read reg: " << std::hex << reg << std::endl; boost::uint32_t ret = _iface->read_spi( UE_SPI_SS_AD9862, spi_config_t::EDGE_RISE, reg, 16 ); - if (codec_debug) std::cout << "codec control read ret: " << std::hex << ret << std::endl; + UHD_LOGV(often) << "codec control read ret: " << std::hex << ret << std::endl; _ad9862_regs.set_reg(addr, boost::uint16_t(ret)); } diff --git a/host/lib/usrp/usrp_e100/fpga_downloader.cpp b/host/lib/usrp/usrp_e100/fpga_downloader.cpp index 018a120d6..a7449d3b1 100644 --- a/host/lib/usrp/usrp_e100/fpga_downloader.cpp +++ b/host/lib/usrp/usrp_e100/fpga_downloader.cpp @@ -18,15 +18,17 @@ #include #ifdef UHD_DLL_EXPORTS #include +#include #else //special case when this file is externally included #include +#include +#define UHD_MSG(type) std::cout namespace uhd{ typedef std::runtime_error os_error; typedef std::runtime_error io_error; } #endif -#include #include #include #include @@ -110,8 +112,9 @@ gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction) direction_file_name = base_path.str() + "/direction"; direction_file.open(direction_file_name.c_str()); - if (!direction_file.is_open()) - std::cout << "Failed to open direction file." << std::endl; + if (!direction_file.is_open()) throw uhd::os_error( + "Failed to open direction file." + ); if (pin_direction == OUT) direction_file << "out" << std::endl; else @@ -123,8 +126,9 @@ gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction) value_file_name = base_path.str() + "/value"; value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out); - if (!value_file.is_open()) - std::cout << "Failed to open value file." << std::endl; + if (!value_file.is_open()) throw uhd::os_error( + "Failed to open value file." + ); } bool gpio::get_value() @@ -140,7 +144,7 @@ bool gpio::get_value() else if (val == "1") return true; else - std::cout << "Data read from value file|" << val << "|" << std::endl; + throw uhd::os_error("Data read from value file|" + val + "|"); return false; } @@ -172,8 +176,7 @@ static void prepare_fpga_for_configuration(gpio &prog, gpio &)//init) } while (count < 10 && !ready_to_program); if (count == 10) { - std::cout << "FPGA not ready for programming." << std::endl; - exit(-1); + throw uhd::os_error("FPGA not ready for programming."); } #endif } @@ -232,10 +235,10 @@ static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &d spi.send(buf, rbuf, bitstream.gcount()); if (error.get_value()) - std::cout << "INIT_B went high, error occured." << std::endl; + throw uhd::os_error("INIT_B went high, error occured."); if (!done.get_value()) - std::cout << "Configuration complete." << std::endl; + UHD_MSG(status) << "Configuration complete." << std::endl; } while (bitstream.gcount() == BUF_SIZE); } @@ -249,20 +252,20 @@ void usrp_e100_load_fpga(const std::string &bin_file){ gpio gpio_init_b(INIT_B, IN); gpio gpio_done (DONE, IN); - std::cout << "Loading FPGA image: " << bin_file << "... " << std::flush; + UHD_MSG(status) << "Loading FPGA image: " << bin_file << "... " << std::flush; if(std::system("/sbin/rmmod usrp_e") != 0){ - std::cerr << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl; + UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl; } prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); - std::cout << "done = " << gpio_done.get_value() << std::endl; + UHD_MSG(status) << "done = " << gpio_done.get_value() << std::endl; send_file_to_fpga(bin_file, gpio_init_b, gpio_done); if(std::system("/sbin/modprobe usrp_e") != 0){ - std::cerr << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl; + UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl; } } diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index 40b8a2393..7e775dfd8 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -17,6 +17,8 @@ #include "usrp_e100_impl.hpp" #include "usrp_e100_regs.hpp" +#include +#include #include #include #include @@ -25,6 +27,7 @@ #include #include #include +#include #include using namespace uhd; @@ -37,7 +40,7 @@ using namespace uhd::transport; static const size_t rx_data_inline_sid = 1; static const size_t tx_async_report_sid = 2; static const int underflow_flags = async_metadata_t::EVENT_CODE_UNDERFLOW | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET; -static const bool recv_debug = false; +#define fp_recv_debug false /*********************************************************************** * io impl details (internal to this file) @@ -116,12 +119,14 @@ void usrp_e100_impl::io_impl::recv_pirate_loop( managed_recv_buffer::sptr buff = this->data_xport->get_recv_buff(); if (not buff.get()) continue; //ignore timeout/error buffers - if (recv_debug){ - std::cout << "len " << buff->size() << std::endl; + if (fp_recv_debug){ + std::ostringstream ss; + ss << "len " << buff->size() << std::endl; for (size_t i = 0; i < 9; i++){ - std::cout << boost::format(" 0x%08x") % buff->cast()[i] << std::endl; + ss << boost::format(" 0x%08x") % buff->cast()[i] << std::endl; } - std::cout << std::endl << std::endl; + ss << std::endl << std::endl; + UHD_LOGV(always) << ss.str(); } try{ @@ -133,7 +138,7 @@ void usrp_e100_impl::io_impl::recv_pirate_loop( //handle an rx data packet or inline message if (if_packet_info.sid == rx_data_inline_sid){ - if (recv_debug) std::cout << "this is rx_data_inline_sid\n"; + if (fp_recv_debug) UHD_LOGV(always) << "this is rx_data_inline_sid\n"; //same number of frames as the data transport -> always immediate recv_pirate_booty.push_with_wait(buff); continue; @@ -141,7 +146,7 @@ void usrp_e100_impl::io_impl::recv_pirate_loop( //handle a tx async report message if (if_packet_info.sid == tx_async_report_sid and if_packet_info.packet_type != vrt::if_packet_info_t::PACKET_TYPE_DATA){ - if (recv_debug) std::cout << "this is tx_async_report_sid\n"; + if (fp_recv_debug) UHD_LOGV(always) << "this is tx_async_report_sid\n"; //fill in the async metadata async_metadata_t metadata; @@ -158,10 +163,10 @@ void usrp_e100_impl::io_impl::recv_pirate_loop( continue; } - if (recv_debug) std::cout << "this is unknown packet\n"; + if (fp_recv_debug) UHD_LOGV(always) << "this is unknown packet\n"; }catch(const std::exception &e){ - std::cerr << "Error (usrp-e recv pirate loop): " << e.what() << std::endl; + UHD_MSG(error) << "Error (usrp-e recv pirate loop): " << e.what() << std::endl; } } } diff --git a/host/lib/usrp/usrp_e100/mboard_impl.cpp b/host/lib/usrp/usrp_e100/mboard_impl.cpp index 5f4a208d3..d31662eb5 100644 --- a/host/lib/usrp/usrp_e100/mboard_impl.cpp +++ b/host/lib/usrp/usrp_e100/mboard_impl.cpp @@ -17,12 +17,12 @@ #include "usrp_e100_impl.hpp" #include "usrp_e100_regs.hpp" +#include #include #include #include #include #include -#include using namespace uhd; using namespace uhd::usrp; @@ -207,10 +207,11 @@ void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){ return; case MBOARD_PROP_CLOCK_RATE: - std::cerr << "Helpful message:" << std::endl; - std::cerr << " I see that you are setting the master clock rate from the API." << std::endl; - std::cerr << " You may find it more convenient to burn this setting into the EEPROM." << std::endl; - std::cerr << " See the application notes for USRP-E1XX for further instructions." << std::endl; + UHD_MSG(warning) + << "I see that you are setting the master clock rate from the API.\n" + << "You may find it more convenient to burn this setting into the EEPROM.\n" + << "See the application notes for USRP-E1XX for further instructions.\n" + ; _clock_ctrl->set_fpga_clock_rate(val.as()); return; diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index 3fa60232e..4247746ab 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -17,6 +17,7 @@ #include "usrp_e100_impl.hpp" #include "usrp_e100_regs.hpp" +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include using namespace uhd; @@ -80,7 +80,7 @@ static device::sptr usrp_e100_make(const device_addr_t &device_addr){ //setup the main interface into fpga std::string node = device_addr["node"]; - std::cout << boost::format("Opening USRP-E on %s") % node << std::endl; + UHD_MSG(status) << boost::format("Opening USRP-E on %s") % node << std::endl; usrp_e100_iface::sptr iface = usrp_e100_iface::make(node); //------------------------------------------------------------------ @@ -121,7 +121,7 @@ static device::sptr usrp_e100_make(const device_addr_t &device_addr){ iface.reset(); usrp_e100_load_fpga(usrp_e100_fpga_image); sleep(1); ///\todo do this better one day. - std::cout << boost::format("re-Opening USRP-E on %s") % node << std::endl; + UHD_MSG(status) << boost::format("re-Opening USRP-E on %s") % node << std::endl; iface = usrp_e100_iface::make(node); try{std::ofstream(hash_file_path) << fpga_hash;}catch(...){} } diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp index f4274dc5a..26774aeda 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp @@ -17,19 +17,18 @@ #include "usrp_e100_iface.hpp" #include +#include #include #include #include //mmap #include //getpagesize #include //poll #include -#include using namespace uhd; using namespace uhd::transport; -static const bool fp_verbose = false; //fast-path verbose -static const bool sp_verbose = false; //slow-path verbose +#define fp_verbose false //fast-path verbose static const size_t poll_breakout = 10; //how many poll timeouts constitute a full timeout /*********************************************************************** @@ -43,14 +42,14 @@ public: void release(void){ if (_info->flags != RB_USER_PROCESS) return; - if (fp_verbose) std::cout << "recv buff: release" << std::endl; + if (fp_verbose) UHD_LOGV(always) << "recv buff: release" << std::endl; _info->flags = RB_KERNEL; //release the frame } bool ready(void){return _info->flags & RB_USER;} sptr get_new(void){ - if (fp_verbose) std::cout << " make_recv_buff: " << get_size() << std::endl; + if (fp_verbose) UHD_LOGV(always) << " make_recv_buff: " << get_size() << std::endl; _info->flags = RB_USER_PROCESS; //claim the frame return sptr(this, &usrp_e100_mmap_zero_copy_mrb::fake_deleter); } @@ -78,18 +77,18 @@ public: void commit(size_t len){ if (_info->flags != RB_USER_PROCESS) return; - if (fp_verbose) std::cout << "send buff: commit " << len << std::endl; + if (fp_verbose) UHD_LOGV(always) << "send buff: commit " << len << std::endl; _info->len = len; _info->flags = RB_USER; //release the frame if (::write(_fd, NULL, 0) < 0){ //notifies the kernel - std::cerr << UHD_THROW_SITE_INFO("write error") << std::endl; + UHD_LOGV(rarely) << UHD_THROW_SITE_INFO("write error") << std::endl; } } bool ready(void){return _info->flags & RB_KERNEL;} sptr get_new(void){ - if (fp_verbose) std::cout << " make_send_buff: " << get_size() << std::endl; + if (fp_verbose) UHD_LOGV(always) << " make_send_buff: " << get_size() << std::endl; _info->flags = RB_USER_PROCESS; //claim the frame return sptr(this, &usrp_e100_mmap_zero_copy_msb::fake_deleter); } @@ -127,15 +126,15 @@ public: (_rb_size.num_rx_frames + _rb_size.num_tx_frames) * _frame_size; //print sizes summary - if (sp_verbose){ - std::cout << "page_size: " << page_size << std::endl; - std::cout << "frame_size: " << _frame_size << std::endl; - std::cout << "num_pages_rx_flags: " << _rb_size.num_pages_rx_flags << std::endl; - std::cout << "num_rx_frames: " << _rb_size.num_rx_frames << std::endl; - std::cout << "num_pages_tx_flags: " << _rb_size.num_pages_tx_flags << std::endl; - std::cout << "num_tx_frames: " << _rb_size.num_tx_frames << std::endl; - std::cout << "map_size: " << _map_size << std::endl; - } + UHD_LOG + << "page_size: " << page_size << std::endl + << "frame_size: " << _frame_size << std::endl + << "num_pages_rx_flags: " << _rb_size.num_pages_rx_flags << std::endl + << "num_rx_frames: " << _rb_size.num_rx_frames << std::endl + << "num_pages_tx_flags: " << _rb_size.num_pages_tx_flags << std::endl + << "num_tx_frames: " << _rb_size.num_tx_frames << std::endl + << "map_size: " << _map_size << std::endl + ; //call mmap to get the memory _mapped_mem = ::mmap( @@ -150,12 +149,12 @@ public: size_t send_buff_off = send_info_off + (_rb_size.num_pages_tx_flags * page_size); //print offset summary - if (sp_verbose){ - std::cout << "recv_info_off: " << recv_info_off << std::endl; - std::cout << "recv_buff_off: " << recv_buff_off << std::endl; - std::cout << "send_info_off: " << send_info_off << std::endl; - std::cout << "send_buff_off: " << send_buff_off << std::endl; - } + UHD_LOG + << "recv_info_off: " << recv_info_off << std::endl + << "recv_buff_off: " << recv_buff_off << std::endl + << "send_info_off: " << send_info_off << std::endl + << "send_buff_off: " << send_buff_off << std::endl + ; //pointers to sections in the mapped memory ring_buffer_info (*recv_info)[], (*send_info)[]; @@ -186,12 +185,12 @@ public: } ~usrp_e100_mmap_zero_copy_impl(void){ - if (sp_verbose) std::cout << "cleanup: munmap" << std::endl; + UHD_LOG << "cleanup: munmap" << std::endl; ::munmap(_mapped_mem, _map_size); } managed_recv_buffer::sptr get_recv_buff(double timeout){ - if (fp_verbose) std::cout << "get_recv_buff: " << _recv_index << std::endl; + if (fp_verbose) UHD_LOGV(always) << "get_recv_buff: " << _recv_index << std::endl; usrp_e100_mmap_zero_copy_mrb &mrb = _mrb_pool[_recv_index]; //poll/wait for a ready frame @@ -201,7 +200,7 @@ public: pfd.fd = _fd; pfd.events = POLLIN; ssize_t poll_ret = ::poll(&pfd, 1, size_t(timeout*1e3/poll_breakout)); - if (fp_verbose) std::cout << " POLLIN: " << poll_ret << std::endl; + if (fp_verbose) UHD_LOGV(always) << " POLLIN: " << poll_ret << std::endl; if (poll_ret > 0) goto found_user_frame; //good poll, continue on } return managed_recv_buffer::sptr(); //timed-out for real @@ -223,7 +222,7 @@ public: } managed_send_buffer::sptr get_send_buff(double timeout){ - if (fp_verbose) std::cout << "get_send_buff: " << _send_index << std::endl; + if (fp_verbose) UHD_LOGV(always) << "get_send_buff: " << _send_index << std::endl; usrp_e100_mmap_zero_copy_msb &msb = _msb_pool[_send_index]; //poll/wait for a ready frame @@ -232,7 +231,7 @@ public: pfd.fd = _fd; pfd.events = POLLOUT; ssize_t poll_ret = ::poll(&pfd, 1, size_t(timeout*1e3)); - if (fp_verbose) std::cout << " POLLOUT: " << poll_ret << std::endl; + if (fp_verbose) UHD_LOGV(always) << " POLLOUT: " << poll_ret << std::endl; if (poll_ret <= 0) return managed_send_buffer::sptr(); } -- cgit v1.2.3 From 9734a74366dd095256c2e2c58c5c9bcd7547f72d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 20:40:36 -0700 Subject: uhd: various tweaks to log and msg, replaced a few remaining stdio --- host/include/uhd/utils/log.hpp | 9 ++------- host/include/uhd/utils/msg.hpp | 9 ++------- host/include/uhd/utils/safe_call.hpp | 4 ++-- host/lib/device.cpp | 5 +++-- host/lib/usrp/usrp1/usrp1_impl.cpp | 1 + host/lib/usrp/usrp2/mboard_impl.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 1 + host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 1 + host/lib/utils/log.cpp | 2 +- host/lib/utils/msg.cpp | 18 +++++++++++++----- 10 files changed, 27 insertions(+), 25 deletions(-) (limited to 'host/lib/usrp/usrp_e100/usrp_e100_impl.cpp') diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 666dfa982..8d8f42fd0 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -54,7 +54,7 @@ * Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl; */ #define UHD_LOGV(verbosity) \ - uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) + uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)() /*! * A UHD logger macro with default verbosity. @@ -85,12 +85,7 @@ namespace uhd{ namespace _log{ const std::string &function ); ~log(void); - - std::ostream &get(void); - - template std::ostream &operator<<(const T &x){ - return get() << x; - } + std::ostream &operator()(void); }; }} //namespace uhd::_log diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp index 2313215bf..17179f551 100644 --- a/host/include/uhd/utils/msg.hpp +++ b/host/include/uhd/utils/msg.hpp @@ -27,7 +27,7 @@ * Usage: UHD_MSG(warning) << "some warning message" << std::endl; */ #define UHD_MSG(type) \ - uhd::msg::_msg(uhd::msg::type) + uhd::msg::_msg(uhd::msg::type)() namespace uhd{ namespace msg{ @@ -55,12 +55,7 @@ namespace uhd{ namespace msg{ struct UHD_API_FUTURE _msg{ _msg(const type_t type); ~_msg(void); - - std::ostream &get(void); - - template std::ostream &operator<<(const T &x){ - return get() << x; - } + std::ostream &operator()(void); }; }} //namespace uhd::msg diff --git a/host/include/uhd/utils/safe_call.hpp b/host/include/uhd/utils/safe_call.hpp index b9f545b23..ab287cc66 100644 --- a/host/include/uhd/utils/safe_call.hpp +++ b/host/include/uhd/utils/safe_call.hpp @@ -20,10 +20,10 @@ #include #include -#include +#include //! helper macro for safe call to produce warnings -#define _UHD_SAFE_CALL_WARNING(code, what) UHD_MSG(warning) << \ +#define _UHD_SAFE_CALL_WARNING(code, what) UHD_LOGV(rarely) << \ UHD_THROW_SITE_INFO("Exception caught in safe-call.") + #code + " -> " + what \ ; diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 84b4d5452..c5bc047da 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ void device::register_device( const find_t &find, const make_t &make ){ - //std::cout << "registering device" << std::endl; + UHD_LOGV(always) << "registering device" << std::endl; get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make)); } @@ -128,7 +129,7 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ device_addr_t dev_addr; make_t maker; boost::tie(dev_addr, maker) = dev_addr_makers.at(which); size_t dev_hash = hash_device_addr(dev_addr); - //std::cout << boost::format("Hash: %u") % dev_hash << std::endl; + UHD_LOG << boost::format("Device hash: %u") % dev_hash << std::endl; //copy keys that were in hint but not in dev_addr //this way, we can pass additional transport arguments diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 182705034..57aae1b58 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -123,6 +123,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) * Make **********************************************************************/ static device::sptr usrp1_make(const device_addr_t &device_addr){ + UHD_MSG(status) << "Opening a USRP1 device..." << std::endl; //extract the FPGA path for the USRP1 std::string usrp1_fpga_image = find_image_path( diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index daccc0865..c9931be45 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -142,7 +142,7 @@ usrp2_mboard_impl::usrp2_mboard_impl( else { _mimo_clocking_mode_is_master = (_iface->peek32(_iface->regs.status) & (1 << 8)) != 0; } - UHD_MSG(status) << boost::format("mboard%d MIMO %s") % _index % + UHD_MSG(status) << boost::format("mboard%d is MIMO %s") % _index % (_mimo_clocking_mode_is_master?"master":"slave") << std::endl; //init the clock config diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 4eb5508e2..2bc259657 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -228,6 +228,7 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u * Structors **********************************************************************/ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ + UHD_MSG(status) << "Opening a USRP2/N-Series device..." << std::endl; device_addr_t device_addr = _device_addr; //setup the dsp transport hints (default to a large recv buff) diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index 4247746ab..00d7dd029 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -77,6 +77,7 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){ * Make **********************************************************************/ static device::sptr usrp_e100_make(const device_addr_t &device_addr){ + UHD_MSG(status) << "Opening a USRP E-Series device..." << std::endl; //setup the main interface into fpga std::string node = device_addr["node"]; diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index f67a14411..8b270af6b 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -209,6 +209,6 @@ uhd::_log::log::~log(void){ uhd_logger_stream_resource().aquire(false); } -std::ostream & uhd::_log::log::get(void){ +std::ostream & uhd::_log::log::operator()(void){ return uhd_logger_stream_resource().get(); } diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp index 0eaca05a5..e850b5a6d 100644 --- a/host/lib/utils/msg.cpp +++ b/host/lib/utils/msg.cpp @@ -34,11 +34,19 @@ static void msg_to_cout(const std::string &msg){ std::stringstream ss; - BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){ - ss << "-- " << line << std::endl; + static bool just_had_a_newline = true; + BOOST_FOREACH(char ch, msg){ + if (just_had_a_newline){ + just_had_a_newline = false; + ss << "-- "; + } + if (ch == '\n'){ + just_had_a_newline = true; + } + ss << ch; } - std::cout << ss.str(); + std::cout << ss.str() << std::flush; } static void msg_to_cerr(const std::string &title, const std::string &msg){ @@ -49,7 +57,7 @@ static void msg_to_cerr(const std::string &title, const std::string &msg){ ss << " " << line << std::endl; } - std::cerr << ss.str(); + std::cerr << ss.str() << std::flush; } /*********************************************************************** @@ -110,6 +118,6 @@ uhd::msg::_msg::~_msg(void){ msg_mutex.unlock(); } -std::ostream & uhd::msg::_msg::get(void){ +std::ostream & uhd::msg::_msg::operator()(void){ return msg_ss; } -- cgit v1.2.3 From c9bf4798cc19e9ac9bf2fbcfeeae7ed26936b19d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 5 May 2011 14:58:18 -0700 Subject: usrp1: overload read_eeprom to handle multi-byte reads --- host/lib/usrp/usrp1/usrp1_iface.cpp | 11 +++++++++++ host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'host/lib/usrp/usrp_e100/usrp_e100_impl.cpp') diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index f66337ef9..0942e2613 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -165,6 +165,17 @@ public: return out_bytes; } + //! overload read_eeprom to handle multi-byte reads + byte_vector_t read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes + ){ + //do a zero byte write to start read cycle + this->write_i2c(addr, byte_vector_t(1, offset)); + return this->read_i2c(addr, num_bytes); //read all bytes + } + /******************************************************************* * SPI * diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index 00d7dd029..4247746ab 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -77,7 +77,6 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){ * Make **********************************************************************/ static device::sptr usrp_e100_make(const device_addr_t &device_addr){ - UHD_MSG(status) << "Opening a USRP E-Series device..." << std::endl; //setup the main interface into fpga std::string node = device_addr["node"]; -- cgit v1.2.3