43 #include <boost/python.hpp>
44namespace bp = boost::python;
54rh::MemMap::MemMap(uint64_t base, uint32_t size) :
rim::Slave(4, 0xFFFFFFFF) {
63 if ((map_ =
reinterpret_cast<uint8_t*
>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, base))) ==
64 reinterpret_cast<void*
>(-1))
67 log_->debug(
"Created map to 0x%" PRIx64
" with size 0x%" PRIx32, base, size);
71 thread_ =
new std::thread(&rh::MemMap::runThread,
this);
75rh::MemMap::~MemMap() {
79void rh::MemMap::stop() {
85 munmap(
reinterpret_cast<void*
>(
const_cast<uint8_t*
>(map_)), size_);
97void rh::MemMap::runThread() {
107 if ((tran = queue_.pop()) != NULL) {
112 if (tran->expired()) {
113 log_->warning(
"Transaction expired. Id=%" PRIu32, tran->id());
118 if ((tran->size() % 4) != 0) {
119 tran->error(
"Invalid transaction size %" PRIu32
", must be an integer number of 4 bytes", tran->size());
125 if ((tran->address() + tran->size()) > size_) {
126 tran->error(
"Request transaction to address 0x%" PRIx64
" with size %" PRIu32
" is out of bounds",
133 tPtr =
reinterpret_cast<uint32_t*
>(tran->begin());
134 mPtr =
const_cast<uint32_t*
>(
reinterpret_cast<volatile uint32_t*
>(map_ + tran->address()));
136 while (count != tran->size()) {
149 log_->debug(
"Transaction id=%" PRIu32
", addr 0x%08" PRIx64
". Size=%" PRIu32
", type=%" PRIu32,
159void rh::MemMap::setup_python() {
162 bp::class_<rh::MemMap, rh::MemMapPtr, bp::bases<rim::Slave>, boost::noncopyable>(
"MemMap",
163 bp::init<uint64_t, uint32_t>());
165 bp::implicitly_convertible<rh::MemMapPtr, rim::SlavePtr>();
static GeneralError create(std::string src, const char *fmt,...)
Creates a formatted error instance.
RAII helper that releases the Python GIL for a scope.
static std::shared_ptr< rogue::Logging > create(const std::string &name, bool quiet=false)
Creates a logger instance.
std::shared_ptr< rogue::hardware::MemMap > MemMapPtr
Shared pointer alias for MemMap.
std::shared_ptr< rogue::interfaces::memory::TransactionLock > TransactionLockPtr
Shared pointer alias for TransactionLock.
static const uint32_t Write
Memory write transaction type.
std::shared_ptr< rogue::interfaces::memory::Transaction > TransactionPtr
Shared pointer alias for Transaction.
static const uint32_t Post
Memory posted write transaction type.