Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / dboard / db_basic_and_lf.cpp @ 988cba70

History | View | Annotate | Download (7.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 <uhd/usrp/subdev_props.hpp>
19
#include <uhd/types/dict.hpp>
20
#include <uhd/types/ranges.hpp>
21
#include <uhd/utils/assert.hpp>
22
#include <uhd/utils/static.hpp>
23
#include <uhd/usrp/dboard_base.hpp>
24
#include <uhd/usrp/dboard_manager.hpp>
25
#include <boost/assign/list_of.hpp>
26
#include <boost/format.hpp>
27

    
28
using namespace uhd;
29
using namespace uhd::usrp;
30
using namespace boost::assign;
31

    
32
/***********************************************************************
33
 * The basic and lf boards:
34
 *   They share a common class because only the frequency bounds differ.
35
 **********************************************************************/
36
class basic_rx : public rx_dboard_base{
37
public:
38
    basic_rx(ctor_args_t args, double max_freq);
39
    ~basic_rx(void);
40

    
41
    void rx_get(const wax::obj &key, wax::obj &val);
42
    void rx_set(const wax::obj &key, const wax::obj &val);
43

    
44
private:
45
    double _max_freq;
46
};
47

    
48
class basic_tx : public tx_dboard_base{
49
public:
50
    basic_tx(ctor_args_t args, double max_freq);
51
    ~basic_tx(void);
52

    
53
    void tx_get(const wax::obj &key, wax::obj &val);
54
    void tx_set(const wax::obj &key, const wax::obj &val);
55

    
56
private:
57
    double _max_freq;
58
};
59

    
60
static const uhd::dict<std::string, subdev_conn_t> sd_name_to_conn = map_list_of
61
    ("AB", SUBDEV_CONN_COMPLEX_IQ)
62
    ("A",  SUBDEV_CONN_REAL_I)
63
    ("B",  SUBDEV_CONN_REAL_Q)
64
;
65

    
66
/***********************************************************************
67
 * Register the basic and LF dboards
68
 **********************************************************************/
69
static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t args){
70
    return dboard_base::sptr(new basic_rx(args, 90e9));
71
}
72

    
73
static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t args){
74
    return dboard_base::sptr(new basic_tx(args, 90e9));
75
}
76

    
77
static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t args){
78
    return dboard_base::sptr(new basic_rx(args, 32e6));
79
}
80

    
81
static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t args){
82
    return dboard_base::sptr(new basic_tx(args, 32e6));
83
}
84

    
85
UHD_STATIC_BLOCK(reg_basic_and_lf_dboards){
86
    dboard_manager::register_dboard(0x0000, &make_basic_tx, "Basic TX", sd_name_to_conn.keys());
87
    dboard_manager::register_dboard(0x0001, &make_basic_rx, "Basic RX", sd_name_to_conn.keys());
88
    dboard_manager::register_dboard(0x000e, &make_lf_tx,    "LF TX",    sd_name_to_conn.keys());
89
    dboard_manager::register_dboard(0x000f, &make_lf_rx,    "LF RX",    sd_name_to_conn.keys());
90
}
91

    
92
/***********************************************************************
93
 * Basic and LF RX dboard
94
 **********************************************************************/
95
basic_rx::basic_rx(ctor_args_t args, double max_freq) : rx_dboard_base(args){
96
    _max_freq = max_freq;
97
}
98

    
99
basic_rx::~basic_rx(void){
100
    /* NOP */
101
}
102

    
103
void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
104
    named_prop_t key = named_prop_t::extract(key_);
105

    
106
    //handle the get request conditioned on the key
107
    switch(key.as<subdev_prop_t>()){
108
    case SUBDEV_PROP_NAME:
109
        val = std::string(str(boost::format("%s - %s")
110
            % get_rx_id().to_pp_string()
111
            % get_subdev_name()
112
        ));
113
        return;
114

    
115
    case SUBDEV_PROP_OTHERS:
116
        val = prop_names_t(); //empty
117
        return;
118

    
119
    case SUBDEV_PROP_GAIN:
120
        val = float(0);
121
        return;
122

    
123
    case SUBDEV_PROP_GAIN_RANGE:
124
        val = gain_range_t(0, 0, 0);
125
        return;
126

    
127
    case SUBDEV_PROP_GAIN_NAMES:
128
        val = prop_names_t(); //empty
129
        return;
130

    
131
    case SUBDEV_PROP_FREQ:
132
        val = double(0);
133
        return;
134

    
135
    case SUBDEV_PROP_FREQ_RANGE:
136
        val = freq_range_t(-_max_freq, +_max_freq);
137
        return;
138

    
139
    case SUBDEV_PROP_ANTENNA:
140
        val = std::string("");
141
        return;
142

    
143
    case SUBDEV_PROP_ANTENNA_NAMES:
144
        val = prop_names_t(1, ""); //vector of 1 empty string
145
        return;
146

    
147
    case SUBDEV_PROP_CONNECTION:
148
        val = sd_name_to_conn[get_subdev_name()];
149
        return;
150

    
151
    case SUBDEV_PROP_USE_LO_OFFSET:
152
        val = false;
153
        return;
154

    
155
    case SUBDEV_PROP_LO_LOCKED:
156
        val = true; //there is no LO, so it must be true!
157
        return;
158

    
159
    default: UHD_THROW_PROP_GET_ERROR();
160
    }
