diff options
author | jcorgan | 2008-12-27 21:09:26 +0000 |
---|---|---|
committer | jcorgan | 2008-12-27 21:09:26 +0000 |
commit | 297479844e3d9a6eea54fa69147e6a20c0bfc412 (patch) | |
tree | 786591a2e3c8aa77d8149630a6a5d00974585af7 /usrp2/host/lib/usrp2_impl.cc | |
parent | a09700c26a39ebddbeb56b5ecddedf50f0cc7ac4 (diff) | |
download | gnuradio-297479844e3d9a6eea54fa69147e6a20c0bfc412.tar.gz gnuradio-297479844e3d9a6eea54fa69147e6a20c0bfc412.tar.bz2 gnuradio-297479844e3d9a6eea54fa69147e6a20c0bfc412.zip |
Implements USRP2 peek() command, allowing arbitrary reads from the internal
Wishbone bus. Minor fix for USRP2 sync_to_pps() (uses correct packet type.)
Example:
>>> from gnuradio import usrp2
>>> u = usrp2.source_32fc()
>>> u.peek(0x1234, 4) # Read four bytes at offset 0x1234 (code)
(185, 244, 253, 164)
>>>
The return value will be zero length upon error.
The read address must be 32-bit aligned, and only the lower 16 bits are
significant. The length must be an integral multiple of 4 bytes. There is
currently a read limit of 176 bytes per read; to change requires some additional
firmware changes to allocate a larger reply packet.
WARNING: Trying to read from memory locations not serviced by RAM or by a
Wishbone peripheral may result in a hang requiring a USRP2 power cycle. The
USRP2 internal memory map is documented in usrp2/firmware/lib/memory_map.h.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10172 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'usrp2/host/lib/usrp2_impl.cc')
-rw-r--r-- | usrp2/host/lib/usrp2_impl.cc | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc index 24e6d7e73..d7769a842 100644 --- a/usrp2/host/lib/usrp2_impl.cc +++ b/usrp2/host/lib/usrp2_impl.cc @@ -72,12 +72,9 @@ namespace usrp2 { case OP_DBOARD_INFO: return "OP_DBOARD_INFO"; case OP_DBOARD_INFO_REPLY: return "OP_DBOARD_INFO_REPLY"; case OP_SYNC_TO_PPS: return "OP_SYNC_TO_PPS"; -#if 0 - case OP_WRITE_REG: return "OP_WRITE_REG"; - case OP_WRITE_REG_MASKED: return "OP_WRITE_REG_MASKED"; - case OP_READ_REG: return "OP_READ_REG"; - case OP_READ_REG_REPLY: return "OP_READ_REG_REPLY"; -#endif + case OP_PEEK: return "OP_PEEK"; + case OP_PEEK_REPLY: return "OP_PEEK_REPLY"; + default: char buf[64]; snprintf(buf, sizeof(buf), "<unknown opcode: %d>", opcode); @@ -1024,8 +1021,8 @@ namespace usrp2 { bool usrp2::impl::sync_to_pps() { - op_config_mimo_cmd cmd; - op_generic_t reply; + op_generic_cmd cmd; + op_generic_t reply; memset(&cmd, 0, sizeof(cmd)); init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); @@ -1042,4 +1039,47 @@ namespace usrp2 { return ntohx(reply.ok) == 1; } + std::vector<uint8_t> + usrp2::impl::peek(uint32_t addr, uint32_t len) + { + std::vector<uint8_t> result; // zero sized on error return + // fprintf(stderr, "usrp2::peek: addr=%08X len=%u\n", addr, len); + + 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); + return result; + } + + op_peek_cmd cmd; + op_generic_t *reply; + + memset(&cmd, 0, sizeof(cmd)); + init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); + cmd.op.opcode = OP_PEEK; + cmd.op.len = sizeof(cmd.op); + cmd.op.rid = d_next_rid++; + cmd.eop.opcode = OP_EOP; + cmd.eop.len = sizeof(cmd.eop); + + cmd.op.addr = htonl(addr); + cmd.op.bytes = htonl(len); + + reply = (op_generic_t *)malloc(sizeof(*reply)+len); + pending_reply p(cmd.op.rid, reply, sizeof(*reply)+len); + 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]); + } + + free(reply); + return result; + } + } // namespace usrp2 |