Imported Upstream version 3.0
[debian/gnuradio] / gr-usrp / src / usrp1_sink_s.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <usrp1_sink_s.h>
28 #include <gr_io_signature.h>
29 #include <usrp_standard.h>
30 #include <usrp_bytesex.h>
31
32 usrp1_sink_s_sptr
33 usrp1_make_sink_s (int which_board,
34                    unsigned int interp_rate,
35                    int nchan,
36                    int mux,
37                    int fusb_block_size,
38                    int fusb_nblocks,
39                    const std::string fpga_filename,
40                    const std::string firmware_filename
41                    ) throw (std::runtime_error)
42 {
43   return usrp1_sink_s_sptr (new usrp1_sink_s (which_board,
44                                               interp_rate,
45                                               nchan,
46                                               mux,
47                                               fusb_block_size,
48                                               fusb_nblocks,
49                                               fpga_filename,
50                                               firmware_filename
51                                               ));
52 }
53
54
55 usrp1_sink_s::usrp1_sink_s (int which_board,
56                             unsigned int interp_rate,
57                             int nchan,
58                             int mux,
59                             int fusb_block_size,
60                             int fusb_nblocks,
61                             const std::string fpga_filename,
62                             const std::string firmware_filename
63                             ) throw (std::runtime_error)
64   : usrp1_sink_base ("usrp1_sink_s",
65                      gr_make_io_signature (1, 1, sizeof (short)),
66                      which_board, interp_rate, nchan, mux,
67                      fusb_block_size, fusb_nblocks,
68                      fpga_filename, firmware_filename)
69 {
70   set_output_multiple (512 / sizeof(short));    // don't change
71 }
72
73 usrp1_sink_s::~usrp1_sink_s ()
74 {
75   // NOP
76 }
77
78 /*
79  * Take one short input stream and format it into interleaved short I & Q
80  * for the usrp.
81  */
82 void
83 usrp1_sink_s::copy_to_usrp_buffer (gr_vector_const_void_star &input_items,
84                                    int  input_index,
85                                    int  input_items_available,
86                                    int  &input_items_consumed,  // out
87                                    void *usrp_buffer,
88                                    int  usrp_buffer_length,
89                                    int  &bytes_written)         // out
90 {
91   short *in = &((short *) input_items[0])[input_index];
92   short *dst = (short *) usrp_buffer;
93
94   static const int usrp_bytes_per_input_item = sizeof (short);
95
96   int nitems = std::min (input_items_available,
97                          usrp_buffer_length / usrp_bytes_per_input_item);
98
99   for (int i = 0; i < nitems; i++){     // FIXME unroll
100     dst[i] = host_to_usrp_short(in[i]);
101   }
102
103   input_items_consumed = nitems;
104   bytes_written = nitems * usrp_bytes_per_input_item;
105 }
106