From 61ca7aa44f1c29d653114238cd0e87ad7cccecd7 Mon Sep 17 00:00:00 2001 From: daniel-k Date: Tue, 19 Dec 2017 19:02:14 +0100 Subject: [PATCH] fpga/ip: add C++ timer implementation --- fpga/include/villas/fpga/ips/timer.hpp | 82 ++++++++++++++++++++++++++ fpga/lib/CMakeLists.txt | 1 + fpga/lib/ips/timer.cpp | 54 +++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 fpga/include/villas/fpga/ips/timer.hpp create mode 100644 fpga/lib/ips/timer.cpp diff --git a/fpga/include/villas/fpga/ips/timer.hpp b/fpga/include/villas/fpga/ips/timer.hpp new file mode 100644 index 000000000..0f28c79b5 --- /dev/null +++ b/fpga/include/villas/fpga/ips/timer.hpp @@ -0,0 +1,82 @@ +/** Timer related helper functions + * + * These functions present a simpler interface to Xilinx' Timer Counter driver (XTmrCtr_*) + * + * @author Steffen Vogel + * @author Daniel Krebs + * @copyright 2017, Steffen Vogel + * @license GNU General Public License (version 3) + * + * VILLASfpga + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +/** @addtogroup fpga VILLASfpga + * @{ + */ + +#pragma once + +#include "fpga/ip.hpp" +#include + +namespace villas { +namespace fpga { +namespace ip { + + +class Timer : public IpCore +{ +public: +// ~Timer(); + + bool start(); + +private: + XTmrCtr xtmr; +}; + + + +class TimerFactory : public IpCoreFactory { +public: + + TimerFactory() : + IpCoreFactory(getName()) + {} + + IpCore* create() + { return new Timer; } + + std::string + getName() const + { return "Timer"; } + + std::string + getDescription() const + { return "Xilinx's programmable timer / counter"; } + + Vlnv getCompatibleVlnv() const + { return {"xilinx.com:ip:axi_timer:"}; } + + std::list getDependencies() const + { return { {"intc", Vlnv("acs.eonerc.rwth-aachen.de:user:axi_pcie_intc:") } }; } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +/** @} */ diff --git a/fpga/lib/CMakeLists.txt b/fpga/lib/CMakeLists.txt index 1d639f14e..40e5df6bd 100644 --- a/fpga/lib/CMakeLists.txt +++ b/fpga/lib/CMakeLists.txt @@ -7,6 +7,7 @@ set(SOURCES card.cpp ips/timer.c + ips/timer.cpp ips/model.c ips/switch.c ips/dft.c diff --git a/fpga/lib/ips/timer.cpp b/fpga/lib/ips/timer.cpp new file mode 100644 index 000000000..246bc9a78 --- /dev/null +++ b/fpga/lib/ips/timer.cpp @@ -0,0 +1,54 @@ +/** Timer related helper functions + * + * These functions present a simpler interface to Xilinx' Timer Counter driver (XTmrCtr_*) + * + * @author Steffen Vogel + * @author Daniel Krebs + * @copyright 2017, Steffen Vogel + * @license GNU General Public License (version 3) + * + * VILLASfpga + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + + +#include "config.h" + +#include "log.hpp" +#include "fpga/ips/timer.hpp" + +namespace villas { +namespace fpga { +namespace ip { + + +// instantiate factory to make available to plugin infrastructure +static TimerFactory factory; + +bool Timer::start() +{ + XTmrCtr_Config xtmr_cfg; + xtmr_cfg.SysClockFreqHz = FPGA_AXI_HZ; + + XTmrCtr_CfgInitialize(&xtmr, &xtmr_cfg, getBaseaddr()); + XTmrCtr_InitHw(&xtmr); + + return true; +} + + +} // namespace ip +} // namespace fpga +} // namespace villas