3 * Copyright 2003,2006,2008,2009 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.
34 #include "time_stuff.h"
35 #include <usrp/usrp_standard.h>
36 #include <usrp/usrp_bytesex.h>
37 #include "fpga_regs_common.h"
38 #include "fpga_regs_standard.h"
46 static bool test_input (usrp_standard_rx_sptr urx, int max_bytes, FILE *fp);
49 set_progname (char *path)
51 char *p = strrchr (path, '/');
61 fprintf (stderr, "usage: %s [-f] [-v] [-l] [-c] [-D <decim>] [-F freq] [-o output_file]\n", prog_name);
62 fprintf (stderr, " [-f] loop forever\n");
63 fprintf (stderr, " [-M] how many Megabytes to transfer (default 128)\n");
64 fprintf (stderr, " [-v] verbose\n");
65 fprintf (stderr, " [-l] digital loopback in FPGA\n");
66 fprintf (stderr, " [-c] counting in FPGA\n");
67 fprintf (stderr, " [-8] 8-bit samples across USB\n");
68 fprintf (stderr, " [-B <fusb_block_size>] set fast usb block_size\n");
69 fprintf (stderr, " [-N <fusb_nblocks>] set fast usb nblocks\n");
70 fprintf (stderr, " [-R] set real time scheduling: SCHED_FIFO; pri = midpoint\n");
78 fprintf (stderr, "die: %s: %s\n", prog_name, msg);
83 main (int argc, char **argv)
85 bool verbose_p = false;
86 bool loopback_p = false;
87 bool counting_p = false;
88 bool width_8_p = false;
89 int max_bytes = 128 * (1L << 20);
91 char *output_filename = 0;
93 int decim = 8; // 32 MB/sec
94 double center_freq = 0;
95 int fusb_block_size = 0;
97 bool realtime_p = false;
100 set_progname (argv[0]);
102 while ((ch = getopt (argc, argv, "fvlco:D:F:M:8B:N:R")) != EOF){
125 output_filename = optarg;
129 decim = strtol (optarg, 0, 0);
133 center_freq = strtod (optarg, 0);
137 max_bytes = strtol (optarg, 0, 0) * (1L << 20);
138 if (max_bytes < 0) max_bytes = 0;
142 fusb_block_size = strtol (optarg, 0, 0);
146 fusb_nblocks = strtol (optarg, 0, 0);
158 #ifdef HAVE_SCHED_SETSCHEDULER
160 int policy = SCHED_FIFO;
161 int pri = (sched_get_priority_max (policy) - sched_get_priority_min (policy)) / 2;
162 int pid = 0; // this process
164 struct sched_param param;
165 memset(¶m, 0, sizeof(param));
166 param.sched_priority = pri;
167 int result = sched_setscheduler(pid, policy, ¶m);
169 perror ("sched_setscheduler: failed to set real time priority");
172 printf("SCHED_FIFO enabled with priority = %d\n", pri);
178 if (output_filename){
179 fp = fopen (output_filename, "wb");
181 perror (output_filename);
186 mode |= usrp_standard_rx::FPGA_MODE_LOOPBACK;
188 mode |= usrp_standard_rx::FPGA_MODE_COUNTING;
191 usrp_standard_rx_sptr urx =
192 usrp_standard_rx::make (which_board, decim, 1, -1, mode,
193 fusb_block_size, fusb_nblocks);
196 die ("usrp_standard_rx::make");
198 if (!urx->set_rx_freq (0, center_freq))
199 die ("urx->set_rx_freq");
205 if (!urx->set_format(usrp_standard_rx::make_format(width, shift, want_q)))
206 die("urx->set_format");
209 urx->start(); // start data xfers
211 test_input (urx, max_bytes, fp);
221 test_input (usrp_standard_rx_sptr urx, int max_bytes, FILE *fp)
224 static const int BUFSIZE = urx->block_size();
225 static const int N = BUFSIZE/sizeof (short);
229 double start_wall_time = get_elapsed_time ();
230 double start_cpu_time = get_cpu_usage ();
238 for (nbytes = 0; max_bytes == 0 || nbytes < max_bytes; nbytes += BUFSIZE){
240 unsigned int ret = urx->read (buf, sizeof (buf), &overrun);
241 if (ret != sizeof (buf)){
242 fprintf (stderr, "test_input: error, ret = %d\n", ret);
246 printf ("rx_overrun\n");
252 for (unsigned int i = 0; i < sizeof (buf) / sizeof (short); i++)
253 buf[i] = usrp_to_host_short (buf[i]);
255 if (write (fd, buf, sizeof (buf)) == -1){
262 double stop_wall_time = get_elapsed_time ();
263 double stop_cpu_time = get_cpu_usage ();
265 double delta_wall = stop_wall_time - start_wall_time;
266 double delta_cpu = stop_cpu_time - start_cpu_time;
268 printf ("xfered %.3g bytes in %.3g seconds. %.4g bytes/sec. cpu time = %.4g\n",
269 (double) max_bytes, delta_wall, max_bytes / delta_wall, delta_cpu);
270 printf ("noverruns = %d\n", noverruns);