18 for(_mmapSize = _mmapSizeMax; _mmapSize >= _mmapSizeMin; _mmapSize /= 2) {
19 _mem = ::mmap(NULL, _mmapSize, PROT_READ | PROT_WRITE, MAP_SHARED, _file, 0);
20 if(_mem !=
reinterpret_cast<void*
>(-1)) {
23 std::cout <<
"XDMA: mapped " << _mmapSize <<
" bytes" << std::endl;
29 std::stringstream err_msg;
30 err_msg <<
"XDMA: couldn't mmap the minimum size of " << _mmapSizeMin
31 <<
" bytes: " << strerror_r(errno, mmap_err,
sizeof(mmap_err));
36 ::munmap(_mem, _mmapSize);
39 volatile int32_t* CtrlIntf::_reg_ptr(uintptr_t offs)
const {
40 return static_cast<volatile int32_t*
>(_mem) + offs / 4;
43 void CtrlIntf::_check_range(
const std::string access_type, uintptr_t address,
size_t nBytes)
const {
44 if((address + nBytes) <= _mmapSize) {
47 std::stringstream err_msg;
48 err_msg <<
"XDMA: attempt to " << access_type <<
" beyond mapped area: " << nBytes <<
" bytes at 0x" << std::hex
49 << address << std::dec <<
" (" << _mmapSize <<
" bytes mapped)";
53 void CtrlIntf::read(uintptr_t address, int32_t* __restrict__ buf,
size_t nBytes) {
54 _check_range(
"read", address, nBytes);
55 volatile int32_t* rptr = _reg_ptr(address);
56 while(nBytes >=
sizeof(int32_t)) {
58 nBytes -=
sizeof(int32_t);
67 _check_range(
"write", address, nBytes);
68 volatile int32_t* __restrict__ wptr = _reg_ptr(address);
69 while(nBytes >=
sizeof(int32_t)) {
71 nBytes -=
sizeof(int32_t);