diff --git a/slsDetectorServers/matterhornServer/include/BaseMatterhornServer.h b/slsDetectorServers/matterhornServer/include/BaseMatterhornServer.h index 8ea72b8a0..5c48751b9 100644 --- a/slsDetectorServers/matterhornServer/include/BaseMatterhornServer.h +++ b/slsDetectorServers/matterhornServer/include/BaseMatterhornServer.h @@ -1,10 +1,10 @@ #pragma once #include "ArmBusCommunication.hpp" #include "DetectorServer.h" +#include "MatterhornDefs.hpp" #include "MemoryModel.hpp" #include "RegisterDefs.hpp" #include "SPICommunication.h" -#include "SpecializedTemplates.h" #include "TCPInterface.h" #include "fmt/format.h" #include "sls/logger.h" @@ -84,11 +84,13 @@ class BaseMatterhornServer // TODO: for now in MatterhornServer and not generic Server but can be // templated on different IPCore types for each detector - BusCommunication busCommunication{}; + BusCommunication + busCommunication{}; using SPICommunicationClass = std::conditional_t< std::is_same_v, - SPICommunication>, + SPICommunication< + VirtualSPICommunication>, SPICommunication>; SPICommunicationClass spiCommunication{}; diff --git a/slsDetectorServers/matterhornServer/include/MatterhornDefs.hpp b/slsDetectorServers/matterhornServer/include/MatterhornDefs.hpp index 7123af31a..fd283b78f 100644 --- a/slsDetectorServers/matterhornServer/include/MatterhornDefs.hpp +++ b/slsDetectorServers/matterhornServer/include/MatterhornDefs.hpp @@ -1,4 +1,7 @@ #pragma once +#include "RegisterDefs.hpp" +#include "SPIRegisterDefs.hpp" +#include #include namespace sls { @@ -7,6 +10,9 @@ namespace MatterhornDefs { constexpr uint8_t NUM_CHIPS_PER_MODULE = 8; +// TODO: should probably be a specialized template struct + +/// @brief list of Matterhorn SPI registers struct MatterhornSPIRegisters { constexpr static std::array spiregisters{ @@ -25,6 +31,18 @@ struct MatterhornSPIRegisters { MatterhornDefs::NUM_CHIPS_PER_MODULE; }; +/// @brief list of Matterhorn IP cores +struct MatterHornIPCores { + + using ipcore_enum_type = IPCore; + + constexpr static std::array ipcores{ + IPCore::MH_RO_SM_AXI, IPCore::FHDR_AXI, IPCore::AURORA_STATUS, + IPCore::AURORA_STATUS2, IPCore::PACKETIZERREG}; + + constexpr static size_t ip_core_block_size = IPCORE_REGISTER_BLOCK_SIZE; +}; + } // namespace MatterhornDefs } // namespace sls \ No newline at end of file diff --git a/slsDetectorServers/matterhornServer/include/SpecializedTemplates.h b/slsDetectorServers/matterhornServer/include/SpecializedTemplates.h deleted file mode 100644 index f051ccca9..000000000 --- a/slsDetectorServers/matterhornServer/include/SpecializedTemplates.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "ArmBusCommunication.hpp" -#include "MemoryModel.hpp" -#include "RegisterDefs.hpp" - -/** - * @file SpecializedTemplates.h - * @short contains specializations of the template classes for the Matterhorn - * server implementation - */ -namespace sls { - -template -struct IpCoreRegisterBlock { - - std::map &operator()() { return memoryblocks_; } - - const std::map &operator()() const { - return memoryblocks_; - } - - private: - std::map memoryblocks_{ - {IPCore::MH_RO_SM_AXI, - MemoryModel{static_cast(IPCore::MH_RO_SM_AXI), - IPCORE_REGISTER_BLOCK_SIZE}}, - {IPCore::FHDR_AXI, MemoryModel{static_cast(IPCore::FHDR_AXI), - IPCORE_REGISTER_BLOCK_SIZE}}, - {IPCore::AURORA_STATUS, - MemoryModel{static_cast(IPCore::AURORA_STATUS), - IPCORE_REGISTER_BLOCK_SIZE}}, - {IPCore::AURORA_STATUS2, - MemoryModel{static_cast(IPCore::AURORA_STATUS2), - IPCORE_REGISTER_BLOCK_SIZE}}, - {IPCore::PACKETIZERREG, - MemoryModel{static_cast(IPCore::PACKETIZERREG), - IPCORE_REGISTER_BLOCK_SIZE}}, - {IPCore::UNKNOWN, MemoryModel{static_cast(IPCore::UNKNOWN), - IPCORE_REGISTER_BLOCK_SIZE}}}; -}; - -} // namespace sls \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/ArmBusCommunication.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/ArmBusCommunication.hpp index 3cc5222d7..5b43bf16f 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/ArmBusCommunication.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/ArmBusCommunication.hpp @@ -14,26 +14,12 @@ namespace sls { -template -struct IpCoreRegisterBlock { +template class BusCommunication { - const std::map &operator()() const { - return memoryblocks_; - } - - std::map &operator()() { - return memoryblocks_; - } - - private: - std::map memoryblocks_; -}; - -template -class BusCommunication { + using IPCoreEnumType = typename IPCores::ipcore_enum_type; public: - BusCommunication() = default; + BusCommunication(); void mapToMemory(); @@ -41,48 +27,59 @@ class BusCommunication { void writeRegister(const Register ®ister_, const uint32_t data); private: - /// @brief stores register blocks for each IP core - IpCoreRegisterBlock ipcoreregisterblocks; - void bus_w(const uint32_t offset, IPCoreEnumType baseadress, const uint32_t data); uint32_t bus_r(const uint32_t offset, IPCoreEnumType baseadress) const; + + /// @brief map from id of IP Core to memory model for the register block of + /// the IP core + std::map ipcoreregisterblocks{}; }; -template -void BusCommunication::mapToMemory() { +template +BusCommunication::BusCommunication() { - for (auto &map_elem : ipcoreregisterblocks()) { + for (const auto &ip_core : IPCores::ipcores) { + ipcoreregisterblocks.emplace(ip_core, + MemoryModel{static_cast(ip_core), + IPCores::ip_core_block_size}); + } +} + +template +void BusCommunication::mapToMemory() { + + for (auto &map_elem : ipcoreregisterblocks) { map_elem.second.mapToMemory(); } } -template -uint32_t BusCommunication::readRegister( +template +uint32_t BusCommunication::readRegister( const Register ®ister_) const { return bus_r(register_.offset_in_bytes, register_.ip_core); } -template -void BusCommunication::writeRegister( +template +void BusCommunication::writeRegister( const Register ®ister_, const uint32_t data) { bus_w(register_.offset_in_bytes, register_.ip_core, data); } -template -uint32_t BusCommunication::bus_r( +template +uint32_t BusCommunication::bus_r( const uint32_t offset, const IPCoreEnumType baseadress) const { - auto ptr1 = ipcoreregisterblocks().at(baseadress).getMappedMemoryPtr() + + auto ptr1 = ipcoreregisterblocks.at(baseadress).getMappedMemoryPtr() + offset / (sizeof(uint32_t)); return *ptr1; } -template -void BusCommunication::bus_w( +template +void BusCommunication::bus_w( const uint32_t offset, const IPCoreEnumType baseadress, const uint32_t data) { - auto ptr1 = ipcoreregisterblocks().at(baseadress).getMappedMemoryPtr() + + auto ptr1 = ipcoreregisterblocks.at(baseadress).getMappedMemoryPtr() + offset / (sizeof(uint32_t)); *ptr1 = data; }