From e2fcb815141b05205ea9334e2db78f9ceffa62c3 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 12 Aug 2010 16:27:57 -0700 Subject: Added host-side support for UART messaging. Have not yet added GPS control library. Debug crap in mboard_impl.cpp constructor. --- host/lib/usrp/usrp2/mboard_impl.cpp | 7 +++++++ host/lib/usrp/usrp2/usrp2_iface.cpp | 42 +++++++++++++++++++++++++++++++++++++ host/lib/usrp/usrp2/usrp2_iface.hpp | 4 ++++ 3 files changed, 53 insertions(+) (limited to 'host') diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index a3d5e8955..19afd8122 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -110,6 +110,13 @@ usrp2_mboard_impl::usrp2_mboard_impl( (*this)[MBOARD_PROP_RX_SUBDEV_SPEC] = subdev_spec_t(); (*this)[MBOARD_PROP_TX_SUBDEV_SPEC] = subdev_spec_t(); + //TODO DEBUG! this is just here to test writing to and reading from the UART. + std::string mystr = "PTIME:TIME?\n"; + byte_vector_t mybuf(mystr.begin(), mystr.end()); + _iface->write_uart(2, mybuf); + mybuf = _iface->read_uart(2, 15); + std::cout << "DEBUG: " << std::string(mybuf.begin(), mybuf.end()) << std::endl; + //Issue a stop streaming command (in case it was left running). //Since this command is issued before the networking is setup, //most if not all junk packets will never make it to the socket. diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 44aef2a34..aa16865c1 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -171,6 +171,48 @@ public: return result; } +/*********************************************************************** + * UART + **********************************************************************/ + void write_uart(boost::uint8_t dev, const byte_vector_t &buf){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_HEY_WRITE_THIS_UART_FOR_ME_BRO); + out_data.data.uart_args.dev = dev; + out_data.data.uart_args.bytes = buf.size(); + + //limitation of uart transaction size + UHD_ASSERT_THROW(buf.size() <= sizeof(out_data.data.uart_args.data)); + + //copy in the data + std::copy(buf.begin(), buf.end(), out_data.data.uart_args.data); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_MAN_I_TOTALLY_WROTE_THAT_UART_DUDE); + } + + byte_vector_t read_uart(boost::uint8_t dev, size_t num_bytes){ + //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); + out_data.data.uart_args.dev = dev; + out_data.data.uart_args.bytes = num_bytes; + + //limitation of uart transaction size + UHD_ASSERT_THROW(num_bytes <= sizeof(out_data.data.uart_args.data)); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_I_HELLA_READ_THAT_UART_DUDE); + //UHD_ASSERT_THROW(in_data.data.uart_args.bytes = num_bytes); + + //copy out the data + byte_vector_t result(num_bytes); + std::copy(in_data.data.uart_args.data, in_data.data.uart_args.data + num_bytes, result.begin()); + return result; + } + /*********************************************************************** * Send/Recv over control **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index b9f5f0fb8..522beadfb 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -104,6 +104,10 @@ public: bool readback ) = 0; + virtual void write_uart(boost::uint8_t dev, const uhd::byte_vector_t &buf) = 0; + + virtual uhd::byte_vector_t read_uart(boost::uint8_t dev, size_t num_bytes) = 0; + /*! * Set the hardware revision number. Also selects the proper register set for the device. * \param rev the 16-bit revision -- cgit v1.2.3