summaryrefslogtreecommitdiff
path: root/usrp2
diff options
context:
space:
mode:
Diffstat (limited to 'usrp2')
-rw-r--r--usrp2/firmware/apps/app_common_v2.c28
-rw-r--r--usrp2/firmware/include/usrp2_eth_packet.h23
-rw-r--r--usrp2/host/include/usrp2/usrp2.h15
-rw-r--r--usrp2/host/lib/control.h12
-rw-r--r--usrp2/host/lib/usrp2.cc6
-rw-r--r--usrp2/host/lib/usrp2_impl.cc56
-rw-r--r--usrp2/host/lib/usrp2_impl.h1
7 files changed, 125 insertions, 16 deletions
diff --git a/usrp2/firmware/apps/app_common_v2.c b/usrp2/firmware/apps/app_common_v2.c
index 9bb5e4d74..b51c3b23c 100644
--- a/usrp2/firmware/apps/app_common_v2.c
+++ b/usrp2/firmware/apps/app_common_v2.c
@@ -332,6 +332,30 @@ dboard_info_cmd(const op_generic_t *p,
}
static size_t
+peek_cmd(const op_peek_t *p,
+ void *reply_payload, size_t reply_payload_space)
+{
+ op_generic_t *r = (op_generic_t *) reply_payload;
+
+ putstr("peek: addr="); puthex32(p->addr);
+ printf(" bytes=%u\n", p->bytes);
+
+ if (reply_payload_space < (sizeof(*r) + p->bytes)) {
+ putstr("peek: insufficient reply packet space\n");
+ return 0; // FIXME do partial read?
+ }
+
+ r->opcode = OP_PEEK_REPLY;
+ r->len = sizeof(*r)+p->bytes;
+ r->rid = p->rid;
+ r->ok = true;
+
+ memcpy_wa(reply_payload+sizeof(*r), p->addr, p->bytes);
+
+ return r->len;
+}
+
+static size_t
generic_reply(const op_generic_t *p,
void *reply_payload, size_t reply_payload_space,
bool ok)
@@ -435,6 +459,10 @@ handle_control_chan_frame(u2_eth_packet_t *pkt, size_t len)
sync_to_pps((op_generic_t *) payload));
break;
+ case OP_PEEK:
+ subpktlen = peek_cmd((op_peek_t *)payload, reply_payload, reply_payload_space);
+ break;
+
default:
printf("app_common_v2: unhandled opcode = %d\n", gp->opcode);
break;
diff --git a/usrp2/firmware/include/usrp2_eth_packet.h b/usrp2/firmware/include/usrp2_eth_packet.h
index cfff0dd08..8a9994f17 100644
--- a/usrp2/firmware/include/usrp2_eth_packet.h
+++ b/usrp2/firmware/include/usrp2_eth_packet.h
@@ -185,12 +185,8 @@ typedef struct {
#define OP_DBOARD_INFO_REPLY (OP_DBOARD_INFO | OP_REPLY_BIT)
#define OP_SYNC_TO_PPS 10
#define OP_SYNC_TO_PPS_REPLY (OP_SYNC_TO_PPS | OP_REPLY_BIT)
-
-
-//#define OP_WRITE_REG xx // not implemented
-//#define OP_WRITE_REG_MASKED xx
-//#define OP_READ_REG xx
-//#define OP_READ_REG_REPLY xx
+#define OP_PEEK 11
+#define OP_PEEK_REPLY (OP_PEEK | OP_REPLY_BIT)
/*
* All subpackets are a multiple of 4 bytes long.
@@ -203,7 +199,7 @@ typedef struct {
*
* Used by:
* OP_EOP, OP_BURN_MAC_ADDR_REPLY, OP_START_RX_STREAMING_REPLY,
- * OP_STOP_RX_REPLY, OP_DBOARD_INFO
+ * OP_STOP_RX_REPLY, OP_DBOARD_INFO, OP_SYNC_TO_PPS
*/
typedef struct {
uint8_t opcode;
@@ -380,7 +376,17 @@ typedef struct {
u2_db_info_t rx_db_info;
} _AL4 op_dboard_info_reply_t;
-
+/*!
+ * \brief Read from Wishbone memory
+ */
+typedef struct {
+ uint8_t opcode;
+ uint8_t len;
+ uint8_t rid;
+ uint8_t mbz;
+ uint32_t addr;
+ uint32_t bytes;
+} _AL4 op_peek_t;
/*
* ================================================================
@@ -399,6 +405,7 @@ typedef union {
op_config_tx_v2_t op_config_tx_v2;
op_config_tx_reply_v2_t op_config_tx_reply_v2;
op_config_mimo_t op_config_mimo;
+ op_peek_t op_peek;
} u2_subpkt_t;
diff --git a/usrp2/host/include/usrp2/usrp2.h b/usrp2/host/include/usrp2/usrp2.h
index 4fa9da1ee..e942bb579 100644
--- a/usrp2/host/include/usrp2/usrp2.h
+++ b/usrp2/host/include/usrp2/usrp2.h
@@ -361,6 +361,21 @@ namespace usrp2 {
*/
bool sync_to_pps();
+ /*!
+ * Read memory from Wishbone bus
+ *
+ * \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.
+ *
+ * \returns Vector of 8-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);
+
+
#if 0 // not yet implemented
/*!
* \brief Write EEPROM on motherboard or any daughterboard.
diff --git a/usrp2/host/lib/control.h b/usrp2/host/lib/control.h
index fe30b3f74..774ca85f6 100644
--- a/usrp2/host/lib/control.h
+++ b/usrp2/host/lib/control.h
@@ -23,6 +23,13 @@
#include <usrp2_eth_packet.h>
namespace usrp2 {
+
+ struct op_generic_cmd {
+ u2_eth_packet_t h;
+ op_generic_t op;
+ op_generic_t eop;
+ };
+
/*!
* OP_CONFIG_RX_V2 command packet
*/
@@ -73,6 +80,11 @@ namespace usrp2 {
op_generic_t eop;
};
+ struct op_peek_cmd {
+ u2_eth_packet_t h;
+ op_peek_t op;
+ op_generic_t eop;
+ };
/*!
* Control mechanism to allow API calls to block waiting for reply packets
diff --git a/usrp2/host/lib/usrp2.cc b/usrp2/host/lib/usrp2.cc
index ecfc0b30a..136062d08 100644
--- a/usrp2/host/lib/usrp2.cc
+++ b/usrp2/host/lib/usrp2.cc
@@ -395,6 +395,12 @@ namespace usrp2 {
return d_impl->sync_to_pps();
}
+ std::vector<uint8_t>
+ usrp2::peek(uint32_t addr, uint32_t len)
+ {
+ return d_impl->peek(addr, len);
+ }
+
} // namespace usrp2
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
diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h
index f5030f541..d9701287e 100644
--- a/usrp2/host/lib/usrp2_impl.h
+++ b/usrp2/host/lib/usrp2_impl.h
@@ -174,6 +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);
};
} // namespace usrp2