Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / dboard_impl.cpp @ 98ba0cc0

History | View | Annotate | Download (5.12 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 "usrp2_regs.hpp"
20
#include "../dsp_utils.hpp"
21
#include "../misc_utils.hpp"
22
#include <uhd/usrp/subdev_props.hpp>
23
#include <uhd/usrp/dboard_props.hpp>
24
#include <uhd/utils/assert.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 = dboard_eeprom_t(_iface->read_eeprom(USRP2_I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes()));
39
    _tx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(USRP2_I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes()));
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 = std::string("usrp2 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_ID:
79
        val = _rx_db_eeprom.id;
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
            _dboard_manager->get_rx_subdev(key.name), _rx_codec_proxy->get_link()
93
        );
94
        return;
95

    
96
    default: UHD_THROW_PROP_GET_ERROR();
97
    }
98
}
99

    
100
void usrp2_mboard_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
101
    switch(key.as<dboard_prop_t>()){
102

    
103
    case DBOARD_PROP_DBOARD_ID:
104
        _rx_db_eeprom.id = val.as<dboard_id_t>();
105
        _iface->write_eeprom(USRP2_I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes());
106
        return;
107

    
108
    default: UHD_THROW_PROP_SET_ERROR();
109
    }
110
}
111

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

    
118
    //handle the get request conditioned on the key
119
    switch(key.as<dboard_prop_t>()){
120
    case DBOARD_PROP_NAME:
121
        val = std::string("usrp2 dboard (tx unit)");
122
        return;
123

    
124
    case DBOARD_PROP_SUBDEV:
125
        val = _dboard_manager->get_tx_subdev(key.name);
126
        return;
127

    
128
    case DBOARD_PROP_SUBDEV_NAMES:
129
        val = _dboard_manager->get_tx_subdev_names();
130
        return;
131

    
132
    case DBOARD_PROP_DBOARD_ID:
133
        val = _tx_db_eeprom.id;
134
        return;
135

    
136
    case DBOARD_PROP_DBOARD_IFACE:
137
        val = _dboard_iface;
138
        return;
139

    
140
    case DBOARD_PROP_CODEC:
141
        val = _tx_codec_proxy->get_link();
142
        return;
143

    
144
    case DBOARD_PROP_GAIN_GROUP:
145
        val = make_gain_group(
146
            _dboard_manager->get_tx_subdev(key.name), _tx_codec_proxy->get_link()
147
        );
148
        return;
149

    
150
    default: UHD_THROW_PROP_GET_ERROR();
151
    }
152
}
153

    
154
void usrp2_mboard_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
155
    switch(key.as<dboard_prop_t>()){
156

    
157
    case DBOARD_PROP_DBOARD_ID:
158
        _tx_db_eeprom.id = val.as<dboard_id_t>();
159
        _iface->write_eeprom(USRP2_I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes());
160
        return;
161

    
162
    default: UHD_THROW_PROP_SET_ERROR();
163
    }
164
}