summaryrefslogtreecommitdiff
path: root/usrp/host/lib/legacy/db_flexrf.h
blob: b9ccfc3acf29ea10c0091bfca82879eb02135d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/* -*- c++ -*- */
//
// Copyright 2008 Free Software Foundation, Inc.
// 
// This file is part of GNU Radio
// 
// GNU Radio is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either asversion 3, or (at your option)
// any later version.
// 
// GNU Radio is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with GNU Radio; see the file COPYING.  If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street,
// Boston, MA 02110-1301, USA.

#ifndef DB_FLEXRF_H
#define DB_FLEXRF_H

#include <db_base.h>
#include <cmath>

//debug_using_gui = true                // Must be set to True or False
#define debug_using_gui false           // Must be set to True or False

class _AD4360_common;

class flexrf_base : public db_base
{
public:
  flexrf_base(usrp_basic_sptr usrp, int which, int _power_on=0);
  ~flexrf_base();

  struct freq_result_t set_freq(double freq);

  bool  is_quadrature();
  double freq_min();
  double freq_max();

protected:
  void _write_all(int R, int control, int N);
  void _write_control(int control);
  void _write_R(int R);
  void _write_N(int N);
  void _write_it(int v);
  bool _lock_detect();

  virtual bool _compute_regs(double freq, int &retR, int &retcontrol, 
			     int &retN, double &retfreq);
  int  _compute_control_reg();
  int _refclk_divisor();
  double _refclk_freq();

  bool _set_pga(float pga_gain);

  int power_on() { return d_power_on; }
  int power_off() { return 0; }

  bool d_first;
  int  d_spi_format;
  int  d_spi_enable;
  int  d_power_on;
  int  d_PD;

  _AD4360_common *d_common;
};

// ----------------------------------------------------------------

class flexrf_base_tx : public flexrf_base
{
protected:
  void shutdown();

public:
  flexrf_base_tx(usrp_basic_sptr usrp, int which, int _power_on=0);
  ~flexrf_base_tx();

  // All RFX tx d'boards have fixed gain
  float gain_min();
  float gain_max();
  float gain_db_per_step();

  bool set_auto_tr(bool on);
  bool set_enable(bool on);
  bool set_gain(float gain);
};

class flexrf_base_rx : public flexrf_base
{
protected:
  void shutdown();

public:
  flexrf_base_rx(usrp_basic_sptr usrp, int which, int _power_on=0);
  ~flexrf_base_rx();
    
  bool set_auto_tr(bool on);
  bool select_rx_antenna(int which_antenna);
  bool select_rx_antenna(const std::string &which_antenna);
  bool set_gain(float gain);

};

// ----------------------------------------------------------------


class _AD4360_common
{
public:
  _AD4360_common();
  virtual ~_AD4360_common();

  virtual double freq_min() = 0;
  virtual double freq_max() = 0;

  bool _compute_regs(double refclk_freq, double freq, int &retR, 
		     int &retcontrol, int &retN, double &retfreq);
  int _compute_control_reg();
  virtual int _refclk_divisor();
  int _prescaler();

  void R_DIV(int div) { d_R_DIV = div; }

protected:
  int d_R_RSV, d_BSC, d_TEST, d_LDP, d_ABP, d_N_RSV, d_PL, d_MTLD;
  int d_CPG, d_CP3S, d_PDP, d_MUXOUT, d_CR, d_PC;

  // FIXME: d_PD might cause conflict from flexrf_base
  int d_A_DIV, d_B_DIV, d_R_DIV, d_P, d_PD, d_CP2, d_CP1, d_DIVSEL;
  int d_DIV2, d_CPGAIN, d_freq_mult;

};

//----------------------------------------------------------------------

class _2400_common : public _AD4360_common
{
 public:
  _2400_common();
  ~_2400_common() {}
 
  double freq_min();
  double freq_max();
};

//----------------------------------------------------------------------

class _1200_common : public _AD4360_common
{
public:
  _1200_common();
  ~_1200_common() {}

  double freq_min();
  double freq_max();
};

//-------------------------------------------------------------------------

class _1800_common : public _AD4360_common
{
 public:
  _1800_common();
  ~_1800_common() {}

  double freq_min();
  double freq_max();
};

//-------------------------------------------------------------------------

class _900_common : public _AD4360_common
{
public:
  _900_common();
  ~_900_common() {}
  
  double freq_min();
  double freq_max();
};

//-------------------------------------------------------------------------

class _400_common : public _AD4360_common
{
public:
  _400_common();
  ~_400_common() {}

  double freq_min();
  double freq_max();
};

class _400_tx : public _400_common
{
public:
  _400_tx();
  ~_400_tx() {}
};

class _400_rx : public _400_common
{
public:
  _400_rx();
  ~_400_rx() {}
};

//------------------------------------------------------------    

class db_flexrf_2400_tx : public flexrf_base_tx
{
 public:
  db_flexrf_2400_tx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_2400_tx();

  // Wrapper calls to d_common functions
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

class db_flexrf_2400_rx : public flexrf_base_rx
{
public:
  db_flexrf_2400_rx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_2400_rx();
  
  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool i_and_q_swapped();

  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

//------------------------------------------------------------    

class db_flexrf_1200_tx : public flexrf_base_tx
{
public:
  db_flexrf_1200_tx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_1200_tx();

  // Wrapper calls to d_common functions
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

class db_flexrf_1200_rx : public flexrf_base_rx
{
public:
  db_flexrf_1200_rx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_1200_rx();
  
  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool i_and_q_swapped();

  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

//------------------------------------------------------------    

class db_flexrf_1800_tx : public flexrf_base_tx
{
 public:
  db_flexrf_1800_tx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_1800_tx();

  // Wrapper calls to d_common functions
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

class db_flexrf_1800_rx : public flexrf_base_rx
{
public:
  db_flexrf_1800_rx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_1800_rx();
  
  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool i_and_q_swapped();

  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

//------------------------------------------------------------    

class db_flexrf_900_tx : public flexrf_base_tx
{
 public:
  db_flexrf_900_tx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_900_tx();

  // Wrapper calls to d_common functions
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

class db_flexrf_900_rx : public flexrf_base_rx
{
public:
  db_flexrf_900_rx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_900_rx();
  
  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool i_and_q_swapped();

  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};


//------------------------------------------------------------    

class db_flexrf_400_tx : public flexrf_base_tx
{
 public:
  db_flexrf_400_tx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_400_tx();

  // Wrapper calls to d_common functions
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

class db_flexrf_400_rx : public flexrf_base_rx
{
public:
  db_flexrf_400_rx(usrp_basic_sptr usrp, int which);
  ~db_flexrf_400_rx();

  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool i_and_q_swapped();

  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
};

#endif