summaryrefslogtreecommitdiff
path: root/usrp/host/lib/legacy/db_wbx.h
blob: 3202d368c82dee2a72fbca4650d0c77ad0c09df2 (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
/* -*- 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_WBX_H
#define DB_WBX_H

#include <db_base.h>
#include <boost/shared_ptr.hpp>


/*
  A few comments about the WBX boards:
  They are half-duplex.  I.e., transmit and receive are mutually exclusive.
  There is a single LO for both the Tx and Rx sides.
  The the shared control signals are hung off of the Rx side.
  The shared io controls are duplexed onto the Rx side pins.
  The wbx_high d'board always needs to be in 'auto_tr_mode'
*/


class wbx_base : public db_base
{
protected:
  void shutdown();

  /*
   * Abstract base class for all wbx boards.
   * 
   * Derive board specific subclasses from db_wbx_base_{tx,rx}
   */

public:
  wbx_base(usrp_basic_sptr usrp, int which);
  ~wbx_base();
  
  struct freq_result_t set_freq(double freq);
  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool set_gain(float gain);  
  bool is_quadrature();


protected:
  virtual bool _lock_detect();

  // FIXME: After testing, replace these with usrp_basic::common_write_io/oe
  bool _tx_write_oe(int value, int mask);
  bool _rx_write_oe(int value, int mask);
  bool _tx_write_io(int value, int mask);
  bool _rx_write_io(int value, int mask);
  virtual bool _rx_read_io();
  bool _tx_read_io();
  bool  _compute_regs(double freq);
  virtual double _refclk_freq();
  int _refclk_divisor();

  bool _set_pga(float pga_gain);

  bool d_first;
  int d_spi_format;
  int d_spi_enable;
  double d_lo_offset;
};


/****************************************************************************/


class wbx_base_tx : public wbx_base
{
public:
  wbx_base_tx(usrp_basic_sptr usrp, int which);
  ~wbx_base_tx();

  bool set_auto_tr(bool on);
  bool set_enable(bool on);
};


/****************************************************************************/


class wbx_base_rx : public wbx_base
{
public:
  wbx_base_rx(usrp_basic_sptr usrp, int which);
  ~wbx_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);
  bool i_and_q_swapped();
};


/****************************************************************************/


class _ADF410X_common
{
public:
  _ADF410X_common();
  virtual ~_ADF410X_common();
  
  bool _compute_regs(double freq, int &retR, int &retcontrol,
		     int &retN, double &retfreq);
  void _write_all(int R, int N, int control);
  void _write_R(int R);
  void _write_N(int N);
  void _write_func(int func);
  void _write_init(int init);
  int  _prescaler();
  virtual void _write_it(int v);
  virtual double _refclk_freq();
  virtual bool _rx_write_io(int value, int mask);
  virtual bool _lock_detect();

protected:
  virtual usrp_basic* usrp();

  int d_R_RSV, d_LDP, d_TEST, d_ABP;
  int d_N_RSV, d_CP_GAIN;
  int d_P, d_PD2, d_CP2, d_CP1, d_TC, d_FL;
  int d_CP3S, d_PDP, d_MUXOUT, d_PD1, d_CR;
  int d_R_DIV, d_A_DIV, d_B_DIV;
  int d_freq_mult;

  int d_spi_format;
  int d_spi_enable;
};


/****************************************************************************/


class _lo_common : public _ADF410X_common
{
public:
  _lo_common();
  ~_lo_common();

  double freq_min();
  double freq_max();
  
  void set_divider(int main_or_aux, int divisor);
  void set_divider(const std::string &main_or_aux, int divisor);

  struct freq_result_t set_freq(double freq);

protected:
  int d_R_DIV, d_P, d_CP2, d_CP1;
  int d_DIVSEL, d_DIV2, d_CPGAIN;
  int d_div, d_aux_div, d_main_div;
};
        

/****************************************************************************/


class db_wbx_lo_tx : public _lo_common, public wbx_base_tx
{
public:
  db_wbx_lo_tx(usrp_basic_sptr usrp, int which);
  ~db_wbx_lo_tx();

  float gain_min();
  float gain_max();
  float gain_db_per_step();
  bool  set_gain(float gain);

  double _refclk_freq();
  bool _rx_write_io(int value, int mask);
  bool _lock_detect();

protected:
  usrp_basic* usrp();
};
        

/****************************************************************************/


class db_wbx_lo_rx : public _lo_common, public  wbx_base_rx
{
public:
  db_wbx_lo_rx(usrp_basic_sptr usrp, int which);
  ~db_wbx_lo_rx();

  float gain_min();
  float gain_max();
  float gain_db_per_step();

  double _refclk_freq();
  bool _rx_write_io(int value, int mask);
  bool _lock_detect();

protected:
  usrp_basic* usrp();
};

#endif