3 * Copyright 2004,2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_USRP1_SINK_BASE_H
24 #define INCLUDED_USRP1_SINK_BASE_H
26 #include <gr_sync_block.h>
29 class usrp_standard_tx;
33 * \brief abstract interface to Universal Software Radio Peripheral Tx path (Rev 1)
35 class usrp1_sink_base : public gr_sync_block {
37 usrp_standard_tx *d_usrp;
41 usrp1_sink_base (const std::string &name,
42 gr_io_signature_sptr input_signature,
44 unsigned int interp_rate,
49 const std::string fpga_filename,
50 const std::string firmware_filename
51 ) throw (std::runtime_error);
54 * \brief convert between input item format and usrp native format
56 * \param input_items[in] stream(s) of input items
57 * \param input_index[in] starting index in input_items
58 * \param input_items_available[in] number of items available starting at item[index]
59 * \param input_items_consumed[out] number of input items consumed by copy
60 * \param usrp_buffer[out] destination buffer
61 * \param usrp_buffer_length[in] \p usrp_buffer length in bytes
62 * \param bytes_written[out] number of bytes written into \p usrp_buffer
64 virtual void copy_to_usrp_buffer (gr_vector_const_void_star &input_items,
66 int input_items_available,
67 int &input_items_consumed,
69 int usrp_buffer_length,
70 int &bytes_written) = 0;
73 //! magic value used on alternate register read interfaces
74 static const int READ_FAILED = -99999;
79 int work (int noutput_items,
80 gr_vector_const_void_star &input_items,
81 gr_vector_void_star &output_items);
87 * \brief Set interpolator rate. \p rate must be in [4, 1024] and a multiple of 4.
89 * The final complex sample rate across the USB is
90 * dac_freq () / interp_rate () * nchannels ()
92 bool set_interp_rate (unsigned int rate);
93 bool set_nchannels (int nchan);
94 bool set_mux (int mux);
97 * \brief set the frequency of the digital up converter.
99 * \p channel must be 0. \p freq is the center frequency in Hz.
100 * It must be in the range [-44M, 44M]. The frequency specified is
101 * quantized. Use tx_freq to retrieve the actual value used.
103 bool set_tx_freq (int channel, double freq);
105 void set_verbose (bool verbose);
108 * \brief Set Programmable Gain Amplifier (PGA)
110 * \param which which D/A [0,3]
111 * \param gain_in_db gain value (linear in dB)
113 * gain is rounded to closest setting supported by hardware.
114 * Note that DAC 0 and DAC 1 share a gain setting as do DAC 2 and DAC 3.
115 * Setting DAC 0 affects DAC 1 and vice versa. Same with DAC 2 and DAC 3.
117 * \returns true iff sucessful.
119 * \sa pga_min(), pga_max(), pga_db_per_step()
121 bool set_pga (int which, double gain_in_db);
124 * \brief Return programmable gain amplifier gain in dB.
126 * \param which which D/A [0,3]
128 double pga (int which) const;
131 * \brief Return minimum legal PGA gain in dB.
133 double pga_min () const;
136 * \brief Return maximum legal PGA gain in dB.
138 double pga_max () const;
141 * \brief Return hardware step size of PGA (linear in dB).
143 double pga_db_per_step () const;
148 long fpga_master_clock_freq() const;
149 long converter_rate() const;
150 long dac_rate() const { return converter_rate(); } // alias
151 long dac_freq() const { return converter_rate(); } // deprecated alias
153 unsigned int interp_rate () const;
154 int nchannels () const;
156 double tx_freq (int channel) const;
157 int nunderruns () const { return d_nunderruns; }
160 * \brief Return daughterboard ID for given Rx daughterboard slot [0,1].
162 * \return daughterboard id >= 0 if successful
163 * \return -1 if no daugherboard
164 * \return -2 if invalid EEPROM on daughterboard
166 int daughterboard_id (int which_dboard) const;
169 * \brief Write auxiliary digital to analog converter.
171 * \param which_dboard [0,1] which d'board
172 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's.
173 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's.
174 * \param which_dac [2,3] TX slots must use only 2 and 3.
175 * \param value [0,4095]
176 * \returns true iff successful
178 bool write_aux_dac (int which_board, int which_dac, int value);
181 * \brief Read auxiliary analog to digital converter.
183 * \param which_dboard [0,1] which d'board
184 * \param which_adc [0,1]
185 * \returns value in the range [0,4095] if successful, else READ_FAILED.
187 int read_aux_adc (int which_dboard, int which_adc);
190 * \brief Write EEPROM on motherboard or any daughterboard.
191 * \param i2c_addr I2C bus address of EEPROM
192 * \param eeprom_offset byte offset in EEPROM to begin writing
193 * \param buf the data to write
194 * \returns true iff sucessful
196 bool write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf);
199 * \brief Write EEPROM on motherboard or any daughterboard.
200 * \param i2c_addr I2C bus address of EEPROM
201 * \param eeprom_offset byte offset in EEPROM to begin reading
202 * \param len number of bytes to read
203 * \returns the data read if successful, else a zero length string.
205 std::string read_eeprom (int i2c_addr, int eeprom_offset, int len);
208 * \brief Write to I2C peripheral
209 * \param i2c_addr I2C bus address (7-bits)
210 * \param buf the data to write
211 * \returns true iff successful
212 * Writes are limited to a maximum of of 64 bytes.
214 bool write_i2c (int i2c_addr, const std::string buf);
217 * \brief Read from I2C peripheral
218 * \param i2c_addr I2C bus address (7-bits)
219 * \param len number of bytes to read
220 * \returns the data read if successful, else a zero length string.
221 * Reads are limited to a maximum of of 64 bytes.
223 std::string read_i2c (int i2c_addr, int len);
226 * \brief Set ADC offset correction
227 * \param which which ADC[0,3]: 0 = RX_A I, 1 = RX_A Q...
228 * \param offset 16-bit value to subtract from raw ADC input.
230 bool set_adc_offset (int which, int offset);
233 * \brief Set DAC offset correction
234 * \param which which DAC[0,3]: 0 = TX_A I, 1 = TX_A Q...
235 * \param offset 10-bit offset value (ambiguous format: See AD9862 datasheet).
236 * \param offset_pin 1-bit value. If 0 offset applied to -ve differential pin;
237 * If 1 offset applied to +ve differential pin.
239 bool set_dac_offset (int which, int offset, int offset_pin);
242 * \brief Control ADC input buffer
243 * \param which which ADC[0,3]
244 * \param bypass if non-zero, bypass input buffer and connect input
245 * directly to switched cap SHA input of RxPGA.
247 bool set_adc_buffer_bypass (int which, bool bypass);
250 * \brief return the usrp's serial number.
252 * \returns non-zero length string iff successful.
254 std::string serial_number();
257 * \brief Write direction register (output enables) for pins that go to daughterboard.
259 * \param which_dboard [0,1] which d'board
260 * \param value value to write into register
261 * \param mask which bits of value to write into reg
263 * Each d'board has 16-bits of general purpose i/o.
264 * Setting the bit makes it an output from the FPGA to the d'board.
266 * This register is initialized based on a value stored in the
267 * d'board EEPROM. In general, you shouldn't be using this routine
268 * without a very good reason. Using this method incorrectly will
269 * kill your USRP motherboard and/or daughterboard.
271 bool _write_oe (int which_dboard, int value, int mask);
274 * \brief Write daughterboard i/o pin value
276 * \param which_dboard [0,1] which d'board
277 * \param value value to write into register
278 * \param mask which bits of value to write into reg
280 bool write_io (int which_dboard, int value, int mask);
283 * \brief Read daughterboard i/o pin value
285 * \param which_dboard [0,1] which d'board
286 * \returns register value if successful, else READ_FAILED
288 int read_io (int which_dboard);
291 // internal routines...
292 // You probably shouldn't be using these...
295 * \brief Write FPGA register.
296 * \param regno 7-bit register number
297 * \param value 32-bit value
298 * \returns true iff successful
300 bool _write_fpga_reg (int regno, int value); //< 7-bit regno, 32-bit value
303 * \brief Read FPGA register.
304 * \param regno 7-bit register number
305 * \returns register value if successful, else READ_FAILED
307 int _read_fpga_reg (int regno);
310 * \brief Write AD9862 register.
311 * \param which_codec 0 or 1
312 * \param regno 6-bit register number
313 * \param value 8-bit value
314 * \returns true iff successful
316 bool _write_9862 (int which_codec, int regno, unsigned char value);
319 * \brief Read AD9862 register.
320 * \param which_codec 0 or 1
321 * \param regno 6-bit register number
322 * \returns register value if successful, else READ_FAILED
324 int _read_9862 (int which_codec, int regno) const;
327 * \brief Write data to SPI bus peripheral.
329 * \param optional_header 0,1 or 2 bytes to write before buf.
330 * \param enables bitmask of peripherals to write. See usrp_spi_defs.h
331 * \param format transaction format. See usrp_spi_defs.h SPI_FMT_*
332 * \param buf the data to write
333 * \returns true iff successful
334 * Writes are limited to a maximum of 64 bytes.
336 * If \p format specifies that optional_header bytes are present, they are
337 * written to the peripheral immediately prior to writing \p buf.
339 bool _write_spi (int optional_header, int enables, int format, std::string buf);
342 * \brief Read data from SPI bus peripheral.
344 * \param optional_header 0,1 or 2 bytes to write before buf.
345 * \param enables bitmask of peripheral to read. See usrp_spi_defs.h
346 * \param format transaction format. See usrp_spi_defs.h SPI_FMT_*
347 * \param len number of bytes to read. Must be in [0,64].
348 * \returns the data read if sucessful, else a zero length string.
350 * Reads are limited to a maximum of 64 bytes.
352 * If \p format specifies that optional_header bytes are present, they
353 * are written to the peripheral first. Then \p len bytes are read from
354 * the peripheral and returned.
356 std::string _read_spi (int optional_header, int enables, int format, int len);
359 #endif /* INCLUDED_USRP1_SINK_BASE_H */