From 3cff6298cea5f3699aa5db5921cd6933f557a034 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 29 Nov 2017 17:39:21 -0800 Subject: mpm: Add mmap_regs_iface This is a C++-based peek/poke interface into mmaped objects. Useful for better control over UIO devices. Reviewed-By: Brent Stapleton --- mpm/include/mpm/types/mmap_regs_iface.hpp | 58 +++++++++++++++++++++++++++++++ mpm/include/mpm/types/types_python.hpp | 8 +++++ 2 files changed, 66 insertions(+) create mode 100644 mpm/include/mpm/types/mmap_regs_iface.hpp (limited to 'mpm/include') diff --git a/mpm/include/mpm/types/mmap_regs_iface.hpp b/mpm/include/mpm/types/mmap_regs_iface.hpp new file mode 100644 index 000000000..969eb8160 --- /dev/null +++ b/mpm/include/mpm/types/mmap_regs_iface.hpp @@ -0,0 +1,58 @@ +// +// Copyright 2017 Ettus Research, National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#pragma once + +#include +#include +#include +#include + +namespace mpm { namespace types { + + class mmap_regs_iface : public boost::noncopyable + { + public: + mmap_regs_iface( + const std::string &path, + const size_t length, + const size_t offset, + const bool read_only = true, + const bool open_now = true + ); + + //! Will call close() + ~mmap_regs_iface(); + + //! Open the file descriptor and mmap. Safe to call multiple times. + void open(); + + //! Close the file descriptor and mmap. Safe to call multiple times. + void close(); + + //! Write \p data to \p addr + void poke32(const uint32_t addr, const uint32_t data); + + //! Read data from \p addr + uint32_t peek32(const uint32_t addr); + + private: + void log( + mpm::types::log_level_t level, + const std::string path, + const char *comment + ); + + const std::string _path; + const size_t _length; + const size_t _offset; + const bool _read_only; + int _fd = -1; + uint32_t *_mmap = NULL; + + }; + +}} /* namespace mpm::types */ diff --git a/mpm/include/mpm/types/types_python.hpp b/mpm/include/mpm/types/types_python.hpp index 8cb5b6f6a..de777685c 100644 --- a/mpm/include/mpm/types/types_python.hpp +++ b/mpm/include/mpm/types/types_python.hpp @@ -20,6 +20,7 @@ #include "lockable.hpp" #include "regs_iface.hpp" #include "log_buf.hpp" +#include "mmap_regs_iface.hpp" void export_types() { LIBMPM_BOOST_PREAMBLE("types") @@ -52,5 +53,12 @@ void export_types() { ); }) ; + + bp::class_>("mmap_regs_iface", bp::init()) + .def("open", &mmap_regs_iface::open) + .def("close", &mmap_regs_iface::close) + .def("peek32", &mmap_regs_iface::peek32) + .def("poke32", &mmap_regs_iface::poke32) + ; } -- cgit v1.2.3