Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp_e100 / mboard_impl.cpp @ b60418e9

History | View | Annotate | Download (7.67 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 "usrp_e100_impl.hpp"
19
#include "usrp_e100_regs.hpp"
20
#include <uhd/utils/msg.hpp>
21
#include <uhd/exception.hpp>
22
#include <uhd/usrp/dsp_utils.hpp>
23
#include <uhd/usrp/misc_utils.hpp>
24
#include <uhd/usrp/mboard_props.hpp>
25
#include <boost/bind.hpp>
26

    
27
using namespace uhd;
28
using namespace uhd::usrp;
29

    
30
/***********************************************************************
31
 * Mboard Initialization
32
 **********************************************************************/
33
void usrp_e100_impl::mboard_init(void){
34
    _mboard_proxy = wax_obj_proxy::make(
35
        boost::bind(&usrp_e100_impl::mboard_get, this, _1, _2),
36
        boost::bind(&usrp_e100_impl::mboard_set, this, _1, _2)
37
    );
38

    
39
    //init the clock config
40
    _clock_config = clock_config_t::internal();
41
    update_clock_config();
42
}
43

    
44
void usrp_e100_impl::update_clock_config(void){
45
    boost::uint32_t pps_flags = 0;
46

    
47
    //translate pps polarity enums
48
    switch(_clock_config.pps_polarity){
49
    case clock_config_t::PPS_POS: pps_flags |= UE_FLAG_TIME64_PPS_POSEDGE; break;
50
    case clock_config_t::PPS_NEG: pps_flags |= UE_FLAG_TIME64_PPS_NEGEDGE; break;
51
    default: throw uhd::value_error("unhandled clock configuration pps polarity");
52
    }
53

    
54
    //set the pps flags
55
    _iface->poke32(UE_REG_TIME64_FLAGS, pps_flags);
56

    
57
    //clock source ref 10mhz
58
    switch(_clock_config.ref_source){
59
    case clock_config_t::REF_AUTO: _clock_ctrl->use_auto_ref(); break;
60
    case clock_config_t::REF_INT: _clock_ctrl->use_internal_ref(); break;
61
    case clock_config_t::REF_SMA: _clock_ctrl->use_auto_ref(); break;
62
    default: throw uhd::value_error("unhandled clock configuration ref source");
63
    }
64
}
65

    
66
/***********************************************************************
67
 * Mboard Get
68
 **********************************************************************/
69
void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){
70
    named_prop_t key = named_prop_t::extract(key_);
71

    
72
    //handle the get request conditioned on the key
73
    switch(key.as<mboard_prop_t>()){
74
    case MBOARD_PROP_NAME:
75
        val = std::string("usrp-e mboard");
76
        return;
77

    
78
    case MBOARD_PROP_OTHERS:
79
        val = prop_names_t();
80
        return;
81

    
82
    case MBOARD_PROP_RX_DBOARD:
83
        UHD_ASSERT_THROW(key.name == "");
84
        val = _rx_dboard_proxy->get_link();
85
        return;
86

    
87
    case MBOARD_PROP_RX_DBOARD_NAMES:
88
        val = prop_names_t(1, ""); //vector of size 1 with empty string
89
        return;
90

    
91
    case MBOARD_PROP_TX_DBOARD:
92
        UHD_ASSERT_THROW(key.name == "");
93
        val = _tx_dboard_proxy->get_link();
94
        return;
95

    
96
    case MBOARD_PROP_TX_DBOARD_NAMES:
97
        val = prop_names_t(1, ""); //vector of size 1 with empty string
98
        return;
99

    
100
    case MBOARD_PROP_RX_DSP:
101
        UHD_ASSERT_THROW(key.name == "");
102
        val = _rx_ddc_proxy->get_link();
103
        return;
104

    
105
    case MBOARD_PROP_RX_DSP_NAMES:
106
        val = prop_names_t(1, "");
107
        return;
108

    
109
    case MBOARD_PROP_TX_DSP:
110
        UHD_ASSERT_THROW(key.name == "");
111
        val = _tx_duc_proxy->get_link();
112
        return;
113

    
114
    case MBOARD_PROP_TX_DSP_NAMES:
115
        val = prop_names_t(1, "");
116
        return;
117

    
118
    case MBOARD_PROP_CLOCK_CONFIG:
119
        val = _clock_config;
120
        return;
121

    
122
    case MBOARD_PROP_RX_SUBDEV_SPEC:
123
        val = _rx_subdev_spec;
124
        return;
125

    
126
    case MBOARD_PROP_TX_SUBDEV_SPEC:
127
        val = _tx_subdev_spec;
128
        return;
129

    
130
    case MBOARD_PROP_EEPROM_MAP:
131
        val = _iface->mb_eeprom;
132
        return;
133

    
134
    case MBOARD_PROP_TIME_NOW: while(true){
135
        uint32_t secs = _iface->peek32(UE_REG_RB_TIME_NOW_SECS);
136
        uint32_t ticks = _iface->peek32(UE_REG_RB_TIME_NOW_TICKS);
137
        if (secs != _iface->peek32(UE_REG_RB_TIME_NOW_SECS)) continue;
138
        val = time_spec_t(secs, ticks, _clock_ctrl->get_fpga_clock_rate());
139
        return;
140
    }
141

    
142
    case MBOARD_PROP_TIME_PPS: while(true){
143
        uint32_t secs = _iface->peek32(UE_REG_RB_TIME_PPS_SECS);
144
        uint32_t ticks = _iface->peek32(UE_REG_RB_TIME_PPS_TICKS);
145
        if (secs != _iface->peek32(UE_REG_RB_TIME_PPS_SECS)) continue;
146
        val = time_spec_t(secs, ticks, _clock_ctrl->get_fpga_clock_rate());
147
        return;
148
    }
149

    
150
    case MBOARD_PROP_CLOCK_RATE:
151
        val = _clock_ctrl->get_fpga_clock_rate();
152
        return;
153

    
154
    default: UHD_THROW_PROP_GET_ERROR();
155
    }
156
}
157

    
158
/***********************************************************************
159
 * Mboard Set
160
 **********************************************************************/
