summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--firmware/zpu/apps/txrx_uhd.c51
-rw-r--r--host/lib/usrp/usrp2/fw_common.h21
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp39
3 files changed, 51 insertions, 60 deletions
diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c
index a9dc2aa4c..975ec58e2 100644
--- a/firmware/zpu/apps/txrx_uhd.c
+++ b/firmware/zpu/apps/txrx_uhd.c
@@ -43,6 +43,9 @@
#include <bootloader_utils.h>
#endif
+//virtual registers in the firmware to store persistent values
+static uint32_t fw_regs[8];
+
extern uint16_t dsp0_dst_port, err0_dst_port, dsp1_dst_port;
static void handle_udp_data_packet(
@@ -167,40 +170,34 @@ static void handle_udp_ctrl_packet(
/*******************************************************************
* Peek and Poke Register
******************************************************************/
- case USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO:
- switch(ctrl_data_in->data.poke_args.num_bytes){
- case sizeof(uint32_t):
- *((uint32_t *) ctrl_data_in->data.poke_args.addr) = (uint32_t)ctrl_data_in->data.poke_args.data;
- break;
-
- case sizeof(uint16_t):
- *((uint16_t *) ctrl_data_in->data.poke_args.addr) = (uint16_t)ctrl_data_in->data.poke_args.data;
- break;
+ case USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO:
+ switch(ctrl_data_in->data.reg_args.action){
+ case USRP2_REG_ACTION_FPGA_PEEK32:
+ ctrl_data_out.data.reg_args.data = *((uint32_t *) ctrl_data_in->data.reg_args.addr);
+ break;
- case sizeof(uint8_t):
- *((uint8_t *) ctrl_data_in->data.poke_args.addr) = (uint8_t)ctrl_data_in->data.poke_args.data;
- break;
+ case USRP2_REG_ACTION_FPGA_PEEK16:
+ ctrl_data_out.data.reg_args.data = *((uint16_t *) ctrl_data_in->data.reg_args.addr);
+ break;
- }
- ctrl_data_out.id = USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE;
- break;
+ case USRP2_REG_ACTION_FPGA_POKE32:
+ *((uint32_t *) ctrl_data_in->data.reg_args.addr) = (uint32_t)ctrl_data_in->data.reg_args.data;
+ break;
- case USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO:
- switch(ctrl_data_in->data.poke_args.num_bytes){
- case sizeof(uint32_t):
- ctrl_data_out.data.poke_args.data = *((uint32_t *) ctrl_data_in->data.poke_args.addr);
- break;
+ case USRP2_REG_ACTION_FPGA_POKE16:
+ *((uint16_t *) ctrl_data_in->data.reg_args.addr) = (uint16_t)ctrl_data_in->data.reg_args.data;
+ break;
- case sizeof(uint16_t):
- ctrl_data_out.data.poke_args.data = *((uint16_t *) ctrl_data_in->data.poke_args.addr);
- break;
+ case USRP2_REG_ACTION_FW_PEEK32:
+ ctrl_data_out.data.reg_args.data = fw_regs[(ctrl_data_in->data.reg_args.addr)];
+ break;
- case sizeof(uint8_t):
- ctrl_data_out.data.poke_args.data = *((uint8_t *) ctrl_data_in->data.poke_args.addr);
- break;
+ case USRP2_REG_ACTION_FW_POKE32:
+ fw_regs[(ctrl_data_in->data.reg_args.addr)] = ctrl_data_in->data.reg_args.data;
+ break;
}
- ctrl_data_out.id = USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE;
+ ctrl_data_out.id = USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE;
break;
/*******************************************************************
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 9b49610d9..e5c60f27c 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -77,11 +77,8 @@ typedef enum{
USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO = 'h',
USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE = 'H',
- USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO = 'p',
- USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE = 'P',
-
- USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r',
- USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R',
+ USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO = 'r',
+ USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE = 'R',
USRP2_CTRL_ID_HEY_WRITE_THIS_UART_FOR_ME_BRO = 'u',
USRP2_CTRL_ID_MAN_I_TOTALLY_WROTE_THAT_UART_DUDE = 'U',
@@ -106,6 +103,15 @@ typedef enum{
USRP2_CLK_EDGE_FALL = 'f'
} usrp2_clk_edge_t;
+typedef enum{
+ USRP2_REG_ACTION_FPGA_PEEK32 = 1,
+ USRP2_REG_ACTION_FPGA_PEEK16 = 2,
+ USRP2_REG_ACTION_FPGA_POKE32 = 3,
+ USRP2_REG_ACTION_FPGA_POKE16 = 4,
+ USRP2_REG_ACTION_FW_PEEK32 = 5,
+ USRP2_REG_ACTION_FW_POKE32 = 6
+} usrp2_reg_action_t;
+
typedef struct{
uint32_t proto_ver;
uint32_t id;
@@ -128,9 +134,8 @@ typedef struct{
struct {
uint32_t addr;
uint32_t data;
- uint32_t _pad[2];
- uint8_t num_bytes; //1, 2, 4
- } poke_args;
+ uint8_t action;
+ } reg_args;
struct {
uint8_t dev;
uint8_t bytes;
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index d88d31765..87a878b10 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -83,19 +83,19 @@ public:
* Peek and Poke
**********************************************************************/
void poke32(boost::uint32_t addr, boost::uint32_t data){
- return this->poke<boost::uint32_t>(addr, data);
+ this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FPGA_POKE32>(addr, data);
}
boost::uint32_t peek32(boost::uint32_t addr){
- return this->peek<boost::uint32_t>(addr);
+ return this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FPGA_PEEK32>(addr);
}
void poke16(boost::uint32_t addr, boost::uint16_t data){
- return this->poke<boost::uint16_t>(addr, data);
+ this->get_reg<boost::uint16_t, USRP2_REG_ACTION_FPGA_POKE16>(addr, data);
}
boost::uint16_t peek16(boost::uint32_t addr){
- return this->peek<boost::uint16_t>(addr);
+ return this->get_reg<boost::uint16_t, USRP2_REG_ACTION_FPGA_PEEK16>(addr);
}
/***********************************************************************
@@ -201,9 +201,9 @@ public:
}
std::string read_uart(boost::uint8_t dev){
- int readlen = 20;
+ int readlen = 20;
std::string result;
- while(readlen == 20) { //while we keep receiving full packets
+ while(readlen == 20) { //while we keep receiving full packets
//setup the out data
usrp2_ctrl_data_t out_data;
out_data.id = htonl(USRP2_CTRL_ID_SO_LIKE_CAN_YOU_READ_THIS_UART_BRO);
@@ -305,30 +305,19 @@ private:
/***********************************************************************
* Private Templated Peek and Poke
**********************************************************************/
- template <class T> void poke(boost::uint32_t addr, T data){
+ template <class T, usrp2_reg_action_t action>
+ T get_reg(boost::uint32_t addr, T data = 0){
//setup the out data
usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO);
- out_data.data.poke_args.addr = htonl(addr);
- out_data.data.poke_args.data = htonl(boost::uint32_t(data));
- out_data.data.poke_args.num_bytes = sizeof(T);
+ out_data.id = htonl(USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO);
+ out_data.data.reg_args.addr = htonl(addr);
+ out_data.data.reg_args.data = htonl(boost::uint32_t(data));
+ out_data.data.reg_args.action = action;
//send and recv
usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data, MIN_PROTO_COMPAT_REG);
- UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE);
- }
-
- template <class T> T peek(boost::uint32_t addr){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO);
- out_data.data.poke_args.addr = htonl(addr);
- out_data.data.poke_args.num_bytes = sizeof(T);
-
- //send and recv
- usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data, MIN_PROTO_COMPAT_REG);
- UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE);
- return T(ntohl(in_data.data.poke_args.data));
+ UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE);
+ return T(ntohl(in_data.data.reg_args.data));
}
};