root / host / lib / usrp / usrp1 / clock_ctrl.cpp @ 3f4e998b
History | View | Annotate | Download (3.9 kB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 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 |
#include "clock_ctrl.hpp" |
| 19 |
#include "fpga_regs_standard.h" |
| 20 |
#include <uhd/utils/assert.hpp> |
| 21 |
#include <boost/cstdint.hpp> |
| 22 |
#include <boost/assign/list_of.hpp> |
| 23 |
#include <boost/foreach.hpp> |
| 24 |
#include <utility> |
| 25 |
#include <iostream> |
| 26 |
|
| 27 |
using namespace uhd; |
| 28 |
|
| 29 |
/***********************************************************************
|
| 30 |
* Constants
|
| 31 |
**********************************************************************/
|
| 32 |
static const double master_clock_rate = 64e6; |
| 33 |
|
| 34 |
/***********************************************************************
|
| 35 |
* Clock Control Implementation
|
| 36 |
**********************************************************************/
|
| 37 |
class usrp1_clock_ctrl_impl : public usrp1_clock_ctrl { |
| 38 |
public:
|
| 39 |
usrp1_clock_ctrl_impl(usrp1_iface::sptr iface) |
| 40 |
{
|
| 41 |
_iface = iface; |
| 42 |
} |
| 43 |
|
| 44 |
double get_master_clock_freq(void) |
| 45 |
{
|
| 46 |
return master_clock_rate;
|
| 47 |
} |
| 48 |
|
| 49 |
/***********************************************************************
|
| 50 |
* RX Dboard Clock Control (output 9, divider 3)
|
| 51 |
**********************************************************************/
|
| 52 |
void enable_rx_dboard_clock(bool) |
| 53 |
{
|
| 54 |
std::cerr << "USRP: enable_rx_dboard_clock() disabled" << std::endl;
|
| 55 |
_iface->poke32(FR_RX_A_REFCLK, 0);
|
| 56 |
_iface->poke32(FR_RX_B_REFCLK, 0);
|
| 57 |
} |
| 58 |
|
| 59 |
std::vector<double> get_rx_dboard_clock_rates(void) |
| 60 |
{
|
| 61 |
#if 0
|
| 62 |
std::vector<double> rates;
|
| 63 |
for (size_t div = 1; div <= 127; div++)
|
| 64 |
rates.push_back(master_clock_rate / div);
|
| 65 |
return rates;
|
| 66 |
#else
|
| 67 |
return std::vector<double>(1, master_clock_rate); |
| 68 |
#endif
|
| 69 |
} |
| 70 |
|
| 71 |
/*
|
| 72 |
* Daughterboard reference clock register
|
| 73 |
*
|
| 74 |
* Bit 7 - 1 turns on refclk, 0 allows IO use
|
| 75 |
* Bits 6:0 - Divider value
|
| 76 |
*/
|
| 77 |
void set_rx_dboard_clock_rate(double) |
| 78 |
{
|
| 79 |
#if 0
|
| 80 |
assert_has(get_rx_dboard_clock_rates(), rate, "rx dboard clock rate");
|
| 81 |
size_t divider = size_t(rate/master_clock_rate);
|
| 82 |
_iface->poke32(FR_RX_A_REFCLK, (divider & 0x7f) | 0x80);
|
| 83 |
#else
|
| 84 |
std::cerr << "USRP: set_rx_dboard_clock_rate() disabled" << std::endl;
|
| 85 |
_iface->poke32(FR_RX_A_REFCLK, 0);
|
| 86 |
_iface->poke32(FR_RX_B_REFCLK, 0);
|
| 87 |
#endif
|
| 88 |
} |
| 89 |
|
| 90 |
/***********************************************************************
|
| 91 |
* TX Dboard Clock Control
|
| 92 |
**********************************************************************/
|
| 93 |
void enable_tx_dboard_clock(bool) |
| 94 |
{
|
| 95 |
std::cerr << "USRP: set_tx_dboard_clock() disabled" << std::endl;
|
| 96 |
_iface->poke32(FR_TX_A_REFCLK, 0);
|
| 97 |
_iface->poke32(FR_TX_B_REFCLK, 0);
|
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
std::vector<double> get_tx_dboard_clock_rates(void) |
| 102 |
{
|
| 103 |
return get_rx_dboard_clock_rates(); //same master clock, same dividers... |
| 104 |
} |
| 105 |
|
| 106 |
void set_tx_dboard_clock_rate(double) |
| 107 |
{
|
| 108 |
std::cerr << "USRP: set_tx_dboard_clock_rate() disabled" << std::endl;
|
| 109 |
_iface->poke32(FR_TX_A_REFCLK, 0);
|
| 110 |
_iface->poke32(FR_TX_B_REFCLK, 0);
|
| 111 |
} |
| 112 |
|
| 113 |
private:
|
| 114 |
usrp1_iface::sptr _iface; |
| 115 |
|
| 116 |
}; |
| 117 |
|
| 118 |
/***********************************************************************
|
| 119 |
* Clock Control Make
|
| 120 |
**********************************************************************/
|
| 121 |
usrp1_clock_ctrl::sptr usrp1_clock_ctrl::make(usrp1_iface::sptr iface) |
| 122 |
{
|
| 123 |
return sptr(new usrp1_clock_ctrl_impl(iface)); |
| 124 |
} |