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
11namespace 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
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)) {
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
void read(uintptr_t address, int32_t *__restrict__ buf, size_t nbytes) override
Definition DmaIntf.cc:19
virtual ~DmaIntf()
Definition DmaIntf.cc:17
void write(uintptr_t address, const int32_t *data, size_t nbytes) override
Definition DmaIntf.cc:27
Exception thrown when a runtime error has occured.
Definition Exception.h:18
std::string to_string(Boolean &value)
STL namespace.
std::string to_string(const std::string &v)