Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / dboard_impl.cpp @ 97496ace

History | View | Annotate | Download (6.08 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

    
19
#include "usrp2_impl.hpp"
20
#include "usrp2_regs.hpp"
21
#include <uhd/usrp/subdev_props.hpp>
22
#include <uhd/usrp/dboard_props.hpp>
23
#include <uhd/utils/assert.hpp>
24
#include <boost/format.hpp>
25

    
26
using namespace uhd;
27
using namespace uhd::usrp;
28

    
29
/***********************************************************************
30
 * Helper Methods
31
 **********************************************************************/
32
void usrp2_impl::dboard_init(void){
33
    //grab the dboard ids over the control line
34
    usrp2_ctrl_data_t out_data;
35
    out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO);
36
    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
37
    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE);
38

    
39
    //extract the dboard ids an convert them
40
    dboard_id_t rx_dboard_id = ntohs(in_data.data.dboard_ids.rx_id);
41
    dboard_id_t tx_dboard_id = ntohs(in_data.data.dboard_ids.tx_id);
42

    
43
    //create a new dboard interface and manager
44
    dboard_interface::sptr _dboard_interface(
45
        make_usrp2_dboard_interface(this)
46
    );
47
    _dboard_manager = dboard_manager::make(
48
        rx_dboard_id, tx_dboard_id, _dboard_interface
49
    );
50

    
51
    //load dboards
52
    _rx_dboard_proxy = wax_obj_proxy::make(
53
        boost::bind(&usrp2_impl::rx_dboard_get, this, _1, _2),
54
        boost::bind(&usrp2_impl::rx_dboard_set, this, _1, _2)
55
    );
56
    _tx_dboard_proxy = wax_obj_proxy::make(
57
        boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2),
58
        boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2)
59
    );
60

    
61
    //init the subdevs in use (use the first subdevice)
62
    _rx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_rx_subdev_names().at(0));
63
    update_rx_mux_config();
64

    
65
    _tx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_tx_subdev_names().at(0));
66
    update_tx_mux_config();
67
}
68

    
69
void usrp2_impl::update_rx_mux_config(void){
70
    //calculate the rx mux
71
    boost::uint32_t rx_mux = 0;
72
    ASSERT_THROW(_rx_subdevs_in_use.size() == 1);
73
    wax::obj rx_subdev = _dboard_manager->get_rx_subdev(_rx_subdevs_in_use.at(0));
74
    std::cout << "Using: " << rx_subdev[SUBDEV_PROP_NAME].as<std::string>() << std::endl;
75
    if (rx_subdev[SUBDEV_PROP_QUADRATURE].as<bool>()){
76
        rx_mux = (0x01 << 2) | (0x00 << 0); //Q=ADC1, I=ADC0
77
    }else{
78
        rx_mux = 0x00; //ADC0
79
    }
80
    if (rx_subdev[SUBDEV_PROP_IQ_SWAPPED].as<bool>()){
81
        rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0);
82
    }
83

    
84
    this->poke32(FR_DSP_RX_MUX, rx_mux);
85
}
86

    
87
void usrp2_impl::update_tx_mux_config(void){
88
    //calculate the tx mux
89
    boost::uint32_t tx_mux = 0x10;
90
    ASSERT_THROW(_tx_subdevs_in_use.size() == 1);
91
    wax::obj tx_subdev = _dboard_manager->get_tx_subdev(_tx_subdevs_in_use.at(0));
92
    std::cout << "Using: " << tx_subdev[SUBDEV_PROP_NAME].as<std::string>() << std::endl;
93
    if (tx_subdev[SUBDEV_PROP_IQ_SWAPPED].as<bool>()){
94
        tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0);
95
    }
96

    
97
    this->poke32(FR_DSP_TX_MUX, tx_mux);
98
}
99

    
100
/***********************************************************************
101
 * RX DBoard Properties
102
 **********************************************************************/
103
void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
104
    wax::obj key; std::string name;
105
    boost::tie(key, name) = extract_named_prop(key_);
106

    
107
    //handle the get request conditioned on the key
108
    switch(key.as<dboard_prop_t>()){
109
    case DBOARD_PROP_NAME:
110
        val = std::string("usrp2 dboard (rx unit)");
111
        return;
112

    
113
    case DBOARD_PROP_SUBDEV:
114
        val = _dboard_manager->get_rx_subdev(name);
115
        return;
116

    
117
    case DBOARD_PROP_SUBDEV_NAMES:
118
        val = _dboard_manager->get_rx_subdev_names();
119
        return;
120

    
121
    case DBOARD_PROP_USED_SUBDEVS:
122
        val = _rx_subdevs_in_use;
123
        return;
124

    
125
    //case DBOARD_PROP_CODEC:
126
    //    throw std::runtime_error("unhandled prop in usrp2 dboard");
127
    }
128
}
129

    
130
void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
131
    if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){
132
        _rx_subdevs_in_use = val.as<prop_names_t>();
133
        update_rx_mux_config(); //if the val is bad, this will throw
134
        return;
135
    }
136

    
137
    throw std::runtime_error("Cannot set on usrp2 dboard");
138
}
139

    
140
/***********************************************************************
141
 * TX DBoard Properties
142
 **********************************************************************/
143
void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
144
    wax::obj key; std::string name;
145
    boost::tie(key, name) = extract_named_prop(key_);
146

    
147
    //handle the get request conditioned on the key
148
    switch(key.as<dboard_prop_t>()){
149
    case DBOARD_PROP_NAME:
150
        val = std::string("usrp2 dboard (tx unit)");
151
        return;
152

    
153
    case DBOARD_PROP_SUBDEV:
154
        val = _dboard_manager->get_tx_subdev(name);
155
        return;
156

    
157
    case DBOARD_PROP_SUBDEV_NAMES:
158
        val = _dboard_manager->get_tx_subdev_names();
159
        return;
160

    
161
    case DBOARD_PROP_USED_SUBDEVS:
162
        val = _tx_subdevs_in_use;
163
        return;
164

    
165
    //case DBOARD_PROP_CODEC:
166
    //    throw std::runtime_error("unhandled prop in usrp2 dboard");
167
    }
168
}
169

    
170
void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
171
    if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){
172
        _tx_subdevs_in_use = val.as<prop_names_t>();
173
        update_tx_mux_config(); //if the val is bad, this will throw
174
        return;
175
    }
176

    
177
    throw std::runtime_error("Cannot set on usrp2 dboard");
178
}