commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 137/148: Fixed and tested setting the usrp2


From: git
Subject: [Commit-gnuradio] [gnuradio] 137/148: Fixed and tested setting the usrp2 time and start rx streaming at. Added a demo app to apps called rx_timed_samples.cc to test this. Fixed the gr-usrp2 module to reflect the recent usrp2 api changes. Changed the way the firmware calls stop_rx_cmd, fixed issue with packets kept in the buffer after stop.
Date: Mon, 15 Aug 2016 00:47:34 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.

commit 7cdfd920fac87de0199e1443e7b8845eca084d1d
Author: Josh Blum <address@hidden>
Date:   Tue Jan 19 14:31:46 2010 -0800

    Fixed and tested setting the usrp2 time and start rx streaming at.
    Added a demo app to apps called rx_timed_samples.cc to test this.
    Fixed the gr-usrp2 module to reflect the recent usrp2 api changes.
    Changed the way the firmware calls stop_rx_cmd, fixed issue with packets 
kept in the buffer after stop.
---
 gr-usrp2/src/usrp2.i                |   8 +-
 gr-usrp2/src/usrp2_base.cc          |  12 +--
 gr-usrp2/src/usrp2_base.h           |  10 +--
 usrp2/apps/.gitignore               |   1 +
 usrp2/apps/Makefile.am              |   4 +-
 usrp2/apps/rx_timed_samples.cc      | 159 ++++++++++++++++++++++++++++++++++++
 usrp2/firmware/apps/app_common_v2.c |   5 +-
 usrp2/firmware/apps/txrx.c          |  16 ++--
 usrp2/include/usrp2/usrp2.h         |   4 +
 usrp2/lib/usrp2_impl.cc             |  14 ++--
 10 files changed, 203 insertions(+), 30 deletions(-)

diff --git a/gr-usrp2/src/usrp2.i b/gr-usrp2/src/usrp2.i
index 3197402..e6434a9 100644
--- a/gr-usrp2/src/usrp2.i
+++ b/gr-usrp2/src/usrp2.i
@@ -31,7 +31,7 @@
 %}
 
 %include <usrp2/tune_result.h>
-%include <usrp2/mimo_config.h>
+%include <usrp2/clock_config.h>
 
 %template(uint32_t_vector) std::vector<uint32_t>;
 
@@ -49,9 +49,9 @@ public:
   std::string interface_name() const;
   %rename(_real_fpga_master_clock_freq) fpga_master_clock_freq;
   bool fpga_master_clock_freq(long *freq);
-  bool config_mimo(int flags);
-  bool sync_to_pps();
-  bool sync_every_pps(bool enable);
+  bool config_clock(const usrp2::clock_config_t &clock_config);
+  bool set_time_at_next_pps(const usrp2::time_spec_t &time_spec);
+  bool set_time(const usrp2::time_spec_t &time_spec);
   std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
   bool poke32(uint32_t addr, const std::vector<uint32_t> &data);
 };
diff --git a/gr-usrp2/src/usrp2_base.cc b/gr-usrp2/src/usrp2_base.cc
index bb99597..3ab6db3 100644
--- a/gr-usrp2/src/usrp2_base.cc
+++ b/gr-usrp2/src/usrp2_base.cc
@@ -68,21 +68,21 @@ usrp2_base::fpga_master_clock_freq(long *freq) const
 }
 
 bool
-usrp2_base::config_mimo(int flags)
+usrp2_base::config_clock(const usrp2::clock_config_t &clock_config)
 {
-  return d_u2->config_mimo(flags);
+  return d_u2->config_clock(clock_config);
 }
 
 bool
-usrp2_base::sync_to_pps()
+usrp2_base::set_time_at_next_pps(const usrp2::time_spec_t &time_spec)
 {
-  return d_u2->sync_to_pps();
+  return d_u2->set_time_at_next_pps(time_spec);
 }
 
 bool
-usrp2_base::sync_every_pps(bool enable)
+usrp2_base::set_time(const usrp2::time_spec_t &time_spec)
 {
-  return d_u2->sync_every_pps(enable);
+  return d_u2->set_time(time_spec);
 }
 
 std::vector<uint32_t>
