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>
33 static const int OUTPUT_MULTIPLE_SAMPLES = 128; // DON'T CHANGE THIS VALUE!
35 usrp_sink_base::usrp_sink_base (const std::string &name,
36 gr_io_signature_sptr input_signature,
38 unsigned int interp_rate,
43 const std::string fpga_filename,
44 const std::string firmware_filename
45 ) throw (std::runtime_error)
48 gr_make_io_signature (0, 0, 0)),
51 d_usrp = usrp_standard_tx::make (which_board,
60 throw std::runtime_error ("can't open usrp");
62 set_usrp_basic(d_usrp);
64 // All calls to d_usrp->write must be multiples of 512 bytes.
66 set_output_multiple (OUTPUT_MULTIPLE_SAMPLES);
69 usrp_sink_base::~usrp_sink_base ()
74 usrp_sink_base::work (int noutput_items,
75 gr_vector_const_void_star &input_items,
76 gr_vector_void_star &output_items)
78 static const int BUFSIZE = 16 * (1L << 10); // 16kB
79 unsigned char outbuf[BUFSIZE];
82 int input_items_consumed;
87 while (input_index < noutput_items){
89 copy_to_usrp_buffer (input_items,
91 noutput_items - input_index, // input_items_available
92 input_items_consumed, // [out]
93 &outbuf[obi], // [out] usrp_buffer
94 BUFSIZE - obi, // usrp_buffer_length
95 bytes_written); // [out]
97 assert (input_index + input_items_consumed <= noutput_items);
98 assert (obi + bytes_written <= BUFSIZE);
100 input_index += input_items_consumed;
101 obi += bytes_written;
103 if (obi >= BUFSIZE){ // flush
104 if (d_usrp->write (outbuf, obi, &underrun) != obi)
105 return -1; // indicate we're done
109 // fprintf (stderr, "usrp_sink: underrun\n");
110 fputs ("uU", stderr);
117 assert (obi % 512 == 0);
118 if (d_usrp->write (outbuf, obi, &underrun) != obi)
119 return -1; // indicate we're done
123 // fprintf (stderr, "usrp_sink: underrun\n");
124 fputs ("uU", stderr);
128 return noutput_items;
132 usrp_sink_base::set_interp_rate (unsigned int rate)
134 return d_usrp->set_interp_rate (rate);
138 usrp_sink_base::set_nchannels (int nchan)
140 return d_usrp->set_nchannels (nchan);
144 usrp_sink_base::set_mux (int mux)
146 return d_usrp->set_mux (mux);
150 usrp_sink_base::determine_tx_mux_value(usrp_subdev_spec ss)
152 return d_usrp->determine_tx_mux_value(ss);
156 usrp_sink_base::determine_tx_mux_value(usrp_subdev_spec ss_a, usrp_subdev_spec ss_b)
158 return d_usrp->determine_tx_mux_value(ss_a, ss_b);
162 usrp_sink_base::set_tx_freq (int channel, double freq)
164 return d_usrp->set_tx_freq (channel, freq);
168 usrp_sink_base::interp_rate () const
170 return d_usrp->interp_rate ();
174 usrp_sink_base::nchannels () const
176 return d_usrp->nchannels ();
180 usrp_sink_base::mux () const
182 return d_usrp->mux ();
187 usrp_sink_base::tx_freq (int channel) const
189 return d_usrp->tx_freq (channel);
193 usrp_sink_base::has_rx_halfband()
195 return d_usrp->has_rx_halfband();
199 usrp_sink_base::has_tx_halfband()
201 return d_usrp->has_tx_halfband();
205 usrp_sink_base::nddcs()
207 return d_usrp->nddcs();
211 usrp_sink_base::nducs()
213 return d_usrp->nducs();
217 usrp_sink_base::start()
219 return d_usrp->start();
223 usrp_sink_base::stop()
225 return d_usrp->stop();
230 usrp_sink_base::tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result)
232 return d_usrp->tune(chan, db, target_freq, result);
236 usrp_sink_base::pick_tx_subdevice()
239 USRP_DBID_FLEX_400_TX,
240 USRP_DBID_FLEX_900_TX,
241 USRP_DBID_FLEX_1200_TX,
242 USRP_DBID_FLEX_2400_TX,
246 std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int)));
247 return pick_subdev(candidates);