Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / dboard_impl.cpp @ 7bf40947

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], dboard_slot
71
        );
72

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

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

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

    
89
}
90

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
214
    default: UHD_THROW_PROP_SET_ERROR();
215
    }
216
}