3 * Copyright 2004,2008 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 <usrp_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 usrp_sink_base::usrp_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)
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 usrp");
61 set_usrp_basic(d_usrp);
63 // All calls to d_usrp->write must be multiples of 512 bytes.
65 set_output_multiple (OUTPUT_MULTIPLE_SAMPLES);
68 usrp_sink_base::~usrp_sink_base ()
73 usrp_sink_base::work (int noutput_items,
74 gr_vector_const_void_star &input_items,
75 gr_vector_void_star &output_items)
77 static const int BUFSIZE = 16 * (1L << 10); // 16kB
78 unsigned char outbuf[BUFSIZE];
81 int input_items_consumed;
86 while (input_index < noutput_items){
88 copy_to_usrp_buffer (input_items,
90 noutput_items - input_index, // input_items_available
91 input_items_consumed, // [out]
92 &outbuf[obi], // [out] usrp_buffer
93 BUFSIZE - obi, // usrp_buffer_length
94 bytes_written); // [out]
96 assert (input_index + input_items_consumed <= noutput_items);
97 assert (obi + bytes_written <= BUFSIZE);
99 input_index += input_items_consumed;
100 obi += bytes_written;
102 if (obi >= BUFSIZE){ // flush
103 if (d_usrp->write (outbuf, obi, &underrun) != obi)
104 return -1; // indicate we're done
108 // fprintf (stderr, "usrp_sink: underrun\n");
109 fputs ("uU", stderr);
116 assert (obi % 512 == 0);
117 if (d_usrp->write (outbuf, obi, &underrun) != obi)
118 return -1; // indicate we're done
122 // fprintf (stderr, "usrp_sink: underrun\n");
123 fputs ("uU", stderr);
127 return noutput_items;
131 usrp_sink_base::set_interp_rate (unsigned int rate)
133 return d_usrp->set_interp_rate (rate);
137 usrp_sink_base::set_nchannels (int nchan)
139 return d_usrp->set_nchannels (nchan);
143 usrp_sink_base::set_mux (int mux)
145 return d_usrp->set_mux (mux);
149 usrp_sink_base::determine_tx_mux_value(usrp_subdev_spec ss)
151 return d_usrp->determine_tx_mux_value(ss);
155 usrp_sink_base::set_tx_freq (int channel, double freq)
157 return d_usrp->set_tx_freq (channel, freq);
161 usrp_sink_base::interp_rate () const
163 return d_usrp->interp_rate ();
167 usrp_sink_base::nchannels () const
169 return d_usrp->nchannels ();
173 usrp_sink_base::mux () const
175 return d_usrp->mux ();
180 usrp_sink_base::tx_freq (int channel) const
182 return d_usrp->tx_freq (channel);
186 usrp_sink_base::has_rx_halfband()
188 return d_usrp->has_rx_halfband();
192 usrp_sink_base::has_tx_halfband()
194 return d_usrp->has_tx_halfband();
198 usrp_sink_base::nddcs()
200 return d_usrp->nddcs();
204 usrp_sink_base::nducs()
206 return d_usrp->nducs();
210 usrp_sink_base::start()
212 return d_usrp->start();
216 usrp_sink_base::stop()
218 return d_usrp->stop();
223 usrp_sink_base::tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result)
225 return d_usrp->tune(chan, db, target_freq, result);
229 usrp_sink_base::pick_tx_subdevice()
232 USRP_DBID_FLEX_400_TX,
233 USRP_DBID_FLEX_900_TX,
234 USRP_DBID_FLEX_1200_TX,
235 USRP_DBID_FLEX_2400_TX,
239 std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int)));
240 return pick_subdev(candidates);