Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / codec_impl.cpp @ 476afe68

History | View | Annotate | Download (4.98 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 "usrp2_impl.hpp"
19
#include <uhd/usrp/codec_props.hpp>
20
#include <uhd/types/dict.hpp>
21
#include <uhd/types/ranges.hpp>
22
#include <boost/bind.hpp>
23
#include <boost/assign/list_of.hpp>
24
#include <uhd/utils/assert.hpp>
25
#include <uhd/utils/exception.hpp>
26

    
27
using namespace uhd;
28
using namespace uhd::usrp;
29
using namespace boost::assign;
30

    
31
//this only applies to USRP2P
32
static const uhd::dict<std::string, gain_range_t> codec_rx_gain_ranges = map_list_of
33
                                  ("analog", gain_range_t(0, 3.5, 3.5))
34
                                  ("digital", gain_range_t(0, 6.0, 0.5))
35
                                  ("digital-fine", gain_range_t(0, 0.5, 0.05));
36

    
37

    
38
/***********************************************************************
39
 * Helper Methods
40
 **********************************************************************/
41
void usrp2_mboard_impl::codec_init(void){
42
    //make proxies
43
    _rx_codec_proxy = wax_obj_proxy::make(
44
        boost::bind(&usrp2_mboard_impl::rx_codec_get, this, _1, _2),
45
        boost::bind(&usrp2_mboard_impl::rx_codec_set, this, _1, _2)
46
    );
47
    _tx_codec_proxy = wax_obj_proxy::make(
48
        boost::bind(&usrp2_mboard_impl::tx_codec_get, this, _1, _2),
49
        boost::bind(&usrp2_mboard_impl::tx_codec_set, this, _1, _2)
50
    );
51
}
52

    
53
/***********************************************************************
54
 * RX Codec Properties
55
 **********************************************************************/
56
void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){
57
    named_prop_t key = named_prop_t::extract(key_);
58

    
59
    //handle the get request conditioned on the key
60
    switch(key.as<codec_prop_t>()){
61
    case CODEC_PROP_NAME:
62
        val = std::string("usrp2 adc");
63
        return;
64

    
65
    case CODEC_PROP_OTHERS:
66
        val = prop_names_t();
67
        return;
68

    
69
    case CODEC_PROP_GAIN_NAMES:
70
        switch(_iface->get_rev()){
71
        case usrp2_iface::USRP_N200:
72
        case usrp2_iface::USRP_N210:
73
            val = prop_names_t(codec_rx_gain_ranges.keys());
74
            return;
75

    
76
        default: val = prop_names_t();
77
        }
78
        return;
79

    
80
    case CODEC_PROP_GAIN_I:
81
    case CODEC_PROP_GAIN_Q:
82
        assert_has(_codec_rx_gains.keys(), key.name, "codec rx gain name");
83
        val = _codec_rx_gains[key.name];
84
        return;
85

    
86
    case CODEC_PROP_GAIN_RANGE:
87
      assert_has(codec_rx_gain_ranges.keys(), key.name, "codec rx gain range name");
88
      val = codec_rx_gain_ranges[key.name];
89
      return;
90

    
91
    default: UHD_THROW_PROP_GET_ERROR();
92
    }
93
}
94

    
95
void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){
96
    named_prop_t key = named_prop_t::extract(key_);
97

    
98
    switch(key.as<codec_prop_t>()) {
99
    case CODEC_PROP_GAIN_I:
100
    case CODEC_PROP_GAIN_Q:
101
        this->rx_codec_set_gain(val.as<float>(), key.name);
102
        return;
103

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

    
108
/***********************************************************************
109
 * Helper function to set RX codec gain
110
 ***********************************************************************/
111

    
112
void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){
113
  assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain name");
114

    
115
  _codec_rx_gains[name] = gain;
116

    
117
  if(name == "analog") {
118
    _codec_ctrl->set_rx_analog_gain(gain > 0); //just turn it on or off
119
    return;
120
  }
121
  if(name == "digital") {
122
    _codec_ctrl->set_rx_digital_gain(gain);
123
    return;
124
  }
125
  if(name == "digital-fine") {
126
    _codec_ctrl->set_rx_digital_fine_gain(gain);
127
    return;
128
  }
129
  UHD_THROW_PROP_SET_ERROR();
130
}
131

    
132

    
133
/***********************************************************************
134
 * TX Codec Properties
135
 **********************************************************************/
136
void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){
137
    named_prop_t key = named_prop_t::extract(key_);
138

    
139
    //handle the get request conditioned on the key
140
    switch(key.as<codec_prop_t>()){
141
    case CODEC_PROP_NAME:
142
        val = std::string("usrp2 dac - ad9777");
143
        return;
144

    
145
    case CODEC_PROP_OTHERS:
146
        val = prop_names_t();
147
        return;
148

    
149
    case CODEC_PROP_GAIN_NAMES:
150
        val = prop_names_t(); //no gain elements to be controlled
151
        return;
152

    
153
    default: UHD_THROW_PROP_GET_ERROR();
154
    }
155
}
156

    
157
void usrp2_mboard_impl::tx_codec_set(const wax::obj &, const wax::obj &){
158
    UHD_THROW_PROP_SET_ERROR();
159
}