From 95b966a599c0030921dc6b530ca8c94633d905f6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 23 Mar 2011 18:48:30 -0700 Subject: uhd: update copyright headers with automated script --- host/lib/usrp/usrp1/clock_ctrl.hpp | 2 +- host/lib/usrp/usrp1/usrp1_ctrl.cpp | 2 +- host/lib/usrp/usrp1/usrp1_ctrl.hpp | 2 +- host/lib/usrp/usrp1/usrp1_iface.cpp | 2 +- host/lib/usrp/usrp1/usrp1_iface.hpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/clock_ctrl.hpp b/host/lib/usrp/usrp1/clock_ctrl.hpp index 645472f02..339d547e6 100644 --- a/host/lib/usrp/usrp1/clock_ctrl.hpp +++ b/host/lib/usrp/usrp1/clock_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp index 3fa6cb8b7..22e9fd1ce 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.hpp b/host/lib/usrp/usrp1/usrp1_ctrl.hpp index ee68f8401..970ca2951 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.hpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index 0c37610ce..ea7c1cea5 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 diff --git a/host/lib/usrp/usrp1/usrp1_iface.hpp b/host/lib/usrp/usrp1/usrp1_iface.hpp index fdb7464ce..2ebcdbacc 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.hpp +++ b/host/lib/usrp/usrp1/usrp1_iface.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 -- cgit v1.2.3 From 48f6e1f8aae24ee4ff3b15232cfc335b0210ed11 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 29 Mar 2011 17:27:17 -0700 Subject: usrp1: ignore claimed interfaces, avoids the problem of discovery when one device is claimed --- host/lib/usrp/usrp1/usrp1_impl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 7005c59f2..a99777775 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -86,7 +86,11 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) } //std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl; - usrp_ctrl::make(usb_control::make(handle))->usrp_load_firmware(usrp1_fw_image); + usb_control::sptr control; + try{control = usb_control::make(handle);} + catch(const uhd::exception &){continue;} //ignore claimed + + usrp_ctrl::make(control)->usrp_load_firmware(usrp1_fw_image); } //get descriptors again with serial number, but using the initialized VID/PID now since we have firmware @@ -94,7 +98,11 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) pid = USRP1_PRODUCT_ID; BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) { - usrp1_iface::sptr iface = usrp1_iface::make(usrp_ctrl::make(usb_control::make(handle))); + usb_control::sptr control; + try{control = usb_control::make(handle);} + catch(const uhd::exception &){continue;} //ignore claimed + + usrp1_iface::sptr iface = usrp1_iface::make(usrp_ctrl::make(control)); device_addr_t new_addr; new_addr["type"] = "usrp1"; new_addr["name"] = iface->mb_eeprom["name"]; -- cgit v1.2.3 From 1d29ee1086620b7dc51dcdbcaaef2690d2e95dc6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 30 Mar 2011 16:48:09 -0700 Subject: usrp1: switch usrp1 iface to use spi read (transact never worked) It detects the number of header bytes by searching for non-zero bytes. --- host/lib/usrp/usrp1/usrp1_iface.cpp | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index ea7c1cea5..8f10df751 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -175,24 +175,31 @@ public: UHD_ASSERT_THROW((num_bits <= 32) && !(num_bits % 8)); size_t num_bytes = num_bits / 8; - // Byteswap on num_bytes - unsigned char buff[4] = { 0 }; - for (size_t i = 1; i <= num_bytes; i++) - buff[num_bytes - i] = (bits >> ((i - 1) * 8)) & 0xff; - if (readback) { - boost::uint8_t w_len_h = which_slave & 0xff; - boost::uint8_t w_len_l = num_bytes & 0xff; - - int ret = _ctrl_transport->usrp_control_read( - VRQ_SPI_TRANSACT, - (buff[0] << 8) | (buff[1] << 0), - (buff[2] << 8) | (buff[3] << 0), - buff, - (w_len_h << 8) | (w_len_l << 0)); - - if (ret < 0) throw uhd::io_error("USRP1: failed SPI readback transaction"); - + unsigned char buff[4] = { + (bits >> 0) & 0xff, (bits >> 8) & 0xff, + (bits >> 16) & 0xff, (bits >> 24) & 0xff + }; + //conditions where there are two header bytes + if (num_bytes >= 3 and buff[num_bytes-1] != 0 and buff[num_bytes-2] != 0 and buff[num_bytes-3] == 0){ + if (int(num_bytes-2) != _ctrl_transport->usrp_control_read( + VRQ_SPI_READ, (buff[num_bytes-1] << 8) | (buff[num_bytes-2] << 0), + (which_slave << 8) | SPI_FMT_MSB | SPI_FMT_HDR_2, + buff, num_bytes-2 + )) throw uhd::io_error("USRP1: failed SPI readback transaction"); + } + + //conditions where there is one header byte + else if (num_bytes >= 2 and buff[num_bytes-1] != 0 and buff[num_bytes-2] == 0){ + if (int(num_bytes-1) != _ctrl_transport->usrp_control_read( + VRQ_SPI_READ, buff[num_bytes-1], + (which_slave << 8) | SPI_FMT_MSB | SPI_FMT_HDR_1, + buff, num_bytes-1 + )) throw uhd::io_error("USRP1: failed SPI readback transaction"); + } + else{ + throw uhd::io_error("USRP1: invalid input data for SPI readback"); + } boost::uint32_t val = (((boost::uint32_t)buff[0]) << 0) | (((boost::uint32_t)buff[1]) << 8) | (((boost::uint32_t)buff[2]) << 16) | @@ -200,6 +207,11 @@ public: return val; } else { + // Byteswap on num_bytes + unsigned char buff[4] = { 0 }; + for (size_t i = 1; i <= num_bytes; i++) + buff[num_bytes - i] = (bits >> ((i - 1) * 8)) & 0xff; + boost::uint8_t w_index_h = which_slave & 0xff; boost::uint8_t w_index_l = (SPI_FMT_MSB | SPI_FMT_HDR_0) & 0xff; -- cgit v1.2.3 From 6f70d17b206226823dc6108410d0608373300f58 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 30 Mar 2011 16:51:01 -0700 Subject: usrp1: fixed codec ctrl aux adc read (didnt start conversions) + cleaned-up logic --- host/lib/usrp/usrp1/codec_ctrl.cpp | 73 +++++++++++++++----------------------- 1 file changed, 29 insertions(+), 44 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp index 1b4411002..9df29da0e 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.cpp +++ b/host/lib/usrp/usrp1/codec_ctrl.cpp @@ -71,7 +71,6 @@ private: usrp1_clock_ctrl::sptr _clock_ctrl; int _spi_slave; ad9862_regs_t _ad9862_regs; - aux_adc_t _last_aux_adc_a, _last_aux_adc_b; void send_reg(boost::uint8_t addr); void recv_reg(boost::uint8_t addr); @@ -134,6 +133,10 @@ usrp1_codec_ctrl_impl::usrp1_codec_ctrl_impl(usrp1_iface::sptr iface, this->send_reg(addr); } + //always start conversions for aux ADC + _ad9862_regs.start_a = 1; + _ad9862_regs.start_b = 1; + //aux adc clock _ad9862_regs.clk_4 = ad9862_regs_t::CLK_4_1_4; this->send_reg(34); @@ -206,55 +209,37 @@ static double aux_adc_to_volts(boost::uint8_t high, boost::uint8_t low) return double(((boost::uint16_t(high) << 2) | low)*3.3)/0x3ff; } -double usrp1_codec_ctrl_impl::read_aux_adc(aux_adc_t which) -{ - //check to see if the switch needs to be set - bool write_switch = false; - switch(which) { - +double usrp1_codec_ctrl_impl::read_aux_adc(aux_adc_t which){ + switch(which){ case AUX_ADC_A1: + _ad9862_regs.select_a = ad9862_regs_t::SELECT_A_AUX_ADC1; + this->send_reg(34); //start conversion and select mux + this->recv_reg(28); //read the value (2 bytes, 2 reads) + this->recv_reg(29); + return aux_adc_to_volts(_ad9862_regs.aux_adc_a1_9_2, _ad9862_regs.aux_adc_a1_1_0); + case AUX_ADC_A2: - if (which != _last_aux_adc_a) { - _ad9862_regs.select_a = (which == AUX_ADC_A1)? - ad9862_regs_t::SELECT_A_AUX_ADC1: ad9862_regs_t::SELECT_A_AUX_ADC2; - _last_aux_adc_a = which; - write_switch = true; - } - break; + _ad9862_regs.select_a = ad9862_regs_t::SELECT_A_AUX_ADC2; + this->send_reg(34); //start conversion and select mux + this->recv_reg(26); //read the value (2 bytes, 2 reads) + this->recv_reg(27); + return aux_adc_to_volts(_ad9862_regs.aux_adc_a2_9_2, _ad9862_regs.aux_adc_a2_1_0); case AUX_ADC_B1: - case AUX_ADC_B2: - if (which != _last_aux_adc_b) { - _ad9862_regs.select_b = (which == AUX_ADC_B1)? - ad9862_regs_t::SELECT_B_AUX_ADC1: ad9862_regs_t::SELECT_B_AUX_ADC2; - _last_aux_adc_b = which; - write_switch = true; - } - break; + _ad9862_regs.select_b = ad9862_regs_t::SELECT_B_AUX_ADC1; + this->send_reg(34); //start conversion and select mux + this->recv_reg(32); //read the value (2 bytes, 2 reads) + this->recv_reg(33); + return aux_adc_to_volts(_ad9862_regs.aux_adc_b1_9_2, _ad9862_regs.aux_adc_b1_1_0); + case AUX_ADC_B2: + _ad9862_regs.select_b = ad9862_regs_t::SELECT_B_AUX_ADC2; + this->send_reg(34); //start conversion and select mux + this->recv_reg(30); //read the value (2 bytes, 2 reads) + this->recv_reg(31); + return aux_adc_to_volts(_ad9862_regs.aux_adc_b2_9_2, _ad9862_regs.aux_adc_b2_1_0); } - - //write the switch if it changed - if(write_switch) this->send_reg(34); - - //map aux adcs to register values to read - static const uhd::dict aux_dac_to_addr = boost::assign::map_list_of - (AUX_ADC_A2, 26) (AUX_ADC_A1, 28) - (AUX_ADC_B2, 30) (AUX_ADC_B1, 32) - ; - - //read the value - this->recv_reg(aux_dac_to_addr[which]+0); - this->recv_reg(aux_dac_to_addr[which]+1); - - //return the value scaled to volts - switch(which) { - case AUX_ADC_A1: return aux_adc_to_volts(_ad9862_regs.aux_adc_a1_9_2, _ad9862_regs.aux_adc_a1_1_0); - case AUX_ADC_A2: return aux_adc_to_volts(_ad9862_regs.aux_adc_a2_9_2, _ad9862_regs.aux_adc_a2_1_0); - case AUX_ADC_B1: return aux_adc_to_volts(_ad9862_regs.aux_adc_b1_9_2, _ad9862_regs.aux_adc_b1_1_0); - case AUX_ADC_B2: return aux_adc_to_volts(_ad9862_regs.aux_adc_b2_9_2, _ad9862_regs.aux_adc_b2_1_0); - } - UHD_ASSERT_THROW(false); + UHD_THROW_INVALID_CODE_PATH(); } /*********************************************************************** -- cgit v1.2.3 From 1c5076ea68345e74de35cad43e4a4b4adf68fa15 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 31 Mar 2011 15:00:56 -0700 Subject: uhd: implemented boost barriers on all code that creates threads The barrier ensures that the thread must spawn before the caller exits. Some of the code already used a mutex to accomplish this, however cygwin chokes when a mutex is locked twice by the same thread. Mutex implementations were replaced with the barrier implementation. Also the barrier implementation is far cleaner. --- host/lib/transport/libusb1_zero_copy.cpp | 8 ++++++-- host/lib/usrp/usrp1/soft_time_ctrl.cpp | 14 ++++++++------ host/lib/usrp/usrp2/io_impl.cpp | 25 ++++++++++++------------- host/lib/usrp/usrp_e100/io_impl.cpp | 16 +++++++++++----- 4 files changed, 37 insertions(+), 26 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 9f38ce97b..fe6936c7e 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -191,9 +192,11 @@ public: //spawn the event handler threads size_t concurrency = hints.cast("concurrency_hint", 1); + boost::barrier spawn_barrier(concurrency+1); for (size_t i = 0; i < concurrency; i++) _thread_group.create_thread( - boost::bind(&libusb_zero_copy_impl::run_event_loop, this) + boost::bind(&libusb_zero_copy_impl::run_event_loop, this, boost::ref(spawn_barrier)) ); + spawn_barrier.wait(); } ~libusb_zero_copy_impl(void){ @@ -263,7 +266,8 @@ private: boost::thread_group _thread_group; bool _threads_running; - void run_event_loop(void){ + void run_event_loop(boost::barrier &spawn_barrier){ + spawn_barrier.wait(); set_thread_priority_safe(); libusb_context *context = libusb::session::get_global_session()->get_context(); _threads_running = true; diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index e1b671811..1bab34e7b 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -43,10 +44,11 @@ public: _stream_on_off(stream_on_off) { //synchronously spawn a new thread - _update_mutex.lock(); //lock mutex before spawned - _thread_group.create_thread(boost::bind(&soft_time_ctrl_impl::recv_cmd_dispatcher, this)); - _update_mutex.lock(); //lock blocks until spawned - _update_mutex.unlock(); //unlock mutex before done + boost::barrier spawn_barrier(2); + _thread_group.create_thread(boost::bind( + &soft_time_ctrl_impl::recv_cmd_dispatcher, this, boost::ref(spawn_barrier)) + ); + spawn_barrier.wait(); //initialize the time to something this->set_time(time_spec_t(0.0)); @@ -175,8 +177,8 @@ public: _stream_mode = cmd.stream_mode; } - void recv_cmd_dispatcher(void){ - _update_mutex.unlock(); + void recv_cmd_dispatcher(boost::barrier &spawn_barrier){ + spawn_barrier.wait(); try{ boost::any cmd; while (true){ diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 340e9d155..07cbd2432 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -25,7 +25,8 @@ #include #include #include -#include +#include +#include #include using namespace uhd; @@ -209,11 +210,10 @@ struct usrp2_impl::io_impl{ vrt_packet_handler::send_state packet_handler_send_state; //methods and variables for the pirate crew - void recv_pirate_loop(usrp2_mboard_impl::sptr, zero_copy_if::sptr, size_t); + void recv_pirate_loop(boost::barrier &, usrp2_mboard_impl::sptr, zero_copy_if::sptr, size_t); boost::thread_group recv_pirate_crew; bool recv_pirate_crew_raiding; bounded_buffer async_msg_fifo; - boost::mutex spawn_mutex; }; /*********************************************************************** @@ -223,13 +223,15 @@ struct usrp2_impl::io_impl{ * - put async message packets into queue **********************************************************************/ void usrp2_impl::io_impl::recv_pirate_loop( - usrp2_mboard_impl::sptr mboard, zero_copy_if::sptr err_xport, size_t index + boost::barrier &spawn_barrier, + usrp2_mboard_impl::sptr mboard, + zero_copy_if::sptr err_xport, + size_t index ){ + spawn_barrier.wait(); set_thread_priority_safe(); recv_pirate_crew_raiding = true; - spawn_mutex.unlock(); - //store a reference to the flow control monitor (offset by max dsps) flow_control_monitor &fc_mon = *(this->fc_mons[index*usrp2_mboard_impl::MAX_NUM_DSPS]); @@ -286,19 +288,16 @@ void usrp2_impl::io_init(void){ _io_impl = UHD_PIMPL_MAKE(io_impl, (dsp_xports)); //create a new pirate thread for each zc if (yarr!!) + boost::barrier spawn_barrier(_mboards.size()+1); for (size_t i = 0; i < _mboards.size(); i++){ - //lock the unlocked mutex (non-blocking) - _io_impl->spawn_mutex.lock(); //spawn a new pirate to plunder the recv booty _io_impl->recv_pirate_crew.create_thread(boost::bind( &usrp2_impl::io_impl::recv_pirate_loop, - _io_impl.get(), _mboards.at(i), err_xports.at(i), i + _io_impl.get(), boost::ref(spawn_barrier), + _mboards.at(i), err_xports.at(i), i )); - //block here until the spawned thread unlocks - _io_impl->spawn_mutex.lock(); - //exit loop iteration in an unlocked condition - _io_impl->spawn_mutex.unlock(); } + spawn_barrier.wait(); //update mapping here since it didnt b4 when io init not called first update_xport_channel_mapping(); diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index fc6aaeaee..cbab5a761 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -23,7 +23,8 @@ #include "../../transport/vrt_packet_handler.hpp" #include #include -#include +#include +#include #include using namespace uhd; @@ -93,7 +94,7 @@ struct usrp_e100_impl::io_impl{ bool continuous_streaming; //a pirate's life is the life for me! - void recv_pirate_loop(usrp_e100_clock_ctrl::sptr); + void recv_pirate_loop(boost::barrier &, usrp_e100_clock_ctrl::sptr); bounded_buffer recv_pirate_booty; bounded_buffer async_msg_fifo; boost::thread_group recv_pirate_crew; @@ -105,8 +106,10 @@ struct usrp_e100_impl::io_impl{ * - while raiding, loot for recv buffers * - put booty into the alignment buffer **********************************************************************/ -void usrp_e100_impl::io_impl::recv_pirate_loop(usrp_e100_clock_ctrl::sptr clock_ctrl) -{ +void usrp_e100_impl::io_impl::recv_pirate_loop( + boost::barrier &spawn_barrier, usrp_e100_clock_ctrl::sptr clock_ctrl +){ + spawn_barrier.wait(); set_thread_priority_safe(); recv_pirate_crew_raiding = true; @@ -201,9 +204,12 @@ void usrp_e100_impl::io_init(void){ _iface->poke32(UE_REG_CTRL_TX_POLICY, UE_FLAG_CTRL_TX_POLICY_NEXT_PACKET); //spawn a pirate, yarrr! + boost::barrier spawn_barrier(2); _io_impl->recv_pirate_crew.create_thread(boost::bind( - &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), _clock_ctrl + &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), + boost::ref(spawn_barrier), _clock_ctrl )); + spawn_barrier.wait(); } void usrp_e100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd){ -- cgit v1.2.3