Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / dboard_impl.cpp @ 16f08844

History | View | Annotate | Download (5.13 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 "usrp2_impl.hpp"
19
#include "usrp2_regs.hpp"
20
#include <uhd/usrp/misc_utils.hpp>
21
#include <uhd/usrp/dsp_utils.hpp>
22
#include <uhd/usrp/subdev_props.hpp>
23
#include <uhd/usrp/dboard_props.hpp>
24
#include <uhd/exception.hpp>
25
#include <boost/format.hpp>
26
#include <boost/bind.hpp>
27
#include <boost/asio.hpp> //htonl and ntohl
28
#include <iostream>
29

    
30
using namespace uhd;
31
using namespace uhd::usrp;
32

    
33
/***********************************************************************
34
 * Helper Methods
35
 **********************************************************************/
36
void usrp2_mboard_impl::dboard_init(void){
37
    //read the dboard eeprom to extract the dboard ids
38
    _rx_db_eeprom.load(*_iface, USRP2_I2C_ADDR_RX_DB);
39
    _tx_db_eeprom.load(*_iface, USRP2_I2C_ADDR_TX_DB);
40

    
41
    //create a new dboard interface and manager
42
    _dboard_iface = make_usrp2_dboard_iface(_iface, _clock_ctrl);
43
    _dboard_manager = dboard_manager::make(
44
        _rx_db_eeprom.id, _tx_db_eeprom.id, _dboard_iface
45
    );
46

    
47
    //load dboards
48
    _rx_dboard_proxy = wax_obj_proxy::make(
49
        boost::bind(&usrp2_mboard_impl::rx_dboard_get, this, _1, _2),
50
        boost::bind(&usrp2_mboard_impl::rx_dboard_set, this, _1, _2)
51
    );
52
    _tx_dboard_proxy = wax_obj_proxy::make(
53
        boost::bind(&usrp2_mboard_impl::tx_dboard_get, this, _1, _2),
54
        boost::bind(&usrp2_mboard_impl::tx_dboard_set, this, _1, _2)
55
    );
56
}
57

    
58
/***********************************************************************
59
 * RX DBoard Properties
60
 **********************************************************************/
61
void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
62
    named_prop_t key = named_prop_t::extract(key_);
63

    
64
    //handle the get request conditioned on the key
65
    switch(key.as<dboard_prop_t>()){
66
    case DBOARD_PROP_NAME:
67
        val = _iface->get_cname() + " dboard (rx unit)";
68
        return;
69

    
70
    case DBOARD_PROP_SUBDEV:
71
        val = _dboard_manager->get_rx_subdev(key.name);
72
        return;
73

    
74
    case DBOARD_PROP_SUBDEV_NAMES:
75
        val = _dboard_manager->get_rx_subdev_names();
76
        return;
77

    
78
    case DBOARD_PROP_DBOARD_EEPROM:
79
        val = _rx_db_eeprom;
80
        return;
81

    
82
    case DBOARD_PROP_DBOARD_IFACE:
83
        val = _dboard_iface;
84
        return;
85

    
86
    case DBOARD_PROP_CODEC:
87
        val = _rx_codec_proxy->get_link();
88
        return;
89

    
90
    case DBOARD_PROP_GAIN_GROUP:
91
        val = make_gain_group(
92
            _rx_db_eeprom.id,
93
            _dboard_manager->get_rx_subdev(key.name),
94
            _rx_codec_proxy->get_link(),
95
            GAIN_GROUP_POLICY_RX
96
        );
97
        return;
98

    
99
    default: UHD_THROW_PROP_GET_ERROR();
100
    }
101
}
102

    
103
void usrp2_mboard_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
104
    switch(key.as<dboard_prop_t>()){
105

    
106
    case DBOARD_PROP_DBOARD_EEPROM:
107
        _rx_db_eeprom = val.as<dboard_eeprom_t>();
108
        _rx_db_eeprom.store(*_iface, USRP2_I2C_ADDR_RX_DB);
109
        return;
110

    
111
    default: UHD_THROW_PROP_SET_ERROR();
112
    }
113
}
114

    
115
/***********************************************************************
116
 * TX DBoard Properties
117
 **********************************************************************/
118
void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
119
    named_prop_t key = named_prop_t::extract(key_);
120

    
121
    //handle the get request conditioned on the key
122
    switch(key.as<dboard_prop_t>()){
123
    case DBOARD_PROP_NAME:
124
        val = _iface->get_cname() + " dboard (tx unit)";
125
        return;
126

    
127
    case DBOARD_PROP_SUBDEV:
128
        val = _dboard_manager->get_tx_subdev(key.name);
129
        return;
130

    
131
    case DBOARD_PROP_SUBDEV_NAMES:
132
        val = _dboard_manager->get_tx_subdev_names();
133
        return;
134

    
135
    case DBOARD_PROP_DBOARD_EEPROM:
136
        val = _tx_db_eeprom;
137
        return;
138

    
139
    case DBOARD_PROP_DBOARD_IFACE:
140
        val = _dboard_iface;
141
        return;
142

    
143
    case DBOARD_PROP_CODEC:
144
        val = _tx_codec_proxy->get_link();
145
        return;
146

    
147
    case DBOARD_PROP_GAIN_GROUP:
148
        val = make_gain_group(
149
            _tx_db_eeprom.id,
150
            _dboard_manager->get_tx_subdev(key.name),
151
            _tx_codec_proxy->get_link(),
152
            GAIN_GROUP_POLICY_TX
153
        );
154
        return;
155

    
156
    default: UHD_THROW_PROP_GET_ERROR();
157
    }
158
}
159

    
160
void usrp2_mboard_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
161
    switch(key.as<dboard_prop_t>()){
162

    
163
    case DBOARD_PROP_DBOARD_EEPROM:
164
        _tx_db_eeprom = val.as<dboard_eeprom_t>();
165
        _tx_db_eeprom.store(*_iface, USRP2_I2C_ADDR_TX_DB);
166
        return;
167

    
168
    default: UHD_THROW_PROP_SET_ERROR();
169
    }
170
}