Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / dboard / db_basic_and_lf.cpp @ 4ecc24d0

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 <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
/***********************************************************************
61
 * Register the basic and LF dboards
62
 **********************************************************************/
63
static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t args){
64
    return dboard_base::sptr(new basic_rx(args, 90e9));
65
}
66

    
67
static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t args){
68
    return dboard_base::sptr(new basic_tx(args, 90e9));
69
}
70

    
71
static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t args){
72
    return dboard_base::sptr(new basic_rx(args, 32e6));
73
}
74

    
75
static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t args){
76
    return dboard_base::sptr(new basic_tx(args, 32e6));
77
}
78

    
79
UHD_STATIC_BLOCK(reg_basic_and_lf_dboards){
80
    dboard_manager::register_dboard(0x0000, &make_basic_tx, "Basic TX");
81
    dboard_manager::register_dboard(0x0001, &make_basic_rx, "Basic RX", list_of("AB")("A")("B"));
82
    dboard_manager::register_dboard(0x000e, &make_lf_tx,    "LF TX");
83
    dboard_manager::register_dboard(0x000f, &make_lf_rx,    "LF RX",    list_of("AB")("A")("B"));
84
}
85

    
86
/***********************************************************************
87
 * Basic and LF RX dboard
88
 **********************************************************************/
89
basic_rx::basic_rx(ctor_args_t args, double max_freq) : rx_dboard_base(args){
90
    _max_freq = max_freq;
91
}
92

    
93
basic_rx::~basic_rx(void){
94
    /* NOP */
95
}
96

    
97
void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
98
    named_prop_t key = named_prop_t::extract(key_);
99

    
100
    //handle the get request conditioned on the key
101
    switch(key.as<subdev_prop_t>()){
102
    case SUBDEV_PROP_NAME:
103
        val = std::string(str(boost::format("%s - %s")
104
            % get_rx_id().to_pp_string()
105
            % get_subdev_name()
106
        ));
107
        return;
108

    
109
    case SUBDEV_PROP_OTHERS:
110
        val = prop_names_t(); //empty
111
        return;
112

    
113
    case SUBDEV_PROP_GAIN:
114
        val = float(0);
115
        return;
116

    
117
    case SUBDEV_PROP_GAIN_RANGE:
118
        val = gain_range_t(0, 0, 0);
119
        return;
120

    
121
    case SUBDEV_PROP_GAIN_NAMES:
122
        val = prop_names_t(); //empty
123
        return;
124

    
125
    case SUBDEV_PROP_FREQ:
126
        val = double(0);
127
        return;
128

    
129
    case SUBDEV_PROP_FREQ_RANGE:
130
        val = freq_range_t(-_max_freq, +_max_freq);
131
        return;
132

    
133
    case SUBDEV_PROP_ANTENNA:
134
        val = std::string("");
135
        return;
136

    
137
    case SUBDEV_PROP_ANTENNA_NAMES:
138
        val = prop_names_t(1, ""); //vector of 1 empty string
139
        return;
140

    
141
    case SUBDEV_PROP_CONNECTION:{
142
            static const uhd::dict<std::string, subdev_conn_t> name_to_conn = map_list_of
143
                ("A",  SUBDEV_CONN_REAL_I)
144
                ("B",  SUBDEV_CONN_REAL_Q)
145
                ("AB", SUBDEV_CONN_COMPLEX_IQ)
146
            ;
147
            val = name_to_conn[get_subdev_name()];
148
        } return;
149

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

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

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

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

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

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

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

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

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

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

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

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

    
197
    //handle the get request conditioned on the key
198
    switch(key.as<subdev_prop_t>()){
199
    case SUBDEV_PROP_NAME:
200
        val = get_tx_id().to_pp_string();
201
        return;
202

    
203
    case SUBDEV_PROP_OTHERS:
204
        val = prop_names_t(); //empty
205
        return;
206

    
207
    case SUBDEV_PROP_GAIN:
208
        val = float(0);
209
        return;
210

    
211
    case SUBDEV_PROP_GAIN_RANGE:
212
        val = gain_range_t(0, 0, 0);
213
        return;
214

    
215
    case SUBDEV_PROP_GAIN_NAMES:
216
        val = prop_names_t(); //empty
217
        return;
218

    
219
    case SUBDEV_PROP_FREQ:
220
        val = double(0);
221
        return;
222

    
223
    case SUBDEV_PROP_FREQ_RANGE:
224
        val = freq_range_t(-_max_freq, +_max_freq);
225
        return;
226

    
227
    case SUBDEV_PROP_ANTENNA:
228
        val = std::string("");
229
        return;
230

    
231
    case SUBDEV_PROP_ANTENNA_NAMES:
232
        val = prop_names_t(1, ""); //vector of 1 empty string
233
        return;
234

    
235
    case SUBDEV_PROP_CONNECTION:
236
        val = SUBDEV_CONN_COMPLEX_IQ;
237
        return;
238

    
239
    case SUBDEV_PROP_USE_LO_OFFSET:
240
        val = false;
241
        return;
242

    
243
    case SUBDEV_PROP_LO_LOCKED:
244
        val = true; //there is no LO, so it must be true!
245
        return;
246

    
247
    default: UHD_THROW_PROP_GET_ERROR();
248
    }
249
}
250

    
251
void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){
252
    named_prop_t key = named_prop_t::extract(key_);
253

    
254
    //handle the get request conditioned on the key
255
    switch(key.as<subdev_prop_t>()){
256

    
257
    case SUBDEV_PROP_GAIN:
258
        UHD_ASSERT_THROW(val.as<float>() == float(0));
259
        return;
260

    
261
    case SUBDEV_PROP_ANTENNA:
262
        if (val.as<std::string>().empty()) return;
263
        throw std::runtime_error("no selectable antennas on this board");
264

    
265
    case SUBDEV_PROP_FREQ:
266
        return; // it wont do you much good, but you can set it
267

    
268
    default: UHD_THROW_PROP_SET_ERROR();
269
    }
270
}