commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10174 - in gnuradio/trunk: gr-usrp2/src usrp2/host/in


From: jcorgan
Subject: [Commit-gnuradio] r10174 - in gnuradio/trunk: gr-usrp2/src usrp2/host/include/usrp2 usrp2/host/lib
Date: Sun, 28 Dec 2008 10:26:30 -0700 (MST)

Author: jcorgan
Date: 2008-12-28 10:26:29 -0700 (Sun, 28 Dec 2008)
New Revision: 10174

Modified:
   gnuradio/trunk/gr-usrp2/src/usrp2.i
   gnuradio/trunk/gr-usrp2/src/usrp2_base.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_base.h
   gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
   gnuradio/trunk/usrp2/host/lib/usrp2.cc
   gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc
   gnuradio/trunk/usrp2/host/lib/usrp2_impl.h
Log:
Replaced USRP2 peek() with peek32(), handles endian-swapping if needed

Modified: gnuradio/trunk/gr-usrp2/src/usrp2.i
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-12-28 04:17:43 UTC (rev 10173)
+++ gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-12-28 17:26:29 UTC (rev 10174)
@@ -36,7 +36,7 @@
 
 %include <usrp2/tune_result.h>
 
-%template(uint8_t_vector) std::vector<uint8_t>;
+%template(uint32_t_vector) std::vector<uint32_t>;
 
 // ----------------------------------------------------------------
 
@@ -52,7 +52,7 @@
   %rename(_real_fpga_master_clock_freq) fpga_master_clock_freq;
   bool fpga_master_clock_freq(long *freq);
   bool sync_to_pps();
-  std::vector<uint8_t> peek(uint32_t addr, uint32_t len);
+  std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
 };
 
 // ----------------------------------------------------------------

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_base.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_base.cc   2008-12-28 04:17:43 UTC (rev 
10173)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_base.cc   2008-12-28 17:26:29 UTC (rev 
10174)
@@ -67,10 +67,10 @@
   return d_u2->sync_to_pps();
 }
 
-std::vector<uint8_t>
-usrp2_base::peek(uint32_t addr, uint32_t len)
+std::vector<uint32_t>
+usrp2_base::peek32(uint32_t addr, uint32_t words)
 {
-  return d_u2->peek(addr, len);
+  return d_u2->peek32(addr, words);
 }
 
 bool

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_base.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_base.h    2008-12-28 04:17:43 UTC (rev 
10173)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_base.h    2008-12-28 17:26:29 UTC (rev 
10174)
@@ -63,11 +63,10 @@
    */
   bool sync_to_pps();
 
-
   /*!
-   * \brief Read memory from Wishbone bus
+   * \brief Read memory from Wishbone bus as words
    */
-  std::vector<uint8_t> peek(uint32_t addr, uint32_t len);
+  std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
 
   /*!
    * \brief Called by scheduler when starting flowgraph

Modified: gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
===================================================================
--- gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-12-28 04:17:43 UTC 
(rev 10173)
+++ gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-12-28 17:26:29 UTC 
(rev 10174)
@@ -362,18 +362,18 @@
     bool sync_to_pps();
 
     /*!
-     * Read memory from Wishbone bus
+     * Read memory from Wishbone bus as 32-bit words.  Handles endian swapping 
if needed.
      *
      * \param addr      32-bit aligned address.  Only the lower 16-bits are 
significant.
-     * \param len       Number of bytes to read, must be positive and multiple 
of 4.
+     * \param len       Number of 32-bit words
      * 
-     * \returns         Vector of 8-bit read values
+     * \returns         Vector of 32-bit read values
      *
      * WARNING: Attempts to read memory from addresses that do not correspond 
to RAM or
      * memory-mapped peripherals may cause the USRP2 to hang, requiring a 
power cycle.
      * 
      */
-    std::vector<uint8_t> peek(uint32_t addr, uint32_t len);
+    std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
 
 
 #if 0  // not yet implemented

