Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / dboard_impl.cpp @ c9569736

History | View | Annotate | Download (7.1 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 "usrp1_impl.hpp"
19
#include "usrp_i2c_addr.h"
20
#include <uhd/usrp/dsp_utils.hpp>
21
#include <uhd/usrp/misc_utils.hpp>
22
#include <uhd/utils/assert.hpp>
23
#include <uhd/usrp/dboard_props.hpp>
24
#include <uhd/usrp/subdev_props.hpp>
25
#include <boost/bind.hpp>
26
#include <boost/foreach.hpp>
27
#include <boost/format.hpp>
28
#include <iostream>
29

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

    
33
/***********************************************************************
34
 * Helper Functions
35
 **********************************************************************/
36
static boost::uint8_t get_rx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){
37
    switch(dboard_slot){
38
    case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_RX_A;
39
    case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_RX_B;
40
    default: UHD_THROW_INVALID_CODE_PATH();
41
    }
42
}
43

    
44
static boost::uint8_t get_tx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){
45
    switch(dboard_slot){
46
    case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_TX_A;
47
    case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_TX_B;
48
    default: UHD_THROW_INVALID_CODE_PATH();
49
    }
50
}
51

    
52
/***********************************************************************
53
 * Dboard Initialization
54
 **********************************************************************/
55
void usrp1_impl::dboard_init(void)
56
{
57
    BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){
58

    
59
        //read the tx and rx dboard eeproms
60
        _rx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom(
61
            get_rx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes()
62
        ));
63

    
64
        _tx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom(
65
            get_tx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes()
66
        ));
67

    
68
        //create a new dboard interface and manager
69
        _dboard_ifaces[dboard_slot] = make_dboard_iface(
70
            _iface, _clock_ctrl, _codec_ctrls[dboard_slot],
71
            dboard_slot, _rx_db_eeproms[dboard_slot].id
72
        );
73

    
74
        _dboard_managers[dboard_slot] = dboard_manager::make(
75
            _rx_db_eeproms[dboard_slot].id,
76
            _tx_db_eeproms[dboard_slot].id,
77
            _dboard_ifaces[dboard_slot]
78
        );
79

    
80
        //setup the dboard proxies
81
        _rx_dboard_proxies[dboard_slot] = wax_obj_proxy::make(
82
             boost::bind(&usrp1_impl::rx_dboard_get, this, _1, _2, dboard_slot),
83
             boost::bind(&usrp1_impl::rx_dboard_set, this, _1, _2, dboard_slot));
84

    
85
        _tx_dboard_proxies[dboard_slot] = wax_obj_proxy::make(
86
             boost::bind(&usrp1_impl::tx_dboard_get, this, _1, _2, dboard_slot),
87
             boost::bind(&usrp1_impl::tx_dboard_set, this, _1, _2, dboard_slot));
88
    }
89

    
90
}
91

    
92
/***********************************************************************
93
 * RX Dboard Get
94
 **********************************************************************/
95
void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot)
96
{
97
    named_prop_t key = named_prop_t::extract(key_);
98

    
99
    //handle the get request conditioned on the key
100
    switch(key.as<dboard_prop_t>()){
101
    case DBOARD_PROP_NAME:
102
        val = str(boost::format("usrp1 dboard (rx unit) - %c") % char(dboard_slot));
103
        return;
104

    
105
    case DBOARD_PROP_SUBDEV:
106
        val = _dboard_managers[dboard_slot]->get_rx_subdev(key.name);
107
        return;
108

    
109
    case DBOARD_PROP_SUBDEV_NAMES:
110
        val = _dboard_managers[dboard_slot]->get_rx_subdev_names();
111
        return;
112

    
113
    case DBOARD_PROP_DBOARD_ID:
114
        val = _rx_db_eeproms[dboard_slot].id;
115
        return;
116

    
117
    case DBOARD_PROP_DBOARD_IFACE:
118
        val = _dboard_ifaces[dboard_slot];
119
        return;
120

    
121
    case DBOARD_PROP_CODEC:
122
        val = _rx_codec_proxies[dboard_slot]->get_link();
123
        return;
124

    
125
    case DBOARD_PROP_GAIN_GROUP:
126
        val = make_gain_group(
127
            _dboard_managers[dboard_slot]->get_rx_subdev(key.name),
128
            _rx_codec_proxies[dboard_slot]->get_link(),
129
            GAIN_GROUP_POLICY_RX
130
        );
131
        return;
132

    
133
    default: UHD_THROW_PROP_GET_ERROR();
134
    }
135
}
136

    
137
/***********************************************************************
138
 * RX Dboard Set
139
 **********************************************************************/
140
void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot)
141
{
142
    switch(key.as<dboard_prop_t>()) {
143
    case DBOARD_PROP_DBOARD_ID:
144
        _rx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>();
145
        _iface->write_eeprom(
146
            get_rx_ee_addr(dboard_slot), 0,
147
            _rx_db_eeproms[dboard_slot].get_eeprom_bytes()
148
        );
149
        return;
150

    
151
    default:
152
        UHD_THROW_PROP_SET_ERROR();
153
    }
154
}
155

    
156
/***********************************************************************
157
 * TX Dboard Get
158
 **********************************************************************/
159
void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot)
160
{
161
    named_prop_t key = named_prop_t::extract(key_);
162

    
163
    //handle the get request conditioned on the key
164
    switch(key.as<dboard_prop_t>()){
165
    case DBOARD_PROP_NAME:
166
        val = str(boost::format("usrp1 dboard (tx unit) - %c") % char(dboard_slot));
167
        return;
168

    
169
    case DBOARD_PROP_SUBDEV:
170
        val = _dboard_managers[dboard_slot]->get_tx_subdev(key.name);
171
        return;
172

    
173
    case DBOARD_PROP_SUBDEV_NAMES:
174
        val = _dboard_managers[dboard_slot]->get_tx_subdev_names();
175
        return;
176

    
177
    case DBOARD_PROP_DBOARD_ID:
178
        val = _tx_db_eeproms[dboard_slot].id;
179
        return;
180

    
181
    case DBOARD_PROP_DBOARD_IFACE:
182
        val = _dboard_ifaces[dboard_slot];
183
        return;
184

    
185
    case DBOARD_PROP_CODEC:
186
        val = _tx_codec_proxies[dboard_slot]->get_link();
187
        return;
188

    
189
    case DBOARD_PROP_GAIN_GROUP:
190
        val = make_gain_group(
191
            _dboard_managers[dboard_slot]->get_tx_subdev(key.name),
192
            _tx_codec_proxies[dboard_slot]->get_link(),
193
            GAIN_GROUP_POLICY_TX
194
        );
195
        return;
196

    
197
    default: UHD_THROW_PROP_GET_ERROR();
198
    }
199
}
200

    
201
/***********************************************************************
202
 * TX Dboard Set
203
 **********************************************************************/
204
void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot)
205
{
206
    switch(key.as<dboard_prop_t>()) {
207
    case DBOARD_PROP_DBOARD_ID:
208
        _tx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>();
209
        _iface->write_eeprom(
210
            get_tx_ee_addr(dboard_slot), 0,
211
            _tx_db_eeproms[dboard_slot].get_eeprom_bytes()
212
        );
213
        return;
214

    
215
    default: UHD_THROW_PROP_SET_ERROR();
216
    }
217
}