commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9224 - gnuradio/branches/developers/trondeau/dbs/usrp


From: trondeau
Subject: [Commit-gnuradio] r9224 - gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy
Date: Sun, 10 Aug 2008 13:45:41 -0600 (MDT)

Author: trondeau
Date: 2008-08-10 13:45:40 -0600 (Sun, 10 Aug 2008)
New Revision: 9224

Added:
   gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.cc
   gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.h
   
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.cc
   
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.h
   gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.cc
   gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.h
Log:
wip: ugly but mostly working code for TV_RX and RFX boards with a lot of debug 
info dumped to screen. RFX2400 is producing data; class structure needs to be 
cleaned up.

Added: 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.cc
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.cc 
                        (rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.cc 
2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,1079 @@
+//
+// 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.
+
+#include <db_flexrf.h>
+#include <sstream>
+#include <assert.h>
+
+
+flexrf_base::flexrf_base(usrp_basic *usrp, int which)
+  : db_base(usrp, which)
+{
+  /*
+    @param usrp: instance of usrp.source_c
+    @param which: which side: 0 or 1 corresponding to side A or B respectively
+    @type which: int
+  */
+
+  printf("flexrf_base::flexrf_base\n");
+    
+  d_first = true;
+  d_spi_format = SPI_FMT_MSB | SPI_FMT_HDR_0;
+
+  d_usrp->_write_oe(d_which, 0, 0xffff);   // turn off all outputs
+  _enable_refclk(false);                // disable refclk
+
+  std::vector<float> g = gain_range();  // initialize gain
+  set_gain(float(g[0]+g[1]) / 2.0);
+  
+  set_auto_tr(false);
+
+  printf("here\n");
+
+  /*
+  std::string title;
+  if(debug_using_gui) {
+    title = "FlexRF Debug Rx";
+    if(d_tx) {
+      title = "FlexRF Debug Tx";
+    }
+    d_gui = flexrf_debug_gui.flexrf_debug_gui(title);
+    d_gui.Show(true);
+  }
+  */
+}
+
+flexrf_base::~flexrf_base()
+{
+  d_usrp->write_io(d_which, d_power_off, POWER_UP);   // turn off power to 
board
+
+  // Power down VCO/PLL
+  d_PD = 3;
+  
+  // FIXME: Where is _compute_control_reg() declared?
+  printf("need to get _compute_control_reg() for this\n");
+  throw 0;
+  //write_control(_compute_control_reg());
+  _enable_refclk(false);                       // turn off refclk
+  set_auto_tr(false);
+}
+
+void
+flexrf_base::_write_all(int R, int control, int N)
+{
+  /*
+    Write R counter latch, control latch and N counter latch to VCO.
+    
+    Adds 10ms delay between writing control and N if this is first call.
+    This is the required power-up sequence.
+    
+    @param R: 24-bit R counter latch
+    @type R: int
+    @param control: 24-bit control latch
+    @type control: int
+    @param N: 24-bit N counter latch
+    @type N: int
+  */
+  timespec t;
+  t.tv_sec = 0;
+  t.tv_nsec = 10000000;
+
+  _write_R(R);
+  _write_control(control);
+  if(d_first) {
+    //time.sleep(0.010);
+    nanosleep(&t, NULL);
+    d_first = false;
+  }
+  _write_N(N);
+}
+
+void
+flexrf_base::_write_control(int control)
+{
+  _write_it((control & ~0x3) | 0);
+}
+
+void
+flexrf_base::_write_R(int R)
+{
+  _write_it((R & ~0x3) | 1);
+}
+
+void
+flexrf_base::_write_N(int N)
+{
+  _write_it((N & ~0x3) | 2);
+}
+
+void
+flexrf_base::_write_it(int v)
+{
+  char s[3];
+  s[0] = (char)((v >> 16) & 0xff);
+  s[1] = (char)((v >>  8) & 0xff);
+  s[2] = (char)(v & 0xff);
+  d_usrp->_write_spi(0, d_spi_enable, d_spi_format, s);
+}
+        
+bool
+flexrf_base::_lock_detect()
+{
+  /*
+    @returns: the value of the VCO/PLL lock detect bit.
+    @rtype: 0 or 1
+  */
+  if(d_usrp->read_io(d_which) & PLL_LOCK_DETECT) {
+    return true;
+  }
+  else {      // Give it a second chance
+    if(d_usrp->read_io(d_which) & PLL_LOCK_DETECT) {
+      return true;
+    }
+    else {
+      return false;
+    }
+  }
+}
+
+bool
+flexrf_base::_compute_regs(float freq, int &retR, int &retcontrol, int &retN, 
float &retfreq)
+{
+  /*
+    Determine values of R, control, and N registers, along with actual freq.
+    
+    @param freq: target frequency in Hz
+    @type freq: float
+    @returns: (R, control, N, actual_freq)
+    @rtype: tuple(int, int, int, float)
+    
+    Override this in derived classes.
+  */
+  
+  //raise NotImplementedError;
+  printf("flexrf_base::_compute_regs\n");
+  throw 0;
+}
+
+float
+flexrf_base::_refclk_freq(flexrf_base *child)
+{
+  // return float(d_u.fpga_master_clock_freq())/d_refclk_divisor()
+  printf("frexrf_base::_refclk_freq()\n");
+  return 64e6/child->_refclk_divisor();
+}
+
+std::vector<float>
+flexrf_base::set_freq(float freq)
+{
+  /*
+    @returns (ok, actual_baseband_freq) where:
+    ok is True or False and indicates success or failure,
+    actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
+  */
+
+  std::vector<float> args(2, 0);
+  
+  // Offsetting the LO helps get the Tx carrier leakage out of the way.
+  // This also ensures that on Rx, we're not getting hosed by the
+  // FPGA's DC removal loop's time constant.  We were seeing a
+  // problem when running with discontinuous transmission.
+  // Offsetting the LO made the problem go away.
+  freq += d_lo_offset;
+  
+  int R, control, N;
+  float actual_freq;
+  _compute_regs(freq, R, control, N, actual_freq);
+
+  if(R==0) {
+    return args;
+  }
+   
+  _write_all(R, control, N);
+  args[0] = _lock_detect();
+  args[1] = actual_freq;
+  return args;
+}
+
+std::vector<float> 
+flexrf_base::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max();
+  g[2] = d_usrp->pga_db_per_step();
+  return g;
+}
+
+bool
+flexrf_base::set_gain(float gain)
+{
+  /*
+    Set the gain.
+    
+    @param gain:  gain in decibels
+    @returns True/False
+  */
+  return _set_pga(gain);
+}
+
+bool
+flexrf_base::_set_pga(float pga_gain)
+{
+  if(d_which == 0) {
+    d_usrp->set_pga(0, pga_gain);
+    d_usrp->set_pga(1, pga_gain);
+  }
+  else {
+    d_usrp->set_pga(2, pga_gain);
+    d_usrp->set_pga(3, pga_gain);
+  }
+  return true;
+}
+
+bool
+flexrf_base::is_quadrature()
+{
+  /*
+    Return True if this board requires both I & Q analog channels.
+    
+    This bit of info is useful when setting up the USRP Rx mux register.
+  */
+  return true;
+}
+
+void
+flexrf_base::set_lo_offset(float offset)
+{
+  /*
+    Set amount by which LO is offset from requested tuning frequency.
+    
+    @param offset: offset in Hz
+  */
+  d_lo_offset = offset;
+}
+
+float 
+flexrf_base::lo_offset()
+{
+  /*
+    Get amount by which LO is offset from requested tuning frequency.
+    
+    @returns Offset in Hz
+  */
+  return d_lo_offset;
+}
+
+// ----------------------------------------------------------------
+
+flexrf_base_tx::flexrf_base_tx(usrp_basic *usrp, int which)
+  : flexrf_base(usrp, which)
+{
+  /*
+    @param usrp: instance of usrp.sink_c
+    @param which: 0 or 1 corresponding to side TX_A or TX_B respectively.
+  */
+  
+  int d_spi_enable;
+  if(which == 0) {
+    d_spi_enable = SPI_ENABLE_TX_A;
+  }
+  else {
+    d_spi_enable = SPI_ENABLE_TX_B;
+  }
+  
+  // power up the transmit side, but don't enable the mixer
+  d_usrp->_write_oe(d_which,(POWER_UP|RX_TXN|ENABLE), 0xffff);
+  d_usrp->write_io(d_which, (d_power_on|RX_TXN), (POWER_UP|RX_TXN|ENABLE));
+  set_lo_offset(4e6);
+}
+
+flexrf_base_tx::~flexrf_base_tx()
+{
+  // Power down and leave the T/R switch in the R position
+  d_usrp->write_io(d_which, (d_power_off|RX_TXN), (POWER_UP|RX_TXN|ENABLE));
+}
+
+void
+flexrf_base_tx::set_auto_tr(bool on)
+{
+  if(on) {
+    set_atr_mask (RX_TXN | ENABLE);
+    set_atr_txval(0      | ENABLE);
+    set_atr_rxval(RX_TXN | 0);
+  }
+  else {
+    set_atr_mask (0);
+    set_atr_txval(0);
+    set_atr_rxval(0);
+  }
+}
+
+void
+flexrf_base_tx::set_enable(bool on)
+{
+  /*
+    Enable transmitter if on is true
+  */
+
+  int v;
+  int mask = RX_TXN | ENABLE;
+  if(on) {
+    v = ENABLE;
+  }
+  else {
+    v = RX_TXN;
+  }
+  d_usrp->write_io(d_which, v, mask);
+}
+
+std::vector<float>
+flexrf_base_tx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+    
+    Flex Tx boards require that the PGA be maxed out to properly bias their 
circuitry.
+  */
+
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_max();  // FIXME: min?
+  g[1] = d_usrp->pga_max();
+  g[2] = 1;
+  return g;
+}
+
+bool
+flexrf_base_tx::set_gain(float gain)
+{
+  /*
+    Set the gain.
+    
+    @param gain:  gain in decibels
+    @returns True/False
+  */
+  return _set_pga(d_usrp->pga_max());
+}
+
+
+/******************************************************************************/
+
+
+flexrf_base_rx::flexrf_base_rx(usrp_basic *usrp, int which)
+  : flexrf_base(usrp, which)
+{
+  /*
+    @param usrp: instance of usrp.source_c
+    @param which: 0 or 1 corresponding to side RX_A or RX_B respectively.
+  */
+
+  d_usrp = (usrp_basic_rx*)usrp;
+  d_tx = false;
+
+  if(which == 0) {
+    d_spi_enable = SPI_ENABLE_RX_A;
+  }
+  else {
+    d_spi_enable = SPI_ENABLE_RX_B;
+  }
+  
+  d_usrp->_write_oe(d_which, (POWER_UP|RX2_RX1N|ENABLE), 0xffff);
+  d_usrp->write_io(d_which,  (d_power_on|RX2_RX1N|ENABLE), 
(POWER_UP|RX2_RX1N|ENABLE));
+  
+  // set up for RX on TX/RX port
+  select_rx_antenna("TX/RX");
+  
+  bypass_adc_buffers(true);
+
+  set_lo_offset(-4e6);
+}
+
+flexrf_base_rx::~flexrf_base_rx()
+{
+  // Power down
+  d_usrp->write_io(d_which, d_power_off, (POWER_UP|ENABLE));
+}
+    
+void
+flexrf_base_rx::set_auto_tr(bool on)
+{
+  if(on) {
+    set_atr_mask (ENABLE);
+    set_atr_txval(     0);
+    set_atr_rxval(ENABLE);
+  }
+  else {
+    set_atr_mask (0);
+    set_atr_txval(0);
+    set_atr_rxval(0);
+  }
+}
+
+void
+flexrf_base_rx::select_rx_antenna(int which_antenna)
+{
+  /*
+    Specify which antenna port to use for reception.
+    @param which_antenna: either 'TX/RX' or 'RX2'
+  */
+
+  if(which_antenna == 0) {
+    d_usrp->write_io(d_which, 0,RX2_RX1N);
+  }
+  else if(which_antenna == 1) {
+    d_usrp->write_io(d_which, RX2_RX1N, RX2_RX1N);
+  }
+  else {
+    //raise ValueError, "which_antenna must be either 'TX/RX' or 'RX2'";
+    printf("which_antenna must be either 'TX/RX' or 'RX2'\n");
+    throw 0;
+  }
+}
+
+void
+flexrf_base_rx::select_rx_antenna(const std::string &which_antenna)
+{
+  /*
+    Specify which antenna port to use for reception.
+    @param which_antenna: either 'TX/RX' or 'RX2'
+  */
+
+  if(which_antenna == "TX/RX") {
+    d_usrp->write_io(d_which, 0, RX2_RX1N);
+  }
+  else if(which_antenna == "RX2") {
+    d_usrp->write_io(d_which, RX2_RX1N, RX2_RX1N);
+  }
+  else {
+    //raise ValueError, "which_antenna must be either 'TX/RX' or 'RX2'";
+    printf("which_antenna must be either 'TX/RX' or 'RX2'\n");
+    throw 0;
+  }
+}
+
+bool
+flexrf_base_rx::set_gain(float gain)
+{
+  /*
+    Set the gain.
+    
+    @param gain:  gain in decibels
+    @returns True/False
+  */
+  
+  float pga_gain, agc_gain;
+  float V_maxgain, V_mingain, V_fullscale, dac_value;
+
+  float maxgain = gain_range()[1] - d_usrp->pga_max();
+  float mingain = gain_range()[0];
+  if(gain > maxgain) {
+    pga_gain = gain-maxgain;
+    assert(pga_gain <= d_usrp->pga_max());
+    agc_gain = maxgain;
+  }
+  else {
+    pga_gain = 0;
+    agc_gain = gain;
+  }
+  
+  V_maxgain = .2;
+  V_mingain = 1.2;
+  V_fullscale = 3.3;
+  dac_value = (agc_gain*(V_maxgain-V_mingain)/(maxgain-mingain) + 
V_mingain)*4096/V_fullscale;
+
+  assert(dac_value>=0 && dac_value<4096);
+
+  return (d_usrp->write_aux_dac(d_which, 0, int(dac_value)) && 
_set_pga(int(pga_gain)));
+}
+
+// ----------------------------------------------------------------
+
+
+_AD4360_common::_AD4360_common(bool tx)
+  : d_tx(tx)
+{
+  printf("_AD4360_common::_AD4360_common\n");
+
+  // R-Register Common Values
+  d_R_RSV = 0;  // bits 23,22
+  d_BSC   = 3;  // bits 21,20 Div by 8 to be safe
+  d_TEST  = 0;  // bit 19
+  d_LDP   = 1;  // bit 18
+  d_ABP   = 0;  // bit 17,16   3ns
+
+  // N-Register Common Values
+  d_N_RSV = 0;  // bit 7
+        
+  // Control Register Common Values
+  d_PD    = 0;  // bits 21,20   Normal operation
+  d_PL    = 0;  // bits 13,12   11mA
+  d_MTLD  = 1;  // bit 11       enabled
+  d_CPG   = 0;  // bit 10       CP setting 1
+  d_CP3S  = 0;  // bit 9        Normal
+  d_PDP   = 1;  // bit 8        Positive
+  d_MUXOUT = 1; // bits 7:5     Digital Lock Detect
+  d_CR    = 0;  // bit 4        Normal
+  d_PC    = 1;  // bits 3,2     Core power 10mA
+}
+
+_AD4360_common::~_AD4360_common()
+{
+}
+
+bool
+_AD4360_common::_compute_regs(float refclk_freq, float freq, int &retR, 
+                             int &retcontrol, int &retN, float &retfreq)
+{
+  /*
+    Determine values of R, control, and N registers, along with actual freq.
+    
+    @param freq: target frequency in Hz
+    @type freq: float
+    @returns: (R, control, N, actual_freq)
+    @rtype: tuple(int, int, int, float)
+  */
+
+  printf("_AD360_common::_comput_regs\n");
+  
+  //  Band-specific N-Register Values
+  //float phdet_freq = _refclk_freq()/d_R_DIV;
+  float phdet_freq = refclk_freq/d_R_DIV;
+  float desired_n = round(freq*d_freq_mult/phdet_freq);
+  float actual_freq = desired_n * phdet_freq;
+  int B = floor(desired_n/_prescaler());
+  int A = desired_n - _prescaler()*B;
+  d_B_DIV = int(B);    // bits 20:8
+  d_A_DIV = int(A);    // bit 6:2
+
+  //assert db_B_DIV >= db_A_DIV
+  if(d_B_DIV < d_A_DIV) {
+    retR = 0;
+    retcontrol = 0;
+    retN = 0;
+    retfreq = 0;
+    return false;
+  }
+
+  int R = (d_R_RSV<<22) | (d_BSC<<20) | (d_TEST<<19) | 
+    (d_LDP<<18) | (d_ABP<<16) | (d_R_DIV<<2);
+        
+  int control = _compute_control_reg();
+
+  int N = (d_DIVSEL<<23) | (d_DIV2<<22) | (d_CPGAIN<<21) | 
+    (d_B_DIV<<8) | (d_N_RSV<<7) | (d_A_DIV<<2);
+
+  retR = R;
+  retcontrol = control;
+  retN = N;
+  retfreq = actual_freq/d_freq_mult;
+  return true;
+}
+
+int
+_AD4360_common::_compute_control_reg()
+{
+  int control = (d_P<<22) | (d_PD<<20) | (d_CP2<<17) | (d_CP1<<14) | (d_PL<<12)
+    | (d_MTLD<<11) | (d_CPG<<10) | (d_CP3S<<9) | (d_PDP<<8) |
+    (d_MUXOUT<<5) | (d_CR<<4) | (d_PC<<2);
+  
+  return control;
+}
+
+int
+_AD4360_common::_refclk_divisor()
+{
+  /*
+    Return value to stick in REFCLK_DIVISOR register
+  */
+  printf("_AD4360_common::_refclk_divisor()\n");
+  return 1;
+}
+    
+int
+_AD4360_common::_prescaler()
+{
+  if(d_P == 0) {
+    return 8;
+  }
+  else if(d_P == 1) {
+    return 16;
+  }
+  else {
+    return 32;
+  }
+}
+
+std::vector<float> 
+_AD4360_common::freq_range()
+{
+  printf("AD4360_common::freq_range()\n");
+  throw 0;
+}
+
+//----------------------------------------------------------------------
+
+_2400_common::_2400_common(bool tx)
+  : _AD4360_common(tx)
+{
+  // Band-specific R-Register Values
+  d_R_DIV = 16;  // bits 15:2
+   
+  // Band-specific C-Register values
+  d_P = 1;        // bits 23,22   Div by 16/17
+  d_CP2 = 7;      // bits 19:17
+  d_CP1 = 7;      // bits 16:14
+
+  // Band specifc N-Register Values
+  d_DIVSEL = 0;   // bit 23
+  d_DIV2 = 0;     // bit 22
+  d_CPGAIN = 0;   // bit 21
+  d_freq_mult = 1;
+
+  printf("_2400_common::_2400_common\n");
+}
+
+std::vector<float> 
+_2400_common::freq_range()            // FIXME
+{
+  std::vector<float> f(3,0);
+  f[0] = 2300e6;
+  f[1] = 2700e6;
+  f[2] = 4e6;
+  return f;
+}
+
+#if 0
+//----------------------------------------------------------------------
+
+_1200_common::_1200_common(bool tx)
+  : _AD4360_common(tx)
+{
+  // Band-specific R-Register Values
+  d_R_DIV = 16;  // bits 15:2  DIV by 16 for a 1 MHz phase detector freq
+   
+  // Band-specific C-Register values
+  d_P = 1;        // bits 23,22   Div by 16/17
+  d_CP2 = 7;      // bits 19:17   1.25 mA
+  d_CP1 = 7;      // bits 16:14   1.25 mA
+  
+  // Band specifc N-Register Values
+  d_DIVSEL = 0;   // bit 23
+  d_DIV2 = 1;     // bit 22
+  d_CPGAIN = 0;   // bit 21
+  d_freq_mult = 2;
+}
+
+std::vector<float> 
+_1200_common::freq_range()           // FIXME
+{
+  std::vector<float> f(3,0);
+  f[0] = 1150e6;
+  f[1] = 1350e6;
+  f[2] = 4e6;
+  return f;
+}
+
+//-------------------------------------------------------------------------
+
+_1800_common::_1800_common(bool tx)
+  : _AD4360_common(tx)
+{
+  // Band-specific R-Register Values
+  d_R_DIV = 16;  // bits 15:2  DIV by 16 for a 1 MHz phase detector freq
+    
+  // Band-specific C-Register values
+  d_P = 1;        // bits 23,22   Div by 16/17
+  d_CP2 = 7;      // bits 19:17   1.25 mA
+  d_CP1 = 7;      // bits 16:14   1.25 mA
+  
+  // Band specifc N-Register Values
+  d_DIVSEL = 0;   // bit 23
+  d_DIV2 = 0;     // bit 22
+  d_freq_mult = 1;
+  d_CPGAIN = 0;   // bit 21
+}
+
+std::vector<float> 
+_1800_common::freq_range()           // FIXME
+{
+  std::vector<float> f(3,0);
+  f[0] = 1600e6;
+  f[1] = 2000e6;
+  f[2] = 4e6;
+  return f;
+}
+
+//-------------------------------------------------------------------------
+
+_900_common::_900_common(bool tx)
+  : _AD4360_common(tx)
+{
+  // Band-specific R-Register Values
+  d_R_DIV = 16;  // bits 15:2  DIV by 16 for a 1 MHz phase detector freq
+   
+  // Band-specific C-Register values
+  d_P = 1;        // bits 23,22   Div by 16/17
+  d_CP2 = 7;      // bits 19:17   1.25 mA
+  d_CP1 = 7;      // bits 16:14   1.25 mA
+  
+  // Band specifc N-Register Values
+  d_DIVSEL = 0;   // bit 23
+  d_DIV2 = 1;     // bit 22
+  d_freq_mult = 2;
+  d_CPGAIN = 0;   // bit 21
+}
+
+std::vector<float>
+_900_common::freq_range()           // FIXME
+{
+  std::vector<float> f(3,0);
+  f[0] = 800e6;
+  f[1] = 1000e6;
+  f[2] = 4e6;
+  return f;
+}
+
+//-------------------------------------------------------------------------
+
+_400_common::_400_common(bool tx)
+  : _AD4360_common(tx)
+{
+  // Band-specific R-Register Values
+  d_R_DIV = 16;   // bits 15:2 
+   
+  // Band-specific C-Register values
+  d_P = 0;        // bits 23,22   Div by 8/9
+  d_CP2 = 7;      // bits 19:17   1.25 mA
+  d_CP1 = 7;      // bits 16:14   1.25 mA
+  
+  // Band specifc N-Register Values  These are different for TX/RX
+  d_DIVSEL = 0;   // bit 23
+  if(d_tx) {
+    d_DIV2 = 1;   // bit 22
+  }
+  else {
+    d_DIV2 = 0;   // bit 22   // RX side has built-in DIV2 in AD8348
+  }
+  d_freq_mult = 2;
+  
+  d_CPGAIN = 0;   // bit 21
+}
+
+std::vector<float> 
+_400_common::freq_range()
+{
+  std::vector<float> f(3,0);
+  f[0] = 400e6;
+  f[1] = 500e6;
+  f[2] = 1e3;
+  return f;
+}  
+#endif
+
+//------------------------------------------------------------    
+
+db_flexrf_2400_tx::db_flexrf_2400_tx(usrp_basic *usrp, int which)
+  : flexrf_base_tx(usrp, which)
+{
+  printf("flexrf_2400_tx\n");
+  d_common = new _2400_common(d_tx);
+
+  d_power_on = 0;
+  d_power_off = 0;    // powering it off kills the serial bus
+}
+
+db_flexrf_2400_tx::~db_flexrf_2400_tx()
+{
+  delete d_common;
+}
+
+std::vector<float> 
+db_flexrf_2400_tx::freq_range()
+{
+  return d_common->freq_range();
+}
+
+std::vector<float>
+db_flexrf_2400_tx::set_freq(float freq)
+{
+  return flexrf_base::set_freq(freq);
+}
+
+bool
+db_flexrf_2400_tx::_compute_regs(float freq, int &retR, int &retcontrol, int 
&retN, float &retfreq)
+{
+  return d_common->_compute_regs(_refclk_freq(this), freq, retR, retcontrol, 
retN, retfreq);
+}
+
+
+db_flexrf_2400_rx::db_flexrf_2400_rx(usrp_basic *usrp, int which)
+  : flexrf_base_rx(usrp, which)
+{
+  printf("flexrf_2400_rx\n");
+  d_common = new _2400_common(false);
+  d_power_on = 0;
+  d_power_off = 0;   // Powering it off kills the serial bus
+}
+
+db_flexrf_2400_rx::~db_flexrf_2400_rx()
+{
+  delete d_common;
+}
+
+std::vector<float> 
+db_flexrf_2400_rx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max()+70;
+  g[2] = 0.05;
+  return g;
+}
+
+bool
+db_flexrf_2400_rx::i_and_q_swapped()
+{
+  return true;
+}
+
+std::vector<float> 
+db_flexrf_2400_rx::freq_range()
+{
+  return flexrf_base::freq_range();
+}
+
+std::vector<float>
+db_flexrf_2400_rx::set_freq(float freq)
+{
+  std::vector<float> args(2, 0);
+  freq += d_lo_offset;
+  
+  int R, control, N;
+  float actual_freq;
+  _compute_regs(freq, R, control, N, actual_freq);
+
+  if(R==0) {
+    return args;
+  }
+   
+  _write_all(R, control, N);
+  args[0] = _lock_detect();
+  args[1] = actual_freq;
+  return args;
+}
+
+bool
+db_flexrf_2400_rx::_compute_regs(float freq, int &retR, int &retcontrol, int 
&retN, float &retfreq)
+{
+  printf("flexrf_2400_rx::_compute_regs\n");
+  return d_common->_compute_regs(_refclk_freq(this), freq, retR, retcontrol, 
retN, retfreq);
+}
+
+int
+db_flexrf_2400_rx::_refclk_divisor()
+{
+  printf("flexrf_2400_rx::_refclk_divisor()\n");
+  return d_common->_refclk_divisor();
+}
+
+
+#if 0
+//------------------------------------------------------------    
+
+db_flexrf_1200_tx::db_flexrf_1200_tx(usrp_basic *usrp, int which)
+  : flexrf_base_tx(usrp, which),
+     _1200_common(true)
+{
+  d_power_on = 0;
+  d_power_off = 0;    // powering it off kills the serial bus
+}
+
+db_flexrf_1200_rx::db_flexrf_1200_rx(usrp_basic *usrp, int which)
+  : flexrf_base_rx(usrp, which),
+    _1200_common(false)
+{
+  d_power_on = 0;
+  d_power_off = 0;   // Powering it off kills the serial bus
+}
+
+std::vector<float> 
+db_flexrf_1200_rx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max()+70;
+  g[2] = 0.05;
+  return g;
+}
+
+bool
+db_flexrf_1200_rx::i_and_q_swapped()
+{
+  return true;
+}
+
+
+//------------------------------------------------------------    
+
+
+db_flexrf_1800_tx::db_flexrf_1800_tx(usrp_basic *usrp, int which)
+  : flexrf_base_tx(usrp, which),
+     _1800_common(true)
+{
+  d_power_on = 0;
+  d_power_off = 0;    // powering it off kills the serial bus
+}
+
+db_flexrf_1800_rx::db_flexrf_1800_rx(usrp_basic *usrp, int which)
+  : flexrf_base_rx(usrp, which),
+    _1800_common(false)
+{
+  d_power_on = 0;
+  d_power_off = 0;   // Powering it off kills the serial bus
+}
+
+std::vector<float> 
+db_flexrf_1800_rx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max()+70;
+  g[2] = 0.05;
+  return g;
+}
+
+bool
+db_flexrf_1800_rx::i_and_q_swapped()
+{
+  return true;
+}
+
+
+//------------------------------------------------------------    
+
+
+db_flexrf_900_tx::db_flexrf_900_tx(usrp_basic *usrp, int which)
+  : flexrf_base_tx(usrp, which),
+    _900_common(true)
+{
+  d_power_on = 0;
+  d_power_off = 0;    // powering it off kills the serial bus
+}
+db_flexrf_900_rx::db_flexrf_900_rx(usrp_basic *usrp, int which)
+  : flexrf_base_rx(usrp, which),
+    _900_common(false)
+{
+  d_power_on = 0;
+  d_power_off = 0;   // Powering it off kills the serial bus
+}
+
+std::vector<float> 
+db_flexrf_900_rx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max()+70;
+  g[2] = 0.05;
+  return g;
+}
+
+bool
+db_flexrf_900_rx::i_and_q_swapped()
+{
+  return true;
+}
+
+
+//------------------------------------------------------------    
+
+
+db_flexrf_400_tx::db_flexrf_400_tx(usrp_basic *usrp, int which)
+  : flexrf_base_tx(usrp, which),
+    _400_common(true)
+{
+  d_power_on = POWER_UP;
+  d_power_off = 0;    // powering it off kills the serial bus
+}
+
+db_flexrf_400_rx::db_flexrf_400_rx(usrp_basic *usrp, int which)
+  : flexrf_base_rx(usrp, which),
+    _400_common(false)
+{
+  d_power_on = POWER_UP;
+  d_power_off = 0;   // Powering it off kills the serial bus
+}
+
+std::vector<float> 
+db_flexrf_400_rx::gain_range()
+{
+  /*
+    Return range of gain that can be set by this d'board.
+    
+    @returns (min_gain, max_gain, step_size)
+    Where gains are expressed in decibels (your mileage may vary)
+  */
+  std::vector<float> g(3,0);
+  g[0] = d_usrp->pga_min();
+  g[1] = d_usrp->pga_max()+45;
+  g[2] = 0.035;
+  return g;
+}
+
+bool
+db_flexrf_400_rx::i_and_q_swapped()
+{
+  return true;
+}
+#endif
+

