Merge branch 'maint'
[debian/gnuradio] / usrp / host / include / usrp / db_flexrf.h
1 /* -*- c++ -*- */
2 //
3 // Copyright 2008,2009 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 asversion 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
18 // along with GNU Radio; see the file COPYING.  If not, write to
19 // the Free Software Foundation, Inc., 51 Franklin Street,
20 // Boston, MA 02110-1301, USA.
21
22 #ifndef DB_FLEXRF_H
23 #define DB_FLEXRF_H
24
25 #include <usrp/db_base.h>
26 #include <cmath>
27
28 //debug_using_gui = true                // Must be set to True or False
29 #define debug_using_gui false           // Must be set to True or False
30
31 class _AD4360_common;
32
33 class flexrf_base : public db_base
34 {
35 public:
36   flexrf_base(usrp_basic_sptr usrp, int which, int _power_on=0);
37   ~flexrf_base();
38
39   struct freq_result_t set_freq(double freq);
40
41   bool  is_quadrature();
42   double freq_min();
43   double freq_max();
44
45 protected:
46   void _write_all(int R, int control, int N);
47   void _write_control(int control);
48   void _write_R(int R);
49   void _write_N(int N);
50   void _write_it(int v);
51   bool _lock_detect();
52
53   virtual bool _compute_regs(double freq, int &retR, int &retcontrol, 
54                              int &retN, double &retfreq);
55   int  _compute_control_reg();
56   int _refclk_divisor();
57
58   bool _set_pga(float pga_gain);
59
60   int power_on() { return d_power_on; }
61   int power_off() { return 0; }
62
63   bool d_first;
64   int  d_spi_format;
65   int  d_spi_enable;
66   int  d_power_on;
67   int  d_PD;
68
69   _AD4360_common *d_common;
70 };
71
72 // ----------------------------------------------------------------
73
74 class flexrf_base_tx : public flexrf_base
75 {
76 protected:
77   void shutdown();
78
79 public:
80   flexrf_base_tx(usrp_basic_sptr usrp, int which, int _power_on=0);
81   ~flexrf_base_tx();
82
83   // All RFX tx d'boards have fixed gain
84   float gain_min();
85   float gain_max();
86   float gain_db_per_step();
87
88   bool set_auto_tr(bool on);
89   bool set_enable(bool on);
90   bool set_gain(float gain);
91 };
92
93 class flexrf_base_rx : public flexrf_base
94 {
95 protected:
96   void shutdown();
97
98 public:
99   flexrf_base_rx(usrp_basic_sptr usrp, int which, int _power_on=0);
100   ~flexrf_base_rx();
101     
102   bool set_auto_tr(bool on);
103   bool select_rx_antenna(int which_antenna);
104   bool select_rx_antenna(const std::string &which_antenna);
105   bool set_gain(float gain);
106
107 };
108
109 // ----------------------------------------------------------------
110
111
112 class _AD4360_common
113 {
114 public:
115   _AD4360_common();
116   virtual ~_AD4360_common();
117
118   virtual double freq_min() = 0;
119   virtual double freq_max() = 0;
120
121   bool _compute_regs(double refclk_freq, double freq, int &retR, 
122                      int &retcontrol, int &retN, double &retfreq);
123   int _compute_control_reg();
124   virtual int _refclk_divisor();
125   int _prescaler();
126
127   void R_DIV(int div) { d_R_DIV = div; }
128
129 protected:
130   int d_R_RSV, d_BSC, d_TEST, d_LDP, d_ABP, d_N_RSV, d_PL, d_MTLD;
131   int d_CPG, d_CP3S, d_PDP, d_MUXOUT, d_CR, d_PC;
132
133   // FIXME: d_PD might cause conflict from flexrf_base
134   int d_A_DIV, d_B_DIV, d_R_DIV, d_P, d_PD, d_CP2, d_CP1, d_DIVSEL;
135   int d_DIV2, d_CPGAIN, d_freq_mult;
136
137 };
138
139 //----------------------------------------------------------------------
140
141 class _2200_common : public _AD4360_common
142 {
143  public:
144   _2200_common();
145   ~_2200_common() {}
146  
147   double freq_min();
148   double freq_max();
149 };
150
151 //----------------------------------------------------------------------
152
153 class _2400_common : public _AD4360_common
154 {
155  public:
156   _2400_common();
157   ~_2400_common() {}
158  
159   double freq_min();
160   double freq_max();
161 };
162
163 //----------------------------------------------------------------------
164
165 class _1200_common : public _AD4360_common
166 {
167 public:
168   _1200_common();
169   ~_1200_common() {}
170
171   double freq_min();
172   double freq_max();
173 };
174
175 //-------------------------------------------------------------------------
176
177 class _1800_common : public _AD4360_common
178 {
179  public:
180   _1800_common();
181   ~_1800_common() {}
182
183   double freq_min();
184   double freq_max();
185 };
186
187 //-------------------------------------------------------------------------
188
189 class _900_common : public _AD4360_common
190 {
191 public:
192   _900_common();
193   ~_900_common() {}
194   
195   double freq_min();
196   double freq_max();
197 };
198
199 //-------------------------------------------------------------------------
200
201 class _400_common : public _AD4360_common
202 {
203 public:
204   _400_common();
205   ~_400_common() {}
206
207   double freq_min();
208   double freq_max();
209 };
210
211 class _400_tx : public _400_common
212 {
213 public:
214   _400_tx();
215   ~_400_tx() {}
216 };
217
218 class _400_rx : public _400_common
219 {
220 public:
221   _400_rx();
222   ~_400_rx() {}
223 };
224
225 //------------------------------------------------------------    
226
227 class db_flexrf_2200_tx : public flexrf_base_tx
228 {
229  public:
230   db_flexrf_2200_tx(usrp_basic_sptr usrp, int which);
231   ~db_flexrf_2200_tx();
232
233   // Wrapper calls to d_common functions
234   bool _compute_regs(double freq, int &retR, int &retcontrol,
235                      int &retN, double &retfreq);
236 };
237
238 class db_flexrf_2200_rx : public flexrf_base_rx
239 {
240 public:
241   db_flexrf_2200_rx(usrp_basic_sptr usrp, int which);
242   ~db_flexrf_2200_rx();
243   
244   float gain_min();
245   float gain_max();
246   float gain_db_per_step();
247   bool i_and_q_swapped();
248
249   bool _compute_regs(double freq, int &retR, int &retcontrol,
250                      int &retN, double &retfreq);
251 };
252
253 //------------------------------------------------------------    
254
255 class db_flexrf_2400_tx : public flexrf_base_tx
256 {
257  public:
258   db_flexrf_2400_tx(usrp_basic_sptr usrp, int which);
259   ~db_flexrf_2400_tx();
260
261   // Wrapper calls to d_common functions
262   bool _compute_regs(double freq, int &retR, int &retcontrol,
263                      int &retN, double &retfreq);
264 };
265
266 class db_flexrf_2400_rx : public flexrf_base_rx
267 {
268 public:
269   db_flexrf_2400_rx(usrp_basic_sptr usrp, int which);
270   ~db_flexrf_2400_rx();
271   
272   float gain_min();
273   float gain_max();
274   float gain_db_per_step();
275   bool i_and_q_swapped();
276
277   bool _compute_regs(double freq, int &retR, int &retcontrol,
278                      int &retN, double &retfreq);
279 };
280
281 //------------------------------------------------------------    
282
283 class db_flexrf_1200_tx : public flexrf_base_tx
284 {
285 public:
286   db_flexrf_1200_tx(usrp_basic_sptr usrp, int which);
287   ~db_flexrf_1200_tx();
288
289   // Wrapper calls to d_common functions
290   bool _compute_regs(double freq, int &retR, int &retcontrol,
291                      int &retN, double &retfreq);
292 };
293
294 class db_flexrf_1200_rx : public flexrf_base_rx
295 {
296 public:
297   db_flexrf_1200_rx(usrp_basic_sptr usrp, int which);
298   ~db_flexrf_1200_rx();
299   
300   float gain_min();
301   float gain_max();
302   float gain_db_per_step();
303   bool i_and_q_swapped();
304
305   bool _compute_regs(double freq, int &retR, int &retcontrol,
306                      int &retN, double &retfreq);
307 };
308
309 //------------------------------------------------------------    
310
311 class db_flexrf_1800_tx : public flexrf_base_tx
312 {
313  public:
314   db_flexrf_1800_tx(usrp_basic_sptr usrp, int which);
315   ~db_flexrf_1800_tx();
316
317   // Wrapper calls to d_common functions
318   bool _compute_regs(double freq, int &retR, int &retcontrol,
319                      int &retN, double &retfreq);
320 };
321
322 class db_flexrf_1800_rx : public flexrf_base_rx
323 {
324 public:
325   db_flexrf_1800_rx(usrp_basic_sptr usrp, int which);
326   ~db_flexrf_1800_rx();
327   
328   float gain_min();
329   float gain_max();
330   float gain_db_per_step();
331   bool i_and_q_swapped();
332
333   bool _compute_regs(double freq, int &retR, int &retcontrol,
334                      int &retN, double &retfreq);
335 };
336
337 //------------------------------------------------------------    
338
339 class db_flexrf_900_tx : public flexrf_base_tx
340 {
341  public:
342   db_flexrf_900_tx(usrp_basic_sptr usrp, int which);
343   ~db_flexrf_900_tx();
344
345   // Wrapper calls to d_common functions
346   bool _compute_regs(double freq, int &retR, int &retcontrol,
347                      int &retN, double &retfreq);
348 };
349
350 class db_flexrf_900_rx : public flexrf_base_rx
351 {
352 public:
353   db_flexrf_900_rx(usrp_basic_sptr usrp, int which);
354   ~db_flexrf_900_rx();
355   
356   float gain_min();
357   float gain_max();
358   float gain_db_per_step();
359   bool i_and_q_swapped();
360
361   bool _compute_regs(double freq, int &retR, int &retcontrol,
362                      int &retN, double &retfreq);
363 };
364
365
366 //------------------------------------------------------------    
367
368 class db_flexrf_400_tx : public flexrf_base_tx
369 {
370  public:
371   db_flexrf_400_tx(usrp_basic_sptr usrp, int which);
372   ~db_flexrf_400_tx();
373
374   // Wrapper calls to d_common functions
375   bool _compute_regs(double freq, int &retR, int &retcontrol,
376                      int &retN, double &retfreq);
377 };
378
379 class db_flexrf_400_rx : public flexrf_base_rx
380 {
381 public:
382   db_flexrf_400_rx(usrp_basic_sptr usrp, int which);
383   ~db_flexrf_400_rx();
384
385   float gain_min();
386   float gain_max();
387   float gain_db_per_step();
388   bool i_and_q_swapped();
389
390   bool _compute_regs(double freq, int &retR, int &retcontrol,
391                      int &retN, double &retfreq);
392 };
393
394 #endif