Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / usrp1_impl.cpp @ ec8005e3

History | View | Annotate | Download (7.1 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 std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost::assign::list_of
38
    (usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B)
39
;
40

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

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

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

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

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

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

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

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

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

    
86
    return usrp1_addrs;
87
}
88

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
176
usrp1_impl::~usrp1_impl(void){
177
    /* NOP */
178
}
179

    
180
bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, size_t timeout_ms){
181
    //dummy fill-in for the recv_async_msg
182
    boost::this_thread::sleep(boost::posix_time::milliseconds(timeout_ms));
183
    return false;
184
}
185

    
186
/***********************************************************************
187
 * Device Get
188
 **********************************************************************/
189
void usrp1_impl::get(const wax::obj &key_, wax::obj &val)
190
{
191
    named_prop_t key = named_prop_t::extract(key_);
192

    
193
    //handle the get request conditioned on the key
194
    switch(key.as<device_prop_t>()){
195
    case DEVICE_PROP_NAME:
196
        val = std::string("usrp1 device");
197
        return;
198

    
199
    case DEVICE_PROP_MBOARD:
200
        UHD_ASSERT_THROW(key.name == "");
201
        val = _mboard_proxy->get_link();
202
        return;
203

    
204
    case DEVICE_PROP_MBOARD_NAMES:
205
        val = prop_names_t(1, ""); //vector of size 1 with empty string
206
        return;
207

    
208
    default: UHD_THROW_PROP_GET_ERROR();
209
    }
210
}
211

    
212
/***********************************************************************
213
 * Device Set
214
 **********************************************************************/
215
void usrp1_impl::set(const wax::obj &, const wax::obj &)
216
{
217
    UHD_THROW_PROP_SET_ERROR();
218
}