Modified: gnuradio/trunk/usrp2/host/lib/usrp2.cc
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2.cc      2008-12-28 04:17:43 UTC (rev 
10173)
+++ gnuradio/trunk/usrp2/host/lib/usrp2.cc      2008-12-28 17:26:29 UTC (rev 
10174)
@@ -395,10 +395,10 @@
     return d_impl->sync_to_pps();
   }
 
-  std::vector<uint8_t>
-  usrp2::peek(uint32_t addr, uint32_t len)
+  std::vector<uint32_t>
+  usrp2::peek32(uint32_t addr, uint32_t words)
   {
-    return d_impl->peek(addr, len);
+    return d_impl->peek32(addr, words);
   }
 
 } // namespace usrp2

Modified: gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc 2008-12-28 04:17:43 UTC (rev 
10173)
+++ gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc 2008-12-28 17:26:29 UTC (rev 
10174)
@@ -1039,25 +1039,27 @@
     return ntohx(reply.ok) == 1;
   }
 
-  std::vector<uint8_t>
-  usrp2::impl::peek(uint32_t addr, uint32_t len)
+  std::vector<uint32_t>
+  usrp2::impl::peek32(uint32_t addr, uint32_t words)
   {
-    std::vector<uint8_t> result; // zero sized on error return
-    // fprintf(stderr, "usrp2::peek: addr=%08X len=%u\n", addr, len);
+    std::vector<uint32_t> result; // zero sized on error return
+    // fprintf(stderr, "usrp2::peek: addr=%08X words=%u\n", addr, words);
 
     if (addr % 4 != 0) {
       fprintf(stderr, "usrp2::peek: addr (=%08X) must be 32-bit word 
aligned\n", addr); 
       return result;
     }
 
-    if (len < 4 || len % 4 != 0) {
-      fprintf(stderr, "usrp2::peek: len (=%u) must be an integral multiple of 
4\n", len);
+    if (words == 0)
       return result;
-    }
 
     op_peek_cmd   cmd;
     op_generic_t *reply;
 
+    int wlen = sizeof(uint32_t);
+    int rlen = sizeof(op_generic_t);
+    size_t bytes = words*wlen;
+
     memset(&cmd, 0, sizeof(cmd));
     init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
     cmd.op.opcode = OP_PEEK;
@@ -1067,15 +1069,15 @@
     cmd.eop.len = sizeof(cmd.eop);
 
     cmd.op.addr = htonl(addr);
-    cmd.op.bytes = htonl(len);
+    cmd.op.bytes = htonl(bytes);
 
-    reply = (op_generic_t *)malloc(sizeof(*reply)+len);
-    pending_reply p(cmd.op.rid, reply, sizeof(*reply)+len);
+    reply = (op_generic_t *)malloc(rlen+bytes);
+    pending_reply p(cmd.op.rid, reply, rlen+bytes);
     if (transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) {
-      uint32_t bytes = reply->len-sizeof(*reply);
-      uint8_t *data = (uint8_t *)(reply)+sizeof(*reply);
-      for (unsigned int i = 0; i < bytes; i++)
-       result.push_back(data[i]);
+      uint32_t nwords = (reply->len-rlen)/sizeof(uint32_t);
+      uint32_t *data = (uint32_t *)(reply+rlen/wlen);
+      for (unsigned int i = 0; i < nwords; i++)
+       result.push_back(ntohl(data[i]));
     }
 
     free(reply);

Modified: gnuradio/trunk/usrp2/host/lib/usrp2_impl.h
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2_impl.h  2008-12-28 04:17:43 UTC (rev 
10173)
+++ gnuradio/trunk/usrp2/host/lib/usrp2_impl.h  2008-12-28 17:26:29 UTC (rev 
10174)
@@ -174,7 +174,7 @@
 
     bool burn_mac_addr(const std::string &new_addr);
     bool sync_to_pps();
-    std::vector<uint8_t> peek(uint32_t addr, uint32_t len);
+    std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
   };
   
 } // namespace usrp2





reply via email to

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