aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp1
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp1')
-rw-r--r--host/lib/usrp/usrp1/CMakeLists.txt4
-rw-r--r--host/lib/usrp/usrp1/codec_ctrl.cpp6
-rw-r--r--host/lib/usrp/usrp1/dsp_impl.cpp5
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp180
-rw-r--r--host/lib/usrp/usrp1/mboard_impl.cpp3
-rw-r--r--host/lib/usrp/usrp1/usrp1_ctrl.cpp422
-rw-r--r--host/lib/usrp/usrp1/usrp1_ctrl.hpp118
-rw-r--r--host/lib/usrp/usrp1/usrp1_iface.cpp6
-rw-r--r--host/lib/usrp/usrp1/usrp1_iface.hpp4
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp33
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.hpp8
11 files changed, 117 insertions, 672 deletions
diff --git a/host/lib/usrp/usrp1/CMakeLists.txt b/host/lib/usrp/usrp1/CMakeLists.txt
index 9e50f5728..c208cfe8c 100644
--- a/host/lib/usrp/usrp1/CMakeLists.txt
+++ b/host/lib/usrp/usrp1/CMakeLists.txt
@@ -25,8 +25,6 @@
LIBUHD_REGISTER_COMPONENT("USRP1" ENABLE_USRP1 ON "ENABLE_LIBUHD;ENABLE_USB" OFF)
IF(ENABLE_USRP1)
- INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../firmware/fx2/common)
-
LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/clock_ctrl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/clock_ctrl.hpp
@@ -43,7 +41,5 @@ IF(ENABLE_USRP1)
${CMAKE_CURRENT_SOURCE_DIR}/usrp1_iface.hpp
${CMAKE_CURRENT_SOURCE_DIR}/usrp1_impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usrp1_impl.hpp
- ${CMAKE_CURRENT_SOURCE_DIR}/usrp1_ctrl.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/usrp1_ctrl.hpp
)
ENDIF(ENABLE_USRP1)
diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp
index 64a93ede5..448135185 100644
--- a/host/lib/usrp/usrp1/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp1/codec_ctrl.cpp
@@ -20,6 +20,7 @@
#include "clock_ctrl.hpp"
#include "ad9862_regs.hpp"
#include <uhd/utils/log.hpp>
+#include <uhd/utils/safe_call.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -140,8 +141,7 @@ usrp1_codec_ctrl_impl::usrp1_codec_ctrl_impl(usrp1_iface::sptr iface,
this->send_reg(34);
}
-usrp1_codec_ctrl_impl::~usrp1_codec_ctrl_impl(void)
-{
+usrp1_codec_ctrl_impl::~usrp1_codec_ctrl_impl(void){UHD_SAFE_CALL(
//set aux dacs to zero
this->write_aux_dac(AUX_DAC_A, 0);
this->write_aux_dac(AUX_DAC_B, 0);
@@ -154,7 +154,7 @@ usrp1_codec_ctrl_impl::~usrp1_codec_ctrl_impl(void)
_ad9862_regs.tx_digital_pd = 1;
_ad9862_regs.tx_analog_pd = ad9862_regs_t::TX_ANALOG_PD_BOTH;
this->send_reg(8);
-}
+)}
/***********************************************************************
* Codec Control Gain Control Methods
diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp
index 66b11b989..0bddc49f0 100644
--- a/host/lib/usrp/usrp1/dsp_impl.cpp
+++ b/host/lib/usrp/usrp1/dsp_impl.cpp
@@ -114,6 +114,7 @@ void usrp1_impl::rx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh
_iface->poke32(FR_DECIM_RATE, _rx_dsp_decim/2 - 1);
this->restore_rx(s);
}
+ this->update_xport_channel_mapping(); //rate changed -> update
return;
case DSP_PROP_STREAM_CMD:
@@ -211,8 +212,10 @@ void usrp1_impl::tx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh
bool s = this->disable_tx();
_iface->poke32(FR_INTERP_RATE, _tx_dsp_interp/2 - 1);
this->restore_tx(s);
- return;
}
+ this->update_xport_channel_mapping(); //rate changed -> update
+ return;
+
default: UHD_THROW_PROP_SET_ERROR();
}
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 8ac2696eb..90ed17cd8 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -15,12 +15,15 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include "../../transport/vrt_packet_handler.hpp"
+#define SRPH_DONT_CHECK_SEQUENCE
+#include "../../transport/super_recv_packet_handler.hpp"
+#include "../../transport/super_send_packet_handler.hpp"
#include "usrp_commands.h"
#include "usrp1_impl.hpp"
#include <uhd/utils/msg.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/utils/thread_priority.hpp>
+#include <uhd/usrp/dsp_props.hpp>
#include <uhd/transport/bounded_buffer.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>
@@ -88,13 +91,39 @@ private:
};
/***********************************************************************
+ * BS VRT packer/unpacker functions (since samples don't have headers)
+ **********************************************************************/
+static void usrp1_bs_vrt_packer(
+ boost::uint32_t *,
+ vrt::if_packet_info_t &if_packet_info
+){
+ if_packet_info.num_header_words32 = 0;
+ if_packet_info.num_packet_words32 = if_packet_info.num_payload_words32;
+}
+
+static void usrp1_bs_vrt_unpacker(
+ const boost::uint32_t *,
+ vrt::if_packet_info_t &if_packet_info
+){
+ if_packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_DATA;
+ if_packet_info.num_payload_words32 = if_packet_info.num_packet_words32;
+ if_packet_info.num_header_words32 = 0;
+ if_packet_info.packet_count = 0;
+ if_packet_info.sob = false;
+ if_packet_info.eob = false;
+ if_packet_info.has_sid = false;
+ if_packet_info.has_cid = false;
+ if_packet_info.has_tsi = false;
+ if_packet_info.has_tsf = false;
+ if_packet_info.has_tlr = false;
+}
+
+/***********************************************************************
* IO Implementation Details
**********************************************************************/
struct usrp1_impl::io_impl{
io_impl(zero_copy_if::sptr data_transport):
data_transport(data_transport),
- get_recv_buffs_fcn(boost::bind(&usrp1_impl::io_impl::get_recv_buffs, this, _1)),
- get_send_buffs_fcn(boost::bind(&usrp1_impl::io_impl::get_send_buffs, this, _1)),
underflow_poll_samp_count(0),
overflow_poll_samp_count(0),
curr_buff(offset_send_buffer(data_transport->get_send_buff())),
@@ -109,16 +138,9 @@ struct usrp1_impl::io_impl{
zero_copy_if::sptr data_transport;
- //timeouts set on calls to recv/send (passed into get buffs methods)
- double recv_timeout, send_timeout;
-
- //bound callbacks for get buffs (bound once here, not in fast-path)
- vrt_packet_handler::get_recv_buffs_t get_recv_buffs_fcn;
- vrt_packet_handler::get_send_buffs_t get_send_buffs_fcn;
-
//state management for the vrt packet handler code
- vrt_packet_handler::recv_state packet_handler_recv_state;
- vrt_packet_handler::send_state packet_handler_send_state;
+ sph::recv_packet_handler recv_handler;
+ sph::send_packet_handler send_handler;
//state management for overflow and underflow
size_t underflow_poll_samp_count;
@@ -132,11 +154,13 @@ struct usrp1_impl::io_impl{
offset_managed_send_buffer omsb;
void commit_send_buff(offset_send_buffer&, offset_send_buffer&, size_t);
void flush_send_buff(void);
- bool get_send_buffs(vrt_packet_handler::managed_send_buffs_t &);
- bool get_recv_buffs(vrt_packet_handler::managed_recv_buffs_t &buffs){
- UHD_ASSERT_THROW(buffs.size() == 1);
- buffs[0] = data_transport->get_recv_buff(recv_timeout);
- return buffs[0].get() != NULL;
+ managed_send_buffer::sptr get_send_buff(double timeout){
+ //try to get a new managed buffer with timeout
+ offset_send_buffer next_buff(data_transport->get_send_buff(timeout));
+ if (not next_buff.buff.get()) return managed_send_buffer::sptr(); /* propagate timeout here */
+
+ //make a new managed buffer with the offset buffs
+ return omsb.get_new(curr_buff, next_buff);
}
};
@@ -185,32 +209,13 @@ void usrp1_impl::io_impl::flush_send_buff(void){
if (bytes_to_pad == 0) bytes_to_pad = alignment_padding;
//get the buffer, clear, and commit (really current buffer)
- vrt_packet_handler::managed_send_buffs_t buffs(1);
- if (this->get_send_buffs(buffs)){
- std::memset(buffs[0]->cast<void *>(), 0, bytes_to_pad);
- buffs[0]->commit(bytes_to_pad);
+ managed_send_buffer::sptr buff = this->get_send_buff(.1);
+ if (buff.get() != NULL){
+ std::memset(buff->cast<void *>(), 0, bytes_to_pad);
+ buff->commit(bytes_to_pad);
}
}
-/*!
- * Get a managed send buffer with the alignment padding:
- * Always grab the next send buffer so we can timeout here.
- */
-bool usrp1_impl::io_impl::get_send_buffs(
- vrt_packet_handler::managed_send_buffs_t &buffs
-){
- UHD_ASSERT_THROW(buffs.size() == 1);
-
- //try to get a new managed buffer with timeout
- offset_send_buffer next_buff(data_transport->get_send_buff(send_timeout));
- if (not next_buff.buff.get()) return false; /* propagate timeout here */
-
- //make a new managed buffer with the offset buffs
- buffs[0] = omsb.get_new(curr_buff, next_buff);
-
- return true;
-}
-
/***********************************************************************
* Initialize internals within this file
**********************************************************************/
@@ -232,6 +237,34 @@ void usrp1_impl::io_init(void){
this->enable_tx(true); //always enabled
rx_stream_on_off(false);
_io_impl->flush_send_buff();
+
+ //update mapping here since it didnt b4 when io init not called first
+ update_xport_channel_mapping();
+}
+
+void usrp1_impl::update_xport_channel_mapping(void){
+ if (_io_impl.get() == NULL) return; //not inited yet
+
+ //set all of the relevant properties on the handler
+ boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock();
+ _io_impl->recv_handler.set_vrt_unpacker(&usrp1_bs_vrt_unpacker);
+ _io_impl->recv_handler.set_tick_rate(_clock_ctrl->get_master_clock_freq());
+ _io_impl->recv_handler.set_samp_rate(_rx_dsp_proxies[_rx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());
+ _io_impl->recv_handler.set_xport_chan_get_buff(0, boost::bind(
+ &uhd::transport::zero_copy_if::get_recv_buff, _io_impl->data_transport, _1
+ ));
+ _io_impl->recv_handler.set_converter(_rx_otw_type, _rx_subdev_spec.size());
+
+ //set all of the relevant properties on the handler
+ boost::mutex::scoped_lock send_lock = _io_impl->send_handler.get_scoped_lock();
+ _io_impl->send_handler.set_vrt_packer(&usrp1_bs_vrt_packer);
+ _io_impl->send_handler.set_tick_rate(_clock_ctrl->get_master_clock_freq());
+ _io_impl->send_handler.set_samp_rate(_tx_dsp_proxies[_tx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());
+ _io_impl->send_handler.set_xport_chan_get_buff(0, boost::bind(
+ &usrp1_impl::io_impl::get_send_buff, _io_impl.get(), _1
+ ));
+ _io_impl->send_handler.set_converter(_tx_otw_type, _tx_subdev_spec.size());
+ _io_impl->send_handler.set_max_samples_per_packet(get_max_send_samps_per_packet());
}
void usrp1_impl::rx_stream_on_off(bool enb){
@@ -245,14 +278,6 @@ void usrp1_impl::rx_stream_on_off(bool enb){
/***********************************************************************
* Data send + helper functions
**********************************************************************/
-static void usrp1_bs_vrt_packer(
- boost::uint32_t *,
- vrt::if_packet_info_t &if_packet_info
-){
- if_packet_info.num_header_words32 = 0;
- if_packet_info.num_packet_words32 = if_packet_info.num_payload_words32;
-}
-
size_t usrp1_impl::get_max_send_samps_per_packet(void) const {
return (_data_transport->get_send_frame_size() - alignment_padding)
/ _tx_otw_type.get_sample_size()
@@ -261,29 +286,21 @@ size_t usrp1_impl::get_max_send_samps_per_packet(void) const {
}
size_t usrp1_impl::send(
- const send_buffs_type &buffs, size_t num_samps,
+ const send_buffs_type &buffs, size_t nsamps_per_buff,
const tx_metadata_t &metadata, const io_type_t &io_type,
send_mode_t send_mode, double timeout
){
- if (_soft_time_ctrl->send_pre(metadata, timeout)) return num_samps;
-
- _io_impl->send_timeout = timeout;
- size_t num_samps_sent = vrt_packet_handler::send(
- _io_impl->packet_handler_send_state, //last state of the send handler
- buffs, num_samps, //buffer to fill
- metadata, send_mode, //samples metadata
- io_type, _tx_otw_type, //input and output types to convert
- _clock_ctrl->get_master_clock_freq(), //master clock tick rate
- &usrp1_bs_vrt_packer,
- _io_impl->get_send_buffs_fcn,
- get_max_send_samps_per_packet(),
- 0, //vrt header offset
- _tx_subdev_spec.size() //num channels
+ if (_soft_time_ctrl->send_pre(metadata, timeout)) return 0;
+
+ size_t num_samps_sent = _io_impl->send_handler.send(
+ buffs, nsamps_per_buff,
+ metadata, io_type,
+ send_mode, timeout
);
//handle eob flag (commit the buffer, disable the DACs)
//check num samps sent to avoid flush on incomplete/timeout
- if (metadata.end_of_burst and num_samps_sent == num_samps){
+ if (metadata.end_of_burst and num_samps_sent == nsamps_per_buff){
_io_impl->flush_send_buff();
}
@@ -306,23 +323,6 @@ size_t usrp1_impl::send(
/***********************************************************************
* Data recv + helper functions
**********************************************************************/
-static void usrp1_bs_vrt_unpacker(
- const boost::uint32_t *,
- vrt::if_packet_info_t &if_packet_info
-){
- if_packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_DATA;
- if_packet_info.num_payload_words32 = if_packet_info.num_packet_words32;
- if_packet_info.num_header_words32 = 0;
- if_packet_info.packet_count = 0;
- if_packet_info.sob = false;
- if_packet_info.eob = false;
- if_packet_info.has_sid = false;
- if_packet_info.has_cid = false;
- if_packet_info.has_tsi = false;
- if_packet_info.has_tsf = false;
- if_packet_info.has_tlr = false;
-}
-
size_t usrp1_impl::get_max_recv_samps_per_packet(void) const {
return _data_transport->get_recv_frame_size()
/ _rx_otw_type.get_sample_size()
@@ -331,22 +331,14 @@ size_t usrp1_impl::get_max_recv_samps_per_packet(void) const {
}
size_t usrp1_impl::recv(
- const recv_buffs_type &buffs, size_t num_samps,
+ const recv_buffs_type &buffs, size_t nsamps_per_buff,
rx_metadata_t &metadata, const io_type_t &io_type,
recv_mode_t recv_mode, double timeout
){
- _io_impl->recv_timeout = timeout;
- size_t num_samps_recvd = vrt_packet_handler::recv(
- _io_impl->packet_handler_recv_state, //last state of the recv handler
- buffs, num_samps, //buffer to fill
- metadata, recv_mode, //samples metadata
- io_type, _rx_otw_type, //input and output types to convert
- _clock_ctrl->get_master_clock_freq(), //master clock tick rate
- &usrp1_bs_vrt_unpacker,
- _io_impl->get_recv_buffs_fcn,
- &vrt_packet_handler::handle_overflow_nop,
- 0, //vrt header offset
- _rx_subdev_spec.size() //num channels
+ size_t num_samps_recvd = _io_impl->recv_handler.recv(
+ buffs, nsamps_per_buff,
+ metadata, io_type,
+ recv_mode, timeout
);
_soft_time_ctrl->recv_post(metadata, num_samps_recvd);
diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp
index f699c8e12..a265a5089 100644
--- a/host/lib/usrp/usrp1/mboard_impl.cpp
+++ b/host/lib/usrp/usrp1/mboard_impl.cpp
@@ -352,6 +352,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
bool s = this->disable_rx();
_iface->poke32(FR_RX_MUX, calc_rx_mux(_rx_subdev_spec, _mboard_proxy->get_link()));
this->restore_rx(s);
+ this->update_xport_channel_mapping();
}return;
case MBOARD_PROP_TX_SUBDEV_SPEC:{
@@ -367,6 +368,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
bool s = this->disable_tx();
_iface->poke32(FR_TX_MUX, calc_tx_mux(_tx_subdev_spec, _mboard_proxy->get_link()));
this->restore_tx(s);
+ this->update_xport_channel_mapping();
}return;
case MBOARD_PROP_EEPROM_MAP:
@@ -387,6 +389,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
<< "See the application notes for USRP1 for further instructions.\n"
;
_clock_ctrl->set_master_clock_freq(val.as<double>());
+ this->update_xport_channel_mapping();
return;
case MBOARD_PROP_CLOCK_CONFIG:{
diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp
deleted file mode 100644
index 2e6f6e014..000000000
--- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp
+++ /dev/null
@@ -1,422 +0,0 @@
-//
-// 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
-// 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 <http://www.gnu.org/licenses/>.
-//
-
-#include "usrp1_ctrl.hpp"
-#include "usrp_commands.h"
-#include <uhd/utils/msg.hpp>
-#include <uhd/exception.hpp>
-#include <uhd/transport/usb_control.hpp>
-#include <boost/functional/hash.hpp>
-#include <boost/thread/thread.hpp>
-#include <fstream>
-#include <sstream>
-#include <string>
-#include <vector>
-#include <cstring>
-
-using namespace uhd;
-
-#define FX2_FIRMWARE_LOAD 0xa0
-
-static const bool load_img_msg = true;
-
-/***********************************************************************
- * Helper Functions
- **********************************************************************/
-/*!
- * Create a file hash
- * The hash will be used to identify the loaded firmware and fpga image
- * \param filename file used to generate hash value
- * \return hash value in a size_t type
- */
-static size_t generate_hash(const char *filename)
-{
- std::ifstream file(filename);
- if (not file){
- throw uhd::io_error(std::string("cannot open input file ") + filename);
- }
-
- size_t hash = 0;
-
- char ch;
- while (file.get(ch)) {
- boost::hash_combine(hash, ch);
- }
-
- if (not file.eof()){
- throw uhd::io_error(std::string("file error ") + filename);
- }
-
- file.close();
- return hash;
-}
-
-
-/*!
- * Verify checksum of a Intel HEX record
- * \param record a line from an Intel HEX file
- * \return true if record is valid, false otherwise
- */
-static bool checksum(std::string *record)
-{
-
- size_t len = record->length();
- unsigned int i;
- unsigned char sum = 0;
- unsigned int val;
-
- for (i = 1; i < len; i += 2) {
- std::istringstream(record->substr(i, 2)) >> std::hex >> val;
- sum += val;
- }
-
- if (sum == 0)
- return true;
- else
- return false;
-}
-
-
-/*!
- * Parse Intel HEX record
- *
- * \param record a line from an Intel HEX file
- * \param len output length of record
- * \param addr output address
- * \param type output type
- * \param data output data
- * \return true if record is sucessfully read, false on error
- */
-bool parse_record(std::string *record, unsigned int &len,
- unsigned int &addr, unsigned int &type,
- unsigned char* data)
-{
- unsigned int i;
- std::string _data;
- unsigned int val;
-
- if (record->substr(0, 1) != ":")
- return false;
-
- std::istringstream(record->substr(1, 2)) >> std::hex >> len;
- std::istringstream(record->substr(3, 4)) >> std::hex >> addr;
- std::istringstream(record->substr(7, 2)) >> std::hex >> type;
-
- for (i = 0; i < len; i++) {
- std::istringstream(record->substr(9 + 2 * i, 2)) >> std::hex >> val;
- data[i] = (unsigned char) val;
- }
-
- return true;
-}
-
-
-/*!
- * USRP control implementation for device discovery and configuration
- */
-class usrp_ctrl_impl : public usrp_ctrl {
-public:
- usrp_ctrl_impl(uhd::transport::usb_control::sptr ctrl_transport)
- {
- _ctrl_transport = ctrl_transport;
- }
-
- void usrp_load_firmware(std::string filestring, bool force)
- {
- const char *filename = filestring.c_str();
-
- size_t hash = generate_hash(filename);
-
- size_t loaded_hash; usrp_get_firmware_hash(loaded_hash);
-
- if (not force and (hash == loaded_hash)) return;
-
- //FIXME: verify types
- unsigned int len;
- unsigned int addr;
- unsigned int type;
- unsigned char data[512];
-
- std::ifstream file;
- file.open(filename, std::ifstream::in);
-
- if (!file.good()) {
- throw uhd::io_error("usrp_load_firmware: cannot open firmware input file");
- }
-
- unsigned char reset_y = 1;
- unsigned char reset_n = 0;
-
- //hit the reset line
- if (load_img_msg) UHD_MSG(status) << "Loading firmware image: " << filestring << "..." << std::flush;
- usrp_control_write(FX2_FIRMWARE_LOAD, 0xe600, 0, &reset_y, 1);
-
- while (!file.eof()) {
- std::string record;
- file >> record;
-
- //check for valid record
- if (not checksum(&record) or not parse_record(&record, len, addr, type, data)) {
- throw uhd::io_error("usrp_load_firmware: bad record checksum");
- }
-
- //type 0x00 is data
- if (type == 0x00) {
- int ret = usrp_control_write(FX2_FIRMWARE_LOAD, addr, 0, data, len);
- if (ret < 0) throw uhd::io_error("usrp_load_firmware: usrp_control_write failed");
- }
- //type 0x01 is end
- else if (type == 0x01) {
- usrp_set_firmware_hash(hash); //set hash before reset
- usrp_control_write(FX2_FIRMWARE_LOAD, 0xe600, 0, &reset_n, 1);
- file.close();
-
- //wait for things to settle
- boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
- if (load_img_msg) UHD_MSG(status) << " done" << std::endl;
- return;
- }
- //type anything else is unhandled
- else {
- throw uhd::io_error("usrp_load_firmware: unsupported record");
- }
- }
-
- //file did not end
- throw uhd::io_error("usrp_load_firmware: bad record");
- }
-
- void usrp_init(void){
- //disable
- usrp_rx_enable(false);
- usrp_tx_enable(false);
-
- //toggle resets
- usrp_rx_reset(true);
- usrp_tx_reset(true);
- usrp_rx_reset(false);
- usrp_tx_reset(false);
- }
-
- void usrp_load_fpga(std::string filestring)
- {
- const char *filename = filestring.c_str();
-
- size_t hash = generate_hash(filename);
-
- size_t loaded_hash; usrp_get_fpga_hash(loaded_hash);
-
- if (hash == loaded_hash) return;
- const int ep0_size = 64;
- unsigned char buf[ep0_size];
-
- if (load_img_msg) UHD_MSG(status) << "Loading FPGA image: " << filestring << "..." << std::flush;
- std::ifstream file;
- file.open(filename, std::ios::in | std::ios::binary);
- if (not file.good()) {
- throw uhd::io_error("usrp_load_fpga: cannot open fpga input file");
- }
-
- usrp_fpga_reset(true); //holding the fpga in reset while loading
-
- if (usrp_control_write_cmd(VRQ_FPGA_LOAD, 0, FL_BEGIN) < 0) {
- throw uhd::io_error("usrp_load_fpga: fpga load error");
- }
-
- while (not file.eof()) {
- file.read((char *)buf, sizeof(buf));
- size_t n = file.gcount();
- int ret = usrp_control_write(VRQ_FPGA_LOAD, 0, FL_XFER, buf, n);
- if (ret < 0 or size_t(ret) != n) {
- throw uhd::io_error("usrp_load_fpga: fpga load error");
- }
- }
-
- if (usrp_control_write_cmd(VRQ_FPGA_LOAD, 0, FL_END) < 0) {
- throw uhd::io_error("usrp_load_fpga: fpga load error");
- }
-
- usrp_set_fpga_hash(hash);
-
- usrp_fpga_reset(false); //done loading, take fpga out of reset
-
- file.close();
- if (load_img_msg) UHD_MSG(status) << " done" << std::endl;
- }
-
- void usrp_load_eeprom(std::string filestring)
- {
- const char *filename = filestring.c_str();
- const boost::uint16_t i2c_addr = 0x50;
-
- //FIXME: verify types
- int len;
- unsigned int addr;
- unsigned char data[256];
- unsigned char sendbuf[17];
-
- std::ifstream file;
- file.open(filename, std::ifstream::in);
-
- if (not file.good()) {
- throw uhd::io_error("usrp_load_eeprom: cannot open EEPROM input file");
- }
-
- file.read((char *)data, 256);
- len = file.gcount();
-
- if(len == 256) {
- throw uhd::io_error("usrp_load_eeprom: image size too large");
- }
-
- const int pagesize = 16;
- addr = 0;
- while(len > 0) {
- sendbuf[0] = addr;
- memcpy(sendbuf+1, &data[addr], len > pagesize ? pagesize : len);
- int ret = usrp_i2c_write(i2c_addr, sendbuf, (len > pagesize ? pagesize : len)+1);
- if (ret < 0) {
- throw uhd::io_error("usrp_load_eeprom: usrp_i2c_write failed");
- }
- addr += pagesize;
- len -= pagesize;
- boost::this_thread::sleep(boost::posix_time::milliseconds(100));
- }
- file.close();
- }
-
-
- void usrp_set_led(int led_num, bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_SET_LED, on, led_num) >= 0);
- }
-
-
- void usrp_get_firmware_hash(size_t &hash)
- {
- UHD_ASSERT_THROW(usrp_control_read(0xa0, USRP_HASH_SLOT_0_ADDR, 0,
- (unsigned char*) &hash, sizeof(size_t)) >= 0);
- }
-
-
- void usrp_set_firmware_hash(size_t hash)
- {
- UHD_ASSERT_THROW(usrp_control_write(0xa0, USRP_HASH_SLOT_0_ADDR, 0,
- (unsigned char*) &hash, sizeof(size_t)) >= 0);
-
- }
-
-
- void usrp_get_fpga_hash(size_t &hash)
- {
- UHD_ASSERT_THROW(usrp_control_read(0xa0, USRP_HASH_SLOT_1_ADDR, 0,
- (unsigned char*) &hash, sizeof(size_t)) >= 0);
- }
-
-
- void usrp_set_fpga_hash(size_t hash)
- {
- UHD_ASSERT_THROW(usrp_control_write(0xa0, USRP_HASH_SLOT_1_ADDR, 0,
- (unsigned char*) &hash, sizeof(size_t)) >= 0);
- }
-
- void usrp_tx_enable(bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_FPGA_SET_TX_ENABLE, on, 0) >= 0);
- }
-
-
- void usrp_rx_enable(bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_FPGA_SET_RX_ENABLE, on, 0) >= 0);
- }
-
-
- void usrp_tx_reset(bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_FPGA_SET_TX_RESET, on, 0) >= 0);
- }
-
-
- void usrp_rx_reset(bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_FPGA_SET_RX_RESET, on, 0) >= 0);
- }
-
- void usrp_fpga_reset(bool on)
- {
- UHD_ASSERT_THROW(usrp_control_write_cmd(VRQ_FPGA_SET_RESET, on, 0) >= 0);
- }
-
- int usrp_control_write(boost::uint8_t request,
- boost::uint16_t value,
- boost::uint16_t index,
- unsigned char *buff,
- boost::uint16_t length)
- {
- return _ctrl_transport->submit(VRT_VENDOR_OUT, // bmReqeustType
- request, // bRequest
- value, // wValue
- index, // wIndex
- buff, // data
- length); // wLength
- }
-
-
- int usrp_control_read(boost::uint8_t request,
- boost::uint16_t value,
- boost::uint16_t index,
- unsigned char *buff,
- boost::uint16_t length)
- {
- return _ctrl_transport->submit(VRT_VENDOR_IN, // bmReqeustType
- request, // bRequest
- value, // wValue
- index, // wIndex
- buff, // data
- length); // wLength
- }
-
-
- int usrp_control_write_cmd(boost::uint8_t request, boost::uint16_t value, boost::uint16_t index)
- {
- return usrp_control_write(request, value, index, 0, 0);
- }
-
- int usrp_i2c_write(boost::uint16_t i2c_addr, unsigned char *buf, boost::uint16_t len)
- {
- return usrp_control_write(VRQ_I2C_WRITE, i2c_addr, 0, buf, len);
- }
-
- int usrp_i2c_read(boost::uint16_t i2c_addr, unsigned char *buf, boost::uint16_t len)
- {
- return usrp_control_read(VRQ_I2C_READ, i2c_addr, 0, buf, len);
- }
-
-
-
-private:
- uhd::transport::usb_control::sptr _ctrl_transport;
-};
-
-/***********************************************************************
- * Public make function for usrp_ctrl interface
- **********************************************************************/
-usrp_ctrl::sptr usrp_ctrl::make(uhd::transport::usb_control::sptr ctrl_transport){
- return sptr(new usrp_ctrl_impl(ctrl_transport));
-}
-
diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.hpp b/host/lib/usrp/usrp1/usrp1_ctrl.hpp
deleted file mode 100644
index a6e4ffba7..000000000
--- a/host/lib/usrp/usrp1/usrp1_ctrl.hpp
+++ /dev/null
@@ -1,118 +0,0 @@
-//
-// 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
-// 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 <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_USRP_CTRL_HPP
-#define INCLUDED_USRP_CTRL_HPP
-
-#include <uhd/transport/usb_control.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-
-class usrp_ctrl : boost::noncopyable{
-public:
- typedef boost::shared_ptr<usrp_ctrl> sptr;
-
- /*!
- * Make a usrp control object from a control transport
- * \param ctrl_transport a USB control transport
- * \return a new usrp control object
- */
- static sptr make(uhd::transport::usb_control::sptr ctrl_transport);
-
- //! Call init after the fpga is loaded
- virtual void usrp_init(void) = 0;
-
- /*!
- * Load firmware in Intel HEX Format onto device
- * \param filename name of firmware file
- * \param force reload firmware if already loaded
- */
- virtual void usrp_load_firmware(std::string filename,
- bool force = false) = 0;
-
- /*!
- * Load fpga file onto usrp
- * \param filename name of fpga image
- */
- virtual void usrp_load_fpga(std::string filename) = 0;
-
- /*!
- * Load USB descriptor file in Intel HEX format into EEPROM
- * \param filename name of EEPROM image
- */
- virtual void usrp_load_eeprom(std::string filestring) = 0;
-
- /*!
- * Submit an IN transfer
- * \param request device specific request
- * \param value device specific field
- * \param index device specific field
- * \param buff buffer to place data
- * \return number of bytes read or error
- */
- virtual int usrp_control_read(boost::uint8_t request,
- boost::uint16_t value,
- boost::uint16_t index,
- unsigned char *buff,
- boost::uint16_t length) = 0;
-
- /*!
- * Submit an OUT transfer
- * \param request device specific request
- * \param value device specific field
- * \param index device specific field
- * \param buff buffer of data to be sent
- * \return number of bytes written or error
- */
- virtual int usrp_control_write(boost::uint8_t request,
- boost::uint16_t value,
- boost::uint16_t index,
- unsigned char *buff,
- boost::uint16_t length) = 0;
-
- /*!
- * Perform an I2C write
- * \param i2c_addr I2C device address
- * \param buf data to be written
- * \param len length of data in bytes
- * \return number of bytes written or error
- */
-
- virtual int usrp_i2c_write(boost::uint16_t i2c_addr,
- unsigned char *buf,
- boost::uint16_t len) = 0;
-
- /*!
- * Perform an I2C read
- * \param i2c_addr I2C device address
- * \param buf data to be read
- * \param len length of data in bytes
- * \return number of bytes read or error
- */
-
- virtual int usrp_i2c_read(boost::uint16_t i2c_addr,
- unsigned char *buf,
- boost::uint16_t len) = 0;
-
- //! enable/disable the rx path
- virtual void usrp_rx_enable(bool on) = 0;
-
- //! enable/disable the tx path
- virtual void usrp_tx_enable(bool on) = 0;
-};
-
-#endif /* INCLUDED_USRP_CTRL_HPP */
diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp
index 0942e2613..8877f19db 100644
--- a/host/lib/usrp/usrp1/usrp1_iface.cpp
+++ b/host/lib/usrp/usrp1/usrp1_iface.cpp
@@ -33,7 +33,7 @@ public:
/*******************************************************************
* Structors
******************************************************************/
- usrp1_iface_impl(usrp_ctrl::sptr ctrl_transport)
+ usrp1_iface_impl(uhd::usrp::fx2_ctrl::sptr ctrl_transport)
{
_ctrl_transport = ctrl_transport;
mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_B000);
@@ -287,13 +287,13 @@ public:
}
private:
- usrp_ctrl::sptr _ctrl_transport;
+ uhd::usrp::fx2_ctrl::sptr _ctrl_transport;
};
/***********************************************************************
* Public Make Function
**********************************************************************/
-usrp1_iface::sptr usrp1_iface::make(usrp_ctrl::sptr ctrl_transport)
+usrp1_iface::sptr usrp1_iface::make(uhd::usrp::fx2_ctrl::sptr ctrl_transport)
{
return sptr(new usrp1_iface_impl(ctrl_transport));
}
diff --git a/host/lib/usrp/usrp1/usrp1_iface.hpp b/host/lib/usrp/usrp1/usrp1_iface.hpp
index 2ebcdbacc..c374149fa 100644
--- a/host/lib/usrp/usrp1/usrp1_iface.hpp
+++ b/host/lib/usrp/usrp1/usrp1_iface.hpp
@@ -21,7 +21,7 @@
#include <uhd/usrp/mboard_iface.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
-#include "usrp1_ctrl.hpp"
+#include "fx2_ctrl.hpp"
/*!
* The usrp1 interface class:
@@ -40,7 +40,7 @@ public:
* \param ctrl_transport the usrp controller object
* \return a new usrp1 interface object
*/
- static sptr make(usrp_ctrl::sptr ctrl_transport);
+ static sptr make(uhd::usrp::fx2_ctrl::sptr ctrl_transport);
/*!
* Perform a general USB firmware OUT operation
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index b1fa986d1..a3d502038 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -16,7 +16,6 @@
//
#include "usrp1_impl.hpp"
-#include "usrp1_ctrl.hpp"
#include "fpga_regs_standard.h"
#include "usrp_spi_defs.h"
#include <uhd/utils/log.hpp>
@@ -90,7 +89,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
try{control = usb_control::make(handle);}
catch(const uhd::exception &){continue;} //ignore claimed
- usrp_ctrl::make(control)->usrp_load_firmware(usrp1_fw_image);
+ fx2_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
@@ -102,7 +101,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
try{control = usb_control::make(handle);}
catch(const uhd::exception &){continue;} //ignore claimed
- usrp1_iface::sptr iface = usrp1_iface::make(usrp_ctrl::make(control));
+ usrp1_iface::sptr iface = usrp1_iface::make(fx2_ctrl::make(control));
device_addr_t new_addr;
new_addr["type"] = "usrp1";
new_addr["name"] = iface->mb_eeprom["name"];
@@ -147,7 +146,7 @@ static device::sptr usrp1_make(const device_addr_t &device_addr){
//create control objects and a data transport
usb_control::sptr ctrl_transport = usb_control::make(handle);
- usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport);
+ fx2_ctrl::sptr usrp_ctrl = fx2_ctrl::make(ctrl_transport);
usrp_ctrl->usrp_load_fpga(usrp1_fpga_image);
usrp_ctrl->usrp_init();
usb_zero_copy::sptr data_transport = usb_zero_copy::make(
@@ -169,7 +168,7 @@ UHD_STATIC_BLOCK(register_usrp1_device){
* Structors
**********************************************************************/
usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
- usrp_ctrl::sptr ctrl_transport)
+ uhd::usrp::fx2_ctrl::sptr ctrl_transport)
: _data_transport(data_transport), _ctrl_transport(ctrl_transport)
{
_iface = usrp1_iface::make(ctrl_transport);
@@ -200,29 +199,19 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
//initialize the dsps
tx_dsp_init();
- //initialize the send/recv
- io_init();
-
//init the subdev specs
this->mboard_set(MBOARD_PROP_RX_SUBDEV_SPEC, subdev_spec_t());
this->mboard_set(MBOARD_PROP_TX_SUBDEV_SPEC, subdev_spec_t());
-}
-usrp1_impl::~usrp1_impl(void){
- UHD_SAFE_CALL(this->enable_rx(false);)
- UHD_SAFE_CALL(this->enable_tx(false);)
- //Safely destruct all RAII objects in a device.
- //This prevents the mboard deconstructor from throwing,
- //which allows the device to be safely deconstructed.
- BOOST_FOREACH(dboard_slot_t slot, _dboard_slots){
- UHD_SAFE_CALL(_dboard_managers[slot].reset();)
- UHD_SAFE_CALL(_dboard_ifaces[slot].reset();)
- UHD_SAFE_CALL(_codec_ctrls[slot].reset();)
- }
- UHD_SAFE_CALL(_clock_ctrl.reset();)
- UHD_SAFE_CALL(_io_impl.reset();)
+ //initialize the send/recv
+ io_init();
}
+usrp1_impl::~usrp1_impl(void){UHD_SAFE_CALL(
+ this->enable_rx(false);
+ this->enable_tx(false);
+)}
+
bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, double timeout){
//dummy fill-in for the recv_async_msg
boost::this_thread::sleep(boost::posix_time::microseconds(long(timeout*1e6)));
diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp
index a4d40a54d..bea1dbe3b 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.hpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.hpp
@@ -16,7 +16,6 @@
//
#include "usrp1_iface.hpp"
-#include "usrp1_ctrl.hpp"
#include "clock_ctrl.hpp"
#include "codec_ctrl.hpp"
#include "soft_time_ctrl.hpp"
@@ -75,7 +74,7 @@ public:
//structors
usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
- usrp_ctrl::sptr ctrl_transport);
+ uhd::usrp::fx2_ctrl::sptr ctrl_transport);
~usrp1_impl(void);
@@ -115,6 +114,9 @@ private:
const uhd::usrp::dboard_id_t &rx_dboard_id
);
+ //!call when the channel mapping is changed
+ void update_xport_channel_mapping(void);
+
//soft time control emulation
uhd::usrp::soft_time_ctrl::sptr _soft_time_ctrl;
@@ -197,7 +199,7 @@ private:
//transports
uhd::transport::usb_zero_copy::sptr _data_transport;
- usrp_ctrl::sptr _ctrl_transport;
+ uhd::usrp::fx2_ctrl::sptr _ctrl_transport;
//capabilities
size_t get_num_ducs(void);