Merged r10071:10164 from features/cppdb-test into trunk. Implements the fully native...
[debian/gnuradio] / gr-usrp / src / usrp_base.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <usrp_base.h>
26 #include <usrp_basic.h>
27
28 class truth_table_element_t 
29 {
30 public:
31   truth_table_element_t(int side, unsigned int uses, bool swap_iq, unsigned int mux_val);
32   bool operator==(const truth_table_element_t &in);
33   bool operator!=(const truth_table_element_t &in);
34
35   unsigned int mux_val() { return d_mux_val; }
36
37 private:
38   int          d_side;
39   unsigned int d_uses;
40   bool         d_swap_iq;
41   unsigned int d_mux_val;
42 };
43
44
45 usrp_base::~usrp_base()
46 {
47 }
48
49 void
50 usrp_base::set_usrp_basic(boost::shared_ptr<usrp_basic> u)
51 {
52   d_usrp_basic = u;
53 }
54
55 std::vector<std::vector<db_base_sptr> >
56 usrp_base::db()
57 {
58   return d_usrp_basic->db();
59 }
60
61 std::vector<db_base_sptr> 
62 usrp_base::db(int which_side)
63 {
64   return d_usrp_basic->db(which_side);
65 }
66
67 db_base_sptr
68 usrp_base::db(int which_side, int which_dev)
69 {
70   return d_usrp_basic->selected_subdev(usrp_subdev_spec(which_side, which_dev));
71 }
72
73 db_base_sptr
74 usrp_base::selected_subdev(usrp_subdev_spec ss)
75 {
76   return d_usrp_basic->selected_subdev(ss);
77 }
78
79 long
80 usrp_base::fpga_master_clock_freq() const
81 {
82   return d_usrp_basic->fpga_master_clock_freq();
83 }
84
85 void
86 usrp_base::set_verbose (bool verbose)
87 {  
88   d_usrp_basic->set_verbose (verbose);
89 }
90
91 bool
92 usrp_base::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf)
93 {
94   return d_usrp_basic->write_eeprom (i2c_addr, eeprom_offset, buf);
95 }
96
97 std::string
98 usrp_base::read_eeprom (int i2c_addr, int eeprom_offset, int len)
99 {
100   return d_usrp_basic->read_eeprom (i2c_addr, eeprom_offset, len);
101 }
102
103 bool
104 usrp_base::write_i2c (int i2c_addr, const std::string buf)
105 {
106   return d_usrp_basic->write_i2c (i2c_addr, buf);
107 }
108
109 std::string
110 usrp_base::read_i2c (int i2c_addr, int len)
111 {
112   return d_usrp_basic->read_i2c (i2c_addr, len);
113 }
114
115 bool
116 usrp_base::set_adc_offset (int which, int offset)
117 {
118   return d_usrp_basic->set_adc_offset (which, offset);
119 }
120
121 bool
122 usrp_base::set_dac_offset (int which, int offset, int offset_pin)
123 {
124   return d_usrp_basic->set_dac_offset (which, offset, offset_pin);
125 }
126
127 bool
128 usrp_base::set_adc_buffer_bypass (int which, bool bypass)
129 {
130   return d_usrp_basic->set_adc_buffer_bypass (which, bypass);
131 }
132
133 bool
134 usrp_base::set_dc_offset_cl_enable(int bits, int mask)
135 {
136   return d_usrp_basic->set_dc_offset_cl_enable(bits, mask);
137 }
138
139 std::string
140 usrp_base::serial_number()
141 {
142   return d_usrp_basic->serial_number();
143 }
144
145 int
146 usrp_base::daughterboard_id (int which) const
147 {
148   return d_usrp_basic->daughterboard_id (which);
149 }
150
151 bool
152 usrp_base::write_atr_tx_delay(int value)
153 {
154   return d_usrp_basic->write_atr_tx_delay(value);
155 }
156
157 bool
158 usrp_base::write_atr_rx_delay(int value)
159 {
160   return d_usrp_basic->write_atr_rx_delay(value);
161 }
162
163 bool
164 usrp_base::set_pga (int which, double gain)
165 {
166   return d_usrp_basic->set_pga (which, gain);
167 }
168
169 double
170 usrp_base::pga (int which) const
171 {
172   return d_usrp_basic->pga (which);
173 }
174
175 double
176 usrp_base::pga_min () const
177 {
178   return d_usrp_basic->pga_min ();
179 }
180
181 double
182 usrp_base::pga_max () const
183 {
184   return d_usrp_basic->pga_max ();
185 }
186
187 double
188 usrp_base::pga_db_per_step () const
189 {
190   return d_usrp_basic->pga_db_per_step ();
191 }
192
193 bool
194 usrp_base::_write_oe (int which_dboard, int value, int mask)
195 {
196   return d_usrp_basic->_write_oe (which_dboard, value, mask);
197 }
198
199 bool
200 usrp_base::write_io (int which_dboard, int value, int mask)
201 {
202   return d_usrp_basic->write_io (which_dboard, value, mask);
203 }
204
205 int
206 usrp_base::read_io (int which_dboard)
207 {
208   return d_usrp_basic->read_io (which_dboard);
209 }
210
211 bool
212 usrp_base::write_atr_mask(int which_side, int value)
213 {
214   return d_usrp_basic->write_atr_mask(which_side, value);
215 }
216
217 bool
218 usrp_base::write_atr_txval(int which_side, int value)
219 {
220   return d_usrp_basic->write_atr_txval(which_side, value);
221 }
222
223 bool
224 usrp_base::write_atr_rxval(int which_side, int value)
225 {
226   return d_usrp_basic->write_atr_rxval(which_side, value);
227 }
228
229 bool
230 usrp_base::write_aux_dac (int which_dboard, int which_dac, int value)
231 {
232   return d_usrp_basic->write_aux_dac (which_dboard, which_dac, value);
233 }
234
235 int
236 usrp_base::read_aux_adc (int which_dboard, int which_adc)
237 {
238   return d_usrp_basic->read_aux_adc (which_dboard, which_adc);
239 }
240
241 long
242 usrp_base::converter_rate() const
243 {
244   return d_usrp_basic->converter_rate();
245 }
246
247 bool
248 usrp_base::_set_led(int which_led, bool on)
249 {
250   return d_usrp_basic->_set_led(which_led, on);
251 }
252
253 bool
254 usrp_base::_write_fpga_reg (int regno, int value)
255 {
256   return d_usrp_basic->_write_fpga_reg (regno, value);
257 }
258
259 bool
260 usrp_base::_write_fpga_reg_masked (int regno, int value, int mask)
261 {
262   return d_usrp_basic->_write_fpga_reg_masked (regno, value, mask);
263 }
264
265 int
266 usrp_base::_read_fpga_reg (int regno)
267 {
268   return d_usrp_basic->_read_fpga_reg (regno);
269 }
270
271 bool
272 usrp_base::_write_9862 (int which_codec, int regno, unsigned char value)
273 {
274   return d_usrp_basic->_write_9862 (which_codec, regno, value);
275 }
276
277 int
278 usrp_base::_read_9862 (int which_codec, int regno) const
279 {
280   return d_usrp_basic->_read_9862 (which_codec, regno);
281 }
282
283 bool
284 usrp_base::_write_spi (int optional_header, int enables,
285                                int format, std::string buf)
286 {
287   return d_usrp_basic->_write_spi (optional_header, enables, format, buf);
288 }
289
290 std::string
291 usrp_base::_read_spi (int optional_header, int enables, int format, int len)
292 {
293   return d_usrp_basic->_read_spi (optional_header, enables, format, len);
294 }
295
296 usrp_subdev_spec
297 usrp_base::pick_subdev(std::vector<int> candidates)
298 {
299   int dbid0 = db(0, 0)->dbid();
300   int dbid1 = db(1, 0)->dbid();
301
302   for (int i = 0; i < candidates.size(); i++) {
303     int dbid = candidates[i];
304     if (dbid0 == dbid)
305       return usrp_subdev_spec(0, 0);
306     if (dbid1 == dbid)
307       return usrp_subdev_spec(1, 0);
308   }
309
310   if (dbid0 >= 0)
311     return usrp_subdev_spec(0, 0);
312   if (dbid1 >= 0)
313     return usrp_subdev_spec(1, 0);
314
315   throw std::runtime_error("No suitable daughterboard found!");
316 }