root / host / lib / usrp / usrp1 / usrp1_impl.cpp @ fe7df530
History | View | Annotate | Download (6.7 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 <boost/format.hpp> |
| 27 |
#include <boost/assign/list_of.hpp> |
| 28 |
#include <boost/filesystem.hpp> |
| 29 |
#include <iostream> |
| 30 |
|
| 31 |
using namespace uhd; |
| 32 |
using namespace uhd::usrp; |
| 33 |
using namespace uhd::transport; |
| 34 |
|
| 35 |
const std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost::assign::list_of
|
| 36 |
(usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B) |
| 37 |
; |
| 38 |
|
| 39 |
/***********************************************************************
|
| 40 |
* Discovery
|
| 41 |
**********************************************************************/
|
| 42 |
static device_addrs_t usrp1_find(const device_addr_t &hint) |
| 43 |
{
|
| 44 |
device_addrs_t usrp1_addrs; |
| 45 |
std::string filename = "/usr/local/share/usrp/rev4/std.ihx"; |
| 46 |
|
| 47 |
//return an empty list of addresses when type is set to non-usrp1
|
| 48 |
if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs; |
| 49 |
|
| 50 |
//see what we got on the USB bus
|
| 51 |
std::vector<usb_device_handle::sptr> device_list = |
| 52 |
usb_device_handle::get_device_list(); |
| 53 |
|
| 54 |
//find the usrps and load firmware
|
| 55 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 56 |
if (handle->get_vendor_id() == 0xfffe && |
| 57 |
handle->get_product_id() == 0x0002) {
|
| 58 |
|
| 59 |
usb_control::sptr ctrl_transport = usb_control::make(handle); |
| 60 |
usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport); |
| 61 |
usrp_ctrl->usrp_load_firmware(filename); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
//wait for things to settle
|
| 66 |
sleep(1);
|
| 67 |
|
| 68 |
//get descriptors again with serial number
|
| 69 |
device_list = usb_device_handle::get_device_list(); |
| 70 |
|
| 71 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 72 |
if (handle->get_vendor_id() == 0xfffe && |
| 73 |
handle->get_product_id() == 0x0002) {
|
| 74 |
|
| 75 |
device_addr_t new_addr; |
| 76 |
new_addr["type"] = "usrp1"; |
| 77 |
new_addr["serial"] = handle->get_serial();
|
| 78 |
usrp1_addrs.push_back(new_addr); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return usrp1_addrs;
|
| 83 |
} |
| 84 |
|
| 85 |
/***********************************************************************
|
| 86 |
* Make
|
| 87 |
**********************************************************************/
|
| 88 |
static device::sptr usrp1_make(const device_addr_t &device_addr) |
| 89 |
{
|
| 90 |
std::string filename;
|
| 91 |
|
| 92 |
if (device_addr.has_key("fpga")) |
| 93 |
filename = device_addr["fpga"];
|
| 94 |
else
|
| 95 |
filename = "/usr/local/share/usrp/rev4/std_2rxhb_2tx.rbf";
|
| 96 |
|
| 97 |
std::cout << "Make usrp1 with " << filename << std::endl;
|
| 98 |
|
| 99 |
//try to match the given device address with something on the USB bus
|
| 100 |
std::vector<usb_device_handle::sptr> device_list = |
| 101 |
usb_device_handle::get_device_list(); |
| 102 |
|
| 103 |
//create data and control transports
|
| 104 |
usb_zero_copy::sptr data_transport; |
| 105 |
usrp_ctrl::sptr usrp_ctrl; |
| 106 |
|
| 107 |
BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
|
| 108 |
if (handle->get_vendor_id() == 0xfffe && |
| 109 |
handle->get_product_id() == 0x0002 &&
|
| 110 |
handle->get_serial() == device_addr["serial"]) {
|
| 111 |
|
| 112 |
usb_control::sptr ctrl_transport = usb_control::make(handle); |
| 113 |
usrp_ctrl = usrp_ctrl::make(ctrl_transport); |
| 114 |
usrp_ctrl->usrp_load_fpga(filename); |
| 115 |
|
| 116 |
data_transport = usb_zero_copy::make(handle, // identifier
|
| 117 |
6, // IN endpoint |
| 118 |
2, // OUT endpoint |
| 119 |
2 * (1 << 20), // buffer size |
| 120 |
16384); // transfer size |
| 121 |
break;
|
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
//create the usrp1 implementation guts
|
| 126 |
return device::sptr(new usrp1_impl(data_transport, usrp_ctrl)); |
| 127 |
} |
| 128 |
|
| 129 |
UHD_STATIC_BLOCK(register_usrp1_device){
|
| 130 |
device::register_device(&usrp1_find, &usrp1_make); |
| 131 |
} |
| 132 |
|
| 133 |
/***********************************************************************
|
| 134 |
* Structors
|
| 135 |
**********************************************************************/
|
| 136 |
usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, |
| 137 |
usrp_ctrl::sptr ctrl_transport) |
| 138 |
: _data_transport(data_transport), _ctrl_transport(ctrl_transport) |
| 139 |
{
|
| 140 |
_iface = usrp1_iface::make(ctrl_transport); |
| 141 |
|
| 142 |
//create clock interface
|
| 143 |
_clock_ctrl = usrp1_clock_ctrl::make(_iface); |
| 144 |
|
| 145 |
//create codec interface
|
| 146 |
_codec_ctrls[DBOARD_SLOT_A] = usrp1_codec_ctrl::make( |
| 147 |
_iface, _clock_ctrl, SPI_ENABLE_CODEC_A |
| 148 |
); |
| 149 |
_codec_ctrls[DBOARD_SLOT_B] = usrp1_codec_ctrl::make( |
| 150 |
_iface, _clock_ctrl, SPI_ENABLE_CODEC_B |
| 151 |
); |
| 152 |
|
| 153 |
//initialize the codecs
|
| 154 |
codec_init(); |
| 155 |
|
| 156 |
//initialize the mboard
|
| 157 |
mboard_init(); |
| 158 |
|
| 159 |
//initialize the dboards
|
| 160 |
dboard_init(); |
| 161 |
|
| 162 |
//initialize the dsps
|
| 163 |
rx_dsp_init(); |
| 164 |
|
| 165 |
//initialize the dsps
|
| 166 |
tx_dsp_init(); |
| 167 |
|
| 168 |
//initialize the send/recv
|
| 169 |
io_init(); |
| 170 |
|
| 171 |
//turn on the transmitter
|
| 172 |
_ctrl_transport->usrp_tx_enable(true);
|
| 173 |
} |
| 174 |
|
| 175 |
usrp1_impl::~usrp1_impl(void){
|
| 176 |
/* NOP */
|
| 177 |
} |
| 178 |
|
| 179 |
/***********************************************************************
|
| 180 |
* Device Get
|
| 181 |
**********************************************************************/
|
| 182 |
void usrp1_impl::get(const wax::obj &key_, wax::obj &val) |
| 183 |
{
|
| 184 |
named_prop_t key = named_prop_t::extract(key_); |
| 185 |
|
| 186 |
//handle the get request conditioned on the key
|
| 187 |
switch(key.as<device_prop_t>()){
|
| 188 |
case DEVICE_PROP_NAME:
|
| 189 |
val = std::string("usrp1 device"); |
| 190 |
return;
|
| 191 |
|
| 192 |
case DEVICE_PROP_MBOARD:
|
| 193 |
UHD_ASSERT_THROW(key.name == "");
|
| 194 |
val = _mboard_proxy->get_link(); |
| 195 |
return;
|
| 196 |
|
| 197 |
case DEVICE_PROP_MBOARD_NAMES:
|
| 198 |
val = prop_names_t(1, ""); //vector of size 1 with empty string |
| 199 |
return;
|
| 200 |
|
| 201 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
/***********************************************************************
|
| 206 |
* Device Set
|
| 207 |
**********************************************************************/
|
| 208 |
void usrp1_impl::set(const wax::obj &, const wax::obj &) |
| 209 |
{
|
| 210 |
UHD_THROW_PROP_SET_ERROR(); |
| 211 |
} |