root / host / lib / usrp / usrp1 / usrp1_impl.cpp @ b96088b6
History | View | Annotate | Download (7.4 kB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include "usrp1_impl.hpp" |
| 19 |
#include "usrp1_ctrl.hpp" |
| 20 |
#include "fpga_regs_standard.h" |
| 21 |
#include "usrp_spi_defs.h" |
| 22 |
#include <uhd/transport/usb_control.hpp> |
| 23 |
#include <uhd/usrp/device_props.hpp> |
| 24 |
#include <uhd/utils/assert.hpp> |
| 25 |
#include <uhd/utils/static.hpp> |
| 26 |
#include <uhd/utils/images.hpp> |
| 27 |
#include <boost/format.hpp> |
| 28 |
#include <boost/assign/list_of.hpp> |
| 29 |
#include <boost/filesystem.hpp> |
| 30 |
#include <boost/thread/thread.hpp> |
| 31 |
#include <iostream> |
| 32 |
|
| 33 |
using namespace uhd; |
| 34 |
using namespace uhd::usrp; |
| 35 |
using namespace uhd::transport; |
| 36 |
|
| 37 |
const boost::uint16_t USRP1_VENDOR_ID = 0xfffe; |
| 38 |
const boost::uint16_t USRP1_PRODUCT_ID = 0x0002; |
| 39 |
const boost::uint16_t FX2_VENDOR_ID = 0x04b4; |
| 40 |
const boost::uint16_t FX2_PRODUCT_ID = 0x8613; |
| 41 |
|
| 42 |
const std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost::assign::list_of
|
| 43 |
(usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B) |
| 44 |
; |
| 45 |
|
| 46 |
/***********************************************************************
|
| 47 |
* Discovery
|
| 48 |
**********************************************************************/
|
| 49 |
static device_addrs_t usrp1_find(const device_addr_t &hint) |
| 50 |
{
|
| 51 |
device_addrs_t usrp1_addrs; |
| 52 |
|
| 53 |
//return an empty list of addresses when type is set to non-usrp1
|
| 54 |
if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs; |
| 55 |
|
| 56 |
//extract the firmware path for the USRP1
|
| 57 |
std::string usrp1_fw_image = find_image_path(
|
| 58 |
hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx" |
| 59 |
); |
| 60 |
std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
|
| 61 |
|
| 62 |
boost::uint16_t vid = hint.has_key("uninit") ? FX2_VENDOR_ID : USRP1_VENDOR_ID;
|
| 63 |
boost::uint16_t pid = hint.has_key("uninit") ? FX2_PRODUCT_ID : USRP1_PRODUCT_ID;
|
| 64 |
|
| 65 |
//see what we got on the USB bus
|
| 66 |
std::vector<usb_device_handle::sptr> device_list = |
| 67 |
usb_device_handle::get_device_list(vid, pid); |
| 68 |
|
| 69 |
if(device_list.size() == 0) return usrp1_addrs; //return nothing if no USRPs found |
| 70 |
|
| 71 |
//find the usrps and load firmware
|
| 72 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 73 |
usb_control::sptr ctrl_transport = usb_control::make(handle); |
| 74 |
usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport); |
| 75 |
usrp_ctrl->usrp_load_firmware(usrp1_fw_image); |
| 76 |
} |
| 77 |
|
| 78 |
//get descriptors again with serial number, but using the initialized VID/PID now since we have firmware
|
| 79 |
vid = USRP1_VENDOR_ID; |
| 80 |
pid = USRP1_PRODUCT_ID; |
| 81 |
device_list = usb_device_handle::get_device_list(vid, pid); |
| 82 |
|
| 83 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 84 |
device_addr_t new_addr; |
| 85 |
new_addr["type"] = "usrp1"; |
| 86 |
new_addr["serial"] = handle->get_serial();
|
| 87 |
usrp1_addrs.push_back(new_addr); |
| 88 |
} |
| 89 |
|
| 90 |
return usrp1_addrs;
|
| 91 |
} |
| 92 |
|
| 93 |
/***********************************************************************
|
| 94 |
* Make
|
| 95 |
**********************************************************************/
|
| 96 |
static device::sptr usrp1_make(const device_addr_t &device_addr) |
| 97 |
{
|
| 98 |
//extract the FPGA path for the USRP1
|
| 99 |
std::string usrp1_fpga_image = find_image_path(
|
| 100 |
device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf" |
| 101 |
); |
| 102 |
std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
|
| 103 |
|
| 104 |
//try to match the given device address with something on the USB bus
|
| 105 |
std::vector<usb_device_handle::sptr> device_list = |
| 106 |
usb_device_handle::get_device_list(USRP1_VENDOR_ID, USRP1_PRODUCT_ID); |
| 107 |
|
| 108 |
//create data and control transports
|
| 109 |
usb_zero_copy::sptr data_transport; |
| 110 |
usrp_ctrl::sptr usrp_ctrl; |
| 111 |
|
| 112 |
|
| 113 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 114 |
if (handle->get_serial() == device_addr["serial"]) { |
| 115 |
usb_control::sptr ctrl_transport = usb_control::make(handle); |
| 116 |
usrp_ctrl = usrp_ctrl::make(ctrl_transport); |
| 117 |
usrp_ctrl->usrp_load_fpga(usrp1_fpga_image); |
| 118 |
|
| 119 |
data_transport = usb_zero_copy::make(handle, // identifier
|
| 120 |
6, // IN endpoint |
| 121 |
2, // OUT endpoint |
| 122 |
2 * (1 << 20), // buffer size |
| 123 |
16384); // transfer size |
| 124 |
break;
|
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
//create the usrp1 implementation guts
|
| 129 |
return device::sptr(new usrp1_impl(data_transport, usrp_ctrl)); |
| 130 |
} |
| 131 |
|
| 132 |
UHD_STATIC_BLOCK(register_usrp1_device){
|
| 133 |
device::register_device(&usrp1_find, &usrp1_make); |
| 134 |
} |
| 135 |
|
| 136 |
/***********************************************************************
|
| 137 |
* Structors
|
| 138 |
**********************************************************************/
|
| 139 |
usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, |
| 140 |
usrp_ctrl::sptr ctrl_transport) |
| 141 |
: _data_transport(data_transport), _ctrl_transport(ctrl_transport) |
| 142 |
{
|
| 143 |
_iface = usrp1_iface::make(ctrl_transport); |
| 144 |
|
| 145 |
//create clock interface
|
| 146 |
_clock_ctrl = usrp1_clock_ctrl::make(_iface); |
| 147 |
|
| 148 |
//create codec interface
|
| 149 |
_codec_ctrls[DBOARD_SLOT_A] = usrp1_codec_ctrl::make( |
| 150 |
_iface, _clock_ctrl, SPI_ENABLE_CODEC_A |
| 151 |
); |
| 152 |
_codec_ctrls[DBOARD_SLOT_B] = usrp1_codec_ctrl::make( |
| 153 |
_iface, _clock_ctrl, SPI_ENABLE_CODEC_B |
| 154 |
); |
| 155 |
|
| 156 |
//initialize the codecs
|
| 157 |
codec_init(); |
| 158 |
|
| 159 |
//initialize the mboard
|
| 160 |
mboard_init(); |
| 161 |
|
| 162 |
//initialize the dboards
|
| 163 |
dboard_init(); |
| 164 |
|
| 165 |
//initialize the dsps
|
| 166 |
rx_dsp_init(); |
| 167 |
|
| 168 |
//initialize the dsps
|
| 169 |
tx_dsp_init(); |
| 170 |
|
| 171 |
//initialize the send/recv
|
| 172 |
io_init(); |
| 173 |
|
| 174 |
//turn on the transmitter
|
| 175 |
_ctrl_transport->usrp_tx_enable(true);
|
| 176 |
} |
| 177 |
|
| 178 |
usrp1_impl::~usrp1_impl(void){
|
| 179 |
/* NOP */
|
| 180 |
} |
| 181 |
|
| 182 |
bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, size_t timeout_ms){
|
| 183 |
//dummy fill-in for the recv_async_msg
|
| 184 |
boost::this_thread::sleep(boost::posix_time::milliseconds(timeout_ms)); |
| 185 |
return false; |
| 186 |
} |
| 187 |
|
| 188 |
/***********************************************************************
|
| 189 |
* Device Get
|
| 190 |
**********************************************************************/
|
| 191 |
void usrp1_impl::get(const wax::obj &key_, wax::obj &val) |
| 192 |
{
|
| 193 |
named_prop_t key = named_prop_t::extract(key_); |
| 194 |
|
| 195 |
//handle the get request conditioned on the key
|
| 196 |
switch(key.as<device_prop_t>()){
|
| 197 |
case DEVICE_PROP_NAME:
|
| 198 |
val = std::string("usrp1 device"); |
| 199 |
return;
|
| 200 |
|
| 201 |
case DEVICE_PROP_MBOARD:
|
| 202 |
UHD_ASSERT_THROW(key.name == "");
|
| 203 |
val = _mboard_proxy->get_link(); |
| 204 |
return;
|
| 205 |
|
| 206 |
case DEVICE_PROP_MBOARD_NAMES:
|
| 207 |
val = prop_names_t(1, ""); //vector of size 1 with empty string |
| 208 |
return;
|
| 209 |
|
| 210 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
/***********************************************************************
|
| 215 |
* Device Set
|
| 216 |
**********************************************************************/
|
| 217 |
void usrp1_impl::set(const wax::obj &, const wax::obj &) |
| 218 |
{
|
| 219 |
UHD_THROW_PROP_SET_ERROR(); |
| 220 |
} |