Imported Upstream version 3.2.2
[debian/gnuradio] / usrp / host / lib / legacy / db_wbx.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_WBX_H
23 #define DB_WBX_H
24
25 #include <db_base.h>
26 #include <boost/shared_ptr.hpp>
27
28
29 /*
30   A few comments about the WBX boards:
31   They are half-duplex.  I.e., transmit and receive are mutually exclusive.
32   There is a single LO for both the Tx and Rx sides.
33   The the shared control signals are hung off of the Rx side.
34   The shared io controls are duplexed onto the Rx side pins.
35   The wbx_high d'board always needs to be in 'auto_tr_mode'
36 */
37
38
39 class wbx_base : public db_base
40 {
41 protected:
42   void shutdown();
43
44   /*
45    * Abstract base class for all wbx boards.
46    * 
47    * Derive board specific subclasses from db_wbx_base_{tx,rx}
48    */
49
50 public:
51   wbx_base(usrp_basic_sptr usrp, int which);
52   ~wbx_base();
53   
54   struct freq_result_t set_freq(double freq);
55   float gain_min();
56   float gain_max();
57   float gain_db_per_step();
58   bool set_gain(float gain);  
59   bool is_quadrature();
60
61
62 protected:
63   virtual bool _lock_detect();
64
65   // FIXME: After testing, replace these with usrp_basic::common_write_io/oe
66   bool _tx_write_oe(int value, int mask);
67   bool _rx_write_oe(int value, int mask);
68   bool _tx_write_io(int value, int mask);
69   bool _rx_write_io(int value, int mask);
70   virtual bool _rx_read_io();
71   bool _tx_read_io();
72   bool  _compute_regs(double freq);
73   virtual double _refclk_freq();
74   int _refclk_divisor();
75
76   bool _set_pga(float pga_gain);
77
78   bool d_first;
79   int d_spi_format;
80   int d_spi_enable;
81   double d_lo_offset;
82 };
83
84
85 /****************************************************************************/
86
87
88 class wbx_base_tx : public wbx_base
89 {
90 public:
91   wbx_base_tx(usrp_basic_sptr usrp, int which);
92   ~wbx_base_tx();
93
94   bool set_auto_tr(bool on);
95   bool set_enable(bool on);
96 };
97
98
99 /****************************************************************************/
100
101
102 class wbx_base_rx : public wbx_base
103 {
104 public:
105   wbx_base_rx(usrp_basic_sptr usrp, int which);
106   ~wbx_base_rx();
107   
108   bool set_auto_tr(bool on);
109   bool select_rx_antenna(int which_antenna);
110   bool select_rx_antenna(const std::string &which_antenna);
111   bool set_gain(float gain);
112   bool i_and_q_swapped();
113 };
114
115
116 /****************************************************************************/
117
118
119 class _ADF410X_common
120 {
121 public:
122   _ADF410X_common();
123   virtual ~_ADF410X_common();
124   
125   bool _compute_regs(double freq, int &retR, int &retcontrol,
126                      int &retN, double &retfreq);
127   void _write_all(int R, int N, int control);
128   void _write_R(int R);
129   void _write_N(int N);
130   void _write_func(int func);
131   void _write_init(int init);
132   int  _prescaler();
133   virtual void _write_it(int v);
134   virtual double _refclk_freq();
135   virtual bool _rx_write_io(int value, int mask);
136   virtual bool _lock_detect();
137
138 protected:
139   virtual usrp_basic* usrp();
140
141   int d_R_RSV, d_LDP, d_TEST, d_ABP;
142   int d_N_RSV, d_CP_GAIN;
143   int d_P, d_PD2, d_CP2, d_CP1, d_TC, d_FL;
144   int d_CP3S, d_PDP, d_MUXOUT, d_PD1, d_CR;
145   int d_R_DIV, d_A_DIV, d_B_DIV;
146   int d_freq_mult;
147
148   int d_spi_format;
149   int d_spi_enable;
150 };
151
152
153 /****************************************************************************/
154
155
156 class _lo_common : public _ADF410X_common
157 {
158 public:
159   _lo_common();
160   ~_lo_common();
161
162   double freq_min();
163   double freq_max();
164   
165   void set_divider(int main_or_aux, int divisor);
166   void set_divider(const std::string &main_or_aux, int divisor);
167
168   struct freq_result_t set_freq(double freq);
169
170 protected:
171   int d_R_DIV, d_P, d_CP2, d_CP1;
172   int d_DIVSEL, d_DIV2, d_CPGAIN;
173   int d_div, d_aux_div, d_main_div;
174 };
175         
176
177 /****************************************************************************/
178
179
180 class db_wbx_lo_tx : public _lo_common, public wbx_base_tx
181 {
182 public:
183   db_wbx_lo_tx(usrp_basic_sptr usrp, int which);
184   ~db_wbx_lo_tx();
185
186   float gain_min();
187   float gain_max();
188   float gain_db_per_step();
189   bool  set_gain(float gain);
190
191   double _refclk_freq();
192   bool _rx_write_io(int value, int mask);
193   bool _lock_detect();
194
195 protected:
196   usrp_basic* usrp();
197 };
198         
199
200 /****************************************************************************/
201
202
203 class db_wbx_lo_rx : public _lo_common, public  wbx_base_rx
204 {
205 public:
206   db_wbx_lo_rx(usrp_basic_sptr usrp, int which);
207   ~db_wbx_lo_rx();
208
209   float gain_min();
210   float gain_max();
211   float gain_db_per_step();
212
213   double _refclk_freq();
214   bool _rx_write_io(int value, int mask);
215   bool _lock_detect();
216
217 protected:
218   usrp_basic* usrp();
219 };
220
221 #endif