Merged r11377:11390 from jcorgan/usrp-headers in to trunk.
[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 #include <usrp/db_basic.h>
22 #include <db_base_impl.h>
23
24 db_basic_tx::db_basic_tx(boost::shared_ptr<usrp_basic> usrp, int which)
25   : db_base(usrp, which)
26 {
27   // Handler for Basic Tx daughterboards.
28   // 
29   // @param usrp: instance of usrp.source_c
30   // @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
31
32   set_gain((gain_min() + gain_max()) / 2);         // initialize gain
33 }
34
35 db_basic_tx::~db_basic_tx()
36 {
37 }
38
39 double 
40 db_basic_tx::freq_min() 
41 {
42   return -90e9;
43 }
44
45 double 
46 db_basic_tx::freq_max() 
47 {
48   return 90e9;
49 }
50
51 struct freq_result_t 
52 db_basic_tx::set_freq(double target_freq)
53 {
54   // Set the frequency.
55   // 
56   // @param freq:  target RF frequency in Hz
57   // @type freq:   double
58   // 
59   // @returns (ok, actual_baseband_freq) where:
60   //   ok is True or False and indicates success or failure,
61   //   actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
62   
63   struct freq_result_t args = {false, 0};
64   args.ok = true;
65   args.baseband_freq = 0.0;
66   return args;
67 }
68
69 float
70 db_basic_tx::gain_min()
71 {
72   return usrp()->pga_min();
73 }
74
75 float
76 db_basic_tx::gain_max()
77 {
78   return usrp()->pga_max();
79 }
80
81 float
82 db_basic_tx::gain_db_per_step()
83 {
84   return usrp()->pga_db_per_step();
85 }
86
87 bool 
88 db_basic_tx::set_gain(float gain)
89 {
90   // Set the gain.
91   // 
92   // @param gain:  gain in decibels
93   // @returns True/False
94
95   bool ok = usrp()->set_pga(d_which * 2 + 0, gain);
96   ok = ok && usrp()->set_pga(d_which * 2 + 1, gain);
97   return ok;
98 }
99
100 bool 
101 db_basic_tx::is_quadrature()
102 {
103   // Return True if this board requires both I & Q analog channels.
104   
105   return true;
106 }
107
108
109 /******************************************************************************/
110
111
112 db_basic_rx::db_basic_rx(usrp_basic_sptr usrp, int which, int subdev)
113   : db_base(usrp, which)
114 {
115   // Handler for Basic Rx daughterboards.
116   // 
117   // @param usrp: instance of usrp.source_c
118   // @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
119   // @param subdev: which analog i/o channel: 0 or 1
120   // @type subdev: int
121   
122   d_subdev = subdev;
123     
124   bypass_adc_buffers(true);
125
126   if(0) {       // Doing this would give us a different default than the historical values...
127     set_gain(float(gain_min() + gain_max()) / 2.0);       // initialize gain
128   }
129 }
130
131 db_basic_rx::~db_basic_rx()
132 {
133 }
134
135 double
136 db_basic_rx::freq_min() 
137 {
138   return -90e9;
139 }
140
141 double
142 db_basic_rx::freq_max()
143 {
144   return 90e9;
145 }
146
147 struct freq_result_t 
148 db_basic_rx::set_freq(double target_freq)
149 {
150   // Set the frequency.
151   // 
152   // @param freq:  target RF frequency in Hz
153   // @type freq:   double
154   // 
155   // @returns (ok, actual_baseband_freq) where:
156   //   ok is True or False and indicates success or failure,
157   //   actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
158   
159   struct freq_result_t args = {true, 0.0};
160   return args;
161 }
162
163 float
164 db_basic_rx::gain_min()
165 {
166   return usrp()->pga_min();
167 }
168
169 float
170 db_basic_rx::gain_max()
171 {
172   return usrp()->pga_max();
173 }
174
175 float
176 db_basic_rx::gain_db_per_step()
177 {
178   return usrp()->pga_db_per_step();
179 }
180
181 bool 
182 db_basic_rx::set_gain(float gain)
183 {
184   // Set the gain.
185   // 
186   // @param gain:  gain in decibels
187   // @returns True/False
188   
189   return usrp()->set_pga(d_which * 2 + d_subdev, gain);
190 }
191
192 bool 
193 db_basic_rx::is_quadrature()
194 {
195   // Return True if this board requires both I & Q analog channels.
196
197   // This bit of info is useful when setting up the USRP Rx mux register.
198   
199   return (d_subdev == 2);
200 }
201
202
203
204 /******************************************************************************/
205
206
207 db_lf_tx::db_lf_tx(usrp_basic_sptr usrp, int which)
208   : db_basic_tx(usrp, which)
209 {
210   // Handler for Low Freq Tx daughterboards.
211   //
212   // @param usrp: instance of usrp.source_c
213   // @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
214 }
215
216 db_lf_tx::~db_lf_tx()
217 {
218 }
219
220 double 
221 db_lf_tx::freq_min() 
222 {
223   return -32e6;
224 }
225
226 double 
227 db_lf_tx::freq_max()
228 {
229   return 32e6;
230 }
231
232 /******************************************************************************/
233
234
235 db_lf_rx::db_lf_rx(usrp_basic_sptr usrp, int which, int subdev)
236   : db_basic_rx(usrp, which, subdev)
237 {
238   // Handler for Low Freq Rx daughterboards.
239   //
240   // @param usrp: instance of usrp.source_c
241   // @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
242   // @param subdev: which analog i/o channel: 0 or 1
243   // @type subdev: int
244 }
245
246 db_lf_rx::~db_lf_rx()
247 {
248 }
249
250 double
251 db_lf_rx::freq_min() 
252 {
253   return 0.0;
254 }
255
256 double
257 db_lf_rx::freq_max() 
258 {
259   return 32e6;
260 }
261
262