3 * Copyright 2004 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 3, 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.
27 #include <usrp1_sink_base.h>
28 #include <gr_io_signature.h>
29 #include <usrp_standard.h>
32 static const int OUTPUT_MULTIPLE_SAMPLES = 128; // DON'T CHANGE THIS VALUE!
34 usrp1_sink_base::usrp1_sink_base (const std::string &name,
35 gr_io_signature_sptr input_signature,
37 unsigned int interp_rate,
42 const std::string fpga_filename,
43 const std::string firmware_filename
44 ) throw (std::runtime_error)
45 : gr_sync_block (name,
47 gr_make_io_signature (0, 0, 0)),
50 d_usrp = usrp_standard_tx::make (which_board,
59 throw std::runtime_error ("can't open usrp1");
61 // All calls to d_usrp->write must be multiples of 512 bytes.
63 set_output_multiple (OUTPUT_MULTIPLE_SAMPLES);
66 usrp1_sink_base::~usrp1_sink_base ()
72 usrp1_sink_base::start()
74 return d_usrp->start();
78 usrp1_sink_base::stop()
80 return d_usrp->stop();
84 usrp1_sink_base::work (int noutput_items,
85 gr_vector_const_void_star &input_items,
86 gr_vector_void_star &output_items)
88 static const int BUFSIZE = 16 * (1L << 10); // 16kB
89 unsigned char outbuf[BUFSIZE];
92 int input_items_consumed;
97 while (input_index < noutput_items){
99 copy_to_usrp_buffer (input_items,
101 noutput_items - input_index, // input_items_available
102 input_items_consumed, // [out]
103 &outbuf[obi], // [out] usrp_buffer
104 BUFSIZE - obi, // usrp_buffer_length
105 bytes_written); // [out]
107 assert (input_index + input_items_consumed <= noutput_items);
108 assert (obi + bytes_written <= BUFSIZE);
110 input_index += input_items_consumed;
111 obi += bytes_written;
113 if (obi >= BUFSIZE){ // flush
114 if (d_usrp->write (outbuf, obi, &underrun) != obi)
115 return -1; // indicate we're done
119 // fprintf (stderr, "usrp1_sink: underrun\n");
120 fputs ("uU", stderr);
127 assert (obi % 512 == 0);
128 if (d_usrp->write (outbuf, obi, &underrun) != obi)
129 return -1; // indicate we're done
133 // fprintf (stderr, "usrp1_sink: underrun\n");
134 fputs ("uU", stderr);
138 return noutput_items;
142 usrp1_sink_base::set_interp_rate (unsigned int rate)
144 return d_usrp->set_interp_rate (rate);
148 usrp1_sink_base::set_nchannels (int nchan)
150 return d_usrp->set_nchannels (nchan);
154 usrp1_sink_base::set_mux (int mux)
156 return d_usrp->set_mux (mux);
160 usrp1_sink_base::set_tx_freq (int channel, double freq)
162 return d_usrp->set_tx_freq (channel, freq);
166 usrp1_sink_base::fpga_master_clock_freq() const
168 return d_usrp->fpga_master_clock_freq();
172 usrp1_sink_base::converter_rate () const
174 return d_usrp->converter_rate ();
178 usrp1_sink_base::interp_rate () const
180 return d_usrp->interp_rate ();
184 usrp1_sink_base::nchannels () const
186 return d_usrp->nchannels ();
190 usrp1_sink_base::mux () const
192 return d_usrp->mux ();
197 usrp1_sink_base::tx_freq (int channel) const
199 return d_usrp->tx_freq (channel);
203 usrp1_sink_base::set_verbose (bool verbose)
205 d_usrp->set_verbose (verbose);
209 usrp1_sink_base::write_aux_dac (int which_dboard, int which_dac, int value)
211 return d_usrp->write_aux_dac (which_dboard, which_dac, value);
215 usrp1_sink_base::read_aux_adc (int which_dboard, int which_adc)
217 return d_usrp->read_aux_adc (which_dboard, which_adc);
221 usrp1_sink_base::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf)
223 return d_usrp->write_eeprom (i2c_addr, eeprom_offset, buf);
227 usrp1_sink_base::read_eeprom (int i2c_addr, int eeprom_offset, int len)
229 return d_usrp->read_eeprom (i2c_addr, eeprom_offset, len);
233 usrp1_sink_base::write_i2c (int i2c_addr, const std::string buf)
235 return d_usrp->write_i2c (i2c_addr, buf);
239 usrp1_sink_base::read_i2c (int i2c_addr, int len)
241 return d_usrp->read_i2c (i2c_addr, len);
245 usrp1_sink_base::set_pga (int which, double gain)
247 return d_usrp->set_pga (which, gain);
251 usrp1_sink_base::pga (int which) const
253 return d_usrp->pga (which);
257 usrp1_sink_base::pga_min () const
259 return d_usrp->pga_min ();
263 usrp1_sink_base::pga_max () const
265 return d_usrp->pga_max ();
269 usrp1_sink_base::pga_db_per_step () const
271 return d_usrp->pga_db_per_step ();
275 usrp1_sink_base::daughterboard_id (int which) const
277 return d_usrp->daughterboard_id (which);
281 usrp1_sink_base::set_adc_offset (int which, int offset)
283 return d_usrp->set_adc_offset (which, offset);
287 usrp1_sink_base::set_dac_offset (int which, int offset, int offset_pin)
289 return d_usrp->set_dac_offset (which, offset, offset_pin);
293 usrp1_sink_base::set_adc_buffer_bypass (int which, bool bypass)
295 return d_usrp->set_adc_buffer_bypass (which, bypass);
299 usrp1_sink_base::serial_number()
301 return d_usrp->serial_number();
305 usrp1_sink_base::_write_oe (int which_dboard, int value, int mask)
307 return d_usrp->_write_oe (which_dboard, value, mask);
311 usrp1_sink_base::write_io (int which_dboard, int value, int mask)
313 return d_usrp->write_io (which_dboard, value, mask);
317 usrp1_sink_base::read_io (int which_dboard)
319 return d_usrp->read_io (which_dboard);
322 // internal routines...
325 usrp1_sink_base::_write_fpga_reg (int regno, int value)
327 return d_usrp->_write_fpga_reg (regno, value);
331 usrp1_sink_base::_read_fpga_reg (int regno)
333 return d_usrp->_read_fpga_reg (regno);
337 usrp1_sink_base::_write_9862 (int which_codec, int regno, unsigned char value)
339 return d_usrp->_write_9862 (which_codec, regno, value);
343 usrp1_sink_base::_read_9862 (int which_codec, int regno) const
345 return d_usrp->_read_9862 (which_codec, regno);
349 usrp1_sink_base::_write_spi (int optional_header, int enables,
350 int format, std::string buf)
352 return d_usrp->_write_spi (optional_header, enables, format, buf);
356 usrp1_sink_base::_read_spi (int optional_header, int enables, int format, int len)
358 return d_usrp->_read_spi (optional_header, enables, format, len);