Skip to content

Commit

Permalink
Load xdaq devices plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneLin0708 committed Jan 16, 2024
1 parent 7f38717 commit 31fc274
Show file tree
Hide file tree
Showing 15 changed files with 1,006 additions and 1,039 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Linux
AccessModifierOffset: -4
BinPackArguments: false
AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
# Build
/build
/.venv
/.cache
/CMakeUserPresets.json
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(CMAKE_AUTORCC ON)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Multimedia Network Widgets Xml)
find_package(OpenCL REQUIRED)
find_package(okFrontPanel REQUIRED)
find_package(xdaq REQUIRED)

set(ICON_NAME "xdaq-icon.icns")
set(ICON_PATH ${PROJECT_SOURCE_DIR}/images/${ICON_NAME})
Expand Down Expand Up @@ -54,9 +55,16 @@ target_include_directories(IntanRHX PRIVATE

message(STATUS "Qt5 : ${Qt5_DIR}")

target_compile_features(IntanRHX PUBLIC cxx_std_14)
target_compile_features(IntanRHX PUBLIC cxx_std_17)
target_compile_options(IntanRHX PRIVATE $<$<CXX_COMPILER_ID:Clang,GNU>:-Wno-deprecated>)
target_compile_definitions(IntanRHX PUBLIC $<$<CONFIG:Debug>:DEBUG>)
find_package(nlohmann_json REQUIRED)
find_package(fmt REQUIRED)
option(Sanitize "Enable sanitizers" OFF)
# if(Sanitize)
# target_compile_options(IntanRHX PRIVATE $<$<CXX_COMPILER_ID:Clang,GNU>:-fsanitize=address,undefined>)
# target_link_options(IntanRHX PRIVATE $<$<CXX_COMPILER_ID:Clang,GNU>:-fsanitize=address,undefined>)
# endif()

target_link_libraries(
IntanRHX
Expand All @@ -68,17 +76,13 @@ target_link_libraries(
Qt5::Widgets
Qt5::Xml
OpenCL::OpenCL
okFrontPanel::okFrontPanel
# okFrontPanel::okFrontPanel
nlohmann_json::nlohmann_json
fmt::fmt
xdaq::xdaq
)


if(UseMockOkFrontPanel)
find_package(fmt REQUIRED)
target_compile_definitions(IntanRHX PRIVATE UseMockOkFrontPanel)
target_link_libraries(IntanRHX PUBLIC fmt::fmt-header-only)
endif()


# copy the bit file and kernel.cl
add_custom_command(TARGET IntanRHX POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
Expand Down
53 changes: 53 additions & 0 deletions Engine/API/Hardware/controller_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "controller_info.h"

#include <fmt/format.h>

#include <chrono>
#include <thread>

bool wait_xdaq(xdaq::Device *dev, int retry)
{
using Clock = std::chrono::high_resolution_clock;
for (; retry >= 0; --retry) {
const auto start = Clock::now();
while (true) {
if ((*dev->get_register_sync(0x22) & 0x4) == 0) return true;
if ((Clock::now() - start) > std::chrono::seconds(3)) break;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (retry == 0) return false;
dev->trigger(0x48, 3);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return false;
}

XDAQInfo read_xdaq_info(xdaq::Device *dev)
{
if (!wait_xdaq(dev, 1)) {
throw std::runtime_error("XDAQ is not ready, please restart the device and try again");
}
XDAQInfo info;
info.serial = fmt::format("{:08x}", *dev->get_register_sync(0x32));
const auto hdmi = *dev->get_register_sync(0x31);
switch ((hdmi & 0xFF)) {
case 0:
if (((hdmi & 0xFF00) >> 8) == 1)
info.model = XDAQModel::Core;
else if (((hdmi & 0xFF00) >> 8) == 3)
info.model = XDAQModel::One;
else
info.model = XDAQModel::Unknown;
break;
case 1: info.model = XDAQModel::Core; break;
case 2: info.model = XDAQModel::One; break;
default: info.model = XDAQModel::Unknown;
}
info.expander = (*dev->get_register_sync(0x35)) != 0;
info.max_rhs_channels = ((hdmi >> 16) & 0xFF) * 16;
info.max_rhd_channels = ((hdmi >> 24) & 0xFF) * 32;
if (info.model == XDAQModel::Core) {
info.max_rhd_channels /= 2;
}
return info;
}
22 changes: 22 additions & 0 deletions Engine/API/Hardware/controller_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <xdaq/xdaq/device.h>

#include <functional>
#include <string>

enum class XDAQModel { Unknown = 0, Core = 1, One = 3 };

struct XDAQInfo {
std::string plugin;
std::string id;
std::string serial;
XDAQModel model = XDAQModel::Unknown;

int max_rhd_channels = 0;
int max_rhs_channels = 0;
bool expander = false;
std::string device_config;
std::function<xdaq::Device *(std::string)> get_device = nullptr;
};

XDAQInfo read_xdaq_info(xdaq::Device *dev);
Loading

0 comments on commit 31fc274

Please sign in to comment.