0c834402d0e44f8fa4f70bec409bc85672fef007
[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 _2400_common : public _AD4360_common
142 {
143  public:
144   _2400_common();
145   ~_2400_common() {}
146  
147   double freq_min();
148   double freq_max();
149 };
150
151 //----------------------------------------------------------------------
152
153 class _1200_common : public _AD4360_common
154 {
155 public:
156   _1200_common();
157   ~_1200_common() {}
158
159   double freq_min();
160   double freq_max();
161 };
162
163 //-------------------------------------------------------------------------
164
165 class _1800_common : public _AD4360_common
166 {
167  public:
168   _1800_common();
169   ~_1800_common() {}
170
171   double freq_min();
172   double freq_max();
173 };
174
175 //-------------------------------------------------------------------------
176
177 class _900_common : public _AD4360_common
178 {
179 public:
180   _900_common();
181   ~_900_common() {}
182   
183   double freq_min();
184   double freq_max();
185 };
186
187 //-------------------------------------------------------------------------
188
189 class _400_common : public _AD4360_common
190 {
191 public:
192   _400_common();
193   ~_400_common() {}
194
195   double freq_min();
196   double freq_max();
197 };
198
199 class _400_tx : public _400_common
200 {
201 public:
202   _400_tx();
203   ~_400_tx() {}
204 };
205
206 class _400_rx : public _400_common
207 {
208 public:
209   _400_rx();
210   ~_400_rx() {}
211 };
212
213 //------------------------------------------------------------    
214
215 class db_flexrf_2400_tx : public flexrf_base_tx
216 {
217  public:
218   db_flexrf_2400_tx(usrp_basic_sptr usrp, int which);
219   ~db_flexrf_2400_tx();
220
221   // Wrapper calls to d_common functions
222   bool _compute_regs(double freq, int &retR, int &retcontrol,
223                      int &retN, double &retfreq);
224 };
225
226 class db_flexrf_2400_rx : public flexrf_base_rx
227 {
228 public:
229   db_flexrf_2400_rx(usrp_basic_sptr usrp, int which);
230   ~db_flexrf_2400_rx();
231   
232   float gain_min();
233   float gain_max();
234   float gain_db_per_step();
235   bool i_and_q_swapped();
236
237   bool _compute_regs(double freq, int &retR, int &retcontrol,
238                      int &retN, double &retfreq);
239 };
240
241 //------------------------------------------------------------    
242
243 class db_flexrf_1200_tx : public flexrf_base_tx
244 {
245 public:
246   db_flexrf_1200_tx(usrp_basic_sptr usrp, int which);
247   ~db_flexrf_1200_tx();
248
249   // Wrapper calls to d_common functions
250   bool _compute_regs(double freq, int &retR, int &retcontrol,
251                      int &retN, double &retfreq);
252 };
253
254 class db_flexrf_1200_rx : public flexrf_base_rx
255 {
256 public:
257   db_flexrf_1200_rx(usrp_basic_sptr usrp, int which);
258   ~db_flexrf_1200_rx();
259   
260   float gain_min();
261   float gain_max();
262   float gain_db_per_step();
263   bool i_and_q_swapped();
264
265   bool _compute_regs(double freq, int &retR, int &retcontrol,
266                      int &retN, double &retfreq);
267 };
268
269 //------------------------------------------------------------    
270
271 class db_flexrf_1800_tx : public flexrf_base_tx
272 {
273  public:
274   db_flexrf_1800_tx(usrp_basic_sptr usrp, int which);
275   ~db_flexrf_1800_tx();
276
277   // Wrapper calls to d_common functions
278   bool _compute_regs(double freq, int &retR, int &retcontrol,
279                      int &retN, double &retfreq);
280 };
281
282 class db_flexrf_1800_rx : public flexrf_base_rx
283 {
284 public:
285   db_flexrf_1800_rx(usrp_basic_sptr usrp, int which);
286   ~db_flexrf_1800_rx();
287   
288   float gain_min();
289   float gain_max();
290   float gain_db_per_step();
291   bool i_and_q_swapped();
292
293   bool _compute_regs(double freq, int &retR, int &retcontrol,
294                      int &retN, double &retfreq);
295 };
296
297 //------------------------------------------------------------    
298
299 class db_flexrf_900_tx : public flexrf_base_tx
300 {
301  public:
302   db_flexrf_900_tx(usrp_basic_sptr usrp, int which);
303   ~db_flexrf_900_tx();
304
305   // Wrapper calls to d_common functions
306   bool _compute_regs(double freq, int &retR, int &retcontrol,
307                      int &retN, double &retfreq);
308 };
309
310 class db_flexrf_900_rx : public flexrf_base_rx
311 {
312 public:
313   db_flexrf_900_rx(usrp_basic_sptr usrp, int which);
314   ~db_flexrf_900_rx();
315   
316   float gain_min();
317   float gain_max();
318   float gain_db_per_step();
319   bool i_and_q_swapped();
320
321   bool _compute_regs(double freq, int &retR, int &retcontrol,
322                      int &retN, double &retfreq);
323 };
324
325
326 //------------------------------------------------------------    
327
328 class db_flexrf_400_tx : public flexrf_base_tx
329 {
330  public:
331   db_flexrf_400_tx(usrp_basic_sptr usrp, int which);
332   ~db_flexrf_400_tx();
333
334   // Wrapper calls to d_common functions
335   bool _compute_regs(double freq, int &retR, int &retcontrol,
336                      int &retN, double &retfreq);
337 };
338
339 class db_flexrf_400_rx : public flexrf_base_rx
340 {
341 public:
342   db_flexrf_400_rx(usrp_basic_sptr usrp, int which);
343   ~db_flexrf_400_rx();
344
345   float gain_min();
346   float gain_max();
347   float gain_db_per_step();
348   bool i_and_q_swapped();
349
350   bool _compute_regs(double freq, int &retR, int &retcontrol,
351                      int &retN, double &retfreq);
352 };
353
354 #endif