Statistics
| Branch: | Tag: | Revision:

root / host / include / uhd / usrp / dboard_iface.hpp @ 48ad3b73

History | View | Annotate | Download (7.2 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_UHD_USRP_DBOARD_IFACE_HPP
19
#define INCLUDED_UHD_USRP_DBOARD_IFACE_HPP
20

    
21
#include <uhd/config.hpp>
22
#include <uhd/types/serial.hpp>
23
#include <boost/shared_ptr.hpp>
24
#include <boost/cstdint.hpp>
25
#include <string>
26
#include <vector>
27

    
28
namespace uhd{ namespace usrp{
29

    
30
/*!
31
 * The daughter board dboard interface to be subclassed.
32
 * A dboard instance interfaces with the mboard though this api.
33
 * This interface provides i2c, spi, gpio, atr, aux dac/adc access.
34
 * Each mboard should have a specially tailored iface for its dboard.
35
 */
36
class UHD_API dboard_iface{
37
public:
38
    typedef boost::shared_ptr<dboard_iface> sptr;
39

    
40
    //! tells the host which unit to use
41
    enum unit_t{
42
        UNIT_RX = 'r',
43
        UNIT_TX = 't'
44
    };
45

    
46
    //! possible atr registers
47
    enum atr_reg_t{
48
        ATR_REG_IDLE        = 'i',
49
        ATR_REG_TX_ONLY     = 't',
50
        ATR_REG_RX_ONLY     = 'r',
51
        ATR_REG_FULL_DUPLEX = 'f'
52
    };
53

    
54
    //! aux dac selection enums (per unit)
55
    enum aux_dac_t{
56
        AUX_DAC_A = 'a',
57
        AUX_DAC_B = 'b',
58
        AUX_DAC_C = 'c',
59
        AUX_DAC_D = 'd'
60
    };
61

    
62
    //! aux adc selection enums (per unit)
63
    enum aux_adc_t{
64
        AUX_ADC_A = 'a',
65
        AUX_ADC_B = 'b'
66
    };
67

    
68
    //! Special properties that differentiate this daughterboard slot
69
    struct special_props_t{
70
        /*!
71
         * Soft clock divider:
72
         * When a motherboard cannot provided a divided dboard clock,
73
         * it may provided a "soft" divided clock over an FPGA GPIO.
74
         * The implementation must know the type of clock provided.
75
         */
76
        bool soft_clock_divider;
77

    
78
        /*!
79
         * Mangle i2c addresses:
80
         * When i2c is shared across multiple daugterboard slots,
81
         * the i2c addresses will be mangled on the secondary slot
82
         * to avoid conflicts between slots in the i2c address space.
83
         * The mangling is daguhterboard specific so the implementation
84
         * needs to know whether it should use mangled addresses or not.
85
         */
86
        bool mangle_i2c_addrs;
87
    };
88

    
89
    /*!
90
     * Get special properties information for this dboard slot.
91
     * This call helps the dboard code to handle implementation
92
     * differences between different motherboards and dboard slots.
93
     * \return the special properties struct
94
     */
95
    virtual special_props_t get_special_props(void) = 0;
96

    
97
    /*!
98
     * Write to an aux dac.
99
     *
100
     * \param unit which unit rx or tx
101
     * \param which_dac the dac index 0, 1, 2, 3...
102
     * \param value the value in volts
103
     */
104
    virtual void write_aux_dac(unit_t unit, aux_dac_t which_dac, float value) = 0;
105

    
106
    /*!
107
     * Read from an aux adc.
108
     *
109
     * \param unit which unit rx or tx
110
     * \param which_adc the adc index 0, 1, 2, 3...
111
     * \return the value in volts
112
     */
113
    virtual float read_aux_adc(unit_t unit, aux_adc_t which_adc) = 0;
114

    
115
    /*!
116
     * Set a daughterboard output pin control source.
117
     * By default, the outputs are all GPIO controlled.
118
     *
119
     * \param unit which unit rx or tx
120
     * \param value 16-bits, 0=GPIO controlled, 1=ATR controlled
121
     */
122
    virtual void set_pin_ctrl(unit_t unit, boost::uint16_t value) = 0;
123

    
124
    /*!
125
     * Set a daughterboard ATR register.
126
     *
127
     * \param unit which unit rx or tx
128
     * \param reg which ATR register to set
129
     * \param value 16-bits, 0=ATR output low, 1=ATR output high
130
     */
131
    virtual void set_atr_reg(unit_t unit, atr_reg_t reg, boost::uint16_t value) = 0;
132

    
133
    /*!
134
     * Set daughterboard GPIO data direction register.
135
     * By default, the GPIO pins are all inputs.
136
     *
137
     * \param unit which unit rx or tx
138
     * \param value 16-bits, 0=GPIO input, 1=GPIO output
139
     */
140
    virtual void set_gpio_ddr(unit_t unit, boost::uint16_t value) = 0;
141

    
142
    /*!
143
     * Read daughterboard GPIO pin values.
144
     *
145
     * \param unit which unit rx or tx
146
     * \param value 16-bits, 0=GPIO output low, 1=GPIO output high
147
     */
148
    virtual void write_gpio(unit_t unit, boost::uint16_t value) = 0;
149

    
150
    /*!
151
     * Setup the GPIO debug mux.
152
     *
153
     * \param unit which unit rx or tx
154
     * \param which which debug: 0, 1
155
     */
156
    virtual void set_gpio_debug(unit_t unit, int which) = 0;
157

    
158
    /*!
159
     * Read daughterboard GPIO pin values.
160
     *
161
     * \param unit which unit rx or tx
162
     * \return the value of the gpio unit
163
     */
164
    virtual boost::uint16_t read_gpio(unit_t unit) = 0;
165

    
166
    /*!
167
     * Write to an I2C peripheral.
168
     *
169
     * \param addr I2C bus address (7-bits)
170
     * \param bytes the data to write
171
     */
172
    virtual void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes) = 0;
173

    
174
    /*!
175
     * Read from an I2C peripheral.
176
     *
177
     * \param addr I2C bus address (7-bits)
178
     * \param num_bytes number of bytes to read
179
     * \return the data read if successful, else a zero length string.
180
     */
181
    virtual byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes) = 0;
182

    
183
    /*!
184
     * Write data to SPI bus peripheral.
185
     *
186
     * \param unit which unit, rx or tx
187
     * \param config configuration settings
188
     * \param data the bits to write LSB first
189
     * \param num_bits the number of bits in data
190
     */
191
    virtual void write_spi(
192
        unit_t unit,
193
        const spi_config_t &config,
194
        boost::uint32_t data,
195
        size_t num_bits
196
    ) = 0;
197

    
198
    /*!
199
     * Read and write data to SPI bus peripheral.
200
     *
201
     * \param unit which unit, rx or tx
202
     * \param config configuration settings
203
     * \param data the bits to write LSB first
204
     * \param num_bits the number of bits in data
205
     * \return the data that was read
206
     */
207
    virtual boost::uint32_t read_write_spi(
208
        unit_t unit,
209
        const spi_config_t &config,
210
        boost::uint32_t data,
211
        size_t num_bits
212
    ) = 0;
213

    
214
    /*!
215
     * Set the rate of a dboard clock.
216
     *
217
     * \param unit which unit rx or tx
218
     * \param rate the clock rate in Hz
219
     */
220
    virtual void set_clock_rate(unit_t unit, double rate) = 0;
221

    
222
    /*!
223
     * Get the rate of a dboard clock.
224
     *
225
     * \param unit which unit rx or tx
226
     * \return the clock rate in Hz
227
     */
228
    virtual double get_clock_rate(unit_t unit) = 0;
229

    
230
    /*!
231
     * Get a list of possible rates for the dboard clock.
232
     *
233
     * \param unit which unit rx or tx
234
     * \return a list of clock rates in Hz
235
     */
236
    virtual std::vector<double> get_clock_rates(unit_t unit) = 0;
237

    
238
    /*!
239
     * Enable or disable a dboard clock.
240
     *
241
     * \param unit which unit rx or tx
242
     * \param enb true for enabled
243
     */
244
    virtual void set_clock_enabled(unit_t unit, bool enb) = 0;
245
};
246

    
247
}} //namespace
248

    
249
#endif /* INCLUDED_UHD_USRP_DBOARD_IFACE_HPP */