From 1b149f561370687ad65e3aa644a402f00dbd16ea Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 7 Oct 2014 11:32:14 +0200 Subject: Initial commit E300 support. --- host/lib/usrp/e300/e300_global_regs.cpp | 131 ++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 host/lib/usrp/e300/e300_global_regs.cpp (limited to 'host/lib/usrp/e300/e300_global_regs.cpp') diff --git a/host/lib/usrp/e300/e300_global_regs.cpp b/host/lib/usrp/e300/e300_global_regs.cpp new file mode 100644 index 000000000..3ba895826 --- /dev/null +++ b/host/lib/usrp/e300/e300_global_regs.cpp @@ -0,0 +1,131 @@ +// +// Copyright 2014 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "e300_global_regs.hpp" + +#include +#include +#include +#include +#include + +namespace uhd { namespace usrp { namespace e300 { + +class global_regs_local_impl : public global_regs +{ +public: + global_regs_local_impl(const size_t ctrl_base) : _ctrl_base(ctrl_base) + { + } + + virtual ~global_regs_local_impl(void) + { + } + + boost::uint32_t peek32(const uhd::wb_iface::wb_addr_type addr) + { + // setup readback register + _poke32(_ctrl_base + global_regs::SR_CORE_READBACK, addr); + return _peek32(_ctrl_base); + } + + void poke32(const uhd::wb_iface::wb_addr_type addr, const boost::uint32_t data) + { + _poke32(_ctrl_base + static_cast(addr), data); + } + + +private: + const size_t _ctrl_base; + + UHD_INLINE void _poke32(const boost::uint32_t addr, const boost::uint32_t data) + { + volatile boost::uint32_t *p = reinterpret_cast(addr); + *p = data; + } + + UHD_INLINE boost::uint32_t _peek32(const boost::uint32_t addr) + { + volatile const boost::uint32_t *p = reinterpret_cast(addr); + return *p; + } +}; + +global_regs::sptr global_regs::make(const size_t ctrl_base) +{ + return sptr(new global_regs_local_impl(ctrl_base)); +} + +class global_regs_zc_impl : public global_regs +{ +public: + global_regs_zc_impl(uhd::transport::zero_copy_if::sptr xport) : _xport(xport) + { + } + + virtual ~global_regs_zc_impl(void) + { + } + + boost::uint32_t peek32(const uhd::wb_iface::wb_addr_type addr) + { + global_regs_transaction_t transaction; + transaction.is_poke = uhd::htonx(0); + transaction.addr = uhd::htonx( + static_cast(addr)); + { + uhd::transport::managed_send_buffer::sptr buff = _xport->get_send_buff(10.0); + if (not buff or buff->size() < sizeof(transaction)) + throw std::runtime_error("global_regs_zc_impl send timeout"); + std::memcpy(buff->cast(), &transaction, sizeof(transaction)); + buff->commit(sizeof(transaction)); + } + { + uhd::transport::managed_recv_buffer::sptr buff = _xport->get_recv_buff(10.0); + if (not buff or buff->size() < sizeof(transaction)) + throw std::runtime_error("global_regs_zc_impl recv timeout"); + std::memcpy(&transaction, buff->cast(), sizeof(transaction)); + } + return uhd::ntohx(transaction.data); + } + + void poke32(const uhd::wb_iface::wb_addr_type addr, const boost::uint32_t data) + { + global_regs_transaction_t transaction; + transaction.is_poke = uhd::htonx(1); + transaction.addr = uhd::htonx( + static_cast(addr)); + transaction.data = uhd::htonx(data); + { + uhd::transport::managed_send_buffer::sptr buff = _xport->get_send_buff(10.0); + if (not buff or buff->size() < sizeof(transaction)) + throw uhd::runtime_error("global_regs_zc_impl send timeout"); + std::memcpy(buff->cast(), &transaction, sizeof(transaction)); + buff->commit(sizeof(transaction)); + } + } + +private: + uhd::transport::zero_copy_if::sptr _xport; +}; + +global_regs::sptr global_regs::make(uhd::transport::zero_copy_if::sptr xport) +{ + return sptr(new global_regs_zc_impl(xport)); +} + +}}}; -- cgit v1.2.3