Changeset 9115
- Timestamp:
- 07/31/08 22:40:47
- Files:
-
- usrp2/branches/developers/eb/merge-wip/host-ng/apps (modified) (1 prop)
- usrp2/branches/developers/eb/merge-wip/host-ng/apps/Makefile.am (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/apps/test.sh (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/apps/test2_usrp2.cc (copied) (copied from usrp2/branches/features/host-ng/host-ng/apps/test2_usrp2.cc)
- usrp2/branches/developers/eb/merge-wip/host-ng/apps/test_usrp2.cc (modified) (5 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/configure.ac (modified) (3 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/Makefile.am (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/copiers.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/include/usrp2/copiers.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/copy_handler.h (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/data_handler.h (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/metadata.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/include/usrp2/metadata.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/rx_sample_handler.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/include/usrp2/rx_sample_handler.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/strtod_si.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/include/usrp2/strtod_si.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/tune_result.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/include/usrp2/tune_result.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/usrp2.h (modified) (1 diff)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/Makefile.am (modified) (4 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.cc (modified) (3 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.h (modified) (6 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/copiers.cc (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/copiers.cc)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/copy_handler.cc (modified) (3 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/data_handler.cc (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/data_handler.cc)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/eth_buffer.cc (modified) (13 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/eth_buffer.h (modified) (7 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/find.cc (modified) (4 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/ring.cc (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/ring.cc)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/ring.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/ring.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/rx_sample_handler.cc (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/rx_sample_handler.cc)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/strtod_si.c (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/strtod_si.c)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/usrp2.cc (modified) (3 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/usrp2_bytesex.h (copied) (copied from usrp2/branches/features/host-ng/host-ng/lib/usrp2_bytesex.h)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/usrp2_impl.cc (modified) (14 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/usrp2_impl.h (modified) (4 diffs)
- usrp2/branches/developers/eb/merge-wip/host-ng/lib/usrp2_thread.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
usrp2/branches/developers/eb/merge-wip/host-ng/apps
- Property svn:ignore changed from Makefile Makefile.in .libs .deps test_eth test_usrp2 cerr *.sh to Makefile Makefile.in .libs .deps test_eth test_usrp2 test2_usrp2 cerr *.sh
usrp2/branches/developers/eb/merge-wip/host-ng/apps/Makefile.am
r8600 r9115 18 18 include $(top_srcdir)/Makefile.common 19 19 20 AM_CPPFLAGS = -Wall -Werror 21 INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES)20 #AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall -Werror -O2 -g") 21 AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) 22 22 23 23 LDADD = \ 24 24 ../lib/libusrp2ng.la \ 25 $(GNURADIO_CORE_LIBS)25 -lgruel 26 26 27 27 noinst_PROGRAMS = \ 28 test _usrp228 test2_usrp2 29 29 30 test _usrp2_SOURCES = \31 test _usrp2.cc30 test2_usrp2_SOURCES = \ 31 test2_usrp2.cc 32 32 usrp2/branches/developers/eb/merge-wip/host-ng/apps/test.sh
r8591 r9115 1 1 #!/bin/sh 2 2 3 sudo ./test_usrp2 1>cerr 2>&13 sudo ./test_usrp2 -d 4 4 4 5 5 usrp2/branches/developers/eb/merge-wip/host-ng/apps/test_usrp2.cc
r8600 r9115 22 22 23 23 #include <usrp2/usrp2.h> 24 #include <gr_realtime.h> 24 #include <usrp2/tune_result.h> 25 #include <usrp2/strtod_si.h> 26 #include <usrp2/copy_handler.h> 27 #include <gruel/realtime.h> 28 #include <sys/time.h> 25 29 #include <iostream> 26 30 #include <string.h> 31 #include <boost/scoped_ptr.hpp> 27 32 28 33 static void … … 41 46 fprintf(stderr, " -e ETH_INTERFACE specify ethernet interface [default=eth0]\n"); 42 47 fprintf(stderr, " -m MAC_ADDR mac address of USRP2 HH:HH [default=first one found]\n"); 48 fprintf(stderr, " -f FREQUENCY specify receive center frequency in Hz [default=0.0]\n"); 49 fprintf(stderr, " -d DECIM specify receive decimation rate [default=5]\n"); 50 fprintf(stderr, " -g GAIN specify receive daughterboard gain [default=0]\n"); 51 fprintf(stderr, " -n SAMPLES specify number of samples to receive [default=250e6]\n"); 52 fprintf(stderr, " -b BUFSIZE specify size of receive buffer [default=64k]\n"); 43 53 } 44 54 … … 49 59 const char *interface = "eth0"; 50 60 const char *mac_addr_str = ""; 51 61 double rx_freq = 0.0; 62 int rx_decim = 5; 63 double rx_gain = 0.0; 64 double samples = 250e6; 65 double bufsize = 65536; 66 52 67 int ch; 53 68 54 while ((ch = getopt(argc, argv, "he:m: ")) != EOF){69 while ((ch = getopt(argc, argv, "he:m:f:d:g:n:b:")) != EOF){ 55 70 switch (ch){ 56 71 … … 63 78 break; 64 79 80 case 'f': 81 if (!strtod_si(optarg, &rx_freq)) { 82 std::cerr << "invalid number: " << optarg << std::endl; 83 usage(argv[0]); 84 exit(1); 85 } 86 break; 87 88 case 'g': 89 if (!strtod_si(optarg, &rx_gain)) { 90 std::cerr << "invalid number: " << optarg << std::endl; 91 usage(argv[0]); 92 exit(1); 93 } 94 break; 95 96 case 'd': 97 rx_decim = strtol(optarg, 0, 0); 98 if (rx_decim < 4 or rx_decim > 512) { 99 std::cerr << "invalid decimation rate: " << optarg << std::endl; 100 usage(argv[0]); 101 exit(1); 102 } 103 break; 104 105 case 'n': 106 if (!strtod_si(optarg, &samples)) { 107 std::cerr << "invalid number: " << optarg << std::endl; 108 usage(argv[0]); 109 exit(1); 110 } 111 break; 112 113 case 'b': 114 if (!strtod_si(optarg, &bufsize)) { 115 std::cerr << "invalid number: " << optarg << std::endl; 116 usage(argv[0]); 117 exit(1); 118 } 119 break; 120 65 121 case 'h': 66 122 default: … … 69 125 } 70 126 } 71 72 gr _rt_status_t rt = gr_enable_realtime_scheduling();73 if (rt != RT_OK)127 128 gruel::rt_status_t rt = gruel::enable_realtime_scheduling(); 129 if (rt != gruel::RT_OK) 74 130 std::cerr << "Failed to enable realtime scheduling" << std::endl; 75 131 76 132 usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str); 77 133 78 u2->set_rx_gain(1.0); 79 u2->set_rx_freq(0.0, NULL); 80 u2->set_rx_decim(5); 81 //u2->start_rx_streaming(); 82 83 struct timespec ts; 84 ts.tv_sec = 10; 85 ts.tv_nsec = 0; 86 int r = nanosleep(&ts, 0); 87 if (r == -1) 88 perror("nanosleep"); 89 90 //u2->stop_rx_streaming(); 91 134 // FIXME in case it was left running... 135 if (!u2->stop_rx_streaming()){ 136 fprintf(stderr, "stop_rx_streaming failed\n"); 137 } 138 139 if (!u2->set_rx_gain(rx_gain)){ 140 fprintf(stderr, "set_rx_gain(%f) failed\n", rx_gain); 141 exit(1); 142 } 143 144 usrp2::tune_result tr; 145 if (!u2->set_rx_center_freq(rx_freq, &tr)){ 146 fprintf(stderr, "set_rx_center_freq(%g) failed\n", rx_freq); 147 exit(1); 148 } 149 150 printf("Daughterboard configuration:\n"); 151 printf(" baseband_freq=%f\n", tr.baseband_freq); 152 printf(" ddc_freq=%f\n", tr.dxc_freq); 153 printf(" residual_freq=%f\n", tr.residual_freq); 154 printf(" inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no"); 155 156 if (!u2->set_rx_decim(rx_decim)) { 157 fprintf(stderr, "set_rx_decim(%d) failed\n", rx_decim); 158 exit(1); 159 } 160 161 printf("USRP2 using decimation rate of %d\n", rx_decim); 162 163 if (!u2->start_rx_streaming()){ 164 fprintf(stderr, "start_rx_streaming failed\n"); 165 exit(1); 166 } 167 168 size_t nsamples = static_cast<size_t>(samples); 169 size_t buflen = static_cast<size_t>(bufsize); 170 boost::scoped_ptr<unsigned char> buf(new unsigned char[buflen]); 171 172 printf("Receiving %li samples into buffer of length %li bytes.\n\n", nsamples, buflen); 173 174 struct timeval start, end; 175 gettimeofday(&start, 0); 176 177 printf("Each '.' is 100 packets:\n"); 178 179 unsigned long bytes = 0; 180 unsigned long times = 0; 181 182 do { 183 usrp2::copy_handler h(buf.get(), buflen); 184 bool ok; 185 unsigned int n = 0; 186 do { 187 ok = u2->rx_samples(0, &h); 188 if (h.times() > n) { 189 printf("."); fflush(stdout); 190 n = n+100; 191 } 192 } 193 while (ok && !h.full() && (bytes+h.bytes()) <= nsamples*4); 194 if (!ok) 195 break; 196 197 bytes += h.bytes(); 198 times += h.times(); 199 } 200 while (bytes <= nsamples*4); // FIXME will vary by sample format 201 202 gettimeofday(&end, 0); 203 long n_usecs = end.tv_usec-start.tv_usec; 204 long n_secs = end.tv_sec-start.tv_sec; 205 double elapsed = (double)n_secs + (double)n_usecs*1e-6; 206 double mbs = bytes/elapsed/1e6; 207 double pps = times/elapsed; 208 209 u2->stop_rx_streaming(); 210 211 printf("\nCopy handler called %li times.\n", times); 212 printf("Copy handler called with %li bytes.\n\n", bytes); 213 printf("Elapsed time was %5.3f seconds.\n", elapsed); 214 printf("Packet rate was %1.0f pkts/sec.\n", pps); 215 printf("Approximate throughput was %5.2f MB/sec.\n", mbs); 216 printf("Total instances of overruns was %d.\n", u2->rx_overruns()); 217 printf("Total missing frames was %d.\n", u2->rx_missing()); 218 92 219 return 0; 93 220 } usrp2/branches/developers/eb/merge-wip/host-ng/configure.ac
r8516 r9115 1 dnl Copyright 2001,2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.1 dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. 2 2 dnl 3 3 dnl This program is free software: you can redistribute it and/or modify … … 82 82 AC_PATH_PROG([RM_PROG], [rm]) 83 83 84 AC_LIBTOOL_WIN32_DLL 84 85 dnl AC_DISABLE_SHARED dnl don't build shared libraries 85 86 AC_ENABLE_SHARED dnl do build shared libraries 86 87 AC_DISABLE_STATIC dnl don't build static libraries 87 AC_PROG_LIBTOOL 88 m4_ifdef([LT_INIT],[LT_INIT],[AC_PROG_LIBTOOL]) 88 89 dnl GR_FORTRAN 89 90 … … 161 162 ]) 162 163 164 PKG_CHECK_MODULES(GRUEL, gruel > 3) 165 AC_SUBST(GRUEL_LIBS) 166 AC_SUBST(GRUEL_CFLAGS) 167 163 168 dnl Do we have "dot", part of the graphviz package from AT&T? 164 169 dnl Doxgen will use it to draw pretty diagrams ;-) usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/Makefile.am
r8582 r9115 23 23 24 24 usrp2include_HEADERS = \ 25 copiers.h \ 25 26 copy_handler.h \ 26 27 data_handler.h \ 28 strtod_si.h \ 29 tune_result.h \ 27 30 usrp2.h usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/copy_handler.h
r8583 r9115 27 27 namespace usrp2 { 28 28 29 class copy_handler : data_handler, boost::noncopyable29 class copy_handler : public data_handler, boost::noncopyable 30 30 { 31 31 uint8_t *d_dest; // next write pointer 32 unsigned int d_space;// space left in destination buffer33 unsigned int d_bytes;// total bytes copied34 unsigned int d_times;// number of times invoked32 size_t d_space; // space left in destination buffer 33 size_t d_bytes; // total bytes copied 34 size_t d_times; // number of times invoked 35 35 36 36 public: 37 copy_handler(void *dest, unsigned int len);37 copy_handler(void *dest, size_t len); 38 38 ~copy_handler(); 39 39 40 virtual uint32_t operator()(const void *base, unsigned int len); 40 virtual data_handler::result operator()(const void *base, size_t len); 41 42 size_t bytes() const { return d_bytes; } 43 size_t times() const { return d_times; } 44 45 static const size_t MIN_COPY_LEN = 1484; // FIXME: calculate eth packet - thdr 46 bool full() const { return d_space < MIN_COPY_LEN; } 41 47 }; 42 48 usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/data_handler.h
r8583 r9115 23 23 24 24 #include <stdint.h> 25 #include <stddef.h> 25 26 26 27 namespace usrp2 { 27 28 28 29 /*! 29 * \brief abstract function object called to handle received data blocks30 * \brief Abstract function object called to handle received data blocks. 30 31 */ 31 32 class data_handler 32 33 { 33 34 public: 34 static const unsigned int KEEP = 0x0001; // do not discard data 35 static const unsigned int DONE = 0x0002; // do not call this object again 35 36 enum result_bits { 37 RELEASE = 0x0000, //< OK to release data (opposite of KEEP) 38 KEEP = 0x0001, //< do not discard data 39 DONE = 0x0002, //< do not call this object again 40 }; 36 41 42 typedef int result; //< bitmask of result_bits 43 37 44 /*! 38 45 * \param base points to the beginning of the data 39 46 * \param len is the length in bytes of the data 47 * \returns bitmask composed of DONE, KEEP 40 48 */ 41 virtual unsigned int operator()(const void *base, unsigned int len) = 0;42 virtual ~data_handler();49 virtual result operator()(const void *base, size_t len) = 0; 50 virtual ~data_handler(); 43 51 }; 44 52 usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/usrp2.h
r8543 r9115 23 23 #include <boost/utility.hpp> 24 24 #include <vector> 25 #include <usrp2/rx_sample_handler.h> 25 26 26 27 namespace usrp2 { 27 28 28 /*! 29 * Structure to hold properties of USRP2 hardware devices. 30 * 31 */ 32 struct props 33 { 34 std::string addr; 35 uint16_t hw_rev; 36 uint8_t fpga_md5sum[16]; 37 uint8_t sw_md5sum[16]; 29 /*! 30 * Structure to hold properties of USRP2 hardware devices. 31 * 32 */ 33 struct props 34 { 35 std::string addr; 36 uint16_t hw_rev; 37 uint8_t fpga_md5sum[16]; 38 uint8_t sw_md5sum[16]; 39 }; 40 41 typedef std::vector<props> props_vector_t; 42 43 /*! 44 * \brief Search the ethernet for all USRP2s or for a specific USRP2. 45 * 46 * \param ifc is the name of the OS ethernet interface (e.g., "eth0") 47 * \param mac_addr is the MAC address of the desired USRP2, or "" to search for all. 48 * mac_addr must be either a zero length string, "", or must be of the form 49 * "01:02:03:04:05:06" or "05:06". 50 * 51 * \returns a vector of properties, 1 entry for each matching USRP2 found. 52 */ 53 props_vector_t find(const std::string &ifc, const std::string &mac_addr=""); 54 55 class tune_result; 56 57 class usrp2 : boost::noncopyable 58 { 59 public: 60 static const unsigned int MAX_CHAN = 30; 61 62 /*! 63 * Shared pointer to this class 64 */ 65 typedef boost::shared_ptr<usrp2> sptr; 66 67 /*! 68 * Static function to return an instance of usrp2 as a shared pointer 69 * 70 * \param ifc Network interface name, e.g., "eth0" 71 * \param addr Network mac address, e.g., "01:02:03:04:05:06", "05:06" or "". 72 * "" will autoselect a USRP2 if there is only a single one on the local ethernet. 73 */ 74 static sptr make(const std::string &ifc, const std::string &addr=""); 75 76 /*! 77 * Class destructor 78 */ 79 ~usrp2(); 80 81 /* 82 * ---------------------------------------------------------------- 83 * Rx configuration and control 84 * ---------------------------------------------------------------- 85 */ 86 87 /*! 88 * Set receiver gain 89 */ 90 bool set_rx_gain(double gain); 91 92 /*! 93 * Set receiver center frequency 94 */ 95 bool set_rx_center_freq(double frequency, tune_result *result); 96 97 /*! 98 * Set receiver sample rate decimation 99 */ 100 bool set_rx_decim(int decimation_factor); 101 102 /*! 103 * Set receiver IQ magnitude scaling 104 */ 105 bool set_rx_scale_iq(int scale_i, int scale_q); 106 107 /*! 108 * Set received sample format 109 * 110 * domain: complex or real 111 * type: floating, fixed point, or raw 112 * depth: bits per sample 113 * 114 * Sets format over the wire for samples from USRP2. 115 */ 116 // bool set_rx_format(...); 117 118 /*! 119 * Start streaming receive mode. USRP2 will send a continuous stream of 120 * DSP pipeline samples to host. Call rx_samples(...) to access. 121 * 122 * \param channel Stream channel number (0-30) 123 * \param items_per_frame Number of 32-bit items per frame. 124 */ 125 bool start_rx_streaming(unsigned int channel=0, unsigned int items_per_frame=0); 126 127 /*! 128 * Stop streaming receive mode. 129 */ 130 bool stop_rx_streaming(unsigned int channel=0); 131 132 /*! 133 * \brief Receive data from the specified channel 134 * This method is used to receive all data: streaming or discrete. 135 */ 136 bool rx_samples(unsigned int channel, rx_sample_handler *handler); 137 138 /*! 139 * Returns number of times receive overruns have occurred 140 */ 141 unsigned int rx_overruns(); 142 143 /*! 144 * Returns total number of missing frames from overruns. 145 */ 146 unsigned int rx_missing(); 147 148 /* 149 * ---------------------------------------------------------------- 150 * Tx configuration and control 151 * ---------------------------------------------------------------- 152 */ 153 154 /*! 155 * Set receiver gain 156 */ 157 bool set_tx_gain(double gain); 158 159 /*! 160 * Set transmitter center frequency 161 */ 162 bool set_tx_center_freq(double frequency, tune_result *result); 163 164 /*! 165 * Set transmitter sample rate interpolation 166 */ 167 bool set_tx_interp(int interpolation_factor); 168 169 /*! 170 * Set transmit IQ magnitude scaling 171 */ 172 bool set_tx_scale_iq(int scale_i, int scale_q); 173 174 /*! 175 * Set transmit sample format 176 * 177 * domain: complex or real 178 * type: floating, fixed point, or raw 179 * depth: bits per sample 180 * 181 * Sets format over the wire for samples to USRP2. 182 */ 183 // bool set_tx_format(...); 184 185 // bool tx_samples(...) 186 187 188 189 class impl; // implementation details 190 191 private: 192 // Only usrp2::make factory function can instantiate this class 193 usrp2(const std::string &ifc, const std::string &addr); 194 195 // All private state is held in opaque pointer 196 std::auto_ptr<impl> d_impl; 197 }; 198 38 199 }; 39 200 40 typedef std::vector<props> props_vector_t;41 42 props_vector_t find(const std::string &ifc, const std::string &addr="");43 44 /*!45 * Structure to hold results of tuning46 */47 class usrp2_tune_result48 {49 public:50 // RF frequency that corresponds to DC in the IF51 double baseband_freq;52 53 // frequency programmed into the DDC/DUC54 double dxc_freq;55 56 // residual frequency (typically < 0.01 Hz)57 double residual_freq;58 59 // is the spectrum inverted?60 bool spectrum_inverted;61 62 usrp2_tune_result()63 : baseband_freq(0), dxc_freq(0), residual_freq(0), spectrum_inverted(false) {}64 ~usrp2_tune_result();65 };66 67 class usrp2 : boost::noncopyable68 {69 public:70 /*!71 * Shared pointer to this class72 */73 typedef boost::shared_ptr<usrp2> sptr;74 75 /*!76 * Static function to return an instance of usrp2 as a shared pointer77 *78 * \param ifc Network interface name, e.g., "eth0"79 * \param addr Network mac address, e.g., "01:02:03:04:05:06" or "05:06",80 * default is auto-select81 */82 static sptr make(const std::string &ifc, const std::string &addr="");83 84 /*!85 * Class destructor86 */87 ~usrp2();88 89 /*90 * Rx configuration and control91 */92 93 /*!94 * Set receiver gain95 */96 bool set_rx_gain(double gain);97 98 /*!99 * Set receiver center frequency100 */101 bool set_rx_freq(double frequency, usrp2_tune_result *result);102 103 /*!104 * Set receiver sample rate decimation105 */106 bool set_rx_decim(int decimation_factor);107 108 /*!109 * Set receiver IQ magnitude scaling110 */111 bool set_rx_scale_iq(int scale_i, int scale_q);112 113 /*!114 * Set received sample format115 *116 * domain: complex or real117 * type: floating, fixed point, or raw118 * depth: bits per sample119 *120 * Sets format over the wire for samples from USRP2 and determines121 * default reader and writer functors122 *123 */124 // bool set_rx_format(...);125 126 /*!127 * Start streaming receive mode. USRP2 will send a continuous stream of128 * DSP pipeline samples to host. Call rx_samples(...) to access.129 *130 * \param items_per_frame Interpreted according to current receive format131 */132 bool start_rx_streaming(unsigned int items_per_frame=0);133 134 /*!135 * Stop streaming receive mode.136 */137 bool stop_rx_streaming();138 139 /* Ignore :-) */140 class impl;141 142 private:143 // Only usrp2::make factory function can instantiate this class144 usrp2(const std::string &ifc, const std::string &addr);145 146 // All private state is held in opaque pointer147 std::auto_ptr<impl> d_impl;148 };149 150 };151 152 201 #endif /* INCLUDED_USRP2_H */ usrp2/branches/developers/eb/merge-wip/host-ng/lib/Makefile.am
r8600 r9115 18 18 include $(top_srcdir)/Makefile.common 19 19 20 AM_CPPFLAGS = -Wall -Werror 21 INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES)20 #AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall -Werror -O2 -g") 21 AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) $(BOOST_CFLAGS) 22 22 23 23 lib_LTLIBRARIES = \ … … 26 26 libusrp2ng_la_SOURCES = \ 27 27 control.cc \ 28 copiers.cc \ 28 29 copy_handler.cc \ 30 data_handler.cc \ 29 31 eth_buffer.cc \ 30 32 ethernet.cc \ 31 33 find.cc \ 32 34 pktfilter.cc \ 35 ring.cc \ 36 rx_sample_handler.cc \ 37 strtod_si.c \ 33 38 usrp2.cc \ 34 39 usrp2_impl.cc \ … … 36 41 37 42 libusrp2ng_la_LIBADD = \ 38 $(GR_OMNITHREAD_LIBS) 43 $(GR_OMNITHREAD_LIBS) \ 44 $(GRUEL_LIBS) 39 45 40 46 # Private headers not needed for above the API development … … 45 51 ethernet.h \ 46 52 pktfilter.h \ 53 ring.h \ 47 54 usrp2_impl.h \ 48 55 usrp2_thread.h usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.cc
r8600 r9115 24 24 #endif 25 25 26 #include <omni_time.h> 26 27 #include "control.h" 27 28 #include <iostream> … … 29 30 namespace usrp2 { 30 31 31 pending_reply::pending_reply( int rid, void *buffer, int len)32 pending_reply::pending_reply(unsigned int rid, void *buffer, size_t len) 32 33 : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len) 33 34 { … … 36 37 pending_reply::~pending_reply() 37 38 { 38 signal(); 39 signal(); // Needed? 39 40 } 40 41 41 42 int 42 pending_reply::wait( int secs, long nsecs)43 pending_reply::wait(double secs) 43 44 { 44 int res = d_cond.timedwait(secs, nsecs); 45 if (res == 0) 46 std::cerr << "usrp2: no response to command packet" << std::endl; 47 return res; 45 omni_mutex_lock l(d_mutex); 46 omni_time abs_timeout = omni_time::time(omni_time(secs)); 47 return d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); 48 48 } 49 49 usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.h
r8606 r9115 31 31 u2_eth_packet_t h; 32 32 op_config_rx_v2_t op; 33 op_ eop_teop;33 op_generic_t eop; 34 34 }; 35 36 struct op_start_rx_streaming_cmd 37 { 38 u2_eth_packet_t h; 39 op_start_rx_streaming_t op; 40 op_generic_t eop; 41 }; 42 43 struct op_stop_rx_cmd { 44 u2_eth_packet_t h; 45 op_generic_t op; 46 op_generic_t eop; 47 }; 48 49 struct op_config_tx_v2_cmd 50 { 51 u2_eth_packet_t h; 52 op_config_tx_v2_t op; 53 op_generic_t eop; 54 }; 55 35 56 36 57 /*! … … 40 61 { 41 62 private: 42 intd_rid;63 unsigned int d_rid; 43 64 omni_mutex d_mutex; 44 65 omni_condition d_cond; 45 66 void *d_buffer; 46 intd_len;67 size_t d_len; 47 68 48 69 public: … … 51 72 * buffer, and buffer length. 52 73 */ 53 pending_reply( int rid, void *buffer, int len);74 pending_reply(unsigned int rid, void *buffer, size_t len); 54 75 55 76 /*! … … 63 84 * 0 = timeout 64 85 */ 65 int wait( int secs, long nsecs);86 int wait(double secs); 66 87 67 88 /*! … … 73 94 * Retrieve pending reply ID 74 95 */ 75 int rid() const { return d_rid; }96 unsigned int rid() const { return d_rid; } 76 97 77 98 /*! … … 79 100 */ 80 101 void *buffer() const { return d_buffer; } 102 103 /*! 104 * Retrieve destination buffer length 105 */ 106 size_t len() const { return d_len; } 81 107 }; 82 108 usrp2/branches/developers/eb/merge-wip/host-ng/lib/copy_handler.cc
r8600 r9115 25 25 26 26 #include <usrp2/copy_handler.h> 27 #include <iostream> 27 28 28 29 namespace usrp2 { 29 30 30 copy_handler::copy_handler(void *dest, unsigned int len)31 copy_handler::copy_handler(void *dest, size_t len) 31 32 : d_dest((uint8_t *)dest), d_space(len), d_bytes(0), d_times(0) 32 33 { … … 38 39 } 39 40 40 uint32_t41 copy_handler::operator()(const void *base, unsigned int len)41 data_handler::result 42 copy_handler::operator()(const void *base, size_t len) 42 43 { 43 44 if (len > d_space) … … 48 49 d_bytes += len; 49 50 d_times++; 51 52 if (d_space < MIN_COPY_LEN) 53 return DONE; // don't call me anymore 50 54 51 if (d_space == 0)52 return DONE; // don't call me anymore53 54 55 return 0; 55 56 } usrp2/branches/developers/eb/merge-wip/host-ng/lib/eth_buffer.cc
r8600 r9115 34 34 #include <cmath> 35 35 #include <errno.h> 36 37 #define ETH_BUFFER_DEBUG 1 // define to 0 or 1 36 #include <stdexcept> 37 38 39 #define ETH_BUFFER_DEBUG 0 // define to 0 or 1 38 40 #if ETH_BUFFER_DEBUG 39 41 #define DEBUG_LOG(x) ::write(2, (x), 1) … … 48 50 namespace usrp2 { 49 51 50 data_handler::~data_handler()51 {52 // default nop destructor53 }54 55 52 eth_buffer::eth_buffer(size_t rx_bufsize) 56 53 : d_fd(0), d_using_tpring(false), d_buflen(0), d_buf(0), d_frame_nr(0), 57 d_head(0), d_ring(0), d_ethernet(new ethernet()) 58 { 59 if (ETH_BUFFER_DEBUG) 60 std::cerr << "eth_buffer: constructor" << std::endl; 61 54 d_frame_size(0), d_head(0), d_ring(0), d_ethernet(new ethernet()) 55 { 62 56 if (rx_bufsize == 0) 63 57 d_buflen = (size_t)MAX_MEM_SIZE; … … 70 64 eth_buffer::~eth_buffer() 71 65 { 72 if (ETH_BUFFER_DEBUG)73 std::cerr << "eth_buffer: destructor" << std::endl;74 75 66 close(); 76 67 } … … 79 70 eth_buffer::open(const std::string &ifname, int protocol) 80 71 { 81 if (ETH_BUFFER_DEBUG)82 std::cerr << "eth_buffer: using interface " << ifname83 << ", protocol=" << protocol << std::endl;84 85 72 if (!d_ethernet->open(ifname, protocol)) { 86 73 std::cerr << "eth_buffer: unable to open interface " … … 98 85 req.tp_frame_size = 99 86 (unsigned int)rint(pow(2, ceil(log2(TPACKET_ALIGN(TPACKET_HDRLEN)+TPACKET_ALIGN(MAX_PKT_SIZE))))); 87 d_frame_size = req.tp_frame_size; 100 88 101 89 // Calculate minimum contiguous pages needed to enclose a frame … … 115 103 d_frame_nr = req.tp_frame_nr; 116 104 105 #if 0 117 106 if (ETH_BUFFER_DEBUG) 118 107 std::cerr << "eth_buffer:" … … 123 112 << " buflen=" << d_buflen 124 113 << std::endl; 114 #endif 125 115 126 116 // Try to get kernel shared memory buffer … … 133 123 } 134 124 135 if (ETH_BUFFER_DEBUG) 136 std::cerr << "eth_buffer: using malloc'd memory for buffer" << std::endl; 125 std::cerr << "eth_buffer: using malloc'd memory for buffer" << std::endl; 137 126 } 138 127 else { 139 128 d_using_tpring = true; 140 d_buf = (uint8_t *)mmap(0, d_buflen, PROT_READ|PROT_WRITE, MAP_SHARED, d_fd, 0);141 if ( !d_buf){129 void *p = mmap(0, d_buflen, PROT_READ|PROT_WRITE, MAP_SHARED, d_fd, 0); 130 if (p == MAP_FAILED){ 142 131 perror("eth_buffer: mmap"); 143 132 return false; 144 133 } 134 d_buf = (uint8_t *) p; 145 135 146 136 if (ETH_BUFFER_DEBUG) … … 148 138 } 149 139 150 // Initialize packet ring140 // Initialize our pointers into the packet ring 151 141 d_ring = std::vector<uint8_t *>(req.tp_frame_nr); 152 142 for (unsigned int i=0; i < req.tp_frame_nr; i++) { 153 143 d_ring[i] = (uint8_t *)(d_buf+i*req.tp_frame_size); 154 ((tpacket_hdr *)(d_ring[i]))->tp_status = TP_STATUS_KERNEL; // free155 ((tpacket_hdr *)(d_ring[i]))->tp_len = req.tp_frame_size;156 144 } 157 145 … … 184 172 } 185 173 186 int187 eth_buffer::rx_frames(data_handler *f, int timeout )188 { 189 DEBUG_LOG(" '");174 eth_buffer::result 175 eth_buffer::rx_frames(data_handler *f, int timeout_in_ms) 176 { 177 DEBUG_LOG("\n"); 190 178 191 179 while (!frame_available()) { 192 if (timeout == 0) {180 if (timeout_in_ms == 0) { 193 181 DEBUG_LOG("w"); 194 return 0; // would block182 return EB_WOULD_BLOCK; 195 183 } 196 184 … … 202 190 DEBUG_LOG("P"); 203 191 204 int pres = poll(&pfd, 1, timeout );192 int pres = poll(&pfd, 1, timeout_in_ms); 205 193 if (pres == -1) { 206 194 perror("poll"); 207 DEBUG_LOG("E"); 208 return -1; 195 return EB_ERROR; 209 196 } 210 197 211 198 if (pres == 0) { 212
