diff --git a/common/include/villas/kernel/devices/device_ip_matcher.hpp b/common/include/villas/kernel/devices/device_ip_matcher.hpp new file mode 100644 index 000000000..dbb7c5df2 --- /dev/null +++ b/common/include/villas/kernel/devices/device_ip_matcher.hpp @@ -0,0 +1,40 @@ +/* Matcher for IP devices in an OS devicetree and ips on a fpga board. + * Matching based on address prefix in device name and ip memory address + * + * Author: Pascal Bauer + * + * SPDX-FileCopyrightText: 2023-2024 Pascal Bauer + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +class DeviceIpMatcher { +private: + std::vector devices; + std::list> ips; + +public: + DeviceIpMatcher(std::vector devices, + std::list> ips) + : devices(devices), ips(ips) {} + + std::vector, + villas::kernel::devices::IpDevice>> + match() const { + std::vector, + villas::kernel::devices::IpDevice>> + pairs; + for (auto device : devices) { + for (auto ip : ips) { + if (ip->getBaseaddr() == device.addr()) { + pairs.push_back(std::make_pair(ip, device)); + } + } + } + return pairs; + } +}; \ No newline at end of file