Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / usrp1_impl.cpp @ 954be827

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

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

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

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

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

    
52
    //extract the firmware path for the USRP1
53
    std::string usrp1_fw_image = find_image_path(
54
        hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx"
55
    );
56
    std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
57

    
58
    //see what we got on the USB bus
59
    std::vector<usb_device_handle::sptr> device_list =
60
        usb_device_handle::get_device_list();
61

    
62
    //find the usrps and load firmware
63
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
64
        if (handle->get_vendor_id() == 0xfffe &&
65
            handle->get_product_id() == 0x0002) {
66

    
67
            usb_control::sptr ctrl_transport = usb_control::make(handle);
68
            usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport);
69
            usrp_ctrl->usrp_load_firmware(usrp1_fw_image);
70
        }
71
    }
72

    
73
    //get descriptors again with serial number
74
    device_list = usb_device_handle::get_device_list();
75

    
76
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
77
        if (handle->get_vendor_id() == 0xfffe &&
78
            handle->get_product_id() == 0x0002) {
79

    
80
            device_addr_t new_addr;
81
            new_addr["type"] = "usrp1";
82
            new_addr["serial"] = handle->get_serial();
83
            usrp1_addrs.push_back(new_addr);
84
        }
85
    }
86

    
87
    return usrp1_addrs;
88
}
89

    
90
/***********************************************************************
91
 * Make
92
 **********************************************************************/
93
static device::sptr usrp1_make(const device_addr_t &device_addr)
94
{
95
    //extract the FPGA path for the USRP1
96
    std::string usrp1_fpga_image = find_image_path(
97
        device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf"
98
    );
99
    std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
100

    
101
    //try to match the given device address with something on the USB bus
102
    std::vector<usb_device_handle::sptr> device_list =
103
        usb_device_handle::get_device_list();
104

    
105
    //create data and control transports
106
    usb_zero_copy::sptr data_transport;
107
    usrp_ctrl::sptr usrp_ctrl;
108

    
109
    BOOST_FOREACH(usb_device_handle::sptr handle, device_list) {
110
        if (handle->get_vendor_id() == 0xfffe &&
111
            handle->get_product_id() == 0x0002 &&
112
            handle->get_serial() == device_addr["serial"]) {
113

    
114
            usb_control::sptr ctrl_transport = usb_control::make(handle);
115
            usrp_ctrl = usrp_ctrl::make(ctrl_transport);
116
            usrp_ctrl->usrp_load_fpga(usrp1_fpga_image);
117

    
118
            data_transport = usb_zero_copy::make(handle,        // identifier
119
                                                 6,             // IN endpoint
120
                                                 2,             // OUT endpoint
121
                                                 2 * (1 << 20), // buffer size
122
                                                 16384);        // transfer size
123
            break;
124
        }
125
    }
126

    
127
    //create the usrp1 implementation guts
128
    return device::sptr(new usrp1_impl(data_transport, usrp_ctrl));
129
}
130

    
131
UHD_STATIC_BLOCK(register_usrp1_device){
132
    device::register_device(&usrp1_find, &usrp1_make);
133
}
134

    
135
/***********************************************************************
136
 * Structors
137
 **********************************************************************/
138
usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
139
                       usrp_ctrl::sptr ctrl_transport)
140
 : _data_transport(data_transport), _ctrl_transport(ctrl_transport)
141
{
142
    _iface = usrp1_iface::make(ctrl_transport);
143

    
144
    //create clock interface
145
    _clock_ctrl = usrp1_clock_ctrl::make(_iface);
146

    
147
    //create codec interface
148
    _codec_ctrls[DBOARD_SLOT_A] = usrp1_codec_ctrl::make(
149
        _iface, _clock_ctrl, SPI_ENABLE_CODEC_A
150
    );
151
    _codec_ctrls[DBOARD_SLOT_B] = usrp1_codec_ctrl::make(
152
        _iface, _clock_ctrl, SPI_ENABLE_CODEC_B
153
    );
154

    
155
    //initialize the codecs
156
    codec_init();
157

    
158
    //initialize the mboard
159
    mboard_init();
160

    
161
    //initialize the dboards 
162
    dboard_init();
163

    
164
    //initialize the dsps
165
    rx_dsp_init();
166

    
167
    //initialize the dsps
168
    tx_dsp_init();
169

    
170
    //initialize the send/recv
171
    io_init();
172

    
173
    //turn on the transmitter
174
    _ctrl_transport->usrp_tx_enable(true);
175

    
176
    //init the subdev specs
177
    this->mboard_set(MBOARD_PROP_RX_SUBDEV_SPEC, subdev_spec_t());
178
    this->mboard_set(MBOARD_PROP_TX_SUBDEV_SPEC, subdev_spec_t());
179
}
180

    
181
usrp1_impl::~usrp1_impl(void){
182
    /* NOP */
183
}
184

    
185
bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, size_t timeout_ms){
186
    //dummy fill-in for the recv_async_msg
187
    boost::this_thread::sleep(boost::posix_time::milliseconds(timeout_ms));
188
    return false;
189
}
190

    
191
/***********************************************************************
192
 * Device Get
193
 **********************************************************************/
194
void usrp1_impl::get(const wax::obj &key_, wax::obj &val)
195
{
196
    named_prop_t key = named_prop_t::extract(key_);
197

    
198
    //handle the get request conditioned on the key
199
    switch(key.as<device_prop_t>()){
200
    case DEVICE_PROP_NAME:
201
        val = std::string("usrp1 device");
202
        return;
203

    
204
    case DEVICE_PROP_MBOARD:
205
        UHD_ASSERT_THROW(key.name == "");
206
        val = _mboard_proxy->get_link();
207
        return;
208

    
209
    case DEVICE_PROP_MBOARD_NAMES:
210
        val = prop_names_t(1, ""); //vector of size 1 with empty string
211
        return;
212

    
213
    default: UHD_THROW_PROP_GET_ERROR();
214
    }
215
}
216

    
217
/***********************************************************************
218
 * Device Set
219
 **********************************************************************/
220
void usrp1_impl::set(const wax::obj &, const wax::obj &)
221
{
222
    UHD_THROW_PROP_SET_ERROR();
223
}