20 for(_mmapSize = _mmapSizeMax; _mmapSize >= _mmapSizeMin; _mmapSize /= 2) {
21 _mem = ::mmap(NULL, _mmapSize, PROT_READ | PROT_WRITE, MAP_SHARED, _file, 0);
22 if(_mem !=
reinterpret_cast<void*
>(-1)) {
25 std::cout <<
"XDMA: mapped " << _mmapSize <<
" bytes" << std::endl;
31 std::stringstream err_msg;
32 err_msg <<
"XDMA: couldn't mmap the minimum size of " << _mmapSizeMin
33 <<
" bytes: " << strerror_r(errno, mmap_err,
sizeof(mmap_err));
38 ::munmap(_mem, _mmapSize);
41 volatile int32_t* CtrlIntf::_reg_ptr(uintptr_t offs)
const {
42 return static_cast<volatile int32_t*
>(_mem) + offs / 4;
45 void CtrlIntf::_check_range(
const std::string access_type, uintptr_t address,
size_t nBytes)
const {
46 if((address + nBytes) <= _mmapSize) {
49 std::stringstream err_msg;
50 err_msg <<
"XDMA: attempt to " << access_type <<
" beyond mapped area: " << nBytes <<
" bytes at 0x" << std::hex
51 << address << std::dec <<
" (" << _mmapSize <<
" bytes mapped)";
55 void CtrlIntf::read(uintptr_t address, int32_t* __restrict__ buf,
size_t nBytes) {
56 _check_range(
"read", address, nBytes);
57 volatile int32_t* rptr = _reg_ptr(address);
58 while(nBytes >=
sizeof(int32_t)) {
60 nBytes -=
sizeof(int32_t);
69 _check_range(
"write", address, nBytes);
70 volatile int32_t* __restrict__ wptr = _reg_ptr(address);
71 while(nBytes >=
sizeof(int32_t)) {
73 nBytes -=
sizeof(int32_t);
void write(uintptr_t address, const int32_t *data, size_t nBytes) override
void read(uintptr_t address, int32_t *__restrict__ buf, size_t nBytes) override
Exception thrown when a runtime error has occured.