Imported Upstream version 3.2.2
[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_fpga_master_clock_freq(long master_clock)
87 {
88   d_usrp_basic->set_fpga_master_clock_freq(master_clock);
89 }
90
91 void
92 usrp_base::set_verbose (bool verbose)
93 {  
94   d_usrp_basic->set_verbose (verbose);
95 }
96
97 bool
98 usrp_base::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf)
99 {
100   return d_usrp_basic->write_eeprom (i2c_addr, eeprom_offset, buf);
101 }
102
103 std::string
104 usrp_base::read_eeprom (int i2c_addr, int eeprom_offset, int len)
105 {
106   return d_usrp_basic->read_eeprom (i2c_addr, eeprom_offset, len);
107 }
108
109 bool
110 usrp_base::write_i2c (int i2c_addr, const std::string buf)
111 {
112   return d_usrp_basic->write_i2c (i2c_addr, buf);
113 }
114
115 std::string
116 usrp_base::read_i2c (int i2c_addr, int len)
117 {
118   return d_usrp_basic->read_i2c (i2c_addr, len);
119 }
120
121 bool
122 usrp_base::set_adc_offset (int which, int offset)
123 {
124   return d_usrp_basic->set_adc_offset (which, offset);
125 }
126
127 bool
128 usrp_base::set_dac_offset (int which, int offset, int offset_pin)
129 {
130   return d_usrp_basic->set_dac_offset (which, offset, offset_pin);
131 }
132
133 bool
134 usrp_base::set_adc_buffer_bypass (int which, bool bypass)
135 {
136   return d_usrp_basic->set_adc_buffer_bypass (which, bypass);
137 }
138
139 bool
140 usrp_base::set_dc_offset_cl_enable(int bits, int mask)
141 {
142   return d_usrp_basic->set_dc_offset_cl_enable(bits, mask);
143 }
144
145 std::string
146 usrp_base::serial_number()
147 {
148   return d_usrp_basic->serial_number();
149 }
150
151 int
152 usrp_base::daughterboard_id (int which) const
153 {
154   return d_usrp_basic->daughterboard_id (which);
155 }
156
157 bool
158 usrp_base::write_atr_tx_delay(int value)
159 {
160   return d_usrp_basic->write_atr_tx_delay(value);
161 }
162
163 bool
164 usrp_base::write_atr_rx_delay(int value)
165 {
166   return d_usrp_basic->write_atr_rx_delay(value);
167 }
168
169 bool
170 usrp_base::set_pga (int which, double gain)
171 {
172   return d_usrp_basic->set_pga (which, gain);
173 }
174
175 double
176 usrp_base::pga (int which) const
177 {
178   return d_usrp_basic->pga (which);
179 }
180
181 double
182 usrp_base::pga_min () const
183 {
184   return d_usrp_basic->pga_min ();
185 }
186
187 double
188 usrp_base::pga_max () const
189 {
190   return d_usrp_basic->pga_max ();
191 }
192
193 double
194 usrp_base::pga_db_per_step () const
195 {
196   return d_usrp_basic->pga_db_per_step ();
197 }
198
199 bool
200 usrp_base::_write_oe (int which_dboard, int value, int mask)
201 {
202   return d_usrp_basic->_write_oe (which_dboard, value, mask);
203 }
204
205 bool
206 usrp_base::write_io (int which_dboard, int value, int mask)
207 {
208   return d_usrp_basic->write_io (which_dboard, value, mask);
209 }
210
211 int
212 usrp_base::read_io (int which_dboard)
213 {
214   return d_usrp_basic->read_io (which_dboard);
215 }
216
217 bool
218 usrp_base::write_atr_mask(int which_side, int value)
219 {
220   return d_usrp_basic->write_atr_mask(which_side, value);
221 }
222
223 bool
224 usrp_base::write_atr_txval(int which_side, int value)
225 {
226   return d_usrp_basic->write_atr_txval(which_side, value);
227 }
228
229 bool
230 usrp_base::write_atr_rxval(int which_side, int value)
231 {
232   return d_usrp_basic->write_atr_rxval(which_side, value);
233 }
234
235 bool
236 usrp_base::write_aux_dac (int which_dboard, int which_dac, int value)
237 {
238   return d_usrp_basic->write_aux_dac (which_dboard, which_dac, value);
239 }
240
241 int
242 usrp_base::read_aux_adc (int which_dboard, int which_adc)
243 {
244   return d_usrp_basic->read_aux_adc (which_dboard, which_adc);
245 }
246
247 long
248 usrp_base::converter_rate() const
249 {
250   return d_usrp_basic->converter_rate();
251 }
252
253 bool
254 usrp_base::_set_led(int which_led, bool on)
255 {
256   return d_usrp_basic->_set_led(which_led, on);
257 }
258
259 bool
260 usrp_base::_write_fpga_reg (int regno, int value)
261 {
262   return d_usrp_basic->_write_fpga_reg (regno, value);
263 }
264
265 bool
266 usrp_base::_write_fpga_reg_masked (int regno, int value, int mask)
267 {
268   return d_usrp_basic->_write_fpga_reg_masked (regno, value, mask);
269 }
270
271 int
272 usrp_base::_read_fpga_reg (int regno)
273 {
274   return d_usrp_basic->_read_fpga_reg (regno);
275 }
276
277 bool
278 usrp_base::_write_9862 (int which_codec, int regno, unsigned char value)
279 {
280   return d_usrp_basic->_write_9862 (which_codec, regno, value);
281 }
282
283 int
284 usrp_base::_read_9862 (int which_codec, int regno) const
285 {
286   return d_usrp_basic->_read_9862 (which_codec, regno);
287 }
288
289 bool
290 usrp_base::_write_spi (int optional_header, int enables,
291                                int format, std::string buf)
292 {
293   return d_usrp_basic->_write_spi (optional_header, enables, format, buf);
294 }
295
296 std::string
297 usrp_base::_read_spi (int optional_header, int enables, int format, int len)
298 {
299   return d_usrp_basic->_read_spi (optional_header, enables, format, len);
300 }
301
302 usrp_subdev_spec
303 usrp_base::pick_subdev(std::vector<int> candidates)
304 {
305   int dbid0 = db(0, 0)->dbid();
306   int dbid1 = db(1, 0)->dbid();
307
308   for (int i = 0; i < candidates.size(); i++) {
309     int dbid = candidates[i];
310     if (dbid0 == dbid)
311       return usrp_subdev_spec(0, 0);
312     if (dbid1 == dbid)
313       return usrp_subdev_spec(1, 0);
314   }
315
316   if (dbid0 >= 0)
317     return usrp_subdev_spec(0, 0);
318   if (dbid1 >= 0)
319     return usrp_subdev_spec(1, 0);
320
321   throw std::runtime_error("No suitable daughterboard found!");
322 }