Imported Upstream version 3.2.2
[debian/gnuradio] / usrp / host / lib / legacy / db_flexrf.h
1 /* -*- c++ -*- */
2 //
3 // Copyright 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 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 <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   double _refclk_freq();
58
59   bool _set_pga(float pga_gain);
60
61   int power_on() { return d_power_on; }
62   int power_off() { return 0; }
63
64   bool d_first;
65   int  d_spi_format;
66   int  d_spi_enable;
67   int  d_power_on;
68   int  d_PD;
69
70   _AD4360_common *d_common;
71 };
72
73 // ----------------------------------------------------------------
74
75 class flexrf_base_tx : public flexrf_base
76 {
77 protected:
78   void shutdown();
79
80 public:
81   flexrf_base_tx(usrp_basic_sptr usrp, int which, int _power_on=0);
82   ~flexrf_base_tx();
83
84   // All RFX tx d'boards have fixed gain
85   float gain_min();
86   float gain_max();
87   float gain_db_per_step();
88
89   bool set_auto_tr(bool on);
90   bool set_enable(bool on);
91   bool set_gain(float gain);
92 };
93
94 class flexrf_base_rx : public flexrf_base
95 {
96 protected:
97   void shutdown();
98
99 public:
100   flexrf_base_rx(usrp_basic_sptr usrp, int which, int _power_on=0);
101   ~flexrf_base_rx();
102     
103   bool set_auto_tr(bool on);
104   bool select_rx_antenna(int which_antenna);
105   bool select_rx_antenna(const std::string &which_antenna);
106   bool set_gain(float gain);
107
108 };
109
110 // ----------------------------------------------------------------
111
112
113 class _AD4360_common
114 {
115 public:
116   _AD4360_common();
117   virtual ~_AD4360_common();
118
119   virtual double freq_min() = 0;
120   virtual double freq_max() = 0;
121
122   bool _compute_regs(double refclk_freq, double freq, int &retR, 
123                      int &retcontrol, int &retN, double &retfreq);
124   int _compute_control_reg();
125   virtual int _refclk_divisor();
126   int _prescaler();
127
128   void R_DIV(int div) { d_R_DIV = div; }
129
130 protected:
131   int d_R_RSV, d_BSC, d_TEST, d_LDP, d_ABP, d_N_RSV, d_PL, d_MTLD;
132   int d_CPG, d_CP3S, d_PDP, d_MUXOUT, d_CR, d_PC;
133
134   // FIXME: d_PD might cause conflict from flexrf_base
135   int d_A_DIV, d_B_DIV, d_R_DIV, d_P, d_PD, d_CP2, d_CP1, d_DIVSEL;
136   int d_DIV2, d_CPGAIN, d_freq_mult;
137
138 };
139
140 //----------------------------------------------------------------------
141
142 class _2400_common : public _AD4360_common
143 {
144  public:
145   _2400_common();
146   ~_2400_common() {}
147  
148   double freq_min();
149   double freq_max();
150 };
151
152 //----------------------------------------------------------------------
153
154 class _1200_common : public _AD4360_common
155 {
156 public:
157   _1200_common();
158   ~_1200_common() {}
159
160   double freq_min();
161   double freq_max();
162 };
163
164 //-------------------------------------------------------------------------
165
166 class _1800_common : public _AD4360_common
167 {
168  public:
169   _1800_common();
170   ~_1800_common() {}
171
172   double freq_min();
173   double freq_max();
174 };
175
176 //-------------------------------------------------------------------------
177
178 class _900_common : public _AD4360_common
179 {
180 public:
181   _900_common();
182   ~_900_common() {}
183   
184   double freq_min();
185   double freq_max();
186 };
187
188 //-------------------------------------------------------------------------
189
190 class _400_common : public _AD4360_common
191 {
192 public:
193   _400_common();
194   ~_400_common() {}
195
196   double freq_min();
197   double freq_max();
198 };
199
200 class _400_tx : public _400_common
201 {
202 public:
203   _400_tx();
204   ~_400_tx() {}
205 };
206
207 class _400_rx : public _400_common
208 {
209 public:
210   _400_rx();
211   ~_400_rx() {}
212 };
213
214 //------------------------------------------------------------    
215
216 class db_flexrf_2400_tx : public flexrf_base_tx
217 {
218  public:
219   db_flexrf_2400_tx(usrp_basic_sptr usrp, int which);
220   ~db_flexrf_2400_tx();
221
222   // Wrapper calls to d_common functions
223   bool _compute_regs(double freq, int &retR, int &retcontrol,
224                      int &retN, double &retfreq);
225 };
226
227 class db_flexrf_2400_rx : public flexrf_base_rx
228 {
229 public:
230   db_flexrf_2400_rx(usrp_basic_sptr usrp, int which);
231   ~db_flexrf_2400_rx();
232   
233   float gain_min();
234   float gain_max();
235   float gain_db_per_step();
236   bool i_and_q_swapped();
237
238   bool _compute_regs(double freq, int &retR, int &retcontrol,
239                      int &retN, double &retfreq);
240 };
241
242 //------------------------------------------------------------    
243
244 class db_flexrf_1200_tx : public flexrf_base_tx
245 {
246 public:
247   db_flexrf_1200_tx(usrp_basic_sptr usrp, int which);
248   ~db_flexrf_1200_tx();
249
250   // Wrapper calls to d_common functions
251   bool _compute_regs(double freq, int &retR, int &retcontrol,
252                      int &retN, double &retfreq);
253 };
254
255 class db_flexrf_1200_rx : public flexrf_base_rx
256 {
257 public:
258   db_flexrf_1200_rx(usrp_basic_sptr usrp, int which);
259   ~db_flexrf_1200_rx();
260   
261   float gain_min();
262   float gain_max();
263   float gain_db_per_step();
264   bool i_and_q_swapped();
265
266   bool _compute_regs(double freq, int &retR, int &retcontrol,
267                      int &retN, double &retfreq);
268 };
269
270 //------------------------------------------------------------    
271
272 class db_flexrf_1800_tx : public flexrf_base_tx
273 {
274  public:
275   db_flexrf_1800_tx(usrp_basic_sptr usrp, int which);
276   ~db_flexrf_1800_tx();
277
278   // Wrapper calls to d_common functions
279   bool _compute_regs(double freq, int &retR, int &retcontrol,
280                      int &retN, double &retfreq);
281 };
282
283 class db_flexrf_1800_rx : public flexrf_base_rx
284 {
285 public:
286   db_flexrf_1800_rx(usrp_basic_sptr usrp, int which);
287   ~db_flexrf_1800_rx();
288   
289   float gain_min();
290   float gain_max();
291   float gain_db_per_step();
292   bool i_and_q_swapped();
293
294   bool _compute_regs(double freq, int &retR, int &retcontrol,
295                      int &retN, double &retfreq);
296 };
297
298 //------------------------------------------------------------    
299
300 class db_flexrf_900_tx : public flexrf_base_tx
301 {
302  public:
303   db_flexrf_900_tx(usrp_basic_sptr usrp, int which);
304   ~db_flexrf_900_tx();
305
306   // Wrapper calls to d_common functions
307   bool _compute_regs(double freq, int &retR, int &retcontrol,
308                      int &retN, double &retfreq);
309 };
310
311 class db_flexrf_900_rx : public flexrf_base_rx
312 {
313 public:
314   db_flexrf_900_rx(usrp_basic_sptr usrp, int which);
315   ~db_flexrf_900_rx();
316   
317   float gain_min();
318   float gain_max();
319   float gain_db_per_step();
320   bool i_and_q_swapped();
321
322   bool _compute_regs(double freq, int &retR, int &retcontrol,
323                      int &retN, double &retfreq);
324 };
325
326
327 //------------------------------------------------------------    
328
329 class db_flexrf_400_tx : public flexrf_base_tx
330 {
331  public:
332   db_flexrf_400_tx(usrp_basic_sptr usrp, int which);
333   ~db_flexrf_400_tx();
334
335   // Wrapper calls to d_common functions
336   bool _compute_regs(double freq, int &retR, int &retcontrol,
337                      int &retN, double &retfreq);
338 };
339
340 class db_flexrf_400_rx : public flexrf_base_rx
341 {
342 public:
343   db_flexrf_400_rx(usrp_basic_sptr usrp, int which);
344   ~db_flexrf_400_rx();
345
346   float gain_min();
347   float gain_max();
348   float gain_db_per_step();
349   bool i_and_q_swapped();
350
351   bool _compute_regs(double freq, int &retR, int &retcontrol,
352                      int &retN, double &retfreq);
353 };
354
355 #endif