Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp2 / usrp2_impl.hpp @ fa7d4a2a

History | View | Annotate | Download (7.43 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
#ifndef INCLUDED_USRP2_IMPL_HPP
19
#define INCLUDED_USRP2_IMPL_HPP
20

    
21
#include "usrp2_iface.hpp"
22
#include "clock_ctrl.hpp"
23
#include "codec_ctrl.hpp"
24
#include "gps_ctrl.hpp"
25
#include <uhd/device.hpp>
26
#include <uhd/utils/pimpl.hpp>
27
#include <uhd/types/dict.hpp>
28
#include <uhd/types/otw_type.hpp>
29
#include <uhd/types/stream_cmd.hpp>
30
#include <uhd/types/clock_config.hpp>
31
#include <uhd/usrp/dboard_eeprom.hpp>
32
#include <boost/shared_ptr.hpp>
33
#include <boost/function.hpp>
34
#include <uhd/transport/vrt_if_packet.hpp>
35
#include <uhd/transport/udp_simple.hpp>
36
#include <uhd/transport/udp_zero_copy.hpp>
37
#include <uhd/usrp/dboard_manager.hpp>
38
#include <uhd/usrp/subdev_spec.hpp>
39

    
40
/*!
41
 * Make a usrp2 dboard interface.
42
 * \param iface the usrp2 interface object
43
 * \param clk_ctrl the clock control object
44
 * \return a sptr to a new dboard interface
45
 */
46
uhd::usrp::dboard_iface::sptr make_usrp2_dboard_iface(
47
    usrp2_iface::sptr iface,
48
    usrp2_clock_ctrl::sptr clk_ctrl
49
);
50

    
51
/*!
52
 * Simple wax obj proxy class:
53
 * Provides a wax obj interface for a set and a get function.
54
 * This allows us to create nested properties structures
55
 * while maintaining flattened code within the implementation.
56
 */
57
class wax_obj_proxy : public wax::obj{
58
public:
59
    typedef boost::function<void(const wax::obj &, wax::obj &)>       get_t;
60
    typedef boost::function<void(const wax::obj &, const wax::obj &)> set_t;
61
    typedef boost::shared_ptr<wax_obj_proxy> sptr;
62

    
63
    static sptr make(const get_t &get, const set_t &set){
64
        return sptr(new wax_obj_proxy(get, set));
65
    }
66

    
67
private:
68
    get_t _get; set_t _set;
69
    wax_obj_proxy(const get_t &get, const set_t &set): _get(get), _set(set){};
70
    void get(const wax::obj &key, wax::obj &val){return _get(key, val);}
71
    void set(const wax::obj &key, const wax::obj &val){return _set(key, val);}
72
};
73

    
74
/*!
75
 * USRP2 mboard implementation guts:
76
 * The implementation details are encapsulated here.
77
 * Handles properties on the mboard, dboard, dsps...
78
 */
79
class usrp2_mboard_impl : public wax::obj{
80
public:
81
    typedef boost::shared_ptr<usrp2_mboard_impl> sptr;
82

    
83
    //structors
84
    usrp2_mboard_impl(
85
        size_t index,
86
        uhd::transport::udp_simple::sptr,
87
        uhd::transport::zero_copy_if::sptr,
88
        const uhd::device_addr_t &device_args,
89
        size_t recv_samps_per_packet
90
    );
91
    ~usrp2_mboard_impl(void);
92

    
93
    inline double get_master_clock_freq(void){
94
        return _clock_ctrl->get_master_clock_rate();
95
    }
96

    
97
    void handle_overflow(void);
98

    
99
private:
100
    size_t _index;
101
    bool _continuous_streaming;
102

    
103
    //interfaces
104
    usrp2_iface::sptr _iface;
105
    usrp2_clock_ctrl::sptr _clock_ctrl;
106
    usrp2_codec_ctrl::sptr _codec_ctrl;
107
    usrp2_gps_ctrl::sptr _gps_ctrl;
108

    
109
    //properties for this mboard
110
    void get(const wax::obj &, wax::obj &);
111
    void set(const wax::obj &, const wax::obj &);
112
    uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec;
113

    
114
    //rx and tx dboard methods and objects
115
    uhd::usrp::dboard_manager::sptr _dboard_manager;
116
    uhd::usrp::dboard_iface::sptr _dboard_iface;
117
    void dboard_init(void);
118

    
119
    //methods and shadows for clock configuration
120
    uhd::clock_config_t _clock_config;
121
    void init_clock_config(void);
122
    void update_clock_config(void);
123
    void set_time_spec(const uhd::time_spec_t &time_spec, bool now);
124

    
125
    //properties interface for the codec
126
    void codec_init(void);
127
    void rx_codec_get(const wax::obj &, wax::obj &);
128
    void rx_codec_set(const wax::obj &, const wax::obj &);
129
    void tx_codec_get(const wax::obj &, wax::obj &);
130
    void tx_codec_set(const wax::obj &, const wax::obj &);
131
    wax_obj_proxy::sptr _rx_codec_proxy;
132
    wax_obj_proxy::sptr _tx_codec_proxy;
133

    
134
    void rx_codec_set_gain(float, const std::string &);
135
    uhd::dict<std::string, float> _codec_rx_gains;
136

    
137
    //properties interface for rx dboard
138
    void rx_dboard_get(const wax::obj &, wax::obj &);
139
    void rx_dboard_set(const wax::obj &, const wax::obj &);
140
    wax_obj_proxy::sptr _rx_dboard_proxy;
141
    uhd::usrp::dboard_eeprom_t _rx_db_eeprom;
142

    
143
    //properties interface for tx dboard
144
    void tx_dboard_get(const wax::obj &, wax::obj &);
145
    void tx_dboard_set(const wax::obj &, const wax::obj &);
146
    wax_obj_proxy::sptr _tx_dboard_proxy;
147
    uhd::usrp::dboard_eeprom_t _tx_db_eeprom;
148

    
149
    //methods and shadows for the ddc dsp
150
    std::vector<size_t> _allowed_decim_and_interp_rates;
151
    size_t _ddc_decim;
152
    double _ddc_freq;
153
    void init_ddc_config(void);
154
    void issue_ddc_stream_cmd(const uhd::stream_cmd_t &stream_cmd);
155

    
156
    //methods and shadows for the duc dsp
157
    size_t _duc_interp;
158
    double _duc_freq;
159
    void init_duc_config(void);
160

    
161
    //properties interface for ddc
162
    void ddc_get(const wax::obj &, wax::obj &);
163
    void ddc_set(const wax::obj &, const wax::obj &);
164
    wax_obj_proxy::sptr _rx_dsp_proxy;
165

    
166
    //properties interface for duc
167
    void duc_get(const wax::obj &, wax::obj &);
168
    void duc_set(const wax::obj &, const wax::obj &);
169
    wax_obj_proxy::sptr _tx_dsp_proxy;
170

    
171
};
172

    
173
/*!
174
 * USRP2 implementation guts:
175
 * The implementation details are encapsulated here.
176
 * Handles device properties and streaming...
177
 */
178
class usrp2_impl : public uhd::device{
179
public:
180
    static const size_t sram_bytes = size_t(1 << 20);
181
    static const boost::uint32_t RECV_SID = 1;
182
    static const boost::uint32_t ASYNC_SID = 2;
183

    
184
    /*!
185
     * Create a new usrp2 impl base.
186
     * \param ctrl_transports the udp transports for control
187
     * \param data_transports the udp transports for data
188
     * \param flow_control_hints optional flow control params
189
     */
190
    usrp2_impl(
191
        std::vector<uhd::transport::udp_simple::sptr> ctrl_transports,
192
        std::vector<uhd::transport::zero_copy_if::sptr> data_transports,
193
        const uhd::device_addrs_t &device_args
194
    );
195

    
196
    ~usrp2_impl(void);
197

    
198
    //the io interface
199
    size_t send(
200
        const std::vector<const void *> &, size_t,
201
        const uhd::tx_metadata_t &, const uhd::io_type_t &,
202
        uhd::device::send_mode_t, double
203
    );
204
    size_t recv(
205
        const std::vector<void *> &, size_t,
206
        uhd::rx_metadata_t &, const uhd::io_type_t &,
207
        uhd::device::recv_mode_t, double
208
    );
209
    size_t get_max_send_samps_per_packet(void) const;
210
    size_t get_max_recv_samps_per_packet(void) const;
211
    bool recv_async_msg(uhd::async_metadata_t &, double);
212

    
213
private:
214
    //device properties interface
215
    void get(const wax::obj &, wax::obj &);
216
    void set(const wax::obj &, const wax::obj &);
217

    
218
    //pointers to mboards on this device (think mimo setup)
219
    std::vector<usrp2_mboard_impl::sptr> _mboards;
220
    uhd::dict<std::string, usrp2_mboard_impl::sptr> _mboard_dict;
221

    
222
    //io impl methods and members
223
    std::vector<uhd::transport::zero_copy_if::sptr> _data_transports;
224
    uhd::otw_type_t _rx_otw_type, _tx_otw_type;
225
    UHD_PIMPL_DECL(io_impl) _io_impl;
226
    void io_init(void);
227
};
228

    
229
#endif /* INCLUDED_USRP2_IMPL_HPP */