commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7972 - in usrp2/trunk/host: apps lib


From: eb
Subject: [Commit-gnuradio] r7972 - in usrp2/trunk/host: apps lib
Date: Sat, 8 Mar 2008 13:32:00 -0700 (MST)

Author: eb
Date: 2008-03-08 13:32:00 -0700 (Sat, 08 Mar 2008)
New Revision: 7972

Modified:
   usrp2/trunk/host/apps/tx_samples_at_t.cc
   usrp2/trunk/host/lib/usrp2_basic.cc
   usrp2/trunk/host/lib/usrp2_basic.h
Log:
work-in-progress: get FPGA time

Modified: usrp2/trunk/host/apps/tx_samples_at_t.cc
===================================================================
--- usrp2/trunk/host/apps/tx_samples_at_t.cc    2008-03-08 18:52:25 UTC (rev 
7971)
+++ usrp2/trunk/host/apps/tx_samples_at_t.cc    2008-03-08 20:32:00 UTC (rev 
7972)
@@ -214,8 +214,36 @@
 
 
   // FIXME query u2 for it's current idea of time
-  uint32_t t_now = 0;
+  uint32_t t_now;
 
+  if (!u2->read_time(which, &t_now)){
+    std::cerr << "tx_samples: read_time failed\n";
+    return 1;
+  }
+
+  if (1){
+    // quick test of roundtrip
+    static const int NTIMES = 10;
+    uint32_t times[NTIMES];
+    for (int i = 0; i < NTIMES; i++){
+      if (!u2->read_time(which, &times[i])){
+       std::cerr << "tx_samples: read_time(2) failed\n";
+       return 1;
+      }
+    }
+
+    int sum_delta = 0;
+    for (int i = 1; i < NTIMES; i++){
+      int delta;
+      delta = times[i] - times[i-1];
+      sum_delta += delta;
+      printf("times[%2d] = %9d  delta = %6d\n", i, times[i], delta);
+    }
+    printf("avg delta = %6d\n", sum_delta / (NTIMES - 1));
+
+    t_now = times[NTIMES - 1];
+  }
+
   // start 0.25 second in the future
   uint32_t t_send =
     t_now + static_cast<uint32_t>(u2->fpga_master_clock_freq() * 0.25);

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-03-08 18:52:25 UTC (rev 7971)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-03-08 20:32:00 UTC (rev 7972)
@@ -36,6 +36,17 @@
 #endif
 
 
+/*
+ * Note, this should be considered a first cut at getting
+ * enough implemented to check out the h/w.  We will probably
+ * completely rework this in the near future.
+ *
+ * Large issues to be discussed and decided include the fundamental
+ * nature of the interaction between USRP2 and app, do reads for
+ * control info block, or is everything asynchronous, use of
+ * callbacks, etc.
+ */
+
 #define        MIN_PKTLEN   64         // per ethernet spec
 #define MAX_PKTLEN 2048                // biggest thing USRP2 can swallow
 
@@ -443,6 +454,59 @@
 }
 
 
+bool
+usrp2_basic::read_time(const u2_mac_addr_t &which, uint32_t *time)
+{
+  *time = 0;
+
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
+
+  struct command {
+    u2_eth_packet_t    h;
+    op_read_time_t     op;
+  };
+    
+  command      *c = (command *) pktbuf;
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
+
+  c->op.opcode = OP_READ_TIME;
+  c->op.len = sizeof(op_read_time_t);
+  c->op.rid_mbz = 0;
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len)
+    return false;
+
+  // Wait for the answer.  Note that this really needs to be
+  // thought through.  In general we could be in the middle of
+  // receiving other packets and need some kind of state machine /
+  // state chart to handle this, defer other packets, etc.
+
+  len = d_ethernet->read_packet(pktbuf, sizeof(*pktbuf));
+  // printf("read_packet = %d\n", len);
+    
+  if (len <= 0)
+    return false;
+
+  // shouldn't happen
+  if ((size_t) len < sizeof(u2_eth_packet_t))
+    return false;
+
+  if (u2p_chan(&((u2_eth_packet_t *)pktbuf)->fixed) != CONTROL_CHAN)
+    return false;
+
+  // point to beginning of payload (subpackets)
+  unsigned char *p = pktbuf + sizeof(u2_eth_packet_t);
+  int opcode = p[0];
+
+  if (opcode == OP_READ_TIME_REPLY){
+    *time = ((op_read_time_reply_t *) p)->time;
+    return true;
+  }
+
+  return false;
+}
+
 // ------------------------------------------------------------------------
 
 std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x)

Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h  2008-03-08 18:52:25 UTC (rev 7971)
+++ usrp2/trunk/host/lib/usrp2_basic.h  2008-03-08 20:32:00 UTC (rev 7972)
@@ -146,6 +146,15 @@
                     u2_eth_samples_t *pkt, size_t nsamples);
 
 
+  /*!
+   * \brief Read FPGA's idea of time
+   *
+   * N.B., this interface will probably change.
+   * We're using it now for testing only.
+   */
+  bool read_time(const u2_mac_addr_t &which, uint32_t *time);
+  
+
   bool burn_mac_addr(const u2_mac_addr_t &which,
                     const u2_mac_addr_t &new_addr);
 





reply via email to

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