Changeset 9115

Show
Ignore:
Timestamp:
07/31/08 22:40:47
Author:
eb
Message:

Merged features/host-ng/host-ng -r8608:9111 into trunk/host-ng.

Files:

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  
    1818include $(top_srcdir)/Makefile.common 
    1919 
    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") 
     21AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) 
    2222 
    2323LDADD = \ 
    2424        ../lib/libusrp2ng.la \ 
    25         $(GNURADIO_CORE_LIBS) 
     25        -lgruel 
    2626 
    2727noinst_PROGRAMS = \ 
    28         test_usrp2 
     28        test2_usrp2 
    2929 
    30 test_usrp2_SOURCES = \ 
    31         test_usrp2.cc 
     30test2_usrp2_SOURCES = \ 
     31        test2_usrp2.cc 
    3232 
  • usrp2/branches/developers/eb/merge-wip/host-ng/apps/test.sh

    r8591 r9115  
    11#!/bin/sh 
    22 
    3 sudo ./test_usrp2 1>cerr 2>&1 
     3sudo ./test_usrp2 -d 4 
    44 
    55 
  • usrp2/branches/developers/eb/merge-wip/host-ng/apps/test_usrp2.cc

    r8600 r9115  
    2222 
    2323#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> 
    2529#include <iostream> 
    2630#include <string.h> 
     31#include <boost/scoped_ptr.hpp> 
    2732 
    2833static void 
     
    4146  fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface [default=eth0]\n"); 
    4247  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"); 
    4353} 
    4454 
     
    4959  const char *interface = "eth0"; 
    5060  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       
    5267  int ch; 
    5368 
    54   while ((ch = getopt(argc, argv, "he:m:")) != EOF){ 
     69  while ((ch = getopt(argc, argv, "he:m:f:d:g:n:b:")) != EOF){ 
    5570    switch (ch){ 
    5671 
     
    6378      break; 
    6479 
     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       
    65121    case 'h': 
    66122    default: 
     
    69125    } 
    70126  } 
    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) 
    74130    std::cerr << "Failed to enable realtime scheduling" << std::endl; 
    75131 
    76132  usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str); 
    77133   
    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 
    92219  return 0; 
    93220} 
  • 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. 
     1dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. 
    22dnl 
    33dnl This program is free software: you can redistribute it and/or modify 
     
    8282AC_PATH_PROG([RM_PROG], [rm]) 
    8383 
     84AC_LIBTOOL_WIN32_DLL 
    8485dnl AC_DISABLE_SHARED   dnl don't build shared libraries 
    8586AC_ENABLE_SHARED        dnl do build shared libraries 
    8687AC_DISABLE_STATIC       dnl don't build static libraries 
    87 AC_PROG_LIBTOOL 
     88m4_ifdef([LT_INIT],[LT_INIT],[AC_PROG_LIBTOOL]) 
    8889dnl GR_FORTRAN 
    8990 
     
    161162]) 
    162163 
     164PKG_CHECK_MODULES(GRUEL, gruel > 3) 
     165AC_SUBST(GRUEL_LIBS) 
     166AC_SUBST(GRUEL_CFLAGS) 
     167 
    163168dnl Do we have "dot", part of the graphviz package from AT&T? 
    164169dnl Doxgen will use it to draw pretty diagrams ;-) 
  • usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/Makefile.am

    r8582 r9115  
    2323 
    2424usrp2include_HEADERS = \ 
     25        copiers.h \ 
    2526        copy_handler.h \ 
    2627        data_handler.h \ 
     28        strtod_si.h \ 
     29        tune_result.h \ 
    2730        usrp2.h 
  • usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/copy_handler.h

    r8583 r9115  
    2727namespace usrp2 { 
    2828 
    29   class copy_handler : data_handler, boost::noncopyable  
     29  class copy_handler : public data_handler, boost::noncopyable  
    3030  { 
    3131    uint8_t *d_dest;      // next write pointer 
    32     unsigned int d_space; // space left in destination buffer 
    33     unsigned int d_bytes; // total bytes copied 
    34     unsigned int d_times; // number of times invoked 
     32    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 
    3535 
    3636  public: 
    37     copy_handler(void *dest, unsigned int len); 
     37    copy_handler(void *dest, size_t len); 
    3838    ~copy_handler(); 
    3939  
    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; } 
    4147  }; 
    4248     
  • usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/data_handler.h

    r8583 r9115  
    2323 
    2424#include <stdint.h> 
     25#include <stddef.h> 
    2526 
    2627namespace usrp2 { 
    2728 
    2829  /*! 
    29    * \brief abstract function object called to handle received data blocks 
     30   * \brief Abstract function object called to handle received data blocks. 
    3031   */ 
    3132  class data_handler  
    3233  { 
    3334  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    }; 
    3641     
     42    typedef int result;         //< bitmask of result_bits 
     43 
    3744    /*! 
    3845     * \param base points to the beginning of the data 
    3946     * \param len is the length in bytes of the data 
     47     * \returns bitmask composed of DONE, KEEP 
    4048     */ 
    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(); 
    4351  }; 
    4452 
  • usrp2/branches/developers/eb/merge-wip/host-ng/include/usrp2/usrp2.h

    r8543 r9115  
    2323#include <boost/utility.hpp> 
    2424#include <vector> 
     25#include <usrp2/rx_sample_handler.h> 
    2526 
    2627namespace usrp2 { 
    2728 
    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 
    38199}; 
    39200 
    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 tuning 
    46  */ 
    47 class usrp2_tune_result 
    48 { 
    49 public: 
    50   // RF frequency that corresponds to DC in the IF 
    51   double baseband_freq; 
    52  
    53   // frequency programmed into the DDC/DUC 
    54   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::noncopyable 
    68 { 
    69 public: 
    70   /*! 
    71    * Shared pointer to this class 
    72    */  
    73   typedef boost::shared_ptr<usrp2> sptr; 
    74   
    75   /*!  
    76    * Static function to return an instance of usrp2 as a shared pointer 
    77    * 
    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-select 
    81    */ 
    82   static sptr make(const std::string &ifc, const std::string &addr=""); 
    83  
    84   /*! 
    85    * Class destructor 
    86    */ 
    87   ~usrp2();   
    88  
    89   /* 
    90    * Rx configuration and control 
    91    */ 
    92  
    93   /*! 
    94    * Set receiver gain 
    95    */ 
    96   bool set_rx_gain(double gain); 
    97  
    98   /*! 
    99    * Set receiver center frequency 
    100    */ 
    101   bool set_rx_freq(double frequency, usrp2_tune_result *result); 
    102  
    103   /*! 
    104    * Set receiver sample rate decimation 
    105    */ 
    106   bool set_rx_decim(int decimation_factor); 
    107  
    108   /*! 
    109    * Set receiver IQ magnitude scaling 
    110    */ 
    111   bool set_rx_scale_iq(int scale_i, int scale_q); 
    112  
    113   /*! 
    114    * Set received sample format 
    115    *    
    116    *    domain: complex or real 
    117    *      type: floating, fixed point, or raw 
    118    *     depth: bits per sample 
    119    * 
    120    * Sets format over the wire for samples from USRP2 and determines  
    121    * default reader and writer functors    
    122    *  
    123    */ 
    124   // bool set_rx_format(...); 
    125  
    126   /*! 
    127    * Start streaming receive mode.  USRP2 will send a continuous stream of 
    128    * DSP pipeline samples to host.  Call rx_samples(...) to access. 
    129    *  
    130    * \param items_per_frame  Interpreted according to current receive format 
    131    */ 
    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 class 
    144   usrp2(const std::string &ifc, const std::string &addr); 
    145    
    146   // All private state is held in opaque pointer 
    147   std::auto_ptr<impl> d_impl; 
    148 }; 
    149  
    150 }; 
    151  
    152201#endif /* INCLUDED_USRP2_H */ 
  • usrp2/branches/developers/eb/merge-wip/host-ng/lib/Makefile.am

    r8600 r9115  
    1818include $(top_srcdir)/Makefile.common 
    1919 
    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") 
     21AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) $(BOOST_CFLAGS) 
    2222 
    2323lib_LTLIBRARIES = \ 
     
    2626libusrp2ng_la_SOURCES = \ 
    2727        control.cc \ 
     28        copiers.cc \ 
    2829        copy_handler.cc \ 
     30        data_handler.cc \ 
    2931        eth_buffer.cc \ 
    3032        ethernet.cc \ 
    3133        find.cc \ 
    3234        pktfilter.cc \ 
     35        ring.cc \ 
     36        rx_sample_handler.cc \ 
     37        strtod_si.c \ 
    3338        usrp2.cc \ 
    3439        usrp2_impl.cc \ 
     
    3641 
    3742libusrp2ng_la_LIBADD = \ 
    38         $(GR_OMNITHREAD_LIBS) 
     43        $(GR_OMNITHREAD_LIBS) \ 
     44        $(GRUEL_LIBS) 
    3945 
    4046# Private headers not needed for above the API development 
     
    4551        ethernet.h \ 
    4652        pktfilter.h \ 
     53        ring.h \ 
    4754        usrp2_impl.h \ 
    4855        usrp2_thread.h 
  • usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.cc

    r8600 r9115  
    2424#endif 
    2525 
     26#include <omni_time.h> 
    2627#include "control.h" 
    2728#include <iostream> 
     
    2930namespace usrp2 { 
    3031 
    31   pending_reply::pending_reply(int rid, void *buffer, int len) 
     32  pending_reply::pending_reply(unsigned int rid, void *buffer, size_t len) 
    3233    : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len) 
    3334  { 
     
    3637  pending_reply::~pending_reply() 
    3738  { 
    38     signal(); 
     39    signal(); // Needed? 
    3940  } 
    4041 
    4142  int 
    42   pending_reply::wait(int secs, long nsecs) 
     43  pending_reply::wait(double secs) 
    4344  { 
    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); 
    4848  } 
    4949 
  • usrp2/branches/developers/eb/merge-wip/host-ng/lib/control.h

    r8606 r9115  
    3131    u2_eth_packet_t   h; 
    3232    op_config_rx_v2_t op; 
    33     op_eop_t         eop; 
     33    op_generic_t      eop; 
    3434  }; 
     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 
    3556 
    3657  /*! 
     
    4061  { 
    4162  private: 
    42     int             d_rid; 
     63    unsigned int    d_rid; 
    4364    omni_mutex      d_mutex; 
    4465    omni_condition  d_cond; 
    4566    void           *d_buffer; 
    46     int             d_len; 
     67    size_t         d_len; 
    4768 
    4869  public:   
     
    5172     * buffer, and buffer length. 
    5273     */ 
    53     pending_reply(int rid, void *buffer, int len); 
     74    pending_reply(unsigned int rid, void *buffer, size_t len); 
    5475 
    5576    /*! 
     
    6384     *          0 = timeout 
    6485     */ 
    65     int wait(int secs, long nsecs); 
     86    int wait(double secs); 
    6687 
    6788    /*! 
     
    7394     * Retrieve pending reply ID 
    7495     */ 
    75     int rid() const { return d_rid; } 
     96    unsigned int rid() const { return d_rid; } 
    7697 
    7798    /*! 
     
    79100     */ 
    80101    void *buffer() const { return d_buffer; } 
     102 
     103    /*! 
     104     * Retrieve destination buffer length 
     105     */ 
     106    size_t len() const { return d_len; } 
    81107  }; 
    82108   
  • usrp2/branches/developers/eb/merge-wip/host-ng/lib/copy_handler.cc

    r8600 r9115  
    2525 
    2626#include <usrp2/copy_handler.h> 
     27#include <iostream> 
    2728 
    2829namespace usrp2 { 
    2930   
    30   copy_handler::copy_handler(void *dest, unsigned int len) 
     31  copy_handler::copy_handler(void *dest, size_t len) 
    3132    : d_dest((uint8_t *)dest), d_space(len), d_bytes(0), d_times(0) 
    3233  { 
     
    3839  } 
    3940   
    40   uint32_
    41   copy_handler::operator()(const void *base, unsigned int len) 
     41  data_handler::resul
     42  copy_handler::operator()(const void *base, size_t len) 
    4243  { 
    4344    if (len > d_space) 
     
    4849    d_bytes += len; 
    4950    d_times++; 
     51 
     52    if (d_space < MIN_COPY_LEN) 
     53      return DONE; // don't call me anymore 
    5054     
    51     if (d_space == 0) 
    52       return DONE; // don't call me anymore 
    53  
    5455    return 0; 
    5556  } 
  • usrp2/branches/developers/eb/merge-wip/host-ng/lib/eth_buffer.cc

    r8600 r9115  
    3434#include <cmath> 
    3535#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 
    3840#if ETH_BUFFER_DEBUG 
    3941#define DEBUG_LOG(x) ::write(2, (x), 1) 
     
    4850namespace usrp2 { 
    4951 
    50   data_handler::~data_handler() 
    51   { 
    52     // default nop destructor 
    53   } 
    54    
    5552  eth_buffer::eth_buffer(size_t rx_bufsize) 
    5653    : 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  { 
    6256    if (rx_bufsize == 0) 
    6357      d_buflen = (size_t)MAX_MEM_SIZE; 
     
    7064  eth_buffer::~eth_buffer() 
    7165  { 
    72     if (ETH_BUFFER_DEBUG) 
    73       std::cerr << "eth_buffer: destructor" << std::endl; 
    74  
    7566    close(); 
    7667  } 
     
    7970  eth_buffer::open(const std::string &ifname, int protocol) 
    8071  { 
    81     if (ETH_BUFFER_DEBUG) 
    82       std::cerr << "eth_buffer: using interface " << ifname 
    83                 << ", protocol=" << protocol << std::endl; 
    84  
    8572    if (!d_ethernet->open(ifname, protocol)) { 
    8673      std::cerr << "eth_buffer: unable to open interface "  
     
    9885    req.tp_frame_size = 
    9986      (unsigned int)rint(pow(2, ceil(log2(TPACKET_ALIGN(TPACKET_HDRLEN)+TPACKET_ALIGN(MAX_PKT_SIZE))))); 
     87    d_frame_size = req.tp_frame_size; 
    10088 
    10189    // Calculate minimum contiguous pages needed to enclose a frame 
     
    115103    d_frame_nr = req.tp_frame_nr; 
    116104 
     105#if 0 
    117106    if (ETH_BUFFER_DEBUG) 
    118107      std::cerr << "eth_buffer:"  
     
    123112                << " buflen=" << d_buflen 
    124113                << std::endl; 
     114#endif 
    125115 
    126116    // Try to get kernel shared memory buffer     
     
    133123      } 
    134124       
    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; 
    137126    } 
    138127    else { 
    139128      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)
    142131        perror("eth_buffer: mmap"); 
    143132        return false; 
    144133      } 
     134      d_buf = (uint8_t *) p; 
    145135 
    146136      if (ETH_BUFFER_DEBUG) 
     
    148138    } 
    149139 
    150     // Initialize packet ring 
     140    // Initialize our pointers into the packet ring 
    151141    d_ring = std::vector<uint8_t *>(req.tp_frame_nr); 
    152142    for (unsigned int i=0; i < req.tp_frame_nr; i++) { 
    153143      d_ring[i] = (uint8_t *)(d_buf+i*req.tp_frame_size); 
    154       ((tpacket_hdr *)(d_ring[i]))->tp_status = TP_STATUS_KERNEL; // free 
    155       ((tpacket_hdr *)(d_ring[i]))->tp_len = req.tp_frame_size; 
    156144    } 
    157145 
     
    184172  } 
    185173   
    186   int  
    187   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"); 
    190178       
    191179    while (!frame_available()) { 
    192       if (timeout == 0) { 
     180      if (timeout_in_ms == 0) { 
    193181        DEBUG_LOG("w"); 
    194         return 0; // would block 
     182        return EB_WOULD_BLOCK; 
    195183      } 
    196184       
     
    202190      DEBUG_LOG("P"); 
    203191 
    204       int pres = poll(&pfd, 1, timeout); 
     192      int pres = poll(&pfd, 1, timeout_in_ms); 
    205193      if (pres == -1) { 
    206194        perror("poll"); 
    207         DEBUG_LOG("E"); 
    208         return -1; 
     195        return EB_ERROR; 
    209196      } 
    210197 
    211198      if (pres == 0) { 
    212