Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.15 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 "clock_control.hpp"
22
#include <uhd/usrp/usrp2.hpp>
23
#include <uhd/types/dict.hpp>
24
#include <uhd/types/otw_type.hpp>
25
#include <uhd/types/stream_cmd.hpp>
26
#include <uhd/types/clock_config.hpp>
27
#include <boost/asio.hpp>
28
#include <boost/thread.hpp>
29
#include <boost/shared_ptr.hpp>
30
#include <boost/function.hpp>
31
#include <boost/assign/list_of.hpp>
32
#include <uhd/transport/vrt.hpp>
33
#include <uhd/transport/udp_simple.hpp>
34
#include <uhd/transport/udp_zero_copy.hpp>
35
#include <uhd/usrp/dboard_manager.hpp>
36
#include "fw_common.h"
37

    
38
class usrp2_impl; //dummy class declaration
39

    
40
/*!
41
 * Make a usrp2 dboard interface.
42
 * \param impl a pointer to the usrp2 impl object
43
 * \return a sptr to a new dboard interface
44
 */
45
uhd::usrp::dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl);
46

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

    
59
    static sptr make(const get_t &get, const set_t &set){
60
        return sptr(new wax_obj_proxy(get, set));
61
    }
62

    
63
    ~wax_obj_proxy(void){
64
        /* NOP */
65
    }
66

    
67
private:
68
    get_t _get;
69
    set_t _set;
70

    
71
    wax_obj_proxy(const get_t &get, const set_t &set){
72
        _get = get;
73
        _set = set;
74
    };
75

    
76
    void get(const wax::obj &key, wax::obj &val){
77
        return _get(key, val);
78
    }
79

    
80
    void set(const wax::obj &key, const wax::obj &val){
81
        return _set(key, val);
82
    }
83
};
84

    
85
/*!
86
 * USRP2 implementation guts:
87
 * The implementation details are encapsulated here.
88
 * Handles properties on the mboard, dboard, dsps...
89
 */
90
class usrp2_impl : public uhd::device{
91
public:
92
    /*!
93
     * Create a new usrp2 impl base.
94
     * \param ctrl_transport the udp transport for control
95
     * \param data_transport the udp transport for data
96
     */
97
    usrp2_impl(
98
        uhd::transport::udp_simple::sptr ctrl_transport,
99
        uhd::transport::udp_zero_copy::sptr data_transport
100
    );
101

    
102
    ~usrp2_impl(void);
103

    
104
    //performs a control transaction
105
    usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &);
106

    
107
    //peek and poke registers
108
    void poke32(boost::uint32_t addr, boost::uint32_t data);
109
    boost::uint32_t peek32(boost::uint32_t addr);
110

    
111
    void poke16(boost::uint32_t addr, boost::uint16_t data);
112
    boost::uint16_t peek16(boost::uint32_t addr);
113

    
114
    //clock control
115
    clock_control::sptr get_clock_control(void);
116

    
117
    //spi read and write
118
    boost::uint32_t transact_spi(
119
        int which_slave,
120
        const uhd::usrp::spi_config_t &config,
121
        boost::uint32_t data,
122
        size_t num_bits,
123
        bool readback
124
    );
125

    
126
    //misc access methods
127
    double get_master_clock_freq(void);
128

    
129
    //the io interface
130
    size_t send(const boost::asio::const_buffer &, const uhd::tx_metadata_t &, const uhd::io_type_t &);
131
    size_t recv(const boost::asio::mutable_buffer &, uhd::rx_metadata_t &, const uhd::io_type_t &);
132

    
133
private:
134
    //device properties interface
135
    void get(const wax::obj &, wax::obj &);
136
    void set(const wax::obj &, const wax::obj &);
137
    clock_control::sptr _clock_control;
138

    
139
    //the raw io interface (samples are in the usrp2 native format)
140
    void recv_raw(uhd::rx_metadata_t &);
141
    uhd::dict<boost::uint32_t, size_t> _tx_stream_id_to_packet_seq;