Added: 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.h
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.h  
                        (rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf.h  
2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,298 @@
+/* -*- 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
+
+// d'board i/o pin defs
+// Tx and Rx have shared defs, but different i/o regs
+#define AUX_RXAGC (1 << 8)
+#define POWER_UP  (1 << 7)         // enables power supply
+#define RX_TXN    (1 << 6)         // Tx only: T/R antenna switch for TX/RX 
port
+#define RX2_RX1N  (1 << 6)         // Rx only: antenna switch between RX2 and 
TX/RX port
+#define ENABLE    (1 << 5)         // enables mixer
+#define AUX_SEN   (1 << 4)
+#define AUX_SCLK  (1 << 3)
+#define PLL_LOCK_DETECT (1 << 2)
+#define AUX_SDO   (1 << 1)
+#define CLOCK_OUT (1 << 0)
+
+class flexrf_base : public db_base
+{
+public:
+  flexrf_base(usrp_basic *usrp, int which);
+  ~flexrf_base();
+
+  std::vector<float> set_freq(float freq);
+  std::vector<float> gain_range();
+  bool  set_gain(float gain);
+  bool  is_quadrature();
+  float lo_offset();
+  void  set_lo_offset(float offset);
+
+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();
+
+  bool _compute_regs(float freq, int &retR, int &retcontrol, int &retN, float 
&retfreq);
+  float _refclk_freq(flexrf_base *child);
+
+  bool _set_pga(float pga_gain);
+
+  float d_lo_offset;
+  bool d_first;
+  int  d_spi_format;
+  int  d_spi_enable;
+  char d_power_off;
+  char d_power_on;
+  int  d_PD;
+};
+
+// ----------------------------------------------------------------
+
+class flexrf_base_tx : public flexrf_base
+{
+public:
+  flexrf_base_tx(usrp_basic *usrp, int which);
+  ~flexrf_base_tx();
+
+  void set_auto_tr(bool on);
+  void set_enable(bool on);
+  std::vector<float> gain_range();
+  bool set_gain(float gain);
+
+protected:
+  usrp_basic_tx *d_usrp;
+};
+
+class flexrf_base_rx : public flexrf_base
+{
+public:
+  flexrf_base_rx(usrp_basic *usrp, int which);
+  ~flexrf_base_rx();
+    
+  void set_auto_tr(bool on);
+  void select_rx_antenna(int which_antenna);
+  void select_rx_antenna(const std::string &which_antenna);
+  bool set_gain(float gain);
+
+protected:
+  usrp_basic_rx *d_usrp;
+};
+
+// ----------------------------------------------------------------
+
+
+class _AD4360_common
+{
+public:
+  _AD4360_common(bool tx);
+  virtual ~_AD4360_common();
+
+  virtual std::vector<float> freq_range();
+
+  bool _compute_regs(float refclk_freq, float freq, int &retR, 
+                    int &retcontrol, int &retN, float &retfreq);
+  int _compute_control_reg();
+  virtual int _refclk_divisor();
+  int _prescaler();
+
+  void R_DIV(int div) { d_R_DIV = div; }
+
+protected:
+  bool d_tx;
+
+  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(bool tx);
+  ~_2400_common() {}
+
+  std::vector<float> freq_range();
+};
+
+//----------------------------------------------------------------------
+
+/*
+class _1200_common : public _AD4360_common
+{
+public:
+  _1200_common(bool tx);
+
+  std::vector<float> freq_range();
+};
+
+//-------------------------------------------------------------------------
+
+class _1800_common : public _AD4360_common
+{
+ public:
+  _1800_common(bool tx);
+
+  std::vector<float> freq_range();
+};
+
+//-------------------------------------------------------------------------
+
+class _900_common : public _AD4360_common
+{
+public:
+  _900_common(bool tx);
+  
+  std::vector<float> freq_range();
+};
+
+//-------------------------------------------------------------------------
+
+class _400_common : public _AD4360_common
+{
+public:
+  _400_common(bool tx);
+
+  std::vector<float> freq_range();
+};  
+*/
+
+//------------------------------------------------------------    
+
+class db_flexrf_2400_tx : public flexrf_base_tx
+{
+ public:
+  db_flexrf_2400_tx(usrp_basic *usrp, int which);
+  ~db_flexrf_2400_tx();
+  bool _compute_regs(float freq, int &retR, int &retcontrol, int &retN, float 
&retfreq);
+  std::vector<float> freq_range();
+  std::vector<float> set_freq(float freq);
+
+protected:
+  _2400_common *d_common;
+};
+
+class db_flexrf_2400_rx : public flexrf_base_rx
+{
+public:
+  db_flexrf_2400_rx(usrp_basic *usrp, int which);
+  ~db_flexrf_2400_rx();
+  
+  std::vector<float> gain_range();
+  bool i_and_q_swapped();
+
+  std::vector<float> freq_range();
+  std::vector<float> set_freq(float freq);
+  bool _compute_regs(float freq, int &retR, int &retcontrol, int &retN, float 
&retfreq);
+  int _refclk_divisor();
+
+protected:
+  _2400_common *d_common;  
+};
+
+//------------------------------------------------------------    
+/*
+class db_flexrf_1200_tx : public flexrf_base_tx, public _1200_common
+{
+ public:
+  db_flexrf_1200_tx(usrp_basic *usrp, int which);
+};
+
+class db_flexrf_1200_rx : public flexrf_base_rx, public _1200_common
+{
+public:
+  db_flexrf_1200_rx(usrp_basic *usrp, int which);
+  
+  std::vector<float> gain_range();
+  bool i_and_q_swapped();
+};
+
+//------------------------------------------------------------    
+
+class db_flexrf_1800_tx : public flexrf_base_tx, public _1800_common
+{
+ public:
+  db_flexrf_1800_tx(usrp_basic *usrp, int which);
+};
+
+class db_flexrf_1800_rx : public flexrf_base_rx, public _1800_common
+{
+public:
+  db_flexrf_1800_rx(usrp_basic *usrp, int which);
+  
+  std::vector<float> gain_range();
+  bool i_and_q_swapped();
+};
+
+//------------------------------------------------------------    
+
+class db_flexrf_900_tx : public flexrf_base_tx, public _900_common
+{
+ public:
+  db_flexrf_900_tx(usrp_basic *usrp, int which);
+};
+
+class db_flexrf_900_rx : public flexrf_base_rx, public _900_common
+{
+public:
+  db_flexrf_900_rx(usrp_basic *usrp, int which);
+  
+  std::vector<float> gain_range();
+  bool i_and_q_swapped();
+};
+
+
+//------------------------------------------------------------    
+
+class db_flexrf_400_tx : public flexrf_base_tx, public _400_common
+{
+ public:
+  db_flexrf_400_tx(usrp_basic *usrp, int which);
+};
+
+class db_flexrf_400_rx : public flexrf_base_rx, public _400_common
+{
+public:
+  db_flexrf_400_rx(usrp_basic *usrp, int which);
+  
+  std::vector<float> gain_range();
+  bool i_and_q_swapped();
+};
+*/
+
+#endif

Added: 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.cc
===================================================================
--- 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.cc
                            (rev 0)
+++ 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.cc
    2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,274 @@
+/*
+ * 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 version 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.
+ */ 
+
+#include <db_flexrf_mimo.h>
+#include <assert.h>
+
+db_flexrf_2400_tx_mimo_a::db_flexrf_2400_tx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_2400_tx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_2400_tx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+
+db_flexrf_2400_rx_mimo_a::db_flexrf_2400_rx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_2400_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_2400_rx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+      
+db_flexrf_2400_tx_mimo_b::db_flexrf_2400_tx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_2400_tx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_2400_tx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_2400_rx_mimo_b::db_flexrf_2400_rx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_2400_rx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_2400_rx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+#if 0    
+db_flexrf_1800_tx_mimo_a::db_flexrf_1800_tx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_1800_tx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_1800_tx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+
+db_flexrf_1800_rx_mimo_a::db_flexrf_1800_rx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_1800_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_1800_rx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+    
+db_flexrf_1800_tx_mimo_b::db_flexrf_1800_tx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_1800_tx(usrp, which)
+{
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_1800_tx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_1800_rx_mimo_b::db_flexrf_1800_rx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_1800_rx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_1800_rx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_1200_tx_mimo_a::db_flexrf_1200_tx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_1200_tx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_1200_tx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+
+db_flexrf_1200_rx_mimo_a::db_flexrf_1200_rx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_1200_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_1200_rx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+    
+db_flexrf_1200_tx_mimo_b::db_flexrf_1200_tx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_1200_tx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_1200_tx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_1200_rx_mimo_b::db_flexrf_1200_rx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_1200_rx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_1200_rx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_900_tx_mimo_a::db_flexrf_900_tx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_900_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_900_tx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+
+db_flexrf_900_rx_mimo_a::db_flexrf_900_rx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_900_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_900_rx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+    
+db_flexrf_900_tx_mimo_b::db_flexrf_900_tx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_900_tx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_900_tx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_900_rx_mimo_b::db_flexrf_900_rx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_900_rx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int db_flexrf_900_rx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+
+db_flexrf_400_tx_mimo_a::db_flexrf_400_tx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_400_tx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_400_tx_mimo_a::_refclk_divisor()
+{
+  return 16;
+}
+    
+db_flexrf_400_rx_mimo_a::db_flexrf_400_rx_mimo_a(usrp_basic *usrp, int which)
+  : db_flexrf_400_rx(usrp, which)
+{
+  _enable_refclk(true);
+  d_common->R_DIV(1);
+}
+
+int 
+db_flexrf_400_rx_mimo_a::db_flexrf_400_rx_mimo_a_refclk_divisor()
+{
+  return 16;
+}
+    
+db_flexrf_400_tx_mimo_b::db_flexrf_400_tx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_400_tx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_400_tx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+    
+db_flexrf_400_rx_mimo_b::db_flexrf_400_rx_mimo_b(usrp_basic *usrp, int which)
+  : db_flexrf_400_rx(usrp, which)
+{
+  d_common->R_DIV(16);
+}
+
+int 
+db_flexrf_400_rx_mimo_b::_refclk_divisor()
+{
+  return 1;
+}
+#endif

Added: 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.h
===================================================================
--- 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.h 
                            (rev 0)
+++ 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_flexrf_mimo.h 
    2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,165 @@
+/*
+ * 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 version 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.
+ */ 
+
+#include <db_flexrf.h>
+
+class db_flexrf_2400_tx_mimo_a : public db_flexrf_2400_tx
+{
+ public:
+  db_flexrf_2400_tx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_2400_rx_mimo_a : public db_flexrf_2400_rx
+{
+ public:
+  db_flexrf_2400_rx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+      
+class db_flexrf_2400_tx_mimo_b : public db_flexrf_2400_tx
+{
+ public:
+  db_flexrf_2400_tx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_2400_rx_mimo_b : public db_flexrf_2400_rx
+{
+ public:
+  db_flexrf_2400_rx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+
+#if 0
+class db_flexrf_1800_tx_mimo_a : public db_flexrf_1800_tx
+{
+ public:
+  db_flexrf_1800_tx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1800_rx_mimo_a : public db_flexrf_1800_rx
+{
+ public:
+  db_flexrf_1800_rx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1800_tx_mimo_b : db_flexrf_1800_tx
+{
+ public:
+  db_flexrf_1800_tx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1800_rx_mimo_b : public db_flexrf_1800_rx
+{
+ public:
+  db_flexrf_1800_rx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1200_tx_mimo_a : public db_flexrf_1200_tx
+{
+ public:
+  db_flexrf_1200_tx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1200_rx_mimo_a : public db_flexrf_1200_rx
+{
+ public:
+  db_flexrf_1200_rx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1200_tx_mimo_b : public db_flexrf_1200_tx
+{
+ public:
+  db_flexrf_1200_tx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_1200_rx_mimo_b : public db_flexrf_1200_rx
+{
+ public:
+  db_flexrf_1200_rx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_900_tx_mimo_a : public db_flexrf_900_tx
+{
+ public:
+  db_flexrf_900_tx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_900_rx_mimo_a : public db_flexrf_900_rx
+{
+ public:
+  db_flexrf_900_rx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_900_tx_mimo_b : public db_flexrf_900_tx
+{
+ public:
+  db_flexrf_900_tx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_900_rx_mimo_b : public db_flexrf_900_rx
+{
+ public:
+  db_flexrf_900_rx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_400_tx_mimo_a : public db_flexrf_400_tx
+{
+ public:
+  db_flexrf_400_tx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_400_rx_mimo_a : public db_flexrf_400_rx
+{
+ public:
+  db_flexrf_400_rx_mimo_a(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_400_tx_mimo_b : public db_flexrf_400_tx
+{
+ public:
+  db_flexrf_400_tx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+
+class db_flexrf_400_rx_mimo_b : public db_flexrf_400_rx
+{
+ public:
+  db_flexrf_400_rx_mimo_b(usrp_basic *usrp, int which);
+  int _refclk_divisor();
+};
+#endif

Added: 
gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.cc
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.cc  
                        (rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.cc  
2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,311 @@
+//
+// 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.
+
+#include <db_tv_rx.h>
+#include <sstream>
+#include <assert.h>
+
+/**************************************************************************************************/
+
+std::string
+int_seq_to_str(std::vector<int> &seq)
+{
+  //convert a sequence of integers into a string
+  //return ''.join (map (chr, seq));
+  
+  std::stringstream str; 
+  std::vector<int>::iterator i;
+  for(i = seq.begin(); i != seq.end(); i++) {
+    str << char((unsigned int)*i);
+  }
+  return str.str();
+}
+
+std::vector<int> 
+str_to_int_seq(std::string str)
+{
+  //convert a string to a list of integers
+  std::vector<int> seq(str.size());
+  std::vector<int>::iterator sitr;
+  std::string::iterator i;
+  for(i=str.begin(); i != str.end(); i++) {
+    int a = atoi(&(*i));
+    seq.push_back(a);
+  }
+  return seq;
+}
+
+int
+control_byte_1(bool fast_tuning_p, int reference_divisor)
+{
+  int c = 0x88;
+  if(fast_tuning_p) {
+    c |= 0x40;
+  }
+
+  if(reference_divisor == 512) {
+    c |= 0x3 << 1;
+  }
+  else if(reference_divisor == 640) {
+    c |= 0x0 << 1;
+  }
+  else if(reference_divisor == 1024) {
+    c |= 0x1 << 1;
+  }
+  else {
+    assert(0);
+  }
+
+  return c;
+}
+
+int
+control_byte_2(float target_freq, bool shutdown_tx_PGA)
+{
+  int c;
+  if(target_freq < 158e6) {        // VHF low
+    c = 0xa0;
+  }
+  else if(target_freq < 464e6) {   // VHF high
+    c = 0x90;
+  }
+  else {                           // UHF
+    c = 0x30;
+  }
+
+  if(shutdown_tx_PGA) {
+    c |= 0x08;
+  }
+
+  return c;
+}
+
+
+/**************************************************************************************************/
+
+
+db_tv_rx::db_tv_rx(usrp_basic *usrp, int which, float first_IF, float 
second_IF)
+  : db_base(usrp, which, true)
+{
+  // Handler for Tv Rx daughterboards.
+  // 
+  // @param usrp: instance of usrp.source_c
+  // @param which: which side: 0 or 1 corresponding to RX_A or RX_B 
respectively
+
+  // FIXME: This is a kluge
+  d_usrp = (usrp_basic_rx*)usrp;
+  d_tx = false;
+
+  if(which == 0) {
+    d_i2c_addr = 0x60;
+  }
+  else {
+    d_i2c_addr = 0x61;
+  }
+
+  d_first_IF = first_IF;
+  d_second_IF = second_IF;
+  d_reference_divisor = 640;
+  d_fast_tuning = false;
+  d_inverted = false;                     // FIXME get rid of this
+        
+  printf("Creating db_tv_rx1\n");
+  std::vector<float> g = gain_range();                  // initialize gain
+  printf("Creating db_tv_rx2    usrp: %x\n", d_usrp);
+  set_gain(float(g[0]+g[1]) / 2.0);
+
+  printf("Creating db_tv_rx3\n");
+  bypass_adc_buffers(false);
+  printf("Creating db_tv_rx4\n");
+}
+
+// Gain setting
+void
+db_tv_rx::_set_rfagc(float gain)
+{
+  float voltage;
+
+  assert(gain <= 60 && gain >= 0);
+  // FIXME this has a 0.5V step between gain = 60 and gain = 59.
+  // Why are there two cases instead of a single linear case?
+  if(gain == 60) {
+    voltage = 4;
+  }
+  else {
+    voltage = gain/60.0 * 2.25 + 1.25;
+  }
+  int dacword = int(4096*voltage/1.22/3.3);    // 1.22 = opamp gain
+
+  assert(dacword>=0 && dacword<4096);
+  printf("db_tv_rx::set_rfagc   usrp: %x\n", d_usrp);
+  d_usrp->write_aux_dac(d_which, 1, dacword);
+}
+
+void
+db_tv_rx::_set_ifagc(float gain)
+{
+  float voltage;
+
+  assert(gain <= 35 && gain >= 0);
+  voltage = gain/35.0 * 2.1 + 1.4;
+  int dacword = int(4096*voltage/1.22/3.3);    // 1.22 = opamp gain
+  
+  assert(dacword>=0 && dacword<4096);
+  d_usrp->write_aux_dac(d_which, 0, dacword);
+}
+
+void
+db_tv_rx::_set_pga(float pga_gain)
+{
+  assert(pga_gain >=0 && pga_gain <=20);
+  if(d_which == 0) {
+    d_usrp->set_pga(0, pga_gain);
+  }
+  else {
+    d_usrp->set_pga (2, pga_gain);
+  }
+}           
+
+std::vector<float> 
+db_tv_rx::freq_range() 
+{
+  // Return range of frequencies in Hz that can be tuned by this d'board.
+  // 
+  // @returns (min_freq, max_freq, step_size)
+  // @rtype tuple
+  
+  std::vector<float> f(3,0);
+  f[0] = 50e6;
+  f[1] = 860e6;
+  f[2] = 10e3;
+  return f;
+}
+
+std::vector<float>
+db_tv_rx::set_freq(float target_freq)
+{
+  // Set the frequency.
+  // 
+  // @param freq:  target RF frequency in Hz
+  // @type freq:   float
+  // 
+  // @returns (ok, actual_baseband_freq) where:
+  //   ok is True or False and indicates success or failure,
+  //   actual_baseband_freq is the RF frequency that corresponds to DC in the 
IF.
+  
+  std::vector<float> args(2, 0);
+
+  std::vector<float> r = freq_range();
+  if((target_freq < r[0]) || (target_freq > r[1])) {
+    return args;
+  }
+  
+  float target_lo_freq = target_freq + d_first_IF;  // High side mixing
+  float f_ref = 4e6 / d_reference_divisor;           // frequency steps
+
+  int divisor = int((target_lo_freq + (f_ref * 4)) / (f_ref * 8));  
+  float actual_lo_freq = (f_ref * 8 * divisor);
+  float actual_freq = actual_lo_freq - d_first_IF;
+
+  if((divisor & ~0x7fff) != 0) {               // must be 15-bits or less
+    return args;
+  }
+        
+  // build i2c command string
+  std::vector<int> buf(4);
+  buf[0] = (divisor >> 8) & 0xff;         // DB1
+  buf[1] = divisor & 0xff;                // DB2
+  buf[2] = control_byte_1(d_fast_tuning, d_reference_divisor);
+  buf[3] = control_byte_2(actual_freq, true);
+
+  bool ok = d_usrp->write_i2c(d_i2c_addr, int_seq_to_str (buf));
+
+  args[0] = 1;
+  args[1] = actual_freq - d_second_IF;
+  return args;
+}
+
+std::vector<float>
+db_tv_rx::gain_range()
+{
+  // Return range of gain that can be set by this d'board.
+  // 
+  // @returns (min_gain, max_gain, step_size)
+  //    Where gains are expressed in decibels (your mileage may vary)
+  
+  std::vector<float> g(3,0);
+  g[0] = 0;
+  g[1] = 115;
+  g[2] = 1;
+  return g;
+}
+
+bool 
+db_tv_rx::set_gain(float gain)
+{
+  // Set the gain.
+  // 
+  // @param gain:  gain in decibels
+  // @returns True/False
+
+  float rfgain, ifgain, pgagain;
+
+  assert(gain>=0 && gain<=115);
+  if(gain>60) {
+    rfgain = 60;
+    gain = gain - 60;
+  }
+  else {
+    rfgain = gain;
+    gain = 0;
+  }
+   
+  if(gain > 35) {
+    ifgain = 35;
+    gain = gain - 35;
+  }
+  else {
+    ifgain = gain;
+    gain = 0;
+  }
+
+  pgagain = gain;
+  _set_rfagc(rfgain);
+  printf("db_tv_rx::set_gain\n");
+  _set_ifagc(ifgain);
+  _set_pga(pgagain);
+
+  return true;
+}
+
+bool 
+db_tv_rx::is_quadrature()
+{
+  // Return True if this board requires both I & Q analog channels.  
+  //return false;
+  return false;
+}
+
+bool
+db_tv_rx::spectrum_inverted() 
+{
+  // The 43.75 MHz version is inverted
+  return d_inverted;
+}

Added: gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.h
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.h   
                        (rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/usrp/host/lib/legacy/db_tv_rx.h   
2008-08-10 19:45:40 UTC (rev 9224)
@@ -0,0 +1,59 @@
+/* -*- 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_TV_RX_H
+#define DB_TV_RX_H
+
+#include <db_base.h>
+
+class db_tv_rx : public db_base
+{
+private:
+  void _set_rfagc(float gain);
+  void _set_ifagc(float gain);
+  void _set_pga(float pga_gain);
+
+  usrp_basic_rx *d_usrp;
+  int d_i2c_addr;
+  float d_first_IF, d_second_IF;
+  int d_reference_divisor;
+  bool d_fast_tuning;
+  bool d_inverted;
+
+public:
+  db_tv_rx(usrp_basic *usrp, int which, 
+          float first_IF, float second_IF);
+
+  std::vector<float> freq_range();
+  std::vector<float> set_freq(float target_freq);
+  std::vector<float> gain_range();
+  bool               set_gain(float gain);
+  bool               is_quadrature();
+
+  bool               spectrum_inverted();
+};
+
+std::string int_seq_to_str(std::vector<int> &seq);
+std::vector<int> str_to_int_seq(std::string str);
+int control_byte_1(bool fast_tuning_p, int reference_divisor);
+int control_byte_2(float target_freq, bool shutdown_tx_PGA);
+
+#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]