161
}
162

    
163
void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
164
    named_prop_t key = named_prop_t::extract(key_);
165

    
166
    //handle the get request conditioned on the key
167
    switch(key.as<subdev_prop_t>()){
168

    
169
    case SUBDEV_PROP_GAIN:
170
        UHD_ASSERT_THROW(val.as<float>() == float(0));
171
        return;
172

    
173
    case SUBDEV_PROP_ANTENNA:
174
        if (val.as<std::string>().empty()) return;
175
        throw std::runtime_error("no selectable antennas on this board");
176

    
177
    case SUBDEV_PROP_FREQ:
178
        return; // it wont do you much good, but you can set it
179

    
180
    default: UHD_THROW_PROP_SET_ERROR();
181
    }
182
}
183

    
184
/***********************************************************************
185
 * Basic and LF TX dboard
186
 **********************************************************************/
187
basic_tx::basic_tx(ctor_args_t args, double max_freq) : tx_dboard_base(args){
188
    _max_freq = max_freq;
189
}
190

    
191
basic_tx::~basic_tx(void){
192
    /* NOP */
193
}
194

    
195
void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){
196
    named_prop_t key = named_prop_t::extract(key_);
197

    
198
    //handle the get request conditioned on the key
199
    switch(key.as<subdev_prop_t>()){
200
    case SUBDEV_PROP_NAME:
201
        val = std::string(str(boost::format("%s - %s")
202
            % get_tx_id().to_pp_string()
203
            % get_subdev_name()
204
        ));
205
        return;
206

    
207
    case SUBDEV_PROP_OTHERS:
208
        val = prop_names_t(); //empty
209
        return;
210

    
211
    case SUBDEV_PROP_GAIN:
212
        val = float(0);
213
        return;
214

    
215
    case SUBDEV_PROP_GAIN_RANGE:
216
        val = gain_range_t(0, 0, 0);
217
        return;
218

    
219
    case SUBDEV_PROP_GAIN_NAMES:
220
        val = prop_names_t(); //empty
221
        return;
222

    
223
    case SUBDEV_PROP_FREQ:
224
        val = double(0);
225
        return;
226

    
227
    case SUBDEV_PROP_FREQ_RANGE:
228
        val = freq_range_t(-_max_freq, +_max_freq);
229
        return;
230

    
231
    case SUBDEV_PROP_ANTENNA:
232
        val = std::string("");
233
        return;
234

    
235
    case SUBDEV_PROP_ANTENNA_NAMES:
236
        val = prop_names_t(1, ""); //vector of 1 empty string
237
        return;
238

    
239
    case SUBDEV_PROP_CONNECTION:
240
        val = sd_name_to_conn[get_subdev_name()];
241
        return;
242

    
243
    case SUBDEV_PROP_USE_LO_OFFSET:
244
        val = false;
245
        return;
246

    
247
    case SUBDEV_PROP_LO_LOCKED:
248
        val = true; //there is no LO, so it must be true!
249
        return;
250

    
251
    default: UHD_THROW_PROP_GET_ERROR();
252
    }
253
}
254

    
255
void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){
256
    named_prop_t key = named_prop_t::extract(key_);
257

    
258
    //handle the get request conditioned on the key
259
    switch(key.as<subdev_prop_t>()){
260

    
261
    case SUBDEV_PROP_GAIN:
262
        UHD_ASSERT_THROW(val.as<float>() == float(0));
263
        return;
264

    
265
    case SUBDEV_PROP_ANTENNA:
266
        if (val.as<std::string>().empty()) return;
267
        throw std::runtime_error("no selectable antennas on this board");
268

    
269
    case SUBDEV_PROP_FREQ:
270
        return; // it wont do you much good, but you can set it
271

    
272
    default: UHD_THROW_PROP_SET_ERROR();
273
    }
274
}