Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / usrp1_impl.cpp @ 80fe3189

History | View | Annotate | Download (7.6 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/usrp/mboard_props.hpp>
25
#include <uhd/utils/warning.hpp>
26
#include <uhd/utils/assert.hpp>
27
#include <uhd/utils/static.hpp>
28
#include <uhd/utils/images.hpp>
29
#include <boost/format.hpp>
30
#include <boost/assign/list_of.hpp>
31
#include <boost/filesystem.hpp>
32
#include <boost/thread/thread.hpp>
33
#include <iostream>
34

    
35
using namespace uhd;
36
using namespace uhd::usrp;
37
using namespace uhd::transport;
38

    
39
const std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost::assign::list_of
40
    (usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B)
41
;
42

    
43
/***********************************************************************
44
 * Discovery
45
 **********************************************************************/
46
static device_addrs_t usrp1_find(const device_addr_t &hint)
47
{
48
    device_addrs_t usrp1_addrs;
49

    
50
    //return an empty list of addresses when type is set to non-usrp1
51
    if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs;
52

    
53
    //extract the firmware path for the USRP1
54
    std::string usrp1_fw_image;
55
    try{
56
        usrp1_fw_image = find_image_path(
57
            hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx"
58
        );
59
    }
60
    catch(const std::exception &e){
61
        uhd::print_warning(
62
            "Could not locate USRP1 firmware.\n"
63
            "Please install the images package.\n"
64
        );
65
        return usrp1_addrs;
66
    }
67
    std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
68

    
69
    //see what we got on the USB bus
70
    std::vector<usb_device_handle::sptr> device_list =
71
        usb_device_handle::get_device_list();
72

    
73
    //find the usrps and load firmware
74
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
75
        if (handle->get_vendor_id() == 0xfffe &&
76
            handle->get_product_id() == 0x0002) {
77

    
78
            usb_control::sptr ctrl_transport = usb_control::make(handle);
79
            usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport);
80
            usrp_ctrl->usrp_load_firmware(usrp1_fw_image);
81
        }
82
    }
83

    
84
    //get descriptors again with serial number
85
    device_list = usb_device_handle::get_device_list();
86

    
87
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
88
        if (handle->get_vendor_id() == 0xfffe &&
89
            handle->get_product_id() == 0x0002) {
90

    
91
            device_addr_t new_addr;
92
            new_addr["type"] = "usrp1";
93
            new_addr["serial"] = handle->get_serial();
94
            usrp1_addrs.push_back(new_addr);
95
        }
96
    }
97

    
98
    return usrp1_addrs;
99
}
100

    
101
/***********************************************************************
102
 * Make
103
 **********************************************************************/
104
static device::sptr usrp1_make(const device_addr_t &device_addr)
105
{
106
    //extract the FPGA path for the USRP1
107
    std::string usrp1_fpga_image = find_image_path(
108
        device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf"
109
    );
110
    std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
111

    
112
    //try to match the given device address with something on the USB bus
113
    std::vector<usb_device_handle::sptr> device_list =
114
        usb_device_handle::get_device_list();
115

    
116
    //create data and control transports
117
    usb_zero_copy::sptr data_transport;
118
    usrp_ctrl::sptr usrp_ctrl;
119

    
120
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
121
        if (handle->get_vendor_id() == 0xfffe &&
122
            handle->get_product_id() == 0x0002 &&
123
            handle->get_serial() == device_addr["serial"]) {
124

    
125
            usb_control::sptr ctrl_transport = usb_control::make(handle);
126
            usrp_ctrl = usrp_ctrl::make(ctrl_transport);
127
            usrp_ctrl->usrp_load_fpga(usrp1_fpga_image);
128

    
129
            data_transport = usb_zero_copy::make(handle,        // identifier
130
                                                 6,             // IN endpoint
131
                                                 2,             // OUT endpoint
132
                                                 2 * (1 << 20), // buffer size
133
                                                 16384);        // transfer size
134
            break;
135
        }
136
    }
137

    
138
    //create the usrp1 implementation guts
139
    return device::sptr(new usrp1_impl(data_transport, usrp_ctrl));
140
}
141

    
142
UHD_STATIC_BLOCK(register_usrp1_device){
143
    device::register_device(&usrp1_find, &usrp1_make);
144
}
145

    
146
/***********************************************************************
147
 * Structors
148
 **********************************************************************/
149
usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
150
                       usrp_ctrl::sptr ctrl_transport)
151
 : _data_transport(data_transport), _ctrl_transport(ctrl_transport)
152
{
153
    _iface = usrp1_iface::make(ctrl_transport);
154

    
155
    //create clock interface
156
    _clock_ctrl = usrp1_clock_ctrl::make(_iface);
157

    
158
    //create codec interface
159
    _codec_ctrls[DBOARD_SLOT_A] = usrp1_codec_ctrl::make(
160
        _iface, _clock_ctrl, SPI_ENABLE_CODEC_A
161
    );
162
    _codec_ctrls[DBOARD_SLOT_B] = usrp1_codec_ctrl::make(
163
        _iface, _clock_ctrl, SPI_ENABLE_CODEC_B
164
    );
165

    
166
    //initialize the codecs
167
    codec_init();
168

    
169
    //initialize the mboard
170
    mboard_init();
171

    
172
    //initialize the dboards 
173
    dboard_init();
174

    
175
    //initialize the dsps
176
    rx_dsp_init();
177

    
178
    //initialize the dsps
179
    tx_dsp_init();
180

    
181
    //initialize the send/recv
182
    io_init();
183

    
184
    //turn on the transmitter
185
    _ctrl_transport->usrp_tx_enable(true);
186

    
187
    //init the subdev specs
188
    this->mboard_set(MBOARD_PROP_RX_SUBDEV_SPEC, subdev_spec_t());
189
    this->mboard_set(MBOARD_PROP_TX_SUBDEV_SPEC, subdev_spec_t());
190
}
191

    
192
usrp1_impl::~usrp1_impl(void){
193
    /* NOP */
194
}
195

    
196
bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, size_t timeout_ms){
197
    //dummy fill-in for the recv_async_msg
198
    boost::this_thread::sleep(boost::posix_time::milliseconds(timeout_ms));
199
    return false;
200
}
201

    
202
/***********************************************************************
203
 * Device Get
204
 **********************************************************************/
205
void usrp1_impl::get(const wax::obj &key_, wax::obj &val)
206
{
207
    named_prop_t key = named_prop_t::extract(key_);
208

    
209
    //handle the get request conditioned on the key
210
    switch(key.as<device_prop_t>()){
211
    case DEVICE_PROP_NAME:
212
        val = std::string("usrp1 device");
213
        return;
214

    
215
    case DEVICE_PROP_MBOARD:
216
        UHD_ASSERT_THROW(key.name == "");
217
        val = _mboard_proxy->get_link();
218
        return;
219

    
220
    case DEVICE_PROP_MBOARD_NAMES:
221
        val = prop_names_t(1, ""); //vector of size 1 with empty string
222
        return;
223

    
224
    default: UHD_THROW_PROP_GET_ERROR();
225
    }
226
}
227

    
228
/***********************************************************************
229
 * Device Set
230
 **********************************************************************/
231
void usrp1_impl::set(const wax::obj &, const wax::obj &)
232
{
233
    UHD_THROW_PROP_SET_ERROR();
234
}