Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / usrp1 / usrp1_impl.hpp @ c9569736

History | View | Annotate | Download (6.9 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_iface.hpp"
19
#include "usrp1_ctrl.hpp"
20
#include "clock_ctrl.hpp"
21
#include "codec_ctrl.hpp"
22
#include <uhd/device.hpp>
23
#include <uhd/utils/pimpl.hpp>
24
#include <uhd/types/dict.hpp>
25
#include <uhd/types/otw_type.hpp>
26
#include <uhd/types/clock_config.hpp>
27
#include <uhd/types/stream_cmd.hpp>
28
#include <uhd/usrp/dboard_id.hpp>
29
#include <uhd/usrp/subdev_spec.hpp>
30
#include <uhd/usrp/dboard_eeprom.hpp>
31
#include <uhd/usrp/dboard_manager.hpp>
32
#include <uhd/transport/usb_zero_copy.hpp>
33

    
34
#ifndef INCLUDED_USRP1_IMPL_HPP
35
#define INCLUDED_USRP1_IMPL_HPP
36

    
37
/*!
38
 * Simple wax obj proxy class:
39
 * Provides a wax obj interface for a set and a get function.
40
 * This allows us to create nested properties structures
41
 * while maintaining flattened code within the implementation.
42
 */
43
class wax_obj_proxy : public wax::obj {
44
public:
45
    typedef boost::function<void(const wax::obj &, wax::obj &)>       get_t;
46
    typedef boost::function<void(const wax::obj &, const wax::obj &)> set_t;
47
    typedef boost::shared_ptr<wax_obj_proxy> sptr;
48

    
49
    static sptr make(const get_t &get, const set_t &set){
50
        return sptr(new wax_obj_proxy(get, set));
51
    }
52

    
53
private:
54
    get_t _get; set_t _set;
55
    wax_obj_proxy(const get_t &get, const set_t &set): _get(get), _set(set) {};
56
    void get(const wax::obj &key, wax::obj &val) {return _get(key, val);}
57
    void set(const wax::obj &key, const wax::obj &val) {return _set(key, val);}
58
};
59

    
60
/*!
61
 * USRP1 implementation guts:
62
 * The implementation details are encapsulated here.
63
 * Handles properties on the mboard, dboard, dsps...
64
 */
65
class usrp1_impl : public uhd::device {
66
public:
67
    //! used everywhere to differentiate slots/sides...
68
    enum dboard_slot_t{
69
        DBOARD_SLOT_A = 'A',
70
        DBOARD_SLOT_B = 'B'
71
    };
72
    //and a way to enumerate through a list of the above...
73
    static const std::vector<dboard_slot_t> _dboard_slots;
74

    
75
    //structors
76
    usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
77
               usrp_ctrl::sptr ctrl_transport);
78

    
79
    ~usrp1_impl(void);
80

    
81
    //the io interface
82
    size_t send(const std::vector<const void *> &,
83
                size_t,
84
                const uhd::tx_metadata_t &,
85
                const uhd::io_type_t &,
86
                send_mode_t);
87

    
88
    size_t recv(const std::vector<void *> &,
89
                size_t, uhd::rx_metadata_t &,
90
                const uhd::io_type_t &,
91
                recv_mode_t,
92
                size_t timeout);
93

    
94
    size_t get_max_send_samps_per_packet(void) const { return 0; }
95
    size_t get_max_recv_samps_per_packet(void) const { return 0; }
96
    bool recv_async_msg(uhd::async_metadata_t &, size_t);
97

    
98
private:
99
    /*!
100
     * Make a usrp1 dboard interface.
101
     * \param iface the usrp1 interface object
102
     * \param clock the clock control interface
103
     * \param codec the codec control interface
104
     * \param dboard_slot the slot identifier
105
     * \param rx_dboard_id the db id for the rx board (used for evil dbsrx purposes)
106
     * \return a sptr to a new dboard interface
107
     */
108
    static uhd::usrp::dboard_iface::sptr make_dboard_iface(
109
        usrp1_iface::sptr iface,
110
        usrp1_clock_ctrl::sptr clock,
111
        usrp1_codec_ctrl::sptr codec,
112
        dboard_slot_t dboard_slot,
113
        const uhd::usrp::dboard_id_t &rx_dboard_id
114
    );
115

    
116
    //interface to ioctls and file descriptor
117
    usrp1_iface::sptr _iface;
118

    
119
    //handle io stuff
120
    UHD_PIMPL_DECL(io_impl) _io_impl;
121
    void io_init(void);
122
    void issue_stream_cmd(const uhd::stream_cmd_t &stream_cmd);
123
    void handle_overrun(size_t);
124

    
125
    //underrun and overrun poll intervals
126
    size_t _rx_samps_per_poll_interval;
127
    size_t _tx_samps_per_poll_interval; 
128

    
129
    //otw types
130
    uhd::otw_type_t _rx_otw_type;
131
    uhd::otw_type_t _tx_otw_type;
132

    
133
    //configuration shadows
134
    uhd::clock_config_t _clock_config;
135
    uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec;
136

    
137
    //clock control
138
    usrp1_clock_ctrl::sptr _clock_ctrl;
139

    
140
    //ad9862 codec control interface
141
    uhd::dict<dboard_slot_t, usrp1_codec_ctrl::sptr> _codec_ctrls;
142

    
143
    //codec properties interfaces
144
    void codec_init(void);
145
    void rx_codec_get(const wax::obj &, wax::obj &, dboard_slot_t);
146
    void rx_codec_set(const wax::obj &, const wax::obj &, dboard_slot_t);
147
    void tx_codec_get(const wax::obj &, wax::obj &, dboard_slot_t);
148
    void tx_codec_set(const wax::obj &, const wax::obj &, dboard_slot_t);
149
    uhd::dict<dboard_slot_t, wax_obj_proxy::sptr> _rx_codec_proxies, _tx_codec_proxies;
150

    
151
    //device functions and settings
152
    void get(const wax::obj &, wax::obj &);
153
    void set(const wax::obj &, const wax::obj &);
154

    
155
    //mboard functions and settings
156
    void mboard_init(void);
157
    void mboard_get(const wax::obj &, wax::obj &);
158
    void mboard_set(const wax::obj &, const wax::obj &);
159
    wax_obj_proxy::sptr _mboard_proxy;
160

    
161
    //xx dboard functions and settings
162
    void dboard_init(void);
163
    uhd::dict<dboard_slot_t, uhd::usrp::dboard_manager::sptr> _dboard_managers;
164
    uhd::dict<dboard_slot_t, uhd::usrp::dboard_iface::sptr> _dboard_ifaces;
165

    
166
    //rx dboard functions and settings
167
    uhd::dict<dboard_slot_t, uhd::usrp::dboard_eeprom_t> _rx_db_eeproms;
168
    void rx_dboard_get(const wax::obj &, wax::obj &, dboard_slot_t);
169
    void rx_dboard_set(const wax::obj &, const wax::obj &, dboard_slot_t);
170
    uhd::dict<dboard_slot_t, wax_obj_proxy::sptr> _rx_dboard_proxies;
171

    
172
    //tx dboard functions and settings
173
    uhd::dict<dboard_slot_t, uhd::usrp::dboard_eeprom_t> _tx_db_eeproms;
174
    void tx_dboard_get(const wax::obj &, wax::obj &, dboard_slot_t);
175
    void tx_dboard_set(const wax::obj &, const wax::obj &, dboard_slot_t);
176
    uhd::dict<dboard_slot_t, wax_obj_proxy::sptr> _tx_dboard_proxies;
177

    
178
    //rx dsp functions and settings
179
    void rx_dsp_init(void);
180
    void rx_dsp_get(const wax::obj &, wax::obj &);
181
    void rx_dsp_set(const wax::obj &, const wax::obj &);
182
    double _rx_dsp_freq; size_t _rx_dsp_decim;
183
    wax_obj_proxy::sptr _rx_dsp_proxy;
184

    
185
    //tx dsp functions and settings
186
    void tx_dsp_init(void);
187
    void tx_dsp_get(const wax::obj &, wax::obj &);
188
    void tx_dsp_set(const wax::obj &, const wax::obj &);
189
    double _tx_dsp_freq; size_t _tx_dsp_interp;
190
    wax_obj_proxy::sptr _tx_dsp_proxy;
191

    
192
    //transports
193
    uhd::transport::usb_zero_copy::sptr _data_transport;
194
    usrp_ctrl::sptr _ctrl_transport;
195
};
196

    
197
#endif /* INCLUDED_USRP1_IMPL_HPP */