GNU Radio 3.4.2 C++ API
db_flexrf.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 //
00003 // Copyright 2008,2009 Free Software Foundation, Inc.
00004 // 
00005 // This file is part of GNU Radio
00006 // 
00007 // GNU Radio is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either asversion 3, or (at your option)
00010 // any later version.
00011 // 
00012 // GNU Radio is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // 
00017 // You should have received a copy of the GNU General Public License
00018 // along with GNU Radio; see the file COPYING.  If not, write to
00019 // the Free Software Foundation, Inc., 51 Franklin Street,
00020 // Boston, MA 02110-1301, USA.
00021 
00022 #ifndef DB_FLEXRF_H
00023 #define DB_FLEXRF_H
00024 
00025 #include <usrp/db_base.h>
00026 #include <cmath>
00027 
00028 //debug_using_gui = true                // Must be set to True or False
00029 #define debug_using_gui false           // Must be set to True or False
00030 
00031 class _AD4360_common;
00032 
00033 class flexrf_base : public db_base
00034 {
00035 public:
00036   flexrf_base(usrp_basic_sptr usrp, int which, int _power_on=0);
00037   ~flexrf_base();
00038 
00039   struct freq_result_t set_freq(double freq);
00040 
00041   bool  is_quadrature();
00042   double freq_min();
00043   double freq_max();
00044 
00045 protected:
00046   void _write_all(int R, int control, int N);
00047   void _write_control(int control);
00048   void _write_R(int R);
00049   void _write_N(int N);
00050   void _write_it(int v);
00051   bool _lock_detect();
00052 
00053   virtual bool _compute_regs(double freq, int &retR, int &retcontrol, 
00054                              int &retN, double &retfreq);
00055   int  _compute_control_reg();
00056   int _refclk_divisor();
00057 
00058   bool _set_pga(float pga_gain);
00059 
00060   int power_on() { return d_power_on; }
00061   int power_off() { return 0; }
00062 
00063   bool d_first;
00064   int  d_spi_format;
00065   int  d_spi_enable;
00066   int  d_power_on;
00067   int  d_PD;
00068 
00069   _AD4360_common *d_common;
00070 };
00071 
00072 // ----------------------------------------------------------------
00073 
00074 class flexrf_base_tx : public flexrf_base
00075 {
00076 protected:
00077   void shutdown();
00078 
00079 public:
00080   flexrf_base_tx(usrp_basic_sptr usrp, int which, int _power_on=0);
00081   ~flexrf_base_tx();
00082 
00083   // All RFX tx d'boards have fixed gain
00084   float gain_min();
00085   float gain_max();
00086   float gain_db_per_step();
00087 
00088   bool set_auto_tr(bool on);
00089   bool set_enable(bool on);
00090   bool set_gain(float gain);
00091 };
00092 
00093 class flexrf_base_rx : public flexrf_base
00094 {
00095 protected:
00096   void shutdown();
00097 
00098 public:
00099   flexrf_base_rx(usrp_basic_sptr usrp, int which, int _power_on=0);
00100   ~flexrf_base_rx();
00101     
00102   bool set_auto_tr(bool on);
00103   bool select_rx_antenna(int which_antenna);
00104   bool select_rx_antenna(const std::string &which_antenna);
00105   bool set_gain(float gain);
00106 
00107 };
00108 
00109 // ----------------------------------------------------------------
00110 
00111 
00112 class _AD4360_common
00113 {
00114 public:
00115   _AD4360_common();
00116   virtual ~_AD4360_common();
00117 
00118   virtual double freq_min() = 0;
00119   virtual double freq_max() = 0;
00120 
00121   bool _compute_regs(double refclk_freq, double freq, int &retR, 
00122                      int &retcontrol, int &retN, double &retfreq);
00123   int _compute_control_reg();
00124   virtual int _refclk_divisor();
00125   int _prescaler();
00126 
00127   void R_DIV(int div) { d_R_DIV = div; }
00128 
00129 protected:
00130   int d_R_RSV, d_BSC, d_TEST, d_LDP, d_ABP, d_N_RSV, d_PL, d_MTLD;
00131   int d_CPG, d_CP3S, d_PDP, d_MUXOUT, d_CR, d_PC;
00132 
00133   // FIXME: d_PD might cause conflict from flexrf_base
00134   int d_A_DIV, d_B_DIV, d_R_DIV, d_P, d_PD, d_CP2, d_CP1, d_DIVSEL;
00135   int d_DIV2, d_CPGAIN, d_freq_mult;
00136 
00137 };
00138 
00139 //----------------------------------------------------------------------
00140 
00141 class _2200_common : public _AD4360_common
00142 {
00143  public:
00144   _2200_common();
00145   ~_2200_common() {}
00146  
00147   double freq_min();
00148   double freq_max();
00149 };
00150 
00151 //----------------------------------------------------------------------
00152 
00153 class _2400_common : public _AD4360_common
00154 {
00155  public:
00156   _2400_common();
00157   ~_2400_common() {}
00158  
00159   double freq_min();
00160   double freq_max();
00161 };
00162 
00163 //----------------------------------------------------------------------
00164 
00165 class _1200_common : public _AD4360_common
00166 {
00167 public:
00168   _1200_common();
00169   ~_1200_common() {}
00170 
00171   double freq_min();
00172   double freq_max();
00173 };
00174 
00175 //-------------------------------------------------------------------------
00176 
00177 class _1800_common : public _AD4360_common
00178 {
00179  public:
00180   _1800_common();
00181   ~_1800_common() {}
00182 
00183   double freq_min();
00184   double freq_max();
00185 };
00186 
00187 //-------------------------------------------------------------------------
00188 
00189 class _900_common : public _AD4360_common
00190 {
00191 public:
00192   _900_common();
00193   ~_900_common() {}
00194   
00195   double freq_min();
00196   double freq_max();
00197 };
00198 
00199 //-------------------------------------------------------------------------
00200 
00201 class _400_common : public _AD4360_common
00202 {
00203 public:
00204   _400_common();
00205   ~_400_common() {}
00206 
00207   double freq_min();
00208   double freq_max();
00209 };
00210 
00211 class _400_tx : public _400_common
00212 {
00213 public:
00214   _400_tx();
00215   ~_400_tx() {}
00216 };
00217 
00218 class _400_rx : public _400_common
00219 {
00220 public:
00221   _400_rx();
00222   ~_400_rx() {}
00223 };
00224 
00225 //------------------------------------------------------------    
00226 
00227 class db_flexrf_2200_tx : public flexrf_base_tx
00228 {
00229  public:
00230   db_flexrf_2200_tx(usrp_basic_sptr usrp, int which);
00231   ~db_flexrf_2200_tx();
00232 
00233   // Wrapper calls to d_common functions
00234   bool _compute_regs(double freq, int &retR, int &retcontrol,
00235                      int &retN, double &retfreq);
00236 };
00237 
00238 class db_flexrf_2200_rx : public flexrf_base_rx
00239 {
00240 public:
00241   db_flexrf_2200_rx(usrp_basic_sptr usrp, int which);
00242   ~db_flexrf_2200_rx();
00243   
00244   float gain_min();
00245   float gain_max();
00246   float gain_db_per_step();
00247   bool i_and_q_swapped();
00248 
00249   bool _compute_regs(double freq, int &retR, int &retcontrol,
00250                      int &retN, double &retfreq);
00251 };
00252 
00253 //------------------------------------------------------------    
00254 
00255 class db_flexrf_2400_tx : public flexrf_base_tx
00256 {
00257  public:
00258   db_flexrf_2400_tx(usrp_basic_sptr usrp, int which);
00259   ~db_flexrf_2400_tx();
00260 
00261   // Wrapper calls to d_common functions
00262   bool _compute_regs(double freq, int &retR, int &retcontrol,
00263                      int &retN, double &retfreq);
00264 };
00265 
00266 class db_flexrf_2400_rx : public flexrf_base_rx
00267 {
00268 public:
00269   db_flexrf_2400_rx(usrp_basic_sptr usrp, int which);
00270   ~db_flexrf_2400_rx();
00271   
00272   float gain_min();
00273   float gain_max();
00274   float gain_db_per_step();
00275   bool i_and_q_swapped();
00276 
00277   bool _compute_regs(double freq, int &retR, int &retcontrol,
00278                      int &retN, double &retfreq);
00279 };
00280 
00281 //------------------------------------------------------------    
00282 
00283 class db_flexrf_1200_tx : public flexrf_base_tx
00284 {
00285 public:
00286   db_flexrf_1200_tx(usrp_basic_sptr usrp, int which);
00287   ~db_flexrf_1200_tx();
00288 
00289   // Wrapper calls to d_common functions
00290   bool _compute_regs(double freq, int &retR, int &retcontrol,
00291                      int &retN, double &retfreq);
00292 };
00293 
00294 class db_flexrf_1200_rx : public flexrf_base_rx
00295 {
00296 public:
00297   db_flexrf_1200_rx(usrp_basic_sptr usrp, int which);
00298   ~db_flexrf_1200_rx();
00299   
00300   float gain_min();
00301   float gain_max();
00302   float gain_db_per_step();
00303   bool i_and_q_swapped();
00304 
00305   bool _compute_regs(double freq, int &retR, int &retcontrol,
00306                      int &retN, double &retfreq);
00307 };
00308 
00309 //------------------------------------------------------------    
00310 
00311 class db_flexrf_1800_tx : public flexrf_base_tx
00312 {
00313  public:
00314   db_flexrf_1800_tx(usrp_basic_sptr usrp, int which);
00315   ~db_flexrf_1800_tx();
00316 
00317   // Wrapper calls to d_common functions
00318   bool _compute_regs(double freq, int &retR, int &retcontrol,
00319                      int &retN, double &retfreq);
00320 };
00321 
00322 class db_flexrf_1800_rx : public flexrf_base_rx
00323 {
00324 public:
00325   db_flexrf_1800_rx(usrp_basic_sptr usrp, int which);
00326   ~db_flexrf_1800_rx();
00327   
00328   float gain_min();
00329   float gain_max();
00330   float gain_db_per_step();
00331   bool i_and_q_swapped();
00332 
00333   bool _compute_regs(double freq, int &retR, int &retcontrol,
00334                      int &retN, double &retfreq);
00335 };
00336 
00337 //------------------------------------------------------------    
00338 
00339 class db_flexrf_900_tx : public flexrf_base_tx
00340 {
00341  public:
00342   db_flexrf_900_tx(usrp_basic_sptr usrp, int which);
00343   ~db_flexrf_900_tx();
00344 
00345   // Wrapper calls to d_common functions
00346   bool _compute_regs(double freq, int &retR, int &retcontrol,
00347                      int &retN, double &retfreq);
00348 };
00349 
00350 class db_flexrf_900_rx : public flexrf_base_rx
00351 {
00352 public:
00353   db_flexrf_900_rx(usrp_basic_sptr usrp, int which);
00354   ~db_flexrf_900_rx();
00355   
00356   float gain_min();
00357   float gain_max();
00358   float gain_db_per_step();
00359   bool i_and_q_swapped();
00360 
00361   bool _compute_regs(double freq, int &retR, int &retcontrol,
00362                      int &retN, double &retfreq);
00363 };
00364 
00365 
00366 //------------------------------------------------------------    
00367 
00368 class db_flexrf_400_tx : public flexrf_base_tx
00369 {
00370  public:
00371   db_flexrf_400_tx(usrp_basic_sptr usrp, int which);
00372   ~db_flexrf_400_tx();
00373 
00374   // Wrapper calls to d_common functions
00375   bool _compute_regs(double freq, int &retR, int &retcontrol,
00376                      int &retN, double &retfreq);
00377 };
00378 
00379 class db_flexrf_400_rx : public flexrf_base_rx
00380 {
00381 public:
00382   db_flexrf_400_rx(usrp_basic_sptr usrp, int which);
00383   ~db_flexrf_400_rx();
00384 
00385   float gain_min();
00386   float gain_max();
00387   float gain_db_per_step();
00388   bool i_and_q_swapped();
00389 
00390   bool _compute_regs(double freq, int &retR, int &retcontrol,
00391                      int &retN, double &retfreq);
00392 };
00393 
00394 #endif