142
    uhd::dict<boost::uint32_t, size_t> _rx_stream_id_to_packet_seq;
143
    static const size_t _mtu = 1500; //FIXME we have no idea
144
    static const size_t _hdrs = (2 + 14 + 20 + 8); //size of headers (pad, eth, ip, udp)
145
    static const size_t _max_rx_samples_per_packet =
146
        (_mtu - _hdrs)/sizeof(boost::uint32_t) -
147
        USRP2_HOST_RX_VRT_HEADER_WORDS32 -
148
        USRP2_HOST_RX_VRT_TRAILER_WORDS32
149
    ;
150
    static const size_t _max_tx_samples_per_packet =
151
        (_mtu - _hdrs)/sizeof(boost::uint32_t) -
152
        uhd::transport::vrt::max_header_words32
153
    ;
154
    uhd::transport::managed_recv_buffer::sptr _rx_smart_buff;
155
    boost::asio::const_buffer _rx_copy_buff;
156
    size_t _fragment_offset_in_samps;
157
    uhd::otw_type_t _otw_type;
158
    void io_init(void);
159

    
160
    //udp transports for control and data
161
    uhd::transport::udp_simple::sptr _ctrl_transport;
162
    uhd::transport::udp_zero_copy::sptr _data_transport;
163

    
164
    //private vars for dealing with send/recv control
165
    boost::uint32_t _ctrl_seq_num;
166
    boost::mutex _ctrl_mutex;
167

    
168
    //methods and shadows for clock configuration
169
    uhd::clock_config_t _clock_config;
170
    void init_clock_config(void);
171
    void update_clock_config(void);
172
    void set_time_spec(const uhd::time_spec_t &time_spec, bool now);
173

    
174
    //rx and tx dboard methods and objects
175
    uhd::usrp::dboard_manager::sptr _dboard_manager;
176
    void dboard_init(void);
177

    
178
    //properties for the mboard
179
    void mboard_init(void);
180
    void mboard_get(const wax::obj &, wax::obj &);
181
    void mboard_set(const wax::obj &, const wax::obj &);
182
    wax_obj_proxy::sptr _mboard_proxy;
183

    
184
    //properties interface for rx dboard
185
    void rx_dboard_get(const wax::obj &, wax::obj &);
186
    void rx_dboard_set(const wax::obj &, const wax::obj &);
187
    wax_obj_proxy::sptr _rx_dboard_proxy;
188
    uhd::prop_names_t _rx_subdevs_in_use;
189

    
190
    //properties interface for tx dboard
191
    void tx_dboard_get(const wax::obj &, wax::obj &);
192
    void tx_dboard_set(const wax::obj &, const wax::obj &);
193
    wax_obj_proxy::sptr _tx_dboard_proxy;
194
    uhd::prop_names_t _tx_subdevs_in_use;
195
    void update_rx_mux_config(void);
196
    void update_tx_mux_config(void);
197

    
198
    //methods and shadows for the ddc dsp
199
    std::vector<size_t> _allowed_decim_and_interp_rates;
200
    size_t _ddc_decim;
201
    double _ddc_freq;
202
    void init_ddc_config(void);
203
    void update_ddc_config(void);
204
    void issue_ddc_stream_cmd(const uhd::stream_cmd_t &stream_cmd);
205

    
206
    //methods and shadows for the duc dsp
207
    size_t _duc_interp;
208
    double _duc_freq;
209
    void init_duc_config(void);
210
    void update_duc_config(void);
211

    
212
    //properties interface for ddc
213
    void ddc_get(const wax::obj &, wax::obj &);
214
    void ddc_set(const wax::obj &, const wax::obj &);
215
    wax_obj_proxy::sptr _rx_dsp_proxy;
216

    
217
    //properties interface for duc
218
    void duc_get(const wax::obj &, wax::obj &);
219
    void duc_set(const wax::obj &, const wax::obj &);
220
    wax_obj_proxy::sptr _tx_dsp_proxy;
221

    
222
};
223

    
224
#endif /* INCLUDED_USRP2_IMPL_HPP */