ChimeraTK-DeviceAccess
03.25.00
Loading...
Searching...
No Matches
DmaIntf.cc
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
4
#include "
DmaIntf.h
"
5
6
#include "
DeviceFile.h
"
7
#include "
Exception.h
"
8
9
#include <fcntl.h>
10
11
namespace
ChimeraTK
{
12
13
DmaIntf::DmaIntf
(
const
std::string& devicePath,
size_t
channelIdx)
14
: _c2h(devicePath +
"/c2h"
+
std
::
to_string
(channelIdx), O_RDONLY),
15
_h2c(devicePath +
"/h2c"
+
std
::
to_string
(channelIdx), O_WRONLY) {}
16
17
DmaIntf::~DmaIntf
() {}
18
19
void
DmaIntf::read
(uintptr_t address, int32_t* __restrict__ buf,
size_t
nbytes) {
20
ssize_t result = ::pread(_c2h, buf, nbytes, address);
21
if
(result !=
static_cast<
ssize_t
>
(nbytes)) {
22
throw
(
ChimeraTK::runtime_error
(
23
"DmaIntf read size mismatch: read "
+
std::to_string
(result) +
" bytes, expected "
+
std::to_string
(nbytes)));
24
}
25
}
26
27
void
DmaIntf::write
(uintptr_t address,
const
int32_t* data,
size_t
nbytes) {
28
ssize_t result = ::pwrite(_h2c, data, nbytes, address);
29
if
(result !=
static_cast<
ssize_t
>
(nbytes)) {
30
throw
(
ChimeraTK::runtime_error
(
"DmaIntf write size mismatch: wrote "
+
std::to_string
(result) +
31
" bytes, expected "
+
std::to_string
(nbytes)));
32
}
33
}
34
35
}
// namespace ChimeraTK
DeviceFile.h
DmaIntf.h
Exception.h
ChimeraTK::DmaIntf::read
void read(uintptr_t address, int32_t *__restrict__ buf, size_t nbytes) override
Definition
DmaIntf.cc:19
ChimeraTK::DmaIntf::~DmaIntf
virtual ~DmaIntf()
Definition
DmaIntf.cc:17
ChimeraTK::DmaIntf::write
void write(uintptr_t address, const int32_t *data, size_t nbytes) override
Definition
DmaIntf.cc:27
ChimeraTK::DmaIntf::DmaIntf
DmaIntf()=delete
ChimeraTK::runtime_error
Exception thrown when a runtime error has occured.
Definition
Exception.h:18
ChimeraTK
Definition
DummyBackend.h:16
ChimeraTK::to_string
std::string to_string(Boolean &value)
Definition
SupportedUserTypes.h:60
std
STL namespace.
std::to_string
std::string to_string(const std::string &v)
Definition
UnifiedBackendTest.h:694
sources
ChimeraTK-DeviceAccess
backends
xdma
src
DmaIntf.cc
Generated by
1.9.8