161
void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){
162
    //handle the get request conditioned on the key
163
    switch(key.as<mboard_prop_t>()){
164

    
165
    case MBOARD_PROP_TIME_NOW:
166
    case MBOARD_PROP_TIME_PPS:{
167
            time_spec_t time_spec = val.as<time_spec_t>();
168
            _iface->poke32(UE_REG_TIME64_TICKS, time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate()));
169
            boost::uint32_t imm_flags = (key.as<mboard_prop_t>() == MBOARD_PROP_TIME_NOW)? 1 : 0;
170
            _iface->poke32(UE_REG_TIME64_IMM, imm_flags);
171
            _iface->poke32(UE_REG_TIME64_SECS, time_spec.get_full_secs());
172
        }
173
        return;
174

    
175
    case MBOARD_PROP_RX_SUBDEV_SPEC:
176
        _rx_subdev_spec = val.as<subdev_spec_t>();
177
        verify_rx_subdev_spec(_rx_subdev_spec, _mboard_proxy->get_link());
178
        //sanity check
179
        UHD_ASSERT_THROW(_rx_subdev_spec.size() == 1);
180
        //set the mux
181
        _iface->poke32(UE_REG_DSP_RX_MUX, dsp_type1::calc_rx_mux_word(
182
            _dboard_manager->get_rx_subdev(_rx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()
183
        ));
184
        return;
185

    
186
    case MBOARD_PROP_TX_SUBDEV_SPEC:
187
        _tx_subdev_spec = val.as<subdev_spec_t>();
188
        verify_tx_subdev_spec(_tx_subdev_spec, _mboard_proxy->get_link());
189
        //sanity check
190
        UHD_ASSERT_THROW(_tx_subdev_spec.size() == 1);
191
        //set the mux
192
        _iface->poke32(UE_REG_DSP_TX_MUX, dsp_type1::calc_tx_mux_word(
193
            _dboard_manager->get_tx_subdev(_tx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()
194
        ));
195
        return;
196

    
197
    case MBOARD_PROP_EEPROM_MAP:
198
        // Step1: commit the map, writing only those values set.
199
        // Step2: readback the entire eeprom map into the iface.
200
        val.as<mboard_eeprom_t>().commit(_iface->get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100);
201
        _iface->mb_eeprom = mboard_eeprom_t(_iface->get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100);
202
        return;
203
        
204
    case MBOARD_PROP_CLOCK_CONFIG:
205
        _clock_config = val.as<clock_config_t>();
206
        update_clock_config();
207
        return;
208

    
209
    case MBOARD_PROP_CLOCK_RATE:
210
        UHD_MSG(warning)
211
            << "I see that you are setting the master clock rate from the API.\n"
212
            << "You may want to pass this into the device address as mcr=<rate>.\n"
213
            << "This way, the clock rate is guaranteed to be initialized first.\n"
214
            << "See the application notes for USRP-E1XX for further instructions.\n"
215
        ;
216
        _clock_ctrl->set_fpga_clock_rate(val.as<double>());
217
        return;
218

    
219
    default: UHD_THROW_PROP_SET_ERROR();
220
    }
221
}