[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9033 - in usrp2/branches/developers/eb/wip/host-ng: .
From: |
eb |
Subject: |
[Commit-gnuradio] r9033 - in usrp2/branches/developers/eb/wip/host-ng: . apps include/usrp2 lib |
Date: |
Mon, 28 Jul 2008 16:24:53 -0600 (MDT) |
Author: eb
Date: 2008-07-28 16:24:53 -0600 (Mon, 28 Jul 2008)
New Revision: 9033
Added:
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/copiers.h
usrp2/branches/developers/eb/wip/host-ng/lib/copiers.cc
Modified:
usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
usrp2/branches/developers/eb/wip/host-ng/configure.ac
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/Makefile.am
usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am
usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc
usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
Log:
usrp2 work-in-progress
Modified: usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
2008-07-28 06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
2008-07-28 22:24:53 UTC (rev 9033)
@@ -24,12 +24,17 @@
#include <usrp2/tune_result.h>
#include <usrp2/strtod_si.h>
#include <usrp2/rx_sample_handler.h>
+#include <usrp2/copiers.h>
#include <gruel/realtime.h>
#include <sys/time.h>
#include <iostream>
#include <string.h>
#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+#include <stdexcept>
+// ------------------------------------------------------------------------
+
class rx_nop_handler : public usrp2::rx_sample_handler
{
size_t d_max_samples;
@@ -45,6 +50,7 @@
size_t nframes() const { return d_nframes; }
size_t nsamples() const { return d_nsamples; }
+ size_t max_samples() const { return d_max_samples; }
bool
operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata
*metadata)
@@ -61,7 +67,115 @@
// nop
}
+// ------------------------------------------------------------------------
+// FIXME make this a template
+
+class complex_16_file_writer : public rx_nop_handler
+{
+ FILE *d_fp;
+ std::string d_filename;
+
+public:
+
+ complex_16_file_writer(const std::string &filename, size_t max_samples)
+ : rx_nop_handler(max_samples), d_filename(filename)
+ {
+ d_fp = fopen(filename.c_str(), "wb");
+ if (d_fp == 0){
+ perror(filename.c_str());
+ throw std::invalid_argument(filename);
+ }
+ }
+
+ ~complex_16_file_writer();
+
+ bool
+ operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata
*metadata)
+ {
+ bool ok = rx_nop_handler::operator()(items, nitems, metadata);
+
+ size_t host_nitems = nitems;
+ std::complex<int16_t> host_items[host_nitems];
+
+ usrp2::copy_u2_complex_16_to_host_complex_16(nitems, items, host_items);
+
+ size_t n = 0;
+ while (n < host_nitems){
+ size_t r = fwrite(&host_items[n], sizeof(host_items[0]), host_nitems -
n, d_fp);
+ n += r;
+ if (r == 0){ // out of space?
+ perror(d_filename.c_str());
+ ok = false;
+ break;
+ }
+ }
+
+ return ok;
+ }
+};
+
+complex_16_file_writer::~complex_16_file_writer()
+{
+ fclose(d_fp);
+}
+
+// ------------------------------------------------------------------------
+
+class complex_float_file_writer : public rx_nop_handler
+{
+ FILE *d_fp;
+ std::string d_filename;
+
+public:
+
+ complex_float_file_writer(const std::string &filename, size_t max_samples)
+ : rx_nop_handler(max_samples), d_filename(filename)
+ {
+ d_fp = fopen(filename.c_str(), "wb");
+ if (d_fp == 0){
+ perror(filename.c_str());
+ throw std::invalid_argument(filename);
+ }
+ }
+
+ ~complex_float_file_writer();
+
+ bool
+ operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata
*metadata)
+ {
+ bool ok = rx_nop_handler::operator()(items, nitems, metadata);
+
+ size_t host_nitems = nitems;
+ std::complex<float> host_items[host_nitems];
+
+ usrp2::copy_u2_complex_16_to_host_complex_float(nitems, items, host_items);
+
+ size_t n = 0;
+ while (n < host_nitems){
+ size_t r = fwrite(&host_items[n], sizeof(host_items[0]), host_nitems -
n, d_fp);
+ n += r;
+ if (r == 0){ // out of space?
+ perror(d_filename.c_str());
+ ok = false;
+ break;
+ }
+ }
+
+ return ok;
+ }
+};
+
+complex_float_file_writer::~complex_float_file_writer()
+{
+ fclose(d_fp);
+}
+
+// ------------------------------------------------------------------------
+
+
+
+
static void
usage(const char *progname)
{
@@ -80,8 +194,10 @@
fprintf(stderr, " -f FREQUENCY specify receive center frequency in
Hz [default=0.0]\n");
fprintf(stderr, " -d DECIM specify receive decimation rate
[default=5]\n");
fprintf(stderr, " -g GAIN specify receive daughterboard gain
[default=0]\n");
- fprintf(stderr, " -n NSAMPLES specify number of samples to receive
[default=250e6]\n");
- fprintf(stderr, " -b BUFSIZE specify size of receive buffer
[default=64k]\n");
+ fprintf(stderr, " -N NSAMPLES specify number of samples to receive
[default=250e6]\n");
+//fprintf(stderr, " -b BUFSIZE specify size of receive buffer
[default=64k]\n");
+ fprintf(stderr, " -o OUTPUT_FILENAME specify file to receive samples
[default=none]\n");
+ fprintf(stderr, " -s write complex<short>
[default=complex<float>]\n");
}
int
@@ -94,11 +210,12 @@
int rx_decim = 5;
double rx_gain = 0.0;
size_t nsamples = static_cast<size_t>(250e6);
- size_t bufsize = 65536;
-
+ bool output_shorts = false;
+ char *output_filename = 0;
+
int ch;
- while ((ch = getopt(argc, argv, "he:m:f:d:g:n:b:")) != EOF){
+ while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:s")) != EOF){
double tmp;
switch (ch){
@@ -135,7 +252,7 @@
}
break;
- case 'n':
+ case 'N':
if (!strtod_si(optarg, &tmp)) {
std::cerr << "invalid number: " << optarg << std::endl;
usage(argv[0]);
@@ -144,6 +261,7 @@
nsamples = static_cast<size_t>(tmp);
break;
+#if 0
case 'b':
if (!strtod_si(optarg, &tmp)) {
std::cerr << "invalid number: " << optarg << std::endl;
@@ -152,6 +270,15 @@
}
bufsize = static_cast<size_t>(tmp);
break;
+#endif
+
+ case 's':
+ output_shorts = true;
+ break;
+
+ case 'o':
+ output_filename = optarg;
+ break;
case 'h':
default:
@@ -160,6 +287,20 @@
}
}
+
+ typedef boost::shared_ptr<rx_nop_handler> handler_sptr;
+ handler_sptr handler;
+
+ if (output_filename){
+ if (output_shorts)
+ handler = handler_sptr(new complex_16_file_writer(output_filename,
nsamples));
+ else
+ handler = handler_sptr(new complex_float_file_writer(output_filename,
nsamples));
+ }
+ else
+ handler = handler_sptr(new rx_nop_handler(nsamples));
+
+
gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
if (rt != gruel::RT_OK)
std::cerr << "Failed to enable realtime scheduling" << std::endl;
@@ -200,21 +341,18 @@
exit(1);
}
- boost::scoped_ptr<unsigned char> buf(new unsigned char[bufsize]);
-
- // printf("Receiving %li samples into buffer of length %li bytes.\n\n",
nsamples, bufsize);
- printf("Receiving %ld samples\n\n", nsamples);
+ printf("Receiving %zd samples\n\n", nsamples);
struct timeval start, end;
gettimeofday(&start, 0);
- // printf("Each '.' is 100 packets:\n");
- rx_nop_handler h(nsamples);
- bool ok = u2->rx_samples(0, &h);
- if (!ok){
- fprintf(stderr, "u2->rx_samples failed\n");
- return 1;
+ while(handler->nsamples() < handler->max_samples()){
+ bool ok = u2->rx_samples(0, handler.get());
+ if (!ok){
+ fprintf(stderr, "u2->rx_samples failed\n");
+ return 1;
+ }
}
@@ -222,13 +360,13 @@
long n_usecs = end.tv_usec-start.tv_usec;
long n_secs = end.tv_sec-start.tv_sec;
double elapsed = (double)n_secs + (double)n_usecs*1e-6;
- double mbs = h.nsamples()*sizeof(uint32_t)/elapsed/1e6;
- double pps = h.nframes()/elapsed;
+ double mbs = handler->nsamples()*sizeof(uint32_t)/elapsed/1e6;
+ double pps = handler->nframes()/elapsed;
u2->stop_rx_streaming();
- printf("\nCopy handler called %li times.\n", h.nframes());
- printf("Copy handler called with %li bytes.\n\n",
h.nsamples()*sizeof(uint32_t));
+ printf("\nCopy handler called %li times.\n", handler->nframes());
+ printf("Copy handler called with %li bytes.\n\n",
handler->nsamples()*sizeof(uint32_t));
printf("Elapsed time was %5.3f seconds.\n", elapsed);
printf("Packet rate was %1.0f pkts/sec.\n", pps);
printf("Approximate throughput was %5.2f MB/sec.\n", mbs);
Modified: usrp2/branches/developers/eb/wip/host-ng/configure.ac
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/configure.ac 2008-07-28
06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/configure.ac 2008-07-28
22:24:53 UTC (rev 9033)
@@ -1,4 +1,4 @@
-dnl Copyright 2001,2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
+dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008 Free Software
Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
@@ -81,10 +81,11 @@
AC_PROG_INSTALL
AC_PATH_PROG([RM_PROG], [rm])
+AC_LIBTOOL_WIN32_DLL
dnl AC_DISABLE_SHARED dnl don't build shared libraries
AC_ENABLE_SHARED dnl do build shared libraries
AC_DISABLE_STATIC dnl don't build static libraries
-AC_PROG_LIBTOOL
+m4_ifdef([LT_INIT],[LT_INIT],[AC_PROG_LIBTOOL])
dnl GR_FORTRAN
GR_NO_UNDEFINED dnl do we need the -no-undefined linker flag
Modified: usrp2/branches/developers/eb/wip/host-ng/include/usrp2/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/Makefile.am
2008-07-28 06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/Makefile.am
2008-07-28 22:24:53 UTC (rev 9033)
@@ -22,6 +22,7 @@
usrp2includedir = $(includedir)/usrp2
usrp2include_HEADERS = \
+ copiers.h \
copy_handler.h \
data_handler.h \
strtod_si.h \
Added: usrp2/branches/developers/eb/wip/host-ng/include/usrp2/copiers.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/copiers.h
(rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/copiers.h
2008-07-28 22:24:53 UTC (rev 9033)
@@ -0,0 +1,63 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_USRP2_COPIERS_H
+#define INCLUDED_USRP2_COPIERS_H
+
+#include <complex>
+#include <stdint.h>
+
+namespace usrp2 {
+
+ // FIXME we may want to rework this, but this will get us on the air
+
+ /*
+ * ----------------------------------------------------------------
+ * Copy and convert from USRP2 wire format to host format
+ * ----------------------------------------------------------------
+ */
+
+ void
+ copy_u2_complex_16_to_host_complex_16(size_t nitems,
+ const uint32_t *items,
+ std::complex<int16_t> *host_items);
+
+ void
+ copy_u2_complex_16_to_host_complex_float(size_t nitems,
+ const uint32_t *items,
+ std::complex<float> *host_items);
+
+ /*
+ * ----------------------------------------------------------------
+ * Copy and convert from host format to USRP2 wire format
+ * ----------------------------------------------------------------
+ */
+
+ void
+ copy_host_complex_16_to_u2_complex_16(size_t nitems,
+ const std::complex<int16_t> *host_items,
+ uint32_t *items);
+
+ void
+ copy_host_complex_float_to_u2_complex_16(size_t nitems,
+ const std::complex<float>
*host_items,
+ uint32_t *items);
+}
+
+
+#endif /* INCLUDED_USRP2_COPIERS_H */
Property changes on:
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/copiers.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am 2008-07-28
06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am 2008-07-28
22:24:53 UTC (rev 9033)
@@ -25,6 +25,7 @@
libusrp2ng_la_SOURCES = \
control.cc \
+ copiers.cc \
copy_handler.cc \
data_handler.cc \
eth_buffer.cc \
Added: usrp2/branches/developers/eb/wip/host-ng/lib/copiers.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/copiers.cc
(rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/copiers.cc 2008-07-28
22:24:53 UTC (rev 9033)
@@ -0,0 +1,107 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <usrp2/copiers.h>
+#include <gruel/inet.h>
+#include <stdexcept>
+#include <assert.h>
+#include <string.h>
+
+// FIXME need gruel::not_implemented
+
+namespace usrp2 {
+
+ /*
+ * ----------------------------------------------------------------
+ * Copy and convert from USRP2 wire format to host format
+ * ----------------------------------------------------------------
+ */
+ void
+ copy_u2_complex_16_to_host_complex_16(size_t nitems,
+ const uint32_t *items,
+ std::complex<int16_t> *host_items)
+ {
+#ifdef WORDS_BIGENDIAN
+
+ assert(sizeof(items[0]) == sizeof(host_items[0]));
+ memcpy(host_items, items, nitems * sizeof(items[0]));
+
+#else
+
+ // FIXME SIMD welcome here
+
+ for (size_t i = 0; i < nitems; i++){
+ uint32_t t = ntohx(items[i]);
+ host_items[i] = std::complex<int16_t>((t >> 16), t & 0xffff);
+ }
+
+#endif
+ }
+
+
+ void
+ copy_u2_complex_16_to_host_complex_float(size_t nitems,
+ const uint32_t *items,
+ std::complex<float> *host_items)
+ {
+ throw std::runtime_error("not implemented");
+ }
+
+
+ /*
+ * ----------------------------------------------------------------
+ * Copy and convert from host format to USRP2 wire format
+ * ----------------------------------------------------------------
+ */
+ void
+ copy_host_complex_16_to_u2_complex_16(size_t nitems,
+ const std::complex<int16_t> *host_items,
+ uint32_t *items)
+ {
+#ifdef WORDS_BIGENDIAN
+
+ assert(sizeof(items[0]) == sizeof(host_items[0]));
+ memcpy(items, host_items, nitems * sizeof(items[0]));
+
+#else
+
+ // FIXME SIMD welcome here
+
+ for (size_t i = 0; i < nitems; i++){
+ items[i] = htonl((host_items[i].real() << 16) | (host_items[i].imag() &
0xffff));
+ }
+
+#endif
+ }
+
+
+ void
+ copy_host_complex_float_to_u2_complex_16(size_t nitems,
+ const std::complex<float>
*host_items,
+ uint32_t *items)
+ {
+ throw std::runtime_error("not implemented");
+ }
+
+}
Property changes on: usrp2/branches/developers/eb/wip/host-ng/lib/copiers.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc 2008-07-28
06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc 2008-07-28
22:24:53 UTC (rev 9033)
@@ -208,6 +208,10 @@
void *base = (uint8_t *)hdr+hdr->tp_mac;
size_t len = hdr->tp_len;
+ // FYI, (base % 4 == 2) Not what we want given the current FPGA
+ // code. This means that our uint32_t samples are not 4-byte
+ // aligned. We'll have to deal with it downstream.
+
if (0)
fprintf(stderr, "eth_buffer: base = %p tp_mac = %3d tp_net = %3d\n",
base, hdr->tp_mac, hdr->tp_net);
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc 2008-07-28
06:07:13 UTC (rev 9032)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc 2008-07-28
22:24:53 UTC (rev 9033)
@@ -91,11 +91,15 @@
if (payload_len_in_bytes < sizeof(u2_fixed_hdr_t)) // invalid format
return false;
- assert((((uintptr_t) p) % 4) == 0); // must be 4-byte
aligned
+ // FIXME deal with the fact that (p % 4) == 2
+ //assert((((uintptr_t) p) % 4) == 0); // must be 4-byte
aligned
u2_fixed_hdr_t *fh = static_cast<u2_fixed_hdr_t *>(p);
+
+ // FIXME unaligned loads!
md->word0 = u2p_word0(fh);
md->timestamp = u2p_timestamp(fh);
+
// md->start_of_burst = (md->word0 & XXX) != 0;
// md->end_of_burst = (md->word0 & XXX) != 0;
// md->rx_overrun = (md->word0 & XXX) != 0;
@@ -452,6 +456,8 @@
usrp2::impl::operator()(const void *base, size_t len)
{
u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
+
+ // FIXME unaligned load!
int chan = u2p_chan(&pkt->hdrs.fixed);
if (chan == CONTROL_CHAN) { // control packets
@@ -471,6 +477,8 @@
// point to beginning of payload (subpackets)
unsigned char *p = (unsigned char *)base + sizeof(u2_eth_packet_t);
+ // FIXME (p % 4) == 2. Not good. Must watch for unaligned loads.
+
// FIXME iterate over payload, handling more than a single subpacket.
//int opcode = p[0];
@@ -526,7 +534,9 @@
/* --- end of fake transport layer handler --- */
+ // FIXME unaligned load!
unsigned int chan = u2p_chan(&pkt->hdrs.fixed);
+
if (!d_channel_rings[chan]) {
DEBUG_LOG("!");
return data_handler::RELEASE; // discard packet, no channel handler
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9033 - in usrp2/branches/developers/eb/wip/host-ng: . apps include/usrp2 lib,
eb <=