root / host / lib / usrp / dboard / db_rfx.cpp @ 7d00269f
History | View | Annotate | Download (20.6 KB)
| 1 | 275b29e0 | Josh Blum | //
|
|---|---|---|---|
| 2 | 261bb80d | Josh Blum | // Copyright 2010-2011 Ettus Research LLC
|
| 3 | 275b29e0 | Josh Blum | //
|
| 4 | // This program is free software: you can redistribute it and/or modify
|
||
| 5 | // it under the terms of the GNU General Public License as published by
|
||
| 6 | // the Free Software Foundation, either version 3 of the License, or
|
||
| 7 | // (at your option) any later version.
|
||
| 8 | //
|
||
| 9 | // This program is distributed in the hope that it will be useful,
|
||
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | // GNU General Public License for more details.
|
||
| 13 | //
|
||
| 14 | // You should have received a copy of the GNU General Public License
|
||
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 16 | //
|
||
| 17 | |||
| 18 | 91319520 | Josh Blum | // IO Pin functions
|
| 19 | 067491b5 | Josh Blum | #define POWER_IO (1 << 7) // Low enables power supply |
| 20 | #define ANTSW_IO (1 << 6) // On TX DB, 0 = TX, 1 = RX, on RX DB 0 = main ant, 1 = RX2 |
||
| 21 | #define MIXER_IO (1 << 5) // Enable appropriate mixer |
||
| 22 | 91319520 | Josh Blum | #define LOCKDET_MASK (1 << 2) // Input pin |
| 23 | |||
| 24 | 067491b5 | Josh Blum | // Mixer constants
|
| 25 | #define MIXER_ENB MIXER_IO
|
||
| 26 | #define MIXER_DIS 0 |
||
| 27 | |||
| 28 | 6d0a60b9 | Josh Blum | // Antenna constants
|
| 29 | #define ANT_TX 0 //the tx line is transmitting |
||
| 30 | 067491b5 | Josh Blum | #define ANT_RX ANTSW_IO //the tx line is receiving |
| 31 | 6d0a60b9 | Josh Blum | #define ANT_TXRX 0 //the rx line is on txrx |
| 32 | 067491b5 | Josh Blum | #define ANT_RX2 ANTSW_IO //the rx line in on rx2 |
| 33 | 6d0a60b9 | Josh Blum | #define ANT_XX 0 //dont care how the antenna is set |
| 34 | |||
| 35 | e6151334 | Josh Blum | #include "adf4360_regs.hpp" |
| 36 | cbf7a091 | Josh Blum | #include <uhd/types/dict.hpp> |
| 37 | 275b29e0 | Josh Blum | #include <uhd/usrp/subdev_props.hpp> |
| 38 | #include <uhd/types/ranges.hpp> |
||
| 39 | #include <uhd/utils/assert.hpp> |
||
| 40 | #include <uhd/utils/static.hpp> |
||
| 41 | f57f616c | Josh Blum | #include <uhd/utils/algorithm.hpp> |
| 42 | bb82453a | Jason Abele | #include <uhd/utils/warning.hpp> |
| 43 | 4220097f | Jason Abele | #include <uhd/usrp/dboard_id.hpp> |
| 44 | 275b29e0 | Josh Blum | #include <uhd/usrp/dboard_base.hpp> |
| 45 | #include <uhd/usrp/dboard_manager.hpp> |
||
| 46 | #include <boost/assign/list_of.hpp> |
||
| 47 | #include <boost/format.hpp> |
||
| 48 | 0718961e | Josh Blum | #include <boost/math/special_functions/round.hpp> |
| 49 | 275b29e0 | Josh Blum | |
| 50 | using namespace uhd; |
||
| 51 | using namespace uhd::usrp; |
||
| 52 | using namespace boost::assign; |
||
| 53 | |||
| 54 | /***********************************************************************
|
||
| 55 | fb000993 | Josh Blum | * The RFX Series constants
|
| 56 | 275b29e0 | Josh Blum | **********************************************************************/
|
| 57 | fb000993 | Josh Blum | static const bool rfx_debug = false; |
| 58 | |||
| 59 | static const prop_names_t rfx_tx_antennas = list_of("TX/RX"); |
||
| 60 | |||
| 61 | static const prop_names_t rfx_rx_antennas = list_of("TX/RX")("RX2"); |
||
| 62 | f57f616c | Josh Blum | |
| 63 | fb000993 | Josh Blum | static const uhd::dict<std::string, gain_range_t> rfx_tx_gain_ranges; //empty |
| 64 | |||
| 65 | static const uhd::dict<std::string, gain_range_t> rfx_rx_gain_ranges = map_list_of |
||
| 66 | 395bbbbc | Josh Blum | ("PGA0", gain_range_t(0, 70, 0.022)) |
| 67 | 4220097f | Jason Abele | ; |
| 68 | |||
| 69 | static const uhd::dict<std::string, gain_range_t> rfx400_rx_gain_ranges = map_list_of |
||
| 70 | 395bbbbc | Josh Blum | ("PGA0", gain_range_t(0, 45, 0.022)) |
| 71 | fb000993 | Josh Blum | ; |
| 72 | |||
| 73 | /***********************************************************************
|
||
| 74 | * The RFX series of dboards
|
||
| 75 | **********************************************************************/
|
||
| 76 | 275b29e0 | Josh Blum | class rfx_xcvr : public xcvr_dboard_base{ |
| 77 | public:
|
||
| 78 | cbf7a091 | Josh Blum | rfx_xcvr( |
| 79 | fd0d9b7d | Josh Blum | ctor_args_t args, |
| 80 | cbf7a091 | Josh Blum | const freq_range_t &freq_range,
|
| 81 | bool rx_div2, bool tx_div2 |
||
| 82 | ); |
||
| 83 | 275b29e0 | Josh Blum | ~rfx_xcvr(void);
|
| 84 | |||
| 85 | void rx_get(const wax::obj &key, wax::obj &val); |
||
| 86 | void rx_set(const wax::obj &key, const wax::obj &val); |
||
| 87 | |||
| 88 | void tx_get(const wax::obj &key, wax::obj &val); |
||
| 89 | void tx_set(const wax::obj &key, const wax::obj &val); |
||
| 90 | |||
| 91 | private:
|
||
| 92 | 08dfff37 | Josh Blum | const freq_range_t _freq_range;
|
| 93 | const uhd::dict<std::string, gain_range_t> _rx_gain_ranges; |
||
| 94 | const uhd::dict<dboard_iface::unit_t, bool> _div2; |
||
| 95 | cbf7a091 | Josh Blum | double _rx_lo_freq, _tx_lo_freq;
|
| 96 | 275b29e0 | Josh Blum | std::string _rx_ant;
|
| 97 | 395bbbbc | Josh Blum | uhd::dict<std::string, double> _rx_gains; |
| 98 | 7d00269f | Jason Abele | boost::uint16_t _power_up; |
| 99 | 275b29e0 | Josh Blum | |
| 100 | cbf7a091 | Josh Blum | void set_rx_lo_freq(double freq); |
| 101 | void set_tx_lo_freq(double freq); |
||
| 102 | 275b29e0 | Josh Blum | void set_rx_ant(const std::string &ant); |
| 103 | fb000993 | Josh Blum | void set_tx_ant(const std::string &ant); |
| 104 | 395bbbbc | Josh Blum | void set_rx_gain(double gain, const std::string &name); |
| 105 | void set_tx_gain(double gain, const std::string &name); |
||
| 106 | fb000993 | Josh Blum | |
| 107 | cbf7a091 | Josh Blum | /*!
|
| 108 | * Set the LO frequency for the particular dboard unit.
|
||
| 109 | * \param unit which unit rx or tx
|
||
| 110 | * \param target_freq the desired frequency in Hz
|
||
| 111 | * \return the actual frequency in Hz
|
||
| 112 | */
|
||
| 113 | double set_lo_freq(dboard_iface::unit_t unit, double target_freq); |
||
| 114 | b1992806 | Josh Blum | |
| 115 | /*!
|
||
| 116 | * Get the lock detect status of the LO.
|
||
| 117 | * \param unit which unit rx or tx
|
||
| 118 | * \return true for locked
|
||
| 119 | */
|
||
| 120 | bool get_locked(dboard_iface::unit_t unit){
|
||
| 121 | return (this->get_iface()->read_gpio(unit) & LOCKDET_MASK) != 0; |
||
| 122 | } |
||
| 123 | 275b29e0 | Josh Blum | }; |
| 124 | |||
| 125 | /***********************************************************************
|
||
| 126 | cbf7a091 | Josh Blum | * Register the RFX dboards (min freq, max freq, rx div2, tx div2)
|
| 127 | 275b29e0 | Josh Blum | **********************************************************************/
|
| 128 | fd0d9b7d | Josh Blum | static dboard_base::sptr make_rfx_flex400(dboard_base::ctor_args_t args){
|
| 129 | 7d00269f | Jason Abele | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(400e6, 500e6), true, true)); |
| 130 | 275b29e0 | Josh Blum | } |
| 131 | |||
| 132 | fd0d9b7d | Josh Blum | static dboard_base::sptr make_rfx_flex900(dboard_base::ctor_args_t args){
|
| 133 | cbf7a091 | Josh Blum | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(750e6, 1050e6), true, true)); |
| 134 | 275b29e0 | Josh Blum | } |
| 135 | |||
| 136 | fd0d9b7d | Josh Blum | static dboard_base::sptr make_rfx_flex1800(dboard_base::ctor_args_t args){
|
| 137 | cbf7a091 | Josh Blum | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1500e6, 2100e6), false, false)); |
| 138 | 275b29e0 | Josh Blum | } |
| 139 | |||
| 140 | fd0d9b7d | Josh Blum | static dboard_base::sptr make_rfx_flex1200(dboard_base::ctor_args_t args){
|
| 141 | cbf7a091 | Josh Blum | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1150e6, 1450e6), true, true)); |
| 142 | 275b29e0 | Josh Blum | } |
| 143 | |||
| 144 | 16335c10 | Josh Blum | static dboard_base::sptr make_rfx_flex2200(dboard_base::ctor_args_t args){
|
| 145 | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(2000e6, 2400e6), false, false)); |
||
| 146 | } |
||
| 147 | |||
| 148 | fd0d9b7d | Josh Blum | static dboard_base::sptr make_rfx_flex2400(dboard_base::ctor_args_t args){
|
| 149 | cbf7a091 | Josh Blum | return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(2300e6, 2900e6), false, false)); |
| 150 | 275b29e0 | Josh Blum | } |
| 151 | |||
| 152 | UHD_STATIC_BLOCK(reg_rfx_dboards){
|
||
| 153 | d96b2e75 | Josh Blum | dboard_manager::register_dboard(0x0024, 0x0028, &make_rfx_flex400, "RFX400"); |
| 154 | dboard_manager::register_dboard(0x0025, 0x0029, &make_rfx_flex900, "RFX900"); |
||
| 155 | dboard_manager::register_dboard(0x0034, 0x0035, &make_rfx_flex1800, "RFX1800"); |
||
| 156 | dboard_manager::register_dboard(0x0026, 0x002a, &make_rfx_flex1200, "RFX1200"); |
||
| 157 | dboard_manager::register_dboard(0x002c, 0x002d, &make_rfx_flex2200, "RFX2200"); |
||
| 158 | dboard_manager::register_dboard(0x0027, 0x002b, &make_rfx_flex2400, "RFX2400"); |
||
| 159 | 275b29e0 | Josh Blum | } |
| 160 | |||
| 161 | /***********************************************************************
|
||
| 162 | * Structors
|
||
| 163 | **********************************************************************/
|
||
| 164 | rfx_xcvr::rfx_xcvr( |
||
| 165 | fd0d9b7d | Josh Blum | ctor_args_t args, |
| 166 | cbf7a091 | Josh Blum | const freq_range_t &freq_range,
|
| 167 | bool rx_div2, bool tx_div2 |
||
| 168 | 08dfff37 | Josh Blum | ): |
| 169 | xcvr_dboard_base(args), |
||
| 170 | _freq_range(freq_range), |
||
| 171 | b08ac627 | Josh Blum | _rx_gain_ranges((get_rx_id() == 0x0024)?
|
| 172 | 08dfff37 | Josh Blum | rfx400_rx_gain_ranges : rfx_rx_gain_ranges |
| 173 | ), |
||
| 174 | _div2(map_list_of |
||
| 175 | (dboard_iface::UNIT_RX, rx_div2) |
||
| 176 | (dboard_iface::UNIT_TX, tx_div2) |
||
| 177 | 7d00269f | Jason Abele | ), |
| 178 | _power_up((get_rx_id() == 0x0024 && get_tx_id() == 0x0028) ? POWER_IO : 0) |
||
| 179 | 08dfff37 | Josh Blum | {
|
| 180 | 91319520 | Josh Blum | //enable the clocks that we need
|
| 181 | e2a94193 | Josh Blum | this->get_iface()->set_clock_enabled(dboard_iface::UNIT_TX, true); |
| 182 | this->get_iface()->set_clock_enabled(dboard_iface::UNIT_RX, true); |
||
| 183 | 91319520 | Josh Blum | |
| 184 | 39943a5b | Josh Blum | //set the gpio directions and atr controls (identically)
|
| 185 | 067491b5 | Josh Blum | boost::uint16_t output_enables = POWER_IO | ANTSW_IO | MIXER_IO; |
| 186 | 39943a5b | Josh Blum | this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_TX, output_enables);
|
| 187 | this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_RX, output_enables);
|
||
| 188 | e2a94193 | Josh Blum | this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_TX, output_enables);
|
| 189 | this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, output_enables);
|
||
| 190 | 91319520 | Josh Blum | |
| 191 | //setup the tx atr (this does not change with antenna)
|
||
| 192 | 7d00269f | Jason Abele | this->get_iface()->set_atr_reg(dboard_iface::UNIT_TX, dboard_iface::ATR_REG_IDLE, _power_up | ANT_XX | MIXER_DIS);
|
| 193 | this->get_iface()->set_atr_reg(dboard_iface::UNIT_TX, dboard_iface::ATR_REG_RX_ONLY, _power_up | ANT_RX | MIXER_DIS);
|
||
| 194 | this->get_iface()->set_atr_reg(dboard_iface::UNIT_TX, dboard_iface::ATR_REG_TX_ONLY, _power_up | ANT_TX | MIXER_ENB);
|
||
| 195 | this->get_iface()->set_atr_reg(dboard_iface::UNIT_TX, dboard_iface::ATR_REG_FULL_DUPLEX, _power_up | ANT_TX | MIXER_ENB);
|
||
| 196 | 6d0a60b9 | Josh Blum | |
| 197 | //setup the rx atr (this does not change with antenna)
|
||
| 198 | 7d00269f | Jason Abele | this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_IDLE, _power_up | ANT_XX | MIXER_DIS);
|
| 199 | this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_TX_ONLY, _power_up | ANT_XX | MIXER_DIS);
|
||
| 200 | this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_FULL_DUPLEX, _power_up | ANT_RX2| MIXER_ENB);
|
||
| 201 | 91319520 | Josh Blum | |
| 202 | //set some default values
|
||
| 203 | 08dfff37 | Josh Blum | set_rx_lo_freq((_freq_range.start() + _freq_range.stop())/2.0); |
| 204 | set_tx_lo_freq((_freq_range.start() + _freq_range.stop())/2.0); |
||
| 205 | f57f616c | Josh Blum | set_rx_ant("RX2");
|
| 206 | 00b33d97 | Jason Abele | |
| 207 | 4220097f | Jason Abele | BOOST_FOREACH(const std::string &name, _rx_gain_ranges.keys()){ |
| 208 | 08dfff37 | Josh Blum | set_rx_gain(_rx_gain_ranges[name].start(), name); |
| 209 | 00b33d97 | Jason Abele | } |
| 210 | 275b29e0 | Josh Blum | } |
| 211 | |||
| 212 | rfx_xcvr::~rfx_xcvr(void){
|
||
| 213 | /* NOP */
|
||
| 214 | } |
||
| 215 | |||
| 216 | /***********************************************************************
|
||
| 217 | fb000993 | Josh Blum | * Antenna Handling
|
| 218 | 275b29e0 | Josh Blum | **********************************************************************/
|
| 219 | void rfx_xcvr::set_rx_ant(const std::string &ant){ |
||
| 220 | f57f616c | Josh Blum | //validate input
|
| 221 | fb000993 | Josh Blum | assert_has(rfx_rx_antennas, ant, "rfx rx antenna name");
|
| 222 | f57f616c | Josh Blum | |
| 223 | 6d0a60b9 | Josh Blum | //set the rx atr regs that change with antenna setting
|
| 224 | this->get_iface()->set_atr_reg(
|
||
| 225 | dboard_iface::UNIT_RX, dboard_iface::ATR_REG_RX_ONLY, |
||
| 226 | 7d00269f | Jason Abele | _power_up | MIXER_ENB | ((ant == "TX/RX")? ANT_TXRX : ANT_RX2)
|
| 227 | 6d0a60b9 | Josh Blum | ); |
| 228 | f57f616c | Josh Blum | |
| 229 | //shadow the setting
|
||
| 230 | _rx_ant = ant; |
||
| 231 | 275b29e0 | Josh Blum | } |
| 232 | |||
| 233 | fb000993 | Josh Blum | void rfx_xcvr::set_tx_ant(const std::string &ant){ |
| 234 | assert_has(rfx_tx_antennas, ant, "rfx tx antenna name");
|
||
| 235 | //only one antenna option, do nothing
|
||
| 236 | } |
||
| 237 | |||
| 238 | /***********************************************************************
|
||
| 239 | * Gain Handling
|
||
| 240 | **********************************************************************/
|
||
| 241 | 395bbbbc | Josh Blum | static double rx_pga0_gain_to_dac_volts(double &gain, double range){ |
| 242 | 00b33d97 | Jason Abele | //voltage level constants (negative slope)
|
| 243 | 395bbbbc | Josh Blum | static const double max_volts = .2, min_volts = 1.2; |
| 244 | static const double slope = (max_volts-min_volts)/(range); |
||
| 245 | 00b33d97 | Jason Abele | |
| 246 | //calculate the voltage for the aux dac
|
||
| 247 | 395bbbbc | Josh Blum | double dac_volts = std::clip<double>(gain*slope + min_volts, max_volts, min_volts); |
| 248 | 00b33d97 | Jason Abele | |
| 249 | //the actual gain setting
|
||
| 250 | gain = (dac_volts - min_volts)/slope; |
||
| 251 | |||
| 252 | return dac_volts;
|
||
| 253 | } |
||
| 254 | |||
| 255 | 395bbbbc | Josh Blum | void rfx_xcvr::set_tx_gain(double, const std::string &name){ |
| 256 | fb000993 | Josh Blum | assert_has(rfx_tx_gain_ranges.keys(), name, "rfx tx gain name");
|
| 257 | 33193a06 | Josh Blum | UHD_THROW_INVALID_CODE_PATH(); //no gains to set
|
| 258 | fb000993 | Josh Blum | } |
| 259 | |||
| 260 | 395bbbbc | Josh Blum | void rfx_xcvr::set_rx_gain(double gain, const std::string &name){ |
| 261 | 4220097f | Jason Abele | assert_has(_rx_gain_ranges.keys(), name, "rfx rx gain name");
|
| 262 | fb000993 | Josh Blum | if(name == "PGA0"){ |
| 263 | 395bbbbc | Josh Blum | double dac_volts = rx_pga0_gain_to_dac_volts(gain,
|
| 264 | 08dfff37 | Josh Blum | (_rx_gain_ranges["PGA0"].stop() - _rx_gain_ranges["PGA0"].start())); |
| 265 | 00b33d97 | Jason Abele | _rx_gains[name] = gain; |
| 266 | |||
| 267 | //write the new voltage to the aux dac
|
||
| 268 | 9d59ce56 | Josh Blum | this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, dboard_iface::AUX_DAC_A, dac_volts);
|
| 269 | fb000993 | Josh Blum | } |
| 270 | 33193a06 | Josh Blum | else UHD_THROW_INVALID_CODE_PATH();
|
| 271 | fb000993 | Josh Blum | } |
| 272 | f57f616c | Josh Blum | |
| 273 | fb000993 | Josh Blum | /***********************************************************************
|
| 274 | * Tuning
|
||
| 275 | **********************************************************************/
|
||
| 276 | void rfx_xcvr::set_rx_lo_freq(double freq){ |
||
| 277 | _rx_lo_freq = set_lo_freq(dboard_iface::UNIT_RX, freq); |
||
| 278 | } |
||
| 279 | |||
| 280 | void rfx_xcvr::set_tx_lo_freq(double freq){ |
||
| 281 | _tx_lo_freq = set_lo_freq(dboard_iface::UNIT_TX, freq); |
||
| 282 | 275b29e0 | Josh Blum | } |
| 283 | |||
| 284 | cbf7a091 | Josh Blum | double rfx_xcvr::set_lo_freq(
|
| 285 | dboard_iface::unit_t unit, |
||
| 286 | double target_freq
|
||
| 287 | ){
|
||
| 288 | 0718961e | Josh Blum | if (rfx_debug) std::cerr << boost::format(
|
| 289 | "RFX tune: target frequency %f Mhz"
|
||
| 290 | 067491b5 | Josh Blum | ) % (target_freq/1e6) << std::endl;
|
| 291 | 0718961e | Josh Blum | |
| 292 | cbf7a091 | Josh Blum | //clip the input
|
| 293 | 775383e6 | Josh Blum | target_freq = _freq_range.clip(target_freq); |
| 294 | 0718961e | Josh Blum | if (_div2[unit]) target_freq *= 2; |
| 295 | cbf7a091 | Josh Blum | |
| 296 | 0718961e | Josh Blum | //map prescalers to the register enums
|
| 297 | static const uhd::dict<int, adf4360_regs_t::prescaler_value_t> prescaler_to_enum = map_list_of |
||
| 298 | (8, adf4360_regs_t::PRESCALER_VALUE_8_9)
|
||
| 299 | (16, adf4360_regs_t::PRESCALER_VALUE_16_17)
|
||
| 300 | (32, adf4360_regs_t::PRESCALER_VALUE_32_33)
|
||
| 301 | ; |
||
| 302 | cbf7a091 | Josh Blum | |
| 303 | 067491b5 | Josh Blum | //map band select clock dividers to enums
|
| 304 | static const uhd::dict<int, adf4360_regs_t::band_select_clock_div_t> bandsel_to_enum = map_list_of |
||
| 305 | (1, adf4360_regs_t::BAND_SELECT_CLOCK_DIV_1)
|
||
| 306 | (2, adf4360_regs_t::BAND_SELECT_CLOCK_DIV_2)
|
||
| 307 | (4, adf4360_regs_t::BAND_SELECT_CLOCK_DIV_4)
|
||
| 308 | (8, adf4360_regs_t::BAND_SELECT_CLOCK_DIV_8)
|
||
| 309 | ; |
||
| 310 | cbf7a091 | Josh Blum | |
| 311 | 5aac700b | Josh Blum | double actual_freq=0, ref_freq = this->get_iface()->get_clock_rate(unit); |
| 312 | int R=0, BS=0, P=0, B=0, A=0; |
||
| 313 | 067491b5 | Josh Blum | |
| 314 | /*
|
||
| 315 | * The goal here to to loop though possible R dividers,
|
||
| 316 | * band select clock dividers, and prescaler values.
|
||
| 317 | * Calculate the A and B counters for each set of values.
|
||
| 318 | * The loop exists when it meets all of the constraints.
|
||
| 319 | * The resulting loop values are loaded into the registers.
|
||
| 320 | *
|
||
| 321 | * fvco = [P*B + A] * fref/R
|
||
| 322 | * fvco*R/fref = P*B + A = N
|
||
| 323 | */
|
||
| 324 | for(R = 2; R <= 32; R+=2){ |
||
| 325 | BOOST_FOREACH(BS, bandsel_to_enum.keys()){
|
||
| 326 | if (ref_freq/R/BS > 1e6) continue; //constraint on band select clock |
||
| 327 | BOOST_FOREACH(P, prescaler_to_enum.keys()){
|
||
| 328 | //calculate B and A from N
|
||
| 329 | double N = target_freq*R/ref_freq;
|
||
| 330 | B = int(std::floor(N/P));
|
||
| 331 | A = boost::math::iround(N - P*B); |
||
| 332 | if (B < A or B > 8191 or B < 3 or A > 31) continue; //constraints on A, B |
||
| 333 | //calculate the actual frequency
|
||
| 334 | actual_freq = double(P*B + A)*ref_freq/R;
|
||
| 335 | if (actual_freq/P > 300e6) continue; //constraint on prescaler output |
||
| 336 | //constraints met: exit loop
|
||
| 337 | goto done_loop;
|
||
| 338 | } |
||
| 339 | } |
||
| 340 | } done_loop:
|
||
| 341 | |||
| 342 | if (rfx_debug) std::cerr << boost::format(
|
||
| 343 | "RFX tune: R=%d, BS=%d, P=%d, B=%d, A=%d"
|
||
| 344 | ) % R % BS % P % B % A << std::endl; |
||
| 345 | cbf7a091 | Josh Blum | |
| 346 | 0718961e | Josh Blum | //load the register values
|
| 347 | adf4360_regs_t regs; |
||
| 348 | regs.core_power_level = adf4360_regs_t::CORE_POWER_LEVEL_10MA; |
||
| 349 | regs.counter_operation = adf4360_regs_t::COUNTER_OPERATION_NORMAL; |
||
| 350 | regs.muxout_control = adf4360_regs_t::MUXOUT_CONTROL_DLD; |
||
| 351 | regs.phase_detector_polarity = adf4360_regs_t::PHASE_DETECTOR_POLARITY_POS; |
||
| 352 | regs.charge_pump_output = adf4360_regs_t::CHARGE_PUMP_OUTPUT_NORMAL; |
||
| 353 | regs.cp_gain_0 = adf4360_regs_t::CP_GAIN_0_SET1; |
||
| 354 | regs.mute_till_ld = adf4360_regs_t::MUTE_TILL_LD_ENB; |
||
| 355 | regs.output_power_level = adf4360_regs_t::OUTPUT_POWER_LEVEL_3_5MA; |
||
| 356 | regs.current_setting1 = adf4360_regs_t::CURRENT_SETTING1_0_31MA; |
||
| 357 | regs.current_setting2 = adf4360_regs_t::CURRENT_SETTING2_0_31MA; |
||
| 358 | regs.power_down = adf4360_regs_t::POWER_DOWN_NORMAL_OP; |
||
| 359 | regs.prescaler_value = prescaler_to_enum[P]; |
||
| 360 | regs.a_counter = A; |
||
| 361 | regs.b_counter = B; |
||
| 362 | regs.cp_gain_1 = adf4360_regs_t::CP_GAIN_1_SET1; |
||
| 363 | 7d00269f | Jason Abele | regs.divide_by_2_output = (_div2[unit] && (get_rx_id() != 0x0024)) ? // Special case RFX400 RX Mixer divides by two |
| 364 | 0718961e | Josh Blum | adf4360_regs_t::DIVIDE_BY_2_OUTPUT_DIV2 : |
| 365 | adf4360_regs_t::DIVIDE_BY_2_OUTPUT_FUND ; |
||
| 366 | regs.divide_by_2_prescaler = adf4360_regs_t::DIVIDE_BY_2_PRESCALER_FUND; |
||
| 367 | regs.r_counter = R; |
||
| 368 | regs.ablpw = adf4360_regs_t::ABLPW_3_0NS; |
||
| 369 | regs.lock_detect_precision = adf4360_regs_t::LOCK_DETECT_PRECISION_5CYCLES; |
||
| 370 | regs.test_mode_bit = 0;
|
||
| 371 | 067491b5 | Josh Blum | regs.band_select_clock_div = bandsel_to_enum[BS]; |
| 372 | cbf7a091 | Josh Blum | |
| 373 | //write the registers
|
||
| 374 | 0718961e | Josh Blum | std::vector<adf4360_regs_t::addr_t> addrs = list_of //correct power-up sequence to write registers (R, C, N)
|
| 375 | (adf4360_regs_t::ADDR_RCOUNTER) |
||
| 376 | e6151334 | Josh Blum | (adf4360_regs_t::ADDR_CONTROL) |
| 377 | (adf4360_regs_t::ADDR_NCOUNTER) |
||
| 378 | ; |
||
| 379 | BOOST_FOREACH(adf4360_regs_t::addr_t addr, addrs){
|
||
| 380 | e2a94193 | Josh Blum | this->get_iface()->write_spi(
|
| 381 | cbf7a091 | Josh Blum | unit, spi_config_t::EDGE_RISE, |
| 382 | regs.get_reg(addr), 24
|
||
| 383 | b66a74ff | Josh Blum | ); |
| 384 | e6151334 | Josh Blum | } |
| 385 | cbf7a091 | Josh Blum | |
| 386 | //return the actual frequency
|
||
| 387 | 0718961e | Josh Blum | if (_div2[unit]) actual_freq /= 2; |
| 388 | if (rfx_debug) std::cerr << boost::format(
|
||
| 389 | "RFX tune: actual frequency %f Mhz"
|
||
| 390 | 067491b5 | Josh Blum | ) % (actual_freq/1e6) << std::endl;
|
| 391 | 0718961e | Josh Blum | return actual_freq;
|
| 392 | e6151334 | Josh Blum | } |
| 393 | |||
| 394 | 275b29e0 | Josh Blum | /***********************************************************************
|
| 395 | * RX Get and Set
|
||
| 396 | **********************************************************************/
|
||
| 397 | void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ |
||
| 398 | 98ba0cc0 | Josh Blum | named_prop_t key = named_prop_t::extract(key_); |
| 399 | 275b29e0 | Josh Blum | |
| 400 | //handle the get request conditioned on the key
|
||
| 401 | switch(key.as<subdev_prop_t>()){
|
||
| 402 | case SUBDEV_PROP_NAME:
|
||
| 403 | 4d5df237 | Josh Blum | val = get_rx_id().to_pp_string(); |
| 404 | 275b29e0 | Josh Blum | return;
|
| 405 | |||
| 406 | case SUBDEV_PROP_OTHERS:
|
||
| 407 | val = prop_names_t(); //empty
|
||
| 408 | return;
|
||
| 409 | |||
| 410 | case SUBDEV_PROP_GAIN:
|
||
| 411 | 98ba0cc0 | Josh Blum | assert_has(_rx_gains.keys(), key.name, "rfx rx gain name");
|
| 412 | val = _rx_gains[key.name]; |
||
| 413 | 275b29e0 | Josh Blum | return;
|
| 414 | |||
| 415 | case SUBDEV_PROP_GAIN_RANGE:
|
||
| 416 | 98ba0cc0 | Josh Blum | assert_has(_rx_gain_ranges.keys(), key.name, "rfx rx gain name");
|
| 417 | val = _rx_gain_ranges[key.name]; |
||
| 418 | 275b29e0 | Josh Blum | return;
|
| 419 | |||
| 420 | case SUBDEV_PROP_GAIN_NAMES:
|
||
| 421 | 4220097f | Jason Abele | val = prop_names_t(_rx_gain_ranges.keys()); |
| 422 | 275b29e0 | Josh Blum | return;
|
| 423 | |||
| 424 | case SUBDEV_PROP_FREQ:
|
||
| 425 | cbf7a091 | Josh Blum | val = _rx_lo_freq; |
| 426 | 275b29e0 | Josh Blum | return;
|
| 427 | |||
| 428 | case SUBDEV_PROP_FREQ_RANGE:
|
||
| 429 | val = _freq_range; |
||
| 430 | return;
|
||
| 431 | |||
| 432 | case SUBDEV_PROP_ANTENNA:
|
||
| 433 | val = _rx_ant; |
||
| 434 | return;
|
||
| 435 | |||
| 436 | fb000993 | Josh Blum | case SUBDEV_PROP_ANTENNA_NAMES:
|
| 437 | val = rfx_rx_antennas; |
||
| 438 | 275b29e0 | Josh Blum | return;
|
| 439 | |||
| 440 | 9a9ca6df | Josh Blum | case SUBDEV_PROP_CONNECTION:
|
| 441 | val = SUBDEV_CONN_COMPLEX_QI; |
||
| 442 | 275b29e0 | Josh Blum | return;
|
| 443 | |||
| 444 | a4f8ad59 | Josh Blum | case SUBDEV_PROP_ENABLED:
|
| 445 | val = true; //always enabled |
||
| 446 | return;
|
||
| 447 | |||
| 448 | e6151334 | Josh Blum | case SUBDEV_PROP_USE_LO_OFFSET:
|
| 449 | 275b29e0 | Josh Blum | val = false;
|
| 450 | return;
|
||
| 451 | 61ec6711 | Josh Blum | |
| 452 | b1992806 | Josh Blum | case SUBDEV_PROP_LO_LOCKED:
|
| 453 | val = this->get_locked(dboard_iface::UNIT_RX);
|
||
| 454 | return;
|
||
| 455 | |||
| 456 | bb82453a | Jason Abele | case SUBDEV_PROP_BANDWIDTH:
|
| 457 | 6a3e499f | Jason Abele | val = 2*20.0e6; //20MHz low-pass, we want complex double-sided |
| 458 | bb82453a | Jason Abele | return;
|
| 459 | |||
| 460 | 6f1bdcb5 | Josh Blum | default: UHD_THROW_PROP_GET_ERROR();
|
| 461 | 275b29e0 | Josh Blum | } |
| 462 | } |
||
| 463 | |||
| 464 | void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ |
||
| 465 | 98ba0cc0 | Josh Blum | named_prop_t key = named_prop_t::extract(key_); |
| 466 | 275b29e0 | Josh Blum | |
| 467 | //handle the get request conditioned on the key
|
||
| 468 | switch(key.as<subdev_prop_t>()){
|
||
| 469 | |||
| 470 | cbf7a091 | Josh Blum | case SUBDEV_PROP_FREQ:
|
| 471 | fb000993 | Josh Blum | this->set_rx_lo_freq(val.as<double>()); |
| 472 | cbf7a091 | Josh Blum | return;
|
| 473 | |||
| 474 | 275b29e0 | Josh Blum | case SUBDEV_PROP_GAIN:
|
| 475 | 395bbbbc | Josh Blum | this->set_rx_gain(val.as<double>(), key.name); |
| 476 | 275b29e0 | Josh Blum | return;
|
| 477 | |||
| 478 | case SUBDEV_PROP_ANTENNA:
|
||
| 479 | fb000993 | Josh Blum | this->set_rx_ant(val.as<std::string>()); |
| 480 | 275b29e0 | Josh Blum | return;
|
| 481 | |||
| 482 | a4f8ad59 | Josh Blum | case SUBDEV_PROP_ENABLED:
|
| 483 | return; //always enabled |
||
| 484 | |||
| 485 | bb82453a | Jason Abele | case SUBDEV_PROP_BANDWIDTH:
|
| 486 | cea3d050 | Josh Blum | uhd::warning::post( |
| 487 | bb82453a | Jason Abele | str(boost::format("RFX: No tunable bandwidth, fixed filtered to 40MHz"))
|
| 488 | ); |
||
| 489 | return;
|
||
| 490 | |||
| 491 | 6f1bdcb5 | Josh Blum | default: UHD_THROW_PROP_SET_ERROR();
|
| 492 | 275b29e0 | Josh Blum | } |
| 493 | } |
||
| 494 | |||
| 495 | /***********************************************************************
|
||
| 496 | * TX Get and Set
|
||
| 497 | **********************************************************************/
|
||
| 498 | void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ |
||
| 499 | 98ba0cc0 | Josh Blum | named_prop_t key = named_prop_t::extract(key_); |
| 500 | 275b29e0 | Josh Blum | |
| 501 | //handle the get request conditioned on the key
|
||
| 502 | switch(key.as<subdev_prop_t>()){
|
||
| 503 | case SUBDEV_PROP_NAME:
|
||
| 504 | 4d5df237 | Josh Blum | val = get_tx_id().to_pp_string(); |
| 505 | 275b29e0 | Josh Blum | return;
|
| 506 | |||
| 507 | case SUBDEV_PROP_OTHERS:
|
||
| 508 | val = prop_names_t(); //empty
|
||
| 509 | return;
|
||
| 510 | |||
| 511 | case SUBDEV_PROP_GAIN:
|
||
| 512 | case SUBDEV_PROP_GAIN_RANGE:
|
||
| 513 | 98ba0cc0 | Josh Blum | assert_has(rfx_tx_gain_ranges.keys(), key.name, "rfx tx gain name");
|
| 514 | fb000993 | Josh Blum | //no controllable tx gains, will not get here
|
| 515 | 275b29e0 | Josh Blum | return;
|
| 516 | |||
| 517 | case SUBDEV_PROP_GAIN_NAMES:
|
||
| 518 | fb000993 | Josh Blum | val = prop_names_t(rfx_tx_gain_ranges.keys()); |
| 519 | 275b29e0 | Josh Blum | return;
|
| 520 | |||
| 521 | case SUBDEV_PROP_FREQ:
|
||
| 522 | cbf7a091 | Josh Blum | val = _tx_lo_freq; |
| 523 | 275b29e0 | Josh Blum | return;
|
| 524 | |||
| 525 | case SUBDEV_PROP_FREQ_RANGE:
|
||
| 526 | val = _freq_range; |
||
| 527 | return;
|
||
| 528 | |||
| 529 | case SUBDEV_PROP_ANTENNA:
|
||
| 530 | f57f616c | Josh Blum | val = std::string("TX/RX"); |
| 531 | 275b29e0 | Josh Blum | return;
|
| 532 | |||
| 533 | case SUBDEV_PROP_ANTENNA_NAMES:
|
||
| 534 | fb000993 | Josh Blum | val = rfx_tx_antennas; |
| 535 | 275b29e0 | Josh Blum | return;
|
| 536 | |||
| 537 | 9a9ca6df | Josh Blum | case SUBDEV_PROP_CONNECTION:
|
| 538 | val = SUBDEV_CONN_COMPLEX_IQ; |
||
| 539 | 275b29e0 | Josh Blum | return;
|
| 540 | |||
| 541 | a4f8ad59 | Josh Blum | case SUBDEV_PROP_ENABLED:
|
| 542 | val = true; //always enabled |
||
| 543 | return;
|
||
| 544 | |||
| 545 | e6151334 | Josh Blum | case SUBDEV_PROP_USE_LO_OFFSET:
|
| 546 | 275b29e0 | Josh Blum | val = true;
|
| 547 | return;
|
||
| 548 | 61ec6711 | Josh Blum | |
| 549 | b1992806 | Josh Blum | case SUBDEV_PROP_LO_LOCKED:
|
| 550 | val = this->get_locked(dboard_iface::UNIT_TX);
|
||
| 551 | return;
|
||
| 552 | |||
| 553 | bb82453a | Jason Abele | case SUBDEV_PROP_BANDWIDTH:
|
| 554 | 6a3e499f | Jason Abele | val = 2*20.0e6; //20MHz low-pass, we want complex double-sided |
| 555 | bb82453a | Jason Abele | return;
|
| 556 | |||
| 557 | 6f1bdcb5 | Josh Blum | default: UHD_THROW_PROP_GET_ERROR();
|
| 558 | 275b29e0 | Josh Blum | } |
| 559 | } |
||
| 560 | |||
| 561 | void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ |
||
| 562 | 98ba0cc0 | Josh Blum | named_prop_t key = named_prop_t::extract(key_); |
| 563 | 275b29e0 | Josh Blum | |
| 564 | //handle the get request conditioned on the key
|
||
| 565 | switch(key.as<subdev_prop_t>()){
|
||
| 566 | |||
| 567 | cbf7a091 | Josh Blum | case SUBDEV_PROP_FREQ:
|
| 568 | fb000993 | Josh Blum | this->set_tx_lo_freq(val.as<double>()); |
| 569 | cbf7a091 | Josh Blum | return;
|
| 570 | |||
| 571 | 275b29e0 | Josh Blum | case SUBDEV_PROP_GAIN:
|
| 572 | 395bbbbc | Josh Blum | this->set_tx_gain(val.as<double>(), key.name); |
| 573 | 275b29e0 | Josh Blum | return;
|
| 574 | |||
| 575 | case SUBDEV_PROP_ANTENNA:
|
||
| 576 | fb000993 | Josh Blum | this->set_tx_ant(val.as<std::string>()); |
| 577 | 275b29e0 | Josh Blum | return;
|
| 578 | |||
| 579 | a4f8ad59 | Josh Blum | case SUBDEV_PROP_ENABLED:
|
| 580 | return; //always enabled |
||
| 581 | |||
| 582 | bb82453a | Jason Abele | case SUBDEV_PROP_BANDWIDTH:
|
| 583 | cea3d050 | Josh Blum | uhd::warning::post( |
| 584 | bb82453a | Jason Abele | str(boost::format("RFX: No tunable bandwidth, fixed filtered to 40MHz"))
|
| 585 | ); |
||
| 586 | return;
|
||
| 587 | |||
| 588 | 6f1bdcb5 | Josh Blum | default: UHD_THROW_PROP_SET_ERROR();
|
| 589 | 275b29e0 | Josh Blum | } |
| 590 | } |