Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.8 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/subdev_spec.hpp>
29
#include <uhd/usrp/dboard_eeprom.hpp>
30
#include <uhd/usrp/dboard_manager.hpp>
31
#include <uhd/transport/usb_zero_copy.hpp>
32

    
33
#ifndef INCLUDED_USRP1_IMPL_HPP
34
#define INCLUDED_USRP1_IMPL_HPP
35

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

    
48
    static sptr make(const get_t &get, const set_t &set)
49
    {
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

    
97
    bool recv_async_msg(uhd::async_metadata_t &, size_t) {
98
        //TODO sleep the number of ms supplied (dont want to hog CPU)
99
        return false;
100
    }
101

    
102
private:
103
    /*!
104
     * Make a usrp1 dboard interface.
105
     * \param iface the usrp1 interface object
106
     * \param clock the clock control interface
107
     * \param codec the codec control interface
108
     * \param dboard_slot the slot identifier
109
     * \return a sptr to a new dboard interface
110
     */
111
    static uhd::usrp::dboard_iface::sptr make_dboard_iface(
112
        usrp1_iface::sptr iface,
113
        usrp1_clock_ctrl::sptr clock,
114
        usrp1_codec_ctrl::sptr codec,
115
        dboard_slot_t dboard_slot
116
    );
117

    
118
    //interface to ioctls and file descriptor
119
    usrp1_iface::sptr _iface;
120

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

    
127
    //underrun and overrun poll intervals
128
    size_t _rx_samps_per_poll_interval;
129
    size_t _tx_samps_per_poll_interval; 
130

    
131
    //otw types
132
    uhd::otw_type_t _rx_otw_type;
133
    uhd::otw_type_t _tx_otw_type;
134

    
135
    //configuration shadows
136
    uhd::clock_config_t _clock_config;
137
    uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec;
138

    
139
    //clock control
140
    usrp1_clock_ctrl::sptr _clock_ctrl;
141

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

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

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

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

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

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

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

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

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

    
194
    //transports
195
    uhd::transport::usb_zero_copy::sptr _data_transport;
196
    usrp_ctrl::sptr _ctrl_transport;
197
};
198

    
199
#endif /* INCLUDED_USRP1_IMPL_HPP */