diff --git a/gr-usrp2/src/usrp2_base.h b/gr-usrp2/src/usrp2_base.h
index 67a62ba..6dc7385 100644
--- a/gr-usrp2/src/usrp2_base.h
+++ b/gr-usrp2/src/usrp2_base.h
@@ -64,19 +64,19 @@ public:
   bool fpga_master_clock_freq(long *freq) const;
 
   /*!
-   * \brief MIMO configuration
+   * \brief clock configuration
    */
-  bool config_mimo(int flags);
+  bool config_clock(const usrp2::clock_config_t &clock_config);
   
   /*!
    * \brief Set master time to 0 at next PPS rising edge
    */
-  bool sync_to_pps();
+  bool set_time_at_next_pps(const usrp2::time_spec_t &time_spec);
 
   /*!
-   * Reset master time to 0 at every PPS edge
+   * Reset master time asap
    */
-  bool sync_every_pps(bool enable);
+  bool set_time(const usrp2::time_spec_t &time_spec);
 
   /*!
    * \brief Read memory from Wishbone bus as words
diff --git a/usrp2/apps/.gitignore b/usrp2/apps/.gitignore
index 4b66ac0..c79b1ba 100644
--- a/usrp2/apps/.gitignore
+++ b/usrp2/apps/.gitignore
@@ -14,3 +14,4 @@
 /usrp2_burn_mac_addr
 /test_mimo_tx
 /gpio
+/rx_timed_samples
diff --git a/usrp2/apps/Makefile.am b/usrp2/apps/Makefile.am
index 542a25c..f06dd7a 100644
--- a/usrp2/apps/Makefile.am
+++ b/usrp2/apps/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2007, 2008 Free Software Foundation, Inc.
+# Copyright 2007, 2008, 2010 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
@@ -36,6 +36,7 @@ bin_PROGRAMS = \
 noinst_PROGRAMS = \
        gen_const \
        rx_streaming_samples \
+       rx_timed_samples \
        test_mimo_tx \
        tx_samples \
        gpio
@@ -43,6 +44,7 @@ noinst_PROGRAMS = \
 find_usrps_SOURCES = find_usrps.cc
 usrp2_burn_mac_addr_SOURCES = usrp2_burn_mac_addr.cc
 rx_streaming_samples_SOURCES = rx_streaming_samples.cc
+rx_timed_samples_SOURCES = rx_timed_samples.cc
 gen_const_SOURCES = gen_const.cc
 tx_samples_SOURCES = tx_samples.cc
 test_mimo_tx_SOURCES = test_mimo_tx.cc
diff --git a/usrp2/apps/rx_timed_samples.cc b/usrp2/apps/rx_timed_samples.cc
new file mode 100644
index 0000000..f1c9f8d
--- /dev/null
+++ b/usrp2/apps/rx_timed_samples.cc
@@ -0,0 +1,159 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <usrp2/usrp2.h>
+#include <usrp2/rx_nop_handler.h>
+#include <gruel/realtime.h>
+#include <sys/time.h>
+#include <iostream>
+#include <stdexcept>
+#include <boost/format.hpp>
+#include <cstring>
+#include <boost/lexical_cast.hpp>
+
+/***********************************************************************
+ * This app exercises the start streaming functionality of the usrp2:
+ *   1) Set the usrp2 time to the current host system time
+ *   2) Call start streaming with a time in the near future
+ *   3) Print the timestamps on the received packets
+ **********************************************************************/
+
+// ------------------------------------------------------------------------
+
+class rx_handler : public vrt::rx_packet_handler
+{
+public:
+
+  rx_handler(size_t max_samples)
+  {
+      d_num_samples = 0;
+      d_max_samples = max_samples;
+  }
+
+  ~rx_handler(){}
+
+  bool //print the timestamps, increment the number of samples
+  operator()(const uint32_t *items, size_t nitems, const vrt::expanded_header 
*vrt_header)
+  {
+    std::cout << boost::format("Got packet: Secs %d, Ticks %d\n")
+        % vrt_header->integer_secs % vrt_header->fractional_secs;
+    d_num_samples += nitems;
+    return true;
+  }
+
+  bool done(void){
+    return d_num_samples >= d_max_samples;
+  }
+
+private:
+  size_t d_max_samples, d_num_samples;
+};
+
+// ------------------------------------------------------------------------
+
+static void
+usage(const char *progname)
+{
+  const char *p = strrchr(progname, '/');      // drop leading directory path
+  if (p)
+    p++;
+
+  if (strncmp(p, "lt-", 3) == 0)               // drop lt- libtool prefix
+    p += 3;
+  
+  std::cerr << boost::format("Usage: %s [options]\n\n") % p;
+  std::cerr << boost::format("Options:\n");
+  std::cerr << boost::format("  -h                   show this message and 
exit\n");
+  std::cerr << boost::format("  -e ETH_INTERFACE     specify ethernet 
interface [default=eth0]\n");
+  std::cerr << boost::format("  -m MAC_ADDR          mac address of USRP2 
HH:HH [default=first one found]\n");
+  std::cerr << boost::format("  -N NSAMPLES          specify number of samples 
to receive [default=1000]\n");
+  std::cerr << boost::format("  -s SECONDS           specify number of seconds 
in the future to receive [default=3]\n");
+}
+
+int
+main(int argc, char **argv)
+{
+  // options and their defaults
+  const char *interface = "eth0";
+  const char *mac_addr_str = "";
+  size_t nsamples = 1000;
+  size_t nseconds = 3;
+
+  int ch;
+
+  while ((ch = getopt(argc, argv, "he:m:N:s:")) != -1){
+    switch (ch){
+
+    case 'e':
+      interface = optarg;
+      break;
+      
+    case 'm':
+      mac_addr_str = optarg;
+      break;
+
+    case 'N':
+      nsamples = boost::lexical_cast<size_t>(optarg);
+      break;
+
+    case 's':
+      nseconds = boost::lexical_cast<size_t>(optarg);
+      break;
+
+    case 'h':
+    default:
+      usage(argv[0]);
+      exit(1);
+    }
+  }
+
+  std::cout << std::endl << std::endl;
+
+  //create a new handler to print info about packets
+  rx_handler my_handler(nsamples);
+
+  //create a new usrp2 object, set some properties
+  usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str);
+  u2->set_rx_decim(16);
+
+  //set the current host time to the usrp2
+  struct timeval curr_time;
+  gettimeofday(&curr_time, NULL);
+  uint32_t curr_secs = curr_time.tv_sec;
+  long clk_rate; u2->fpga_master_clock_freq(&clk_rate);
+  uint32_t curr_ticks = (uint64_t)curr_time.tv_usec*clk_rate/1000000ul;
+  std::cout << boost::format("Current time: Secs %u, Ticks %u\n") % curr_secs 
% curr_ticks;
+  u2->set_time(usrp2::time_spec_t(curr_secs, curr_ticks));
+
+  //begin streaming n seconds in the future
+  std::cout << boost::format("Begin streaming %u seconds in the 
future...\n\n") % nseconds;
+  u2->start_rx_streaming(0, usrp2::time_spec_t(curr_secs+nseconds, 
curr_ticks));
+  while(not my_handler.done()){
+    u2->rx_samples(&my_handler);
+  }
+
+  //done, stop streaming
+  u2->stop_rx_streaming();
+
+  std::cout << std::endl << std::endl;
+  return 0;
+}
diff --git a/usrp2/firmware/apps/app_common_v2.c 
b/usrp2/firmware/apps/app_common_v2.c
index b629b8c..ce5ab28 100644
--- a/usrp2/firmware/apps/app_common_v2.c
+++ b/usrp2/firmware/apps/app_common_v2.c
@@ -43,8 +43,8 @@ static unsigned char exp_seqno __attribute__((unused)) = 0;
 static bool
 set_time(const op_set_time_t *p)
 {
-  printf("Setting time: secs %u, ticks %u\n", p->time_secs, p->time_ticks);
-  sr_time64->secs = p->time_secs;
+  //printf("Setting time: secs %u, ticks %u\n", p->time_secs, p->time_ticks);
+  //sr_time64->secs = p->time_secs; //set below...
   sr_time64->ticks = p->time_ticks;
   switch (p->type){
   case OP_SET_TIME_TYPE_NOW:
@@ -54,6 +54,7 @@ set_time(const op_set_time_t *p)
     sr_time64->imm = 0;
     break;
   }
+  sr_time64->secs = p->time_secs; //set this last to latch the regs
   return true;
 }
 
diff --git a/usrp2/firmware/apps/txrx.c b/usrp2/firmware/apps/txrx.c
index cd6666a..176809e 100644
--- a/usrp2/firmware/apps/txrx.c
+++ b/usrp2/firmware/apps/txrx.c
@@ -125,7 +125,7 @@ static unsigned int streaming_items_per_frame = 0;
 static uint32_t     time_secs = TIME_NOW;
 static uint32_t     time_ticks = TIME_NOW;
 static int          streaming_frame_count = 0;
-#define FRAMES_PER_CMD 1000
+#define FRAMES_PER_CMD 2
 
 bool is_streaming(void){ return streaming_p; }
 
@@ -203,10 +203,16 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, 
op_start_rx_streaming_t *p)
 void
 stop_rx_cmd(void)
 {
-  streaming_p = false;
-  sr_rx_ctrl->clear_overrun = 1;       // flush cmd queue
-  bp_clear_buf(DSP_RX_BUF_0);
-  bp_clear_buf(DSP_RX_BUF_1);
+  if (is_streaming()){
+    streaming_p = false;
+
+    // no samples, "now", not chained
+    sr_rx_ctrl->cmd = MK_RX_CMD(0, 1, 0);
+
+    sr_rx_ctrl->time_secs = 0;
+    sr_rx_ctrl->time_ticks = 0;        // enqueue command
+  }
+
 }
 
 
diff --git a/usrp2/include/usrp2/usrp2.h b/usrp2/include/usrp2/usrp2.h
index 33a88b3..f620ab5 100644
--- a/usrp2/include/usrp2/usrp2.h
+++ b/usrp2/include/usrp2/usrp2.h
@@ -60,6 +60,10 @@ namespace usrp2 {
         secs = ~0;
         ticks = ~0;
       }
+      time_spec(uint32_t new_secs, uint32_t new_ticks = 0){
+        secs = new_secs;
+        ticks = new_ticks;
+      }
   } time_spec_t;
 
   /*!
diff --git a/usrp2/lib/usrp2_impl.cc b/usrp2/lib/usrp2_impl.cc
index bdc8f1a..ec2e83b 100644
--- a/usrp2/lib/usrp2_impl.cc
+++ b/usrp2/lib/usrp2_impl.cc
@@ -425,8 +425,8 @@ namespace usrp2 {
       cmd.op.len = sizeof(cmd.op);
       cmd.op.rid = d_next_rid++;
       cmd.op.items_per_frame = htonl(items_per_frame);
-      cmd.op.time_secs = time_spec.secs;
-      cmd.op.time_ticks = time_spec.ticks;
+      cmd.op.time_secs = htonx(time_spec.secs);
+      cmd.op.time_ticks = htonx(time_spec.ticks);
       cmd.eop.opcode = OP_EOP;
       cmd.eop.len = sizeof(cmd.eop);
 
@@ -778,7 +778,7 @@ namespace usrp2 {
     cmd.op.opcode = OP_CONFIG_CLOCK;
     cmd.op.len = sizeof(cmd.op);
     cmd.op.rid = d_next_rid++;
-    cmd.op.flags = flags;
+    cmd.op.flags = htonx(flags);
     cmd.eop.opcode = OP_EOP;
     cmd.eop.len = sizeof(cmd.eop);
     
@@ -900,8 +900,8 @@ namespace usrp2 {
     cmd.op.len = sizeof(cmd.op);
     cmd.op.rid = d_next_rid++;
     cmd.op.type = OP_SET_TIME_TYPE_PPS;
-    cmd.op.time_secs = time_spec.secs;
-    cmd.op.time_ticks = time_spec.ticks;
+    cmd.op.time_secs = htonx(time_spec.secs);
+    cmd.op.time_ticks = htonx(time_spec.ticks);
 
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
     if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT))
@@ -922,8 +922,8 @@ namespace usrp2 {
     cmd.op.len = sizeof(cmd.op);
     cmd.op.rid = d_next_rid++;
     cmd.op.type = OP_SET_TIME_TYPE_NOW;
-    cmd.op.time_secs = time_spec.secs;
-    cmd.op.time_ticks = time_spec.ticks;
+    cmd.op.time_secs = htonx(time_spec.secs);
+    cmd.op.time_ticks = htonx(time_spec.ticks);
 
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
     if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]