Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / dsp_impl.cpp @ 40217798

History | View | Annotate | Download (5.8 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
            _rx_samps_per_poll_interval = 0.1 * _clock_ctrl->get_master_clock_freq() / rate;
99

    
100
            _iface->poke32(FR_DECIM_RATE, _rx_dsp_decim/2 - 1);
101
        }
102
        return;
103

    
104
    default: UHD_THROW_PROP_SET_ERROR();
105
    }
106

    
107
}
108

    
109
/***********************************************************************
110
 * TX DUC Initialization
111
 **********************************************************************/
112
void usrp1_impl::tx_dsp_init(void)
113
{
114
    _tx_dsp_proxy = wax_obj_proxy::make(
115
                          boost::bind(&usrp1_impl::tx_dsp_get, this, _1, _2),
116
                          boost::bind(&usrp1_impl::tx_dsp_set, this, _1, _2));
117

    
118
    //initial config and update
119
    tx_dsp_set(DSP_PROP_HOST_RATE, _clock_ctrl->get_master_clock_freq() * 2 / 16);
120
}
121

    
122
/***********************************************************************
123
 * TX DUC Get
124
 **********************************************************************/
125
void usrp1_impl::tx_dsp_get(const wax::obj &key, wax::obj &val)
126
{
127
    switch(key.as<dsp_prop_t>()) {
128
    case DSP_PROP_NAME:
129
        val = std::string("usrp1 duc0");
130
        return;
131

    
132
    case DSP_PROP_OTHERS:
133
        val = prop_names_t(); //empty
134
        return;
135

    
136
    case DSP_PROP_FREQ_SHIFT:
137
        val = _tx_dsp_freq;
138
        return;
139

    
140
    case DSP_PROP_CODEC_RATE:
141
        val = _clock_ctrl->get_master_clock_freq() * 2;
142
        return;
143

    
144
    case DSP_PROP_HOST_RATE:
145
        val = _clock_ctrl->get_master_clock_freq() * 2 / _tx_dsp_interp;
146
        return;
147

    
148
    default: UHD_THROW_PROP_GET_ERROR();
149
    }
150

    
151
}
152

    
153
/***********************************************************************
154
 * TX DUC Set
155
 **********************************************************************/
156
void usrp1_impl::tx_dsp_set(const wax::obj &key, const wax::obj &val)
157
{
158
    switch(key.as<dsp_prop_t>()) {
159

    
160
    // TODO: Set both codec frequencies until we have duality properties 
161
    case DSP_PROP_FREQ_SHIFT: {
162
            double new_freq = val.as<double>();
163
            _codec_ctrls[DBOARD_SLOT_A]->set_duc_freq(new_freq);
164
            _codec_ctrls[DBOARD_SLOT_B]->set_duc_freq(new_freq);
165
            _tx_dsp_freq = new_freq;
166
            return;
167
        }
168

    
169
    case DSP_PROP_HOST_RATE: {
170
            unsigned int rate =
171
                    _clock_ctrl->get_master_clock_freq() * 2 / val.as<double>();
172

    
173
            if ((rate & 0x01) || (rate < 8) || (rate > 512)) {
174
                std::cerr << "Interpolation rate must be even and between 8 and 512"
175
                          << std::endl;
176
                return;
177
            }
178

    
179
            _tx_dsp_interp = rate;
180
            _tx_samps_per_poll_interval = 0.1 * _clock_ctrl->get_master_clock_freq() * 2 / rate;
181

    
182
            _iface->poke32(FR_INTERP_RATE, _tx_dsp_interp / 4 - 1);
183
            return;
184
        }
185
    default: UHD_THROW_PROP_SET_ERROR();
186
    }
187

    
188
}