diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 21 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 39 |
2 files changed, 27 insertions, 33 deletions
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)); } }; |