summaryrefslogtreecommitdiff
path: root/usrp2
diff options
context:
space:
mode:
Diffstat (limited to 'usrp2')
-rw-r--r--usrp2/host/include/usrp2/usrp2.h8
-rw-r--r--usrp2/host/lib/usrp2.cc6
-rw-r--r--usrp2/host/lib/usrp2_impl.cc30
-rw-r--r--usrp2/host/lib/usrp2_impl.h2
4 files changed, 24 insertions, 22 deletions
diff --git a/usrp2/host/include/usrp2/usrp2.h b/usrp2/host/include/usrp2/usrp2.h
index e942bb579..ea906cdc7 100644
--- a/usrp2/host/include/usrp2/usrp2.h
+++ b/usrp2/host/include/usrp2/usrp2.h
@@ -362,18 +362,18 @@ namespace usrp2 {
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
diff --git a/usrp2/host/lib/usrp2.cc b/usrp2/host/lib/usrp2.cc
index 136062d08..37d8aaa33 100644
--- a/usrp2/host/lib/usrp2.cc
+++ b/usrp2/host/lib/usrp2.cc
@@ -395,10 +395,10 @@ namespace usrp2 {
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
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index d7769a842..c44c65981 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -1039,25 +1039,27 @@ namespace usrp2 {
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 @@ namespace usrp2 {
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);
diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h
index d9701287e..0a6b97b86 100644
--- a/usrp2/host/lib/usrp2_impl.h
+++ b/usrp2/host/lib/usrp2_impl.h
@@ -174,7 +174,7 @@ namespace usrp2 {
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