From 1e44cf9e9c46c83e9acde104478fa2bd9acadc35 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Thu, 3 Jun 2010 12:49:03 -0700 Subject: Fixing wbx to use _refclk_freq() --- usrp/host/lib/db_wbxng.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'usrp/host/lib/db_wbxng.cc') diff --git a/usrp/host/lib/db_wbxng.cc b/usrp/host/lib/db_wbxng.cc index bd836dfe3..0666025bd 100644 --- a/usrp/host/lib/db_wbxng.cc +++ b/usrp/host/lib/db_wbxng.cc @@ -71,6 +71,12 @@ wbxng_base::~wbxng_base() delete d_common; } +int +wbxng_base::_refclk_divisor() +{ + return 1; +} + struct freq_result_t wbxng_base::set_freq(double freq) { @@ -83,8 +89,8 @@ wbxng_base::set_freq(double freq) // clamp freq freq_t int_freq = freq_t(std::max(freq_min(), std::min(freq, freq_max()))); - bool ok = d_common->_set_freq(int_freq*2); - double freq_result = (double) d_common->_get_freq()/2.0; + bool ok = d_common->_set_freq(int_freq*2, _refclk_freq()); + double freq_result = (double) d_common->_get_freq(_refclk_freq())/2.0; struct freq_result_t args = {ok, freq_result}; /* Wait before reading Lock Detect*/ -- cgit From 9004b4524713992660012d7932f6dcace74e54b0 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Thu, 3 Jun 2010 13:25:42 -0700 Subject: Clean up annoying class structure in wbx --- usrp/host/lib/db_wbxng.cc | 86 ++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 53 deletions(-) (limited to 'usrp/host/lib/db_wbxng.cc') diff --git a/usrp/host/lib/db_wbxng.cc b/usrp/host/lib/db_wbxng.cc index 0666025bd..69220930c 100644 --- a/usrp/host/lib/db_wbxng.cc +++ b/usrp/host/lib/db_wbxng.cc @@ -46,8 +46,8 @@ #define ATTN_SHIFT 8 #define ATTN_MASK (63 << ATTN_SHIFT) -wbxng_base::wbxng_base(usrp_basic_sptr _usrp, int which, int _power_on) - : db_base(_usrp, which), d_power_on(_power_on) +wbxng_base::wbxng_base(usrp_basic_sptr _usrp, int which) + : db_base(_usrp, which) { /* @param usrp: instance of usrp.source_c @@ -152,8 +152,8 @@ wbxng_base::freq_max() // ---------------------------------------------------------------- -wbxng_base_tx::wbxng_base_tx(usrp_basic_sptr _usrp, int which, int _power_on) - : wbxng_base(_usrp, which, _power_on) +db_wbxng_tx::db_wbxng_tx(usrp_basic_sptr _usrp, int which) + : wbxng_base(_usrp, which) { /* @param usrp: instance of usrp.sink_c @@ -171,7 +171,7 @@ wbxng_base_tx::wbxng_base_tx(usrp_basic_sptr _usrp, int which, int _power_on) // power up the transmit side, but don't enable the mixer usrp()->_write_oe(d_which,(RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5), (RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5)); - usrp()->write_io(d_which, (power_on()|RX_TXN|ENABLE_33|ENABLE_5), (RX_TXN|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, (RX_TXN|ENABLE_33|ENABLE_5), (RX_TXN|ENABLE_33|ENABLE_5)); //set_lo_offset(4e6); // Disable VCO/PLL @@ -180,16 +180,16 @@ wbxng_base_tx::wbxng_base_tx(usrp_basic_sptr _usrp, int which, int _power_on) set_gain((gain_min() + gain_max()) / 2.0); // initialize gain } -wbxng_base_tx::~wbxng_base_tx() +db_wbxng_tx::~db_wbxng_tx() { shutdown(); } void -wbxng_base_tx::shutdown() +db_wbxng_tx::shutdown() { - // fprintf(stderr, "wbxng_base_tx::shutdown d_is_shutdown = %d\n", d_is_shutdown); + // fprintf(stderr, "db_wbxng_tx::shutdown d_is_shutdown = %d\n", d_is_shutdown); if (!d_is_shutdown){ d_is_shutdown = true; @@ -199,7 +199,7 @@ wbxng_base_tx::shutdown() d_common->_enable(false); // Power down and leave the T/R switch in the R position - usrp()->write_io(d_which, (power_off()|RX_TXN), (RX_TXN|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, (RX_TXN), (RX_TXN|ENABLE_33|ENABLE_5)); /* @@ -211,7 +211,7 @@ wbxng_base_tx::shutdown() } bool -wbxng_base_tx::set_auto_tr(bool on) +db_wbxng_tx::set_auto_tr(bool on) { bool ok = true; if(on) { @@ -228,7 +228,7 @@ wbxng_base_tx::set_auto_tr(bool on) } bool -wbxng_base_tx::set_enable(bool on) +db_wbxng_tx::set_enable(bool on) { /* Enable transmitter if on is true @@ -250,25 +250,25 @@ wbxng_base_tx::set_enable(bool on) } float -wbxng_base_tx::gain_min() +db_wbxng_tx::gain_min() { return 0.0; } float -wbxng_base_tx::gain_max() +db_wbxng_tx::gain_max() { return 25.0; } float -wbxng_base_tx::gain_db_per_step() +db_wbxng_tx::gain_db_per_step() { return gain_max()/(1+(1.4-0.5)*4096/3.3); } bool -wbxng_base_tx::set_gain(float gain) +db_wbxng_tx::set_gain(float gain) { /* Set the gain. @@ -305,8 +305,8 @@ wbxng_base_tx::set_gain(float gain) /**************************************************************************/ -wbxng_base_rx::wbxng_base_rx(usrp_basic_sptr _usrp, int which, int _power_on) - : wbxng_base(_usrp, which, _power_on) +db_wbxng_rx::db_wbxng_rx(usrp_basic_sptr _usrp, int which) + : wbxng_base(_usrp, which) { /* @param usrp: instance of usrp.source_c @@ -326,7 +326,7 @@ wbxng_base_rx::wbxng_base_rx(usrp_basic_sptr _usrp, int which, int _power_on) d_common->_enable(true); usrp()->_write_oe(d_which, (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); - usrp()->write_io(d_which, (power_on()|RX2_RX1N|RXBB_EN|ENABLE_33|ENABLE_5), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, (RX2_RX1N|RXBB_EN|ENABLE_33|ENABLE_5), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); //fprintf(stderr,"Setting WBXNG RXBB on"); // set up for RX on TX/RX port @@ -337,17 +337,19 @@ wbxng_base_rx::wbxng_base_rx(usrp_basic_sptr _usrp, int which, int _power_on) /* set_lo_offset(-4e6); */ + + set_gain((gain_min() + gain_max()) / 2.0); // initialize gain } -wbxng_base_rx::~wbxng_base_rx() +db_wbxng_rx::~db_wbxng_rx() { shutdown(); } void -wbxng_base_rx::shutdown() +db_wbxng_rx::shutdown() { - // fprintf(stderr, "wbxng_base_rx::shutdown d_is_shutdown = %d\n", d_is_shutdown); + // fprintf(stderr, "db_wbxng_rx::shutdown d_is_shutdown = %d\n", d_is_shutdown); if (!d_is_shutdown){ d_is_shutdown = true; @@ -356,24 +358,24 @@ wbxng_base_rx::shutdown() // Power down VCO/PLL d_common->_enable(false); - // fprintf(stderr, "wbxng_base_rx::shutdown before _write_control\n"); + // fprintf(stderr, "db_wbxng_rx::shutdown before _write_control\n"); //_write_control(_compute_control_reg()); - // fprintf(stderr, "wbxng_base_rx::shutdown before _enable_refclk\n"); + // fprintf(stderr, "db_wbxng_rx::shutdown before _enable_refclk\n"); _enable_refclk(false); // turn off refclk - // fprintf(stderr, "wbxng_base_rx::shutdown before set_auto_tr\n"); + // fprintf(stderr, "db_wbxng_rx::shutdown before set_auto_tr\n"); set_auto_tr(false); // Power down - usrp()->write_io(d_which, power_off(), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, 0, (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); - // fprintf(stderr, "wbxng_base_rx::shutdown after set_auto_tr\n"); + // fprintf(stderr, "db_wbxng_rx::shutdown after set_auto_tr\n"); } } bool -wbxng_base_rx::set_auto_tr(bool on) +db_wbxng_rx::set_auto_tr(bool on) { bool ok = true; if(on) { @@ -390,7 +392,7 @@ wbxng_base_rx::set_auto_tr(bool on) } bool -wbxng_base_rx::select_rx_antenna(int which_antenna) +db_wbxng_rx::select_rx_antenna(int which_antenna) { /* Specify which antenna port to use for reception. @@ -410,7 +412,7 @@ wbxng_base_rx::select_rx_antenna(int which_antenna) } bool -wbxng_base_rx::select_rx_antenna(const std::string &which_antenna) +db_wbxng_rx::select_rx_antenna(const std::string &which_antenna) { /* Specify which antenna port to use for reception. @@ -432,7 +434,7 @@ wbxng_base_rx::select_rx_antenna(const std::string &which_antenna) } bool -wbxng_base_rx::set_gain(float gain) +db_wbxng_rx::set_gain(float gain) { /* Set the gain. @@ -462,7 +464,7 @@ wbxng_base_rx::set_gain(float gain) } bool -wbxng_base_rx::_set_attn(float attn) +db_wbxng_rx::_set_attn(float attn) { int attn_code = int(floor(attn/0.5)); unsigned int iobits = (~attn_code) << ATTN_SHIFT; @@ -470,27 +472,6 @@ wbxng_base_rx::_set_attn(float attn) return usrp()->write_io(d_which, iobits, ATTN_MASK); } -// ---------------------------------------------------------------- - -db_wbxng_tx::db_wbxng_tx(usrp_basic_sptr usrp, int which) - : wbxng_base_tx(usrp, which) -{ -} - -db_wbxng_tx::~db_wbxng_tx() -{ -} - -db_wbxng_rx::db_wbxng_rx(usrp_basic_sptr usrp, int which) - : wbxng_base_rx(usrp, which) -{ - set_gain((gain_min() + gain_max()) / 2.0); // initialize gain -} - -db_wbxng_rx::~db_wbxng_rx() -{ -} - float db_wbxng_rx::gain_min() { @@ -509,7 +490,6 @@ db_wbxng_rx::gain_db_per_step() return 0.05; } - bool db_wbxng_rx::i_and_q_swapped() { -- cgit From 937b74e9f60a2668a6f39f7f5d7291a8e00aef1f Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Thu, 3 Jun 2010 14:35:18 -0700 Subject: Refactor WBX and adf4350 to avoid passing usrp pointer --- usrp/host/lib/db_wbxng.cc | 72 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 17 deletions(-) (limited to 'usrp/host/lib/db_wbxng.cc') diff --git a/usrp/host/lib/db_wbxng.cc b/usrp/host/lib/db_wbxng.cc index 69220930c..62007514a 100644 --- a/usrp/host/lib/db_wbxng.cc +++ b/usrp/host/lib/db_wbxng.cc @@ -67,8 +67,6 @@ wbxng_base::wbxng_base(usrp_basic_sptr _usrp, int which) wbxng_base::~wbxng_base() { - if (d_common) - delete d_common; } int @@ -90,7 +88,18 @@ wbxng_base::set_freq(double freq) freq_t int_freq = freq_t(std::max(freq_min(), std::min(freq, freq_max()))); bool ok = d_common->_set_freq(int_freq*2, _refclk_freq()); + + _write_spi(d_common->compute_register(5)); + _write_spi(d_common->compute_register(4)); + _write_spi(d_common->compute_register(3)); + /* load involved registers */ + _write_spi(d_common->compute_register(2)); + _write_spi(d_common->compute_register(1)); + _write_spi(d_common->compute_register(0)); + double freq_result = (double) d_common->_get_freq(_refclk_freq())/2.0; + + //ok &= _get_locked(); struct freq_result_t args = {ok, freq_result}; /* Wait before reading Lock Detect*/ @@ -150,6 +159,18 @@ wbxng_base::freq_max() return (double) d_common->_get_max_freq()/2.0; } +bool +wbxng_base::_get_locked(void) +{ + return usrp()->read_io(d_which) & PLL_LOCK_DETECT; +} + +void +wbxng_base::_write_spi(std::string data) +{ + usrp()->_write_spi(0, d_spi_enable, d_spi_format, data); +} + // ---------------------------------------------------------------- db_wbxng_tx::db_wbxng_tx(usrp_basic_sptr _usrp, int which) @@ -167,15 +188,24 @@ db_wbxng_tx::db_wbxng_tx(usrp_basic_sptr _usrp, int which) d_spi_enable = SPI_ENABLE_TX_B; } - d_common = new adf4350(_usrp, d_which, d_spi_enable); + d_common = boost::shared_ptr (new adf4350()); + + /* Initialize the registers. */ + _write_spi(d_common->compute_register(5)); + _write_spi(d_common->compute_register(4)); + _write_spi(d_common->compute_register(3)); + _write_spi(d_common->compute_register(2)); + _write_spi(d_common->compute_register(1)); + _write_spi(d_common->compute_register(0)); // power up the transmit side, but don't enable the mixer - usrp()->_write_oe(d_which,(RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5), (RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5)); - usrp()->write_io(d_which, (RX_TXN|ENABLE_33|ENABLE_5), (RX_TXN|ENABLE_33|ENABLE_5)); + usrp()->_write_oe(d_which,(PLL_CE|PLL_PDBRF|RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, (PLL_CE|RX_TXN|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX_TXN|ENABLE_33|ENABLE_5)); //set_lo_offset(4e6); // Disable VCO/PLL - d_common->_enable(true); + //d_common->_enable(true); + usrp()->write_io(d_which, (PLL_PDBRF), (PLL_PDBRF)); set_gain((gain_min() + gain_max()) / 2.0); // initialize gain } @@ -185,7 +215,6 @@ db_wbxng_tx::~db_wbxng_tx() shutdown(); } - void db_wbxng_tx::shutdown() { @@ -196,11 +225,11 @@ db_wbxng_tx::shutdown() // do whatever there is to do to shutdown // Disable VCO/PLL - d_common->_enable(false); + //d_common->_enable(false); + usrp()->write_io(d_which, 0, (PLL_PDBRF)); // Power down and leave the T/R switch in the R position - usrp()->write_io(d_which, (RX_TXN), (RX_TXN|ENABLE_33|ENABLE_5)); - + usrp()->write_io(d_which, (RX_TXN), (PLL_CE|PLL_PDBRF|RX_TXN|ENABLE_33|ENABLE_5)); /* _write_control(_compute_control_reg()); @@ -320,13 +349,22 @@ db_wbxng_rx::db_wbxng_rx(usrp_basic_sptr _usrp, int which) d_spi_enable = SPI_ENABLE_RX_B; } - d_common = new adf4350(_usrp, d_which, d_spi_enable); + d_common = boost::shared_ptr (new adf4350()); + + /* Initialize the registers. */ + _write_spi(d_common->compute_register(5)); + _write_spi(d_common->compute_register(4)); + _write_spi(d_common->compute_register(3)); + _write_spi(d_common->compute_register(2)); + _write_spi(d_common->compute_register(1)); + _write_spi(d_common->compute_register(0)); // Disable VCO/PLL - d_common->_enable(true); + //d_common->_enable(true); + usrp()->write_io(d_which, (PLL_PDBRF), (PLL_PDBRF)); - usrp()->_write_oe(d_which, (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); - usrp()->write_io(d_which, (RX2_RX1N|RXBB_EN|ENABLE_33|ENABLE_5), (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); + usrp()->_write_oe(d_which, (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, (PLL_CE|RX2_RX1N|RXBB_EN|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); //fprintf(stderr,"Setting WBXNG RXBB on"); // set up for RX on TX/RX port @@ -356,7 +394,8 @@ db_wbxng_rx::shutdown() // do whatever there is to do to shutdown // Power down VCO/PLL - d_common->_enable(false); + //d_common->_enable(false); + usrp()->write_io(d_which, 0, (PLL_PDBRF)); // fprintf(stderr, "db_wbxng_rx::shutdown before _write_control\n"); //_write_control(_compute_control_reg()); @@ -368,7 +407,7 @@ db_wbxng_rx::shutdown() set_auto_tr(false); // Power down - usrp()->write_io(d_which, 0, (RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); + usrp()->write_io(d_which, 0, (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); // fprintf(stderr, "db_wbxng_rx::shutdown after set_auto_tr\n"); } @@ -449,7 +488,6 @@ db_wbxng_rx::set_gain(float gain) float pga_gain, agc_gain; float maxgain = gain_max() - usrp()->pga_max(); - float mingain = gain_min(); if(gain > maxgain) { pga_gain = gain-maxgain; assert(pga_gain <= usrp()->pga_max()); -- cgit From 5fc7083812b85a7f3e65daff8e879ef7521f5122 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Fri, 4 Jun 2010 15:34:27 -0700 Subject: Fixed WBX RX PLL enable --- usrp/host/lib/db_wbxng.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'usrp/host/lib/db_wbxng.cc') diff --git a/usrp/host/lib/db_wbxng.cc b/usrp/host/lib/db_wbxng.cc index 62007514a..89200653e 100644 --- a/usrp/host/lib/db_wbxng.cc +++ b/usrp/host/lib/db_wbxng.cc @@ -207,7 +207,7 @@ db_wbxng_tx::db_wbxng_tx(usrp_basic_sptr _usrp, int which) //d_common->_enable(true); usrp()->write_io(d_which, (PLL_PDBRF), (PLL_PDBRF)); - set_gain((gain_min() + gain_max()) / 2.0); // initialize gain + set_gain(gain_min()); // initialize gain } db_wbxng_tx::~db_wbxng_tx() @@ -359,14 +359,14 @@ db_wbxng_rx::db_wbxng_rx(usrp_basic_sptr _usrp, int which) _write_spi(d_common->compute_register(1)); _write_spi(d_common->compute_register(0)); - // Disable VCO/PLL - //d_common->_enable(true); - usrp()->write_io(d_which, (PLL_PDBRF), (PLL_PDBRF)); - usrp()->_write_oe(d_which, (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); usrp()->write_io(d_which, (PLL_CE|RX2_RX1N|RXBB_EN|ENABLE_33|ENABLE_5), (PLL_CE|PLL_PDBRF|RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5)); //fprintf(stderr,"Setting WBXNG RXBB on"); + // Enable VCO/PLL + //d_common->_enable(true); + usrp()->write_io(d_which, (PLL_PDBRF), (PLL_PDBRF)); + // set up for RX on TX/RX port select_rx_antenna("TX/RX"); @@ -376,7 +376,7 @@ db_wbxng_rx::db_wbxng_rx(usrp_basic_sptr _usrp, int which) set_lo_offset(-4e6); */ - set_gain((gain_min() + gain_max()) / 2.0); // initialize gain + set_gain(gain_min()); // initialize gain } db_wbxng_rx::~db_wbxng_rx() -- cgit