root / host / lib / usrp / usrp1 / dsp_impl.cpp @ 273a1048
History | View | Annotate | Download (6.1 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 "usrp1_impl.hpp" |
| 19 |
#include "fpga_regs_standard.h" |
| 20 |
#include <uhd/usrp/dsp_utils.hpp> |
| 21 |
#include <uhd/usrp/dsp_props.hpp> |
| 22 |
#include <boost/bind.hpp> |
| 23 |
#include <boost/format.hpp> |
| 24 |
#include <iostream> |
| 25 |
#include <cmath> |
| 26 |
|
| 27 |
using namespace uhd; |
| 28 |
using namespace uhd::usrp; |
| 29 |
|
| 30 |
/***********************************************************************
|
| 31 |
* RX DDC Initialization
|
| 32 |
**********************************************************************/
|
| 33 |
void usrp1_impl::rx_dsp_init(void) |
| 34 |
{
|
| 35 |
_rx_dsp_proxy = wax_obj_proxy::make( |
| 36 |
boost::bind(&usrp1_impl::rx_dsp_get, this, _1, _2),
|
| 37 |
boost::bind(&usrp1_impl::rx_dsp_set, this, _1, _2));
|
| 38 |
|
| 39 |
rx_dsp_set(DSP_PROP_HOST_RATE, _clock_ctrl->get_master_clock_freq() / 16);
|
| 40 |
} |
| 41 |
|
| 42 |
/***********************************************************************
|
| 43 |
* RX DDC Get
|
| 44 |
**********************************************************************/
|
| 45 |
void usrp1_impl::rx_dsp_get(const wax::obj &key, wax::obj &val) |
| 46 |
{
|
| 47 |
switch(key.as<dsp_prop_t>()){
|
| 48 |
case DSP_PROP_NAME:
|
| 49 |
val = std::string("usrp1 ddc0"); |
| 50 |
return;
|
| 51 |
|
| 52 |
case DSP_PROP_OTHERS:
|
| 53 |
val = prop_names_t(); |
| 54 |
return;
|
| 55 |
|
| 56 |
case DSP_PROP_FREQ_SHIFT:
|
| 57 |
val = _rx_dsp_freq; |
| 58 |
return;
|
| 59 |
|
| 60 |
case DSP_PROP_CODEC_RATE:
|
| 61 |
val = _clock_ctrl->get_master_clock_freq(); |
| 62 |
return;
|
| 63 |
|
| 64 |
case DSP_PROP_HOST_RATE:
|
| 65 |
val = _clock_ctrl->get_master_clock_freq()/_rx_dsp_decim; |
| 66 |
return;
|
| 67 |
|
| 68 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
/***********************************************************************
|
| 74 |
* RX DDC Set
|
| 75 |
**********************************************************************/
|
| 76 |
void usrp1_impl::rx_dsp_set(const wax::obj &key, const wax::obj &val) |
| 77 |
{
|
| 78 |
switch(key.as<dsp_prop_t>()) {
|
| 79 |
case DSP_PROP_FREQ_SHIFT: {
|
| 80 |
double new_freq = val.as<double>(); |
| 81 |
_iface->poke32(FR_RX_FREQ_0, |
| 82 |
-dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_master_clock_freq())); |
| 83 |
_tx_dsp_freq = new_freq; |
| 84 |
return;
|
| 85 |
} |
| 86 |
case DSP_PROP_HOST_RATE: {
|
| 87 |
//FIXME: Stop and resume streaming during set?
|
| 88 |
unsigned int rate = |
| 89 |
_clock_ctrl->get_master_clock_freq() / val.as<double>();
|
| 90 |
|
| 91 |
if ((rate & 0x01) || (rate < 4) || (rate > 256)) { |
| 92 |
std::cerr << "Decimation must be even and between 4 and 256"
|
| 93 |
<< std::endl; |
| 94 |
return;
|
| 95 |
} |
| 96 |
|
| 97 |
_rx_dsp_decim = rate; |
| 98 |
//TODO Poll every 100ms. Make it selectable?
|
| 99 |
_rx_samps_per_poll_interval = 0.1 * _clock_ctrl->get_master_clock_freq() / rate; |
| 100 |
|
| 101 |
_iface->poke32(FR_DECIM_RATE, _rx_dsp_decim/2 - 1); |
| 102 |
} |
| 103 |
return;
|
| 104 |
|
| 105 |
default: UHD_THROW_PROP_SET_ERROR();
|
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
/***********************************************************************
|
| 111 |
* TX DUC Initialization
|
| 112 |
**********************************************************************/
|
| 113 |
void usrp1_impl::tx_dsp_init(void) |
| 114 |
{
|
| 115 |
_tx_dsp_proxy = wax_obj_proxy::make( |
| 116 |
boost::bind(&usrp1_impl::tx_dsp_get, this, _1, _2),
|
| 117 |
boost::bind(&usrp1_impl::tx_dsp_set, this, _1, _2));
|
| 118 |
|
| 119 |
//initial config and update
|
| 120 |
tx_dsp_set(DSP_PROP_HOST_RATE, _clock_ctrl->get_master_clock_freq() * 2 / 16); |
| 121 |
} |
| 122 |
|
| 123 |
/***********************************************************************
|
| 124 |
* TX DUC Get
|
| 125 |
**********************************************************************/
|
| 126 |
void usrp1_impl::tx_dsp_get(const wax::obj &key, wax::obj &val) |
| 127 |
{
|
| 128 |
switch(key.as<dsp_prop_t>()) {
|
| 129 |
case DSP_PROP_NAME:
|
| 130 |
val = std::string("usrp1 duc0"); |
| 131 |
return;
|
| 132 |
|
| 133 |
case DSP_PROP_OTHERS:
|
| 134 |
val = prop_names_t(); //empty
|
| 135 |
return;
|
| 136 |
|
| 137 |
case DSP_PROP_FREQ_SHIFT:
|
| 138 |
val = _tx_dsp_freq; |
| 139 |
return;
|
| 140 |
|
| 141 |
case DSP_PROP_CODEC_RATE:
|
| 142 |
val = _clock_ctrl->get_master_clock_freq() * 2;
|
| 143 |
return;
|
| 144 |
|
| 145 |
case DSP_PROP_HOST_RATE:
|
| 146 |
val = _clock_ctrl->get_master_clock_freq() * 2 / _tx_dsp_interp;
|
| 147 |
return;
|
| 148 |
|
| 149 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 150 |
} |
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
/***********************************************************************
|
| 155 |
* TX DUC Set
|
| 156 |
**********************************************************************/
|
| 157 |
void usrp1_impl::tx_dsp_set(const wax::obj &key, const wax::obj &val) |
| 158 |
{
|
| 159 |
switch(key.as<dsp_prop_t>()) {
|
| 160 |
|
| 161 |
//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
|
| 162 |
//
|
| 163 |
// Set both codec frequencies until we have duality properties
|
| 164 |
//
|
| 165 |
//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
|
| 166 |
case DSP_PROP_FREQ_SHIFT: {
|
| 167 |
double new_freq = val.as<double>(); |
| 168 |
_codec_ctrls[DBOARD_SLOT_A]->set_duc_freq(new_freq); |
| 169 |
_codec_ctrls[DBOARD_SLOT_B]->set_duc_freq(new_freq); |
| 170 |
_tx_dsp_freq = new_freq; |
| 171 |
return;
|
| 172 |
} |
| 173 |
|
| 174 |
case DSP_PROP_HOST_RATE: {
|
| 175 |
unsigned int rate = |
| 176 |
_clock_ctrl->get_master_clock_freq() * 2 / val.as<double>(); |
| 177 |
|
| 178 |
if ((rate & 0x01) || (rate < 8) || (rate > 512)) { |
| 179 |
std::cerr << "Interpolation rate must be even and between 8 and 512"
|
| 180 |
<< std::endl; |
| 181 |
return;
|
| 182 |
} |
| 183 |
|
| 184 |
_tx_dsp_interp = rate; |
| 185 |
|
| 186 |
//TODO Poll every 100ms. Make it selectable?
|
| 187 |
_tx_samps_per_poll_interval = 0.1 * _clock_ctrl->get_master_clock_freq() * 2 / rate; |
| 188 |
|
| 189 |
_iface->poke32(FR_INTERP_RATE, _tx_dsp_interp / 4 - 1); |
| 190 |
return;
|
| 191 |
} |
| 192 |
default: UHD_THROW_PROP_SET_ERROR();
|
| 193 |
} |
| 194 |
|
| 195 |
} |