From b99d0f348eada0500ea5d668d5eba283afa6c4a4 Mon Sep 17 00:00:00 2001 From: Ashish Chaudhari Date: Tue, 28 May 2019 13:21:08 -0700 Subject: rfnoc: Added link/graph specific stream managers - Fleshed out mb_iface - Managers currently only export ctrl APIs. Data APIs TBD --- host/lib/rfnoc/epid_allocator.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 host/lib/rfnoc/epid_allocator.cpp (limited to 'host/lib/rfnoc/epid_allocator.cpp') diff --git a/host/lib/rfnoc/epid_allocator.cpp b/host/lib/rfnoc/epid_allocator.cpp new file mode 100644 index 000000000..984b1716e --- /dev/null +++ b/host/lib/rfnoc/epid_allocator.cpp @@ -0,0 +1,46 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include + +using namespace uhd; +using namespace uhd::rfnoc; + +epid_allocator::epid_allocator(sep_id_t start_epid) : _next_epid(start_epid) {} + + +sep_id_t epid_allocator::allocate_epid(const sep_addr_t& addr) +{ + std::lock_guard lock(_mutex); + + if (_epid_map.count(addr) == 0) { + sep_id_t new_epid = _next_epid++; + _epid_map[addr] = new_epid; + _addr_map[new_epid] = addr; + return new_epid; + } else { + return _epid_map.at(addr); + } +} + +sep_addr_t epid_allocator::lookup_epid(const sep_id_t& epid) const +{ + std::lock_guard lock(_mutex); + + if (_addr_map.count(epid) > 0) { + return _addr_map.at(epid); + } else { + throw uhd::lookup_error("The specified EPID has not been allocated"); + } +} + +void epid_allocator::deallocate_epid(sep_id_t) +{ + std::lock_guard lock(_mutex); + // TODO: Nothing to do for deallocate. + // With the current counter approach we assume that we will not run out of EPIDs +} -- cgit v1.2.3