Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / codec_impl.cpp @ 9cb9e7d5

History | View | Annotate | Download (4.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 <uhd/usrp/codec_props.hpp>
20
#include <boost/bind.hpp>
21

    
22
using namespace uhd;
23
using namespace uhd::usrp;
24

    
25
/***********************************************************************
26
 * Helper Methods
27
 **********************************************************************/
28
void usrp1_impl::codec_init(void)
29
{
30
    //make proxies
31
    _rx_codec_proxy = wax_obj_proxy::make(
32
                          boost::bind(&usrp1_impl::rx_codec_get, this, _1, _2),
33
                          boost::bind(&usrp1_impl::rx_codec_set, this, _1, _2));
34

    
35
    _tx_codec_proxy = wax_obj_proxy::make(
36
                          boost::bind(&usrp1_impl::tx_codec_get, this, _1, _2),
37
                          boost::bind(&usrp1_impl::tx_codec_set, this, _1, _2));
38
}    
39

    
40
/***********************************************************************
41
 * RX Codec Properties
42
 **********************************************************************/
43
static const std::string ad9862_pga_gain_name = "ad9862 pga";
44

    
45
void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val)
46
{
47
    wax::obj key; std::string name;
48
    boost::tie(key, name) = extract_named_prop(key_);
49

    
50
    //handle the get request conditioned on the key
51
    switch(key.as<codec_prop_t>()) {
52
    case CODEC_PROP_NAME:
53
        val = std::string("usrp1 adc - ad9862");
54
        return;
55

    
56
    case CODEC_PROP_OTHERS:
57
        val = prop_names_t();
58
        return;
59

    
60
    case CODEC_PROP_GAIN_NAMES:
61
        val = prop_names_t(1, ad9862_pga_gain_name);
62
        return;
63

    
64
    case CODEC_PROP_GAIN_RANGE:
65
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
66
        val = usrp1_codec_ctrl::rx_pga_gain_range;
67
        return;
68

    
69
    case CODEC_PROP_GAIN_I:
70
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
71
        val = _codec_ctrl->get_rx_pga_gain('A');
72
        return;
73

    
74
    case CODEC_PROP_GAIN_Q:
75
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
76
        val = _codec_ctrl->get_rx_pga_gain('B');
77
        return;
78

    
79
    default: UHD_THROW_PROP_GET_ERROR();
80
    }
81
}
82

    
83
void usrp1_impl::rx_codec_set(const wax::obj &, const wax::obj &)
84
{
85
    wax::obj key; std::string name;
86
    boost::tie(key, name) = extract_named_prop(key_);
87

    
88
    //handle the set request conditioned on the key
89
    switch(key.as<codec_prop_t>()) {
90
    case CODEC_PROP_GAIN_I:
91
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
92
        _codec_ctrl->set_rx_pga_gain(val.as<float>(), 'A');
93
        return;
94

    
95
    case CODEC_PROP_GAIN_Q:
96
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
97
        _codec_ctrl->set_rx_pga_gain(val.as<float>(), 'B');
98
        return;
99

    
100
    default: UHD_THROW_PROP_SET_ERROR();
101
    }
102
}
103

    
104
/***********************************************************************
105
 * TX Codec Properties
106
 **********************************************************************/
107
void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val)
108
{
109
    wax::obj key; std::string name;
110
    boost::tie(key, name) = extract_named_prop(key_);
111

    
112
    //handle the get request conditioned on the key
113
    switch(key.as<codec_prop_t>()) {
114
    case CODEC_PROP_NAME:
115
        val = std::string("usrp1 dac - ad9862");
116
        return;
117

    
118
    case CODEC_PROP_OTHERS:
119
        val = prop_names_t();
120
        return;
121

    
122
    case CODEC_PROP_GAIN_NAMES:
123
        val = prop_names_t(1, ad9862_pga_gain_name);
124
        return;
125

    
126
    case CODEC_PROP_GAIN_RANGE:
127
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
128
        val = usrp1_codec_ctrl::tx_pga_gain_range;
129
        return;
130

    
131
    case CODEC_PROP_GAIN_I: //only one gain for I and Q
132
    case CODEC_PROP_GAIN_Q:
133
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
134
        val = _codec_ctrl->get_tx_pga_gain();
135
        return;
136

    
137
    default: UHD_THROW_PROP_GET_ERROR();
138
    }
139
}
140

    
141
void usrp1_impl::tx_codec_set(const wax::obj &, const wax::obj &)
142
{
143
    wax::obj key; std::string name;
144
    boost::tie(key, name) = extract_named_prop(key_);
145

    
146
    //handle the set request conditioned on the key
147
    switch(key.as<codec_prop_t>()){
148
    case CODEC_PROP_GAIN_I: //only one gain for I and Q
149
    case CODEC_PROP_GAIN_Q:
150
        UHD_ASSERT_THROW(name == ad9862_pga_gain_name);
151
        _codec_ctrl->set_tx_pga_gain(val.as<float>());
152
        return;
153

    
154
    default: UHD_THROW_PROP_SET_ERROR();
155
    }
156
}