Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / codec_impl.cpp @ 16f08844

History | View | Annotate | Download (5.2 KB)

1
//
2
// Copyright 2010-2011 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/exception.hpp>
20
#include <uhd/usrp/codec_props.hpp>
21
#include <boost/bind.hpp>
22
#include <boost/foreach.hpp>
23
#include <boost/format.hpp>
24

    
25
using namespace uhd;
26
using namespace uhd::usrp;
27

    
28
/***********************************************************************
29
 * Helper Methods
30
 **********************************************************************/
31
void usrp1_impl::codec_init(void)
32
{
33
    //make proxies
34
    BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){
35
        _rx_codec_proxies[dboard_slot] = wax_obj_proxy::make(
36
              boost::bind(&usrp1_impl::rx_codec_get, this, _1, _2, dboard_slot),
37
              boost::bind(&usrp1_impl::rx_codec_set, this, _1, _2, dboard_slot));
38

    
39
        _tx_codec_proxies[dboard_slot] = wax_obj_proxy::make(
40
              boost::bind(&usrp1_impl::tx_codec_get, this, _1, _2, dboard_slot),
41
              boost::bind(&usrp1_impl::tx_codec_set, this, _1, _2, dboard_slot));
42
    }
43
}    
44

    
45
/***********************************************************************
46
 * RX Codec Properties
47
 **********************************************************************/
48
static const std::string adc_pga_gain_name = "PGA";
49

    
50
void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot)
51
{
52
    named_prop_t key = named_prop_t::extract(key_);
53

    
54
    //handle the get request conditioned on the key
55
    switch(key.as<codec_prop_t>()) {
56
    case CODEC_PROP_NAME:
57
        val = str(boost::format("usrp1 adc - ad9862 - slot %c") % char(dboard_slot));
58
        return;
59

    
60
    case CODEC_PROP_OTHERS:
61
        val = prop_names_t();
62
        return;
63

    
64
    case CODEC_PROP_GAIN_NAMES:
65
        val = prop_names_t(1, adc_pga_gain_name);
66
        return;
67

    
68
    case CODEC_PROP_GAIN_RANGE:
69
        UHD_ASSERT_THROW(key.name == adc_pga_gain_name);
70
        val = usrp1_codec_ctrl::rx_pga_gain_range;
71
        return;
72

    
73
    case CODEC_PROP_GAIN_I:
74
        UHD_ASSERT_THROW(key.name == adc_pga_gain_name);
75
        val = _codec_ctrls[dboard_slot]->get_rx_pga_gain('A');
76
        return;
77

    
78
    case CODEC_PROP_GAIN_Q:
79
        UHD_ASSERT_THROW(key.name == adc_pga_gain_name);
80
        val = _codec_ctrls[dboard_slot]->get_rx_pga_gain('B');
81
        return;
82

    
83
    default: UHD_THROW_PROP_GET_ERROR();
84
    }
85
}
86

    
87
void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val, dboard_slot_t dboard_slot)
88
{
89
    named_prop_t key = named_prop_t::extract(key_);
90

    
91
    //handle the set request conditioned on the key
92
    switch(key.as<codec_prop_t>()) {
93
    case CODEC_PROP_GAIN_I:
94
        UHD_ASSERT_THROW(key.name == adc_pga_gain_name);
95
        _codec_ctrls[dboard_slot]->set_rx_pga_gain(val.as<double>(), 'A');
96
        return;
97

    
98
    case CODEC_PROP_GAIN_Q:
99
        UHD_ASSERT_THROW(key.name == adc_pga_gain_name);
100
        _codec_ctrls[dboard_slot]->set_rx_pga_gain(val.as<double>(), 'B');
101
        return;
102

    
103
    default: UHD_THROW_PROP_SET_ERROR();
104
    }
105
}
106

    
107
/***********************************************************************
108
 * TX Codec Properties
109
 **********************************************************************/
110
static const std::string dac_pga_gain_name = "PGA";
111

    
112
void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot)
113
{
114
    named_prop_t key = named_prop_t::extract(key_);
115

    
116
    //handle the get request conditioned on the key
117
    switch(key.as<codec_prop_t>()) {
118
    case CODEC_PROP_NAME:
119
        val = str(boost::format("usrp1 dac - ad9862 - slot %c") % char(dboard_slot));
120
        return;
121

    
122
    case CODEC_PROP_OTHERS:
123
        val = prop_names_t();
124
        return;
125

    
126
    case CODEC_PROP_GAIN_NAMES:
127
        val = prop_names_t(1, dac_pga_gain_name);
128
        return;
129

    
130
    case CODEC_PROP_GAIN_RANGE:
131
        UHD_ASSERT_THROW(key.name == dac_pga_gain_name);
132
        val = usrp1_codec_ctrl::tx_pga_gain_range;
133
        return;
134

    
135
    case CODEC_PROP_GAIN_I: //only one gain for I and Q
136
    case CODEC_PROP_GAIN_Q:
137
        UHD_ASSERT_THROW(key.name == dac_pga_gain_name);
138
        val = _codec_ctrls[dboard_slot]->get_tx_pga_gain();
139
        return;
140

    
141
    default: UHD_THROW_PROP_GET_ERROR();
142
    }
143
}
144

    
145
void usrp1_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val, dboard_slot_t dboard_slot)
146
{
147
    named_prop_t key = named_prop_t::extract(key_);
148

    
149
    //handle the set request conditioned on the key
150
    switch(key.as<codec_prop_t>()){
151
    case CODEC_PROP_GAIN_I: //only one gain for I and Q
152
    case CODEC_PROP_GAIN_Q:
153
        UHD_ASSERT_THROW(key.name == dac_pga_gain_name);
154
        _codec_ctrls[dboard_slot]->set_tx_pga_gain(val.as<double>());
155
        return;
156

    
157
    default: UHD_THROW_PROP_SET_ERROR();
158
    }
159
}