Merge branch 'wip/libusb-1.0' of http://gnuradio.org/git/jcorgan into master
[debian/gnuradio] / usrp / host / lib / db_basic.cc
1 //
2 // Copyright 2008,2009 Free Software Foundation, Inc.
3 // 
4 // This file is part of GNU Radio
5 // 
6 // GNU Radio is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either asversion 3, or (at your option)
9 // any later version.
10 // 
11 // GNU Radio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 // 
16 // You should have received a copy of the GNU General Public License
17 // along with GNU Radio; see the file COPYING.  If not, write to
18 // the Free Software Foundation, Inc., 51 Franklin Street,
19 // Boston, MA 02110-1301, USA.
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <usrp/db_basic.h>
26 #include <db_base_impl.h>
27
28 db_basic_tx::db_basic_tx(boost::shared_ptr<usrp_basic> usrp, int which)
29   : db_base(usrp, which)
30 {
31   // Handler for Basic Tx daughterboards.
32   // 
33   // @param usrp: instance of usrp.source_c
34   // @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
35
36   set_gain((gain_min() + gain_max()) / 2);         // initialize gain
37 }
38
39 db_basic_tx::~db_basic_tx()
40 {
41 }
42
43 double 
44 db_basic_tx::freq_min() 
45 {
46   return -90e9;
47 }
48
49 double 
50 db_basic_tx::freq_max() 
51 {
52   return 90e9;
53 }
54
55 struct freq_result_t 
56 db_basic_tx::set_freq(double target_freq)
57 {
58   // Set the frequency.
59   // 
60   // @param freq:  target RF frequency in Hz
61   // @type freq:   double
62   // 
63   // @returns (ok, actual_baseband_freq) where:
64   //   ok is True or False and indicates success or failure,
65   //   actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
66   
67   struct freq_result_t args = {false, 0};
68   args.ok = true;
69   args.baseband_freq = 0.0;
70   return args;
71 }
72
73 float
74 db_basic_tx::gain_min()
75 {
76   return usrp()->pga_min();
77 }
78
79 float
80 db_basic_tx::gain_max()
81 {
82   return usrp()->pga_max();
83 }
84
85 float
86 db_basic_tx::gain_db_per_step()
87 {
88   return usrp()->pga_db_per_step();
89 }
90
91 bool 
92 db_basic_tx::set_gain(float gain)
93 {
94   // Set the gain.
95   // 
96   // @param gain:  gain in decibels
97   // @returns True/False
98
99   bool ok = usrp()->set_pga(d_which * 2 + 0, gain);
100   ok = ok && usrp()->set_pga(d_which * 2 + 1, gain);
101   return ok;
102 }
103
104 bool 
105 db_basic_tx::is_quadrature()
106 {
107   // Return True if this board requires both I & Q analog channels.
108   
109   return true;
110 }
111
112
113 /******************************************************************************/
114
115
116 db_basic_rx::db_basic_rx(usrp_basic_sptr usrp, int which, int subdev)
117   : db_base(usrp, which)
118 {
119   // Handler for Basic Rx daughterboards.
120   // 
121   // @param usrp: instance of usrp.source_c
122   // @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
123   // @param subdev: which analog i/o channel: 0 or 1
124   // @type subdev: int
125   
126   d_subdev = subdev;
127     
128   bypass_adc_buffers(true);
129
130   if(0) {       // Doing this would give us a different default than the historical values...
131     set_gain(float(gain_min() + gain_max()) / 2.0);       // initialize gain
132   }
133 }
134
135 db_basic_rx::~db_basic_rx()
136 {
137 }
138
139 double
140 db_basic_rx::freq_min() 
141 {
142   return -90e9;
143 }
144
145 double
146 db_basic_rx::freq_max()
147 {
148   return 90e9;
149 }
150
151 struct freq_result_t 
152 db_basic_rx::set_freq(double target_freq)
153 {
154   // Set the frequency.
155   // 
156   // @param freq:  target RF frequency in Hz
157   // @type freq:   double
158   // 
159   // @returns (ok, actual_baseband_freq) where:
160   //   ok is True or False and indicates success or failure,
161   //   actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
162   
163   struct freq_result_t args = {true, 0.0};
164   return args;
165 }
166
167 float
168 db_basic_rx::gain_min()
169 {
170   return usrp()->pga_min();
171 }
172
173 float
174 db_basic_rx::gain_max()
175 {
176   return usrp()->pga_max();
177 }
178
179 float
180 db_basic_rx::gain_db_per_step()
181 {
182   return usrp()->pga_db_per_step();
183 }
184
185 bool 
186 db_basic_rx::set_gain(float gain)
187 {
188   // Set the gain.
189   // 
190   // @param gain:  gain in decibels
191   // @returns True/False
192   
193   return usrp()->set_pga(d_which * 2 + d_subdev, gain);
194 }
195
196 bool 
197 db_basic_rx::is_quadrature()
198 {
199   // Return True if this board requires both I & Q analog channels.
200
201   // This bit of info is useful when setting up the USRP Rx mux register.
202   
203   return (d_subdev == 2);
204 }
205
206
207
208 /******************************************************************************/
209
210
211 db_lf_tx::db_lf_tx(usrp_basic_sptr usrp, int which)
212   : db_basic_tx(usrp, which)
213 {
214   // Handler for Low Freq Tx daughterboards.
215   //
216   // @param usrp: instance of usrp.source_c
217   // @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
218 }
219
220 db_lf_tx::~db_lf_tx()
221 {
222 }
223
224 double 
225 db_lf_tx::freq_min() 
226 {
227   return -32e6;
228 }
229
230 double 
231 db_lf_tx::freq_max()
232 {
233   return 32e6;
234 }
235
236 /******************************************************************************/
237
238
239 db_lf_rx::db_lf_rx(usrp_basic_sptr usrp, int which, int subdev)
240   : db_basic_rx(usrp, which, subdev)
241 {
242   // Handler for Low Freq Rx daughterboards.
243   //
244   // @param usrp: instance of usrp.source_c
245   // @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
246   // @param subdev: which analog i/o channel: 0 or 1
247   // @type subdev: int
248 }
249
250 db_lf_rx::~db_lf_rx()
251 {
252 }
253
254 double
255 db_lf_rx::freq_min() 
256 {
257   return 0.0;
258 }
259
260 double
261 db_lf_rx::freq_max() 
262 {
263   return 32e6;
264 }
265
266