Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / codec_impl.cpp @ 258d9bb4

History | View | Annotate | Download (5.45 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
        switch(_iface->get_rev()){
63
        case usrp2_iface::USRP_N200:
64
        case usrp2_iface::USRP_N210:
65
            val = std::string(_iface->get_cname() + " adc - ads62p44");
66
            break;
67

    
68
        case usrp2_iface::USRP2_REV3:
69
        case usrp2_iface::USRP2_REV4:
70
            val = std::string(_iface->get_cname() + " adc - ltc2284");
71
            break;
72

    
73
        case usrp2_iface::USRP_NXXX:
74
            val = std::string(_iface->get_cname() + " adc - ??????");
75
            break;
76
        }
77
        return;
78

    
79
    case CODEC_PROP_OTHERS:
80
        val = prop_names_t();
81
        return;
82

    
83
    case CODEC_PROP_GAIN_NAMES:
84
        switch(_iface->get_rev()){
85
        case usrp2_iface::USRP_N200:
86
        case usrp2_iface::USRP_N210:
87
            val = prop_names_t(codec_rx_gain_ranges.keys());
88
            return;
89

    
90
        default: val = prop_names_t();
91
        }
92
        return;
93

    
94
    case CODEC_PROP_GAIN_I:
95
    case CODEC_PROP_GAIN_Q:
96
        assert_has(_codec_rx_gains.keys(), key.name, "codec rx gain name");
97
        val = _codec_rx_gains[key.name];
98
        return;
99

    
100
    case CODEC_PROP_GAIN_RANGE:
101
      assert_has(codec_rx_gain_ranges.keys(), key.name, "codec rx gain range name");
102
      val = codec_rx_gain_ranges[key.name];
103
      return;
104

    
105
    default: UHD_THROW_PROP_GET_ERROR();
106
    }
107
}
108

    
109
void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){
110
    named_prop_t key = named_prop_t::extract(key_);
111

    
112
    switch(key.as<codec_prop_t>()) {
113
    case CODEC_PROP_GAIN_I:
114
    case CODEC_PROP_GAIN_Q:
115
        this->rx_codec_set_gain(val.as<float>(), key.name);
116
        return;
117

    
118
    default: UHD_THROW_PROP_SET_ERROR();
119
  }
120
}
121

    
122
/***********************************************************************
123
 * Helper function to set RX codec gain
124
 ***********************************************************************/
125

    
126
void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){
127
  assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain name");
128

    
129
  _codec_rx_gains[name] = gain;
130

    
131
  if(name == "analog") {
132
    _codec_ctrl->set_rx_analog_gain(gain > 0); //just turn it on or off
133
    return;
134
  }
135
  if(name == "digital") {
136
    _codec_ctrl->set_rx_digital_gain(gain);
137
    return;
138
  }
139
  if(name == "digital-fine") {
140
    _codec_ctrl->set_rx_digital_fine_gain(gain);
141
    return;
142
  }
143
  UHD_THROW_PROP_SET_ERROR();
144
}
145

    
146

    
147
/***********************************************************************
148
 * TX Codec Properties
149
 **********************************************************************/
150
void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){
151
    named_prop_t key = named_prop_t::extract(key_);
152

    
153
    //handle the get request conditioned on the key
154
    switch(key.as<codec_prop_t>()){
155
    case CODEC_PROP_NAME:
156
        val = std::string(_iface->get_cname() + " dac - ad9777");
157
        return;
158

    
159
    case CODEC_PROP_OTHERS:
160
        val = prop_names_t();
161
        return;
162

    
163
    case CODEC_PROP_GAIN_NAMES:
164
        val = prop_names_t(); //no gain elements to be controlled
165
        return;
166

    
167
    default: UHD_THROW_PROP_GET_ERROR();
168
    }
169
}
170

    
171
void usrp2_mboard_impl::tx_codec_set(const wax::obj &, const wax::obj &){
172
    UHD_THROW_PROP_SET_ERROR();
173
}