mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-07-13 06:40:33 +02:00
moved memory for Bus communication to BucCommunication class
This commit is contained in:
@@ -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<IPCore, MemoryModel> busCommunication{};
|
||||
BusCommunication<MatterhornDefs::MatterHornIPCores, MemoryModel>
|
||||
busCommunication{};
|
||||
|
||||
using SPICommunicationClass = std::conditional_t<
|
||||
std::is_same_v<DerivedServer, VirtualMatterhornServer>,
|
||||
SPICommunication<VirtualSPICommunication<MatterhornSPIRegisters>>,
|
||||
SPICommunication<
|
||||
VirtualSPICommunication<MatterhornDefs::MatterhornSPIRegisters>>,
|
||||
SPICommunication<HardwareSPICommunication>>;
|
||||
|
||||
SPICommunicationClass spiCommunication{};
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include "RegisterDefs.hpp"
|
||||
#include "SPIRegisterDefs.hpp"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
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<SPIRegister, 10> 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<IPCore, 5> 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
|
||||
@@ -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 <typename MemoryModel>
|
||||
struct IpCoreRegisterBlock<IPCore, MemoryModel> {
|
||||
|
||||
std::map<IPCore, MemoryModel> &operator()() { return memoryblocks_; }
|
||||
|
||||
const std::map<IPCore, MemoryModel> &operator()() const {
|
||||
return memoryblocks_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<IPCore, MemoryModel> memoryblocks_{
|
||||
{IPCore::MH_RO_SM_AXI,
|
||||
MemoryModel{static_cast<uint32_t>(IPCore::MH_RO_SM_AXI),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}},
|
||||
{IPCore::FHDR_AXI, MemoryModel{static_cast<uint32_t>(IPCore::FHDR_AXI),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}},
|
||||
{IPCore::AURORA_STATUS,
|
||||
MemoryModel{static_cast<uint32_t>(IPCore::AURORA_STATUS),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}},
|
||||
{IPCore::AURORA_STATUS2,
|
||||
MemoryModel{static_cast<uint32_t>(IPCore::AURORA_STATUS2),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}},
|
||||
{IPCore::PACKETIZERREG,
|
||||
MemoryModel{static_cast<uint32_t>(IPCore::PACKETIZERREG),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}},
|
||||
{IPCore::UNKNOWN, MemoryModel{static_cast<uint32_t>(IPCore::UNKNOWN),
|
||||
IPCORE_REGISTER_BLOCK_SIZE}}};
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
@@ -14,26 +14,12 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
struct IpCoreRegisterBlock {
|
||||
template <typename IPCores, typename MemoryModel> class BusCommunication {
|
||||
|
||||
const std::map<IPCoreEnumType, MemoryModel> &operator()() const {
|
||||
return memoryblocks_;
|
||||
}
|
||||
|
||||
std::map<IPCoreEnumType, MemoryModel> &operator()() {
|
||||
return memoryblocks_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<IPCoreEnumType, MemoryModel> memoryblocks_;
|
||||
};
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
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<IPCoreEnumType, MemoryModel> 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<IPCoreEnumType, MemoryModel> ipcoreregisterblocks{};
|
||||
};
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
void BusCommunication<IPCoreEnumType, MemoryModel>::mapToMemory() {
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
BusCommunication<IPCores, MemoryModel>::BusCommunication() {
|
||||
|
||||
for (auto &map_elem : ipcoreregisterblocks()) {
|
||||
for (const auto &ip_core : IPCores::ipcores) {
|
||||
ipcoreregisterblocks.emplace(ip_core,
|
||||
MemoryModel{static_cast<uint32_t>(ip_core),
|
||||
IPCores::ip_core_block_size});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
void BusCommunication<IPCores, MemoryModel>::mapToMemory() {
|
||||
|
||||
for (auto &map_elem : ipcoreregisterblocks) {
|
||||
map_elem.second.mapToMemory();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
uint32_t BusCommunication<IPCoreEnumType, MemoryModel>::readRegister(
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
uint32_t BusCommunication<IPCores, MemoryModel>::readRegister(
|
||||
const Register ®ister_) const {
|
||||
return bus_r(register_.offset_in_bytes, register_.ip_core);
|
||||
}
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
void BusCommunication<IPCoreEnumType, MemoryModel>::writeRegister(
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
void BusCommunication<IPCores, MemoryModel>::writeRegister(
|
||||
const Register ®ister_, const uint32_t data) {
|
||||
bus_w(register_.offset_in_bytes, register_.ip_core, data);
|
||||
}
|
||||
|
||||
template <typename IPCoreEnumType, typename MemoryModel>
|
||||
uint32_t BusCommunication<IPCoreEnumType, MemoryModel>::bus_r(
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
uint32_t BusCommunication<IPCores, MemoryModel>::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 <typename IPCoreEnumType, typename MemoryModel>
|
||||
void BusCommunication<IPCoreEnumType, MemoryModel>::bus_w(
|
||||
template <typename IPCores, typename MemoryModel>
|
||||
void BusCommunication<IPCores, MemoryModel>::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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user