diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 215a9e07b..6b62d682a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,31 +1,28 @@ // For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: // https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp -// -// SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University -// SPDX-License-Identifier: Apache-2.0 { - "name": "VILLASnode", - "image": "registry.git.rwth-aachen.de/acs/public/villas/node/dev-vscode", - // Uncomment to build the devcontainer locally - // "build": { - // "dockerfile": "../packaging/docker/Dockerfile.fedora", - // "target": "dev-vscode", - // "context": ".." - // }, - "remoteUser": "villas", - "runArgs": [ - "--privileged", - "--security-opt", - "seccomp=unconfined" - ], - "customizations": { - "vscode": { - "extensions": [ - "ms-vscode.cpptools-extension-pack", - "llvm-vs-code-extensions.vscode-clangd", - "xaver.clang-format", - "EditorConfig.EditorConfig" - ] - } - } + "name": "VILLASnode", + "image": "registry.git.rwth-aachen.de/acs/public/villas/node/dev-vscode", + // Uncomment to build the devcontainer locally + // "build": { + // "dockerfile": "../packaging/docker/Dockerfile.fedora", + // "target": "dev-vscode", + // "context": ".." + // }, + "remoteUser": "villas", + "runArgs": [ + "--privileged", + "--security-opt", + "seccomp=unconfined" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools-extension-pack", + "llvm-vs-code-extensions.vscode-clangd", + "xaver.clang-format", + "EditorConfig.EditorConfig" + ] + } + } } diff --git a/.editorconfig b/.editorconfig index 6e05103d5..b5ea25092 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,9 +23,9 @@ indent_style = space indent_size = 4 [*.conf] -indent_style = tab -indent_size = 8 +indent_style = space +indent_size = 4 -[*.nix] +[*.{nix,json}] indent_style = space indent_size = 2 diff --git a/.envrc b/.envrc index 604dd135d..6dff70de7 100644 --- a/.envrc +++ b/.envrc @@ -1,36 +1,4 @@ # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 -export_or_unset() -{ - local var=$1 - - if [ -z "${!var+x}" ]; then - return - fi - - if [ -n "$2" ]; then - export $var="$2" - else - unset $var - fi - -} - -if direnv_version "2.30.0" \ -&& has nix \ -&& nix show-config experimental-features 2>/dev/null | grep -wqF flakes -then - local oldtmp="$TMP" - local oldtemp="$TEMP" - local oldtmpdir="$TMPDIR" - local oldtempdir="$TEMPDIR" - - watch_file ./packaging/nix/*.nix - use flake ./packaging/nix - - export_or_unset TMP "$oldtmp" - export_or_unset TEMP "$oldtemp" - export_or_unset TMPDIR "$oldtmpdir" - export_or_unset TEMPDIR "$oldtempdir" -fi +use flake diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index a2cf7c8ec..d9fd701e2 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -10,3 +10,12 @@ aa16979fdde7cd377977c38eaee02062c3908515 # Update Steffens mail address 7eec1bb75339c60cefe5e9e558d9394e0cceecb6 + +# Introduced clang-format in common/ +5324b788bdd93b3e142a9f53b931dbfc8c3ed39d + +# Make project REUSE compliant in common/ +b1e8cd81da9a3e3d27db27d49d265afc53e0ce4d + +# Update Steffens mail address in common/ +6427fae1e4ca0467e09688d56cec0dcd7d5e600d diff --git a/.gitignore b/.gitignore index 8baeeed29..f1ccf7125 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ /build*/ *~ -*.swp .clang_complete .project .cproject @@ -12,14 +11,19 @@ .direnv/ .cache/ +*.swp +*.pyc +*.a +*.o +*.so +*.user *.egg-info/ +compile_commands.json python/dist/ +python/.eggs/ # YouCompleteMe .ycm_extra_conf.py -*.pyc - -python/.eggs/ -go/lib/_obj/ +graph.dot diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6eace4f4a..30a0981e0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,115 +14,100 @@ variables: CMAKE_EXTRA_OPTS: "-DCMAKE_BUILD_TYPE=Release -DVILLAS_COMPILE_WARNING_AS_ERROR=ON" stages: -- prepare -- build -- test -- packaging -- deploy -- latest + - prepare + - build + - test + - packaging + - deploy + - latest # Stage: prepare # Build docker image which is used to build & test VILLASnode prepare:docker: stage: prepare - image: docker:20.10 + before_script: + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker build ${DOCKER_OPTS} + - docker build ${DOCKER_OPTS} --file ${DOCKER_FILE} --tag ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} --target ${TARGET} . + - docker push ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} variables: TARGET: dev parallel: matrix: - - DISTRO: [ ubuntu, debian, rocky ] - - DISTRO: fedora - DOCKER_OPTS: --tag ${DOCKER_IMAGE}/dev:${CI_COMMIT_REF_NAME} - - DISTRO: fedora - DOCKER_FILE: packaging/docker/Dockerfile.fedora-minimal - DOCKER_IMAGE_DEV: ${DOCKER_IMAGE}/dev-fedora-minimal - - DISTRO: fedora - TARGET: dev-vscode - DOCKER_IMAGE_DEV: ${DOCKER_IMAGE}/dev-vscode + - DISTRO: [ubuntu, debian, rocky] + - DISTRO: fedora + DOCKER_OPTS: --tag ${DOCKER_IMAGE}/dev:${DOCKER_TAG} + - DISTRO: fedora + DOCKER_FILE: packaging/docker/Dockerfile.fedora-minimal + DOCKER_IMAGE_DEV: ${DOCKER_IMAGE}/dev-fedora-minimal + - DISTRO: fedora + TARGET: dev-vscode + DOCKER_IMAGE_DEV: ${DOCKER_IMAGE}/dev-vscode tags: - - docker + - docker-image-builder # Stage: build build:source: stage: build + needs: ["prepare:docker"] image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} script: - - cmake -S . -B build ${CMAKE_OPTS} ${CMAKE_EXTRA_OPTS} - - cmake --build build ${CMAKE_BUILD_OPTS} + - cmake -S . -B build ${CMAKE_OPTS} ${CMAKE_EXTRA_OPTS} + - cmake --build build ${CMAKE_BUILD_OPTS} artifacts: expire_in: 1 week paths: - - build/ + - build/ variables: CMAKE: cmake parallel: matrix: - - DISTRO: [ fedora, fedora-minimal, debian, rocky, ubuntu ] - - DISTRO: fedora-minimal - CMAKE_EXTRA_OPTS: -DVILLAS_COMPILE_WARNING_AS_ERROR=ON - -DWITH_API=OFF - -DWITH_CLIENTS=OFF - -DWITH_CONFIG=OFF - -DWITH_DOC=OFF - -DWITH_FPGA=OFF - -DWITH_GRAPHVIZ=OFF - -DWITH_HOOKS=OFF - -DWITH_LUA=OFF - -DWITH_OPENMP=OFF - -DWITH_PLUGINS=OFF - -DWITH_SRC=OFF - -DWITH_TESTS=OFF - -DWITH_TOOLS=OFF - -DWITH_WEB=OFF - -DCMAKE_MODULE_PATH=/usr/local/lib64/cmake - -DCMAKE_PREFIX_PATH=/usr/local - tags: - - docker + - DISTRO: [fedora, fedora-minimal, debian, rocky, ubuntu] + - DISTRO: fedora-minimal + CMAKE_EXTRA_OPTS: -DVILLAS_COMPILE_WARNING_AS_ERROR=ON + -DWITH_API=OFF + -DWITH_CLIENTS=OFF + -DWITH_CONFIG=OFF + -DWITH_DOC=OFF + -DWITH_FPGA=OFF + -DWITH_GRAPHVIZ=OFF + -DWITH_HOOKS=OFF + -DWITH_LUA=OFF + -DWITH_OPENMP=OFF + -DWITH_PLUGINS=OFF + -DWITH_SRC=OFF + -DWITH_TESTS=OFF + -DWITH_TOOLS=OFF + -DWITH_WEB=OFF + -DCMAKE_MODULE_PATH=/usr/local/lib64/cmake + -DCMAKE_PREFIX_PATH=/usr/local # Stage: test test:python: stage: test script: - - cd python - - /venv/bin/black --check . - - /venv/bin/mypy . - - /venv/bin/flake8 . - - /venv/bin/pytest -v . + - cd python + - /venv/bin/pytest --verbose . + - /venv/bin/black --extend-exclude=".*(\\.pyi|_pb2.py)$" --check . + - /venv/bin/flake8 --extend-exclude="*.pyi,*_pb2.py" . + - /venv/bin/mypy . image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} - tags: - - docker + needs: + - job: "build:source: [fedora]" test:cppcheck: stage: test script: - - cppcheck -j $(nproc) - --max-configs=32 - --error-exitcode=1 - --quiet - --inline-suppr - --enable=warning,performance,portability,missingInclude - --std=c++11 - --suppress=noValidConfiguration - -U '_MSC_VER;_WIN32;_M_ARM' - -U '_MSC_VER;_WIN32;_M_AMD64;_M_X64' - -U '_MSC_FULL_VER;_MSC_VER' - -U '_MSC_BUILD;_MSC_VER' - -I include - -I common/include - src/ lib/ tests/unit/ | tee cppcheck.log + - ./tools/run-cppcheck.sh | tee cppcheck.log image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} - tags: - - docker needs: - - job: "build:source: [fedora]" + - job: "build:source: [fedora]" artifacts: when: on_failure paths: @@ -133,66 +118,54 @@ test:unit: stage: test image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} script: - - cmake -S . -B build ${CMAKE_OPTS} - - cmake --build build ${CMAKE_BUILD_OPTS} --target run-unit-tests - tags: - - docker + - cmake -S . -B build ${CMAKE_OPTS} + - cmake --build build ${CMAKE_BUILD_OPTS} --target run-unit-tests run-unit-tests-common needs: - - job: "build:source: [fedora]" - artifacts: true + - job: "build:source: [fedora]" + artifacts: true test:integration: stage: test image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} script: - - cmake -S . -B build ${CMAKE_OPTS} - - cmake --build build ${CMAKE_BUILD_OPTS} --target run-integration-tests + - cmake -S . -B build ${CMAKE_OPTS} + - cmake --build build ${CMAKE_BUILD_OPTS} --target run-integration-tests artifacts: name: ${CI_PROJECT_NAME}-integration-tests-${CI_BUILD_REF} when: always paths: - - build/tests/integration/ + - build/tests/integration/ services: - - name: eclipse-mosquitto:2.0 - alias: mosquitto - command: [ mosquitto, -c, /mosquitto-no-auth.conf ] - - name: rwthacs/rabbitmq - alias: rabbitmq - - name: redis:6.2 - alias: redis - tags: - - docker + - name: eclipse-mosquitto:2.0 + alias: mosquitto + command: [mosquitto, -c, /mosquitto-no-auth.conf] + - name: rwthacs/rabbitmq + alias: rabbitmq + - name: redis:6.2 + alias: redis needs: - - job: "build:source: [fedora]" - artifacts: true + - job: "build:source: [fedora]" + artifacts: true test:reuse: stage: test + needs: [] image: name: fsfe/reuse:latest entrypoint: [""] - tags: - - docker script: - - reuse lint + - reuse lint # Stage: packaging pkg:docker: stage: packaging - image: docker:20.10 before_script: - - mkdir -p ~/.docker/cli-plugins/ - - wget -O ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64 - - chmod a+x ~/.docker/cli-plugins/docker-buildx - - docker buildx create --use --name cross-platform-build --buildkitd-flags "--allow-insecure-entitlement security.insecure" - - docker buildx inspect --bootstrap cross-platform-build - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + # - docker run --rm --privileged docker.io/aptman/qus -s -- -p script: - - docker buildx build ${DOCKER_OPTS} + - docker build ${DOCKER_OPTS} --pull - --allow security.insecure - --output type=docker --target ${TARGET} --build-arg ARCH=${ARCH} --build-arg TRIPLET=${TRIPLET} @@ -200,9 +173,9 @@ pkg:docker: --platform ${PLATFORM} --file ${DOCKER_FILE} --tag ${DOCKER_IMAGE}:${DOCKER_TAG}-${ARCH} . - - docker push ${DOCKER_IMAGE}:${DOCKER_TAG}-${ARCH} + - docker push ${DOCKER_IMAGE}:${DOCKER_TAG}-${ARCH} tags: - - docker + - docker variables: TARGET: app parallel: @@ -210,17 +183,17 @@ pkg:docker: - DISTRO: debian PLATFORM: linux/amd64 ARCH: x86_64 - TRIPLET: x86_64-linux-gnu - - DISTRO: debian - PLATFORM: linux/arm/v7 - ARCH: armhf - TRIPLET: arm-linux-gnueabihf - DOCKER_FILE: packaging/docker/Dockerfile.debian-multiarch - - DISTRO: debian - PLATFORM: linux/arm64/v8 - ARCH: arm64 - TRIPLET: aarch64-linux-gnu - DOCKER_FILE: packaging/docker/Dockerfile.debian-multiarch + TRIPLET: x86_64-linux-gnu + # - DISTRO: debian + # PLATFORM: linux/arm/v7 + # ARCH: armhf + # TRIPLET: arm-linux-gnueabihf + # DOCKER_FILE: packaging/docker/Dockerfile.debian-multiarch + # - DISTRO: debian + # PLATFORM: linux/arm64/v8 + # ARCH: arm64 + # TRIPLET: aarch64-linux-gnu + # DOCKER_FILE: packaging/docker/Dockerfile.debian-multiarch needs: [] @@ -228,102 +201,95 @@ pkg:docker: deploy:docker: stage: deploy - image: docker:20.10 - variables: - DOCKER_CLI_EXPERIMENTAL: enabled before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker manifest create ${DOCKER_IMAGE}:${DOCKER_TAG} - ${DOCKER_IMAGE}:${DOCKER_TAG}-x86_64 - ${DOCKER_IMAGE}:${DOCKER_TAG}-arm64 - ${DOCKER_IMAGE}:${DOCKER_TAG}-armhf - - docker manifest push ${DOCKER_IMAGE}:${DOCKER_TAG} + - docker manifest rm ${DOCKER_IMAGE}:${DOCKER_TAG} || true + - docker manifest create ${DOCKER_IMAGE}:${DOCKER_TAG} + ${DOCKER_IMAGE}:${DOCKER_TAG}-x86_64 + # ${DOCKER_IMAGE}:${DOCKER_TAG}-arm64 + # ${DOCKER_IMAGE}:${DOCKER_TAG}-armhf + - docker manifest push ${DOCKER_IMAGE}:${DOCKER_TAG} tags: - - docker + - docker needs: - - job: "pkg:docker: [debian, linux/arm64/v8, arm64, aarch64-linux-gnu, packaging/docker/Dockerfile.debian-multiarch]" - - job: "pkg:docker: [debian, linux/arm/v7, armhf, arm-linux-gnueabihf, packaging/docker/Dockerfile.debian-multiarch]" - - job: "pkg:docker: [debian, linux/amd64, x86_64, x86_64-linux-gnu]" + # - job: "pkg:docker: [debian, linux/arm64/v8, arm64, aarch64-linux-gnu, packaging/docker/Dockerfile.debian-multiarch]" + # - job: "pkg:docker: [debian, linux/arm/v7, armhf, arm-linux-gnueabihf, packaging/docker/Dockerfile.debian-multiarch]" + - job: "pkg:docker: [debian, linux/amd64, x86_64, x86_64-linux-gnu]" deploy:docker-dev: stage: deploy - image: docker:20.10 variables: DOCKER_CLI_EXPERIMENTAL: enabled before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker push ${DOCKER_IMAGE}/dev:${DOCKER_TAG} + - docker push ${DOCKER_IMAGE}/dev:${DOCKER_TAG} tags: - - docker + - docker needs: - - job: "prepare:docker: [fedora, --tag ${DOCKER_IMAGE}/dev:${CI_COMMIT_REF_NAME}]" + - job: "prepare:docker: [fedora, --tag ${DOCKER_IMAGE}/dev:${DOCKER_TAG}]" deploy:docker-dev-vscode: stage: deploy - image: docker:20.10 variables: DOCKER_CLI_EXPERIMENTAL: enabled before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker push ${DOCKER_IMAGE}/dev-vscode:${DOCKER_TAG} + - docker push ${DOCKER_IMAGE}/dev-vscode:${DOCKER_TAG} tags: - - docker + - docker needs: - - job: "prepare:docker: [fedora, dev-vscode, ${DOCKER_IMAGE}/dev-vscode]" + - job: "prepare:docker: [fedora, dev-vscode, ${DOCKER_IMAGE}/dev-vscode]" # Stage: latest - .latest:docker:latest: &deploy_latest_docker stage: latest - image: docker:20.10 before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker manifest create ${DOCKER_IMAGE}:latest - ${DOCKER_IMAGE}:${DOCKER_TAG}-x86_64 - ${DOCKER_IMAGE}:${DOCKER_TAG}-arm64 - ${DOCKER_IMAGE}:${DOCKER_TAG}-armhf - - docker manifest push ${DOCKER_IMAGE}:latest + - docker manifest create ${DOCKER_IMAGE}:latest + ${DOCKER_IMAGE}:${DOCKER_TAG}-x86_64 + ${DOCKER_IMAGE}:${DOCKER_TAG}-arm64 + ${DOCKER_IMAGE}:${DOCKER_TAG}-armhf + - docker manifest push ${DOCKER_IMAGE}:latest tags: - - docker + - docker needs: - - job: deploy:docker + - job: deploy:docker .latest:docker-dev:latest: &deploy_latest_docker_dev stage: latest - image: docker:20.10 before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} script: - - docker tag ${DOCKER_IMAGE}/dev:${DOCKER_TAG} ${DOCKER_IMAGE}/dev:latest - - docker push ${DOCKER_IMAGE}/dev:latest + - docker tag ${DOCKER_IMAGE}/dev:${DOCKER_TAG} ${DOCKER_IMAGE}/dev:latest + - docker push ${DOCKER_IMAGE}/dev:latest tags: - - docker + - docker needs: - - job: deploy:docker-dev + - job: deploy:docker-dev latest:docker: <<: *deploy_latest_docker only: - - "/^v\\d+(\\.\\d+)+$/" # Only on version tags + - "/^v\\d+(\\.\\d+)+$/" # Only on version tags latest:docker-dev: <<: *deploy_latest_docker_dev only: - - "/^v\\d+(\\.\\d+)+$/" # Only on version tags + - "/^v\\d+(\\.\\d+)+$/" # Only on version tags latest:docker:manual: <<: *deploy_latest_docker when: manual except: - - "/^v\\d+(\\.\\d+)+$/" # Only on version tags + - "/^v\\d+(\\.\\d+)+$/" # Only on version tags latest:docker-dev:manual: <<: *deploy_latest_docker_dev when: manual except: - - "/^v\\d+(\\.\\d+)+$/" # Only on version tags + - "/^v\\d+(\\.\\d+)+$/" # Only on version tags diff --git a/.gitmodules b/.gitmodules index ffec47725..162371edb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,13 +1,16 @@ # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 -[submodule "common"] - path = common - url = https://github.com/VILLASframework/common.git -[submodule "fpga"] - path = fpga - url = https://github.com/VILLASframework/fpga.git [submodule "packaging/live-iso/fedora-kickstarts"] path = packaging/live-iso/fedora-kickstarts url = https://pagure.io/fedora-kickstarts.git +[submodule "fpga/thirdparty/libxil"] + path = fpga/thirdparty/libxil + url = https://github.com/VILLASframework/libxil.git +[submodule "fpga/thirdparty/udmabuf"] + path = fpga/thirdparty/udmabuf + url = https://github.com/ikwzm/udmabuf +[submodule "fpga/lib/gpu/gdrcopy"] + path = fpga/gpu/thirdparty/gdrcopy + url = https://github.com/daniel-k/gdrcopy.git diff --git a/.reuse/dep5 b/.reuse/dep5 index 29a674205..70de7cb41 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -3,10 +3,6 @@ Upstream-Name: VILLASnode Upstream-Contact: Steffen Vogel Source: https://fein-aachen.org/en/projects/villas-node/ -Files: *.vi *.opal *.dft *.sib *.json *.ipynb doc/pictures/* clients/opal/models/send_receive/eonerc_logo.png doc/favicon.png -Copyright: 2018-2023, Institute for Automation of Complex Power Systems, RWTH Aachen University -License: Apache-2.0 - -Files: clients/rtds/**/*.txt clients/hypersim/*.ecf etc/labs/lab3.pcap packaging/live-iso/files/etc/* packaging/nix/flake.lock tests/valgrind.supp packaging/archlinux/villas-node.install +Files: *.vi *.opal *.dft *.sib *.json *.ipynb *_pb2.py doc/pictures/* doc/favicon.png clients/opal/models/send_receive/eonerc_logo.png clients/rtds/**/*.txt clients/hypersim/*.ecf etc/labs/lab3.pcap packaging/live-iso/files/etc/* flake.lock tests/valgrind.supp packaging/archlinux/villas-node.install Copyright: 2018-2023, Institute for Automation of Complex Power Systems, RWTH Aachen University License: Apache-2.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index a51f53e45..f2871bea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ find_package(RDMACM) find_package(Etherlab) find_package(Lua) find_package(LibDataChannel) +find_package(re) # Check for tools find_program(PASTE NAMES paste) @@ -117,13 +118,7 @@ pkg_check_modules(NANOMSG IMPORTED_TARGET nanomsg) if(NOT NANOMSG_FOUND) pkg_check_modules(NANOMSG IMPORTED_TARGET libnanomsg>=1.0.0) endif() -pkg_check_modules(RE IMPORTED_TARGET re>=2.9.0) -if(NOT RE_FOUND) - pkg_check_modules(RE IMPORTED_TARGET libre>=2.9.0) -endif() -if(NOT RE_FOUND) - pkg_check_modules(RE IMPORTED_TARGET re2) -endif() + if (REDISPP_FOUND) file(READ "${REDISPP_INCLUDEDIR}/sw/redis++/tls.h" CONTENTS) @@ -155,11 +150,11 @@ else() endif() FindSymbol(${LWS_LOCATION} lws_extension_callback_pm_deflate LWS_DEFLATE_FOUND) -# Check if VILLASfpga submodule is present -if(EXISTS "${PROJECT_SOURCE_DIR}/fpga/CMakeLists.txt") - set(FOUND_SUBMODULE_FPGA ON) +# Check if submodules for VILLASfpga are present +if(EXISTS "${PROJECT_SOURCE_DIR}/fpga/thirdparty/libxil/CMakeLists.txt") + set(FOUND_FPGA_SUBMODULES ON) else() - set(FOUND_SUBMODULE_FPGA OFF) + set(FOUND_FPGA_SUBMODULES OFF) endif() # Build options @@ -168,7 +163,7 @@ cmake_dependent_option(WITH_DEFAULTS "Defaults for non required build opt cmake_dependent_option(WITH_API "Build with remote control API" "${WITH_DEFAULTS}" "" OFF) cmake_dependent_option(WITH_CLIENTS "Build client applications" "${WITH_DEFAULTS}" "TOPLEVEL_PROJECT" OFF) cmake_dependent_option(WITH_CONFIG "Build with support for libconfig configuration syntax" "${WITH_DEFAULTS}" "LIBCONFIG_FOUND" OFF) -cmake_dependent_option(WITH_FPGA "Build with support for VILLASfpga" "${WITH_DEFAULTS}" "FOUND_SUBMODULE_FPGA" OFF) +cmake_dependent_option(WITH_FPGA "Build with support for VILLASfpga" "${WITH_DEFAULTS}" "FOUND_FPGA_SUBMODULES" OFF) cmake_dependent_option(WITH_GRAPHVIZ "Build with Graphviz" "${WITH_DEFAULTS}" "CGRAPH_FOUND; GVC_FOUND" OFF) cmake_dependent_option(WITH_HOOKS "Build with support for processing hook plugins" "${WITH_DEFAULTS}" "" OFF) cmake_dependent_option(WITH_LUA "Build with Lua" "${WITH_DEFAULTS}" "LUA_FOUND" OFF) @@ -199,7 +194,7 @@ cmake_dependent_option(WITH_NODE_NANOMSG "Build with nanomsg node-type" cmake_dependent_option(WITH_NODE_NGSI "Build with ngsi node-type" "${WITH_DEFAULTS}" "" OFF) cmake_dependent_option(WITH_NODE_OPAL "Build with opal node-type" "${WITH_DEFAULTS}" "Opal_FOUND" OFF) cmake_dependent_option(WITH_NODE_REDIS "Build with redis node-type" "${WITH_DEFAULTS}" "HIREDIS_FOUND; REDISPP_FOUND" OFF) -cmake_dependent_option(WITH_NODE_RTP "Build with rtp node-type" "${WITH_DEFAULTS}" "RE_FOUND" OFF) +cmake_dependent_option(WITH_NODE_RTP "Build with rtp node-type" "${WITH_DEFAULTS}" "re_FOUND" OFF) cmake_dependent_option(WITH_NODE_SHMEM "Build with shmem node-type" "${WITH_DEFAULTS}" "HAS_SEMAPHORE; HAS_MMAN" OFF) cmake_dependent_option(WITH_NODE_SIGNAL "Build with signal node-type" "${WITH_DEFAULTS}" "" OFF) cmake_dependent_option(WITH_NODE_SOCKET "Build with socket node-type" "${WITH_DEFAULTS}" "LIBNL3_ROUTE_FOUND" OFF) diff --git a/CODEOWNERS b/CODEOWNERS index afeda374d..2dec02cc1 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -13,14 +13,27 @@ # and not the global owner(s) will be requested for a review. # FPGA -fpga @n-eiling -/lib/nodes/fpga.cpp @n-eiling -/include/villas/nodes/fpga.hpp @n-eiling +fpga @n-eiling +/lib/nodes/fpga.cpp @n-eiling +/include/villas/nodes/fpga.hpp @n-eiling +/tools/hwdef-parse.py @n-eiling +/tools/fpga-* @n-eiling +/fpga @n-eiling +/etc/examples/nodes/fpga.conf @n-eiling +/etc/fpga @n-eiling +/doc/openapi/components/schemas/nodes/fpga.yaml @n-eiling + # PMU -/lib/nodes/libiec61850_goose.cpp @windrad6 -/include/villas/nodes/libiec61850_goose.hpp @windrad6 -/lib/nodes/uldaq.cpp @windrad6 -/include/villas/nodes/uldaq.hpp @windrad6 -/lib/dumper.cpp @windrad6 -/include/villas/dumper.hpp @windrad6 +/lib/nodes/libiec61850_goose.cpp @windrad6 +/include/villas/nodes/libiec61850_goose.hpp @windrad6 +/lib/nodes/uldaq.cpp @windrad6 +/include/villas/nodes/uldaq.hpp @windrad6 +/lib/dumper.cpp @windrad6 +/include/villas/dumper.hpp @windrad6 + +# VFIO related files +/common/lib/kernel/pci.cpp @n-eiling +/common/lib/kernel/vfi_*.cpp @n-eiling +/common/include/villas/kernel/devices/* @n-eiling +/common/include/villas/kernel/vfio_*.hpp @n-eiling diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt index 38ab65d4f..137069b82 100644 --- a/LICENSES/Apache-2.0.txt +++ b/LICENSES/Apache-2.0.txt @@ -1,73 +1,73 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt new file mode 100644 index 000000000..ab8be2cd4 --- /dev/null +++ b/LICENSES/BSD-3-Clause.txt @@ -0,0 +1,11 @@ +Copyright (c) 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSES/GPL-2.0-or-later.txt b/LICENSES/GPL-2.0-or-later.txt new file mode 100644 index 000000000..17cb28643 --- /dev/null +++ b/LICENSES/GPL-2.0-or-later.txt @@ -0,0 +1,117 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author + + 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 2 of the License, or (at your option) 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. + +signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice diff --git a/LICENSES/GPL-3.0-or-later.txt b/LICENSES/GPL-3.0-or-later.txt new file mode 100644 index 000000000..f6cdd22a6 --- /dev/null +++ b/LICENSES/GPL-3.0-or-later.txt @@ -0,0 +1,232 @@ +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 (at your option) 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 . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 000000000..cde4ac698 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,10 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md index 521b6e80e..d67a05792 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ VILLASnode is used in distributed- and co-simulation scenarios and developed for User documentation is available here: +## Related Projects + +- [MIOB](https://github.com/RWTH-ACS/miob) +- [DINO](https://github.com/RWTH-ACS/dino) + ## License This project is released under the terms of the [Apache 2.0 license](LICENSE). @@ -44,6 +49,9 @@ For other licensing options please consult [Prof. Antonello Monti](mailto:amonti - SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University - SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH +- SPDX-FileCopyrightText: 2022-2023 Niklas Eiling +- SPDX-FileCopyrightText: 2018-2023 Steffen Vogel +- SPDX-FileCopyrightText: 2018 Daniel Krebs - SPDX-License-Identifier: Apache-2.0 ## Contact @@ -51,8 +59,10 @@ For other licensing options please consult [Prof. Antonello Monti](mailto:amonti [![EONERC ACS Logo](doc/pictures/eonerc_logo.png)](http://www.acs.eonerc.rwth-aachen.de) - Steffen Vogel -- Marija Stevic +- Niklas Eiling +- Felix Wege +- Alexandra Bach -[Institute for Automation of Complex Power Systems (ACS)](http://www.acs.eonerc.rwth-aachen.de) -[EON Energy Research Center (EONERC)](http://www.eonerc.rwth-aachen.de) -[RWTH University Aachen, Germany](http://www.rwth-aachen.de) +[Institute for Automation of Complex Power Systems (ACS)](http://www.acs.eonerc.rwth-aachen.de) +[EON Energy Research Center (EONERC)](http://www.eonerc.rwth-aachen.de) +[RWTH University Aachen, Germany](http://www.rwth-aachen.de) diff --git a/clients/hypersim/README.md b/clients/hypersim/README.md index 858ce8283..85e7c6814 100644 --- a/clients/hypersim/README.md +++ b/clients/hypersim/README.md @@ -4,11 +4,12 @@ This directory contains a HYPERSIM user code model (UCM) for interfacing the HYP ## Documentation -Detailed information for installation and usage of the UCM is provided in the [user documentation](https://villas.fein-aachen.org/doc/node-client-hypersim.html). +Detailed information for installation and usage of the UCM is provided in the [user documentation](https://villas.fein-aachen.org/docs/node/clients/opal_hypersim). -## Author +## Authors - Anju Meghwani +- Louis Birkner ## License diff --git a/clients/hypersim/model/ucm_node.def b/clients/hypersim/model/ucm_node.def index fa959c3d7..116149512 100644 --- a/clients/hypersim/model/ucm_node.def +++ b/clients/hypersim/model/ucm_node.def @@ -109,13 +109,12 @@ UCM_DESCRIPTION = "An interface the VILLASnode gateway" %% BEGIN DOCUMENTATION -- Enter model's documentation after this line... Full documentation of this model is available at: -https://villas.fein-aachen.org/doc/node-client-hypersim.html +https://villas.fein-aachen.org/docs/node/clients/opal_hypersim -Author: - -## Author +## Authors - Anju Meghwani +- Louis Birkner Anju Meghwani is a Research Establishment Officer at Indian Institute of Kanpur, India and worked in Washington State University, Pullman as visiting scholar in Summer 2018. During her visit, she developed an interfacing framework for VILLASnode and HYPERSIM. @@ -161,7 +160,7 @@ UI-ASSIST is a joint research project between India and the US. %% Min : Minimum value allowed. %% Max : Maximum value allowed. %% Flags : Ored values of flags definitions or '-'. -%% Available values : +%% Available values : %% NOT_SIMUL_MOD : Cannot be modified during simulation. %% Description : Short description of parameter (BETWEEN DOUBLE QUOTES) %% @@ -193,7 +192,7 @@ UI-ASSIST is a joint research project between India and the US. %% Fields descriptions: %% %% Name : Connector's unique identifier (tag). -%% +%% %% Units : Signal's units. %% Text field: use the official SI symbols. %% Enter a "-" when not used @@ -219,8 +218,23 @@ UI-ASSIST is a joint research project between India and the US. switchr no int in auto S "Receive Data" switchs no int in auto S "Send Data" -datain no double in auto I "Data Input" -dataout no double out auto O "Data Output" +datain0 no double in auto I "Data Input 0" +datain1 no double in auto I "Data Input 1" +datain2 no double in auto I "Data Input 2" +datain3 no double in auto I "Data Input 3" +datain4 no double in auto I "Data Input 4" +datain5 no double in auto I "Data Input 5" +datain6 no double in auto I "Data Input 6" +datain7 no double in auto I "Data Input 7" + +dataout0 no double out auto O "Data Output 0" +dataout1 no double out auto O "Data Output 1" +dataout2 no double out auto O "Data Output 2" +dataout3 no double out auto O "Data Output 3" +dataout4 no double out auto O "Data Output 4" +dataout5 no double out auto O "Data Output 5" +dataout6 no double out auto O "Data Output 6" +dataout7 no double out auto O "Data Output 7" %% END CONTROL IOS %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +250,7 @@ dataout no double out auto O "Data Output" %% Fields descriptions: %% %% Name : Node's unique identifier. -%% +%% %% Phases : Number of phases. %% Text field: Enter a number (1, 3) or %% 0 for dynamic number of phases. @@ -401,13 +415,13 @@ dataout no double out auto O "Data Output" %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN PREPARATORY INCLUDES PATHS LIST -- Modify the following list... -UCM_PREP_INCLUDES_PATHS = +UCM_PREP_INCLUDES_PATHS = %% END PREPARATORY INCLUDES PATHS LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %% %% 8.5- Required dependency libraries pathnames list. -%% +%% %% Enter the pathnames of your dependency libraries %% separated by spaces after "=". %% Put an "\" at end of line to continue list on next line. @@ -437,7 +451,7 @@ UCM_PREP_INCLUDES_PATHS = %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN PREPARATORY DEPENDANT LIBRARIES LIST -- Modify the following list... -UCM_PREP_DEP_LIBS_PATHNAMES = +UCM_PREP_DEP_LIBS_PATHNAMES = %% END PREPARATORY DEPENDANT LIBRARIES LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -452,7 +466,7 @@ UCM_PREP_DEP_LIBS_PATHNAMES = %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN PREPARATORY LIBRARIES LIST -- Modify the following list... -UCM_PREP_LIBRARIES = +UCM_PREP_LIBRARIES = %% END PREPARATORY LIBRARIES LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -527,7 +541,8 @@ UCM_PREP_LIBRARIES = #define REMOTE_ADR "192.168.1.188" #define MAX_VALUES 64 -#define NO_SEND_DATA 3 +#define NO_SEND_DATA 8 +#define NO_RECV_DATA 8 /***** User Settings End ******/ @@ -630,9 +645,9 @@ struct sockaddr_in rec_addr; %% %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN SIMULATION INITIALIZATION FUNCTION CODE -- Enter code ->... - + int ret; - unsigned int yes = 1; + unsigned int yes = 1; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { perror("socket creation failed"); @@ -643,7 +658,7 @@ struct sockaddr_in rec_addr; perror("socket creation failed"); exit(EXIT_FAILURE); } - + memset(&rec_addr, 0, sizeof(rec_addr)); rec_addr.sin_family = AF_INET; // IPv4 rec_addr.sin_addr.s_addr = htonl(INADDR_ANY); @@ -654,12 +669,12 @@ struct sockaddr_in rec_addr; send_addr.sin_addr.s_addr = inet_addr(REMOTE_ADR); send_addr.sin_port = htons(PORT); - if (bind(sockfd, (struct sockaddr*)&rec_addr, sizeof(struct sockaddr_in)) < 0) + if (bind(sockfd, (struct sockaddr*)&rec_addr, sizeof(struct sockaddr_in)) < 0) fprintf(stdout,"ERROR DETECTED !!! There is a problem in binding"); - if (connect(sockfds, (struct sockaddr*)&send_addr, sizeof(struct sockaddr_in)) < 0) + if (connect(sockfds, (struct sockaddr*)&send_addr, sizeof(struct sockaddr_in)) < 0) fprintf(stdout,"ERROR DETECTED !!! There is a problem in connecting"); - + #if 0 // Join a multicast group struct ip_mreq mreq; @@ -687,7 +702,7 @@ struct sockaddr_in rec_addr; %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN BEFORE VOLTAGE CALCULATION CODE -- Enter code ->... - + %% END BEFORE VOLTAGE CALCULATION CODE %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %% @@ -696,9 +711,9 @@ struct sockaddr_in rec_addr; %% %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN AFTER VOLTAGE CALCULATION -- Enter code ->... - + int ret; - + /* Receiving data */ char bufr[MSG_LEN(MAX_VALUES)]; struct msg *msgr = (struct msg *) bufr; @@ -706,23 +721,40 @@ struct sockaddr_in rec_addr; struct sockaddr_in cli_addr; int cli_addrlen = sizeof(cli_addr); - if (switchr == 1) { + if (switchr == 1) { memset(&cli_addr, 0, sizeof(cli_addr)); memset((char *) msgr, 0, sizeof(bufr)); - + ret = recvfrom(sockfd, (char *) msgr, sizeof(bufr), 0, (struct sockaddr *) &cli_addr, &cli_addrlen); - + msgr->length = htons(msgr->length); msgr->sequence = htonl(msgr->sequence); msgr->ts.sec = htonl(msgr->ts.sec); msgr->ts.nsec = htonl(msgr->ts.nsec); - msgr->data[0].i = ntohl(msgr->data[0].i); - - dataout = (float) msgr->data[0].f; + + if (msgr->length >= NO_RECV_DATA) { + msgr->data[0].i = ntohl(msgr->data[0].i); + msgr->data[1].i = ntohl(msgr->data[1].i); + msgr->data[2].i = ntohl(msgr->data[2].i); + msgr->data[3].i = ntohl(msgr->data[3].i); + msgr->data[4].i = ntohl(msgr->data[4].i); + msgr->data[5].i = ntohl(msgr->data[5].i); + msgr->data[6].i = ntohl(msgr->data[6].i); + msgr->data[7].i = ntohl(msgr->data[7].i); + + dataout0 = (float) msgr->data[0].f; + dataout1 = (float) msgr->data[1].f; + dataout2 = (float) msgr->data[2].f; + dataout3 = (float) msgr->data[3].f; + dataout4 = (float) msgr->data[4].f; + dataout5 = (float) msgr->data[5].f; + dataout6 = (float) msgr->data[6].f; + dataout7 = (float) msgr->data[7].f; + } } /* Sending data */ - char buf[MSG_LEN(MAX_VALUES)]; + char buf[MSG_LEN(NO_SEND_DATA)]; struct msg *msg = (struct msg *) buf; struct timespec now; @@ -740,14 +772,29 @@ struct sockaddr_in rec_addr; msg->ts.sec = now.tv_sec; msg->ts.nsec = now.tv_nsec; - msg->data[0].f = datain; + msg->data[0].f = datain0; + msg->data[1].f = datain1; + msg->data[2].f = datain2; + msg->data[3].f = datain3; + msg->data[3].f = datain3; + msg->data[4].f = datain4; + msg->data[5].f = datain5; + msg->data[6].f = datain6; + msg->data[0].i = htonl(msg->data[0].i); + msg->data[1].i = htonl(msg->data[1].i); + msg->data[2].i = htonl(msg->data[2].i); + msg->data[3].i = htonl(msg->data[3].i); + msg->data[4].i = htonl(msg->data[4].i); + msg->data[5].i = htonl(msg->data[5].i); + msg->data[6].i = htonl(msg->data[6].i); + msg->data[7].i = htonl(msg->data[7].i); msg->length = htons(msg->length); msg->sequence = htonl(msg->sequence); msg->ts.sec = htonl(msg->ts.sec); msg->ts.nsec = htonl(msg->ts.nsec); - + ret = sendto(sockfds, (char *) msg, MSG_LEN(NO_SEND_DATA), 0, (struct sockaddr *) &send_addr, sizeof(send_addr)); } @@ -761,7 +808,7 @@ struct sockaddr_in rec_addr; %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN SIMULATION INCLUDES PATHS LIST -- Modify the following list... -UCM_SIMULATION_INCLUDES_PATHS = +UCM_SIMULATION_INCLUDES_PATHS = %% END SIMULATION INCLUDES PATHS LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -776,7 +823,7 @@ UCM_SIMULATION_INCLUDES_PATHS = %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN SIMULATION DEP LIBS LIST -- Modify the following list... -UCM_SIMULATION_DEP_LIBS_PATHNAMES = +UCM_SIMULATION_DEP_LIBS_PATHNAMES = %% END SIMULATION DEP LIBS LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -788,20 +835,20 @@ UCM_SIMULATION_DEP_LIBS_PATHNAMES = %% %% ARCHITECTURE DEPENDANT PATHS: See NOTE in section 8.5 %% -%% UCM_SIMULATION_LIBRARIES_: use for compiler dependant librairies +%% UCM_SIMULATION_LIBRARIES_: use for compiler dependant librairies %% %%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv %% BEGIN SIMULATION LIBRARIES LIST -- Modify the following list... -UCM_SIMULATION_LIBRARIES = -UCM_SIMULATION_LIBRARIES_WINDOWS = -UCM_SIMULATION_LIBRARIES_LINUX_RHEL5_32 = -UCM_SIMULATION_LIBRARIES_LINUX_RHEL6_64 = -UCM_SIMULATION_LIBRARIES_LINUX_SLES9_ia64 = -UCM_SIMULATION_LIBRARIES_LINUX_SLES10_ia64 = -UCM_SIMULATION_LIBRARIES_LINUX_SLES11SP1_x86_64 = -UCM_SIMULATION_LIBRARIES_LINUX_SLES11SP3_x86_64 = -UCM_SIMULATION_LIBRARIES_LINUX_SLES12SP1_x86_64 = +UCM_SIMULATION_LIBRARIES = +UCM_SIMULATION_LIBRARIES_WINDOWS = +UCM_SIMULATION_LIBRARIES_LINUX_RHEL5_32 = +UCM_SIMULATION_LIBRARIES_LINUX_RHEL6_64 = +UCM_SIMULATION_LIBRARIES_LINUX_SLES9_ia64 = +UCM_SIMULATION_LIBRARIES_LINUX_SLES10_ia64 = +UCM_SIMULATION_LIBRARIES_LINUX_SLES11SP1_x86_64 = +UCM_SIMULATION_LIBRARIES_LINUX_SLES11SP3_x86_64 = +UCM_SIMULATION_LIBRARIES_LINUX_SLES12SP1_x86_64 = %% END SIMULATION LIBRARIES LIST %%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clients/matlab/receiver.m b/clients/matlab/receiver.m index 642a4cbb1..d37c84786 100644 --- a/clients/matlab/receiver.m +++ b/clients/matlab/receiver.m @@ -32,9 +32,9 @@ disp('Receiving data'); while i < num_samples % Wait for connection % Read data from the socket - + [ dat, count ] = fread(t, num_values, 'float32'); - + data(:,i) = dat; i = i + 1; end diff --git a/clients/opal/models/send_receive/Makefile.mk b/clients/opal/models/send_receive/Makefile.mk index 56da211e9..1a0cf4a11 100644 --- a/clients/opal/models/send_receive/Makefile.mk +++ b/clients/opal/models/send_receive/Makefile.mk @@ -41,7 +41,7 @@ ifneq ($(RTLAB_ROOT),) endif CC_OPTS = -std=c99 -D_GNU_SOURCE -MMD -LD_OPTS = +LD_OPTS = OBJS = main.o msg.o utils.o socket.o $(INTEL_OBJS) ifneq ($(PROTOCOL),) diff --git a/clients/opal/models/send_receive/src/main.asv b/clients/opal/models/send_receive/src/main.asv index bdc8c1ad4..dac4d0759 100644 --- a/clients/opal/models/send_receive/src/main.asv +++ b/clients/opal/models/send_receive/src/main.asv @@ -66,7 +66,7 @@ static void * SendToIPPort(void *arg) OpalPrint("%s: SendToIPPort: No transimission block for this controller. Stopping thread.\n", PROGNAME); return NULL; } - + do { /* This call unblocks when the 'Data Ready' line of a send icon is asserted. */ ret = OpalWaitForAsyncSendRequest(&SendID); @@ -109,7 +109,7 @@ static void * SendToIPPort(void *arg) msg->data[i].f = (float) mdldata[i]; msg_hton(msg); - + len = MSG_LEN(msg->length); #elif PROTOCOL == GTNET_SKT uint32_t *imsg = (uint32_t *) msg; @@ -117,7 +117,7 @@ static void * SendToIPPort(void *arg) msg[i] = (float) mdldata[i]; imsg[i] = htonl(imsg[i]); } - + len = mdldata_size / sizeof(double) * sizeof(float); #else #error Unknown protocol @@ -185,12 +185,12 @@ static void * RecvFromIPPort(void *arg) OpalPrint("%s: Timeout while waiting for data\n", PROGNAME, errno); if (ret == -1) /* a more serious error, so we print it */ OpalPrint("%s: Error %d while waiting for data\n", PROGNAME, errno); - + continue; } break; } - + /* Get the number of signals to send back to the model */ OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID); cnt = mdldata_size / sizeof(double); @@ -202,18 +202,18 @@ static void * RecvFromIPPort(void *arg) #if PROTOCOL == VILLAS msg_ntoh(msg); - + ret = msg_verify(msg); if (ret) { OpalPrint("%s: Skipping invalid packet\n", PROGNAME); continue; } - + if (cnt > msg->length) { OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds what was received (%d)\n", PROGNAME, RecvID, cnt, msg->length); } - + for (int i = 0; i < msg->length; i++) { mdldata[i] = (double) msg->data[i].f; printf("Data rcvd from VILLAS %f\n", mdldata[i]); @@ -225,7 +225,7 @@ static void * RecvFromIPPort(void *arg) uint32_t *imsg = (uint32_t *) msg; for (int i = 0; i < cnt; i++) imsg[i] = ntohl(imsg[i]); - + printf("Protocol GTNET_SKT\n"); for (int i = 0; i < cnt; i++) { mdldata[i] = (double) msg[i]; @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) fputs ("test file to check if main runs", testfile); fclose (testfile); } - + int ret; Opal_GenAsyncParam_Ctrl IconCtrlStruct; @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) /* Get IP Controler Parameters (ie: ip address, port number...) and * initialize the device on the QNX node. */ memset(&IconCtrlStruct, 0, sizeof(IconCtrlStruct)); - + ret = OpalGetAsyncCtrlParameters(&IconCtrlStruct, sizeof(IconCtrlStruct)); if (ret != EOK) { OpalPrint("%s: ERROR: Could not get controller parameters (%d).\n", PROGNAME, ret); @@ -311,7 +311,7 @@ int main(int argc, char *argv[]) ret = pthread_create(&tid_send, NULL, SendToIPPort, NULL); if (ret == -1) OpalPrint("%s: ERROR: Could not create thread (SendToIPPort), errno %d\n", PROGNAME, errno); - + ret = pthread_create(&tid_recv, NULL, RecvFromIPPort, NULL); if (ret == -1) OpalPrint("%s: ERROR: Could not create thread (RecvFromIPPort), errno %d\n", PROGNAME, errno); @@ -320,14 +320,14 @@ int main(int argc, char *argv[]) ret = pthread_join(tid_send, NULL); if (ret != 0) OpalPrint("%s: ERROR: pthread_join (SendToIPPort), errno %d\n", PROGNAME, ret); - + ret = pthread_join(tid_recv, NULL); if (ret != 0) OpalPrint("%s: ERROR: pthread_join (RecvFromIPPort), errno %d\n", PROGNAME, ret); /* Close the ip port and shared memories */ socket_close(&skt, IconCtrlStruct); - + OpalCloseAsyncMem (ASYNC_SHMEM_SIZE, ASYNC_SHMEM_NAME); OpalSystemCtrl_UnRegister(PRINT_SHMEM_NAME); diff --git a/clients/opal/models/send_receive/src/main.c b/clients/opal/models/send_receive/src/main.c index 147196f80..6a1eacefe 100644 --- a/clients/opal/models/send_receive/src/main.c +++ b/clients/opal/models/send_receive/src/main.c @@ -138,15 +138,15 @@ static void *SendToIPPort(void *arg) { OpalSetAsyncSendIconError(0, SendID); /* This next call allows the execution of the "asynchronous" process - * to actually be synchronous with the model. To achieve this, you - * should set the "Sending Mode" in the Async_Send block to - * NEED_REPLY_BEFORE_NEXT_SEND or NEED_REPLY_NOW. This will force - * the model to wait for this process to call this - * OpalAsyncSendRequestDone function before continuing. */ + * to actually be synchronous with the model. To achieve this, you + * should set the "Sending Mode" in the Async_Send block to + * NEED_REPLY_BEFORE_NEXT_SEND or NEED_REPLY_NOW. This will force + * the model to wait for this process to call this + * OpalAsyncSendRequestDone function before continuing. */ OpalAsyncSendRequestDone(SendID); /* Before continuing, we make sure that the real-time model - * has not been stopped. If it has, we quit. */ + * has not been stopped. If it has, we quit. */ ModelState = OpalGetAsyncModelState(); } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); @@ -271,7 +271,7 @@ static void *RecvFromIPPort(void *arg) { OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID); /* Before continuing, we make sure that the real-time model - * has not been stopped. If it has, we quit. */ + * has not been stopped. If it has, we quit. */ ModelState = OpalGetAsyncModelState(); } while ((ModelState != STATE_RESET) && (ModelState != STATE_STOP)); @@ -313,7 +313,7 @@ int main(int argc, char *argv[]) { AssignProcToCpu0(); /* Get IP Controler Parameters (ie: ip address, port number...) and - * initialize the device on the QNX node. */ + * initialize the device on the QNX node. */ memset(&IconCtrlStruct, 0, sizeof(IconCtrlStruct)); ret = OpalGetAsyncCtrlParameters(&IconCtrlStruct, sizeof(IconCtrlStruct)); diff --git a/clients/opal/models/send_receive/src/socket.c b/clients/opal/models/send_receive/src/socket.c index 77cc5ec3b..d6a2e1ab6 100644 --- a/clients/opal/models/send_receive/src/socket.c +++ b/clients/opal/models/send_receive/src/socket.c @@ -153,9 +153,9 @@ int socket_recv(struct socket *s, char *data, int len, double timeout) { tv.tv_usec = (int)((timeout - tv.tv_sec) * 1000000); /* Wait for a packet. We use select() to have a timeout. This is - * necessary when reseting the model so we don't wait indefinitely - * and prevent the process from exiting and freeing the port for - * a future instance (model load). */ + * necessary when reseting the model so we don't wait indefinitely + * and prevent the process from exiting and freeing the port for + * a future instance (model load). */ ret = select(s->sd + 1, &sd_set, (fd_set *)0, (fd_set *)0, &tv); switch (ret) { case -1: // Error @@ -165,7 +165,7 @@ int socket_recv(struct socket *s, char *data, int len, double timeout) { default: if (!(FD_ISSET(s->sd, &sd_set))) { /* We received something, but it's not on "sd". Since sd is the only - * descriptor in the set... */ + * descriptor in the set... */ OpalPrint("%s: RecvPacket: God, is that You trying to reach me?\n", PROGNAME); return -1; diff --git a/clients/python/client.py b/clients/python/client.py index daff5bb0d..b6e543d17 100644 --- a/clients/python/client.py +++ b/clients/python/client.py @@ -5,52 +5,53 @@ import villas_pb2 import time, socket, errno, sys, os, signal -layer = sys.argv[1] if len(sys.argv) == 2 else 'udp' +layer = sys.argv[1] if len(sys.argv) == 2 else "udp" -if layer not in ['udp', 'unix']: - raise Exception('Unsupported socket type') +if layer not in ["udp", "unix"]: + raise Exception("Unsupported socket type") -if layer == 'unix': - local = '/var/run/villas-node.client.sock' - remote = '/var/run/villas-node.server.sock' +if layer == "unix": + local = "/var/run/villas-node.client.sock" + remote = "/var/run/villas-node.server.sock" - skt = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + skt = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) - # Delete stale sockets - if os.path.exists(local): - os.unlink(local) -elif layer == 'udp': - local = ('0.0.0.0', 12001) - remote = ('127.0.0.1', 12000) + # Delete stale sockets + if os.path.exists(local): + os.unlink(local) +elif layer == "udp": + local = ("0.0.0.0", 12001) + remote = ("127.0.0.1", 12000) - skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) -print('Start client...') +print("Start client...") skt.bind(local) # Try to connect in case Unix domain socket does not exist yet.. connected = False while not connected: - try: - skt.connect(remote) - except socket.error as serr: - if serr.errno not in [ errno.ECONNREFUSED, errno.ENOENT ]: - raise serr - - print('Not connected. Retrying in 1 sec') - time.sleep(1) - else: - connected = True + try: + skt.connect(remote) + except socket.error as serr: + if serr.errno not in [errno.ECONNREFUSED, errno.ENOENT]: + raise serr -print('Ready. Ctrl-C to quit.') + print("Not connected. Retrying in 1 sec") + time.sleep(1) + else: + connected = True + +print("Ready. Ctrl-C to quit.") msg = villas_pb2.Message() # Gracefully shutdown def sighandler(signum, frame): - running = False + running = False + signal.signal(signal.SIGINT, sighandler) signal.signal(signal.SIGTERM, sighandler) @@ -58,15 +59,15 @@ signal.signal(signal.SIGTERM, sighandler) running = True while running: - dgram = skt.recv(1024) - if not dgram: - break - else: - msg.ParseFromString(dgram) - print(msg) - - skt.send(msg.SerializeToString()) + dgram = skt.recv(1024) + if not dgram: + break + else: + msg.ParseFromString(dgram) + print(msg) + + skt.send(msg.SerializeToString()) skt.close() -print('Bye.') +print("Bye.") diff --git a/cmake/FindCriterion.cmake b/cmake/FindCriterion.cmake new file mode 100644 index 000000000..8946608ce --- /dev/null +++ b/cmake/FindCriterion.cmake @@ -0,0 +1,28 @@ +# Try to find Criterion +# +# Once done this will define +# CRITERION_FOUND - System has Criterion +# CRITERION_INCLUDE_DIRS - The Criterion include directories +# CRITERION_LIBRARIES - The libraries needed to use Criterion +# +# SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +find_package(PkgConfig) + +find_path(CRITERION_INCLUDE_DIR criterion/criterion.h + PATH_SUFFIXES criterion) + +find_library(CRITERION_LIBRARY NAMES criterion libcriterion) + +set(CRITERION_LIBRARIES ${CRITERION_LIBRARY}) +set(CRITERION_INCLUDE_DIRS ${CRITERION_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +# Handle the QUIET and REQUIRED arguments and set CRITERION_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(Criterion DEFAULT_MSG + CRITERION_LIBRARY CRITERION_INCLUDE_DIR) + +mark_as_advanced(CRITERION_INCLUDE_DIR CRITERION_LIBRARY) diff --git a/cmake/FindEtherlab.cmake b/cmake/FindEtherlab.cmake index 95a22afab..2dd757d34 100644 --- a/cmake/FindEtherlab.cmake +++ b/cmake/FindEtherlab.cmake @@ -6,15 +6,15 @@ # SPDX-License-Identifier: Apache-2.0 find_path(ETHERLAB_INCLUDE_DIR - NAMES ecrt.h - PATHS - /opt/etherlab/include + NAMES ecrt.h + PATHS + /opt/etherlab/include ) find_library(ETHERLAB_LIBRARY - NAMES ethercat - PATHS - /opt/etherlab/lib + NAMES ethercat + PATHS + /opt/etherlab/lib ) include(FindPackageHandleStandardArgs) diff --git a/cmake/FindIBVerbs.cmake b/cmake/FindIBVerbs.cmake index 38806105f..d04c14479 100644 --- a/cmake/FindIBVerbs.cmake +++ b/cmake/FindIBVerbs.cmake @@ -5,18 +5,18 @@ # SPDX-License-Identifier: Apache-2.0 find_path(IBVERBS_INCLUDE_DIR - NAMES infiniband/verbs.h + NAMES infiniband/verbs.h ) find_library(IBVERBS_LIBRARY - NAMES ibverbs + NAMES ibverbs ) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set VILLASNODE_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(IBVerbs DEFAULT_MSG - IBVERBS_LIBRARY IBVERBS_INCLUDE_DIR) + IBVERBS_LIBRARY IBVERBS_INCLUDE_DIR) mark_as_advanced(IBVERBS_INCLUDE_DIR IBVERBS_LIBRARY) diff --git a/cmake/FindOpal.cmake b/cmake/FindOpal.cmake index 4cfb5656d..71f44915f 100644 --- a/cmake/FindOpal.cmake +++ b/cmake/FindOpal.cmake @@ -7,41 +7,41 @@ set(OPAL_PREFIX /usr/opalrt/common) find_path(OPAL_INCLUDE_DIR - NAMES AsyncApi.h - HINTS - ${OPAL_PREFIX}/include_target/ - ${PROJECT_SOURCE_DIR}/libopal/include/opal/ + NAMES AsyncApi.h + HINTS + ${OPAL_PREFIX}/include_target/ + ${PROJECT_SOURCE_DIR}/libopal/include/opal/ ) find_library(OPAL_LIBRARY - NAMES OpalAsyncApiCore - HINTS - ${OPAL_PREFIX}/lib/ - ${PROJECT_SOURCE_DIR}/libopal/ + NAMES OpalAsyncApiCore + HINTS + ${OPAL_PREFIX}/lib/ + ${PROJECT_SOURCE_DIR}/libopal/ ) find_library(OPAL_LIBRARY_IRC - NAMES irc - HINTS - ${OPAL_PREFIX}/lib/ - ${PROJECT_SOURCE_DIR}/libopal/ + NAMES irc + HINTS + ${OPAL_PREFIX}/lib/ + ${PROJECT_SOURCE_DIR}/libopal/ ) find_library(OPAL_LIBRARY_UTILS - NAMES OpalUtils - HINTS - ${OPAL_PREFIX}/lib/redhawk/ - ${OPAL_PREFIX}/lib/redhawk64/ - ${PROJECT_SOURCE_DIR}/libopal/ + NAMES OpalUtils + HINTS + ${OPAL_PREFIX}/lib/redhawk/ + ${OPAL_PREFIX}/lib/redhawk64/ + ${PROJECT_SOURCE_DIR}/libopal/ ) find_library(OPAL_LIBRARY_CORE - NAMES OpalCore - HINTS - ${OPAL_PREFIX}/lib/redhawk/ - ${OPAL_PREFIX}/lib/redhawk64/ - ${PROJECT_SOURCE_DIR}/libopal/ + NAMES OpalCore + HINTS + ${OPAL_PREFIX}/lib/redhawk/ + ${OPAL_PREFIX}/lib/redhawk64/ + ${PROJECT_SOURCE_DIR}/libopal/ ) include(FindPackageHandleStandardArgs) diff --git a/cmake/FindRDMACM.cmake b/cmake/FindRDMACM.cmake index 6e6f92ef7..2230f6272 100644 --- a/cmake/FindRDMACM.cmake +++ b/cmake/FindRDMACM.cmake @@ -5,18 +5,18 @@ # SPDX-License-Identifier: Apache-2.0 find_path(RDMACM_INCLUDE_DIR - NAMES rdma/rdma_cma.h + NAMES rdma/rdma_cma.h ) find_library(RDMACM_LIBRARY - NAMES rdmacm + NAMES rdmacm ) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set VILLASNODE_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(RDMACM DEFAULT_MSG - RDMACM_LIBRARY RDMACM_INCLUDE_DIR) + RDMACM_LIBRARY RDMACM_INCLUDE_DIR) mark_as_advanced(RDMACM_INCLUDE_DIR RDMACM_LIBRARY) diff --git a/cmake/FindSymbol.cmake b/cmake/FindSymbol.cmake index 0b566ef95..ebacdf87c 100644 --- a/cmake/FindSymbol.cmake +++ b/cmake/FindSymbol.cmake @@ -5,16 +5,16 @@ # SPDX-License-Identifier: Apache-2.0 function(FindSymbol LIBRARY SYMBOL FOUND) - find_program(OBJDUMP_EXECUTABLE NAMES objdump) + find_program(OBJDUMP_EXECUTABLE NAMES objdump) - execute_process( - COMMAND /bin/sh -c "${OBJDUMP_EXECUTABLE} -T ${LIBRARY} | grep ${SYMBOL} | wc -l" - OUTPUT_VARIABLE OUTPUT - ) + execute_process( + COMMAND /bin/sh -c "${OBJDUMP_EXECUTABLE} -T ${LIBRARY} | grep ${SYMBOL} | wc -l" + OUTPUT_VARIABLE OUTPUT + ) - if(OUTPUT GREATER 0) - set(${FOUND} "${SYMBOL}" PARENT_SCOPE) - else() - set(${FOUND} "${SYMBOL}-NOTFOUND" PARENT_SCOPE) - endif() + if(OUTPUT GREATER 0) + set(${FOUND} "${SYMBOL}" PARENT_SCOPE) + else() + set(${FOUND} "${SYMBOL}-NOTFOUND" PARENT_SCOPE) + endif() endfunction() diff --git a/cmake/GetVersion.cmake b/cmake/GetVersion.cmake new file mode 100644 index 000000000..9fdc6f71f --- /dev/null +++ b/cmake/GetVersion.cmake @@ -0,0 +1,105 @@ +# CMakeLists.txt. +# +# Author: Steffen Vogel +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 +# +# VILLASnode + + +# This CMake function sets the following variables: +# +# ${PREFIX}_VERSION_STR v0.6.3 +# ${PREFIX}_VERSION 0.6.3 +# ${PREFIX}_MAJOR_VERSION 0 +# ${PREFIX}_MINOR_VERSION 6 +# ${PREFIX}_PATCH_VERSION 3 +# ${PREFIX}_RELEASE 1.ci_tests_release.20180823git1cd25c2f +# ${PREFIX}_GIT_REV 1cd25c2f +# ${PREFIX}_GIT_BRANCH ci-tests +# ${PREFIX}_GIT_BRANCH_NORM ci_tests +# ${PREFIX}_VARIANT release +# ${PREFIX}_VARIANT_NORM release +# ${PREFIX}_BUILD_ID v0.6.3-1cd25c2f-release +# ${PREFIX}_BUILD_DATE 20180823 + +function(GetVersion DIR PREFIX) + execute_process( + COMMAND git describe --tags --abbrev=0 --match "v*" + WORKING_DIRECTORY ${DIR} + OUTPUT_VARIABLE VERSION_STR + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + RESULT_VARIABLE RC + ) + + if(NOT RC EQUAL 0) + set(FOUND_GIT_VERSION OFF PARENT_SCOPE) + message(WARNING + "Failed to retrieve version information from Git. " + "Make sure that the source directory is a Git repo and " + "contains at least one valid tag like 'v0.1.0'" + ) + else() + set(FOUND_GIT_VERSION ON PARENT_SCOPE) + + string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" VERSION ${VERSION_STR}) + string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\1" MAJOR_VERSION ${VERSION_STR}) + string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\2" MINOR_VERSION ${VERSION_STR}) + string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\3" PATCH_VERSION ${VERSION_STR}) + + string(TIMESTAMP BUILD_DATE "%Y%m%d") + + if(CMAKE_BUILD_TYPE) + string(TOLOWER "${CMAKE_BUILD_TYPE}" VARIANT) + else() + set(VARIANT "release") + endif() + + if(DEFINED ENV{CI}) + string(APPEND VARIANT "-ci") + string(SUBSTRING $ENV{CI_COMMIT_SHA} 0 7 GIT_REV) + set(GIT_BRANCH $ENV{CI_COMMIT_REF_NAME}) + else() + execute_process( + COMMAND git rev-parse --short=7 HEAD + WORKING_DIRECTORY ${DIR} + OUTPUT_VARIABLE GIT_REV + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + + if(DEFINED ENV{CI_COMMIT_TAG}) + set(RELEASE 1) + else() + string(REPLACE "-" "_" GIT_BRANCH_NORM ${GIT_BRANCH}) + string(REPLACE "-" "_" VARIANT_NORM ${VARIANT}) + + set(RELEASE "1.${GIT_BRANCH_NORM}_${VARIANT_NORM}.${BUILD_DATE}git${GIT_REV}") + endif() + + set(BUILD_ID "v${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${GIT_REV}-${VARIANT}" ) + + # Return results to parent scope + set(${PREFIX}_VERSION_STR ${VERSION_STR} PARENT_SCOPE) + set(${PREFIX}_VERSION ${VERSION} PARENT_SCOPE) + set(${PREFIX}_MAJOR_VERSION ${MAJOR_VERSION} PARENT_SCOPE) + set(${PREFIX}_MINOR_VERSION ${MINOR_VERSION} PARENT_SCOPE) + set(${PREFIX}_PATCH_VERSION ${PATCH_VERSION} PARENT_SCOPE) + set(${PREFIX}_RELEASE ${RELEASE} PARENT_SCOPE) + set(${PREFIX}_GIT_REV ${GIT_REV} PARENT_SCOPE) + set(${PREFIX}_GIT_BRANCH ${GIT_BRANCH} PARENT_SCOPE) + set(${PREFIX}_GIT_BRANCH_NORM ${GIT_BRANCH_NORM} PARENT_SCOPE) + set(${PREFIX}_VARIANT ${VARIANT} PARENT_SCOPE) + set(${PREFIX}_VARIANT_NORM ${VARIANT_NORM} PARENT_SCOPE) + set(${PREFIX}_BUILD_ID ${BUILD_ID} PARENT_SCOPE) + set(${PREFIX}_BUILD_DATE ${BUILD_DATE} PARENT_SCOPE) + endif() +endfunction(GetVersion) diff --git a/common b/common deleted file mode 160000 index 3a66d8ff6..000000000 --- a/common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3a66d8ff657c0824138a03df0aca1b16c88d582a diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 000000000..709017938 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,38 @@ +## CMakeLists.txt +# +# Author: Steffen Vogel +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +include(FindPkgConfig) +include(FeatureSummary) +include(GNUInstallDirs) + +# Check packages +find_package(OpenSSL 1.0.0 REQUIRED) +find_package(CURL 7.29 REQUIRED) +find_package(spdlog 1.6.0 REQUIRED) +find_package(fmt 6.0.0 REQUIRED) +find_package(Criterion) + +pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson>=2.7) +pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig>=1.4.9) +pkg_check_modules(UUID IMPORTED_TARGET REQUIRED uuid>=2.23) + +if(fmt_VERSION VERSION_LESS "9.0.0") + message("Using legacy ostream formatting") + set(FMT_LEGACY_OSTREAM_FORMATTER 1) +endif() + +add_subdirectory(lib) +if(WITH_TESTS) + add_subdirectory(tests) +endif() + +# Disable any colored log output +option(LOG_COLOR_DISABLE "Disable any colored log output" OFF) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/villas/config.hpp.in + ${CMAKE_CURRENT_BINARY_DIR}/include/villas/config.hpp +) diff --git a/common/include/villas/boxes.hpp b/common/include/villas/boxes.hpp new file mode 100644 index 000000000..17ce65ae4 --- /dev/null +++ b/common/include/villas/boxes.hpp @@ -0,0 +1,51 @@ +/* Various helper functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +// The suffixed of the BOX_ macro a constructed by +// combining the following letters in the written order: +// - U for a line facing upwards +// - D for a line facing downwards +// - L for a line facing leftwards +// - R for a line facing rightwards +// +// E.g. a cross can be constructed by combining all line fragments: +// BOX_UDLR +#if 0 // Alternate character set +#define BOX(chr) "\e(0" chr "\e(B" +#define BOX_LR BOX("\x71") // Boxdrawing: ─ +#define BOX_UD BOX("\x78") // Boxdrawing: │ +#define BOX_UDR BOX("\x74") // Boxdrawing: ├ +#define BOX_UDLR BOX("\x6E") // Boxdrawing: ┼ +#define BOX_UDL BOX("\x75") // Boxdrawing: ┤ +#define BOX_ULR BOX("\x76") // Boxdrawing: ┴ +#define BOX_UL BOX("\x6A") // Boxdrawing: ┘ +#define BOX_DLR BOX("\x77") // Boxdrawing: ┘ +#define BOX_DL BOX("\x6B") // Boxdrawing: ┘ +#elif 1 // UTF-8 +#define BOX_LR "─" // Boxdrawing: ─ +#define BOX_UD "│" // Boxdrawing: │ +#define BOX_UDR "├" // Boxdrawing: ├ +#define BOX_UDLR "┼" // Boxdrawing: ┼ +#define BOX_UDL "┤" // Boxdrawing: ┤ +#define BOX_ULR "┴" // Boxdrawing: ┴ +#define BOX_UL "┘" // Boxdrawing: ┘ +#define BOX_DLR "┬" // Boxdrawing: ┘ +#define BOX_DL "┐" // Boxdrawing: ┘ +#define BOX_UR "└" // Boxdrawing: └ +#else // ASCII +#define BOX_LR "-" // Boxdrawing: ─ +#define BOX_UD "|" // Boxdrawing: │ +#define BOX_UDR "+" // Boxdrawing: ├ +#define BOX_UDLR "+" // Boxdrawing: ┼ +#define BOX_UDL "+" // Boxdrawing: ┤ +#define BOX_ULR "+" // Boxdrawing: ┴ +#define BOX_UL "+" // Boxdrawing: ┘ +#define BOX_DLR "+" // Boxdrawing: ┘ +#define BOX_DL "+" // Boxdrawing: ┘ +#endif diff --git a/common/include/villas/buffer.hpp b/common/include/villas/buffer.hpp new file mode 100644 index 000000000..949e9ca61 --- /dev/null +++ b/common/include/villas/buffer.hpp @@ -0,0 +1,37 @@ +/* A simple buffer for encoding streamed JSON messages. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#include + +namespace villas { + +class Buffer : public std::vector { + +protected: + static int callback(const char *data, size_t len, void *ctx); + +public: + Buffer(const char *buf, size_type len) : std::vector(buf, buf + len) {} + + Buffer(size_type count = 0) : std::vector(count, 0) {} + + // Encode JSON document /p j and append it to the buffer + int encode(json_t *j, int flags = 0); + + // Decode JSON document from the beginning of the buffer + json_t *decode(); + + void append(const char *data, size_t len) { insert(end(), data, data + len); } +}; + +} // namespace villas diff --git a/common/include/villas/colors.hpp b/common/include/villas/colors.hpp new file mode 100644 index 000000000..d960e5c45 --- /dev/null +++ b/common/include/villas/colors.hpp @@ -0,0 +1,31 @@ +/* Various helper functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +// CPP stringification +#define XSTR(x) STR(x) +#define STR(x) #x + +// Some color escape codes for pretty log messages +#ifdef LOG_COLOR_DISABLE +#define CLR(clr, str) str +#else +#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#endif + +#define CLR_GRY(str) CLR(30, str) // Print str in gray +#define CLR_RED(str) CLR(31, str) // Print str in red +#define CLR_GRN(str) CLR(32, str) // Print str in green +#define CLR_YEL(str) CLR(33, str) // Print str in yellow +#define CLR_BLU(str) CLR(34, str) // Print str in blue +#define CLR_MAG(str) CLR(35, str) // Print str in magenta +#define CLR_CYN(str) CLR(36, str) // Print str in cyan +#define CLR_WHT(str) CLR(37, str) // Print str in white +#define CLR_BLD(str) CLR(1, str) // Print str in bold diff --git a/common/include/villas/common.hpp b/common/include/villas/common.hpp new file mode 100644 index 000000000..b0eb92429 --- /dev/null +++ b/common/include/villas/common.hpp @@ -0,0 +1,36 @@ +/* Some common defines, enums and datastructures. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +// Common states for most objects in VILLAScommon (paths, nodes, hooks, plugins) +enum class State { + DESTROYED = 0, + INITIALIZED = 1, + PARSED = 2, + CHECKED = 3, + STARTED = 4, + STOPPED = 5, + PENDING_CONNECT = 6, + CONNECTED = 7, + PAUSED = 8, + STARTING = 9, + STOPPING = 10, + PAUSING = 11, + RESUMING = 12, + PREPARED = 13 +}; + +// Callback to destroy list elements. +// +// @param data A pointer to the data which should be freed. +typedef int (*dtor_cb_t)(void *); + +// Convert state enum to human readable string. +std::string stateToString(enum State s); diff --git a/common/include/villas/compat.hpp b/common/include/villas/compat.hpp new file mode 100644 index 000000000..757e46ae8 --- /dev/null +++ b/common/include/villas/compat.hpp @@ -0,0 +1,44 @@ +/* Compatability for different library versions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#if JANSSON_VERSION_HEX < 0x020A00 +size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags); + +int json_dumpfd(const json_t *json, int output, size_t flags); +json_t *json_loadfd(int input, size_t flags, json_error_t *error); +#endif + +#if defined(WITH_CONFIG) && (LIBCONFIG_VER_MAJOR <= 1) && \ + (LIBCONFIG_VER_MINOR < 5) +#include + +#define config_setting_lookup config_lookup_from +#endif + +#ifdef __MACH__ +#include + +#define le16toh(x) OSSwapLittleToHostInt16(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define be64toh(x) OSSwapBigToHostInt64(x) + +#define htole16(x) OSSwapHostToLittleInt16(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htobe64(x) OSSwapHostToBigInt64(x) +#endif // __MACH__ diff --git a/common/include/villas/config.hpp.in b/common/include/villas/config.hpp.in new file mode 100644 index 000000000..63235af35 --- /dev/null +++ b/common/include/villas/config.hpp.in @@ -0,0 +1,52 @@ +/** Compile time configuration + * + * This file contains some compiled-in settings. + * This settings are not part of the configuration file. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + *********************************************************************************/ + +#pragma once + +#define PROJECT_VERSION_STR "@CMAKE_PROJECT_VERSION_STR@" +#define PROJECT_VERSION "@CMAKE_PROJECT_VERSION@" +#define PROJECT_MAJOR_VERSION @CMAKE_PROJECT_MAJOR_VERSION@ +#define PROJECT_MINOR_VERSION @CMAKE_PROJECT_MINOR_VERSION@ +#define PROJECT_PATCH_VERSION @CMAKE_PROJECT_PATCH_VERSION@ +#define PROJECT_RELEASE "@CMAKE_PROJECT_RELEASE@" +#define PROJECT_GIT_REV "@CMAKE_PROJECT_GIT_REV@" +#define PROJECT_GIT_BRANCH "@CMAKE_PROJECT_GIT_BRANCH@" +#define PROJECT_GIT_BRANCH_NORM "@CMAKE_PROJECT_GIT_BRANCH_NORM@" +#define PROJECT_VARIANT "@CMAKE_PROJECT_VARIANT@" +#define PROJECT_VARIANT_NORM "@CMAKE_PROJECT_VARIANT_NORM@" +#define PROJECT_BUILD_ID "@CMAKE_PROJECT_BUILD_ID@" +#define PROJECT_BUILD_DATE "@CMAKE_PROJECT_BUILD_DATE@" + +#define PROJECT_HOMEPAGE_URL "@CMAKE_PROJECT_HOMEPAGE_URL@" +#define PROJECT_NAME "@CMAKE_PROJECT_DESCRIPTION@" + +#define HTTP_USER_AGENT PROJECT_NAME " (" PROJECT_BUILD_ID ")" + +// Hard-coded cache line size +#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__) + #define CACHELINE_SIZE 64 +#else + #error "Unsupported architecture" +#endif + +// Paths +#define PREFIX "@CMAKE_INSTALL_PREFIX@" +#define PLUGIN_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins" +#define SYSFS_PATH "/sys" +#define PROCFS_PATH "/proc" + +// Width of log output in characters +#define LOG_WIDTH 80 +#define LOG_HEIGHT 25 + +#cmakedefine LOG_COLOR_DISABLE + +// Library Features +#cmakedefine FMT_LEGACY_OSTREAM_FORMATTER diff --git a/common/include/villas/cpuset.hpp b/common/include/villas/cpuset.hpp new file mode 100644 index 000000000..11547daed --- /dev/null +++ b/common/include/villas/cpuset.hpp @@ -0,0 +1,126 @@ +/* Human readable cpusets. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __linux__ + +#include +#include + +#include + +namespace villas { +namespace utils { + +class CpuSet { + +protected: + cpu_set_t *setp; + + unsigned num_cpus; + size_t sz; + +public: + CpuSet() : num_cpus(sizeof(uintmax_t) * 8), sz(CPU_ALLOC_SIZE(num_cpus)) { + + setp = CPU_ALLOC(num_cpus); + if (!setp) + throw MemoryAllocationError(); + + zero(); + } + + // Parses string with list of CPU ranges. + // + // @param str Human readable representation of the set. + CpuSet(const std::string &str); + + CpuSet(const char *str); + + // Convert integer to cpu_set_t. + // + // @param set An integer number which is used as the mask + CpuSet(uintmax_t set); + + // Convert cpu_set_t to an integer. */ + operator uintmax_t(); + + operator const cpu_set_t *() { return setp; } + + // Returns human readable representation of the cpuset. + // + // The output format is a list of CPUs with ranges (for example, "0,1,3-9"). + operator std::string(); + + ~CpuSet() { CPU_FREE(setp); } + + CpuSet(const CpuSet &src) : CpuSet(src.num_cpus) { + memcpy(setp, src.setp, sz); + } + + bool empty() const { return count() == 0; } + + bool full() const { return count() == num_cpus; } + + unsigned count() const { return CPU_COUNT_S(sz, setp); } + + void zero() { CPU_ZERO_S(sz, setp); } + + size_t size() const { return sz; } + + CpuSet operator~() { + CpuSet full = UINTMAX_MAX; + + return full ^ *this; + } + + bool operator==(const CpuSet &rhs) { return CPU_EQUAL_S(sz, setp, rhs.setp); } + + CpuSet &operator&=(const CpuSet &rhs) { + CPU_AND_S(sz, setp, setp, rhs.setp); + return *this; + } + + CpuSet &operator|=(const CpuSet &rhs) { + CPU_OR_S(sz, setp, setp, rhs.setp); + return *this; + } + + CpuSet &operator^=(const CpuSet &rhs) { + CPU_XOR_S(sz, setp, setp, rhs.setp); + return *this; + } + + friend CpuSet operator&(CpuSet lhs, const CpuSet &rhs) { + lhs &= rhs; + return lhs; + } + + friend CpuSet operator|(CpuSet lhs, const CpuSet &rhs) { + lhs |= rhs; + return lhs; + } + + friend CpuSet operator^(CpuSet lhs, const CpuSet &rhs) { + lhs ^= rhs; + return lhs; + } + + bool operator[](size_t cpu) const { return isSet(cpu); } + + bool isSet(size_t cpu) const { return CPU_ISSET_S(cpu, sz, setp); } + + void clear(size_t cpu) { CPU_CLR_S(cpu, sz, setp); } + + void set(size_t cpu) { CPU_SET_S(cpu, sz, setp); } +}; + +} // namespace utils +} // namespace villas + +#endif diff --git a/common/include/villas/dsp/exponential_window.hpp b/common/include/villas/dsp/exponential_window.hpp new file mode 100644 index 000000000..a5e89d727 --- /dev/null +++ b/common/include/villas/dsp/exponential_window.hpp @@ -0,0 +1,32 @@ +/* An exponential window. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace dsp { + +template class ExponentialWindow { + +protected: + T a; + T last; + +public: + ExponentialWindow(T _a, T i = 0) : a(a), last(i) {} + + T update(T in) { + last = a * in + (1 - a) * last; + + return last; + } +}; + +} // namespace dsp +} // namespace villas diff --git a/common/include/villas/dsp/moving_average_window.hpp b/common/include/villas/dsp/moving_average_window.hpp new file mode 100644 index 000000000..d91b9127b --- /dev/null +++ b/common/include/villas/dsp/moving_average_window.hpp @@ -0,0 +1,35 @@ +/* A moving average window. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +namespace villas { +namespace dsp { + +template class MovingAverageWindow : public Window { + +protected: + T state; + +public: + MovingAverageWindow(size_t len, T i = 0) : Window(len, i), state(i) {} + + T update(T in) { + T out = Window::update(in); + + state += in; + state -= out; + + return state / (double)Window::getLength(); + } +}; + +} // namespace dsp +} // namespace villas diff --git a/common/include/villas/dsp/pid.hpp b/common/include/villas/dsp/pid.hpp new file mode 100644 index 000000000..74d82d1bc --- /dev/null +++ b/common/include/villas/dsp/pid.hpp @@ -0,0 +1,39 @@ +/* A PID controller. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +namespace villas { +namespace dsp { + +class PID { + +protected: + double dt; + double max; + double min; + double Kp; + double Kd; + double Ki; + double pre_error; + double integral; + +public: + // Kp - proportional gain + // Ki - Integral gain + // Kd - derivative gain + // dt - loop interval time + // max - maximum value of manipulated variable + // min - minimum value of manipulated variable + PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki); + + // Returns the manipulated variable given a setpoint and current process value + double calculate(double setpoint, double pv); +}; + +} // namespace dsp +} // namespace villas diff --git a/common/include/villas/dsp/window.hpp b/common/include/villas/dsp/window.hpp new file mode 100644 index 000000000..51a4c580c --- /dev/null +++ b/common/include/villas/dsp/window.hpp @@ -0,0 +1,73 @@ +/* A sliding/moving window. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace dsp { + +template > +class Window : protected Container { + +public: + using iterator = typename Container::iterator; + using size_type = typename Container::size_type; + +protected: + virtual T filter(T in, size_type i) const { return in; } + + class transform_iterator : public Container::const_iterator { + protected: + const Window *window; + + using base_iterator = typename Container::const_iterator; + + public: + transform_iterator(const Window *w) + : base_iterator(w->Container::begin()), window(w) {} + + T operator*() { + auto i = (*this) - window->begin(); + const auto &v = base_iterator::operator*(); + + return window->filter(v, i); + } + }; + +public: + Window(size_type l = 0, T i = 0) : Container(l, i) {} + + T val(size_type pos) { return this->Container::operator[](pos); } + + T update(T in) { + Container::push_back(in); + + auto out = (*this)[0]; + + Container::pop_front(); + + return out; + } + + // Expose a limited number of functions from deque + + using Container::end; + using Container::size; + + transform_iterator begin() const noexcept { return transform_iterator(this); } + + T operator[](size_type i) const noexcept { + auto v = Container::operator[](i); + + return filter(v, i); + } +}; + +} // namespace dsp +} // namespace villas diff --git a/common/include/villas/dsp/window_cosine.hpp b/common/include/villas/dsp/window_cosine.hpp new file mode 100644 index 000000000..96b5d75ba --- /dev/null +++ b/common/include/villas/dsp/window_cosine.hpp @@ -0,0 +1,98 @@ +/* A sliding/moving window using a Cosine weighting. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#include + +namespace villas { +namespace dsp { + +template < + typename T> // a0 = 1.0, double a1 = 0.0, double a2 = 0.0, double a3 = 0.0, double a4 = 0.0> +class CosineWindow : public Window { + +public: + using size_type = typename Window::size_type; + +protected: + std::vector coefficients; + + T correctionFactor; + + virtual T filter(T in, size_type i) const { return in * coefficients[i]; } + +public: + CosineWindow(double a0, double a1, double a2, double a3, double a4, + size_type len, T i = 0) + : Window(len, i), coefficients(len), correctionFactor(0) { + for (unsigned i = 0; i < len; i++) { + coefficients[i] = + a0 - a1 * cos(2 * M_PI * i / len) + a2 * cos(4 * M_PI * i / len) - + a3 * cos(6 * M_PI * i / len) + a4 * cos(8 * M_PI * i / len); + + correctionFactor += coefficients[i]; + } + + correctionFactor /= len; + } + + virtual T getCorrectionFactor() const { return correctionFactor; } +}; + +// From: https://en.wikipedia.org/wiki/Window_function#Cosine-sum_windows + +template class RectangularWindow : public CosineWindow { + +public: + RectangularWindow(typename Window::size_type len, T i = 0) + : CosineWindow(1, 0., 0., 0., 0., len, i) {} +}; + +template class HannWindow : public CosineWindow { + +public: + HannWindow(typename Window::size_type len, T i = 0) + : CosineWindow(0.5, 0.5, 0., 0., 0., len, i) {} +}; + +template class HammingWindow : public CosineWindow { + +public: + HammingWindow(typename Window::size_type len, T i = 0) + : CosineWindow(25. / 46, 1 - 25. / 46, 0., 0., 0., len, i) {} +}; + +template class FlattopWindow : public CosineWindow { + +public: + FlattopWindow(typename Window::size_type len, T i = 0) + : CosineWindow(0.21557895, 0.41663158, 0.277263158, 0.083578947, + 0.006947368, len, i) {} +}; + +template class NuttallWindow : public CosineWindow { + +public: + NuttallWindow(typename Window::size_type len, T i = 0) + : CosineWindow(0.355768, 0.487396, 0.144232, 0.012604, 0., len, i) {} +}; + +template class BlackmanWindow : public CosineWindow { + +public: + BlackmanWindow(typename Window::size_type len, T i = 0) + : CosineWindow(0.3635819, 0.4891775, 0.1365995, 0.0106411, 0., len, + i) {} +}; + +} // namespace dsp +} // namespace villas diff --git a/common/include/villas/exceptions.hpp b/common/include/villas/exceptions.hpp new file mode 100644 index 000000000..e910dacd2 --- /dev/null +++ b/common/include/villas/exceptions.hpp @@ -0,0 +1,143 @@ +/* Common exceptions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace villas { + +class SystemError : public std::system_error { + +public: + SystemError(const std::string &what) + : std::system_error(errno, std::system_category(), what) {} + + template + SystemError(const std::string &what, Args &&...args) + : SystemError(fmt::format(what, std::forward(args)...)) {} +}; + +class RuntimeError : public std::runtime_error { + +public: + template + RuntimeError(const std::string &what, Args &&...args) + : std::runtime_error(fmt::format(what, std::forward(args)...)) {} +}; + +class MemoryAllocationError : public RuntimeError { + +public: + MemoryAllocationError() : RuntimeError("Failed to allocate memory") {} +}; + +class JsonError : public std::runtime_error { + +protected: + json_error_t error; + +public: + template + JsonError(const json_t *s, const json_error_t &e, + const std::string &what = std::string(), Args &&...args) + : std::runtime_error( + fmt::format("{}: {} in {}:{}:{}", + fmt::format(what, std::forward(args)...), + error.text, error.source, error.line, error.column)), + error(e) {} +}; + +class ConfigError : public std::runtime_error { + +protected: + // A setting-id referencing the setting. + std::string id; + json_t *setting; + json_error_t error; + + char *msg; + + std::string getMessage() const { + std::stringstream ss; + + ss << std::runtime_error::what() << std::endl; + + if (error.position >= 0) { + ss << std::endl; + ss << " " << error.text << " in " << error.source << ":" << error.line + << ":" << error.column << std::endl; + } + + ss << std::endl + << " Please consult the user documentation for details: " << std::endl; + ss << " " << docUri(); + + ss << std::endl; + + return ss.str(); + } + +public: + ~ConfigError() { + if (msg) + free(msg); + } + + template + ConfigError(json_t *s, const std::string &i, + const std::string &what = "Failed to parse configuration") + : std::runtime_error(what), id(i), setting(s) { + error.position = -1; + + msg = strdup(getMessage().c_str()); + } + + template + ConfigError(json_t *s, const std::string &i, const std::string &what, + Args &&...args) + : std::runtime_error(fmt::format(what, std::forward(args)...)), + id(i), setting(s) { + error.position = -1; + + msg = strdup(getMessage().c_str()); + } + + template + ConfigError(json_t *s, const json_error_t &e, const std::string &i, + const std::string &what = "Failed to parse configuration") + : std::runtime_error(what), id(i), setting(s), error(e) { + msg = strdup(getMessage().c_str()); + } + + template + ConfigError(json_t *s, const json_error_t &e, const std::string &i, + const std::string &what, Args &&...args) + : std::runtime_error(fmt::format(what, std::forward(args)...)), + id(i), setting(s), error(e) { + msg = strdup(getMessage().c_str()); + } + + std::string docUri() const { + std::string baseUri = "https://villas.fein-aachen.org/doc/jump?"; + + return baseUri + id; + } + + virtual const char *what() const noexcept { return msg; } +}; + +} // namespace villas diff --git a/common/include/villas/graph/directed.hpp b/common/include/villas/graph/directed.hpp new file mode 100644 index 000000000..9b4ea8328 --- /dev/null +++ b/common/include/villas/graph/directed.hpp @@ -0,0 +1,255 @@ +/* A directed graph. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace villas { +namespace graph { + +template +class DirectedGraph { +public: + using VertexIdentifier = Vertex::Identifier; + using EdgeIdentifier = Edge::Identifier; + using Path = std::list; + + DirectedGraph(const std::string &name = "DirectedGraph") + : lastVertexId(0), lastEdgeId(0), logger(Log::get(name)) {} + + std::shared_ptr getVertex(VertexIdentifier vertexId) const { + // Cannot use [] operator, because creates non-existing elements + // at() will throw std::out_of_range if element does not exist + return vertices.at(vertexId); + } + + template + VertexIdentifier findVertex(UnaryPredicate p) { + for (auto &v : vertices) { + auto &vertexId = v.first; + auto &vertex = v.second; + + if (p(vertex)) { + return vertexId; + } + } + + throw std::out_of_range("vertex not found"); + } + + std::shared_ptr getEdge(EdgeIdentifier edgeId) const { + if (edgeId >= lastEdgeId) + throw std::invalid_argument("edge doesn't exist"); + + // Cannot use [] operator, because creates non-existing elements + // at() will throw std::out_of_range if element does not exist + return edges.at(edgeId); + } + + std::size_t getEdgeCount() const { return edges.size(); } + + std::size_t getVertexCount() const { return vertices.size(); } + + VertexIdentifier addVertex(std::shared_ptr vertex) { + vertex->id = lastVertexId++; + + logger->debug("New vertex: {}", vertex->toString()); + vertices[vertex->id] = vertex; + + return vertex->id; + } + + EdgeIdentifier addEdge(std::shared_ptr edge, + VertexIdentifier fromVertexId, + VertexIdentifier toVertexId) { + // Allocate edge id + edge->id = lastEdgeId++; + + // Connect it + edge->from = fromVertexId; + edge->to = toVertexId; + + logger->debug("New edge {}: {} -> {}", edge->toString(), edge->from, + edge->to); + + // This is a directed graph, so only push edge to starting vertex + getVertex(edge->from)->edges.push_back(edge->id); + + // Add new edge to graph + edges[edge->id] = edge; + + return edge->id; + } + + EdgeIdentifier addDefaultEdge(VertexIdentifier fromVertexId, + VertexIdentifier toVertexId) { + // Create a new edge + std::shared_ptr edge(new EdgeType); + + return addEdge(edge, fromVertexId, toVertexId); + } + + void removeEdge(EdgeIdentifier edgeId) { + auto edge = getEdge(edgeId); + auto startVertex = getVertex(edge->from); + + // Remove edge only from starting vertex (this is a directed graph) + logger->debug("Remove edge {} from vertex {}", edgeId, edge->from); + startVertex->edges.remove(edgeId); + + logger->debug("Remove edge {}", edgeId); + edges.erase(edgeId); + } + + void removeVertex(VertexIdentifier vertexId) { + // Delete every edge that start or ends at this vertex + auto it = edges.begin(); + while (it != edges.end()) { + auto &edgeId = it->first; + auto &edge = it->second; + + bool removeEdge = false; + + if (edge->to == vertexId) { + logger->debug("Remove edge {} from vertex {}'s edge list", edgeId, + edge->from); + + removeEdge = true; + + auto startVertex = getVertex(edge->from); + startVertex->edges.remove(edge->id); + } + + if ((edge->from == vertexId) or removeEdge) { + logger->debug("Remove edge {}", edgeId); + // Remove edge from global edge list + it = edges.erase(it); + } else + ++it; + } + + logger->debug("Remove vertex {}", vertexId); + vertices.erase(vertexId); + lastVertexId--; + } + + const std::list & + vertexGetEdges(VertexIdentifier vertexId) const { + return getVertex(vertexId)->edges; + } + + using check_path_fn = std::function; + + static bool checkPath(const Path &) { return true; } + + bool getPath(VertexIdentifier fromVertexId, VertexIdentifier toVertexId, + Path &path, check_path_fn pathCheckFunc = checkPath) { + if (fromVertexId == toVertexId) + // Arrived at the destination + return true; + else { + auto fromVertex = getVertex(fromVertexId); + + for (auto &edgeId : fromVertex->edges) { + auto edgeOfFromVertex = getEdge(edgeId); + + // Loop detection + bool loop = false; + for (auto &edgeIdInPath : path) { + auto edgeInPath = getEdge(edgeIdInPath); + if (edgeInPath->from == edgeOfFromVertex->to) { + loop = true; + break; + } + } + + if (loop) { + logger->debug("Loop detected via edge {}", edgeId); + continue; + } + + // Remember the path we're investigating to detect loops + path.push_back(edgeId); + + // Recursive, depth-first search + if (getPath(edgeOfFromVertex->to, toVertexId, path, pathCheckFunc) and + pathCheckFunc(path)) + // Path found, we're done + return true; + else + // Tear down path that didn't lead to the destination + path.pop_back(); + } + } + + return false; + } + + void dump(const std::string &fileName = "") const { + logger->info("Vertices:"); + for (auto &v : vertices) { + auto &vertex = v.second; + + // Format connected vertices into a list + std::stringstream ssEdges; + for (auto &edge : vertex->edges) { + ssEdges << getEdge(edge)->to << " "; + } + + logger->info(" {} connected to: {}", vertex->toString(), ssEdges.str()); + } + + std::fstream s(fileName, s.out | s.trunc); + if (s.is_open()) { + s << "digraph memgraph {" << std::endl; + } + + logger->info("Edges:"); + for (auto &e : edges) { + auto &edge = e.second; + + logger->info(" {}: {} -> {}", edge->toString(), edge->from, edge->to); + if (s.is_open()) { + auto from = getVertex(edge->from); + auto to = getVertex(edge->to); + + s << std::dec; + s << " \"" << *from << "\" -> \"" << *to << "\"" + << " [label=\"" << *edge << "\"];" << std::endl; + } + } + + if (s.is_open()) { + s << "}" << std::endl; + s.close(); + } + } + +protected: + VertexIdentifier lastVertexId; + EdgeIdentifier lastEdgeId; + + std::map> vertices; + std::map> edges; + + Logger logger; +}; + +} // namespace graph +} // namespace villas diff --git a/common/include/villas/graph/edge.hpp b/common/include/villas/graph/edge.hpp new file mode 100644 index 000000000..e2d8c179c --- /dev/null +++ b/common/include/villas/graph/edge.hpp @@ -0,0 +1,51 @@ +/* A graph edge. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +namespace villas { +namespace graph { + +class Edge { + template friend class DirectedGraph; + +public: + using Identifier = std::size_t; + + friend std::ostream &operator<<(std::ostream &stream, const Edge &edge) { + return stream << edge.id; + } + + bool operator==(const Edge &other) { return this->id == other.id; } + + Vertex::Identifier getVertexTo() const { return to; } + + Vertex::Identifier getVertexFrom() const { return from; } + + std::string toString() { + std::stringstream ss; + ss << *this; + return ss.str(); + } + +private: + Identifier id; + Vertex::Identifier from; + Vertex::Identifier to; +}; + +} // namespace graph +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/graph/vertex.hpp b/common/include/villas/graph/vertex.hpp new file mode 100644 index 000000000..4aecf5cbd --- /dev/null +++ b/common/include/villas/graph/vertex.hpp @@ -0,0 +1,52 @@ +/* A graph vertex. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +namespace villas { +namespace graph { + +class Vertex { + template friend class DirectedGraph; + +public: + using Identifier = std::size_t; + + Vertex() : id(0) {} + + const Identifier &getIdentifier() const { return id; } + + friend std::ostream &operator<<(std::ostream &stream, const Vertex &vertex) { + return stream << vertex.id; + } + + bool operator==(const Vertex &other) { return this->id == other.id; } + + std::string toString() { + std::stringstream ss; + ss << *this; + return ss.str(); + } + +private: + Identifier id; + // HACK: how to resolve this circular type dependency? + std::list edges; +}; + +} // namespace graph +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/hist.hpp b/common/include/villas/hist.hpp new file mode 100644 index 000000000..3c7acb33e --- /dev/null +++ b/common/include/villas/hist.hpp @@ -0,0 +1,99 @@ +/* Histogram class. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#include + +#define HEIGHT (LOG_WIDTH - 55) +#define SEQ 17 + +namespace villas { + +// Histogram structure used to collect statistics. +class Hist { + +public: + using cnt_t = uintmax_t; + using idx_t = std::vector::difference_type; + + // Initialize struct Hist with supplied values and allocate memory for buckets. + Hist(int buckets = 0, cnt_t warmup = 0); + + // Reset all counters and values back to zero. + void reset(); + + // Count a value within its corresponding bucket. + void put(double value); + + // Calculate the variance of all counted values. + double getVar() const; + + // Calculate the mean average of all counted values. + double getMean() const; + + // Calculate the standard derivation of all counted values. + double getStddev() const; + + // Print all statistical properties of distribution including a graphical plot of the histogram. + void print(Logger logger, bool details, std::string prefix = "") const; + + // Print ASCII style plot of histogram. + void plot(Logger logger) const; + + // Dump histogram data in Matlab format. + // + // @return The string containing the dump. The caller is responsible to free() the buffer. + char *dump() const; + + // Prints Matlab struct containing all infos to file. + int dumpMatlab(FILE *f) const; + + // Write the histogram in JSON format to file \p f. + int dumpJson(FILE *f) const; + + // Build a libjansson / JSON object of the histogram. + json_t *toJson() const; + + double getHigh() const { return high; } + + double getLow() const { return low; } + + double getHighest() const { return highest; } + + double getLowest() const { return lowest; } + + double getLast() const { return last; } + + cnt_t getTotal() const { return total; } + +protected: + double resolution; // The distance between two adjacent buckets. + + double high; // The value of the highest bucket. + double low; // The value of the lowest bucket. + + double highest; // The highest value observed (may be higher than #high). + double lowest; // The lowest value observed (may be lower than #low). + double last; // The last value which has been put into the buckets. + + cnt_t total; // Total number of counted values. + cnt_t warmup; // Number of values which are used during warmup phase. + + cnt_t higher; // The number of values which are higher than #high. + cnt_t lower; // The number of values which are lower than #low. + + std::vector data; // Bucket counters. + + double _m[2], _s[2]; // Private variables for online variance calculation. +}; + +} // namespace villas diff --git a/common/include/villas/kernel/devices/pci_device.hpp b/common/include/villas/kernel/devices/pci_device.hpp new file mode 100644 index 000000000..65794644b --- /dev/null +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -0,0 +1,130 @@ +/* Linux PCI helpers. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include +#include + +#include + +namespace villas { +namespace kernel { +namespace devices { + +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) +#define PCI_FUNC(devfn) ((devfn) & 0x07) + +class Id { +public: + Id(const std::string &str); + + Id(int vid = 0, int did = 0, int cc = 0) + : vendor(vid), device(did), class_code(cc) {} + + bool operator==(const Id &i); + + unsigned int vendor; + unsigned int device; + unsigned int class_code; +}; + +class Slot { +public: + Slot(const std::string &str); + + Slot(int dom = 0, int b = 0, int dev = 0, int fcn = 0) + : domain(dom), bus(b), device(dev), function(fcn) {} + + bool operator==(const Slot &s); + + unsigned int domain; + unsigned int bus; + unsigned int device; + unsigned int function; +}; + +struct Region { + int num; + uintptr_t start; + uintptr_t end; + unsigned long long flags; +}; + +class PciDevice { +public: + PciDevice(Id i, Slot s) : id(i), slot(s), log(Log::get("kernel:pci")) {} + + PciDevice(Id i) : id(i), log(Log::get("kernel:pci")) {} + + PciDevice(Slot s) : slot(s), log(Log::get("kernel:pci")) {} + + bool operator==(const PciDevice &other); + + // Get currently loaded driver for device + std::string getDriver() const; + + // Bind a new LKM to the PCI device + bool attachDriver(const std::string &driver) const; + + // Return the IOMMU group of this PCI device or -1 if the device is not in a group + int getIommuGroup() const; + + std::list getRegions() const; + + // Write 32-bit BAR value from to the PCI configuration space + void writeBar(uint32_t addr, unsigned bar = 0); + + // If BAR values in config space and in the kernel do not match, rewrite + // the BAR value of the kernel to PCIe config space + void rewriteBar(unsigned bar = 0); + + // Read 32-bit BAR value from the PCI configuration space + uint32_t readBar(unsigned bar = 0) const; + + // Read 32-bit BAR value from the devices resource file. + // This is what the kernel thinks the BAR should be. + uint32_t readHostBar(unsigned bar = 0) const; + + Id id; + Slot slot; + +private: + villas::Logger log; + +protected: + std::fstream + openSysFs(const std::string &subPath, + std::ios_base::openmode mode = std::ios_base::in | + std::ios_base::out) const; +}; + +class PciDeviceList : public std::list> { +private: + // Initialize Linux PCI handle. + // + // This search for all available PCI devices under /sys/bus/pci + PciDeviceList(); + PciDeviceList &operator=(const PciDeviceList &); + static PciDeviceList *instance; + +public: + static PciDeviceList *getInstance(); + + PciDeviceList::value_type lookupDevice(const Slot &s); + + PciDeviceList::value_type lookupDevice(const Id &i); + + PciDeviceList::value_type lookupDevice(const PciDevice &f); +}; + +} // namespace devices +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/kernel/kernel.hpp b/common/include/villas/kernel/kernel.hpp new file mode 100644 index 000000000..67db8e930 --- /dev/null +++ b/common/include/villas/kernel/kernel.hpp @@ -0,0 +1,67 @@ +/* Linux kernel related functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include + +namespace villas { +namespace kernel { + +// Get the version of the kernel +utils::Version getVersion(); + +// Get number of reserved hugepages +int getNrHugepages(); + +// Set number of reserved hugepages +int setNrHugepages(int nr); + +// Get kernel cmdline parameter +// +// See https://www.kernel.org/doc/Documentation/kernel-parameters.txt +// +// @param param The cmdline parameter to look for +// @param buf The string buffer to which the parameter value will be copied to +// @param len The length of the buffer \p value +// @retval 0 Parameter \p key was found and value was copied to \p value +// @reval <>0 Kernel was not booted with parameter \p key +int getCmdlineParam(const char *param, char *buf, size_t len); + +// Checks if a kernel module is loaded +// +// @param module the name of the module +// @retval 0 Module is loaded +// @reval <>0 Module is not loaded +int isModuleLoaded(const char *module); + +// Load kernel module via modprobe +int loadModule(const char *module); + +// Set parameter of loaded kernel module +int setModuleParam(const char *module, const char *param, const char *value); + +// Get cacheline size in bytes +int getCachelineSize(); + +// Get the size of a standard page in bytes +int getPageSize(); + +// Get the size of a huge page in bytes +int getHugePageSize(); + +// Get CPU base frequency +int get_cpu_frequency(uint64_t *freq); + +// Set SMP affinity of IRQ +int setIRQAffinity(unsigned irq, uintmax_t aff, uintmax_t *old); + +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/kernel/rt.hpp b/common/include/villas/kernel/rt.hpp new file mode 100644 index 000000000..3fdf80b0f --- /dev/null +++ b/common/include/villas/kernel/rt.hpp @@ -0,0 +1,34 @@ +/* Linux specific real-time optimizations. + * + * @see: https://wiki.linuxfoundation.org/realtime/documentation/howto/applications/application_base + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace kernel { +namespace rt { + +void init(int priority, int affinity); + +void setProcessAffinity(int affinity); +void setThreadAffinity(pthread_t thread, int affinity); + +void setPriority(int priority); + +// Checks for realtime (PREEMPT_RT) patched kernel. +// +// See https://rt.wiki.kernel.org +// +// @retval true Kernel is patched. +// @retval false Kernel is not patched. +bool isPreemptible(); + +} // namespace rt +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/kernel/vfio_container.hpp b/common/include/villas/kernel/vfio_container.hpp new file mode 100644 index 000000000..2165092da --- /dev/null +++ b/common/include/villas/kernel/vfio_container.hpp @@ -0,0 +1,83 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Niklas Eiling + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-FileCopyrightText: 2014-2023 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include +#include + +#include + +namespace villas { +namespace kernel { +namespace vfio { + +// Backwards compatability with older kernels +#ifdef VFIO_UPDATE_VADDR +static constexpr size_t EXTENSION_SIZE = VFIO_UPDATE_VADDR + 1; +#elif defined(VFIO_UNMAP_ALL) +static constexpr size_t EXTENSION_SIZE = VFIO_UNMAP_ALL + 1; +#else +static constexpr size_t EXTENSION_SIZE = VFIO_NOIOMMU_IOMMU + 1; +#endif + +class Container { +public: + Container(std::vector required_modules = {"vfio"}); + + // No copying allowed because we manage the vfio state in constructor and destructors + Container(Container const &) = delete; + void operator=(Container const &) = delete; + + ~Container(); + + void dump(); + + void attachGroup(std::shared_ptr group); + std::shared_ptr getOrAttachGroup(int index); + + std::shared_ptr attachDevice(const std::string &name, int groupIndex); + std::shared_ptr attachDevice(devices::PciDevice &pdev); + + // Map VM to an IOVA, which is accessible by devices in the container + // + // @param virt virtual address of memory + // @param phys IOVA where to map @p virt, -1 to use VFIO internal allocator + // @param length size of memory region in bytes + // @return IOVA address, UINTPTR_MAX on failure + uintptr_t memoryMap(uintptr_t virt, uintptr_t phys, size_t length); + + // munmap() a region which has been mapped by vfio_map_region() + bool memoryUnmap(uintptr_t phys, size_t length); + + bool isIommuEnabled() const { return this->hasIommu; } + +private: + int fd; + int version; + + std::array extensions; + uint64_t iova_next; // Next free IOVA address + bool hasIommu; + + // All groups bound to this container + std::list> groups; + + Logger log; +}; + +} // namespace vfio +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp new file mode 100644 index 000000000..ca49c2e1f --- /dev/null +++ b/common/include/villas/kernel/vfio_device.hpp @@ -0,0 +1,101 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Niklas Eiling + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-FileCopyrightText: 2014-2023 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace villas { +namespace kernel { +namespace vfio { + +class Device { +public: + Device(const std::string &name, int groupFileDescriptor, + const kernel::devices::PciDevice *pci_device = nullptr); + ~Device(); + + // No copying allowed because we manage the vfio state in constructor and destructors + Device(Device const &) = delete; + void operator=(Device const &) = delete; + + bool reset(); + + std::string getName() { return name; }; + + // Map a device memory region to the application address space (e.g. PCI BARs) + void *regionMap(size_t index); + + // munmap() a region which has been mapped by vfio_map_region() + bool regionUnmap(size_t index); + + // Get the size of a device memory region + size_t regionGetSize(size_t index); + + // Enable memory accesses and bus mastering for PCI device + bool pciEnable(); + + int pciMsiInit(int efds[32]); + int pciMsiDeinit(int efds[32]); + bool pciMsiFind(int nos[32]); + + bool isVfioPciDevice() const; + bool pciHotReset(); + + int getFileDescriptor() const { return fd; } + std::vector &getEventfdList() { return eventfdList; } + + void dump(); + + bool isAttachedToGroup() const { return attachedToGroup; } + + void setAttachedToGroup() { this->attachedToGroup = true; } + + int getNumberIrqs() const { return this->info.num_irqs; } + +private: + // Name of the device as listed under + // /sys/kernel/iommu_groups/[vfio_group::index]/devices/ + std::string name; + + // VFIO device file descriptor + int fd; + + bool attachedToGroup; + int groupFd; + + // Interrupt eventfds + std::vector eventfdList; + + struct vfio_device_info info; + + std::vector irqs; + std::vector regions; + std::vector mappings; + + // libpci handle of the device + const kernel::devices::PciDevice *pci_device; + + Logger log; +}; + +} // namespace vfio +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/kernel/vfio_group.hpp b/common/include/villas/kernel/vfio_group.hpp new file mode 100644 index 000000000..5f990c46c --- /dev/null +++ b/common/include/villas/kernel/vfio_group.hpp @@ -0,0 +1,76 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Niklas Eiling + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-FileCopyrightText: 2014-2023 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include +#include + +#include +#include + +namespace villas { +namespace kernel { +namespace vfio { + +#define VFIO_PATH "/dev/vfio/" +#define VFIO_DEV VFIO_PATH "vfio" + +class Group { +public: + Group(int index, bool iommuEnabled); + ~Group(); + + // No copying allowed because we manage the vfio state in constructor and destructors + Group(Group const &) = delete; + void operator=(Group const &) = delete; + + void setAttachedToContainer() { attachedToContainer = true; } + + bool isAttachedToContainer() { return attachedToContainer; } + + int getFileDescriptor() { return fd; } + + int getIndex() { return index; } + + std::shared_ptr attachDevice(std::shared_ptr device); + std::shared_ptr + attachDevice(const std::string &name, + const kernel::devices::PciDevice *pci_device = nullptr); + + bool checkStatus(); + void dump(); + +private: + // VFIO group file descriptor + int fd; + + // Index of the IOMMU group as listed under /sys/kernel/iommu_groups/ + int index; + + bool attachedToContainer; + + // Status of group + struct vfio_group_status status; + + // All devices owned by this group + std::list> devices; + + Logger log; +}; + +} // namespace vfio +} // namespace kernel +} // namespace villas diff --git a/common/include/villas/list.hpp b/common/include/villas/list.hpp new file mode 100644 index 000000000..f65f9c5e4 --- /dev/null +++ b/common/include/villas/list.hpp @@ -0,0 +1,133 @@ +/* A generic list implementation. + * + * This is a generic implementation of a list which can store void pointers to + * arbitrary data. The data itself is not stored or managed by the list. + * + * Internally, an array of pointers is used to store the pointers. + * If needed, this array will grow by realloc(). + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#define LIST_CHUNKSIZE 16 + +// Static list initialization +#define LIST_INIT_STATIC(l) \ + __attribute__((constructor(105))) static void UNIQUE(__ctor)() { \ + int ret __attribute__((unused)); \ + ret = list_init(l); \ + } \ + __attribute__((destructor(105))) static void UNIQUE(__dtor)() { \ + int ret __attribute__((unused)); \ + ret = list_destroy(l, nullptr, false); \ + } + +#define list_length(list) ((list)->length) +#define list_at_safe(list, index) \ + ((list)->length > index ? (list)->array[index] : nullptr) +#define list_at(list, index) ((list)->array[index]) + +#define list_first(list) list_at(list, 0) +#define list_last(list) list_at(list, (list)->length - 1) + +namespace villas { + +// Callback to search or sort a list. +typedef int (*cmp_cb_t)(const void *, const void *); + +// The list data structure. +struct List { + enum State state; // The state of this list. + void **array; // Array of pointers to list elements. + size_t capacity; // Size of list::array in elements. + size_t length; // Number of elements of list::array which are in use. + pthread_mutex_t lock; // A mutex to allow thread-safe accesses. +}; + +// Initialize a list. +// +// @param l A pointer to the list data structure. +int list_init(struct List *l) __attribute__((warn_unused_result)); + +// Destroy a list and call destructors for all list elements +// +// @param free free() all list members during when calling list_destroy() +// @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed. +// @param l A pointer to the list data structure. +int list_destroy(struct List *l, dtor_cb_t dtor = nullptr, bool free = false) + __attribute__((warn_unused_result)); + +// Append an element to the end of the list. +void list_push(struct List *l, void *p); + +// Clear list. +void list_clear(struct List *l); + +// Remove all occurences of a list item. +void list_remove_all(struct List *l, void *p); + +int list_remove(struct List *l, size_t idx); + +int list_insert(struct List *l, size_t idx, void *p); + +// Return the first element of the list for which cmp returns zero. +void *list_search(struct List *l, cmp_cb_t cmp, const void *ctx); + +// Returns the number of occurences for which cmp returns zero when called on all list elements. +int list_count(struct List *l, cmp_cb_t cmp, void *ctx); + +// Return 0 if list contains pointer p. +int list_contains(struct List *l, void *p); + +// Sort the list using the quicksort algorithm of libc. +void list_sort(struct List *l, cmp_cb_t cmp); + +// Set single element in list. +int list_set(struct List *l, unsigned index, void *value); + +// Return index in list for value. +// +// @retval <0 No list entry matching \p value was found. +// @retval >=0 Entry \p value was found at returned index. +ssize_t list_index(struct List *l, void *value); + +// Extend the list to the given length by filling new slots with given value. +void list_extend(struct List *l, size_t len, void *val); + +// Remove all elements for which the callback returns a non-zero return code. +void list_filter(struct List *l, dtor_cb_t cb); + +// Lookup an element from the list based on a name. +template +T *list_lookup_name(struct List *l, const std::string &name) { + return (T *)list_search( + l, + [](const void *a, const void *b) -> int { + auto *e = reinterpret_cast(a); + auto *s = reinterpret_cast(b); + + return *s == e->name ? 0 : 1; + }, + &name); +} + +// Lookup index of list element based on name. +template +ssize_t list_lookup_index(struct List *l, const std::string &name) { + auto *f = list_lookup_name(l, name); + + return f ? list_index(l, f) : -1; +} + +} // namespace villas diff --git a/common/include/villas/log.hpp b/common/include/villas/log.hpp new file mode 100644 index 000000000..459939499 --- /dev/null +++ b/common/include/villas/log.hpp @@ -0,0 +1,98 @@ +/* Logging. + * + * Author: Daniel Krebs + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include +#include +#include + +#include + +namespace villas { + +// Forward declarations +using Logger = std::shared_ptr; +class Log { + +public: + using Level = spdlog::level::level_enum; + using DefaultSink = std::shared_ptr; + using DistSink = std::shared_ptr; + using Formatter = std::shared_ptr; + + class Expression { + public: + std::string name; + Level level; + + Expression(const std::string &n, Level lvl) : name(n), level(lvl) {} + + Expression(json_t *json); + }; + +protected: + DistSink sinks; + DefaultSink sink; + Formatter formatter; + + Level level; + + std::string pattern; // Logging format. + std::string prefix; // Prefix each line with this string. + + std::list expressions; + +public: + Log(Level level = Level::info); + + // Get the real usable log output width which fits into one line. + int getWidth(); + + void parse(json_t *json); + + static Log &getInstance() { + // This will "leak" memory. Because we don't have a complex destructor it's okay + // that this will be cleaned up implicitly on program exit. + static auto log = new Log(); + return *log; + }; + + Logger getNewLogger(const std::string &name); + + static Logger get(const std::string &name) { + static auto &log = getInstance(); + return log.getNewLogger(name); + } + + void setFormatter(const std::string &pattern, const std::string &pfx = ""); + void setLevel(Level lvl); + void setLevel(const std::string &lvl); + + Level getLevel() const; + std::string getLevelName() const; + + void addSink(std::shared_ptr sink) { + sink->set_formatter(formatter->clone()); + sink->set_level(level); + + sinks->add_sink(sink); + } + + void replaceStdSink(std::shared_ptr sink) { + sink->set_formatter(formatter->clone()); + sink->set_level(level); + + sinks->sinks()[0] = sink; + } +}; + +} // namespace villas diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp new file mode 100644 index 000000000..a98556d4d --- /dev/null +++ b/common/include/villas/memory.hpp @@ -0,0 +1,288 @@ +/* Memory management. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include +#include + +namespace villas { + +// Basic memory block backed by an address space in the memory graph +// +// This is a generic representation of a chunk of memory in the system. It can +// reside anywhere and represent different types of memory. +class MemoryBlock { +public: + using deallocator_fn = std::function; + + using Ptr = std::shared_ptr; + using UniquePtr = std::unique_ptr; + + // cppcheck-suppress passedByValue + MemoryBlock(size_t offset, size_t size, + const MemoryManager::AddressSpaceId &addrSpaceId) + : offset(offset), size(size), addrSpaceId(addrSpaceId) {} + + MemoryManager::AddressSpaceId getAddrSpaceId() const { return addrSpaceId; } + + size_t getSize() const { return size; } + + size_t getOffset() const { return offset; } + +protected: + size_t offset; // Offset (or address) inside address space + size_t size; // Size in bytes of this block + MemoryManager::AddressSpaceId addrSpaceId; // Identifier in memory graph +}; + +// Wrapper for a MemoryBlock to access the underlying memory directly +// +// The underlying memory block has to be accessible for the current process, +// that means it has to be mapped accordingly and registered to the global +// memory graph. +// Furthermore, this wrapper can be owning the memory block when initialized +// with a moved unique pointer. Otherwise, it just stores a reference to the +// memory block and it's the users responsibility to take care that the memory +// block is valid. +template class MemoryAccessor { +public: + using Type = T; + + // Take ownership of the MemoryBlock + MemoryAccessor(std::unique_ptr mem) + : translation(MemoryManager::get().getTranslationFromProcess( + mem->getAddrSpaceId())), + memoryBlock(std::move(mem)) {} + + // Just act as an accessor, do not take ownership of MemoryBlock + MemoryAccessor(const MemoryBlock &mem) + : translation(MemoryManager::get().getTranslationFromProcess( + mem.getAddrSpaceId())) {} + + MemoryAccessor(const MemoryTranslation &translation) + : translation(translation) {} + + T &operator*() const { + return *reinterpret_cast(translation.getLocalAddr(0)); + } + + T &operator[](size_t idx) const { + const size_t offset = sizeof(T) * idx; + return *reinterpret_cast(translation.getLocalAddr(offset)); + } + + T *operator&() const { + return reinterpret_cast(translation.getLocalAddr(0)); + } + + T *operator->() const { + return reinterpret_cast(translation.getLocalAddr(0)); + } + + const MemoryBlock &getMemoryBlock() const { + if (not memoryBlock) + throw std::bad_alloc(); + else + return *memoryBlock; + } + +private: + // Cached memory translation for fast access + MemoryTranslation translation; + + // Take the unique pointer in case user wants this class to have ownership + std::unique_ptr memoryBlock; +}; + +// Base memory allocator +// +// Note the usage of CRTP idiom here to access methods of derived allocators. +// The concept is explained here at [1]. +// +// [1] https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern +template class BaseAllocator { +public: + // memoryAddrSpaceId: memory that is managed by this allocator + BaseAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId) + : memoryAddrSpaceId(memoryAddrSpaceId) { + // CRTP + derivedAlloc = static_cast(this); + std::string loggerName = fmt::format("memory:", derivedAlloc->getName()); + logger = Log::get(loggerName); + + // Default deallocation callback + free = [&](MemoryBlock *mem) { + logger->warn("no free callback defined for addr space {}, not freeing", + mem->getAddrSpaceId()); + + removeMemoryBlock(*mem); + }; + } + + BaseAllocator(std::unique_ptr mem) + : BaseAllocator(mem->getAddrSpaceId()) { + // cppcheck-suppress useInitializationList + memoryBlock = std::move(mem); + derivedAlloc = nullptr; + } + + virtual std::unique_ptr + + allocateBlock(size_t size) = 0; + + template MemoryAccessor allocate(size_t num) { + if (num == 0) { + // Doesn't make sense to allocate an empty block + logger->error("Trying to allocate empty memory"); + throw std::bad_alloc(); + } + + const size_t size = num * sizeof(T); + auto mem = allocateBlock(size); + + // Check if the allocated memory is really accessible by writing to the + // allocated memory and reading back. Exponentially increase offset to + // speed up testing. + MemoryAccessor byteAccessor(*mem); + size_t idx = 0; + for (int i = 0; idx < mem->getSize(); i++, idx = (1 << i)) { + auto val = static_cast(i); + byteAccessor[idx] = val; + if (byteAccessor[idx] != val) { + logger->error("Cannot access allocated memory"); + throw std::bad_alloc(); + } + } + + return MemoryAccessor(std::move(mem)); + } + +protected: + void insertMemoryBlock(const MemoryBlock &mem) { + auto &mm = MemoryManager::get(); + mm.createMapping(mem.getOffset(), 0, mem.getSize(), derivedAlloc->getName(), + memoryAddrSpaceId, mem.getAddrSpaceId()); + } + + void removeMemoryBlock(const MemoryBlock &mem) { + // This will also remove any mapping to and from the memory block + auto &mm = MemoryManager::get(); + mm.removeAddressSpace(mem.getAddrSpaceId()); + } + + MemoryManager::AddressSpaceId getAddrSpaceId() const { + return memoryAddrSpaceId; + } + + MemoryBlock::deallocator_fn free; + Logger logger; + + // Optional, if allocator should own the memory block + std::unique_ptr memoryBlock; + +private: + MemoryManager::AddressSpaceId memoryAddrSpaceId; + DerivedAllocator *derivedAlloc; +}; + +// Linear memory allocator +// +// This is the simplest kind of allocator. The idea is to keep a pointer at the +// first memory address of your memory chunk and move it every time an +// allocation is done. Due to its simplicity, this allocator doesn't allow +// specific positions of memory to be freed. Usually, all memory is freed +// together. +class LinearAllocator : public BaseAllocator { +public: + LinearAllocator(const MemoryManager::AddressSpaceId &memoryAddrSpaceId, + size_t memorySize, size_t internalOffset = 0); + + LinearAllocator(std::unique_ptr mem) + : LinearAllocator(mem->getAddrSpaceId(), mem->getSize()) { + memoryBlock = std::move(mem); + } + + size_t getAvailableMemory() const { return memorySize - nextFreeAddress; } + + size_t getSize() const { return memorySize; } + + std::string getName() const; + + std::unique_ptr + allocateBlock(size_t size); + +private: + static constexpr size_t alignBytes = sizeof(uintptr_t); + static constexpr size_t alignMask = alignBytes - 1; + + size_t getAlignmentPadding(uintptr_t addr) const { + return (alignBytes - (addr & alignMask)) & alignMask; + } + + size_t nextFreeAddress; // Next chunk will be allocated here + size_t memorySize; // Total size of managed memory + size_t internalOffset; // Offset in address space (usually 0) + size_t allocationCount; // Number of individual allocations present +}; + +// Wrapper around mmap() to create villas memory blocks +// +// This class simply wraps around mmap() and munmap() to allocate memory in the +// host memory via the OS. +class HostRam { +public: + class HostRamAllocator : public BaseAllocator { + public: + HostRamAllocator(); + + std::string getName() const { return "HostRamAlloc"; } + + std::unique_ptr + allocateBlock(size_t size); + }; + + static HostRamAllocator &getAllocator() { + // This will "leak" memory. Because we don't have a complex destructor it's okay + // that this will be cleaned up implicitly on program exit. + static auto allocator = new HostRamAllocator(); + return *allocator; + } +}; + +class HostDmaRam { +public: + class HostDmaRamAllocator : public LinearAllocator { + public: + HostDmaRamAllocator(int num); + + virtual ~HostDmaRamAllocator(); + + std::string getName() const { return getUdmaBufName(num); } + + private: + int num; + }; + + static HostDmaRamAllocator &getAllocator(int num = 0); + +private: + static std::map> allocators; + + static std::string getUdmaBufName(int num); + + static std::string getUdmaBufBasePath(int num); + + static size_t getUdmaBufBufSize(int num); + + static uintptr_t getUdmaBufPhysAddr(int num); +}; + +} // namespace villas diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp new file mode 100644 index 000000000..60f61c96c --- /dev/null +++ b/common/include/villas/memory_manager.hpp @@ -0,0 +1,238 @@ +/* Memory manager. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace villas { + +// Translation between a local (master) to a foreign (slave) address space +// +// Memory translations can be chained together using the `+=` operator which is +// used internally by the MemoryManager to compute a translation through +// multiple hops (memory mappings). +class MemoryTranslation { +public: + // MemoryTranslation + // @param src Base address of local address space + // @param dst Base address of foreign address space + // @param size Size of "memory window" + MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) + : src(src), dst(dst), size(size) {} + + uintptr_t getLocalAddr(uintptr_t addrInForeignAddrSpace) const; + + uintptr_t getForeignAddr(uintptr_t addrInLocalAddrSpace) const; + + size_t getSize() const { return size; } + + friend std::ostream &operator<<(std::ostream &stream, + const MemoryTranslation &translation) { + return stream << std::hex << "(src=0x" << translation.src << ", dst=0x" + << translation.dst << ", size=0x" << translation.size << ")"; + } + + // Merge two MemoryTranslations together + MemoryTranslation &operator+=(const MemoryTranslation &other); + +private: + uintptr_t src; // Base address of local address space + uintptr_t dst; // Base address of foreign address space + size_t size; // Size of "memory window" +}; + +// Global memory manager to resolve addresses across address spaces +// +// Every entity in the system has to register its (master) address space and +// create mappings to other (slave) address spaces that it can access. A +// directed graph is then constructed which allows to traverse addresses spaces +// through multiple mappings and resolve addresses through this "tunnel" of +// memory mappings. +class MemoryManager { +private: + // This is a singleton, so private constructor ... + MemoryManager() + : memoryGraph("memory:graph"), logger(Log::get("memory:manager")) { + pathCheckFunc = [&](const MemoryGraph::Path &path) { + return this->pathCheck(path); + }; + } + + // ... and no copying or assigning + MemoryManager(const MemoryManager &) = delete; + MemoryManager &operator=(const MemoryManager &) = delete; + + // Custom edge in memory graph representing a memory mapping + // + // A memory mapping maps from one address space into another and can only be + // traversed in the forward direction which reflects the nature of real + // memory mappings. + // + // Implementation Notes: + // The member #src is the address in the "from" address space, where the + // destination address space is mapped. The member #dest is the address in + // the destination address space, where the mapping points to. Often, #dest + // will be zero for mappings to hardware, but consider the example when + // mapping FPGA to application memory: + // The application allocates a block 1kB at address 0x843001000 in its + // address space. The mapping would then have a #dest address of 0x843001000 + // and a #size of 1024. + class Mapping : public graph::Edge { + public: + std::string name; // Human-readable name + uintptr_t src; // Base address in "from" address space + uintptr_t dest; // Base address in "to" address space + size_t size; // Size of the mapping + + friend std::ostream &operator<<(std::ostream &stream, + const Mapping &mapping) { + return stream << static_cast(mapping) << " = " + << mapping.name << std::hex << " (src=0x" << mapping.src + << ", dest=0x" << mapping.dest << ", size=0x" + << mapping.size << ")"; + } + + std::string toString() { + std::stringstream s; + s << *this; + return s.str(); + } + }; + + // Custom vertex in memory graph representing an address space + // + // Since most information in the memory graph is stored in the edges (memory + // mappings), this is just a small extension to the default vertex. It only + // associates an additional string #name for human-readability. + class AddressSpace : public graph::Vertex { + public: + std::string name; // Human-readable name + + friend std::ostream &operator<<(std::ostream &stream, + const AddressSpace &addrSpace) { + return stream << static_cast(addrSpace) << " = " + << addrSpace.name; + } + }; + + // Memory graph with custom edges and vertices for address resolution + using MemoryGraph = graph::DirectedGraph; + +public: + using AddressSpaceId = MemoryGraph::VertexIdentifier; + using MappingId = MemoryGraph::EdgeIdentifier; + + struct InvalidTranslation : public std::exception {}; + + // Get singleton instance + static MemoryManager &get(); + + MemoryGraph &getGraph() { return memoryGraph; } + void printGraph(); + + AddressSpaceId getProcessAddressSpace() { + return getOrCreateAddressSpace("process"); + } + + AddressSpaceId getPciAddressSpace() { + return getOrCreateAddressSpace("pcie"); + } + + AddressSpaceId + getProcessAddressSpaceMemoryBlock(const std::string &memoryBlock) { + return getOrCreateAddressSpace( + getSlaveAddrSpaceName("process", memoryBlock)); + } + + AddressSpaceId getOrCreateAddressSpace(std::string name); + + void removeAddressSpace(const AddressSpaceId &addrSpaceId) { + memoryGraph.removeVertex(addrSpaceId); + } + + // Create a default mapping + MappingId createMapping(uintptr_t src, uintptr_t dest, size_t size, + const std::string &name, AddressSpaceId fromAddrSpace, + AddressSpaceId toAddrSpace); + + // Add a mapping + // + // Can be used to derive from Mapping in order to implement custom + // constructor/destructor. + MappingId addMapping(std::shared_ptr mapping, + AddressSpaceId fromAddrSpace, + AddressSpaceId toAddrSpace); + + AddressSpaceId findAddressSpace(const std::string &name); + + std::list findPath(const AddressSpaceId &fromAddrSpaceId, + const AddressSpaceId &toAddrSpaceId); + + MemoryTranslation getTranslation(const AddressSpaceId &fromAddrSpaceId, + const AddressSpaceId &toAddrSpaceId); + + // cppcheck-suppress passedByValue + MemoryTranslation + getTranslationFromProcess(const AddressSpaceId &foreignAddrSpaceId) { + return getTranslation(getProcessAddressSpace(), foreignAddrSpaceId); + } + + static std::string getSlaveAddrSpaceName(const std::string &ipInstance, + const std::string &memoryBlock) { + return ipInstance + "/" + memoryBlock; + } + + static std::string getMasterAddrSpaceName(const std::string &ipInstance, + const std::string &busInterface) { + return ipInstance + ":" + busInterface; + } + +private: + // Convert a Mapping to MemoryTranslation for calculations + static MemoryTranslation getTranslationFromMapping(const Mapping &mapping) { + return MemoryTranslation(mapping.src, mapping.dest, mapping.size); + } + + bool pathCheck(const MemoryGraph::Path &path); + + // Directed graph that stores address spaces and memory mappings + MemoryGraph memoryGraph; + + // Cache mapping of names to address space ids for fast lookup + std::map addrSpaceLookup; + + // Logger for universal access in this class + Logger logger; + + MemoryGraph::check_path_fn pathCheckFunc; + + // Static pointer to global instance, because this is a singleton + static MemoryManager *instance; +}; + +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/plugin.hpp b/common/include/villas/plugin.hpp new file mode 100644 index 000000000..41a0f18d5 --- /dev/null +++ b/common/include/villas/plugin.hpp @@ -0,0 +1,156 @@ +/* Loadable / plugin support. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace plugin { + +// Forward declarations +class Plugin; +class Registry; + +extern Registry *registry; + +template using List = std::list; + +class SubRegistry { + +public: + virtual List<> lookup() = 0; +}; + +class Registry { + +protected: + List<> plugins; + List registries; + +public: + Logger getLogger() { return Log::get("plugin:registry"); } + + void add(Plugin *p) { plugins.push_back(p); } + + void addSubRegistry(SubRegistry *sr) { registries.push_back(sr); } + + void remove(Plugin *p) { plugins.remove(p); } + + // Get all plugins including sub-registries + List<> lookup() { + List<> all; + + all.insert(all.end(), plugins.begin(), plugins.end()); + + for (auto r : registries) { + auto p = r->lookup(); + + all.insert(all.end(), p.begin(), p.end()); + } + + return all; + } + + // Get all plugins of specific type + template List lookup() { + List list; + + for (Plugin *p : lookup()) { + T *t = dynamic_cast(p); + if (t) + list.push_back(t); + } + + // Sort alphabetically + list.sort( + [](const T *a, const T *b) { return a->getName() < b->getName(); }); + + return list; + } + + // Get all plugins of specific type and name + template T *lookup(const std::string &name) { + for (T *p : lookup()) { + if (p->getName() != name) + continue; + + return p; + } + + return nullptr; + } + + template void dump(); +}; + +class Plugin { + + friend plugin::Registry; + +protected: + Logger logger; + +public: + Plugin(); + + virtual ~Plugin(); + + // Copying a plugin doesn't make sense, so explicitly deny it + Plugin(Plugin const &) = delete; + void operator=(Plugin const &) = delete; + + virtual void dump(); + + // Get plugin name + virtual std::string getName() const = 0; + + // Get plugin type + virtual std::string getType() const = 0; + + // Get plugin description + virtual std::string getDescription() const = 0; + + virtual Logger getLogger() { + if (!logger) { + auto name = fmt::format("{}:{}", getType(), getName()); + logger = Log::get(name); + } + + return logger; + } + + friend std::ostream &operator<<(std::ostream &os, const class Plugin &p) { + return os << p.getName(); + } +}; + +template void Registry::dump() { + getLogger()->info("Available plugins:"); + + for (Plugin *p : plugins) { + T *t = dynamic_cast(p); + if (t) + getLogger()->info(" - {}: {}", p->getName(), p->getDescription()); + } +} + +} // namespace plugin +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/popen.hpp b/common/include/villas/popen.hpp new file mode 100644 index 000000000..e952640d1 --- /dev/null +++ b/common/include/villas/popen.hpp @@ -0,0 +1,92 @@ +/* Bi-directional popen. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace utils { + +class Popen { + +public: + using arg_list = std::vector; + using env_map = std::map; + + using char_type = char; + using stdio_buf = __gnu_cxx::stdio_filebuf; + + Popen(const std::string &cmd, const arg_list &args = arg_list(), + const env_map &env = env_map(), const std::string &wd = std::string(), + bool shell = false); + ~Popen(); + + void open(); + int close(); + void kill(int signal = SIGINT); + + int getFdIn() { return fd_in; } + + int getFdOut() { return fd_out; } + + pid_t getPid() const { return pid; } + +protected: + std::string command; + std::string working_dir; + arg_list arguments; + env_map environment; + bool shell; + pid_t pid; + + int fd_in, fd_out; +}; + +class PopenStream : public Popen { + +public: + PopenStream(const std::string &cmd, const arg_list &args = arg_list(), + const env_map &env = env_map(), + const std::string &wd = std::string(), bool shell = false); + ~PopenStream(); + + std::istream &cin() { return *(input.stream); } + + std::ostream &cout() { return *(output.stream); } + + void open(); + int close(); + +protected: + struct { + std::unique_ptr stream; + std::unique_ptr buffer; + } input; + + struct { + std::unique_ptr stream; + std::unique_ptr buffer; + } output; +}; + +} // namespace utils +} // namespace villas + +template +std::istream &operator>>(villas::utils::PopenStream &po, T &value) { + return *(po.input.stream) >> value; +} diff --git a/common/include/villas/table.hpp b/common/include/villas/table.hpp new file mode 100644 index 000000000..555dd3141 --- /dev/null +++ b/common/include/villas/table.hpp @@ -0,0 +1,69 @@ +/* Print fancy tables. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include + +namespace villas { + +class Table; + +class TableColumn { + + friend Table; + +public: + enum class Alignment { LEFT, RIGHT }; + +protected: + int _width; // The real width of this column. Calculated by Table::resize(). + + int width; // Width of the column. + +public: + TableColumn(int w, enum Alignment a, const std::string &t, + const std::string &f, const std::string &u = "") + : _width(0), width(w), title(t), format(f), unit(u), align(a) {} + + std::string title; // The title as shown in the table header. + std::string format; // The format which is used to print the table rows. + std::string unit; // An optional unit which will be shown in the table header. + + enum Alignment align; + + int getWidth() const { return _width; } +}; + +class Table { + +protected: + int resize(int w); + + int width; + + std::vector columns; + + Logger logger; + +public: + Table(Logger log, const std::vector &cols) + : width(-1), columns(cols), logger(log) {} + + // Print a table header consisting of \p n columns. + void header(); + + // Print table rows. + void row(int count, ...); + + int getWidth() const { return width; } +}; + +} // namespace villas diff --git a/common/include/villas/task.hpp b/common/include/villas/task.hpp new file mode 100644 index 000000000..bf88a0c3a --- /dev/null +++ b/common/include/villas/task.hpp @@ -0,0 +1,72 @@ +/* Run tasks periodically. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include + +// We can choose between two periodic task implementations +//#define PERIODIC_TASK_IMPL NANOSLEEP +#define TIMERFD 1 +#define CLOCK_NANOSLEEP 2 +#define NANOSLEEP 3 +#define RDTSC 4 + +#if defined(__MACH__) +#define PERIODIC_TASK_IMPL NANOSLEEP +#elif defined(__linux__) +#define PERIODIC_TASK_IMPL TIMERFD +#else +#error "Platform not supported" +#endif + +#if PERIODIC_TASK_IMPL == RDTSC +#include +#endif + +struct Task { + int clock; // CLOCK_{MONOTONIC,REALTIME} + +#if PERIODIC_TASK_IMPL == RDTSC // We use cycle counts in RDTSC mode + uint64_t period; + uint64_t next; +#else + struct timespec period; // The period of periodic invations of this task + struct timespec next; // The timer value for the next invocation +#endif + +#if PERIODIC_TASK_IMPL == TIMERFD + int fd; // The timerfd_create(2) file descriptior. +#elif PERIODIC_TASK_IMPL == RDTSC + struct Tsc tsc; // Initialized by tsc_init(). +#endif + + // Create a new task with the given rate. + Task(int clock = CLOCK_REALTIME); + + ~Task(); + + // Wait until task elapsed + // + // @retval 0 An error occured. Maybe the task was stopped. + // @retval >0 The nummer of runs this task already fired. + uint64_t wait(); + + void setNext(const struct timespec *next); + void setTimeout(double to); + void setRate(double rate); + + void stop(); + + // Returns a poll'able file descriptor which becomes readable when the timer expires. + // + // Note: currently not supported on all platforms. + int getFD() const; +}; diff --git a/common/include/villas/terminal.hpp b/common/include/villas/terminal.hpp new file mode 100644 index 000000000..a564a459e --- /dev/null +++ b/common/include/villas/terminal.hpp @@ -0,0 +1,47 @@ +/* Terminal handling. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include + +namespace villas { + +class Terminal { + +protected: + struct winsize window; // Size of the terminal window. + + bool isTty; + + static class Terminal *current; + +public: + Terminal(); + + // Signal handler for TIOCGWINSZ + static void resize(int signal, siginfo_t *sinfo, void *ctx); + + static int getCols() { + if (!current) + current = new Terminal(); + + return current->window.ws_col; + } + + static int getRows() { + if (!current) + current = new Terminal(); + + return current->window.ws_row; + } +}; + +} // namespace villas diff --git a/common/include/villas/timing.hpp b/common/include/villas/timing.hpp new file mode 100644 index 000000000..36f8ab8c4 --- /dev/null +++ b/common/include/villas/timing.hpp @@ -0,0 +1,36 @@ +/* Time related functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include + +// Compare two timestamps. Return zero if they are equal. +ssize_t time_cmp(const struct timespec *a, const struct timespec *b); + +// Get delta between two timespec structs. +struct timespec time_diff(const struct timespec *start, + const struct timespec *end); + +// Get sum of two timespec structs. +struct timespec time_add(const struct timespec *start, + const struct timespec *end); + +// Return current time as a struct timespec. +struct timespec time_now(); + +// Return the diffrence off two timestamps as double value in seconds. +double time_delta(const struct timespec *start, const struct timespec *end); + +// Convert timespec to double value representing seconds. +double time_to_double(const struct timespec *ts); + +// Convert double containing seconds after 1970 to timespec. +struct timespec time_from_double(double secs); diff --git a/common/include/villas/tool.hpp b/common/include/villas/tool.hpp new file mode 100644 index 000000000..bbe4b72c4 --- /dev/null +++ b/common/include/villas/tool.hpp @@ -0,0 +1,53 @@ +/* Common entry point for all villas command line tools. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace villas { + +class Tool { + +protected: + Logger logger; + + int argc; + char **argv; + + std::string name; + + static Tool *current_tool; + + static void staticHandler(int signal, siginfo_t *sinfo, void *ctx); + + virtual void handler(int, siginfo_t *, void *) {} + + std::list handlerSignals; + + static void printCopyright(); + + static void printVersion(); + +public: + Tool(int ac, char *av[], const std::string &name, + const std::list &sigs = {}); + + virtual int main() { return 0; } + + virtual void usage() {} + + virtual void parse() {} + + virtual int run(); +}; + +} // namespace villas diff --git a/common/include/villas/tsc.hpp b/common/include/villas/tsc.hpp new file mode 100644 index 000000000..ca8c1bf26 --- /dev/null +++ b/common/include/villas/tsc.hpp @@ -0,0 +1,41 @@ +/* Measure time and sleep with IA-32 time-stamp counter. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#if !(__x86_64__ || __i386__) +#error this header is for x86 only +#endif + +#include +#include +#include + +#include + +#ifndef bit_TSC +#define bit_TSC (1 << 4) +#endif + +#define bit_TSC_INVARIANT (1 << 8) +#define bit_RDTSCP (1 << 27) + +struct Tsc { + uint64_t frequency; + + bool rdtscp_supported; + bool is_invariant; +}; + +__attribute__((unused)) static uint64_t tsc_now(struct Tsc *t) { + uint32_t tsc_aux; + return t->rdtscp_supported ? __rdtscp(&tsc_aux) : __rdtsc(); +} + +int tsc_init(struct Tsc *t) __attribute__((warn_unused_result)); + +uint64_t tsc_rate_to_cycles(struct Tsc *t, double rate); diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp new file mode 100644 index 000000000..a65fb6cba --- /dev/null +++ b/common/include/villas/utils.hpp @@ -0,0 +1,223 @@ +/* Utilities. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#ifdef __GNUC__ +#define LIKELY(x) __builtin_expect((x), 1) +#define UNLIKELY(x) __builtin_expect((x), 0) +#else +#define LIKELY(x) (x) +#define UNLIKELY(x) (x) +#endif + +// Check assertion and exit if failed. +#ifndef assert +#define assert(exp) \ + do { \ + if (!EXPECT(exp, 0)) \ + error("Assertion failed: '%s' in %s(), %s:%d", XSTR(exp), __FUNCTION__, \ + __BASE_FILE__, __LINE__); \ + } while (0) +#endif + +// CPP stringification +#define XSTR(x) STR(x) +#define STR(x) #x + +#define CONCAT_DETAIL(x, y) x##y +#define CONCAT(x, y) CONCAT_DETAIL(x, y) +#define UNIQUE(x) CONCAT(x, __COUNTER__) + +#ifdef ALIGN +#undef ALIGN +#endif +#define ALIGN(x, a) ALIGN_MASK(x, (uintptr_t)(a) - 1) +#define ALIGN_MASK(x, m) (((uintptr_t)(x) + (m)) & ~(m)) +#define IS_ALIGNED(x, a) (ALIGN(x, a) == (uintptr_t)x) + +#define SWAP(x, y) \ + do { \ + auto t = x; \ + x = y; \ + y = t; \ + } while (0) + +// Round-up integer division +#define CEIL(x, y) (((x) + (y) - 1) / (y)) + +// Get nearest up-rounded power of 2 +#define LOG2_CEIL(x) (1 << (villas::utils::log2i((x) - 1) + 1)) + +// Check if the number is a power of 2 +#define IS_POW2(x) (((x) != 0) && !((x) & ((x) - 1))) + +// Calculate the number of elements in an array. +#define ARRAY_LEN(a) (sizeof(a) / sizeof(a)[0]) + +// Return the bigger value +#ifdef MAX +#undef MAX +#endif +#define MAX(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a > _b ? _a : _b; \ + }) + +// Return the smaller value +#ifdef MIN +#undef MIN +#endif +#define MIN(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) +#define MIN3(a, b, c) MIN(MIN((a), (b)), (c)) + +#ifndef offsetof +#define offsetof(type, member) __builtin_offsetof(type, member) +#endif + +#ifndef container_of +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); \ + }) +#endif + +#define BITS_PER_LONGLONG (sizeof(long long) * 8) + +// Some helper macros +#define BITMASK(h, l) \ + (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONGLONG - 1 - (h)))) +#define BIT(nr) (1UL << (nr)) + +namespace villas { +namespace utils { + +std::vector tokenize(std::string s, const std::string &delimiter); + +template void assertExcept(bool condition, const T &exception) { + if (not condition) + throw exception; +} + +// Register a exit callback for program termination: SIGINT, SIGKILL & SIGALRM. +int signalsInit(void (*cb)(int signal, siginfo_t *sinfo, void *ctx), + std::list cbSignals = {}, + std::list ignoreSignals = {SIGCHLD}) + __attribute__((warn_unused_result)); + +// Fill buffer with random data. +ssize_t readRandom(char *buf, size_t len); + +// Remove ANSI control sequences for colored output. +char *decolor(char *str); + +// Normal random variate generator using the Box-Muller method +// +// @param m Mean +// @param s Standard deviation +// @return Normal variate random variable (Gaussian) +double boxMuller(float m, float s); + +// Double precission uniform random variable +double randf(); + +// Concat formatted string to an existing string. +// +// This function uses realloc() to resize the destination. +// Please make sure to only on dynamic allocated destionations!!! +// +// @param dest A pointer to a malloc() allocated memory region +// @param fmt A format string like for printf() +// @param ... Optional parameters like for printf() +// @retval The the new value of the dest buffer. +char *strcatf(char **dest, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); + +// Variadic version of strcatf() +char *vstrcatf(char **dest, const char *fmt, va_list va) + __attribute__((format(printf, 2, 0))); + +char *strf(const char *fmt, ...); +char *vstrf(const char *fmt, va_list va); + +// Allocate and copy memory. +void *memdup(const void *src, size_t bytes); + +// Call quit() in the main thread. +void die(); + +// Get log2 of long long integers +int log2i(long long x); + +// Send signal \p sig to main thread. +void killme(int sig); + +pid_t spawn(const char *name, char *const argv[]); + +// Determines the string length as printed on the screen (ignores escable sequences). +size_t strlenp(const char *str); + +// Calculate SHA1 hash of complete file \p f and place it into \p sha1. +// +// @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size. +// @retval 0 Everything was okay. +int sha1sum(FILE *f, unsigned char *sha1); + +// Check if process is running inside a Docker container. +bool isDocker(); + +// Check if process is running inside a Kubernetes container. +bool isKubernetes(); + +// Check if process is running inside a containerized environment. +bool isContainer(); + +// Check if the process is running in a privileged environment (has SYS_ADMIN capability). +bool isPrivileged(); + +// helper type for std::visit +template struct overloaded : Ts... { + using Ts::operator()...; +}; + +// explicit deduction guide (not needed as of C++20) +template overloaded(Ts...) -> overloaded; + +namespace base64 { + +using byte = std::uint8_t; + +std::string encode(const std::vector &input); +std::vector decode(const std::string &input); + +} // namespace base64 +} // namespace utils +} // namespace villas diff --git a/common/include/villas/uuid.hpp b/common/include/villas/uuid.hpp new file mode 100644 index 000000000..660ccf79d --- /dev/null +++ b/common/include/villas/uuid.hpp @@ -0,0 +1,37 @@ +/* UUID helpers. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include + +typedef char uuid_string_t[37]; + +namespace villas { +namespace uuid { + +// Convert a UUID to C++ string +std::string toString(const uuid_t in); + +// Generate an UUID by MD5 hashing the provided string +int generateFromString(uuid_t out, const std::string &data, + const std::string &ns = ""); + +// Generate an UUID by MD5 hashing the provided string +int generateFromString(uuid_t out, const std::string &data, const uuid_t ns); + +// Generate an UUID by MD5 hashing the serialized representation of the provided JSON object +void generateFromJson(uuid_t out, json_t *json, const std::string &ns = ""); + +// Generate an UUID by MD5 hashing the serialized representation of the provided JSON object +int generateFromJson(uuid_t out, json_t *json, const uuid_t ns); + +} // namespace uuid +} // namespace villas diff --git a/common/include/villas/version.hpp b/common/include/villas/version.hpp new file mode 100644 index 000000000..fc4d6c03d --- /dev/null +++ b/common/include/villas/version.hpp @@ -0,0 +1,42 @@ +/* Version. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace utils { + +class Version { + +protected: + int components[3]; + + static int cmp(const Version &lhs, const Version &rhs); + +public: + // Parse a dotted version string. + Version(const std::string &s); + + Version(int maj, int min = 0, int pat = 0); + + inline bool operator==(const Version &rhs) { return cmp(*this, rhs) == 0; } + + inline bool operator!=(const Version &rhs) { return cmp(*this, rhs) != 0; } + + inline bool operator<(const Version &rhs) { return cmp(*this, rhs) < 0; } + + inline bool operator>(const Version &rhs) { return cmp(*this, rhs) > 0; } + + inline bool operator<=(const Version &rhs) { return cmp(*this, rhs) <= 0; } + + inline bool operator>=(const Version &rhs) { return cmp(*this, rhs) >= 0; } +}; + +} // namespace utils +} // namespace villas diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt new file mode 100644 index 000000000..116d786e6 --- /dev/null +++ b/common/lib/CMakeLists.txt @@ -0,0 +1,105 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 +# +# VILLAScommon + + +add_library(villas-common SHARED + base64.cpp + buffer.cpp + common.cpp + compat.cpp + cpuset.cpp + dsp/pid.cpp + hist.cpp + kernel/kernel.cpp + kernel/rt.cpp + list.cpp + log.cpp + memory_manager.cpp + memory.cpp + plugin.cpp + popen.cpp + table.cpp + task.cpp + terminal.cpp + timing.cpp + tool.cpp + utils.cpp + uuid.cpp + version.cpp +) + +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + target_sources(villas-common PRIVATE tsc.cpp) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL Linux) + target_sources(villas-common PRIVATE + kernel/devices/pci_device.cpp + kernel/vfio_device.cpp + kernel/vfio_group.cpp + kernel/vfio_container.cpp + ) +endif() + +target_include_directories(villas-common PUBLIC + ${OPENSSL_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR}/common/include + ${PROJECT_SOURCE_DIR}/common/include +) + +target_link_libraries(villas-common PUBLIC + PkgConfig::JANSSON + PkgConfig::UUID + ${OPENSSL_LIBRARIES} + ${CURL_LIBRARIES} + ${CMAKE_DL_LIBS} + spdlog::spdlog + fmt::fmt + stdc++ +) + +if(WITH_CONFIG) + target_link_libraries(villas-common PUBLIC + PkgConfig::LIBCONFIG + ) +endif() + +target_compile_definitions(villas-common PUBLIC + -D__STDC_FORMAT_MACROS -D_GNU_SOURCE +) + +set_target_properties(villas-common PROPERTIES + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION 1 +) + +install( + TARGETS villas-common + EXPORT VILLASCommonConfig + COMPONENT lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +install( + DIRECTORY ${CMAKE_SOURCE_DIR}/common/include/villas/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/villas + COMPONENT devel + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp" +) + +install( + DIRECTORY ${PROJECT_BINARY_DIR}/common/include/villas/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/villas + COMPONENT devel + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp" +) diff --git a/common/lib/base64.cpp b/common/lib/base64.cpp new file mode 100644 index 000000000..ac3c8536f --- /dev/null +++ b/common/lib/base64.cpp @@ -0,0 +1,121 @@ +/* Base64 encoding/decoding. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include + +namespace villas { +namespace utils { +namespace base64 { + +static const char kEncodeLookup[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char kPadCharacter = '='; + +std::string encode(const std::vector &input) { + std::string encoded; + encoded.reserve(((input.size() / 3) + (input.size() % 3 > 0)) * 4); + + std::uint32_t temp{}; + auto it = input.begin(); + + for (std::size_t i = 0; i < input.size() / 3; ++i) { + temp = (*it++) << 16; + temp += (*it++) << 8; + temp += (*it++); + encoded.append(1, kEncodeLookup[(temp & 0x00FC0000) >> 18]); + encoded.append(1, kEncodeLookup[(temp & 0x0003F000) >> 12]); + encoded.append(1, kEncodeLookup[(temp & 0x00000FC0) >> 6]); + encoded.append(1, kEncodeLookup[(temp & 0x0000003F)]); + } + + switch (input.size() % 3) { + case 1: + temp = (*it++) << 16; + encoded.append(1, kEncodeLookup[(temp & 0x00FC0000) >> 18]); + encoded.append(1, kEncodeLookup[(temp & 0x0003F000) >> 12]); + encoded.append(2, kPadCharacter); + break; + + case 2: + temp = (*it++) << 16; + temp += (*it++) << 8; + encoded.append(1, kEncodeLookup[(temp & 0x00FC0000) >> 18]); + encoded.append(1, kEncodeLookup[(temp & 0x0003F000) >> 12]); + encoded.append(1, kEncodeLookup[(temp & 0x00000FC0) >> 6]); + encoded.append(1, kPadCharacter); + break; + } + + return encoded; +} + +std::vector decode(const std::string &input) { + if (input.length() % 4) + throw std::runtime_error("Invalid base64 length!"); + + std::size_t padding{}; + + if (input.length()) { + if (input[input.length() - 1] == kPadCharacter) + padding++; + if (input[input.length() - 2] == kPadCharacter) + padding++; + } + + std::vector decoded; + decoded.reserve(((input.length() / 4) * 3) - padding); + + std::uint32_t temp{}; + auto it = input.begin(); + + while (it < input.end()) { + for (std::size_t i = 0; i < 4; ++i) { + temp <<= 6; + if (*it >= 0x41 && *it <= 0x5A) + temp |= *it - 0x41; + else if (*it >= 0x61 && *it <= 0x7A) + temp |= *it - 0x47; + else if (*it >= 0x30 && *it <= 0x39) + temp |= *it + 0x04; + else if (*it == 0x2B) + temp |= 0x3E; + else if (*it == 0x2F) + temp |= 0x3F; + else if (*it == kPadCharacter) { + switch (input.end() - it) { + case 1: + decoded.push_back((temp >> 16) & 0x000000FF); + decoded.push_back((temp >> 8) & 0x000000FF); + return decoded; + case 2: + decoded.push_back((temp >> 10) & 0x000000FF); + return decoded; + default: + throw std::runtime_error("Invalid padding in base64!"); + } + } else + throw std::runtime_error("Invalid character in base64!"); + + ++it; + } + + decoded.push_back((temp >> 16) & 0x000000FF); + decoded.push_back((temp >> 8) & 0x000000FF); + decoded.push_back((temp) & 0x000000FF); + } + + return decoded; +} + +} // namespace base64 +} // namespace utils +} // namespace villas diff --git a/common/lib/buffer.cpp b/common/lib/buffer.cpp new file mode 100644 index 000000000..eede18d4a --- /dev/null +++ b/common/lib/buffer.cpp @@ -0,0 +1,38 @@ +/* A simple buffer for encoding streamed JSON messages. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +using namespace villas; + +json_t *Buffer::decode() { + json_t *j; + json_error_t err; + + j = json_loadb(data(), size(), JSON_DISABLE_EOF_CHECK, &err); + if (!j) + return nullptr; + + // Remove decoded JSON document from beginning + erase(begin(), begin() + err.position); + + return j; +} + +int Buffer::encode(json_t *j, int flags) { + return json_dump_callback(j, callback, this, flags); +} + +int Buffer::callback(const char *data, size_t len, void *ctx) { + Buffer *b = static_cast(ctx); + + // Append junk of JSON to buffer + b->insert(b->end(), &data[0], &data[len]); + + return 0; +} diff --git a/common/lib/common.cpp b/common/lib/common.cpp new file mode 100644 index 000000000..9a15b9efa --- /dev/null +++ b/common/lib/common.cpp @@ -0,0 +1,44 @@ +/* Common code. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +std::string stateToString(enum State s) { + switch (s) { + case State::DESTROYED: + return "destroyed"; + + case State::INITIALIZED: + return "initialized"; + + case State::PARSED: + return "parsed"; + + case State::CHECKED: + return "checked"; + + case State::STARTED: + return "running"; + + case State::STOPPED: + return "stopped"; + + case State::PENDING_CONNECT: + return "pending-connect"; + + case State::CONNECTED: + return "connected"; + + case State::PAUSED: + return "paused"; + + default: + return ""; + } +} diff --git a/common/lib/compat.cpp b/common/lib/compat.cpp new file mode 100644 index 000000000..fb19b45ef --- /dev/null +++ b/common/lib/compat.cpp @@ -0,0 +1,60 @@ +/* Compatability for different library versions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +#if JANSSON_VERSION_HEX < 0x020A00 +size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags) { + char *str; + size_t len; + + str = json_dumps(json, flags); + if (!str) + return 0; + + len = strlen(str); // Not \0 terminated + if (buffer && len <= size) + memcpy(buffer, str, len); + + free(str); + + return len; +} + +static size_t json_loadfd_callback(void *buffer, size_t buflen, void *data) { + int *fd = (int *)data; + + return (size_t)read(*fd, buffer, buflen); +} + +json_t *json_loadfd(int input, size_t flags, json_error_t *error) { + return json_load_callback(json_loadfd_callback, (void *)&input, flags, error); +} + +static int json_dumpfd_callback(const char *buffer, size_t size, void *data) { +#ifdef HAVE_UNISTD_H + int *dest = (int *)data; + + if (write(*dest, buffer, size) == (ssize_t)size) + return 0; +#else + (void)buffer; + (void)size; + (void)data; +#endif // HAVE_UNISTD_H + + return -1; +} + +int json_dumpfd(const json_t *json, int output, size_t flags) { + return json_dump_callback(json, json_dumpfd_callback, (void *)&output, flags); +} +#endif // JANSSON_VERSION_HEX < 0x020A00 diff --git a/common/lib/cpuset.cpp b/common/lib/cpuset.cpp new file mode 100644 index 000000000..d781a30d2 --- /dev/null +++ b/common/lib/cpuset.cpp @@ -0,0 +1,105 @@ +/* Human readable cpusets. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +using namespace villas::utils; + +#ifdef __linux__ + +CpuSet::CpuSet(uintmax_t iset) : CpuSet() { + zero(); + + for (size_t i = 0; i < num_cpus; i++) { + if (iset & (1L << i)) + set(i); + } +} + +CpuSet::CpuSet(const std::string &str) : CpuSet() { + size_t endpos, start, end; + + for (auto token : tokenize(str, ",")) { + auto sep = token.find('-'); + + if (sep == std::string::npos) { + start = std::stoi(token, &endpos); + + if (token.begin() + endpos != token.end()) + throw std::invalid_argument("Not a valid CPU set"); + + if (start < num_cpus) + set(start); + } else { + start = std::stoi(token, &endpos); + + if (token.begin() + endpos != token.begin() + sep) + throw std::invalid_argument("Not a valid CPU set"); + + auto token2 = token.substr(endpos + 1); + + end = std::stoi(token2, &endpos); + + if (token2.begin() + endpos != token2.end()) + throw std::invalid_argument("Not a valid CPU set"); + + for (size_t i = start; i <= end && i < num_cpus; i++) + set(i); + } + } +} + +CpuSet::CpuSet(const char *str) : CpuSet(std::string(str)) {} + +CpuSet::operator uintmax_t() { + uintmax_t iset = 0; + + for (size_t i = 0; i < num_cpus; i++) { + if (isSet(i)) + iset |= 1ULL << i; + } + + return iset; +} + +CpuSet::operator std::string() { + std::stringstream ss; + + bool first = true; + + for (size_t i = 0; i < num_cpus; i++) { + if (isSet(i)) { + size_t run = 0; + for (size_t j = i + 1; j < num_cpus; j++) { + if (!isSet(j)) + break; + + run++; + } + + if (first) + first = false; + else + ss << ","; + + ss << i; + + if (run == 1) { + ss << "," << (i + 1); + i++; + } else if (run > 1) { + ss << "-" << (i + run); + i += run; + } + } + } + + return ss.str(); +} + +#endif // __linux__ diff --git a/common/lib/dsp/pid.cpp b/common/lib/dsp/pid.cpp new file mode 100644 index 000000000..5924dfcff --- /dev/null +++ b/common/lib/dsp/pid.cpp @@ -0,0 +1,48 @@ +/* A PID controller. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +using namespace std; +using namespace villas::dsp; + +PID::PID(double _dt, double _max, double _min, double _Kp, double _Kd, + double _Ki) + : dt(_dt), max(_max), min(_min), Kp(_Kp), Kd(_Kd), Ki(_Ki), pre_error(0), + integral(0) {} + +double PID::calculate(double setpoint, double pv) { + // Calculate error + double error = setpoint - pv; + + // Proportional term + double Pout = Kp * error; + + // Integral term + integral += error * dt; + double Iout = Ki * integral; + + // Derivative term + double derivative = (error - pre_error) / dt; + double Dout = Kd * derivative; + + // Calculate total output + double output = Pout + Iout + Dout; + + // Restrict to max/min + if (output > max) + output = max; + else if (output < min) + output = min; + + // Save error to previous error + pre_error = error; + + return output; +} diff --git a/common/lib/hist.cpp b/common/lib/hist.cpp new file mode 100644 index 000000000..d2ad73df9 --- /dev/null +++ b/common/lib/hist.cpp @@ -0,0 +1,231 @@ +/* Histogram class. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include +#include +#include + +using namespace villas; +using namespace villas::utils; + +namespace villas { + +Hist::Hist(int buckets, Hist::cnt_t wu) + : resolution(0), high(0), low(0), + highest(std::numeric_limits::min()), + lowest(std::numeric_limits::max()), last(0), total(0), warmup(wu), + higher(0), lower(0), data(buckets, 0), _m{0, 0}, _s{0, 0} {} + +void Hist::put(double value) { + last = value; + + // Update min/max + if (value > highest) + highest = value; + if (value < lowest) + lowest = value; + + if (data.size()) { + if (total < warmup) { + // We are still in warmup phase... Waiting for more samples... + } else if (data.size() && total == warmup && warmup != 0) { + low = getMean() - 3 * getStddev(); + high = getMean() + 3 * getStddev(); + resolution = (high - low) / data.size(); + } else if (data.size() && (total == warmup) && (warmup == 0)) { + // There is no warmup phase + // TODO resolution = ? + } else { + idx_t idx = std::round((value - low) / resolution); + + // Check bounds and increment + if (idx >= (idx_t)data.size()) + higher++; + else if (idx < 0) + lower++; + else + data[idx]++; + } + } + + total++; + + // Online / running calculation of variance and mean + // by Donald Knuth’s Art of Computer Programming, Vol 2, page 232, 3rd edition + if (total == 1) { + _m[1] = _m[0] = value; + _s[1] = 0.0; + } else { + _m[0] = _m[1] + (value - _m[1]) / total; + _s[0] = _s[1] + (value - _m[1]) * (value - _m[0]); + + // Set up for next iteration + _m[1] = _m[0]; + _s[1] = _s[0]; + } +} + +void Hist::reset() { + total = 0; + higher = 0; + lower = 0; + + highest = std::numeric_limits::min(); + lowest = std::numeric_limits::max(); + + for (auto &elm : data) + elm = 0; +} + +double Hist::getMean() const { + return total > 0 ? _m[0] : std::numeric_limits::quiet_NaN(); +} + +double Hist::getVar() const { + return total > 1 ? _s[0] / (total - 1) + : std::numeric_limits::quiet_NaN(); +} + +double Hist::getStddev() const { return sqrt(getVar()); } + +void Hist::print(Logger logger, bool details, std::string prefix) const { + if (total > 0) { + Hist::cnt_t missed = total - higher - lower; + + logger->info("{}Counted values: {} ({} between {} and {})", prefix, total, + missed, low, high); + logger->info("{}Highest: {:g}", prefix, highest); + logger->info("{}Lowest: {:g}", prefix, lowest); + logger->info("{}Mu: {:g}", prefix, getMean()); + logger->info("{}1/Mu: {:g}", prefix, 1.0 / getMean()); + logger->info("{}Variance: {:g}", prefix, getVar()); + logger->info("{}Stddev: {:g}", prefix, getStddev()); + + if (details && total - higher - lower > 0) { + char *buf = dump(); + logger->info("{}Matlab: {}", prefix, buf); + free(buf); + + plot(logger); + } + } else + logger->info("{}Counted values: {}", prefix, total); +} + +void Hist::plot(Logger logger) const { + // Get highest bar + Hist::cnt_t max = *std::max_element(data.begin(), data.end()); + + std::vector cols = { + {-9, TableColumn::Alignment::RIGHT, "Value", "%+9.3g"}, + {-6, TableColumn::Alignment::RIGHT, "Count", "%6ju"}, + {0, TableColumn::Alignment::LEFT, "Plot", "%s", "occurrences"}}; + + Table table = Table(logger, cols); + + // Print plot + table.header(); + + for (size_t i = 0; i < data.size(); i++) { + double value = low + (i)*resolution; + Hist::cnt_t cnt = data[i]; + int bar = cols[2].getWidth() * ((double)cnt / max); + + char *buf = strf("%s", ""); + for (int i = 0; i < bar; i++) + buf = strcatf(&buf, "\u2588"); + + table.row(3, value, cnt, buf); + + free(buf); + } +} + +char *Hist::dump() const { + char *buf = new char[128]; + if (!buf) + throw MemoryAllocationError(); + + memset(buf, 0, 128); + + strcatf(&buf, "[ "); + + for (auto elm : data) + strcatf(&buf, "%ju ", elm); + + strcatf(&buf, "]"); + + return buf; +} + +json_t *Hist::toJson() const { + json_t *json_buckets, *json_hist; + + json_hist = json_pack("{ s: f, s: f, s: i }", "low", low, "high", high, + "total", total); + + if (total > 0) { + json_object_update(json_hist, + json_pack("{ s: i, s: i, s: f, s: f, s: f, s: f, s: f }", + "higher", higher, "lower", lower, "highest", + highest, "lowest", lowest, "mean", getMean(), + "variance", getVar(), "stddev", getStddev())); + } + + if (total - lower - higher > 0) { + json_buckets = json_array(); + + for (auto elm : data) + json_array_append(json_buckets, json_integer(elm)); + + json_object_set(json_hist, "buckets", json_buckets); + } + + return json_hist; +} + +int Hist::dumpJson(FILE *f) const { + json_t *j = Hist::toJson(); + + int ret = json_dumpf(j, f, 0); + + json_decref(j); + + return ret; +} + +int Hist::dumpMatlab(FILE *f) const { + fprintf(f, "struct("); + fprintf(f, "'low', %f, ", low); + fprintf(f, "'high', %f, ", high); + fprintf(f, "'total', %ju, ", total); + fprintf(f, "'higher', %ju, ", higher); + fprintf(f, "'lower', %ju, ", lower); + fprintf(f, "'highest', %f, ", highest); + fprintf(f, "'lowest', %f, ", lowest); + fprintf(f, "'mean', %f, ", getMean()); + fprintf(f, "'variance', %f, ", getVar()); + fprintf(f, "'stddev', %f, ", getStddev()); + + if (total - lower - higher > 0) { + char *buf = dump(); + fprintf(f, "'buckets', %s", buf); + free(buf); + } else + fprintf(f, "'buckets', zeros(1, %zu)", data.size()); + + fprintf(f, ")"); + + return 0; +} + +} // namespace villas diff --git a/common/lib/kernel/devices/pci_device.cpp b/common/lib/kernel/devices/pci_device.cpp new file mode 100644 index 000000000..ef8a8b5d0 --- /dev/null +++ b/common/lib/kernel/devices/pci_device.cpp @@ -0,0 +1,459 @@ +/* Linux PCI helpers. + * + * Author: Steffen Vogel + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace villas::kernel::devices; + +#define PCI_BASE_ADDRESS_N(n) (PCI_BASE_ADDRESS_0 + sizeof(uint32_t) * (n)) + +PciDeviceList *PciDeviceList::instance = nullptr; + +PciDeviceList *PciDeviceList::getInstance() { + if (instance == nullptr) { + instance = new PciDeviceList(); + } + return instance; +}; + +PciDeviceList::PciDeviceList() { + struct dirent *e; + DIR *dp; + FILE *f; + char path[PATH_MAX]; + int ret; + + snprintf(path, sizeof(path), "%s/bus/pci/devices", SYSFS_PATH); + + dp = opendir(path); + if (!dp) + throw SystemError("Failed to detect PCI devices"); + + while ((e = readdir(dp))) { + // Ignore special entries + if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) + continue; + + Id id; + Slot slot; + + struct { + const char *s; + unsigned int *p; + } map[] = {{"vendor", &id.vendor}, {"device", &id.device}}; + + // Read vendor & device id + for (int i = 0; i < 2; i++) { + snprintf(path, sizeof(path), "%s/bus/pci/devices/%s/%s", SYSFS_PATH, + e->d_name, map[i].s); + + f = fopen(path, "r"); + if (!f) + throw SystemError("Failed to open '{}'", path); + + ret = fscanf(f, "%x", map[i].p); + if (ret != 1) + throw RuntimeError("Failed to parse {} ID from: {}", map[i].s, path); + + fclose(f); + } + + // Get slot id + ret = sscanf(e->d_name, "%4x:%2x:%2x.%u", &slot.domain, &slot.bus, + &slot.device, &slot.function); + if (ret != 4) + throw RuntimeError("Failed to parse PCI slot number: {}", e->d_name); + + emplace_back(std::make_shared(id, slot)); + } + + closedir(dp); +} + +PciDeviceList::value_type PciDeviceList::lookupDevice(const Slot &s) { + return *std::find_if(begin(), end(), [s](const PciDeviceList::value_type &d) { + return d->slot == s; + }); +} + +PciDeviceList::value_type PciDeviceList::lookupDevice(const Id &i) { + return *std::find_if(begin(), end(), [i](const PciDeviceList::value_type &d) { + return d->id == i; + }); +} + +PciDeviceList::value_type PciDeviceList::lookupDevice(const PciDevice &d) { + auto dev = + std::find_if(begin(), end(), + [d](const PciDeviceList::value_type &e) { return *e == d; }); + + return dev == end() ? value_type() : *dev; +} + +Id::Id(const std::string &str) : vendor(0), device(0), class_code(0) { + char *s, *c, *e; + char *tmp = strdup(str.c_str()); + + if (!*tmp) + return; + + s = strchr(tmp, ':'); + if (!s) { + free(tmp); + throw RuntimeError("Failed to parse PCI id: ':' expected", str); + } + + *s++ = 0; + if (tmp[0] && strcmp(tmp, "*")) { + long int x = strtol(tmp, &e, 16); + + if ((e && *e) || (x < 0 || x > 0xffff)) { + free(tmp); + throw RuntimeError("Failed to parse PCI id: {}: Invalid vendor id", str); + } + + vendor = x; + } + + c = strchr(s, ':'); + if (c) + *c++ = 0; + + if (s[0] && strcmp(s, "*")) { + long int x = strtol(s, &e, 16); + if ((e && *e) || (x < 0 || x > 0xffff)) { + free(tmp); + throw RuntimeError("Failed to parse PCI id: {}: Invalid device id", str); + } + + device = x; + } + + if (c && c[0] && strcmp(s, "*")) { + long int x = strtol(c, &e, 16); + + if ((e && *e) || (x < 0 || x > 0xffff)) { + free(tmp); + throw RuntimeError("Failed to parse PCI id: {}: Invalid class code", str); + } + + class_code = x; + } + free(tmp); +} + +bool Id::operator==(const Id &i) { + if ((i.device != 0 && i.device != device) || + (i.vendor != 0 && i.vendor != vendor)) + return false; + + if ((i.class_code != 0) || (i.class_code != class_code)) + return false; + + return true; +} + +Slot::Slot(const std::string &str) : domain(0), bus(0), device(0), function(0) { + char *tmp = strdup(str.c_str()); + char *colon = strrchr(tmp, ':'); + char *dot = strchr((colon ? colon + 1 : tmp), '.'); + char *mid = tmp; + char *e, *buss, *colon2; + + if (colon) { + *colon++ = 0; + mid = colon; + + colon2 = strchr(tmp, ':'); + if (colon2) { + *colon2++ = 0; + buss = colon2; + + if (tmp[0] && strcmp(tmp, "*")) { + long int x = strtol(tmp, &e, 16); + if ((e && *e) || (x < 0 || x > 0x7fffffff)) { + free(tmp); + throw RuntimeError("Failed to parse PCI slot: {}: invalid domain", + str); + } + + domain = x; + } + } else + buss = tmp; + + if (buss[0] && strcmp(buss, "*")) { + long int x = strtol(buss, &e, 16); + if ((e && *e) || (x < 0 || x > 0xff)) { + free(tmp); + throw RuntimeError("Failed to parse PCI slot: {}: invalid bus", str); + } + + bus = x; + } + } + + if (dot) + *dot++ = 0; + + if (mid[0] && strcmp(mid, "*")) { + long int x = strtol(mid, &e, 16); + + if ((e && *e) || (x < 0 || x > 0x1f)) { + free(tmp); + throw RuntimeError("Failed to parse PCI slot: {}: invalid slot", str); + } + + device = x; + } + + if (dot && dot[0] && strcmp(dot, "*")) { + long int x = strtol(dot, &e, 16); + + if ((e && *e) || (x < 0 || x > 7)) { + free(tmp); + throw RuntimeError("Failed to parse PCI slot: {}: invalid function", str); + } + + function = x; + } + + free(tmp); +} + +bool Slot::operator==(const Slot &s) { + if ((s.domain != 0 && s.domain != domain) || (s.bus != 0 && s.bus != bus) || + (s.device != 0 && s.device != device) || + (s.function != 0 && s.function != function)) + return false; + + return true; +} + +bool PciDevice::operator==(const PciDevice &f) { + return id == f.id && slot == f.slot; +} + +std::list PciDevice::getRegions() const { + FILE *f; + char sysfs[1024]; + + snprintf(sysfs, sizeof(sysfs), + "%s/bus/pci/devices/%04x:%02x:%02x.%x/resource", SYSFS_PATH, + slot.domain, slot.bus, slot.device, slot.function); + + f = fopen(sysfs, "r"); + if (!f) + throw SystemError("Failed to open resource mapping {}", sysfs); + + std::list regions; + + ssize_t bytesRead; + char *line = nullptr; + size_t len = 0; + + int reg_num = 0; + + // Cap to 8 regions, just because we don't know how many may exist. + while (reg_num < 8 && (bytesRead = getline(&line, &len, f)) != -1) { + unsigned long long tokens[3]; + char *s = line; + for (int i = 0; i < 3; i++) { + char *end; + tokens[i] = strtoull(s, &end, 16); + if (s == end) { + log->debug("Error parsing line {} of {}", reg_num + 1, sysfs); + tokens[0] = tokens[1] = 0; // Mark invalid + break; + } + s = end; + } + + free(line); + + // Required for getline() to allocate a new buffer on the next iteration. + line = nullptr; + len = 0; + + if (tokens[0] != tokens[1]) { // This is a valid region + Region region; + + region.num = reg_num; + region.start = tokens[0]; + region.end = tokens[1]; + region.flags = tokens[2]; + + regions.push_back(region); + } + + reg_num++; + } + + fclose(f); + + return regions; +} + +std::string PciDevice::getDriver() const { + int ret; + char sysfs[1024], syml[1024]; + memset(syml, 0, sizeof(syml)); + + snprintf(sysfs, sizeof(sysfs), "%s/bus/pci/devices/%04x:%02x:%02x.%x/driver", + SYSFS_PATH, slot.domain, slot.bus, slot.device, slot.function); + + struct stat st; + ret = stat(sysfs, &st); + if (ret) + return ""; + + ret = readlink(sysfs, syml, sizeof(syml)); + if (ret < 0) + throw SystemError("Failed to follow link: {}", sysfs); + + return basename(syml); +} + +bool PciDevice::attachDriver(const std::string &driver) const { + FILE *f; + char fn[1024]; + + // Add new ID to driver + snprintf(fn, sizeof(fn), "%s/bus/pci/drivers/%s/new_id", SYSFS_PATH, + driver.c_str()); + f = fopen(fn, "w"); + if (!f) + throw SystemError("Failed to add PCI id to {} driver ({})", driver, fn); + + log->info("Adding ID to {} module: {:04x} {:04x}", driver, id.vendor, + id.device); + fprintf(f, "%04x %04x", id.vendor, id.device); + fclose(f); + + // Bind to driver + snprintf(fn, sizeof(fn), "%s/bus/pci/drivers/%s/bind", SYSFS_PATH, + driver.c_str()); + f = fopen(fn, "w"); + if (!f) + throw SystemError("Failed to bind PCI device to {} driver ({})", driver, + fn); + + log->info("Bind device to {} driver", driver); + fprintf(f, "%04x:%02x:%02x.%x\n", slot.domain, slot.bus, slot.device, + slot.function); + fclose(f); + + return true; +} + +uint32_t PciDevice::readHostBar(unsigned barNum) const { + auto file = openSysFs("resource", std::ios_base::in); + + std::string line; + + unsigned i; + for (i = 0; i <= barNum && !file.eof(); i++) + std::getline(file, line); + + if (i != barNum && file.eof()) + throw RuntimeError("Failed to read resource file"); + + unsigned long long start, end, flags; + if (std::sscanf(line.c_str(), "%llx %llx %llx", &start, &end, &flags) != 3) + throw SystemError("Failed to parse BAR line"); + + if (end <= start) { + throw SystemError("Invalid BAR: start={}, end={}", start, end); + } + + log->debug("Host BAR: start={:#x}, end={:#x}, size={:#x}, flags={:#x}", start, + end, end - start + 1, flags); + + return start; +} + +void PciDevice::rewriteBar(unsigned barNum) { + auto hostBar = readHostBar(barNum); + auto configBar = readBar(barNum); + + log->debug("Host BAR: {:#x}, configbar: {:#x}", hostBar, configBar); + + if (hostBar == configBar) { + log->debug("BAR is already correct"); + return; + } + + log->debug("BAR is incorrect, rewriting"); + + writeBar(hostBar, barNum); +} + +uint32_t PciDevice::readBar(unsigned barNum) const { + uint32_t addr; + auto file = openSysFs("config", std::ios_base::in); + + file.seekg(PCI_BASE_ADDRESS_N(barNum)); + file.read(reinterpret_cast(&addr), sizeof(addr)); + + return addr; +} + +void PciDevice::writeBar(uint32_t addr, unsigned barNum) { + auto file = openSysFs("config", std::ios_base::out); + + file.seekp(PCI_BASE_ADDRESS_N(barNum)); + file.write(reinterpret_cast(&addr), sizeof(addr)); +} + +int PciDevice::getIommuGroup() const { + int ret; + char *group; + + // readlink() does not add a null terminator! + char link[1024] = {0}; + char sysfs[1024]; + + snprintf(sysfs, sizeof(sysfs), + "%s/bus/pci/devices/%04x:%02x:%02x.%x/iommu_group", SYSFS_PATH, + slot.domain, slot.bus, slot.device, slot.function); + + ret = readlink(sysfs, link, sizeof(link)); + if (ret < 0) + return -1; + + group = basename(link); + + return atoi(group); +} + +std::fstream PciDevice::openSysFs(const std::string &subPath, + std::ios_base::openmode mode) const { + std::fstream file; + + auto sysFsFilename = + fmt::format("{}/bus/pci/devices/{:04x}:{:02x}:{:02x}.{:x}/{}", SYSFS_PATH, + slot.domain, slot.bus, slot.device, slot.function, subPath); + + file.exceptions(std::ifstream::failbit | std::ifstream::badbit); + file.open(sysFsFilename, mode); + + return file; +} diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp new file mode 100644 index 000000000..902b67130 --- /dev/null +++ b/common/lib/kernel/kernel.cpp @@ -0,0 +1,333 @@ +/* Linux kernel related functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace villas; +using namespace villas::utils; + +Version villas::kernel::getVersion() { + struct utsname uts; + + if (uname(&uts) < 0) + throw SystemError("Failed to retrieve system identification"); + + std::string rel = uts.release; + + // Remove release part. E.g. 4.9.93-linuxkit-aufs + auto sep = rel.find('-'); + auto ver = rel.substr(0, sep - 1); + + return Version(ver); +} + +int villas::kernel::getCachelineSize() { +#if defined(__linux__) && defined(__x86_64__) && defined(__GLIBC__) + return sysconf(_SC_LEVEL1_ICACHE_LINESIZE); +#elif defined(__MACH__) + // Open the command for reading. + FILE *fp = popen("sysctl -n machdep.cpu.cache.linesize", "r"); + if (fp == nullptr) + return -1; + + int ret, size; + + ret = fscanf(fp, "%d", &size); + + pclose(fp); + + return ret == 1 ? size : -1; +#else + return CACHELINE_SIZE; +#endif +} + +#if defined(__linux__) +int villas::kernel::getPageSize() { return sysconf(_SC_PAGESIZE); } +#else +#error "Unsupported platform" +#endif + +// There is no sysconf interface to get the hugepage size +int villas::kernel::getHugePageSize() { +#ifdef __linux__ + char *key, *value, *unit, *line = nullptr, *lasts; + int sz = -1; + size_t len = 0; + FILE *f; + + f = fopen(PROCFS_PATH "/meminfo", "r"); + if (!f) + return -1; + + while (getline(&line, &len, f) != -1) { + key = strtok_r(line, ": ", &lasts); + value = strtok_r(nullptr, " ", &lasts); + unit = strtok_r(nullptr, "\n", &lasts); + + if (!strcmp(key, "Hugepagesize") && !strcmp(unit, "kB")) { + sz = strtoul(value, nullptr, 10) * 1024; + break; + } + } + + free(line); + fclose(f); + + return sz; +#elif defined(__x86_64__) + return 1 << 21; +#elif defined(__i386__) + return 1 << 22; +#else +#error "Unsupported architecture" +#endif +} + +#ifdef __linux__ + +int villas::kernel::setModuleParam(const char *module, const char *param, + const char *value) { + FILE *f; + char fn[256]; + + snprintf(fn, sizeof(fn), "%s/module/%s/parameters/%s", SYSFS_PATH, module, + param); + f = fopen(fn, "w"); + if (!f) + throw RuntimeError("Failed set parameter {} for kernel module {} to {}", + module, param, value); + + auto logger = Log::get("kernel"); + logger->debug("Set parameter {} of kernel module {} to {}", module, param, + value); + + fprintf(f, "%s", value); + fclose(f); + + return 0; +} + +int villas::kernel::loadModule(const char *module) { + int ret; + + ret = isModuleLoaded(module); + if (!ret) { + auto logger = Log::get("kernel"); + logger->debug("Kernel module {} already loaded...", module); + return 0; + } + + pid_t pid = fork(); + switch (pid) { + case -1: // Error + return -1; + + case 0: // Child + execlp("modprobe", "modprobe", module, (char *)0); + exit(EXIT_FAILURE); // exec() never returns + + default: + wait(&ret); + + return isModuleLoaded(module); + } +} + +int villas::kernel::isModuleLoaded(const char *module) { + FILE *f; + int ret = -1; + char *line = nullptr; + size_t len = 0; + + f = fopen(PROCFS_PATH "/modules", "r"); + if (!f) + return -1; + + while (getline(&line, &len, f) >= 0) { + if (strstr(line, module) == line) { + ret = 0; + break; + } + } + + free(line); + fclose(f); + + return ret; +} + +int villas::kernel::getCmdlineParam(const char *param, char *buf, size_t len) { + int ret; + char cmdline[512], key[128], value[128], *lasts, *tok; + + FILE *f = fopen(PROCFS_PATH "/cmdline", "r"); + if (!f) + return -1; + + if (!fgets(cmdline, sizeof(cmdline), f)) + goto out; + + tok = strtok_r(cmdline, " \t", &lasts); + do { + ret = sscanf(tok, "%127[^=]=%127s", key, value); + if (ret >= 1) { + auto logger = Log::get("kernel"); + if (ret >= 2) + logger->debug("Found kernel param: {}={}", key, value); + else + logger->debug("Found kernel param: {}", key); + + if (strcmp(param, key) == 0) { + if (ret >= 2 && buf) + snprintf(buf, len, "%s", value); + + return 0; // Found + } + } + } while ((tok = strtok_r(nullptr, " \t", &lasts))); + +out: + fclose(f); + + return -1; // Not found or error +} + +int villas::kernel::getNrHugepages() { + FILE *f; + int nr, ret; + + f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "r"); + if (!f) { + auto logger = Log::get("kernel"); + logger->error("Failed to open {}: {}", PROCFS_PATH "/sys/vm/nr_hugepages", + strerror(errno)); + return -1; + } + + ret = fscanf(f, "%d", &nr); + if (ret != 1) + nr = -1; + + fclose(f); + + return nr; +} + +int villas::kernel::setNrHugepages(int nr) { + FILE *f; + + f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "w"); + if (!f) + return -1; + + fprintf(f, "%d\n", nr); + fclose(f); + + return 0; +} + +int villas::kernel::setIRQAffinity(unsigned irq, uintmax_t aff, + uintmax_t *old) { + char fn[64]; + FILE *f; + int ret = 0; + + snprintf(fn, sizeof(fn), "/proc/irq/%u/smp_affinity", irq); + + f = fopen(fn, "w+"); + if (!f) + return -1; // IRQ does not exist + + if (old) + ret = fscanf(f, "%jx", old); + + fprintf(f, "%jx", aff); + fclose(f); + + return ret; +} + +int villas::kernel::get_cpu_frequency(uint64_t *freq) { + char *line = nullptr, *sep, *end; + size_t len = 0; + double dfreq; + int ret; + FILE *f; + + // Try to get CPU frequency from cpufreq module + f = fopen(SYSFS_PATH "/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", + "r"); + if (!f) + goto cpuinfo; + + ret = fscanf(f, "%" PRIu64, freq); + fclose(f); + if (ret != 1) + return -1; + + // cpufreq reports kHz + *freq = *freq * 1000; + + return 0; + +cpuinfo: + // Try to read CPU frequency from /proc/cpuinfo + f = fopen(PROCFS_PATH "/cpuinfo", "r"); + if (!f) + return -1; // We give up here + + ret = -1; + while (getline(&line, &len, f) >= 0) { + if (strstr(line, "cpu MHz") == line) { + ret = 0; + break; + } + } + if (ret) + goto out; + + sep = strchr(line, ':'); + if (!sep) { + ret = -1; + goto out; + } + + dfreq = strtod(sep + 1, &end); + + if (end == sep + 1) { + ret = -1; + goto out; + } + + // Frequency is given in MHz + *freq = dfreq * 1e6; + +out: + fclose(f); + free(line); + + return ret; +} +#endif // __linux__ diff --git a/common/lib/kernel/rt.cpp b/common/lib/kernel/rt.cpp new file mode 100644 index 000000000..6f1ec22d8 --- /dev/null +++ b/common/lib/kernel/rt.cpp @@ -0,0 +1,139 @@ +/* Linux specific real-time optimizations. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#ifdef __linux__ +using villas::utils::CpuSet; +#endif // __linux__ + +namespace villas { +namespace kernel { +namespace rt { + +void init(int priority, int affinity) { + Logger logger = Log::get("kernel:rt"); + + logger->info("Initialize sub-system"); + +#ifdef __linux__ + int is_rt, is_isol; + char isolcpus[255]; + + // Use FIFO scheduler with real time priority + is_rt = isPreemptible(); + if (!is_rt) + logger->warn("We recommend to use an PREEMPT_RT patched kernel!"); + + if (priority) + setPriority(priority); + else + logger->warn( + "You might want to use the 'priority' setting to increase " PROJECT_NAME + "'s process priority"); + + if (affinity) { + is_isol = getCmdlineParam("isolcpus", isolcpus, sizeof(isolcpus)); + if (is_isol) + logger->warn("You should reserve some cores for " PROJECT_NAME + " (see 'isolcpus')"); + else { + CpuSet cset_pin(affinity); + CpuSet cset_isol(isolcpus); + CpuSet cset_non_isol = ~cset_isol & cset_pin; + + if (cset_non_isol.count() > 0) + logger->warn("Affinity setting includes cores which are not isolated: " + "affinity={}, isolcpus={}, non_isolated={}", + (std::string)cset_pin, (std::string)cset_isol, + (std::string)cset_non_isol); + } + + setProcessAffinity(affinity); + } else + logger->warn( + "You might want to use the 'affinity' setting to pin " PROJECT_NAME + " to dedicate CPU cores"); +#else + logger->warn("This platform is not optimized for real-time execution"); + + (void)affinity; + (void)priority; +#endif // __linux__ +} + +#ifdef __linux__ +void setProcessAffinity(int affinity) { + int ret; + + assert(affinity != 0); + + Logger logger = Log::get("kernel:rt"); + + // Pin threads to CPUs by setting the affinity + CpuSet cset_pin(affinity); + + ret = sched_setaffinity(0, cset_pin.size(), cset_pin); + if (ret) + throw SystemError("Failed to set CPU affinity of process"); + + logger->debug("Set affinity to {} {}", + cset_pin.count() == 1 ? "core" : "cores", + (std::string)cset_pin); +} + +void setThreadAffinity(pthread_t thread, int affinity) { + int ret; + + assert(affinity != 0); + + Logger logger = Log::get("kernel:rt"); + + CpuSet cset_pin(affinity); + + ret = pthread_setaffinity_np(thread, cset_pin.size(), cset_pin); + if (ret) + throw SystemError("Failed to set CPU affinity of thread"); + + logger->debug("Set affinity of thread {} to {} {}", (long unsigned)thread, + cset_pin.count() == 1 ? "core" : "cores", + (std::string)cset_pin); +} + +void setPriority(int priority) { + int ret; + struct sched_param param; + param.sched_priority = priority; + + Logger logger = Log::get("kernel:rt"); + + ret = sched_setscheduler(0, SCHED_FIFO, ¶m); + if (ret) + throw SystemError("Failed to set real time priority"); + + logger->debug("Task priority set to {}", priority); +} + +bool isPreemptible() { + return access(SYSFS_PATH "/kernel/realtime", R_OK) == 0; +} + +#endif // __linux__ + +} // namespace rt +} // namespace kernel +} // namespace villas diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp new file mode 100644 index 000000000..76923aa08 --- /dev/null +++ b/common/lib/kernel/vfio_container.cpp @@ -0,0 +1,312 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2014-2021 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _DEFAULT_SOURCE + +#if defined(__arm__) || defined(__aarch64__) +#define _LARGEFILE64_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#endif + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace villas::kernel::vfio; + +#ifndef VFIO_NOIOMMU_IOMMU +#define VFIO_NOIOMMU_IOMMU 8 +#endif + +static std::array construct_vfio_extension_str() { + std::array ret; + ret[VFIO_TYPE1_IOMMU] = "Type 1"; + ret[VFIO_SPAPR_TCE_IOMMU] = "SPAPR TCE"; + ret[VFIO_TYPE1v2_IOMMU] = "Type 1 v2"; + ret[VFIO_DMA_CC_IOMMU] = "DMA CC"; + ret[VFIO_EEH] = "EEH"; + ret[VFIO_TYPE1_NESTING_IOMMU] = "Type 1 Nesting"; + ret[VFIO_SPAPR_TCE_v2_IOMMU] = "SPAPR TCE v2"; + ret[VFIO_NOIOMMU_IOMMU] = "No IOMMU"; +// Backwards compatability with older kernels +#ifdef VFIO_UNMAP_ALL + ret[VFIO_UNMAP_ALL] = "Unmap all"; +#endif +#ifdef VFIO_UPDATE_VADDR + ret[VFIO_UPDATE_VADDR] = "Update vaddr"; +#endif + return ret; +} + +static std::array VFIO_EXTENSION_STR = + construct_vfio_extension_str(); + +Container::Container(std::vector required_modules) + : fd(-1), version(0), extensions(), iova_next(0), hasIommu(false), groups(), + log(Log::get("kernel:vfio:container")) { + for (auto module : required_modules) { + if (kernel::loadModule(module.c_str()) != 0) { + throw RuntimeError("Kernel module '{}' required but could not be loaded. " + "Please load manually!", + module); + } + } + + // Create a VFIO Container + fd = open(VFIO_DEV, O_RDWR); + if (fd < 0) + throw RuntimeError("Failed to open VFIO container"); + + // Check VFIO API version + version = ioctl(fd, VFIO_GET_API_VERSION); + if (version < 0 || version != VFIO_API_VERSION) + throw RuntimeError("Unknown API version: {}", version); + + // Check available VFIO extensions (IOMMU types) + for (unsigned int i = VFIO_TYPE1_IOMMU; i < EXTENSION_SIZE; i++) { + int ret = ioctl(fd, VFIO_CHECK_EXTENSION, i); + + extensions[i] = ret != 0; + + log->debug("VFIO extension {} is {} ({})", i, + extensions[i] ? "available" : "not available", + VFIO_EXTENSION_STR[i]); + } + + if (extensions[VFIO_TYPE1_IOMMU]) { + log->debug("Using VFIO type {} ({})", VFIO_TYPE1_IOMMU, + VFIO_EXTENSION_STR[VFIO_TYPE1_IOMMU]); + hasIommu = true; + } else if (extensions[VFIO_NOIOMMU_IOMMU]) { + log->debug("Using VFIO type {} ({})", VFIO_NOIOMMU_IOMMU, + VFIO_EXTENSION_STR[VFIO_NOIOMMU_IOMMU]); + hasIommu = false; + } else + throw RuntimeError("No supported IOMMU type available"); + + log->debug("Version: {:#x}", version); + log->debug("IOMMU: {}", hasIommu ? "yes" : "no"); +} + +Container::~Container() { + // Release memory and close fds + groups.clear(); + + log->debug("Cleaning up container with fd {}", fd); + + // Close container + int ret = close(fd); + if (ret < 0) + log->error("Error closing vfio container fd {}: {}", fd, ret); +} + +void Container::attachGroup(std::shared_ptr group) { + if (group->isAttachedToContainer()) + throw RuntimeError("Group is already attached to a container"); + + // Claim group ownership + int ret = ioctl(group->getFileDescriptor(), VFIO_GROUP_SET_CONTAINER, &fd); + if (ret < 0) + throw SystemError("Failed to attach VFIO group {} to container fd {}", + group->getIndex(), fd); + + // Set IOMMU type + int iommu_type = isIommuEnabled() ? VFIO_TYPE1_IOMMU : VFIO_NOIOMMU_IOMMU; + + ret = ioctl(fd, VFIO_SET_IOMMU, iommu_type); + if (ret < 0) + throw SystemError("Failed to set IOMMU type of container"); + + group->setAttachedToContainer(); + + log->debug("Attached new group {} to VFIO container with fd {}", + group->getIndex(), fd); + + // Push to our list + groups.push_back(std::move(group)); +} + +std::shared_ptr Container::getOrAttachGroup(int index) { + // Search if group with index already exists + for (auto &group : groups) { + if (group->getIndex() == index) + return group; + } + + // Group not yet part of this container, so acquire ownership + auto group = std::make_shared(index, isIommuEnabled()); + attachGroup(group); + + return group; +} + +void Container::dump() { + log->info("File descriptor: {}", fd); + log->info("Version: {}", version); + + // Check available VFIO extensions (IOMMU types) + for (size_t i = 0; i < extensions.size(); i++) + log->debug("VFIO extension {} ({}) is {}", extensions[i], + VFIO_EXTENSION_STR[i], + extensions[i] ? "available" : "not available"); + + for (auto &group : groups) + group->dump(); +} + +std::shared_ptr Container::attachDevice(const std::string &name, + int index) { + auto group = getOrAttachGroup(index); + auto device = group->attachDevice(name); + + return device; +} + +std::shared_ptr Container::attachDevice(devices::PciDevice &pdev) { + int ret; + char name[32], iommu_state[4]; + static constexpr const char *kernelDriver = "vfio-pci"; + + // Load PCI bus driver for VFIO + if (kernel::loadModule("vfio_pci")) + throw RuntimeError("Failed to load kernel driver: vfio_pci"); + + // Bind PCI card to vfio-pci driver if not already bound + if (pdev.getDriver() != kernelDriver) { + log->debug("Bind PCI card to kernel driver '{}'", kernelDriver); + pdev.attachDriver(kernelDriver); + } + + try { + pdev.rewriteBar(); + } catch (std::exception &e) { + + throw RuntimeError( + e.what() + + std::string( + "\nBAR of device is in inconsistent state. Rewriting the BAR " + "failed. Please remove, rescan and reset the device and " + "try again.")); + } + + // Get IOMMU group of device + int index = isIommuEnabled() ? pdev.getIommuGroup() : 0; + if (index < 0) { + ret = kernel::getCmdlineParam("intel_iommu", iommu_state, + sizeof(iommu_state)); + if (ret != 0 || strcmp("on", iommu_state) != 0) + log->warn("Kernel booted without command line parameter " + "'intel_iommu' set to 'on'. Please check documentation " + "(https://villas.fein-aachen.org/doc/fpga-setup.html) " + "for help with troubleshooting."); + + throw RuntimeError("Failed to get IOMMU group of device"); + } + + // VFIO device name consists of PCI BDF + snprintf(name, sizeof(name), "%04x:%02x:%02x.%x", pdev.slot.domain, + pdev.slot.bus, pdev.slot.device, pdev.slot.function); + + log->info("Attach to device {} with index {}", std::string(name), index); + auto group = getOrAttachGroup(index); + auto device = group->attachDevice(name, &pdev); + + // Check if this is really a vfio-pci device + if (!device->isVfioPciDevice()) + throw RuntimeError("Device is not a vfio-pci device"); + + return device; +} + +uintptr_t Container::memoryMap(uintptr_t virt, uintptr_t phys, size_t length) { + int ret; + + if (not hasIommu) { + log->error("DMA mapping not supported without IOMMU"); + return UINTPTR_MAX; + } + + if (length & 0xFFF) { + length += 0x1000; + length &= ~0xFFF; + } + + // Super stupid allocator + size_t iovaIncrement = 0; + if (phys == UINTPTR_MAX) { + phys = this->iova_next; + iovaIncrement = length; + } + + struct vfio_iommu_type1_dma_map dmaMap; + memset(&dmaMap, 0, sizeof(dmaMap)); + + dmaMap.argsz = sizeof(dmaMap); + dmaMap.vaddr = virt; + dmaMap.iova = phys; + dmaMap.size = length; + dmaMap.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; + + ret = ioctl(this->fd, VFIO_IOMMU_MAP_DMA, &dmaMap); + if (ret) { + log->error("Failed to create DMA mapping: {}", ret); + return UINTPTR_MAX; + } + + log->debug("DMA map size={:#x}, iova={:#x}, vaddr={:#x}", dmaMap.size, + dmaMap.iova, dmaMap.vaddr); + + // Mapping successful, advance IOVA allocator + this->iova_next += iovaIncrement; + + // We intentionally don't return the actual mapped length, the users are + // only guaranteed to have their demanded memory mapped correctly + return dmaMap.iova; +} + +bool Container::memoryUnmap(uintptr_t phys, size_t length) { + int ret; + + if (not hasIommu) + return true; + + struct vfio_iommu_type1_dma_unmap dmaUnmap; + dmaUnmap.argsz = sizeof(struct vfio_iommu_type1_dma_unmap); + dmaUnmap.flags = 0; + dmaUnmap.iova = phys; + dmaUnmap.size = length; + + ret = ioctl(this->fd, VFIO_IOMMU_UNMAP_DMA, &dmaUnmap); + if (ret) { + log->error("Failed to unmap DMA mapping"); + return false; + } + log->debug("DMA unmap size={:#x}, iova={:#x}", dmaUnmap.size, dmaUnmap.iova); + + return true; +} diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp new file mode 100644 index 000000000..ff70f3cb7 --- /dev/null +++ b/common/lib/kernel/vfio_device.cpp @@ -0,0 +1,432 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Niklas Eiling + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-FileCopyrightText: 2014-2023 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _DEFAULT_SOURCE + +#if defined(__arm__) || defined(__aarch64__) +#define _LARGEFILE64_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +using namespace villas::kernel::vfio; + +static const char *vfio_pci_region_names[] = { + "PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX + "PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX + "PCI_BAR2", // VFIO_PCI_BAR2_REGION_INDEX + "PCI_BAR3", // VFIO_PCI_BAR3_REGION_INDEX + "PCI_BAR4", // VFIO_PCI_BAR4_REGION_INDEX + "PCI_BAR5", // VFIO_PCI_BAR5_REGION_INDEX + "PCI_ROM", // VFIO_PCI_ROM_REGION_INDEX + "PCI_CONFIG", // VFIO_PCI_CONFIG_REGION_INDEX + "PCI_VGA" // VFIO_PCI_INTX_IRQ_INDEX +}; + +static const char *vfio_pci_irq_names[] = { + "PCI_INTX", // VFIO_PCI_INTX_IRQ_INDEX + "PCI_MSI", // VFIO_PCI_MSI_IRQ_INDEX + "PCI_MSIX", // VFIO_PCI_MSIX_IRQ_INDEX + "PCI_ERR", // VFIO_PCI_ERR_IRQ_INDEX + "PCI_REQ" // VFIO_PCI_REQ_IRQ_INDEX +}; + +Device::Device(const std::string &name, int groupFileDescriptor, + const kernel::devices::PciDevice *pci_device) + : name(name), fd(-1), attachedToGroup(false), groupFd(groupFileDescriptor), + info(), irqs(), regions(), mappings(), pci_device(pci_device), + log(Log::get("kernel:vfio:device")) { + if (groupFileDescriptor < 0) + throw RuntimeError("Invalid group file descriptor"); + + // Open device fd + fd = ioctl(groupFileDescriptor, VFIO_GROUP_GET_DEVICE_FD, name.c_str()); + if (fd < 0) + throw RuntimeError("Failed to open VFIO device: {}", name.c_str()); + + // Get device info + info.argsz = sizeof(info); + + int ret = ioctl(fd, VFIO_DEVICE_GET_INFO, &info); + if (ret < 0) + throw RuntimeError("Failed to get VFIO device info for: {}", name); + + log->debug("device info: flags: 0x{:x}, num_regions: {}, num_irqs: {}", + info.flags, info.num_regions, info.num_irqs); + + // device_info.num_region reports always 9 and includes a VGA region, which is only supported on + // certain device IDs. So for non-VGA devices VFIO_PCI_CONFIG_REGION_INDEX will be the highest + // region index. This is the config space. + info.num_regions = pci_device != 0 ? VFIO_PCI_CONFIG_REGION_INDEX + 1 : 1; + + // Reserve slots already so that we can use the []-operator for access + irqs.resize(info.num_irqs); + regions.resize(info.num_regions); + mappings.resize(info.num_regions); + + // Get device regions + for (size_t i = 0; i < info.num_regions; i++) { + struct vfio_region_info region; + memset(®ion, 0, sizeof(region)); + + region.argsz = sizeof(region); + region.index = i; + + ret = ioctl(fd, VFIO_DEVICE_GET_REGION_INFO, ®ion); + if (ret < 0) + throw RuntimeError("Failed to get region {} of VFIO device: {}", i, name); + + log->debug("region {} info: flags: 0x{:x}, cap_offset: 0x{:x}, size: " + "0x{:x}, offset: 0x{:x}", + region.index, region.flags, region.cap_offset, region.size, + region.offset); + + regions[i] = region; + } + + // Get device IRQs + for (size_t i = 0; i < info.num_irqs; i++) { + struct vfio_irq_info irq; + memset(&irq, 0, sizeof(irq)); + + irq.argsz = sizeof(irq); + irq.index = i; + + ret = ioctl(fd, VFIO_DEVICE_GET_IRQ_INFO, &irq); + if (ret < 0) + throw RuntimeError("Failed to get IRQ {} of VFIO device: {}", i, name); + + log->debug("irq {} info: flags: 0x{:x}, count: {}", irq.index, irq.flags, + irq.count); + + irqs[i] = irq; + } +} + +Device::~Device() { + log->debug("Cleaning up device {} with fd {}", this->name, this->fd); + + for (auto ®ion : regions) { + regionUnmap(region.index); + } + if (isVfioPciDevice()) { + pciHotReset(); + } + reset(); + + int ret = close(fd); + if (ret != 0) { + log->error("Closing device fd {} failed", fd); + } +} + +bool Device::reset() { + log->debug("Resetting device."); + if (this->info.flags & VFIO_DEVICE_FLAGS_RESET) + return ioctl(this->fd, VFIO_DEVICE_RESET) == 0; + else + return false; // Not supported by this device +} + +void *Device::regionMap(size_t index) { + struct vfio_region_info *r = ®ions[index]; + + if (!(r->flags & VFIO_REGION_INFO_FLAG_MMAP)) + return MAP_FAILED; + + int flags = MAP_SHARED; + +#if !(defined(__arm__) || defined(__aarch64__)) + flags |= MAP_SHARED | MAP_32BIT; +#endif + + log->debug("Mapping region {} of size 0x{:x} with flags 0x{:x}", index, + r->size, flags); + mappings[index] = + mmap(nullptr, r->size, PROT_READ | PROT_WRITE, flags, fd, r->offset); + + return mappings[index]; +} + +bool Device::regionUnmap(size_t index) { + int ret; + struct vfio_region_info *r = ®ions[index]; + + if (!mappings[index]) + return false; // Was not mapped + + log->debug("Unmap region {} from device {}", index, name); + + ret = munmap(mappings[index], r->size); + if (ret) + return false; + + mappings[index] = nullptr; + + return true; +} + +size_t Device::regionGetSize(size_t index) { + if (index >= regions.size()) { + log->error("Index out of range: {} >= {}", index, regions.size()); + throw std::out_of_range("Index out of range"); + } + + return regions[index].size; +} + +void Device::dump() { + log->info("Device {}: regions={}, irqs={}, flags={}", name, info.num_regions, + info.num_irqs, info.flags); + + for (size_t i = 0; i < info.num_regions && i < 8; i++) { + struct vfio_region_info *region = ®ions[i]; + + if (region->size > 0) { + log->info("Region {} {}: size={}, offset={}, flags={}", region->index, + (info.flags & VFIO_DEVICE_FLAGS_PCI) ? vfio_pci_region_names[i] + : "", + region->size, region->offset, region->flags); + } + } + + for (size_t i = 0; i < info.num_irqs; i++) { + struct vfio_irq_info *irq = &irqs[i]; + + if (irq->count > 0) { + log->info("IRQ {} {}: count={}, flags={}", irq->index, + (info.flags & VFIO_DEVICE_FLAGS_PCI) ? vfio_pci_irq_names[i] + : "", + irq->count, irq->flags); + } + } +} + +bool Device::pciEnable() { + int ret; + uint32_t reg; + const off64_t offset = + PCI_COMMAND + (static_cast(VFIO_PCI_CONFIG_REGION_INDEX) << 40); + + // Check if this is really a vfio-pci device + if (!(this->info.flags & VFIO_DEVICE_FLAGS_PCI)) + return false; + + ret = pread64(this->fd, ®, sizeof(reg), offset); + if (ret != sizeof(reg)) + return false; + + // Enable memory access and PCI bus mastering which is required for DMA + reg |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; + + ret = pwrite64(this->fd, ®, sizeof(reg), offset); + if (ret != sizeof(reg)) + return false; + + return true; +} + +int Device::pciMsiInit(int efds[]) { + // Check if this is really a vfio-pci device + if (not isVfioPciDevice()) + return -1; + + const size_t irqCount = irqs[VFIO_PCI_MSI_IRQ_INDEX].count; + const size_t irqSetSize = + sizeof(struct vfio_irq_set) + sizeof(int) * irqCount; + + auto *irqSetBuf = new char[irqSetSize]; + if (!irqSetBuf) + throw MemoryAllocationError(); + + auto *irqSet = reinterpret_cast(irqSetBuf); + + irqSet->argsz = irqSetSize; + // DATA_EVENTFD binds the interrupt to the provided eventfd. + // SET_ACTION_TRIGGER enables kernel->userspace signalling. + irqSet->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER; + irqSet->index = VFIO_PCI_MSI_IRQ_INDEX; + irqSet->start = 0; + irqSet->count = irqCount; + + // Now set the new eventfds + for (size_t i = 0; i < irqCount; i++) { + efds[i] = eventfd(0, 0); + if (efds[i] < 0) { + delete[] irqSetBuf; + return -1; + } + eventfdList.push_back(efds[i]); + } + + memcpy(irqSet->data, efds, sizeof(int) * irqCount); + + if (ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) { + delete[] irqSetBuf; + return -1; + } + + delete[] irqSetBuf; + + return irqCount; +} + +int Device::pciMsiDeinit(int efds[]) { + Log::get("Device")->debug("Deinitializing MSI interrupts for device {}", + name); + // Check if this is really a vfio-pci device + if (not isVfioPciDevice()) + return -1; + + const size_t irqCount = irqs[VFIO_PCI_MSI_IRQ_INDEX].count; + const size_t irqSetSize = + sizeof(struct vfio_irq_set) + sizeof(int) * irqCount; + + auto *irqSetBuf = new char[irqSetSize]; + if (!irqSetBuf) + throw MemoryAllocationError(); + + auto *irqSet = reinterpret_cast(irqSetBuf); + + irqSet->argsz = irqSetSize; + irqSet->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER; + irqSet->index = VFIO_PCI_MSI_IRQ_INDEX; + irqSet->count = irqCount; + irqSet->start = 0; + + for (size_t i = 0; i < irqCount; i++) { + close(efds[i]); + efds[i] = -1; + } + + memcpy(irqSet->data, efds, sizeof(int) * irqCount); + + if (ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) { + delete[] irqSetBuf; + return -1; + } + + delete[] irqSetBuf; + + return irqCount; +} + +bool Device::pciMsiFind(int nos[]) { + int ret, idx, irq; + char *end, *col, *last, line[1024], name[13]; + FILE *f; + + f = fopen("/proc/interrupts", "r"); + if (!f) + return false; + + for (int i = 0; i < 32; i++) + nos[i] = -1; + + // For each line in /proc/interrupts + while (fgets(line, sizeof(line), f)) { + col = strtok(line, " "); + + // IRQ number is in first column + irq = strtol(col, &end, 10); + if (col == end) + continue; + + // Find last column of line + do { + last = col; + } while ((col = strtok(nullptr, " "))); + + ret = sscanf(last, "vfio-msi[%d](%12[0-9:])", &idx, name); + if (ret == 2) { + if (strstr(this->name.c_str(), name) == this->name.c_str()) + nos[idx] = irq; + } + } + + fclose(f); + + return true; +} + +bool Device::isVfioPciDevice() const { + return info.flags & VFIO_DEVICE_FLAGS_PCI; +} + +bool Device::pciHotReset() { + // Check if this is really a vfio-pci device + if (!isVfioPciDevice()) + return false; + + log->debug("Performing hot reset."); + const size_t reset_info_len = sizeof(struct vfio_pci_hot_reset_info) + + sizeof(struct vfio_pci_dependent_device) * 64; + + auto *reset_info_buf = new char[reset_info_len]; + if (!reset_info_buf) + throw MemoryAllocationError(); + + auto *reset_info = + reinterpret_cast(reset_info_buf); + + reset_info->argsz = reset_info_len; + + if (ioctl(fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, reset_info) != 0) { + delete[] reset_info_buf; + return false; + } + + log->debug("Dependent devices for hot-reset:"); + for (size_t i = 0; i < reset_info->count; i++) { + struct vfio_pci_dependent_device *dd = &reset_info->devices[i]; + log->debug(" {:04x}:{:02x}:{:02x}.{:01x}: iommu_group={}", dd->segment, + dd->bus, PCI_SLOT(dd->devfn), PCI_FUNC(dd->devfn), dd->group_id); + } + + delete[] reset_info_buf; + + const size_t reset_len = + sizeof(struct vfio_pci_hot_reset) + sizeof(int32_t) * 1; + auto *reset_buf = new char[reset_len]; + if (!reset_buf) + throw MemoryAllocationError(); + + auto *reset = reinterpret_cast(reset_buf); + + reset->argsz = reset_len; + reset->count = 1; + reset->group_fds[0] = groupFd; + + int ret = ioctl(fd, VFIO_DEVICE_PCI_HOT_RESET, reset); + const bool success = (ret == 0); + + delete[] reset_buf; + + if (!success) { + log->warn("PCI hot reset failed, maybe no IOMMU available?"); + return true; + } + + return success; +} diff --git a/common/lib/kernel/vfio_group.cpp b/common/lib/kernel/vfio_group.cpp new file mode 100644 index 000000000..512460c20 --- /dev/null +++ b/common/lib/kernel/vfio_group.cpp @@ -0,0 +1,125 @@ +/* Virtual Function IO wrapper around kernel API. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2014-2021 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _DEFAULT_SOURCE + +#if defined(__arm__) || defined(__aarch64__) +#define _LARGEFILE64_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#endif + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace villas::kernel::vfio; + +Group::Group(int index, bool iommuEnabled) + : fd(-1), index(index), attachedToContainer(false), status(), devices(), + log(Log::get("kernel:vfio:group")) { + // Open group fd + std::stringstream groupPath; + groupPath << VFIO_PATH << (iommuEnabled ? "" : "noiommu-") << index; + + log->debug("path: {}", groupPath.str().c_str()); + fd = open(groupPath.str().c_str(), O_RDWR); + if (fd < 0) { + log->error("Failed to open VFIO group {}", index); + throw RuntimeError("Failed to open VFIO group"); + } + + log->debug("VFIO group {} (fd {}) has path {}", index, fd, groupPath.str()); + + checkStatus(); +} + +std::shared_ptr Group::attachDevice(std::shared_ptr device) { + if (device->isAttachedToGroup()) + throw RuntimeError("Device is already attached to a group"); + + devices.push_back(device); + + device->setAttachedToGroup(); + + return device; +} + +std::shared_ptr +Group::attachDevice(const std::string &name, + const kernel::devices::PciDevice *pci_device) { + auto device = std::make_shared(name, fd, pci_device); + return attachDevice(device); +} + +bool Group::checkStatus() { + int ret; + + // Check group viability and features + status.argsz = sizeof(status); + + ret = ioctl(fd, VFIO_GROUP_GET_STATUS, &status); + if (ret < 0) { + log->error("Failed to get VFIO group status"); + return false; + } + + if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) { + log->error( + "VFIO group is not available: bind all devices to the VFIO driver!"); + return false; + } + log->debug("VFIO group is {} viable", index); + return true; +} + +void Group::dump() { + log->info("VFIO Group {}, viable={}, container={}", index, + (status.flags & VFIO_GROUP_FLAGS_VIABLE) > 0, + (status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET) > 0); + + for (auto &device : devices) { + device->dump(); + } +} + +Group::~Group() { + // Release memory and close fds + devices.clear(); + + log->debug("Cleaning up group {} with fd {}", index, fd); + + if (fd < 0) + log->debug("Destructing group that has not been attached"); + else { + log->debug("unsetting group container"); + int ret = ioctl(fd, VFIO_GROUP_UNSET_CONTAINER); + if (ret != 0) + log->error("Cannot unset container for group fd {}", fd); + + ret = close(fd); + if (ret != 0) + log->error("Cannot close group fd {}", fd); + } +} diff --git a/common/lib/list.cpp b/common/lib/list.cpp new file mode 100644 index 000000000..fbac03205 --- /dev/null +++ b/common/lib/list.cpp @@ -0,0 +1,265 @@ +/* A generic linked list. + * + * Linked lists a used for several data structures in the code. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include +#include + +using namespace villas; + +int villas::list_init(struct List *l) { + pthread_mutex_init(&l->lock, nullptr); + + l->length = 0; + l->capacity = 0; + l->array = nullptr; + l->state = State::INITIALIZED; + + return 0; +} + +int villas::list_destroy(struct List *l, dtor_cb_t destructor, bool release) { + pthread_mutex_lock(&l->lock); + + assert(l->state != State::DESTROYED); + + for (size_t i = 0; i < list_length(l); i++) { + void *e = list_at(l, i); + + if (destructor) + destructor(e); + if (release) + free(e); + } + + free(l->array); + + l->length = -1; + l->capacity = 0; + l->array = nullptr; + l->state = State::DESTROYED; + + pthread_mutex_unlock(&l->lock); + pthread_mutex_destroy(&l->lock); + + return 0; +} + +void villas::list_push(struct List *l, void *p) { + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + // Resize array if out of capacity + if (l->length >= l->capacity) { + l->capacity += LIST_CHUNKSIZE; + l->array = (void **)realloc(l->array, l->capacity * sizeof(void *)); + } + + l->array[l->length] = p; + l->length++; + + pthread_mutex_unlock(&l->lock); +} + +void villas::list_clear(struct List *l) { + pthread_mutex_lock(&l->lock); + + l->length = 0; + + pthread_mutex_unlock(&l->lock); +} + +int villas::list_remove(struct List *l, size_t idx) { + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + if (idx >= l->length) + return -1; + + for (size_t i = idx; i < l->length - 1; i++) + l->array[i] = l->array[i + 1]; + + l->length--; + + pthread_mutex_unlock(&l->lock); + + return 0; +} + +int villas::list_insert(struct List *l, size_t idx, void *p) { + size_t i; + void *t, *o; + + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + if (idx >= l->length) + return -1; + + // Resize array if out of capacity + if (l->length + 1 > l->capacity) { + l->capacity += LIST_CHUNKSIZE; + l->array = (void **)realloc(l->array, l->capacity * sizeof(void *)); + } + + o = p; + for (i = idx; i < l->length; i++) { + t = l->array[i]; + l->array[i] = o; + o = t; + } + + l->array[l->length] = o; + l->length++; + + pthread_mutex_unlock(&l->lock); + + return 0; +} + +void villas::list_remove_all(struct List *l, void *p) { + int removed = 0; + + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + for (size_t i = 0; i < list_length(l); i++) { + if (list_at(l, i) == p) + removed++; + else + l->array[i - removed] = list_at(l, i); + } + + l->length -= removed; + + pthread_mutex_unlock(&l->lock); +} + +int villas::list_contains(struct List *l, void *p) { + return list_count( + l, [](const void *a, const void *b) { return a == b ? 0 : 1; }, p); +} + +int villas::list_count(struct List *l, cmp_cb_t cmp, void *ctx) { + int c = 0; + void *e; + + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + for (size_t i = 0; i < list_length(l); i++) { + e = list_at(l, i); + if (cmp(e, ctx) == 0) + c++; + } + + pthread_mutex_unlock(&l->lock); + + return c; +} + +void *villas::list_search(struct List *l, cmp_cb_t cmp, const void *ctx) { + void *e; + + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + for (size_t i = 0; i < list_length(l); i++) { + e = list_at(l, i); + if (cmp(e, ctx) == 0) + goto out; + } + + e = nullptr; // Not found + +out: + pthread_mutex_unlock(&l->lock); + + return e; +} + +void villas::list_sort(struct List *l, cmp_cb_t cmp) { + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + auto array = std::vector(l->array, l->array + l->length); + + std::sort(array.begin(), array.end(), + [cmp](void *&a, void *&b) -> bool { return cmp(a, b) < 0; }); + + std::copy(array.begin(), array.end(), l->array); + + pthread_mutex_unlock(&l->lock); +} + +int villas::list_set(struct List *l, unsigned index, void *value) { + if (index >= l->length) + return -1; + + l->array[index] = value; + + return 0; +} + +ssize_t villas::list_index(struct List *l, void *p) { + void *e; + ssize_t f; + + pthread_mutex_lock(&l->lock); + + assert(l->state == State::INITIALIZED); + + for (size_t i = 0; i < list_length(l); i++) { + e = list_at(l, i); + if (e == p) { + f = i; + goto found; + } + } + + f = -1; + +found: + pthread_mutex_unlock(&l->lock); + + return f; +} + +void villas::list_extend(struct List *l, size_t len, void *val) { + while (list_length(l) < len) + list_push(l, val); +} + +void villas::list_filter(struct List *l, dtor_cb_t cb) { + size_t i, j; + pthread_mutex_lock(&l->lock); + + for (i = 0, j = 0; i < list_length(l); i++) { + void *e = list_at(l, i); + + if (!cb(e)) + l->array[j++] = e; + } + + l->length = j; + + pthread_mutex_unlock(&l->lock); +} diff --git a/common/lib/log.cpp b/common/lib/log.cpp new file mode 100644 index 000000000..3320eb579 --- /dev/null +++ b/common/lib/log.cpp @@ -0,0 +1,196 @@ +/* Logging and debugging routines. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +using namespace villas; + +static std::map levelNames = { + {spdlog::level::trace, "trc"}, {spdlog::level::debug, "dbg"}, + {spdlog::level::info, "info"}, {spdlog::level::warn, "warn"}, + {spdlog::level::err, "err"}, {spdlog::level::critical, "crit"}, + {spdlog::level::off, "off"}}; + +class CustomLevelFlag : public spdlog::custom_flag_formatter { + +public: + void format(const spdlog::details::log_msg &msg, const std::tm &, + spdlog::memory_buf_t &dest) override { + auto lvl = levelNames[msg.level]; + auto lvlpad = std::string(padinfo_.width_ - lvl.size(), ' ') + lvl; + dest.append(lvlpad.data(), lvlpad.data() + lvlpad.size()); + } + + spdlog::details::padding_info get_padding_info() { return padinfo_; } + + std::unique_ptr clone() const override { + return spdlog::details::make_unique(); + } +}; + +Log::Log(Level lvl) : level(lvl), pattern("%H:%M:%S %^%-4t%$ %-16n %v") { + char *p = getenv("VILLAS_LOG_PREFIX"); + + sinks = std::make_shared(); + + setLevel(level); + setFormatter(pattern, p ? p : ""); + + // Default sink + sink = std::make_shared(); + + sinks->add_sink(sink); +} + +int Log::getWidth() { + int width = Terminal::getCols() - 50; + + if (!prefix.empty()) + width -= prefix.length(); + + return width; +} + +Logger Log::getNewLogger(const std::string &name) { + Logger logger = spdlog::get(name); + + if (not logger) { + logger = std::make_shared(name, sinks); + + logger->set_level(level); + logger->set_formatter(formatter->clone()); + + for (auto &expr : expressions) { + int flags = 0; +#ifdef FNM_EXTMATCH + // musl-libc doesnt support this flag yet + flags |= FNM_EXTMATCH; +#endif + if (!fnmatch(expr.name.c_str(), name.c_str(), flags)) + logger->set_level(expr.level); + } + + spdlog::register_logger(logger); + } + + return logger; +} + +void Log::parse(json_t *json) { + const char *level = nullptr; + const char *path = nullptr; + const char *pattern = nullptr; + + int ret, syslog = 0; + + json_error_t err; + json_t *json_expressions = nullptr; + + ret = json_unpack_ex(json, &err, JSON_STRICT, + "{ s?: s, s?: s, s?: o, s?: b, s?: s }", "level", &level, + "file", &path, "expressions", &json_expressions, + "syslog", &syslog, "pattern", &pattern); + if (ret) + throw ConfigError(json, err, "node-config-logging"); + + if (level) + setLevel(level); + + if (path) { + auto sink = std::make_shared(path); + + sinks->add_sink(sink); + } + + if (syslog) { +#if SPDLOG_VERSION >= 10400 + auto sink = std::make_shared( + "villas", LOG_PID, LOG_DAEMON, true); +#else + auto sink = std::make_shared( + "villas", LOG_PID, LOG_DAEMON); +#endif + sinks->add_sink(sink); + } + + if (json_expressions) { + if (!json_is_array(json_expressions)) + throw ConfigError(json_expressions, "node-config-logging-expressions", + "The 'expressions' setting must be a list of objects."); + + size_t i; + json_t *json_expression; + + // cppcheck-suppress unknownMacro + json_array_foreach(json_expressions, i, json_expression) + expressions.emplace_back(json_expression); + } +} + +void Log::setFormatter(const std::string &pat, const std::string &pfx) { + pattern = pat; + prefix = pfx; + + formatter = std::make_shared( + spdlog::pattern_time_type::utc); + formatter->add_flag('t'); + formatter->set_pattern(prefix + pattern); + + sinks->set_formatter(formatter->clone()); +} + +void Log::setLevel(Level lvl) { + level = lvl; + + sinks->set_level(lvl); +} + +void Log::setLevel(const std::string &lvl) { + auto l = SPDLOG_LEVEL_NAMES; + + auto it = std::find(l.begin(), l.end(), lvl); + if (it == l.end()) + throw RuntimeError("Invalid log level {}", lvl); + + setLevel(spdlog::level::from_str(lvl)); +} + +Log::Level Log::getLevel() const { return level; } + +std::string Log::getLevelName() const { + auto sv = spdlog::level::to_string_view(level); + + return std::string(sv.data()); +} + +Log::Expression::Expression(json_t *json) { + int ret; + + const char *nme; + const char *lvl; + + json_error_t err; + + ret = json_unpack_ex(json, &err, JSON_STRICT, "{ s: s, s: s }", "name", &nme, + "level", &lvl); + if (ret) + throw ConfigError(json, err, "node-config-logging-expressions"); + + level = spdlog::level::from_str(lvl); + name = nme; +} diff --git a/common/lib/memory.cpp b/common/lib/memory.cpp new file mode 100644 index 000000000..205d8c70f --- /dev/null +++ b/common/lib/memory.cpp @@ -0,0 +1,266 @@ +/* Memory managment. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include +#include + +#include + +namespace villas { + +std::unique_ptr +HostRam::HostRamAllocator::allocateBlock(size_t size) { + // Align to next bigger page size chunk + if (size & size_t(0xFFF)) { + size += size_t(0x1000); + size &= size_t(~0xFFF); + } + +#if defined(__linux__) && !(defined(__arm__) || defined(__aarch64__)) + const int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT; +#else + const int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS; +#endif + const int mmap_protection = PROT_READ | PROT_WRITE; + + const void *addr = mmap(nullptr, size, mmap_protection, mmap_flags, 0, 0); + if (addr == nullptr) { + throw std::bad_alloc(); + } + + auto &mm = MemoryManager::get(); + + // Assemble name for this block + std::stringstream name; + name << std::showbase << std::hex << reinterpret_cast(addr); + + auto blockAddrSpaceId = mm.getProcessAddressSpaceMemoryBlock(name.str()); + + const auto localAddr = reinterpret_cast(addr); + std::unique_ptr mem( + new MemoryBlock(localAddr, size, blockAddrSpaceId), this->free); + + insertMemoryBlock(*mem); + + return mem; +} + +LinearAllocator::LinearAllocator( + const MemoryManager::AddressSpaceId &memoryAddrSpaceId, size_t memorySize, + size_t internalOffset) + : BaseAllocator(memoryAddrSpaceId), nextFreeAddress(0), + memorySize(memorySize), internalOffset(internalOffset), + allocationCount(0) { + // Make sure to start at aligned offset, reduce size in case we need padding + if (const size_t paddingBytes = getAlignmentPadding(internalOffset)) { + assert(paddingBytes < memorySize); + + internalOffset += paddingBytes; + memorySize -= paddingBytes; + } + + // Deallocation callback + free = [&](MemoryBlock *mem) { + logger->debug( + "Deallocating memory block at local addr {:#x} (addr space {})", + mem->getOffset(), mem->getAddrSpaceId()); + + removeMemoryBlock(*mem); + + allocationCount--; + if (allocationCount == 0) { + logger->debug("All allocations are deallocated now, freeing memory"); + + // All allocations have been deallocated, free all memory + nextFreeAddress = 0; + } + + logger->debug("Available memory: {:#x} bytes", getAvailableMemory()); + }; +} + +std::string LinearAllocator::getName() const { + std::stringstream name; + name << "LinearAlloc" << getAddrSpaceId(); + if (internalOffset != 0) { + name << "@0x" << std::hex << internalOffset; + } + + return name.str(); +} + +std::unique_ptr +LinearAllocator::allocateBlock(size_t size) { + if (size > getAvailableMemory()) { + throw std::bad_alloc(); + } + + // Assign address + const uintptr_t localAddr = nextFreeAddress + internalOffset; + + // Reserve memory + nextFreeAddress += size; + + // Make sure it is aligned + if (const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) { + nextFreeAddress += paddingBytes; + + // If next free address is outside this block due to padding, cap it + nextFreeAddress = std::min(nextFreeAddress, memorySize); + } + + auto &mm = MemoryManager::get(); + + // Assemble name for this block + std::stringstream blockName; + blockName << std::showbase << std::hex << localAddr; + + // Create address space + auto addrSpaceName = mm.getSlaveAddrSpaceName(getName(), blockName.str()); + auto addrSpaceId = mm.getOrCreateAddressSpace(addrSpaceName); + + logger->debug("Allocated {:#x} bytes for {}, {:#x} bytes remaining", size, + addrSpaceId, getAvailableMemory()); + + std::unique_ptr mem( + new MemoryBlock(localAddr, size, addrSpaceId), this->free); + + // Mount block into the memory graph + insertMemoryBlock(*mem); + + // Increase the allocation count + allocationCount++; + + return mem; +} + +HostRam::HostRamAllocator::HostRamAllocator() + : BaseAllocator(MemoryManager::get().getProcessAddressSpace()) { + free = [&](MemoryBlock *mem) { + if (::munmap(reinterpret_cast(mem->getOffset()), mem->getSize()) != + 0) { + logger->warn("munmap() failed for {:#x} of size {:#x}", mem->getOffset(), + mem->getSize()); + } + + removeMemoryBlock(*mem); + }; +} + +std::map> + HostDmaRam::allocators; + +HostDmaRam::HostDmaRamAllocator::HostDmaRamAllocator(int num) + : LinearAllocator( + MemoryManager::get().getOrCreateAddressSpace(getUdmaBufName(num)), + getUdmaBufBufSize(num)), + num(num) { + auto &mm = MemoryManager::get(); + logger = Log::get(getName()); + + if (getSize() == 0) { + logger->error( + "Zero-sized DMA buffer not supported, is the kernel module loaded?"); + throw std::bad_alloc(); + } + + const uintptr_t base = getUdmaBufPhysAddr(num); + + mm.createMapping(base, 0, getSize(), getName() + "-PCI", + mm.getPciAddressSpace(), getAddrSpaceId()); + + const auto bufPath = std::string("/dev/") + getUdmaBufName(num); + const int bufFd = open(bufPath.c_str(), O_RDWR | O_SYNC); + if (bufFd != -1) { + void *buf = + mmap(nullptr, getSize(), PROT_READ | PROT_WRITE, MAP_SHARED, bufFd, 0); + close(bufFd); + + if (buf != MAP_FAILED) + mm.createMapping(reinterpret_cast(buf), 0, getSize(), + getName() + "-VA", mm.getProcessAddressSpace(), + getAddrSpaceId()); + else + logger->warn("Cannot map {}", bufPath); + } else + logger->warn("Cannot open {}", bufPath); + + logger->info("Mapped {} of size {} bytes", bufPath, getSize()); +} + +HostDmaRam::HostDmaRamAllocator::~HostDmaRamAllocator() { + auto &mm = MemoryManager::get(); + + void *baseVirt; + try { + auto translation = mm.getTranslationFromProcess(getAddrSpaceId()); + baseVirt = reinterpret_cast(translation.getLocalAddr(0)); + } catch (const std::out_of_range &) { + // Not mapped, nothing to do + return; + } + + logger->debug("Unmapping {}", getName()); + + // Try to unmap it + if (::munmap(baseVirt, getSize()) != 0) { + logger->warn("munmap() failed for {:p} of size {:#x}", baseVirt, getSize()); + } +} + +std::string HostDmaRam::getUdmaBufName(int num) { + std::stringstream name; + name << "udmabuf" << num; + + return name.str(); +} + +std::string HostDmaRam::getUdmaBufBasePath(int num) { + std::stringstream path; + path << "/sys/class/udmabuf/udmabuf" << num << "/"; + return path.str(); +} + +size_t HostDmaRam::getUdmaBufBufSize(int num) { + std::fstream s(getUdmaBufBasePath(num) + "size", s.in); + if (s.is_open()) { + std::string line; + if (std::getline(s, line)) { + return std::strtoul(line.c_str(), nullptr, 10); + } + } + + return 0; +} + +uintptr_t HostDmaRam::getUdmaBufPhysAddr(int num) { + std::fstream s(getUdmaBufBasePath(num) + "phys_addr", s.in); + if (s.is_open()) { + std::string line; + if (std::getline(s, line)) { + return std::strtoul(line.c_str(), nullptr, 16); + } + } + + return UINTPTR_MAX; +} + +HostDmaRam::HostDmaRamAllocator &HostDmaRam::getAllocator(int num) { + auto &allocator = allocators[num]; + if (not allocator) { + allocator = std::make_unique(num); + } + + return *allocator; +} + +} // namespace villas diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp new file mode 100644 index 000000000..61f641b95 --- /dev/null +++ b/common/lib/memory_manager.cpp @@ -0,0 +1,250 @@ +/* Memory managment. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include + +using namespace villas; +using namespace villas::utils; + +namespace villas { + +MemoryManager *MemoryManager::instance = nullptr; + +MemoryManager &MemoryManager::get() { + if (instance == nullptr) { + instance = new MemoryManager; + if (!instance) + throw MemoryAllocationError(); + } + + return *instance; +} + +MemoryManager::AddressSpaceId +MemoryManager::getOrCreateAddressSpace(std::string name) { + try { + // Try fast lookup + return addrSpaceLookup.at(name); + } catch (const std::out_of_range &) { + // Does not yet exist, create + std::shared_ptr addrSpace(new AddressSpace); + addrSpace->name = name; + + // Cache it for the next access + addrSpaceLookup[name] = memoryGraph.addVertex(addrSpace); + + return addrSpaceLookup[name]; + } +} + +MemoryManager::MappingId +MemoryManager::createMapping(uintptr_t src, uintptr_t dest, size_t size, + const std::string &name, + MemoryManager::AddressSpaceId fromAddrSpace, + MemoryManager::AddressSpaceId toAddrSpace) { + std::shared_ptr mapping(new Mapping); + + mapping->name = name; + mapping->src = src; + mapping->dest = dest; + mapping->size = size; + + return addMapping(mapping, fromAddrSpace, toAddrSpace); +} + +MemoryManager::MappingId +MemoryManager::addMapping(std::shared_ptr mapping, + MemoryManager::AddressSpaceId fromAddrSpace, + MemoryManager::AddressSpaceId toAddrSpace) { + return memoryGraph.addEdge(mapping, fromAddrSpace, toAddrSpace); +} + +MemoryManager::AddressSpaceId +MemoryManager::findAddressSpace(const std::string &name) { + return memoryGraph.findVertex( + [&](const std::shared_ptr &v) { return v->name == name; }); +} + +std::list +MemoryManager::findPath(const MemoryManager::AddressSpaceId &fromAddrSpaceId, + const MemoryManager::AddressSpaceId &toAddrSpaceId) { + std::list path; + + auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId); + auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId); + + // Find a path through the memory graph + MemoryGraph::Path pathGraph; + if (not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, + pathCheckFunc)) { + + logger->debug("No translation found from ({}) to ({})", + fromAddrSpace->toString(), toAddrSpace->toString()); + + throw std::out_of_range("no translation found"); + } + + for (auto &mappingId : pathGraph) { + auto mapping = memoryGraph.getEdge(mappingId); + path.push_back(mapping->getVertexTo()); + } + + return path; +} + +MemoryTranslation MemoryManager::getTranslation( + const MemoryManager::AddressSpaceId &fromAddrSpaceId, + const MemoryManager::AddressSpaceId &toAddrSpaceId) { + // Find a path through the memory graph + MemoryGraph::Path path; + if (not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, + pathCheckFunc)) { + + auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId); + auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId); + logger->debug("No translation found from ({}) to ({})", + fromAddrSpace->toString(), toAddrSpace->toString()); + + throw std::out_of_range("no translation found"); + } + + // Start with an identity mapping + MemoryTranslation translation(0, 0, SIZE_MAX); + + // Iterate through path and merge all mappings into a single translation + for (auto &mappingId : path) { + auto mapping = memoryGraph.getEdge(mappingId); + translation += getTranslationFromMapping(*mapping); + } + + return translation; +} + +bool MemoryManager::pathCheck(const MemoryGraph::Path &path) { + // Start with an identity mapping + MemoryTranslation translation(0, 0, SIZE_MAX); + + // Try to add all mappings together to a common translation. If this fails + // there is a non-overlapping window. + for (auto &mappingId : path) { + auto mapping = memoryGraph.getEdge(mappingId); + try { + translation += getTranslationFromMapping(*mapping); + } catch (const InvalidTranslation &) { + return false; + } + } + + return true; +} + +uintptr_t +MemoryTranslation::getLocalAddr(uintptr_t addrInForeignAddrSpace) const { + assert(addrInForeignAddrSpace >= dst); + assert(addrInForeignAddrSpace < (dst + size)); + return src + addrInForeignAddrSpace - dst; +} + +uintptr_t +MemoryTranslation::getForeignAddr(uintptr_t addrInLocalAddrSpace) const { + assert(addrInLocalAddrSpace >= src); + assert(addrInLocalAddrSpace < (src + size)); + return dst + addrInLocalAddrSpace - src; +} + +MemoryTranslation & +MemoryTranslation::operator+=(const MemoryTranslation &other) { + Logger logger = Log::get("MemoryTranslation"); + + // Set level to debug to enable debug output + logger->set_level(spdlog::level::info); + + const uintptr_t this_dst_high = this->dst + this->size; + const uintptr_t other_src_high = other.src + other.size; + + logger->debug("this->src: {:#x}", this->src); + logger->debug("this->dst: {:#x}", this->dst); + logger->debug("this->size: {:#x}", this->size); + logger->debug("other.src: {:#x}", other.src); + logger->debug("other.dst: {:#x}", other.dst); + logger->debug("other.size: {:#x}", other.size); + logger->debug("this_dst_high: {:#x}", this_dst_high); + logger->debug("other_src_high: {:#x}", other_src_high); + + // Make sure there is a common memory area + assertExcept(other.src < this_dst_high, MemoryManager::InvalidTranslation()); + assertExcept(this->dst < other_src_high, MemoryManager::InvalidTranslation()); + + const uintptr_t hi = std::max(this_dst_high, other_src_high); + const uintptr_t lo = std::min(this->dst, other.src); + + const uintptr_t diff_hi = (this_dst_high > other_src_high) + ? (this_dst_high - other_src_high) + : (other_src_high - this_dst_high); + + const bool otherSrcIsSmaller = this->dst > other.src; + const uintptr_t diff_lo = + (otherSrcIsSmaller) ? (this->dst - other.src) : (other.src - this->dst); + + logger->debug("hi: {:#x}", hi); + logger->debug("lo: {:#x}", lo); + logger->debug("diff_hi: {:#x}", diff_hi); + logger->debug("diff_lo: {:#x}", diff_lo); + + // New size of aperture, can only stay or shrink + this->size = (hi - lo) - diff_hi - diff_lo; + + // New translation will come out other's destination (by default) + this->dst = other.dst; + + // The source stays the same and can only increase with merged translations + //this->src = this->src; + + if (otherSrcIsSmaller) + // Other mapping starts at lower addresses, so we actually arrive at + // higher addresses + this->dst += diff_lo; + else + // Other mapping starts at higher addresses than this, so we have to + // increase the start + // NOTE: for addresses equality, this just adds 0 + this->src += diff_lo; + + logger->debug("result src: {:#x}", this->src); + logger->debug("result dst: {:#x}", this->dst); + logger->debug("result size: {:#x}", this->size); + + return *this; +} + +void MemoryManager::printGraph() { + auto loggerStatic = logger; + + loggerStatic->info("####### Vertices ########"); + + for (unsigned int i = 0; i < memoryGraph.getVertexCount(); i++) { + auto vertex = memoryGraph.getVertex(i); + loggerStatic->info(std::to_string(i) + ": " + vertex->name); + } + + loggerStatic->info("####### Edges ########"); + + for (unsigned int i = 0; i < memoryGraph.getEdgeCount(); i++) { + auto mapping = memoryGraph.getEdge(i); + loggerStatic->info("From: " + std::to_string(mapping->getVertexFrom()) + + " To: " + std::to_string(mapping->getVertexTo()) + + " ID: " + mapping->toString()); + } +} + +} // namespace villas diff --git a/common/lib/plugin.cpp b/common/lib/plugin.cpp new file mode 100644 index 000000000..ee8c84aa0 --- /dev/null +++ b/common/lib/plugin.cpp @@ -0,0 +1,32 @@ +/* Loadable / plugin support. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include + +using namespace villas::plugin; + +Registry *villas::plugin::registry = nullptr; + +Plugin::Plugin() { + if (registry == nullptr) + registry = new Registry(); + + registry->add(this); +} + +Plugin::~Plugin() { registry->remove(this); } + +void Plugin::dump() { + getLogger()->info("Name: '{}' Description: '{}'", getName(), + getDescription()); +} diff --git a/common/lib/popen.cpp b/common/lib/popen.cpp new file mode 100644 index 000000000..b205b3dcb --- /dev/null +++ b/common/lib/popen.cpp @@ -0,0 +1,184 @@ +/* Bi-directional popen. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace villas { +namespace utils { + +Popen::Popen(const std::string &cmd, const arg_list &args, const env_map &env, + const std::string &wd, bool sh) + : command(cmd), working_dir(wd), arguments(args), environment(env), + shell(sh) { + open(); +} + +Popen::~Popen() { close(); } + +void Popen::kill(int signal) { ::kill(pid, signal); } + +void Popen::open() { + std::vector argv, envp; + + const int READ = 0; + const int WRITE = 1; + + int ret; + int inpipe[2]; + int outpipe[2]; + + ret = pipe(inpipe); + if (ret) + goto error_out; + + ret = pipe(outpipe); + if (ret) + goto clean_inpipe_out; + + fd_in = outpipe[READ]; + fd_out = inpipe[WRITE]; + + pid = fork(); + if (pid == -1) + goto clean_outpipe_out; + + if (pid == 0) { + // Prepare arguments + if (shell) { + argv.push_back((char *)"sh"); + argv.push_back((char *)"-c"); + argv.push_back((char *)command.c_str()); + } else { + for (auto arg : arguments) { + auto s = strdup(arg.c_str()); + + argv.push_back(s); + } + } + + // Prepare environment + for (char **p = environ; *p; p++) + envp.push_back(*p); + + for (auto env : environment) { + auto e = fmt::format("{}={}", env.first, env.second); + auto s = strdup(e.c_str()); + + envp.push_back(s); + } + + argv.push_back(nullptr); + envp.push_back(nullptr); + + // Redirect IO + ::close(outpipe[READ]); + ::close(inpipe[WRITE]); + + if (inpipe[READ] != STDIN_FILENO) { + dup2(inpipe[READ], STDIN_FILENO); + ::close(inpipe[READ]); + } + + if (outpipe[WRITE] != STDOUT_FILENO) { + dup2(outpipe[WRITE], STDOUT_FILENO); + ::close(outpipe[WRITE]); + } + + // Change working directory + if (!working_dir.empty()) { + int ret; + + ret = chdir(working_dir.c_str()); + if (ret) + exit(127); + } + + execvpe(shell ? _PATH_BSHELL : command.c_str(), (char *const *)argv.data(), + (char *const *)envp.data()); + exit(127); + } + + ::close(outpipe[WRITE]); + ::close(inpipe[READ]); + + return; + +clean_outpipe_out: + ::close(outpipe[READ]); + ::close(outpipe[WRITE]); + +clean_inpipe_out: + ::close(inpipe[READ]); + ::close(inpipe[WRITE]); + +error_out: + throw SystemError("Failed to start subprocess"); +} + +int Popen::close() { + int pstat; + + if (pid != -1) { + do { + pid = waitpid(pid, &pstat, 0); + } while (pid == -1 && errno == EINTR); + } + + return pid == -1 ? -1 : pstat; +} + +PopenStream::PopenStream(const std::string &cmd, const arg_list &args, + const env_map &env, const std::string &wd, bool sh) + : Popen(cmd, args, env, wd, sh) { + open(); +} + +PopenStream::~PopenStream() { close(); } + +void PopenStream::open() { + Popen::open(); + + input.buffer = std::make_unique(fd_in, std::ios_base::in); + output.buffer = std::make_unique(fd_out, std::ios_base::out); + + input.stream = std::make_unique(input.buffer.get()); + output.stream = std::make_unique(output.buffer.get()); +} + +int PopenStream::close() { + int ret = Popen::close(); + + input.stream.reset(); + output.stream.reset(); + + input.buffer.reset(); + output.buffer.reset(); + + return ret; +} + +} // namespace utils +} // namespace villas diff --git a/common/lib/table.cpp b/common/lib/table.cpp new file mode 100644 index 000000000..8c1b50002 --- /dev/null +++ b/common/lib/table.cpp @@ -0,0 +1,142 @@ +/* Print fancy tables. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace villas; +using namespace villas::utils; + +#if !defined(LOG_COLOR_DISABLE) +#define ANSI_RESET "\e[0m" +#else +#define ANSI_RESET +#endif + +int Table::resize(int w) { + int norm, flex, fixed, total; + + width = w; + + norm = 0; + flex = 0; + fixed = 0; + total = width - columns.size() * 2; + + // Normalize width + for (unsigned i = 0; i < columns.size(); i++) { + if (columns[i].width > 0) + norm += columns[i].width; + if (columns[i].width == 0) + flex++; + if (columns[i].width < 0) + fixed += -1 * columns[i].width; + } + + for (unsigned i = 0; i < columns.size(); i++) { + if (columns[i].width > 0) + columns[i]._width = columns[i].width * (float)(total - fixed) / norm; + if (columns[i].width == 0) + columns[i]._width = (float)(total - fixed) / flex; + if (columns[i].width < 0) + columns[i]._width = -1 * columns[i].width; + } + + return 0; +} + +void Table::header() { + if (width != Log::getInstance().getWidth()) + resize(Log::getInstance().getWidth()); + + char *line1 = nullptr; + char *line2 = nullptr; + char *line3 = nullptr; + + for (unsigned i = 0; i < columns.size(); i++) { + int w, u; + char *col, *unit; + + col = strf(CLR_BLD("%s"), columns[i].title.c_str()); + unit = columns[i].unit.size() ? strf(CLR_YEL("%s"), columns[i].unit.c_str()) + : strf(""); + + w = columns[i]._width + strlen(col) - strlenp(col); + u = columns[i]._width + strlen(unit) - strlenp(unit); + + if (columns[i].align == TableColumn::Alignment::LEFT) { + strcatf(&line1, " %-*.*s" ANSI_RESET, w, w, col); + strcatf(&line2, " %-*.*s" ANSI_RESET, u, u, unit); + } else { + strcatf(&line1, " %*.*s" ANSI_RESET, w, w, col); + strcatf(&line2, " %*.*s" ANSI_RESET, u, u, unit); + } + + for (int j = 0; j < columns[i]._width + 2; j++) { + strcatf(&line3, "%s", BOX_LR); + } + + if (i != columns.size() - 1) { + strcatf(&line1, " %s", BOX_UD); + strcatf(&line2, " %s", BOX_UD); + strcatf(&line3, "%s", BOX_UDLR); + } + + free(col); + free(unit); + } + + logger->info("{}", line1); + logger->info("{}", line2); + logger->info("{}", line3); + + free(line1); + free(line2); + free(line3); +} + +void Table::row(int count, ...) { + if (width != Log::getInstance().getWidth()) { + resize(Log::getInstance().getWidth()); + header(); + } + + va_list args; + va_start(args, count); + + char *line = nullptr; + + for (unsigned i = 0; i < columns.size(); ++i) { + char *col = vstrf(columns[i].format.c_str(), args); + + int l = strlenp(col); + int r = strlen(col); + int w = columns[i]._width + r - l; + + if (columns[i].align == TableColumn::Alignment::LEFT) + strcatf(&line, " %-*.*s " ANSI_RESET, w, w, col); + else + strcatf(&line, " %*.*s " ANSI_RESET, w, w, col); + + if (i != columns.size() - 1) + strcatf(&line, BOX_UD); + + free(col); + } + + va_end(args); + + logger->info("{}", line); + free(line); +} diff --git a/common/lib/task.cpp b/common/lib/task.cpp new file mode 100644 index 000000000..ebdfc8e28 --- /dev/null +++ b/common/lib/task.cpp @@ -0,0 +1,171 @@ +/* Run tasks periodically. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include + +using namespace villas; + +#if PERIODIC_TASK_IMPL == TIMERFD +#include +#endif // PERIODIC_TASK_IMPL + +Task::Task(int clk) : clock(clk) { +#if PERIODIC_TASK_IMPL == TIMERFD + fd = timerfd_create(clock, 0); + if (fd < 0) + throw SystemError("Failed to create timerfd"); +#elif PERIODIC_TASK_IMPL == RDTSC + int ret = tsc_init(&tsc); + if (ret) + return ret; +#endif // PERIODIC_TASK_IMPL +} + +void Task::setTimeout(double to) { + struct timespec now; + + clock_gettime(clock, &now); + + struct timespec timeout = time_from_double(to); + struct timespec next = time_add(&now, &timeout); + + setNext(&next); +} + +void Task::setNext(const struct timespec *nxt) { + +#if PERIODIC_TASK_IMPL != RDTSC + next = *nxt; + +#if PERIODIC_TASK_IMPL == TIMERFD + int ret; + struct itimerspec its = {.it_interval = (struct timespec){0, 0}, + .it_value = next}; + + ret = timerfd_settime(fd, TFD_TIMER_ABSTIME, &its, nullptr); + if (ret) + throw SystemError("Failed to set timerfd"); +#endif // PERIODIC_TASK_IMPL == TIMERFD +#endif // PERIODIC_TASK_IMPL != RDTSC +} + +void Task::setRate(double rate) { +#if PERIODIC_TASK_IMPL == RDTSC + period = tsc_rate_to_cycles(&tsc, rate); + next = tsc_now(&tsc) + period; +#else + // A rate of 0 will disarm the timer + period = rate ? time_from_double(1.0 / rate) : (struct timespec){0, 0}; + +#if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP || PERIODIC_TASK_IMPL == NANOSLEEP + struct timespec now, next; + + clock_gettime(clock, &now); + + next = time_add(&now, &period); + + return setNext(&next); +#elif PERIODIC_TASK_IMPL == TIMERFD + int ret; + struct itimerspec its = {.it_interval = period, .it_value = period}; + + ret = timerfd_settime(fd, 0, &its, nullptr); + if (ret) + throw SystemError("Failed to set timerfd"); +#endif // PERIODIC_TASK_IMPL +#endif // PERIODIC_TASK_IMPL == RDTSC +} + +Task::~Task() { +#if PERIODIC_TASK_IMPL == TIMERFD + close(fd); +#endif +} + +uint64_t Task::wait() { + uint64_t runs; + +#if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP || PERIODIC_TASK_IMPL == NANOSLEEP + int ret; + struct timespec now; + + ret = clock_gettime(clock, &now); + if (ret) + return ret; + + for (runs = 0; time_cmp(&next, &now) < 0; runs++) + next = time_add(&next, &period); + +#if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP + do { + ret = clock_nanosleep(clock, TIMER_ABSTIME, &next, nullptr); + } while (ret == EINTR); +#elif PERIODIC_TASK_IMPL == NANOSLEEP + struct timespec req, rem = time_diff(&now, &next); + + do { + req = rem; + ret = nanosleep(&req, &rem); + } while (ret < 0 && errno == EINTR); +#endif + if (ret) + return 0; + + ret = clock_gettime(clock, &now); + if (ret) + return ret; + + for (; time_cmp(&next, &now) < 0; runs++) + next = time_add(&next, &period); +#elif PERIODIC_TASK_IMPL == TIMERFD + int ret; + + ret = read(fd, &runs, sizeof(runs)); + if (ret < 0) + return 0; +#elif PERIODIC_TASK_IMPL == RDTSC + uint64_t now; + + do { + now = tsc_now(&tsc); + } while (now < next); + + for (runs = 0; next < now; runs++) + next += period; +#else +#error "Invalid period task implementation" +#endif + + return runs; +} + +void Task::stop() { +#if PERIODIC_TASK_IMPL == TIMERFD + int ret; + struct itimerspec its = {.it_interval = (struct timespec){0, 0}, + .it_value = (struct timespec){0, 0}}; + + ret = timerfd_settime(fd, 0, &its, nullptr); + if (ret) + throw SystemError("Failed to disarm timerfd"); +#endif // PERIODIC_TASK_IMPL == TIMERFD +} + +int Task::getFD() const { +#if PERIODIC_TASK_IMPL == TIMERFD + return fd; +#else + return -1; +#endif +} diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp new file mode 100644 index 000000000..cb6540262 --- /dev/null +++ b/common/lib/terminal.cpp @@ -0,0 +1,70 @@ +/* Terminal handling. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +using namespace villas; + +class Terminal *Terminal::current = nullptr; + +Terminal::Terminal() { + int ret; + + window.ws_row = 0; + window.ws_col = 0; + + isTty = isatty(STDERR_FILENO); + + Logger logger = Log::get("terminal"); + + if (isTty) { + struct sigaction sa_resize; + sa_resize.sa_flags = SA_SIGINFO; + sa_resize.sa_sigaction = resize; + + sigemptyset(&sa_resize.sa_mask); + + ret = sigaction(SIGWINCH, &sa_resize, nullptr); + if (ret) + throw SystemError("Failed to register signal handler"); + + // Try to get initial terminal dimensions + ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); + if (ret) + logger->warn("Failed to get terminal dimensions"); + } else { + logger->info("stderr is not associated with a terminal! Using fallback " + "values for window size..."); + } + + // Fallback if for some reason we can not determine a prober window size + if (window.ws_col == 0) + window.ws_col = 150; + + if (window.ws_row == 0) + window.ws_row = 50; +} + +void Terminal::resize(int, siginfo_t *, void *) { + if (!current) + current = new Terminal(); + + Logger logger = Log::get("terminal"); + + int ret; + + ret = ioctl(STDERR_FILENO, TIOCGWINSZ, ¤t->window); + if (ret) + throw SystemError("Failed to get terminal dimensions"); + + logger->debug("New terminal size: {}x{}", current->window.ws_row, + current->window.ws_col); +}; diff --git a/common/lib/timing.cpp b/common/lib/timing.cpp new file mode 100644 index 000000000..acbc7e1ea --- /dev/null +++ b/common/lib/timing.cpp @@ -0,0 +1,70 @@ +/* Time related functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +struct timespec time_now() { + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + + return ts; +} + +struct timespec time_add(const struct timespec *start, + const struct timespec *end) { + struct timespec sum = {.tv_sec = end->tv_sec + start->tv_sec, + .tv_nsec = end->tv_nsec + start->tv_nsec}; + + if (sum.tv_nsec >= 1000000000) { + sum.tv_sec += 1; + sum.tv_nsec -= 1000000000; + } + + return sum; +} + +struct timespec time_diff(const struct timespec *start, + const struct timespec *end) { + struct timespec diff = {.tv_sec = end->tv_sec - start->tv_sec, + .tv_nsec = end->tv_nsec - start->tv_nsec}; + + if (diff.tv_nsec < 0) { + diff.tv_sec -= 1; + diff.tv_nsec += 1000000000; + } + + return diff; +} + +struct timespec time_from_double(double secs) { + struct timespec ts; + + ts.tv_sec = secs; + ts.tv_nsec = 1.0e9 * (secs - ts.tv_sec); + + return ts; +} + +double time_to_double(const struct timespec *ts) { + return ts->tv_sec + ts->tv_nsec * 1e-9; +} + +double time_delta(const struct timespec *start, const struct timespec *end) { + struct timespec diff = time_diff(start, end); + + return time_to_double(&diff); +} + +ssize_t time_cmp(const struct timespec *a, const struct timespec *b) { + ssize_t sd = a->tv_sec - b->tv_sec; + ssize_t nsd = a->tv_nsec - b->tv_nsec; + + return sd != 0 ? sd : nsd; +} diff --git a/common/lib/tool.cpp b/common/lib/tool.cpp new file mode 100644 index 000000000..c84bc1a45 --- /dev/null +++ b/common/lib/tool.cpp @@ -0,0 +1,67 @@ +/* Common entry point for all villas command line tools. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +using namespace villas; + +void Tool::staticHandler(int signal, siginfo_t *sinfo, void *ctx) { + if (current_tool) + current_tool->handler(signal, sinfo, ctx); +} + +void Tool::printCopyright() { + std::cout << PROJECT_NAME " " << CLR_BLU(PROJECT_BUILD_ID) + << " (built on " CLR_MAG(__DATE__) " " CLR_MAG(__TIME__) ")" + << std::endl + << " Copyright 2014-2021, Institute for Automation of Complex " + "Power Systems, RWTH Aachen University" + << std::endl + << " Steffen Vogel " << std::endl; +} + +void Tool::printVersion() { std::cout << PROJECT_BUILD_ID << std::endl; } + +Tool::Tool(int ac, char *av[], const std::string &nme, + const std::list &sigs) + : argc(ac), argv(av), name(nme), handlerSignals(sigs) { + current_tool = this; + + logger = Log::get(name); +} + +int Tool::run() { + try { + int ret; + + logger->info("This is VILLASnode {} (built on {}, {})", + CLR_BLD(CLR_YEL(PROJECT_BUILD_ID)), CLR_BLD(CLR_MAG(__DATE__)), + CLR_BLD(CLR_MAG(__TIME__))); + + ret = utils::signalsInit(staticHandler, handlerSignals); + if (ret) + throw RuntimeError("Failed to initialize signal subsystem"); + + // Parse command line arguments + parse(); + + // Run tool + ret = main(); + + logger->info(CLR_GRN("Goodbye!")); + + return ret; + } catch (const std::runtime_error &e) { + logger->error("{}", e.what()); + + return -1; + } +} + +Tool *Tool::current_tool = nullptr; diff --git a/common/lib/tsc.cpp b/common/lib/tsc.cpp new file mode 100644 index 000000000..c132caeff --- /dev/null +++ b/common/lib/tsc.cpp @@ -0,0 +1,48 @@ +/* Measure time and sleep with IA-32 time-stamp counter. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +using namespace villas; + +int tsc_init(struct Tsc *t) { + uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0; + + // Check if TSC is supported + __get_cpuid(0x1, &eax, &ebx, &ecx, &edx); + if (!(edx & bit_TSC)) + return -2; + + // Check if RDTSCP instruction is supported + __get_cpuid(0x80000001, &eax, &ebx, &ecx, &edx); + t->rdtscp_supported = edx & bit_RDTSCP; + + // Check if TSC is invariant + __get_cpuid(0x80000007, &eax, &ebx, &ecx, &edx); + t->is_invariant = edx & bit_TSC_INVARIANT; + + // Intel SDM Vol 3, Section 18.7.3: + // Nominal TSC frequency = CPUID.15H.ECX[31:0] * CPUID.15H.EBX[31:0] ) ÷ CPUID.15H.EAX[31:0] + __get_cpuid(0x15, &eax, &ebx, &ecx, &edx); + + if (ecx != 0) + t->frequency = ecx * ebx / eax; + else { + int ret; +#ifdef __linux__ + ret = kernel::get_cpu_frequency(&t->frequency); + if (ret) + return ret; +#endif + } + + return 0; +} + +uint64_t tsc_rate_to_cycles(struct Tsc *t, double rate) { + return t->frequency / rate; +} diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp new file mode 100644 index 000000000..f495d8121 --- /dev/null +++ b/common/lib/utils.cpp @@ -0,0 +1,355 @@ +/* Utilities. + * + * Author: Daniel Krebs + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static pthread_t main_thread; + +namespace villas { +namespace utils { + +std::vector tokenize(std::string s, const std::string &delimiter) { + std::vector tokens; + + size_t lastPos = 0; + size_t curentPos; + + while ((curentPos = s.find(delimiter, lastPos)) != std::string::npos) { + const size_t tokenLength = curentPos - lastPos; + tokens.push_back(s.substr(lastPos, tokenLength)); + + // Advance in string + lastPos = curentPos + delimiter.length(); + } + + // Check if there's a last token behind the last delimiter. + if (lastPos != s.length()) { + const size_t lastTokenLength = s.length() - lastPos; + tokens.push_back(s.substr(lastPos, lastTokenLength)); + } + + return tokens; +} + +ssize_t readRandom(char *buf, size_t len) { + int fd; + ssize_t bytes = -1; + + fd = open("/dev/urandom", O_RDONLY); + if (fd < 0) + return -1; + + while (len) { + bytes = read(fd, buf, len); + if (bytes < 0) + break; + + len -= bytes; + buf += bytes; + } + + close(fd); + + return bytes; +} + +// Setup exit handler +int signalsInit(void (*cb)(int signal, siginfo_t *sinfo, void *ctx), + std::list cbSignals, std::list ignoreSignals) { + int ret; + + Logger logger = Log::get("signals"); + + logger->info("Initialize subsystem"); + + struct sigaction sa_cb; + sa_cb.sa_flags = SA_SIGINFO | SA_NODEFER; + sa_cb.sa_sigaction = cb; + + struct sigaction sa_ign; + sa_ign.sa_flags = 0; + sa_ign.sa_handler = SIG_IGN; + + main_thread = pthread_self(); + + sigemptyset(&sa_cb.sa_mask); + sigemptyset(&sa_ign.sa_mask); + + cbSignals.insert(cbSignals.begin(), + {SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGALRM}); + cbSignals.sort(); + cbSignals.unique(); + + for (auto signal : cbSignals) { + ret = sigaction(signal, &sa_cb, nullptr); + if (ret) + return ret; + } + + for (auto signal : ignoreSignals) { + ret = sigaction(signal, &sa_ign, nullptr); + if (ret) + return ret; + } + + return 0; +} + +char *decolor(char *str) { + char *p, *q; + bool inseq = false; + + for (p = q = str; *p; p++) { + switch (*p) { + case 0x1b: + if (*(++p) == '[') { + inseq = true; + continue; + } + break; + + case 'm': + if (inseq) { + inseq = false; + continue; + } + break; + } + + if (!inseq) { + *q = *p; + q++; + } + } + + *q = '\0'; + + return str; +} + +void killme(int sig) { + // Send only to main thread in case the ID was initilized by signalsInit() + if (main_thread) + pthread_kill(main_thread, sig); + else + kill(0, sig); +} + +double boxMuller(float m, float s) { + double x1, x2, y1; + static double y2; + static int use_last = 0; + + if (use_last) { // Use value from previous call + y1 = y2; + use_last = 0; + } else { + double w; + do { + x1 = 2.0 * randf() - 1.0; + x2 = 2.0 * randf() - 1.0; + w = x1 * x1 + x2 * x2; + } while (w >= 1.0); + + w = sqrt(-2.0 * log(w) / w); + y1 = x1 * w; + y2 = x2 * w; + use_last = 1; + } + + return m + y1 * s; +} + +double randf() { return (double)random() / RAND_MAX; } + +char *vstrcatf(char **dest, const char *fmt, va_list ap) { + char *tmp; + int n = *dest ? strlen(*dest) : 0; + int i = vasprintf(&tmp, fmt, ap); + + *dest = (char *)(realloc(*dest, n + i + 1)); + if (*dest != nullptr) + strncpy(*dest + n, tmp, i + 1); + + free(tmp); + + return *dest; +} + +char *strcatf(char **dest, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vstrcatf(dest, fmt, ap); + va_end(ap); + + return *dest; +} + +char *strf(const char *fmt, ...) { + char *buf = nullptr; + + va_list ap; + va_start(ap, fmt); + vstrcatf(&buf, fmt, ap); + va_end(ap); + + return buf; +} + +char *vstrf(const char *fmt, va_list va) { + char *buf = nullptr; + + vstrcatf(&buf, fmt, va); + + return buf; +} + +void *memdup(const void *src, size_t bytes) { + void *dst = new char[bytes]; + if (!dst) + throw MemoryAllocationError(); + + memcpy(dst, src, bytes); + + return dst; +} + +pid_t spawn(const char *name, char *const argv[]) { + pid_t pid; + + pid = fork(); + switch (pid) { + case -1: + return -1; + case 0: + return execvp(name, (char *const *)argv); + } + + return pid; +} + +size_t strlenp(const char *str) { + size_t sz = 0; + + for (const char *d = str; *d; d++) { + const unsigned char *c = (const unsigned char *)d; + + if (isprint(*c)) + sz++; + else if (c[0] == '\b') + sz--; + else if (c[0] == '\t') + sz += 4; // Tab width == 4 + // CSI sequence + else if (c[0] == '\e' && c[1] == '[') { + c += 2; + while (*c && *c != 'm') + c++; + } + // UTF-8 + else if (c[0] >= 0xc2 && c[0] <= 0xdf) { + sz++; + c += 1; + } else if (c[0] >= 0xe0 && c[0] <= 0xef) { + sz++; + c += 2; + } else if (c[0] >= 0xf0 && c[0] <= 0xf4) { + sz++; + c += 3; + } + + d = (const char *)c; + } + + return sz; +} + +int log2i(long long x) { + if (x == 0) + return 1; + + return sizeof(x) * 8 - __builtin_clzll(x) - 1; +} + +int sha1sum(FILE *f, unsigned char *sha1) { + int ret; + char buf[512]; + ssize_t bytes; + long seek; + + seek = ftell(f); + fseek(f, 0, SEEK_SET); + + EVP_MD_CTX *c = EVP_MD_CTX_new(); + + ret = EVP_DigestInit(c, EVP_sha1()); + if (!ret) + return -1; + + bytes = fread(buf, 1, 512, f); + while (bytes > 0) { + EVP_DigestUpdate(c, buf, bytes); + bytes = fread(buf, 1, 512, f); + } + + EVP_DigestFinal(c, sha1, nullptr); + + fseek(f, seek, SEEK_SET); + + EVP_MD_CTX_free(c); + + return 0; +} + +bool isDocker() { return access("/.dockerenv", F_OK) != -1; } + +bool isKubernetes() { + return access("/var/run/secrets/kubernetes.io", F_OK) != -1 || + getenv("KUBERNETES_SERVICE_HOST") != nullptr; +} + +bool isContainer() { return isDocker() || isKubernetes(); } + +bool isPrivileged() { + // TODO: a cleaner way would be to use libcap here and check for the + // SYS_ADMIN capability. + auto *f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "w"); + if (!f) + return false; + + fclose(f); + + return true; +} + +} // namespace utils +} // namespace villas diff --git a/common/lib/uuid.cpp b/common/lib/uuid.cpp new file mode 100644 index 000000000..6c7e5c17b --- /dev/null +++ b/common/lib/uuid.cpp @@ -0,0 +1,84 @@ +/* UUID helpers. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +using namespace villas::uuid; + +std::string villas::uuid::toString(const uuid_t in) { + uuid_string_t str; + uuid_unparse_lower(in, str); + return str; +} + +int villas::uuid::generateFromString(uuid_t out, const std::string &data, + const std::string &ns) { + int ret; + EVP_MD_CTX *c = EVP_MD_CTX_new(); + + ret = EVP_DigestInit(c, EVP_md5()); + if (!ret) + return -1; + + // Namespace + ret = EVP_DigestUpdate(c, (unsigned char *)ns.c_str(), ns.size()); + if (!ret) + return -1; + + // Data + ret = EVP_DigestUpdate(c, (unsigned char *)data.c_str(), data.size()); + if (!ret) + return -1; + + ret = EVP_DigestFinal(c, (unsigned char *)out, nullptr); + if (!ret) + return -1; + + EVP_MD_CTX_free(c); + + return 0; +} + +int villas::uuid::generateFromString(uuid_t out, const std::string &data, + const uuid_t ns) { + int ret; + EVP_MD_CTX *c = EVP_MD_CTX_new(); + + ret = EVP_DigestInit(c, EVP_md5()); + if (!ret) + return -1; + + // Namespace + ret = EVP_DigestUpdate(c, (unsigned char *)ns, 16); + if (!ret) + return -1; + + // Data + ret = EVP_DigestUpdate(c, (unsigned char *)data.c_str(), data.size()); + if (!ret) + return -1; + + ret = EVP_DigestFinal(c, (unsigned char *)out, nullptr); + if (!ret) + return -1; + + EVP_MD_CTX_free(c); + + return 0; +} + +int villas::uuid::generateFromJson(uuid_t out, json_t *json, const uuid_t ns) { + char *str = json_dumps(json, JSON_COMPACT | JSON_SORT_KEYS); + + int ret = generateFromString(out, str, ns); + + free(str); + + return ret; +} diff --git a/common/lib/version.cpp b/common/lib/version.cpp new file mode 100644 index 000000000..6d5bf0ca6 --- /dev/null +++ b/common/lib/version.cpp @@ -0,0 +1,48 @@ +/* Version. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include + +using namespace villas::utils; + +Version::Version(const std::string &str) { + size_t endpos; + + auto comp = tokenize(str, "."); + + if (comp.size() > 3) + throw std::invalid_argument("Not a valid version string"); + + for (unsigned i = 0; i < 3; i++) { + if (i < comp.size()) { + components[i] = std::stoi(comp[i], &endpos, 10); + + if (comp[i].begin() + endpos != comp[i].end()) + throw std::invalid_argument("Not a valid version string"); + } else + components[i] = 0; + } +} + +Version::Version(int maj, int min, int pat) : components{maj, min, pat} {} + +int Version::cmp(const Version &lhs, const Version &rhs) { + int d; + + for (int i = 0; i < 3; i++) { + d = lhs.components[i] - rhs.components[i]; + if (d) + return d; + } + + return 0; +} diff --git a/common/tests/CMakeLists.txt b/common/tests/CMakeLists.txt new file mode 100644 index 000000000..fb6d280a5 --- /dev/null +++ b/common/tests/CMakeLists.txt @@ -0,0 +1,10 @@ +# CMakeLists.txt. +# +# Author: Steffen Vogel +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +# We only have unit tests for now +if(CRITERION_FOUND) + add_subdirectory(unit) +endif() diff --git a/common/tests/unit/CMakeLists.txt b/common/tests/unit/CMakeLists.txt new file mode 100644 index 000000000..0da325f7f --- /dev/null +++ b/common/tests/unit/CMakeLists.txt @@ -0,0 +1,39 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 +# +# VILLAScommon + +add_executable(unit-tests-common + buffer.cpp + graph.cpp + hist.cpp + kernel.cpp + list.cpp + task.cpp + timing.cpp + utils.cpp + base64.cpp + popen.cpp +) + +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + list(APPEND TEST_SRC tsc.cpp) +endif() + +target_include_directories(unit-tests-common PUBLIC + ${PROJECT_SOURCE_DIR}/common/include + ${CRITERION_INCLUDE_DIRS} +) + +target_link_libraries(unit-tests-common PUBLIC + villas-common + ${CRITERION_LIBRARIES} +) + +add_custom_target(run-unit-tests-common + COMMAND $ ${CRITERION_OPTS} + USES_TERMINAL +) diff --git a/common/tests/unit/base64.cpp b/common/tests/unit/base64.cpp new file mode 100644 index 000000000..305c0afc5 --- /dev/null +++ b/common/tests/unit/base64.cpp @@ -0,0 +1,31 @@ +/* Unit tests for base64 encoding/decoding. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include + +using namespace villas::utils::base64; + +// cppcheck-suppress unknownMacro +TestSuite(base64, .description = "Base64 En/decoder"); + +static std::vector vec(const char *str) { + return std::vector((byte *)str, (byte *)str + strlen(str)); +} + +Test(base64, encoding) { + cr_assert(encode(vec("pohy0Aiy1ZaVa5aik2yaiy3ifoh3oole")) == + "cG9oeTBBaXkxWmFWYTVhaWsyeWFpeTNpZm9oM29vbGU="); +} + +Test(base64, decoding) { + cr_assert(decode("cG9oeTBBaXkxWmFWYTVhaWsyeWFpeTNpZm9oM29vbGU=") == + vec("pohy0Aiy1ZaVa5aik2yaiy3ifoh3oole")); +} diff --git a/common/tests/unit/buffer.cpp b/common/tests/unit/buffer.cpp new file mode 100644 index 000000000..f6043c0d8 --- /dev/null +++ b/common/tests/unit/buffer.cpp @@ -0,0 +1,114 @@ +/* Unit tests for buffer. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include + +using namespace villas; + +// cppcheck-suppress unknownMacro +TestSuite(buffer, .description = "Buffer datastructure"); + +Test(buffer, decode) { + Buffer buf; + json_t *j; + json_t *k; + + const char *e = "{\"id\": \"5a786626-fbc6-4c04-98c2-48027e68c2fa\"}"; + size_t len = strlen(e); + +#pragma GCC diagnostic push +// Workaround for compiler bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199 +#pragma GCC diagnostic ignored "-Wstringop-overflow" + buf.insert(buf.begin(), e, e + len); +#pragma GCC diagnostic pop + + k = json_loads(e, 0, nullptr); + cr_assert_not_null(k); + + j = buf.decode(); + cr_assert_not_null(j); + cr_assert(json_equal(j, k)); +} + +Test(buffer, encode) { + int ret; + Buffer buf; + json_t *k; + + const char *e = "{\"id\": \"5a786626-fbc6-4c04-98c2-48027e68c2fa\"}"; + + k = json_loads(e, 0, nullptr); + cr_assert_not_null(k); + + ret = buf.encode(k); + cr_assert_eq(ret, 0); + + char *f = buf.data(); + cr_assert_not_null(f); + + cr_assert_str_eq(e, f); + + json_decref(k); +} + +Test(buffer, encode_decode) { + int ret; + Buffer buf; + json_t *k; + json_t *j; + + const char *e = "{\"id\": \"5a786626-fbc6-4c04-98c2-48027e68c2fa\"}"; + + k = json_loads(e, 0, nullptr); + cr_assert_not_null(k); + + ret = buf.encode(k); + cr_assert_eq(ret, 0); + + j = buf.decode(); + cr_assert_not_null(j); + + cr_assert(json_equal(j, k)); + + json_decref(j); + json_decref(k); +} + +Test(buffer, multiple) { + int ret; + const int N = 100; + + Buffer buf; + json_t *k[N]; + json_t *j[N]; + + std::srand(std::time(nullptr)); + + for (int i = 0; i < N; i++) { + k[i] = json_pack("{ s: i }", "id", std::rand()); + cr_assert_not_null(k[i]); + + ret = buf.encode(k[i]); + cr_assert_eq(ret, 0); + } + + for (int i = 0; i < N; i++) { + j[i] = buf.decode(); + cr_assert_not_null(j[i]); + + cr_assert(json_equal(k[i], j[i])); + + json_decref(k[i]); + json_decref(j[i]); + } +} diff --git a/common/tests/unit/graph.cpp b/common/tests/unit/graph.cpp new file mode 100644 index 000000000..2c7cf7408 --- /dev/null +++ b/common/tests/unit/graph.cpp @@ -0,0 +1,127 @@ +/* Graph unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2021 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include + +using namespace villas; + +// cppcheck-suppress unknownMacro +TestSuite(graph, .description = "Graph library"); + +Test(graph, basic, .description = "DirectedGraph") { + Logger logger = Log::get("test:graph:basic"); + villas::graph::DirectedGraph<> g("test:graph:basic"); + + logger->info("Testing basic graph construction and modification"); + + std::shared_ptr v1(new villas::graph::Vertex); + std::shared_ptr v2(new villas::graph::Vertex); + std::shared_ptr v3(new villas::graph::Vertex); + + auto v1id = g.addVertex(v1); + auto v2id = g.addVertex(v2); + auto v3id = g.addVertex(v3); + cr_assert(g.getVertexCount() == 3); + + g.addDefaultEdge(v1id, v2id); + g.addDefaultEdge(v3id, v2id); + g.addDefaultEdge(v1id, v3id); + g.addDefaultEdge(v2id, v1id); + cr_assert(g.getEdgeCount() == 4); + cr_assert(g.vertexGetEdges(v1id).size() == 2); + cr_assert(g.vertexGetEdges(v2id).size() == 1); + cr_assert(g.vertexGetEdges(v3id).size() == 1); + + g.removeVertex(v1id); + g.dump(); + cr_assert(g.getVertexCount() == 2); + cr_assert(g.vertexGetEdges(v2id).size() == 0); +} + +Test(graph, path, .description = "Find path") { + Logger logger = Log::get("test:graph:path"); + logger->info("Testing path finding algorithm"); + + using Graph = villas::graph::DirectedGraph<>; + Graph g("test:graph:path"); + + std::shared_ptr v1(new villas::graph::Vertex); + std::shared_ptr v2(new villas::graph::Vertex); + std::shared_ptr v3(new villas::graph::Vertex); + std::shared_ptr v4(new villas::graph::Vertex); + std::shared_ptr v5(new villas::graph::Vertex); + std::shared_ptr v6(new villas::graph::Vertex); + + auto v1id = g.addVertex(v1); + auto v2id = g.addVertex(v2); + auto v3id = g.addVertex(v3); + + auto v4id = g.addVertex(v4); + auto v5id = g.addVertex(v5); + auto v6id = g.addVertex(v6); + + g.addDefaultEdge(v1id, v2id); + g.addDefaultEdge(v2id, v3id); + + // Create circular subgraph + g.addDefaultEdge(v4id, v5id); + g.addDefaultEdge(v5id, v4id); + g.addDefaultEdge(v5id, v6id); + + g.dump(); + + logger->info("Find simple path via two edges"); + std::list path1; + cr_assert(g.getPath(v1id, v3id, path1)); + + logger->info(" Path from {} to {} via:", v1id, v3id); + for (auto &edge : path1) { + logger->info(" -> edge {}", edge); + } + + logger->info("Find path between two unconnected sub-graphs"); + std::list path2; + cr_assert(not g.getPath(v1id, v4id, path2)); + logger->info(" no path found -> ok"); + + logger->info("Find non-existing path in circular sub-graph"); + std::list path3; + cr_assert(not g.getPath(v4id, v2id, path3)); + logger->info(" no path found -> ok"); + + logger->info("Find path in circular graph"); + std::list path4; + cr_assert(g.getPath(v4id, v6id, path4)); + + logger->info(" Path from {} to {} via:", v4id, v6id); + for (auto &edge : path4) { + logger->info(" -> edge {}", edge); + } +} + +Test(graph, memory_manager, .description = "Global Memory Manager") { + Logger logger = Log::get("test:graph:mm"); + auto &mm = villas::MemoryManager::get(); + + logger->info("Create address spaces"); + auto dmaRegs = mm.getOrCreateAddressSpace("DMA Registers"); + auto pcieBridge = mm.getOrCreateAddressSpace("PCIe Bridge"); + + logger->info("Create a mapping"); + mm.createMapping(0x1000, 0, 0x1000, "Testmapping", dmaRegs, pcieBridge); + + logger->info("Find address space by name"); + auto vertex = mm.findAddressSpace("PCIe Bridge"); + logger->info(" found: {}", vertex); + + mm.getGraph().dump(); +} diff --git a/common/tests/unit/hist.cpp b/common/tests/unit/hist.cpp new file mode 100644 index 000000000..f50fcba1b --- /dev/null +++ b/common/tests/unit/hist.cpp @@ -0,0 +1,32 @@ +/* Unit tests for histogram. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include + +const std::array test_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + +using namespace villas; + +// cppcheck-suppress unknownMacro +TestSuite(hist, .description = "Histogram"); + +Test(hist, simple) { + + Hist h(10, 2); + + for (auto td : test_data) + h.put(td); + + cr_assert_float_eq(h.getMean(), 5.5, 1e-6, "Mean is %lf", h.getMean()); + cr_assert_float_eq(h.getVar(), 9.1666, 1e-3); + cr_assert_float_eq(h.getStddev(), 3.027650, 1e-6); +} diff --git a/common/tests/unit/kernel.cpp b/common/tests/unit/kernel.cpp new file mode 100644 index 000000000..82f192ccd --- /dev/null +++ b/common/tests/unit/kernel.cpp @@ -0,0 +1,99 @@ +/* Unit tests for kernel functions. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include + +using namespace villas::kernel; + +// cppcheck-suppress unknownMacro +TestSuite(kernel, .description = "Kernel features"); + +#if defined(__x86_64__) || defined(__i386__) +#define PAGESIZE (1 << 12) +#define CACHELINESIZE 64 + +#if defined(__x86_64__) +#define HUGEPAGESIZE (1 << 21) +#elif defined(__i386__) +#define HUGEPAGESIZE (1 << 22) +#endif +#else +#error "Unsupported architecture" +#endif + +// This test is not portable, but we currently support x86 only +Test(kernel, sizes) { + int sz; + + sz = getPageSize(); + cr_assert_eq(sz, PAGESIZE); + + sz = getHugePageSize(); + cr_assert(sz == HUGEPAGESIZE); + + sz = getCachelineSize(); + cr_assert_eq(sz, CACHELINESIZE); +} + +#ifdef __linux__ +Test(kernel, hugepages) { + int ret; + + if (!villas::utils::isPrivileged()) { + cr_skip("Super-user permissions required."); + } + + ret = setNrHugepages(25); + cr_assert_eq(ret, 0); + + ret = getNrHugepages(); + cr_assert_eq(ret, 25); + + ret = setNrHugepages(10); + cr_assert_eq(ret, 0); + + ret = getNrHugepages(); + cr_assert_eq(ret, 10); +} + +Test(kernel, version) { + using villas::utils::Version; + + Version ver = villas::kernel::getVersion(); + Version ver1 = {100, 5}; + Version ver2 = {2, 6}; + + cr_assert_lt(ver, ver1); + cr_assert_gt(ver, ver2); +} + +Test(kernel, module, .disabled = true) { + int ret; + + ret = isModuleLoaded("nf_nat"); + cr_assert_eq(ret, 0); + + ret = isModuleLoaded("does_not_exist"); + cr_assert_neq(ret, 0); +} + +Test(kernel, frequency) { + int ret; + uint64_t freq; + + ret = get_cpu_frequency(&freq); + cr_assert_eq(ret, 0); + + // Check for plausability only + cr_assert(freq > 1e9 && freq < 5e9); +} +#endif diff --git a/common/tests/unit/list.cpp b/common/tests/unit/list.cpp new file mode 100644 index 000000000..98b6c34d3 --- /dev/null +++ b/common/tests/unit/list.cpp @@ -0,0 +1,159 @@ +/* Unit tests for array-based list. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include + +using namespace villas; + +static const char *nouns[] = { + "time", "person", "year", "way", "day", "thing", "man", + "world", "life", "hand", "part", "child", "eye", "woman", + "place", "work", "week", "case", "point", "government", "company", + "number", "group", "problem", "fact"}; + +struct data { + const char *name; + int data; +}; + +// cppcheck-suppress unknownMacro +TestSuite(list, .description = "List datastructure"); + +Test(list, list_search) { + int ret; + struct List l; + + ret = list_init(&l); + cr_assert_eq(ret, 0); + + // Fill list + for (unsigned i = 0; i < ARRAY_LEN(nouns); i++) + list_push(&l, (void *)nouns[i]); + + cr_assert_eq(list_length(&l), ARRAY_LEN(nouns)); + + // Declare on stack! + char positive[] = "woman"; + char negative[] = "dinosaurrier"; + + char *found = (char *)list_search(&l, (cmp_cb_t)strcmp, positive); + cr_assert_not_null(found); + cr_assert_eq(found, nouns[13], "found = %p, nouns[13] = %p", found, + nouns[13]); + cr_assert_str_eq(found, positive); + + char *not_found = (char *)list_search(&l, (cmp_cb_t)strcmp, negative); + cr_assert_null(not_found); + + ret = list_destroy(&l, nullptr, false); + cr_assert_eq(ret, 0); +} + +struct content { + int destroyed; +}; + +static int dtor(void *ptr) { + struct content *elm = (struct content *)ptr; + + elm->destroyed = 1; + + return 0; +} + +Test(list, destructor) { + int ret; + struct List l; + + struct content elm; + elm.destroyed = 0; + + ret = list_init(&l); + cr_assert_eq(ret, 0); + + list_push(&l, &elm); + + cr_assert_eq(list_length(&l), 1); + + ret = list_destroy(&l, dtor, false); + cr_assert_eq(ret, 0); + + cr_assert_eq(elm.destroyed, 1); +} + +Test(list, basics) { + uintptr_t i; + int ret; + struct List l; + + ret = list_init(&l); + cr_assert_eq(ret, 0); + + for (i = 0; i < 100; i++) { + cr_assert_eq(list_length(&l), i); + + list_push(&l, (void *)i); + } + + cr_assert_eq(list_at_safe(&l, 555), nullptr); + cr_assert_eq(list_last(&l), (void *)99); + cr_assert_eq(list_first(&l), (void *)0); + + for (size_t j = 0, i = 0; j < list_length(&l); j++) { + void *k = list_at(&l, j); + + cr_assert_eq(k, (void *)i++); + } + + list_sort( + &l, (cmp_cb_t)[](const void *a, const void *b)->int { + return (intptr_t)b - (intptr_t)a; + }); + + for (size_t j = 0, i = 99; j <= 99; j++, i--) { + uintptr_t k = (uintptr_t)list_at(&l, j); + cr_assert_eq(k, i, "Is %zu, expected %zu", k, i); + } + + ret = list_contains(&l, (void *)55); + cr_assert(ret); + + void *before_ptr = list_at(&l, 12); + + ret = list_insert(&l, 12, (void *)123); + cr_assert_eq(ret, 0); + cr_assert_eq(list_at(&l, 12), (void *)123, "Is: %p", list_at(&l, 12)); + + ret = list_remove(&l, 12); + cr_assert_eq(ret, 0); + cr_assert_eq(list_at(&l, 12), before_ptr); + + int counts, before_len; + + before_len = list_length(&l); + counts = list_contains(&l, (void *)55); + cr_assert_gt(counts, 0); + + list_remove_all(&l, (void *)55); + cr_assert_eq(list_length(&l), (size_t)(before_len - counts)); + + ret = list_contains(&l, (void *)55); + cr_assert(!ret); + + ret = list_destroy(&l, nullptr, false); + cr_assert(!ret); + + ret = list_length(&l); + cr_assert_eq(ret, -1, "List not properly destroyed: l.length = %zd", + l.length); +} diff --git a/common/tests/unit/popen.cpp b/common/tests/unit/popen.cpp new file mode 100644 index 000000000..6fe4dd700 --- /dev/null +++ b/common/tests/unit/popen.cpp @@ -0,0 +1,76 @@ +/* Unit tests for bi-directional popen. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +using namespace villas::utils; + +// cppcheck-suppress unknownMacro +TestSuite(popen, .description = "Bi-directional popen"); + +Test(popen, no_shell) { + PopenStream proc("/usr/bin/tee", {"tee", "test"}); + + proc.cout() << "Hello World" << std::endl; + proc.cout().flush(); + + std::string str, str2; + + proc.cin() >> str >> str2; + + std::cout << str << str2 << std::endl; + + cr_assert_eq(str, "Hello"); + cr_assert_eq(str2, "World"); + + proc.kill(); + proc.close(); +} + +Test(popen, shell) { + PopenStream proc("echo \"Hello World\"", {}, {}, std::string(), true); + + std::string str, str2; + + proc.cin() >> str >> str2; + + cr_assert_eq(str, "Hello"); + cr_assert_eq(str2, "World"); + + proc.kill(); + proc.close(); +} + +Test(popen, wd) { + PopenStream proc("/usr/bin/pwd", {"pwd"}, {}, "/usr/lib"); + + std::string wd; + + proc.cin() >> wd; + + cr_assert_eq(wd, "/usr/lib"); + + proc.kill(); + proc.close(); +} + +Test(popen, env) { + PopenStream proc("echo $MYVAR", {}, {{"MYVAR", "TESTVAL"}}, std::string(), + true); + + std::string var; + + proc.cin() >> var; + + cr_assert_eq(var, "TESTVAL"); + + proc.kill(); + proc.close(); +} diff --git a/common/tests/unit/task.cpp b/common/tests/unit/task.cpp new file mode 100644 index 000000000..13f53099c --- /dev/null +++ b/common/tests/unit/task.cpp @@ -0,0 +1,70 @@ +/* Unit tests for periodic tasks. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include + +// cppcheck-suppress unknownMacro +TestSuite(task, .description = "Periodic timer tasks"); + +Test(task, rate, .timeout = 10) { + int runs = 10; + double rate = 5, waited; + struct timespec start, end; + Task task(CLOCK_MONOTONIC); + + task.setRate(rate); + + int i; + for (i = 0; i < runs; i++) { + clock_gettime(CLOCK_MONOTONIC, &start); + + task.wait(); + + clock_gettime(CLOCK_MONOTONIC, &end); + + waited = time_delta(&start, &end); + + if (fabs(waited - 1.0 / rate) > 10e-3) + break; + } + + if (i < runs) + cr_assert_float_eq(waited, 1.0 / rate, 1e-2, + "We slept for %f instead of %f secs in round %d", waited, + 1.0 / rate, i); +} + +Test(task, wait_until, .timeout = 5) { + int ret; + struct timespec start, end, diff, future; + + Task task(CLOCK_REALTIME); + + double waitfor = 3.423456789; + + start = time_now(); + diff = time_from_double(waitfor); + future = time_add(&start, &diff); + + task.setNext(&future); + + ret = task.wait(); + + end = time_now(); + + cr_assert_eq(ret, 1); + + double waited = time_delta(&start, &end); + + cr_assert_float_eq(waited, waitfor, 1e-2, + "We slept for %f instead of %f secs", waited, waitfor); +} diff --git a/common/tests/unit/timing.cpp b/common/tests/unit/timing.cpp new file mode 100644 index 000000000..a7409c3f1 --- /dev/null +++ b/common/tests/unit/timing.cpp @@ -0,0 +1,75 @@ +/* Unit tests for time related utilities. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +// cppcheck-suppress unknownMacro +TestSuite(timing, .description = "Time measurements"); + +Test(timing, time_now) { + struct timespec now1 = time_now(); + struct timespec now2 = time_now(); + + cr_assert(time_cmp(&now1, &now2) <= 0, "time_now() was reordered!"); +} + +Test(timing, time_diff) { + struct timespec ts1 = {.tv_sec = 0, .tv_nsec = 1}; // Value doesnt matter + struct timespec ts2 = {.tv_sec = 1, + .tv_nsec = 0}; // Overflow in nano seconds! + + struct timespec ts3 = time_diff(&ts1, &ts2); + + // ts4 == ts2? + cr_assert_eq(ts3.tv_sec, 0); + cr_assert_eq(ts3.tv_nsec, 999999999); +} + +Test(timing, time_add) { + struct timespec ts1 = {.tv_sec = 1, + .tv_nsec = 999999999}; // Value doesnt matter + struct timespec ts2 = {.tv_sec = 1, + .tv_nsec = 1}; // Overflow in nano seconds! + + struct timespec ts3 = time_add(&ts1, &ts2); + + // ts4 == ts2? + cr_assert_eq(ts3.tv_sec, 3); + cr_assert_eq(ts3.tv_nsec, 0); +} + +Test(timing, time_delta) { + struct timespec ts1 = {.tv_sec = 1, .tv_nsec = 123}; // Value doesnt matter + struct timespec ts2 = {.tv_sec = 5, + .tv_nsec = 246}; // Overflow in nano seconds! + + double delta = time_delta(&ts1, &ts2); + + cr_assert_float_eq(delta, 4 + 123e-9, 1e-9); +} + +Test(timing, time_from_double) { + double ref = 1234.56789; + + struct timespec ts = time_from_double(ref); + + cr_assert_eq(ts.tv_sec, 1234); + cr_assert_eq(ts.tv_nsec, 567890000); +} + +Test(timing, time_to_from_double) { + double ref = 1234.56789; + + struct timespec ts = time_from_double(ref); + double dbl = time_to_double(&ts); + + cr_assert_float_eq(dbl, ref, 1e-9); +} diff --git a/common/tests/unit/tsc.cpp b/common/tests/unit/tsc.cpp new file mode 100644 index 000000000..6e73dc04a --- /dev/null +++ b/common/tests/unit/tsc.cpp @@ -0,0 +1,62 @@ +/* Unit tests for rdtsc. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +#define CNT (1 << 18) + +// cppcheck-suppress unknownMacro +TestSuite(tsc, .description = "Timestamp counters"); + +Test(tsc, increasing) { + int ret; + struct Tsc tsc; + uint64_t *cntrs; + + ret = tsc_init(&tsc); + cr_assert_eq(ret, 0); + + cntrs = new uint64_t[CNT]; + cr_assert_not_null(cntrs); + + for (unsigned i = 0; i < CNT; i++) + cntrs[i] = tsc_now(&tsc); + + for (unsigned i = 1; i < CNT; i++) + cr_assert_lt(cntrs[i - 1], cntrs[i]); + + delete cntrs; +} + +Test(tsc, sleep) { + int ret; + double delta, duration = 1; + struct timespec start, stop; + struct Tsc tsc; + uint64_t start_cycles, end_cycles; + + ret = tsc_init(&tsc); + cr_assert_eq(ret, 0); + + clock_gettime(CLOCK_MONOTONIC, &start); + + start_cycles = tsc_now(&tsc); + end_cycles = start_cycles + duration * tsc.frequency; + + while (tsc_now(&tsc) < end_cycles) + ; + + clock_gettime(CLOCK_MONOTONIC, &stop); + delta = time_delta(&start, &stop); + + cr_assert_float_eq(delta, duration, 1e-4, "Error: %f, Delta: %lf, Freq: %llu", + delta - duration, delta, tsc.frequency); +} diff --git a/common/tests/unit/utils.cpp b/common/tests/unit/utils.cpp new file mode 100644 index 000000000..003c6d5f5 --- /dev/null +++ b/common/tests/unit/utils.cpp @@ -0,0 +1,214 @@ +/* Unit tests for utilities. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include +#include + +using namespace villas::utils; + +// cppcheck-suppress unknownMacro +TestSuite(utils, .description = "Utilities"); + +// Simple normality test for 1,2,3s intervals +Test(utils, box_muller) { + double n; + unsigned sigma[3] = {0}; + unsigned iter = 1000000; + + for (unsigned i = 0; i < iter; i++) { + n = boxMuller(0, 1); + + if (n > 2 || n < -2) + sigma[2]++; + else if (n > 1 || n < -1) + sigma[1]++; + else + sigma[0]++; + } + +#if 0 + printf("%f %f %f\n", + (double) sigma[2] / iter, + (double) sigma[1] / iter, + (double) sigma[0] / iter); +#endif + + // The random variable generated by the Box Muller transform is + // not an ideal normal distributed variable. + // The numbers from below are empirically measured. + cr_assert_float_eq((double)sigma[2] / iter, 0.045527, 1e-2); + cr_assert_float_eq((double)sigma[1] / iter, 0.271644, 1e-2); + cr_assert_float_eq((double)sigma[0] / iter, 0.682829, 1e-2); +} + +#ifdef __linux__ +Test(utils, cpuset) { + using villas::utils::CpuSet; + + uintmax_t int1 = 0x1234567890ABCDEFULL; + + CpuSet cset1(int1); + + std::string cset1_str = cset1; + + CpuSet cset2(cset1_str); + + cr_assert_eq(cset1, cset2); + + uintmax_t int2 = cset2; + + cr_assert_eq(int1, int2); + + CpuSet cset3("1-5"); + CpuSet cset4("1,2,3,4,5"); + + cr_assert_eq(cset3, cset4); + cr_assert_eq(cset3.count(), 5); + + cr_assert(cset3.isSet(3)); + cr_assert_not(cset3.isSet(6)); + + cr_assert(cset3[3]); + cr_assert_not(cset3[6]); + + cset4.set(6); + cr_assert(cset4[6]); + + cset4.clear(6); + cr_assert_not(cset4[6]); + + cr_assert_str_eq(static_cast(cset4).c_str(), "1-5"); + + cr_assert_any_throw(CpuSet cset5("0-")); + + CpuSet cset6; + cr_assert(cset6.empty()); + cr_assert_eq(cset6.count(), 0); + + cr_assert((~cset6).full()); + cr_assert((cset1 | ~cset1).full()); + cr_assert((cset1 ^ cset1).empty()); + cr_assert((cset1 & cset6).empty()); + + cset1.zero(); + cr_assert(cset1.empty()); +} +#endif // __linux__ + +Test(utils, memdup) { + char orig[1024], *copy; + size_t len; + + len = readRandom(orig, sizeof(orig)); + cr_assert_eq(len, sizeof(orig)); + + copy = (char *)memdup(orig, sizeof(orig)); + cr_assert_not_null(copy); + cr_assert_arr_eq(copy, orig, sizeof(orig)); + + free(copy); +} + +Test(utils, is_aligned) { + // Positive + cr_assert(IS_ALIGNED(1, 1)); + cr_assert(IS_ALIGNED(128, 64)); + + // Negative + cr_assert(!IS_ALIGNED(55, 16)); + cr_assert(!IS_ALIGNED(55, 55)); + cr_assert(!IS_ALIGNED(1128, 256)); +} + +Test(utils, ceil) { + cr_assert_eq(CEIL(10, 3), 4); + cr_assert_eq(CEIL(10, 5), 2); + cr_assert_eq(CEIL(4, 3), 2); +} + +Test(utils, is_pow2) { + // Positive + cr_assert(IS_POW2(1)); + cr_assert(IS_POW2(2)); + cr_assert(IS_POW2(64)); + + // Negative + cr_assert(!IS_POW2(0)); + cr_assert(!IS_POW2(3)); + cr_assert(!IS_POW2(11111)); + cr_assert(!IS_POW2(-1)); +} + +Test(utils, strf) { + char *buf = nullptr; + + buf = strcatf(&buf, "Hallo %s", "Steffen."); + cr_assert_str_eq(buf, "Hallo Steffen."); + + strcatf(&buf, " Its Monday %uth %s %u.", 13, "August", 2018); + cr_assert_str_eq(buf, "Hallo Steffen. Its Monday 13th August 2018."); + + free(buf); +} + +Test(utils, version) { + using villas::utils::Version; + + Version v1 = Version("1.2"); + Version v2 = Version("1.3"); + Version v3 = Version("55"); + Version v4 = Version("66"); + Version v5 = Version(66); + Version v6 = Version(1, 2, 5); + Version v7 = Version("1.2.5"); + + cr_assert_lt(v1, v2); + cr_assert_eq(v1, v1); + cr_assert_gt(v2, v1); + cr_assert_lt(v3, v4); + cr_assert_eq(v4, v5); + cr_assert_eq(v6, v7); +} + +Test(utils, sha1sum) { + int ret; + FILE *f = tmpfile(); + + unsigned char hash[SHA_DIGEST_LENGTH]; + unsigned char expected[SHA_DIGEST_LENGTH] = { + 0x69, 0xdf, 0x29, 0xdf, 0x1f, 0xf2, 0xd2, 0x5d, 0xb8, 0x68, + 0x6c, 0x02, 0x8d, 0xdf, 0x40, 0xaf, 0xb3, 0xc1, 0xc9, 0x4d}; + + // Write the first 512 fibonaccia numbers to the file + for (int i = 0, a = 0, b = 1, c; i < 512; i++, a = b, b = c) { + c = a + b; + + fwrite((void *)&c, sizeof(c), 1, f); + } + + ret = sha1sum(f, hash); + + cr_assert_eq(ret, 0); + cr_assert_arr_eq(hash, expected, SHA_DIGEST_LENGTH); + + fclose(f); +} + +Test(utils, decolor) { + char str[] = + "This " CLR_RED("is") " a " CLR_BLU("colored") " " CLR_BLD("text!"); + char expect[] = "This is a colored text!"; + + decolor(str); + + cr_assert_str_eq(str, expect); +} diff --git a/doc/index.html b/doc/index.html index b98e83715..c300a3486 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,5 +1,5 @@ - diff --git a/doc/openapi-relay.yaml b/doc/openapi-relay.yaml index 4f2ca883f..b2f022a79 100644 --- a/doc/openapi-relay.yaml +++ b/doc/openapi-relay.yaml @@ -33,7 +33,7 @@ paths: description: Success content: application/json: - examples: + examples: example1: value: sessions: diff --git a/doc/openapi/components/schemas/config.yaml b/doc/openapi/components/schemas/config.yaml index f79ccb389..6c0299399 100644 --- a/doc/openapi/components/schemas/config.yaml +++ b/doc/openapi/components/schemas/config.yaml @@ -37,4 +37,4 @@ allOf: logging: $ref: config/logging.yaml -- $ref: config/global.yaml +- $ref: config/global.yaml diff --git a/doc/openapi/components/schemas/config/format.yaml b/doc/openapi/components/schemas/config/format.yaml index 85ba3fc4c..90ad2a2f6 100644 --- a/doc/openapi/components/schemas/config/format.yaml +++ b/doc/openapi/components/schemas/config/format.yaml @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 --- type: object -properties: +properties: real_precision: type: integer @@ -12,7 +12,7 @@ properties: Output all real numbers with at most n digits of precision. The valid range for this setting is between 0 and 31 (inclusive), and other values result in an undefined behavior. By default, the precision is 17, to correctly and losslessly encode all IEEE 754 double precision floating point numbers. - + ts_origin: type: boolean default: true diff --git a/doc/openapi/components/schemas/config/formats/json.yaml b/doc/openapi/components/schemas/config/formats/json.yaml index 0603c0f03..613cad40b 100644 --- a/doc/openapi/components/schemas/config/formats/json.yaml +++ b/doc/openapi/components/schemas/config/formats/json.yaml @@ -26,7 +26,7 @@ allOf: description: | If this flag is used, the output is guaranteed to consist only of ASCII characters. This is achieved by escaping all Unicode characters outside the ASCII range. - + sort_keys: type: boolean default: false @@ -37,7 +37,7 @@ allOf: escape_slash: type: boolean default: false - description: + description: Escape the `/` characters in strings with `\/`. - $ref: ../format.yaml diff --git a/doc/openapi/components/schemas/config/global.yaml b/doc/openapi/components/schemas/config/global.yaml index efd7d0784..96673a5b8 100644 --- a/doc/openapi/components/schemas/config/global.yaml +++ b/doc/openapi/components/schemas/config/global.yaml @@ -14,7 +14,7 @@ properties: The number of hugepages which will be reservered by the system. See: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt - + A value of zero will disable the use of huge pages. stats: @@ -25,9 +25,9 @@ properties: Specifies the rate at which statistics about the active paths will be periodically printed to the screen. Setting this value to 5, will print 5 lines per second. - + A line includes information such as: - + - Source and Destination of path - Messages received - Messages sent @@ -54,7 +54,7 @@ properties: idle_stop: type: boolean - default: false + default: true uuid: type: string @@ -65,6 +65,6 @@ properties: Each VILLASnode instance is identified by a globally unique indentifier / UUID. This UUID can be queried by the API. - + If the setting is not provided, a UUID will be generated by hashing the active VILLASnode configuration. This ensures that restarting the VILLASnode instance with the identical configuration will yield always the same UUID. diff --git a/doc/openapi/components/schemas/config/hook.yaml b/doc/openapi/components/schemas/config/hook.yaml index f6014aefa..2579fa158 100644 --- a/doc/openapi/components/schemas/config/hook.yaml +++ b/doc/openapi/components/schemas/config/hook.yaml @@ -8,7 +8,7 @@ properties: type: boolean default: true description: An optional field which can be used to disable a hook. - + priority: type: integer default: 99 diff --git a/doc/openapi/components/schemas/config/hook_multi.yaml b/doc/openapi/components/schemas/config/hook_multi.yaml index 983db59fe..4fdd258b4 100644 --- a/doc/openapi/components/schemas/config/hook_multi.yaml +++ b/doc/openapi/components/schemas/config/hook_multi.yaml @@ -8,7 +8,7 @@ allOf: signals: type: array description: A list of signal names to which this hook should be applied - example: + example: - busA.V - busB.V - busC.V diff --git a/doc/openapi/components/schemas/config/hooks/_rms.yaml b/doc/openapi/components/schemas/config/hooks/_rms.yaml index 5da6ec15b..7d55c37d1 100644 --- a/doc/openapi/components/schemas/config/hooks/_rms.yaml +++ b/doc/openapi/components/schemas/config/hooks/_rms.yaml @@ -8,7 +8,7 @@ allOf: - type: object required: - window_size - properties: + properties: window_size: type: integer min: 1 diff --git a/doc/openapi/components/schemas/config/hooks/cast.yaml b/doc/openapi/components/schemas/config/hooks/cast.yaml index 38af5fad2..176092ac4 100644 --- a/doc/openapi/components/schemas/config/hooks/cast.yaml +++ b/doc/openapi/components/schemas/config/hooks/cast.yaml @@ -16,7 +16,7 @@ allOf: example: integer new_name: type: string - description: The new name of the casted signal. + description: The new name of the casted signal. example: BusA.V new_unit: type: string diff --git a/doc/openapi/components/schemas/config/hooks/ebm.yaml b/doc/openapi/components/schemas/config/hooks/ebm.yaml index 9dedcbca0..e39cfa1df 100644 --- a/doc/openapi/components/schemas/config/hooks/ebm.yaml +++ b/doc/openapi/components/schemas/config/hooks/ebm.yaml @@ -6,7 +6,7 @@ allOf: - type: object required: - phases - properties: + properties: phases: description: Signal indices for voltage & current values for each phase. example: diff --git a/doc/openapi/components/schemas/config/hooks/gate.yaml b/doc/openapi/components/schemas/config/hooks/gate.yaml index 49b6af027..bb5c54315 100644 --- a/doc/openapi/components/schemas/config/hooks/gate.yaml +++ b/doc/openapi/components/schemas/config/hooks/gate.yaml @@ -4,7 +4,7 @@ --- allOf: - type: object - properties: + properties: mode: description: The triggering condition at which the gate opens. type: string diff --git a/doc/openapi/components/schemas/config/hooks/limit_value.yaml b/doc/openapi/components/schemas/config/hooks/limit_value.yaml index de89d1448..53a447175 100644 --- a/doc/openapi/components/schemas/config/hooks/limit_value.yaml +++ b/doc/openapi/components/schemas/config/hooks/limit_value.yaml @@ -7,7 +7,7 @@ allOf: required: - min - max - properties: + properties: min: description: The smallest value which will pass through the hook before getting clipped. type: number diff --git a/doc/openapi/components/schemas/config/hooks/lua.yaml b/doc/openapi/components/schemas/config/hooks/lua.yaml index a6abb38c2..168fb6c2b 100644 --- a/doc/openapi/components/schemas/config/hooks/lua.yaml +++ b/doc/openapi/components/schemas/config/hooks/lua.yaml @@ -9,7 +9,7 @@ allOf: The Lua hook will pass the complete hook configuration to the `prepare()` Lua function. So you can add arbitrary settings here which are then consumed by the Lua script. - properties: + properties: use_names: type: boolean default: true @@ -50,7 +50,7 @@ allOf: |:-- |:-- | | 0 | seconds | | 1 | nanoseconds | - + - `ts_received` The receive timestamp a Lua table containing the following keys: | Index | Description | |:-- |:-- | @@ -71,7 +71,7 @@ allOf: items: allOf: - type: object - properties: + properties: expression: type: string example: "math.sqrt(smp.data[0] ^ 2 + smp.data[1] ^ 2)" diff --git a/doc/openapi/components/schemas/config/hooks/pmu_dft.yaml b/doc/openapi/components/schemas/config/hooks/pmu_dft.yaml index c86e7d1c3..21424cf03 100644 --- a/doc/openapi/components/schemas/config/hooks/pmu_dft.yaml +++ b/doc/openapi/components/schemas/config/hooks/pmu_dft.yaml @@ -10,7 +10,7 @@ allOf: - end_frequency - frequency_resolution - dft_rate - properties: + properties: sample_rate: type: integer default: 0 diff --git a/doc/openapi/components/schemas/config/hooks/pps_ts.yaml b/doc/openapi/components/schemas/config/hooks/pps_ts.yaml index 17899eb56..5fb82e231 100644 --- a/doc/openapi/components/schemas/config/hooks/pps_ts.yaml +++ b/doc/openapi/components/schemas/config/hooks/pps_ts.yaml @@ -6,7 +6,7 @@ allOf: - type: object required: - expected_smp_rate - properties: + properties: mode: type: string enum: diff --git a/doc/openapi/components/schemas/config/hooks/print.yaml b/doc/openapi/components/schemas/config/hooks/print.yaml index de90bc800..53f2af846 100644 --- a/doc/openapi/components/schemas/config/hooks/print.yaml +++ b/doc/openapi/components/schemas/config/hooks/print.yaml @@ -15,5 +15,5 @@ allOf: type: string default: '' description: An optional prefix which will be prepended to each line written by this hook to the output - + - $ref: ../hook.yaml diff --git a/doc/openapi/components/schemas/config/hooks/round.yaml b/doc/openapi/components/schemas/config/hooks/round.yaml index 9822f8b19..70f0fb40f 100644 --- a/doc/openapi/components/schemas/config/hooks/round.yaml +++ b/doc/openapi/components/schemas/config/hooks/round.yaml @@ -4,7 +4,7 @@ --- allOf: - type: object - properties: + properties: precision: type: integer default: 0 diff --git a/doc/openapi/components/schemas/config/hooks/scale.yaml b/doc/openapi/components/schemas/config/hooks/scale.yaml index 1349048f2..bb9e9ffbe 100644 --- a/doc/openapi/components/schemas/config/hooks/scale.yaml +++ b/doc/openapi/components/schemas/config/hooks/scale.yaml @@ -4,7 +4,7 @@ --- allOf: - type: object - properties: + properties: offset: type: number default: 0.0 diff --git a/doc/openapi/components/schemas/config/hooks/shift_seq.yaml b/doc/openapi/components/schemas/config/hooks/shift_seq.yaml index 8ec50b6d8..88e63c8fe 100644 --- a/doc/openapi/components/schemas/config/hooks/shift_seq.yaml +++ b/doc/openapi/components/schemas/config/hooks/shift_seq.yaml @@ -6,7 +6,7 @@ allOf: - type: object required: - offset - properties: + properties: offset: type: integer description: The offset which is added to the sequence number of each processed sample. diff --git a/doc/openapi/components/schemas/config/hooks/skip_first.yaml b/doc/openapi/components/schemas/config/hooks/skip_first.yaml index 58046aa64..db26d1a9a 100644 --- a/doc/openapi/components/schemas/config/hooks/skip_first.yaml +++ b/doc/openapi/components/schemas/config/hooks/skip_first.yaml @@ -4,7 +4,7 @@ --- allOf: - type: object - properties: + properties: samples: type: integer description: The number of samples which should be dropped by this hook after a start or restart of the node/path. diff --git a/doc/openapi/components/schemas/config/hooks/stats.yaml b/doc/openapi/components/schemas/config/hooks/stats.yaml index 43911fe98..9cf3765be 100644 --- a/doc/openapi/components/schemas/config/hooks/stats.yaml +++ b/doc/openapi/components/schemas/config/hooks/stats.yaml @@ -4,7 +4,7 @@ --- allOf: - type: object - properties: + properties: format: $ref: ../format_spec.yaml buckets: diff --git a/doc/openapi/components/schemas/config/logging.yaml b/doc/openapi/components/schemas/config/logging.yaml index d82471689..2d948b5bc 100644 --- a/doc/openapi/components/schemas/config/logging.yaml +++ b/doc/openapi/components/schemas/config/logging.yaml @@ -50,7 +50,7 @@ properties: required: - name - level - properties: + properties: name: type: string title: Logger name filter diff --git a/doc/openapi/components/schemas/config/netem.yaml b/doc/openapi/components/schemas/config/netem.yaml index 1ce51addb..fe33abedc 100644 --- a/doc/openapi/components/schemas/config/netem.yaml +++ b/doc/openapi/components/schemas/config/netem.yaml @@ -16,7 +16,7 @@ properties: enabled: type: boolean default: true - + delay: type: number default: 0 diff --git a/doc/openapi/components/schemas/config/node.yaml b/doc/openapi/components/schemas/config/node.yaml index fc6c6bf64..d62e75182 100644 --- a/doc/openapi/components/schemas/config/node.yaml +++ b/doc/openapi/components/schemas/config/node.yaml @@ -12,7 +12,7 @@ properties: description: | This setting allows to send multiple samples in a single message to the destination nodes. - The value of this setting determines how many samples will be combined into one packet. + The value of this setting determines how many samples will be combined into one packet. hooks: $ref: hook_list.yaml diff --git a/doc/openapi/components/schemas/config/node_signals.yaml b/doc/openapi/components/schemas/config/node_signals.yaml index a594cec8a..7730aa872 100644 --- a/doc/openapi/components/schemas/config/node_signals.yaml +++ b/doc/openapi/components/schemas/config/node_signals.yaml @@ -3,9 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 --- type: object -properties: +properties: in: type: object - properties: + properties: signals: $ref: ./signal_list.yaml diff --git a/doc/openapi/components/schemas/config/nodes/amqp.yaml b/doc/openapi/components/schemas/config/nodes/amqp.yaml index 396a2ec8c..b05d9a365 100644 --- a/doc/openapi/components/schemas/config/nodes/amqp.yaml +++ b/doc/openapi/components/schemas/config/nodes/amqp.yaml @@ -30,7 +30,7 @@ allOf: Note: These settings are only used if the `uri` setting is using the `amqps://` schema. type: object - properties: + properties: verify_hostname: default: true, diff --git a/doc/openapi/components/schemas/config/nodes/exec.yaml b/doc/openapi/components/schemas/config/nodes/exec.yaml index ac3bcf143..8e6198308 100644 --- a/doc/openapi/components/schemas/config/nodes/exec.yaml +++ b/doc/openapi/components/schemas/config/nodes/exec.yaml @@ -23,7 +23,7 @@ allOf: The program which should be executed in the sub-process. The option is passed to the system shell for execution. - + oneOf: - type: array items: diff --git a/doc/openapi/components/schemas/config/nodes/file.yaml b/doc/openapi/components/schemas/config/nodes/file.yaml index 187efcbf1..463c6dd17 100644 --- a/doc/openapi/components/schemas/config/nodes/file.yaml +++ b/doc/openapi/components/schemas/config/nodes/file.yaml @@ -31,7 +31,7 @@ allOf: in: type: object - properties: + properties: epoch: type: number @@ -108,7 +108,7 @@ allOf: description: | With this setting enabled, the outgoing file is flushed whenever new samples have been written to it. - buffer_size: + buffer_size: type: integer default: 0 min: 0 diff --git a/doc/openapi/components/schemas/config/nodes/iec61850-9-2.yaml b/doc/openapi/components/schemas/config/nodes/iec61850-9-2.yaml index fa6a64d5c..2e1b6bbc1 100644 --- a/doc/openapi/components/schemas/config/nodes/iec61850-9-2.yaml +++ b/doc/openapi/components/schemas/config/nodes/iec61850-9-2.yaml @@ -10,6 +10,10 @@ allOf: in: type: object properties: + check_dst_address: + type: boolean + default: false + signals: type: array items: @@ -19,34 +23,50 @@ allOf: type: object required: - signals - - svid + - sv_id properties: signals: type: array items: $ref: ./signals/iec61850_signal.yaml - - svid: + + sv_id: type: string - confrev: + conf_rev: type: integer - smpmod: + smp_mod: type: string enum: - per_nominal_period - samples_per_second - seconds_per_sample - smprate: + smp_synch: + type: string + enum: + - not_synchronized + - local_clock + - global_clock + + smp_rate: type: integer - vlan_id: - type: integer + vlan: + type: object + properties: + enabled: + type: boolean + default: true - vlan_priority: - type: integer + id: + type: integer + default: 0 + + priority: + type: integer + default: 4 interface: type: string @@ -54,8 +74,10 @@ allOf: app_id: type: integer + default: 0x4000 dst_address: type: string + default: 01:0c:cd:01:00:01 - $ref: ../node.yaml diff --git a/doc/openapi/components/schemas/config/nodes/kafka.yaml b/doc/openapi/components/schemas/config/nodes/kafka.yaml index e98fb4f32..a86024f8f 100644 --- a/doc/openapi/components/schemas/config/nodes/kafka.yaml +++ b/doc/openapi/components/schemas/config/nodes/kafka.yaml @@ -70,7 +70,7 @@ allOf: produce: type: string description: The Kafka topic to which this node-type will publish messages. - + timeout: type: number description: A timeout in seconds for the broker connection. diff --git a/doc/openapi/components/schemas/config/nodes/loopback.yaml b/doc/openapi/components/schemas/config/nodes/loopback.yaml index 70e76fb55..35d629ebb 100644 --- a/doc/openapi/components/schemas/config/nodes/loopback.yaml +++ b/doc/openapi/components/schemas/config/nodes/loopback.yaml @@ -5,7 +5,7 @@ allOf: - type: object properties: - + queuelen: type: integer min: 0 diff --git a/doc/openapi/components/schemas/config/nodes/mqtt.yaml b/doc/openapi/components/schemas/config/nodes/mqtt.yaml index d2cc3a6b8..b96b0387c 100644 --- a/doc/openapi/components/schemas/config/nodes/mqtt.yaml +++ b/doc/openapi/components/schemas/config/nodes/mqtt.yaml @@ -12,14 +12,14 @@ allOf: in: type: object - properties: + properties: subscribe: type: string description: Topic to which this node subscribes. out: type: object - properties: + properties: publish: type: string description: Topic to which this node publishes. @@ -59,7 +59,7 @@ allOf: ssl: type: object - properties: + properties: enabled: type: boolean @@ -92,9 +92,9 @@ allOf: type: boolean default: true description: | - Configure verification of the server hostname in the server certificate. + Configure verification of the server hostname in the server certificate. If value is set to true, it is impossible to guarantee that the host you are connecting to is not impersonating your server. - This can be useful in initial server testing, but makes it possible for a malicious third party to impersonate your server through DNS spoofing, for example. + This can be useful in initial server testing, but makes it possible for a malicious third party to impersonate your server through DNS spoofing, for example. Do not use this function in a real system. Setting value to true makes the connection encryption pointless. diff --git a/doc/openapi/components/schemas/config/nodes/ngsi.yaml b/doc/openapi/components/schemas/config/nodes/ngsi.yaml index d6db7fc49..76a986df7 100644 --- a/doc/openapi/components/schemas/config/nodes/ngsi.yaml +++ b/doc/openapi/components/schemas/config/nodes/ngsi.yaml @@ -10,7 +10,7 @@ allOf: endpoint: type: string format: uri - + entity_id: type: string description: ID of NGSI entity. diff --git a/doc/openapi/components/schemas/config/nodes/opal.yaml b/doc/openapi/components/schemas/config/nodes/opal.yaml index 6266dc69e..2146c1479 100644 --- a/doc/openapi/components/schemas/config/nodes/opal.yaml +++ b/doc/openapi/components/schemas/config/nodes/opal.yaml @@ -7,7 +7,7 @@ allOf: properties: send_id: type: integer - + recv_id: type: integer diff --git a/doc/openapi/components/schemas/config/nodes/redis.yaml b/doc/openapi/components/schemas/config/nodes/redis.yaml index 47432bef1..e75b13493 100644 --- a/doc/openapi/components/schemas/config/nodes/redis.yaml +++ b/doc/openapi/components/schemas/config/nodes/redis.yaml @@ -71,7 +71,7 @@ allOf: timeout: type: object - properties: + properties: connect: type: number description: The timeout in seconds for the initial connection establishment. @@ -83,7 +83,7 @@ allOf: keepalive: type: boolean default: false - description: Enable periodic keepalive packets. + description: Enable periodic keepalive packets. key: type: string @@ -104,7 +104,7 @@ allOf: ssl: type: object - properties: + properties: enabled: type: boolean default: true diff --git a/doc/openapi/components/schemas/config/nodes/rtp.yaml b/doc/openapi/components/schemas/config/nodes/rtp.yaml index e3970527d..4c39e69d4 100644 --- a/doc/openapi/components/schemas/config/nodes/rtp.yaml +++ b/doc/openapi/components/schemas/config/nodes/rtp.yaml @@ -14,7 +14,7 @@ allOf: aimd: type: object - properties: + properties: a: type: number default: 10 @@ -50,7 +50,7 @@ allOf: out: type: object - properties: + properties: netem: $ref: ../netem.yaml diff --git a/doc/openapi/components/schemas/config/nodes/shmem.yaml b/doc/openapi/components/schemas/config/nodes/shmem.yaml index c67b9ca7a..60e561942 100644 --- a/doc/openapi/components/schemas/config/nodes/shmem.yaml +++ b/doc/openapi/components/schemas/config/nodes/shmem.yaml @@ -35,7 +35,7 @@ allOf: in: type: object - properties: + properties: name: type: string description: | @@ -45,7 +45,7 @@ allOf: out: type: object - properties: + properties: name: type: string description: | diff --git a/doc/openapi/components/schemas/config/nodes/signal_node.yaml b/doc/openapi/components/schemas/config/nodes/signal_node.yaml index 988b57acf..61a08341d 100644 --- a/doc/openapi/components/schemas/config/nodes/signal_node.yaml +++ b/doc/openapi/components/schemas/config/nodes/signal_node.yaml @@ -50,8 +50,8 @@ allOf: frequency: type: number description: The frequency of the signal when the `signal` setting is one of `sine`, `square`, `triangle`,`pulse` or `ramp`. - default: 1.0 - + default: 1.0 + phase: type: number default: 0.0 diff --git a/doc/openapi/components/schemas/config/nodes/signals/signal_v2_signal.yaml b/doc/openapi/components/schemas/config/nodes/signals/signal_v2_signal.yaml index e9ab4a1a1..6491c1ec8 100644 --- a/doc/openapi/components/schemas/config/nodes/signals/signal_v2_signal.yaml +++ b/doc/openapi/components/schemas/config/nodes/signals/signal_v2_signal.yaml @@ -40,8 +40,8 @@ allOf: frequency: type: number description: The frequency of the signal when the `signal` setting is one of `sine`, `square`, `triangle`,`pulse` or `ramp`. - default: 1.0 - + default: 1.0 + phase: type: number default: 0.0 diff --git a/doc/openapi/components/schemas/config/nodes/signals/uldaq_signal.yaml b/doc/openapi/components/schemas/config/nodes/signals/uldaq_signal.yaml index 5200ae976..ce48c4404 100644 --- a/doc/openapi/components/schemas/config/nodes/signals/uldaq_signal.yaml +++ b/doc/openapi/components/schemas/config/nodes/signals/uldaq_signal.yaml @@ -13,7 +13,7 @@ allOf: type: string description: The input mode for a specific channel. See `input_mode` for allowed values - channel: + channel: type: integer example: 5 description: The channel input number of the device. diff --git a/doc/openapi/components/schemas/config/nodes/socket.yaml b/doc/openapi/components/schemas/config/nodes/socket.yaml index 49c9b1ec7..6330d3d89 100644 --- a/doc/openapi/components/schemas/config/nodes/socket.yaml +++ b/doc/openapi/components/schemas/config/nodes/socket.yaml @@ -49,7 +49,7 @@ allOf: multicast: type: object - properties: + properties: enabled: type: boolean default: true diff --git a/doc/openapi/components/schemas/config/nodes/stats_node.yaml b/doc/openapi/components/schemas/config/nodes/stats_node.yaml index e69b5e8f1..373e774dc 100644 --- a/doc/openapi/components/schemas/config/nodes/stats_node.yaml +++ b/doc/openapi/components/schemas/config/nodes/stats_node.yaml @@ -13,7 +13,7 @@ allOf: type: object required: - signals - properties: + properties: signals: type: array items: diff --git a/doc/openapi/components/schemas/config/nodes/test_rtt.yaml b/doc/openapi/components/schemas/config/nodes/test_rtt.yaml index 03a03355d..2aa753daa 100644 --- a/doc/openapi/components/schemas/config/nodes/test_rtt.yaml +++ b/doc/openapi/components/schemas/config/nodes/test_rtt.yaml @@ -58,7 +58,7 @@ allOf: - 10 - 100 - limit: + count: description: | The resulting test-case will send the number of samples specified by this setting. This setting is exclusive with the `duration` setting. @@ -71,5 +71,15 @@ allOf: This setting is exclusive with the `limit` setting. type: number example: 60.0 - + + mode: + type: string + enum: + - min + - max + - at_least_count + - at_least_duration + - stop_after_count + - stop_after_duration + - $ref: ../node.yaml diff --git a/doc/openapi/components/schemas/config/nodes/uldaq.yaml b/doc/openapi/components/schemas/config/nodes/uldaq.yaml index e6189b659..dc82a7fbe 100644 --- a/doc/openapi/components/schemas/config/nodes/uldaq.yaml +++ b/doc/openapi/components/schemas/config/nodes/uldaq.yaml @@ -6,7 +6,7 @@ allOf: - type: object required: - sample_rate - properties: + properties: interface_type: type: string diff --git a/doc/openapi/components/schemas/config/nodes/webrtc.yaml b/doc/openapi/components/schemas/config/nodes/webrtc.yaml index 64c10373b..9255b645d 100644 --- a/doc/openapi/components/schemas/config/nodes/webrtc.yaml +++ b/doc/openapi/components/schemas/config/nodes/webrtc.yaml @@ -42,7 +42,7 @@ allOf: ice: type: object title: ICE configuration settings - properties: + properties: servers: title: ICE Servers description: A list of ICE servers used for connection establishment diff --git a/doc/openapi/components/schemas/config/nodes/zeromq.yaml b/doc/openapi/components/schemas/config/nodes/zeromq.yaml index aafa81243..f263689be 100644 --- a/doc/openapi/components/schemas/config/nodes/zeromq.yaml +++ b/doc/openapi/components/schemas/config/nodes/zeromq.yaml @@ -39,8 +39,8 @@ allOf: You can use the [`villas zmq-keygen`](../usage/villas-zmq-keygen.md) command to create a new keypair for the following configuration options: type: object - properties: - enabled: + properties: + enabled: type: boolean description: Whether or not the encryption is enabled. diff --git a/doc/openapi/components/schemas/config/path.yaml b/doc/openapi/components/schemas/config/path.yaml index 5483c6c2e..bfaf5edb6 100644 --- a/doc/openapi/components/schemas/config/path.yaml +++ b/doc/openapi/components/schemas/config/path.yaml @@ -31,7 +31,7 @@ properties: - type: array items: type: string - + enabled: type: boolean default: true @@ -124,4 +124,4 @@ properties: If you see queue or pool underrun warnings, try to increase this value. type: number - + diff --git a/doc/openapi/components/schemas/formats/edgeflex.yaml b/doc/openapi/components/schemas/formats/edgeflex.yaml index 58c283c01..2826cbb02 100644 --- a/doc/openapi/components/schemas/formats/edgeflex.yaml +++ b/doc/openapi/components/schemas/formats/edgeflex.yaml @@ -11,7 +11,7 @@ type: object required: - created -properties: +properties: created: title: Sampling timestamp description: A timestamps in miliseconds since 1970-01-01 00:00:00 @@ -26,7 +26,7 @@ additionalProperties: - type: boolean - type: object description: A complex number represented in real and imaginary components - properties: + properties: real: type: number imag: @@ -40,4 +40,3 @@ example: signal3: real: 1234.4556 imag: 23232.12312 - \ No newline at end of file diff --git a/doc/openapi/components/schemas/formats/igor.yaml b/doc/openapi/components/schemas/formats/igor.yaml index 12bd23a9d..a83e390b4 100644 --- a/doc/openapi/components/schemas/formats/igor.yaml +++ b/doc/openapi/components/schemas/formats/igor.yaml @@ -55,7 +55,7 @@ required: - timestamp - readings -properties: +properties: device: description: ID for measurement device type: string @@ -64,13 +64,13 @@ properties: description: Timestamp of measurement in ISO 8601 format type: string pattern: '^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$' - + readings: type: array items: type: object - properties: - + properties: + channel: type: string description: Name of the monitored bus @@ -78,11 +78,11 @@ properties: magnitude: type: number description: Amplitude of the measured signal [V] - + phase: type: number description: Phase of the measured signal [radian] - + frequency: type: number description: Frequency of the line signal [Hz] diff --git a/doc/openapi/components/schemas/formats/sogno-old.yaml b/doc/openapi/components/schemas/formats/sogno-old.yaml index f5badb87c..34f8ade7d 100644 --- a/doc/openapi/components/schemas/formats/sogno-old.yaml +++ b/doc/openapi/components/schemas/formats/sogno-old.yaml @@ -13,7 +13,7 @@ required: - phase - data -properties: +properties: device: description: ID for measurement device type: string @@ -22,12 +22,12 @@ properties: description: Timestamp of measurement in ISO 8601 format type: string pattern: '^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$' - + component: description: ID (uuid) from CIM document type: string format: uuid - + measurand: type: string enum: @@ -39,14 +39,14 @@ properties: - reactivepower - apparentpower - frequency - + phase: type: string enum: - A - B - C - + data: type: number description: | @@ -58,7 +58,7 @@ properties: - activepower: single phase power, unit watts - reactivepower: single phase power, unit voltampere reactive - apparentpower: single phase power, unit voltampere - - frequency: unit hertz + - frequency: unit hertz example: device: pmu-abc0 diff --git a/doc/openapi/components/schemas/formats/sogno.yaml b/doc/openapi/components/schemas/formats/sogno.yaml index e12862ba8..a7279277e 100644 --- a/doc/openapi/components/schemas/formats/sogno.yaml +++ b/doc/openapi/components/schemas/formats/sogno.yaml @@ -23,7 +23,7 @@ required: - timestamp - readings -properties: +properties: device: description: ID for measurement device type: string @@ -32,17 +32,17 @@ properties: description: Timestamp of measurement in ISO 8601 format type: string pattern: '^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$' - + readings: type: array items: type: object - properties: + properties: component: description: ID (uuid) from CIM document type: string format: uuid - + measurand: type: string enum: @@ -54,14 +54,14 @@ properties: - reactivepower - apparentpower - frequency - + phase: type: string enum: - A - B - C - + data: type: number description: | @@ -73,4 +73,4 @@ properties: - activepower: single phase power, unit watts - reactivepower: single phase power, unit voltampere reactive - apparentpower: single phase power, unit voltampere - - frequency: unit hertz + - frequency: unit hertz diff --git a/doc/openapi/openapi.yaml b/doc/openapi/openapi.yaml index d5aa52d0c..857fd7fd5 100644 --- a/doc/openapi/openapi.yaml +++ b/doc/openapi/openapi.yaml @@ -79,7 +79,7 @@ x-tagGroups: - super-node - nodes - paths - + - name: Configuration Files tags: - config @@ -135,11 +135,11 @@ paths: '/graph.{format}': $ref: 'paths/graph.{format}.yaml' -components: - schemas: +components: + schemas: Config: $ref: components/schemas/config.yaml - + TypeField: type: object required: diff --git a/doc/openapi/paths/config.yaml b/doc/openapi/paths/config.yaml index 7f5a19f2d..2dc10836d 100644 --- a/doc/openapi/paths/config.yaml +++ b/doc/openapi/paths/config.yaml @@ -13,7 +13,7 @@ get: description: Success content: application/json: - schema: + schema: $ref: ../components/schemas/config.yaml examples: example1: diff --git a/doc/openapi/paths/restart.yaml b/doc/openapi/paths/restart.yaml index cd2bbf621..8862e3a4f 100644 --- a/doc/openapi/paths/restart.yaml +++ b/doc/openapi/paths/restart.yaml @@ -22,7 +22,7 @@ post: description: | An optional path or URI to a new configuration file which should be loaded after restarting the node. - + The file referenced by the URL must be a [VILLASnode configuration file](#tag/config) - $ref: ../components/schemas/config.yaml responses: diff --git a/doc/pictures/villas_fpga.png b/doc/pictures/villas_fpga.png new file mode 100644 index 000000000..57a0f1895 Binary files /dev/null and b/doc/pictures/villas_fpga.png differ diff --git a/doc/pictures/villas_fpga.svg b/doc/pictures/villas_fpga.svg new file mode 100644 index 000000000..509e098b1 --- /dev/null +++ b/doc/pictures/villas_fpga.svg @@ -0,0 +1,113 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index b4b9ca7f9..d71e5870e 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -5,10 +5,10 @@ # SPDX-License-Identifier: Apache-2.0 install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMPONENT bin - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/villas/node - FILES_MATCHING - PATTERN "*.conf" - PATTERN "*.json" + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMPONENT bin + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/villas/node + FILES_MATCHING + PATTERN "*.conf" + PATTERN "*.json" ) diff --git a/etc/WSCC_9bus_MV.conf b/etc/WSCC_9bus_MV.conf index 0eabebb42..755d44462 100644 --- a/etc/WSCC_9bus_MV.conf +++ b/etc/WSCC_9bus_MV.conf @@ -2,60 +2,57 @@ # SPDX-License-Identifier: Apache-2.0 logging = { - level = "info" + level = "info" } http = { - enabled = false + enabled = false } nodes = { - opal = { - type = "socket" + opal = { + type = "socket" - in = { - address = "*:13000" + in = { + address = "*:13000" - hooks = ( - { type = "stats" } - ), - signals = ( - { type = "float", name = "f0" }, - { type = "float", name = "f1" }, - { type = "float", name = "f2" }, - { type = "float", name = "f3" }, - { type = "float", name = "cnt" } - ) - } - out = { - address = "134.130.169.81:13000" + hooks = ( + { type = "stats" } + ), + signals = ( + { type = "float", name = "f0" }, + { type = "float", name = "f1" }, + { type = "float", name = "f2" }, + { type = "float", name = "f3" }, + { type = "float", name = "cnt" } + ) + } + out = { + address = "134.130.169.81:13000" - netem = { - enabled = true, + netem = { + enabled = true, - delay = 10000, // 10 ms - jitter = 5000, // 5 ms - distribution = "normal", - loss = 10 - } - } - } + delay = 10000, // 10 ms + jitter = 5000, // 5 ms + distribution = "normal", + loss = 10 + } + } + } } paths = ( - { - in = "opal", - out = "opal", + { + in = "opal", + out = "opal", - hooks = ( - { - type = "average", - offset = 0, - signals = ["f0", "f1", "f2", "f3"] - } -# { -# type = "print" -# } - ) - } + hooks = ( + { + type = "average", + offset = 0, + signals = ["f0", "f1", "f2", "f3"] + } + ) + } ) diff --git a/etc/eric-lab.conf b/etc/eric-lab.conf index 62eaa57b6..9cf9954ca 100644 --- a/etc/eric-lab.conf +++ b/etc/eric-lab.conf @@ -4,70 +4,67 @@ # Please note, that using all options at the same time does not really # makes sense. The purpose of this example is to serve as a reference. # -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files -# # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 -name = "villas-acs" # The name of this VILLASnode. Might by used by node-types - # to identify themselves (default is the hostname). - +# The name of this VILLASnode. Might by used by node-types +# to identify themselves (default is the hostname) +name = "villas-acs" logging = { - level = "debug" + level = "debug" } http = { - port = 80 # Port for HTTP connections + # Port for HTTP connections + port = 80 } ## Dictionary of nodes nodes = { - ws = { - type = "websocket" - unit = "MVa" - units = [ "V", "A", "Var" ] - description = "Demo Channel" - series = ( - { label = "Random walk" }, - { label = "Sine" }, - { label = "Rect" }, - { label = "Ramp" } - ) - } - socket1 = { - type = "socket" - layper = "udp" - - in = { - address = "*:12000" - } - out = { - address = "127.0.0.1:12001" - } - } - socket2 = { - type = "socket" - layer = "udp" + ws = { + type = "websocket" + unit = "MVa" + units = [ "V", "A", "Var" ] + description = "Demo Channel" + series = ( + { label = "Random walk" }, + { label = "Sine" }, + { label = "Rect" }, + { label = "Ramp" } + ) + } + socket1 = { + type = "socket" + layper = "udp" - in = { - address = "*:12001" - } - out = { - address = "127.0.0.1:1200" - } - } + in = { + address = "*:12000" + } + out = { + address = "127.0.0.1:12001" + } + } + socket2 = { + type = "socket" + layer = "udp" + + in = { + address = "*:12001" + } + out = { + address = "127.0.0.1:1200" + } + } } ## List of paths paths = ( - { - in = "socket2", - out = "ws" - } + { + in = "socket2", + out = "ws" + } ) diff --git a/etc/examples/api.conf b/etc/examples/api.conf index 144d660e4..83cf35fd7 100644 --- a/etc/examples/api.conf +++ b/etc/examples/api.conf @@ -2,104 +2,104 @@ # SPDX-License-Identifier: Apache-2.0 http = { - port = 8080 + port = 8080 } nodes = { - api_node = { - type = "api" + api_node = { + type = "api" - in = { - signals = ( - { - name = "sig1_in", - type = "float", - unit = "V", - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - }, - { - name = "sig2_in", - type = "float", - unit = "A", - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - }, - { - name = "sig3_in", - type = "float", - unit = "A", - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - } - ) - } + in = { + signals = ( + { + name = "sig1_in", + type = "float", + unit = "V", + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + }, + { + name = "sig2_in", + type = "float", + unit = "A", + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + }, + { + name = "sig3_in", + type = "float", + unit = "A", + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + } + ) + } - out = { - signals = ( - # Output signals have no name, type and unit settings as those are implicitly - # derived from the signals which are routed to this node - { - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - }, - { - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - }, - { - description = "Signal 1", - rate = 100, - readable = true, - writable = false, - payload = "samples" - } - ) - } - } + out = { + signals = ( + # Output signals have no name, type and unit settings as those are implicitly + # derived from the signals which are routed to this node + { + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + }, + { + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + }, + { + description = "Signal 1", + rate = 100, + readable = true, + writable = false, + payload = "samples" + } + ) + } + } - signal_node = { - type = "signal" + signal_node = { + type = "signal" - signal = "mixed" - values = 5 - rate = 1.0 - } + signal = "mixed" + values = 5 + rate = 1.0 + } } paths = ( - { - in = [ - "api_node" - ], - hooks = ( - "print" - ) - }, - { - in = [ - "signal_node" - ] - out = [ - "api_node" - ] - hooks = ( - "print" - ) - } + { + in = [ + "api_node" + ], + hooks = ( + "print" + ) + }, + { + in = [ + "signal_node" + ] + out = [ + "api_node" + ] + hooks = ( + "print" + ) + } ) diff --git a/etc/examples/example.conf b/etc/examples/example.conf index 945242b99..ca6075ee4 100644 --- a/etc/examples/example.conf +++ b/etc/examples/example.conf @@ -4,10 +4,6 @@ # Please note, that using all options at the same time does not really # makes sense. The purpose of this example is to serve as a reference. # -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files -# # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 @@ -19,5 +15,5 @@ # An example node. Define multiple nodes in the "nodes" dictionary @include "nodes/socket.conf" -# A list of example paths. Define multiple paths by appending them to the "paths" list. +# A list of example paths. Define multiple paths by appending them to the "paths" list @include "paths.conf" diff --git a/etc/examples/formats/csv.conf b/etc/examples/formats/csv.conf index 35f727b62..1a35b9d25 100644 --- a/etc/examples/formats/csv.conf +++ b/etc/examples/formats/csv.conf @@ -2,17 +2,17 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "csv" + format = { + type = "csv" - separator = "," - delimiter = "\n" - skip_first_line = false - header = true - } - } + separator = "," + delimiter = "\n" + skip_first_line = false + header = true + } + } } diff --git a/etc/examples/formats/gtnet.conf b/etc/examples/formats/gtnet.conf index d7b661d65..ff54b8de5 100644 --- a/etc/examples/formats/gtnet.conf +++ b/etc/examples/formats/gtnet.conf @@ -2,16 +2,16 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "gtnet" + format = { + type = "gtnet" - bits = 32 - endianess = "little" - fake = false - } - } + bits = 32 + endianess = "little" + fake = false + } + } } diff --git a/etc/examples/formats/iotagent_ul.conf b/etc/examples/formats/iotagent_ul.conf index e9af8373e..74f249510 100644 --- a/etc/examples/formats/iotagent_ul.conf +++ b/etc/examples/formats/iotagent_ul.conf @@ -2,10 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = "iotagent_ul" - } + format = "iotagent_ul" + } } diff --git a/etc/examples/formats/json-edgeflex.conf b/etc/examples/formats/json-edgeflex.conf index 5c894286c..df741e823 100644 --- a/etc/examples/formats/json-edgeflex.conf +++ b/etc/examples/formats/json-edgeflex.conf @@ -2,18 +2,18 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "json.edgeflex" + format = { + type = "json.edgeflex" - indent = 4 - compact = true - ensure_ascii = true - escape_slash = false - sort_keys = true - } - } + indent = 4 + compact = true + ensure_ascii = true + escape_slash = false + sort_keys = true + } + } } diff --git a/etc/examples/formats/json-kafka.conf b/etc/examples/formats/json-kafka.conf index 5a7b46341..454058474 100644 --- a/etc/examples/formats/json-kafka.conf +++ b/etc/examples/formats/json-kafka.conf @@ -2,18 +2,18 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "json.kafka" + format = { + type = "json.kafka" - indent = 2 - schema = { - type = "struct" - name = "villas-node.Value" - } - } - } + indent = 2 + schema = { + type = "struct" + name = "villas-node.Value" + } + } + } } diff --git a/etc/examples/formats/json-reserve.conf b/etc/examples/formats/json-reserve.conf index 604d21caa..fd867a446 100644 --- a/etc/examples/formats/json-reserve.conf +++ b/etc/examples/formats/json-reserve.conf @@ -2,18 +2,18 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "json.reserve" + format = { + type = "json.reserve" - indent = 4 - compact = true - ensure_ascii = true - escape_slash = false - sort_keys = true - } - } + indent = 4 + compact = true + ensure_ascii = true + escape_slash = false + sort_keys = true + } + } } diff --git a/etc/examples/formats/json.conf b/etc/examples/formats/json.conf index 0a57d9d6d..17ef3fea0 100644 --- a/etc/examples/formats/json.conf +++ b/etc/examples/formats/json.conf @@ -2,18 +2,18 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "json" + format = { + type = "json" - indent = 4 - compact = true - ensure_ascii = true - escape_slash = false - sort_keys = true - } - } + indent = 4 + compact = true + ensure_ascii = true + escape_slash = false + sort_keys = true + } + } } diff --git a/etc/examples/formats/opal-asyncip.conf b/etc/examples/formats/opal-asyncip.conf index 9860ef48d..11eed1838 100644 --- a/etc/examples/formats/opal-asyncip.conf +++ b/etc/examples/formats/opal-asyncip.conf @@ -2,31 +2,31 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "socket" - layer = "udp" + node = { + type = "socket" + layer = "udp" - format = { - type = "opal.asyncip" + format = { + type = "opal.asyncip" - dev_id = 99 - } + dev_id = 99 + } - in = { - # Port number specified in Asynchronous Process block of RTlab project - address = ":12000" + in = { + # Port number specified in Asynchronous Process block of RTlab project + address = ":12000" - signals = { - count = 64 + signals = { + count = 64 - # The Asynchronous Process block only supports floating point values! - type = "float" - } - } + # The Asynchronous Process block only supports floating point values! + type = "float" + } + } - out = { - # IP address and port of OPAL-RT Target - address = "192.168.0.44:12000" - } - } + out = { + # IP address and port of OPAL-RT Target + address = "192.168.0.44:12000" + } + } } diff --git a/etc/examples/formats/protobuf.conf b/etc/examples/formats/protobuf.conf index bb3ff56d3..b9b546cd1 100644 --- a/etc/examples/formats/protobuf.conf +++ b/etc/examples/formats/protobuf.conf @@ -2,10 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = "protobuf" - } + format = "protobuf" + } } diff --git a/etc/examples/formats/raw.conf b/etc/examples/formats/raw.conf index a86d13ceb..6efa55d8d 100644 --- a/etc/examples/formats/raw.conf +++ b/etc/examples/formats/raw.conf @@ -2,16 +2,16 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "raw" + format = { + type = "raw" - bits = 32 - endianess = "little" - fake = false - } - } + bits = 32 + endianess = "little" + fake = false + } + } } diff --git a/etc/examples/formats/tsv.conf b/etc/examples/formats/tsv.conf index 0e6a64bea..1a6bafca2 100644 --- a/etc/examples/formats/tsv.conf +++ b/etc/examples/formats/tsv.conf @@ -2,17 +2,17 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "tsv" + format = { + type = "tsv" - separator = "\t" - delimiter = "\n" - skip_first_line = false - header = true - } - } + separator = "\t" + delimiter = "\n" + skip_first_line = false + header = true + } + } } diff --git a/etc/examples/formats/value.conf b/etc/examples/formats/value.conf index a054c36e4..7fc3143ff 100644 --- a/etc/examples/formats/value.conf +++ b/etc/examples/formats/value.conf @@ -2,14 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "value" + format = { + type = "value" - real_precision = 5 - } - } + real_precision = 5 + } + } } diff --git a/etc/examples/formats/villas-binary.conf b/etc/examples/formats/villas-binary.conf index 1346d3f32..01d6eed5e 100644 --- a/etc/examples/formats/villas-binary.conf +++ b/etc/examples/formats/villas-binary.conf @@ -2,14 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "villas.binary" + format = { + type = "villas.binary" - source_index = 99 - } - } + source_index = 99 + } + } } diff --git a/etc/examples/formats/villas-human.conf b/etc/examples/formats/villas-human.conf index b5f6fcfa9..a31a1b950 100644 --- a/etc/examples/formats/villas-human.conf +++ b/etc/examples/formats/villas-human.conf @@ -2,15 +2,15 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = { - type = "villas.human" + format = { + type = "villas.human" - comment_prefix = "#" - header = false - } - } + comment_prefix = "#" + header = false + } + } } diff --git a/etc/examples/formats/villas-web.conf b/etc/examples/formats/villas-web.conf index c2439e966..15b89f058 100644 --- a/etc/examples/formats/villas-web.conf +++ b/etc/examples/formats/villas-web.conf @@ -2,10 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - node = { - type = "file" - uri = "/dev/null" + node = { + type = "file" + uri = "/dev/null" - format = "villas.web" - } + format = "villas.web" + } } diff --git a/etc/examples/global.conf b/etc/examples/global.conf index e3b78ee27..6e3403d71 100644 --- a/etc/examples/global.conf +++ b/etc/examples/global.conf @@ -1,8 +1,4 @@ -# Global configuration file for VILLASnode. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# Global configuration file for VILLASnode # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University @@ -10,32 +6,39 @@ ## Global Options -affinity = 0x01 # Mask of cores the server should run on - # This also maps the NIC interrupts to those cores! +# Mask of cores the server should run on +# This also maps the NIC interrupts to those cores! +affinity = 0x01 -#priority = 50 # Priority for the server tasks. - # Usually the server is using a real-time FIFO - # scheduling algorithm +# Priority for the server tasks +# Usually the server is using a real-time FIFO +# scheduling algorithm - # See: https://github.com/docker/docker/issues/22380 - # on why we cant use real-time scheduling in Docker +# See: https://github.com/docker/docker/issues/22380 +# on why we cant use real-time scheduling in Docker +#priority = 50 -name = "villas-acs" # The name of this VILLASnode. Might by used by node-types - # to identify themselves (default is the hostname). +# The name of this VILLASnode. Might by used by node-types +# to identify themselves (default is the hostname) +name = "villas-acs" logging = { - level = "debug" # The level of verbosity for debug messages - # One of: "warn", "info", "error", "off", "info" + # The level of verbosity for debug messages + # One of: "warn", "info", "error", "off", "info" + level = "debug" + # File for logs + file = "/tmp/villas-node.log" - file = "/tmp/villas-node.log" # File for logs - - syslog = true # Log to syslogd + # Log to syslogd + syslog = true } http = { - enabled = true, # Do not listen on port if true + # Do not listen on port if true + enabled = true, - port = 80 # Port for HTTP connections + # Port for HTTP connections + port = 80 } diff --git a/etc/examples/hooks/average.conf b/etc/examples/hooks/average.conf index 9f03a7eb9..17beca64c 100644 --- a/etc/examples/hooks/average.conf +++ b/etc/examples/hooks/average.conf @@ -4,17 +4,17 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "average" + hooks = ( + { + type = "average" - signals = [ "sine", "square" ] - offset = 0 - } - ) - } + signals = [ "sine", "square" ] + offset = 0 + } + ) + } ) diff --git a/etc/examples/hooks/cast.conf b/etc/examples/hooks/cast.conf index 2b45e9bcd..b23396ffc 100644 --- a/etc/examples/hooks/cast.conf +++ b/etc/examples/hooks/cast.conf @@ -4,20 +4,20 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "cast" + hooks = ( + { + type = "cast" - signal = "random" - - new_name = "int_random" - new_unit = "pts" - new_type = "integer" - } - ) - } + signal = "random" + + new_name = "int_random" + new_unit = "pts" + new_type = "integer" + } + ) + } ) diff --git a/etc/examples/hooks/decimate.conf b/etc/examples/hooks/decimate.conf index 7555fa432..d212fd95e 100644 --- a/etc/examples/hooks/decimate.conf +++ b/etc/examples/hooks/decimate.conf @@ -4,16 +4,16 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "decimate" + hooks = ( + { + type = "decimate" - ratio = 10 - } - ) - } + ratio = 10 + } + ) + } ) diff --git a/etc/examples/hooks/digest.conf b/etc/examples/hooks/digest.conf index 7d8694771..5789f25ca 100644 --- a/etc/examples/hooks/digest.conf +++ b/etc/examples/hooks/digest.conf @@ -4,20 +4,20 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - # Use a frame hook to generate NEW_FRAME annotations. - "frame", - { - type = "digest" - # The algorithm used for digest calculation - algorithm = "sha256" - # The output file for digests - uri = "sequence.digest" - } - ) - } + hooks = ( + # Use a frame hook to generate NEW_FRAME annotations + "frame", + { + type = "digest" + # The algorithm used for digest calculation + algorithm = "sha256" + # The output file for digests + uri = "sequence.digest" + } + ) + } ) diff --git a/etc/examples/hooks/dp.conf b/etc/examples/hooks/dp.conf index 6f897fa4b..a9464c14e 100644 --- a/etc/examples/hooks/dp.conf +++ b/etc/examples/hooks/dp.conf @@ -4,24 +4,24 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "dp" + hooks = ( + { + type = "dp" - signal = "sine" - f0 = 50 # Hz - dt = 0.1 # seconds - - # Alternative to dt - # rate = 10 Hz + signal = "sine" + f0 = 50 # In Hz + dt = 0.1 # In seconds - harmonics = [ 0, 1, 3, 5, 7 ] - inverse = false - } - ) - } + # Alternative to dt + # rate = 10 Hz + + harmonics = [ 0, 1, 3, 5, 7 ] + inverse = false + } + ) + } ) diff --git a/etc/examples/hooks/dump.conf b/etc/examples/hooks/dump.conf index 142eaf28c..37322be35 100644 --- a/etc/examples/hooks/dump.conf +++ b/etc/examples/hooks/dump.conf @@ -4,14 +4,14 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "dump" - } - ) - } + hooks = ( + { + type = "dump" + } + ) + } ) diff --git a/etc/examples/hooks/ebm.conf b/etc/examples/hooks/ebm.conf index 58c47f3e0..9f028e81a 100644 --- a/etc/examples/hooks/ebm.conf +++ b/etc/examples/hooks/ebm.conf @@ -4,20 +4,20 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "ebm" + hooks = ( + { + type = "ebm" - phases = ( - [ 0, 1 ], - [ 2, 3 ], - [ 4, 5 ] - ) - } - ) - } + phases = ( + [ 0, 1 ], + [ 2, 3 ], + [ 4, 5 ] + ) + } + ) + } ) diff --git a/etc/examples/hooks/frame.conf b/etc/examples/hooks/frame.conf index 4cd73e016..84918074a 100644 --- a/etc/examples/hooks/frame.conf +++ b/etc/examples/hooks/frame.conf @@ -4,18 +4,18 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "frame" + hooks = ( + { + type = "frame" - trigger = "timestamp" - unit = "seconds" - interval = 10 - } - ) - } + trigger = "timestamp" + unit = "seconds" + interval = 10 + } + ) + } ) diff --git a/etc/examples/hooks/gate.conf b/etc/examples/hooks/gate.conf index 4cb8e848a..911eb60ce 100644 --- a/etc/examples/hooks/gate.conf +++ b/etc/examples/hooks/gate.conf @@ -4,22 +4,22 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "gate" + hooks = ( + { + type = "gate" - signal = "square" - mode = "above" - threshold = 0.5 - - # Once triggered, keep active for: - duration = 5 # in seconds - samples = 100 # in number of samples - } - ) - } + signal = "square" + mode = "above" + threshold = 0.5 + + # Once triggered, keep active for: + duration = 5 # In seconds + samples = 100 # In number of samples + } + ) + } ) diff --git a/etc/examples/hooks/hook-nodes.conf b/etc/examples/hooks/hook-nodes.conf index 2240af636..66075707a 100644 --- a/etc/examples/hooks/hook-nodes.conf +++ b/etc/examples/hooks/hook-nodes.conf @@ -6,13 +6,13 @@ # of different hooks nodes = { - signal_node = { - type = "signal" - values = 5 - signal = "mixed" - } - file_node = { - type = "file" - uri = "hook_output.log" - } + signal_node = { + type = "signal" + values = 5 + signal = "mixed" + } + file_node = { + type = "file" + uri = "hook_output.log" + } } diff --git a/etc/examples/hooks/ip-dft-pmu.conf b/etc/examples/hooks/ip-dft-pmu.conf index 31de833c9..de9a9c1a2 100644 --- a/etc/examples/hooks/ip-dft-pmu.conf +++ b/etc/examples/hooks/ip-dft-pmu.conf @@ -4,27 +4,36 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "pmu", + hooks = ( + { + type = "pmu", - signals = ( - "sine" - ) + signals = ( + "sine" + ) - sample_rate = 1000, # sample rate of the input signal - dft_rate = 10, # number of phasors calculated per second + # Sample rate of the input signal + sample_rate = 1000, - estimation_range = 10, # the range around the nominal_freq in with the estimation is done - nominal_freq = 50, # the nominal grid frequnecy - number_plc = 10., # the number of power line cylces stored in the buffer - - angle_unit = "rad" # one of: rad, degree - } - ) - } + # Number of phasors calculated per second + dft_rate = 10, + + # Yhe range around the nominal_freq in with the estimation is done + estimation_range = 10, + + # Yhe nominal grid frequnecy + nominal_freq = 50, + + # Yhe number of power line cylces stored in the buffer + number_plc = 10., + + # One of: rad, degree + angle_unit = "rad" + } + ) + } ) diff --git a/etc/examples/hooks/jitter_calc.conf b/etc/examples/hooks/jitter_calc.conf index 012633a18..385ea4910 100644 --- a/etc/examples/hooks/jitter_calc.conf +++ b/etc/examples/hooks/jitter_calc.conf @@ -4,14 +4,14 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "jitter_calc" - } - ) - } + hooks = ( + { + type = "jitter_calc" + } + ) + } ) diff --git a/etc/examples/hooks/limit_rate.conf b/etc/examples/hooks/limit_rate.conf index 162e24783..1f2e8c329 100644 --- a/etc/examples/hooks/limit_rate.conf +++ b/etc/examples/hooks/limit_rate.conf @@ -4,16 +4,16 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "limit_rate" + hooks = ( + { + type = "limit_rate" - rate = 5.5 - } - ) - } + rate = 5.5 + } + ) + } ) diff --git a/etc/examples/hooks/limit_value.conf b/etc/examples/hooks/limit_value.conf index 00848b04f..66628bf5e 100644 --- a/etc/examples/hooks/limit_value.conf +++ b/etc/examples/hooks/limit_value.conf @@ -4,19 +4,19 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "limit_value" + hooks = ( + { + type = "limit_value" - min = -0.5 - max = 0.5 + min = -0.5 + max = 0.5 - signals = [ "sine" ] - } - ) - } + signals = [ "sine" ] + } + ) + } ) diff --git a/etc/examples/hooks/lua.conf b/etc/examples/hooks/lua.conf index 49c48000b..617192244 100644 --- a/etc/examples/hooks/lua.conf +++ b/etc/examples/hooks/lua.conf @@ -6,81 +6,81 @@ stats = 1 paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "lua" + hooks = ( + { + type = "lua" - # Enables or disables the use of signal names in the process() function - # of the Lua script. If disabled, numeric indices will be used. - use_names = true + # Enables or disables the use of signal names in the process() function + # of the Lua script. If disabled, numeric indices will be used + use_names = true - # The Lua hook will pass the complete hook configuration to the prepare() - # function. So you can add arbitrary settings here which are then - # consumed by the Lua script. - some_setting = "Hello World" - this = { - is = { - nested = 1234 - bool_val = true - } - } + # The Lua hook will pass the complete hook configuration to the prepare() + # function. So you can add arbitrary settings here which are then + # consumed by the Lua script + some_setting = "Hello World" + this = { + is = { + nested = 1234 + bool_val = true + } + } - # Script mode: we provide a Lua script containing functions - # for the individual hook points - # Define some or all of the following functions in your Lua script: - # - # prepare(cfg) Called during initialization with a Lua table which contains - # the full hook configuration - # start() Called when the node/path is started - # - # stop() Called when the node/path is stopped - # - # restart() Called when the node/path is restarted. - # Falls back to stop() + start() if absent. - # - # process(smp) Called for each sample which is being processed. - # The sample is passed as a Lua table with the following - # fields: - # - sequence The sequence number of the sample. - # - flags The flags field of the sample. - # - ts_origin The origin timestamp as a Lua table containing - # the following keys: - # 0: seconds - # 1: nanoseconds - # - ts_received The receive timestamp a Lua table containing - # the following keys: - # 0: seconds - # 1: nanoseconds - # - data The sample data as a Lua table container either - # numeric indices or the signal names depending - # on the 'use_names' option of the hook. - # - # periodic() Called periodically with the rate of the global 'stats' option. - script = "../lua/hooks/test.lua" + # Script mode: we provide a Lua script containing functions + # for the individual hook points + # Define some or all of the following functions in your Lua script: + # + # prepare(cfg) Called during initialization with a Lua table which contains + # the full hook configuration + # start() Called when the node/path is started + # + # stop() Called when the node/path is stopped + # + # restart() Called when the node/path is restarted + # Falls back to stop() + start() if absent + # + # process(smp) Called for each sample which is being processed + # The sample is passed as a Lua table with the following + # fields: + # - sequence The sequence number of the sample + # - flags The flags field of the sample + # - ts_origin The origin timestamp as a Lua table containing + # the following keys: + # 0: seconds + # 1: nanoseconds + # - ts_received The receive timestamp a Lua table containing + # the following keys: + # 0: seconds + # 1: nanoseconds + # - data The sample data as a Lua table container either + # numeric indices or the signal names depending + # on the 'use_names' option of the hook + # + # periodic() Called periodically with the rate of the global 'stats' option + script = "../lua/hooks/test.lua" - # Expression mode: We provide a mangled signal list including Lua expressions - signals = ( - { name = "sum", type="float", unit = "V", expression = "smp.data.square * 10" }, + # Expression mode: We provide a mangled signal list including Lua expressions + signals = ( + { name = "sum", type="float", unit = "V", expression = "smp.data.square * 10" }, - # You can access any global variable set by the script - { name = "sequence", type="float", unit = "V", expression = "global_var" }, + # You can access any global variable set by the script + { name = "sequence", type="float", unit = "V", expression = "global_var" }, - # Here we set a global variable from the periodic handler - { name = "temp_aachen", type="float", unit = "°C", expression = "temp_aachen" }, + # Here we set a global variable from the periodic handler + { name = "temp_aachen", type="float", unit = "°C", expression = "temp_aachen" }, - # We can refer to the current time the global Lua variable 't' - { name = "sum", type="float", unit = "V", expression = "math.sin(2 * math.pi * f * t)" }, + # We can refer to the current time the global Lua variable 't' + { name = "sum", type="float", unit = "V", expression = "math.sin(2 * math.pi * f * t)" }, - { name = "random", expression = "smp.data.random" } - ) - }, - { - type = "print" - } - ) - } + { name = "random", expression = "smp.data.random" } + ) + }, + { + type = "print" + } + ) + } ) diff --git a/etc/examples/hooks/ma.conf b/etc/examples/hooks/ma.conf index 8e8d2eeac..de2d925f9 100644 --- a/etc/examples/hooks/ma.conf +++ b/etc/examples/hooks/ma.conf @@ -4,20 +4,20 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "ma", + hooks = ( + { + type = "ma", - window_size = 1000 + window_size = 1000 - signals = [ - "sine" - ] - } - ) - } + signals = [ + "sine" + ] + } + ) + } ) diff --git a/etc/examples/hooks/pmu.conf b/etc/examples/hooks/pmu.conf index e49349ece..238bd002c 100644 --- a/etc/examples/hooks/pmu.conf +++ b/etc/examples/hooks/pmu.conf @@ -4,26 +4,33 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "pmu", + hooks = ( + { + type = "pmu", - signals = ( - "sine" - ) + signals = ( + "sine" + ) - sample_rate = 1000, # sample rate of the input signal - dft_rate = 10, # number of phasors calculated per second + # Sample rate of the input signal + sample_rate = 1000, - nominal_freq = 50, # the nominal grid frequnecy - number_plc = 10., # the number of power line cylces stored in the buffer - - angle_unit = "rad" # one of: rad, degree - } - ) - } + # Number of phasors calculated per second + dft_rate = 10, + + # The nominal grid frequnecy + nominal_freq = 50, + + # The number of power line cylces stored in the buffer + number_plc = 10., + + # One of: rad, degree + angle_unit = "rad" + } + ) + } ) diff --git a/etc/examples/hooks/pmu_dft.conf b/etc/examples/hooks/pmu_dft.conf index 878733238..0f1c669a5 100644 --- a/etc/examples/hooks/pmu_dft.conf +++ b/etc/examples/hooks/pmu_dft.conf @@ -4,34 +4,51 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "pmu_dft", + hooks = ( + { + type = "pmu_dft", - signals = ( - "sine" - ) + signals = ( + "sine" + ) - sample_rate = 1000, # sample rate of the input signal - dft_rate = 10, # number of phasors calculated per second + # Sample rate of the input signal + sample_rate = 1000, - start_frequency = 49.7, # lowest frequency bin - end_frequency = 50.3, # highest frequency bin - frequency_resolution = 0.1, # frequency bin resolution + # Number of phasors calculated per second + dft_rate = 10, - window_size_factor = 1, # a factor with which the window will be increased - window_type = "hamming", # one of: flattop, hamming, hann - padding_type = "zero", # one of: signal_repeat, zero - frequency_estimate_type = "quadratic", # one of: quadratic + # Lowest frequency bin + start_frequency = 49.7, - pps_index = 0, # signal index of the PPS signal - - angle_unit = "rad" # one of: rad, degree - } - ) - } + # Highest frequency bin + end_frequency = 50.3, + + # Frequency bin resolution + frequency_resolution = 0.1, + + # A factor with which the window will be increased + window_size_factor = 1, + + # One of: flattop, hamming, hann + window_type = "hamming", + + # One of: signal_repeat, zero + padding_type = "zero", + + # One of: quadratic + frequency_estimate_type = "quadratic", + + # Signal index of the PPS signal + pps_index = 0, + + # One of: rad, degree + angle_unit = "rad" + } + ) + } ) diff --git a/etc/examples/hooks/power.conf b/etc/examples/hooks/power.conf index bb277b558..f5f86144e 100644 --- a/etc/examples/hooks/power.conf +++ b/etc/examples/hooks/power.conf @@ -4,28 +4,28 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "power", - angle_unit = "degree" - window_size = 1000 - timestamp_align = "center" - pairings = ( - {voltage = "voltage_l1", current = "current_l1"}, - {voltage = "voltage_l2", current = "current_l2"} - ) + hooks = ( + { + type = "power", + angle_unit = "degree" + window_size = 1000 + timestamp_align = "center" + pairings = ( + {voltage = "voltage_l1", current = "current_l1"}, + {voltage = "voltage_l2", current = "current_l2"} + ) - signals = [ - "voltage_l1", - "voltage_l2", - "current_l1", - "current_l2" - ] - } - ) - } + signals = [ + "voltage_l1", + "voltage_l2", + "current_l1", + "current_l2" + ] + } + ) + } ) diff --git a/etc/examples/hooks/pps_ts.conf b/etc/examples/hooks/pps_ts.conf index ea9132d02..2ca5e0816 100644 --- a/etc/examples/hooks/pps_ts.conf +++ b/etc/examples/hooks/pps_ts.conf @@ -4,22 +4,22 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "pps_ts" + hooks = ( + { + type = "pps_ts" - signal = "pps" + signal = "pps" - mode = "simple" # Oneof: simple, horizon - threshold = 0.5 - expected_smp_rate = 5e3 - horizon_estimation = 10 - horizon_compensation = 10 - } - ) - } + mode = "simple" # Oneof: simple, horizon + threshold = 0.5 + expected_smp_rate = 5e3 + horizon_estimation = 10 + horizon_compensation = 10 + } + ) + } ) diff --git a/etc/examples/hooks/print.conf b/etc/examples/hooks/print.conf index 5ed4aba09..466b8adc3 100644 --- a/etc/examples/hooks/print.conf +++ b/etc/examples/hooks/print.conf @@ -4,18 +4,18 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "print", + hooks = ( + { + type = "print", - output = "print_output_file.log" - format = "villas.human" - # prefix = "[file_node] " # prefix and output are exclusive settings! - } - ) - } + output = "print_output_file.log" + format = "villas.human" + # prefix = "[file_node] " # Prefix and output are exclusive settings! + } + ) + } ) diff --git a/etc/examples/hooks/reorder_ts.conf b/etc/examples/hooks/reorder_ts.conf index 405aaaa98..33b80c1b8 100644 --- a/etc/examples/hooks/reorder_ts.conf +++ b/etc/examples/hooks/reorder_ts.conf @@ -4,16 +4,16 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "reorder_ts" + hooks = ( + { + type = "reorder_ts" - window_size = 10 - } - ) - } + window_size = 10 + } + ) + } ) diff --git a/etc/examples/hooks/rms.conf b/etc/examples/hooks/rms.conf index a57398004..0c54c3413 100644 --- a/etc/examples/hooks/rms.conf +++ b/etc/examples/hooks/rms.conf @@ -4,20 +4,20 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "rms", + hooks = ( + { + type = "rms", - window_size = 1000 + window_size = 1000 - signals = [ - "sine" - ] - } - ) - } + signals = [ + "sine" + ] + } + ) + } ) diff --git a/etc/examples/hooks/round.conf b/etc/examples/hooks/round.conf index 5f69b5b55..7a0f6d93b 100644 --- a/etc/examples/hooks/round.conf +++ b/etc/examples/hooks/round.conf @@ -4,17 +4,17 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "round" + hooks = ( + { + type = "round" - signal = "sine" - precision = 4 - } - ) - } + signal = "sine" + precision = 4 + } + ) + } ) diff --git a/etc/examples/hooks/scale.conf b/etc/examples/hooks/scale.conf index 94d59c874..c86b8de58 100644 --- a/etc/examples/hooks/scale.conf +++ b/etc/examples/hooks/scale.conf @@ -4,19 +4,19 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "scale" + hooks = ( + { + type = "scale" - signal = "sine" + signal = "sine" - offset = 100.0 - scale = 55.0 - } - ) - } + offset = 100.0 + scale = 55.0 + } + ) + } ) diff --git a/etc/examples/hooks/shift_seq.conf b/etc/examples/hooks/shift_seq.conf index c32e32ee4..90a25b284 100644 --- a/etc/examples/hooks/shift_seq.conf +++ b/etc/examples/hooks/shift_seq.conf @@ -4,16 +4,16 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "shift_seq" + hooks = ( + { + type = "shift_seq" - offset = 10 - } - ) - } + offset = 10 + } + ) + } ) diff --git a/etc/examples/hooks/shift_ts.conf b/etc/examples/hooks/shift_ts.conf index 4c4448c91..440f1effa 100644 --- a/etc/examples/hooks/shift_ts.conf +++ b/etc/examples/hooks/shift_ts.conf @@ -4,17 +4,17 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "shift_ts" + hooks = ( + { + type = "shift_ts" - mode = "origin" - offset = 5.5 - } - ) - } + mode = "origin" + offset = 5.5 + } + ) + } ) diff --git a/etc/examples/hooks/skip_first.conf b/etc/examples/hooks/skip_first.conf index 348b8328c..8df3549fe 100644 --- a/etc/examples/hooks/skip_first.conf +++ b/etc/examples/hooks/skip_first.conf @@ -4,17 +4,17 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "skip_first" + hooks = ( + { + type = "skip_first" - seconds = 10 - # sequence = 10 - } - ) - } + seconds = 10 + # sequence = 10 + } + ) + } ) diff --git a/etc/examples/hooks/stats.conf b/etc/examples/hooks/stats.conf index 1523343ef..983498f1a 100644 --- a/etc/examples/hooks/stats.conf +++ b/etc/examples/hooks/stats.conf @@ -2,27 +2,27 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node = { - type = "socket" + udp_node = { + type = "socket" - in = { - address = "*:12000" + in = { + address = "*:12000" - hooks = ( - { - type = "stats" + hooks = ( + { + type = "stats" - verbose = true - warmup = 100 - buckets = 25 + verbose = true + warmup = 100 + buckets = 25 - output = "stats.log" - format = "json" - } - ) - } - out = { - address = "127.0.0.1:12000" - } - } + output = "stats.log" + format = "json" + } + ) + } + out = { + address = "127.0.0.1:12000" + } + } } diff --git a/etc/examples/hooks/ts.conf b/etc/examples/hooks/ts.conf index c25f9ca7e..d7de38ce6 100644 --- a/etc/examples/hooks/ts.conf +++ b/etc/examples/hooks/ts.conf @@ -4,14 +4,14 @@ @include "hook-nodes.conf" paths = ( - { - in = "signal_node" - out = "file_node" + { + in = "signal_node" + out = "file_node" - hooks = ( - { - type = "ts" - } - ) - } + hooks = ( + { + type = "ts" + } + ) + } ) diff --git a/etc/examples/nodes/amqp.conf b/etc/examples/nodes/amqp.conf index 1fa1133e5..fc1573076 100644 --- a/etc/examples/nodes/amqp.conf +++ b/etc/examples/nodes/amqp.conf @@ -2,30 +2,30 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - amqp_node = { - type = "amqp", - format = "json", + amqp_node = { + type = "amqp", + format = "json", - # Use 'amqps://' to enable SSL/TLS - uri = "amqp://username:password@example.com:1234/vhost", + # Use 'amqps://' to enable SSL/TLS + uri = "amqp://username:password@example.com:1234/vhost", - # Alternatively connection settings can be specified individually - username = "guest", - password = "guest", - host = "localhost", - vhost = "/", - port = 5672, + # Alternatively connection settings can be specified individually + username = "guest", + password = "guest", + host = "localhost", + vhost = "/", + port = 5672, - exchange = "mytestexchange", - routing_key = "abc", + exchange = "mytestexchange", + routing_key = "abc", - ssl = { - verify_hostname = true, - verify_peer = true, + ssl = { + verify_hostname = true, + verify_peer = true, - ca_cert = "/path/to/ca.crt", - client_cert = "/path/to/client.crt", - client_key = "/path/to/client.key" - } - } + ca_cert = "/path/to/ca.crt", + client_cert = "/path/to/client.crt", + client_key = "/path/to/client.key" + } + } } diff --git a/etc/examples/nodes/api.conf b/etc/examples/nodes/api.conf index a72ab1a19..7f4dccf99 100644 --- a/etc/examples/nodes/api.conf +++ b/etc/examples/nodes/api.conf @@ -2,32 +2,41 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - api_node = { - type = "api" + api_node = { + type = "api" - in = { - signals = ( - { - name = "" # Same as 'id' in uAPI context - description = "Volts on Bus A" # A human readable description of the channel - type = "float" # Same as 'datatype' in uAPI context - unit = "V" - payload = "events" # or 'samples' - rate = 100.0 # An expected refresh/sample rate of the signal - range = { - min = 20.0 - max = 100.0 - } - readable = true - writable = false - } - ) - } + in = { + signals = ( + { + # Same as 'id' in uAPI context + name = "" - out = { - signals = ( - # Similar to above - ) - } - } + # A human readable description of the channel + description = "Volts on Bus A" + + # Same as 'datatype' in uAPI context + type = "float" + unit = "V" + payload = "events" # Or 'samples' + + # An expected refresh/sample rate of the signal + rate = 100.0 + + range = { + min = 20.0 + max = 100.0 + } + + readable = true + writable = false + } + ) + } + + out = { + signals = ( + # Similar to above + ) + } + } } diff --git a/etc/examples/nodes/can.conf b/etc/examples/nodes/can.conf index 582eecb21..52b0933f3 100644 --- a/etc/examples/nodes/can.conf +++ b/etc/examples/nodes/can.conf @@ -2,64 +2,64 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - can_node1 = { - type = "can" - interface_name = "vcan0" - sample_rate = 500000 + can_node1 = { + type = "can" + interface_name = "vcan0" + sample_rate = 500000 - in = { - signals = ( - { - name = "sigin1", - unit = "Volts", - type = "float", - enabled = true, - can_id = 66, - can_size = 4, - can_offset = 0 - }, - { - name = "sigin2", - unit = "Volts", - type = "float", - enabled = true, - can_id = 66, - can_size = 4, - can_offset = 4 - }, - { - name = "sigin3", - unit = "Volts", - type = "float", - enabled = true, - can_id = 67, - can_size = 8, - can_offset = 0 - } - ) - } + in = { + signals = ( + { + name = "sigin1", + unit = "Volts", + type = "float", + enabled = true, + can_id = 66, + can_size = 4, + can_offset = 0 + }, + { + name = "sigin2", + unit = "Volts", + type = "float", + enabled = true, + can_id = 66, + can_size = 4, + can_offset = 4 + }, + { + name = "sigin3", + unit = "Volts", + type = "float", + enabled = true, + can_id = 67, + can_size = 8, + can_offset = 0 + } + ) + } - out = { - signals = ( - { - type = "float", - can_id = 66, - can_size = 4, - can_offset = 0 - }, - { - type = "float", - can_id = 66, - can_size = 4, - can_offset = 4 - }, - { - type = "float", - can_id = 67, - can_size = 8, - can_offset = 0 - } - ) - } - } + out = { + signals = ( + { + type = "float", + can_id = 66, + can_size = 4, + can_offset = 0 + }, + { + type = "float", + can_id = 66, + can_size = 4, + can_offset = 4 + }, + { + type = "float", + can_id = 67, + can_size = 8, + can_offset = 0 + } + ) + } + } } diff --git a/etc/examples/nodes/comedi.conf b/etc/examples/nodes/comedi.conf index 9b4e563e0..d77bb30e8 100644 --- a/etc/examples/nodes/comedi.conf +++ b/etc/examples/nodes/comedi.conf @@ -2,84 +2,84 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - pcie6259 = { - type = "comedi", + pcie6259 = { + type = "comedi", - device = "/dev/comedi0", - in = { - subdevice = 0, - rate = 1000, - - signals = ( - # note: order in this array defines order in villas sample - { channel = 0, range = 0, aref = 0, name = "temperature_int" }, - { channel = 1, range = 0, aref = 0, name = "loopback_ao0" }, - { channel = 2, range = 0, aref = 0, name = "loopback_ao1" }, - { channel = 3, range = 0, aref = 0, name = "bnc_ext" } - ) - }, - out = { - subdevice = 1, - # Note: buffer size and rate shouldn't be changed at the moment - # output sample rate - rate = 40000, - # comedi write buffer in kilobytes - bufsize = 24, - - signals = ( - # note: order in this array corresponds to order in villas sample - { name = "ao0", channel = 0, range = 0, aref = 0 }, - { name = "ao1", channel = 1, range = 0, aref = 0 }, - { name = "ao2", channel = 2, range = 0, aref = 0 }, - { name = "ao3", channel = 3, range = 0, aref = 0 } - ) - } - }, + device = "/dev/comedi0", + in = { + subdevice = 0, + rate = 1000, - remote = { - type = "socket", - layer = "udp" - format = "protobuf", - - in = { - address = "*:12000" - }, - out = { - address = "134.130.169.32:12000" - } - }, + signals = ( + # Note: order in this array defines order in villas sample + { channel = 0, range = 0, aref = 0, name = "temperature_int" }, + { channel = 1, range = 0, aref = 0, name = "loopback_ao0" }, + { channel = 2, range = 0, aref = 0, name = "loopback_ao1" }, + { channel = 3, range = 0, aref = 0, name = "bnc_ext" } + ) + }, + out = { + subdevice = 1, + # Note: buffer size and rate shouldn't be changed at the moment + # output sample rate + rate = 40000, + # Comedi write buffer in kilobytes + bufsize = 24, - sine1 = { - type = "signal", - signal = "sine", - values = 1, - frequency = 50, - rate = 10000, - }, + signals = ( + # Note: order in this array corresponds to order in villas sample + { name = "ao0", channel = 0, range = 0, aref = 0 }, + { name = "ao1", channel = 1, range = 0, aref = 0 }, + { name = "ao2", channel = 2, range = 0, aref = 0 }, + { name = "ao3", channel = 3, range = 0, aref = 0 } + ) + } + }, - sine2 = { - type = "signal", - signal = "sine", - values = 1, - frequency = 100, - rate = 10000, - } + remote = { + type = "socket", + layer = "udp" + format = "protobuf", + + in = { + address = "*:12000" + }, + out = { + address = "134.130.169.32:12000" + } + }, + + sine1 = { + type = "signal", + signal = "sine", + values = 1, + frequency = 50, + rate = 10000, + }, + + sine2 = { + type = "signal", + signal = "sine", + values = 1, + frequency = 100, + rate = 10000, + } } paths = ( - # 2-ch sine - # { - # in = [ "sine1.data[0]", "sine2.data[0]" ] - # out = "pcie6259" - # rate = 10000 - # mask = () - # } + # 2-ch sine + # { + # in = [ "sine1.data[0]", "sine2.data[0]" ] + # out = "pcie6259" + # rate = 10000 + # mask = () + # } - # Remote data via UDP - { - in = "remote.data[0-3]" - out = "pcie6259" - rate = 40000 - mask = () - } + # Remote data via UDP + { + in = "remote.data[0-3]" + out = "pcie6259" + rate = 40000 + mask = () + } ) diff --git a/etc/examples/nodes/ethercat.conf b/etc/examples/nodes/ethercat.conf index c60b4433a..4081a5701 100644 --- a/etc/examples/nodes/ethercat.conf +++ b/etc/examples/nodes/ethercat.conf @@ -2,44 +2,44 @@ # SPDX-License-Identifier: Apache-2.0 ethercat = { - coupler = { - position = 0 - vendor_id = 0x00000002 # Backhoff - product_code = 0x044c2c52 # EK1100 - } + coupler = { + position = 0 + vendor_id = 0x00000002 # Beckhoff + product_code = 0x044c2c52 # EK1100 + } - alias = 0 - master = 0 + alias = 0 + master = 0 } nodes = { - ethercat_node = { - type = "ethercat" + ethercat_node = { + type = "ethercat" - rate = 1000.0 # Rate of master cyclic task + rate = 1000.0 # Rate of master cyclic task - # Analog Input Slave - in = { - num_channels = 8 - range = 10.0 # -10.0 V to +10.0 V + # Analog Input Slave + in = { + num_channels = 8 + range = 10.0 # -10.0 V to +10.0 V - position = 2 - vendor_id = 0x00000002 # Beckhoff - product_code = 0x0bc03052 # EL3008 + position = 2 + vendor_id = 0x00000002 # Beckhoff + product_code = 0x0bc03052 # EL3008 - # PDOs are currently hardcoded! - } + # PDOs are currently hardcoded! + } - # Analog Output Slave - out = { - num_channels = 8 - range = 10.0 # -10.0 V to +10.0 V + # Analog Output Slave + out = { + num_channels = 8 + range = 10.0 # -10.0 V to +10.0 V - position = 1 - vendor_id = 0x00000002 # Beckhoff - product_code = 0x0fc63052 # EL4038 + position = 1 + vendor_id = 0x00000002 # Beckhoff + product_code = 0x0fc63052 # EL4038 - # PDOs are currently hardcoded! - } - } + # PDOs are currently hardcoded! + } + } } diff --git a/etc/examples/nodes/example.conf b/etc/examples/nodes/example.conf index 272e9e86f..73a0501a1 100644 --- a/etc/examples/nodes/example.conf +++ b/etc/examples/nodes/example.conf @@ -2,10 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - example_node = { - type = "example" + example_node = { + type = "example" - setting1 = 1 - setting2 = "abc" - } + setting1 = 1 + setting2 = "abc" + } } diff --git a/etc/examples/nodes/exec.conf b/etc/examples/nodes/exec.conf index 0c39377ad..e293b0758 100644 --- a/etc/examples/nodes/exec.conf +++ b/etc/examples/nodes/exec.conf @@ -2,15 +2,15 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - exec_node = { - type = "exec" - format = "villas.human" - flush = true - exec = "tee test" - shell = true - working_directory = "/tmp" - environment = { - MYVAR = "TESTVAL" - } - } + exec_node = { + type = "exec" + format = "villas.human" + flush = true + exec = "tee test" + shell = true + working_directory = "/tmp" + environment = { + MYVAR = "TESTVAL" + } + } } diff --git a/etc/examples/nodes/file.conf b/etc/examples/nodes/file.conf index 16ca5366b..609846ffd 100644 --- a/etc/examples/nodes/file.conf +++ b/etc/examples/nodes/file.conf @@ -2,32 +2,41 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - file_node = { - type = "file" + file_node = { + type = "file" - ### The following settings are specific to the file node-type!! ### + # These options specify the URI where the the files are stored + # The URI accepts all format tokens of (see strftime(3)) + uri = "logs/input.log", + # uri = "logs/output_%F_%T.log" - uri = "logs/input.log", # These options specify the URI where the the files are stored - #uri = "logs/output_%F_%T.log" # The URI accepts all format tokens of (see strftime(3)) + format = "csv" - format = "csv" + in = { + # One of: direct (default), wait, relative, absolute + epoch_mode = "direct" - in = { - epoch_mode = "direct" # One of: direct (default), wait, relative, absolute - epoch = 10 # The interpretation of this value depends on epoch_mode (default is 0). - # Consult the documentation of a full explanation + # The interpretation of this value depends on epoch_mode (default is 0) + # Consult the documentation of a full explanation + epoch = 10 - rate = 2.0 # A constant rate at which the lines of the input files should be read - # A missing or zero value will use the timestamp in the first column - # of the file to determine the pause between consecutive lines. - eof = "rewind" # Rewind the file and start from the beginning. + # A constant rate at which the lines of the input files should be read + # A missing or zero value will use the timestamp in the first column + # of the file to determine the pause between consecutive lines + rate = 2.0 - buffer_size = 0 # Creates a stream buffer if value is positive - }, - out = { - flush = false # Flush or upload contents of the file every time new samples are sent. + # Rewind the file and start from the beginning + eof = "rewind" - buffer_size = 0 # Creates a stream buffer if value is positive - } - } + # Creates a stream buffer if value is positive + buffer_size = 0 + }, + out = { + # Flush or upload contents of the file every time new samples are sent + flush = false + + # Creates a stream buffer if value is positive + buffer_size = 0 + } + } } diff --git a/etc/examples/nodes/fpga.conf b/etc/examples/nodes/fpga.conf index e7ba7b1a3..c1eb49033 100644 --- a/etc/examples/nodes/fpga.conf +++ b/etc/examples/nodes/fpga.conf @@ -2,32 +2,33 @@ # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } fpgas = { - vc707 = { - interface = "pcie", - id = "10ee:7021", - slot = "0000:88:00.0", - do_reset = true, - ips = "../../../fpga/etc/vc707-xbar-pcie/vc707-xbar-pcie.json", - polling = false, - } + vc707 = { + interface = "pcie" + id = "10ee:7021" + slot = "0000:88:00.0" + do_reset = true + ips = "../../fpga/etc/vc707-xbar-pcie/vc707-xbar-pcie-dino-v2.json" + polling = false + } } nodes = { - fpga_0 = { - type = "fpga", - card = "vc707" - connect = ["0->3", "3->dma", "0<-dma"] - } + fpga_0 = { + type = "fpga" + card = "vc707" + connect = ["0->3", "3->dma", "0<-dma"] + timestep = 10e-3 + } } paths = ( - { - in = "fpga_0" - out = "fpga_0" - hooks = ({ type = "print"}) - } + { + in = "fpga_0" + out = "fpga_0" + hooks = ({ type = "print"}) + } ) diff --git a/etc/examples/nodes/iec60870-5-104-sequence.conf b/etc/examples/nodes/iec60870-5-104-sequence.conf index d10e1d057..673c91640 100644 --- a/etc/examples/nodes/iec60870-5-104-sequence.conf +++ b/etc/examples/nodes/iec60870-5-104-sequence.conf @@ -2,24 +2,24 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - iec104_node_seq = { - type = "iec60870-5-104" - address = "0.0.0.0" - port = 2404 - ca = 1 - out = { - # Create a sequence of 5 floats with identical IOAs - signals = { - asdu_type_id = "M_ME_NA_1" - ioa = 4202852 - count = 5 - } + iec104_node_seq = { + type = "iec60870-5-104" + address = "0.0.0.0" + port = 2404 + ca = 1 + out = { + # Create a sequence of 5 floats with identical IOAs + signals = { + asdu_type_id = "M_ME_NA_1" + ioa = 4202852 + count = 5 + } - # Interpret the duplicate IOAs as a sequence by incrementing the - # IOA with each duplication. This only applies to two adjacent - # signals with the same IOA. Specifying an IOA twice with other - # IOAs inbetween is an error. - duplicate_ioa_is_sequence = true - } - } + # Interpret the duplicate IOAs as a sequence by incrementing the + # IOA with each duplication. This only applies to two adjacent + # signals with the same IOA. Specifying an IOA twice with other + # IOAs inbetween is an error + duplicate_ioa_is_sequence = true + } + } } diff --git a/etc/examples/nodes/iec60870-5-104.conf b/etc/examples/nodes/iec60870-5-104.conf index f0711c899..db36d1beb 100644 --- a/etc/examples/nodes/iec60870-5-104.conf +++ b/etc/examples/nodes/iec60870-5-104.conf @@ -3,47 +3,49 @@ nodes = { - iec104_node = { - type = "iec60870-5-104" + iec104_node = { + type = "iec60870-5-104" - # Network address and port of the server - # 0.0.0.0 listens on all interfaces - address = "0.0.0.0" - port = 2404 - - # Common address of this IEC104 slave - ca = 41025 - - # Queue sizes for this node - low_priority_queue = 100 - high_priority_queue = 100 + # Network address and port of the server + # 0.0.0.0 listens on all interfaces + address = "0.0.0.0" + port = 2404 - out = { - # Map signals to information object addresses and ASDU data types - # one ASDU per specified asdu_type_id/asdu_type+with_timestamp is - # send for each sample. Signals of the same type are collected - # in a single ASDU. - signals = ( - { - # The ASDU data type - asdu_type = "normalized-float" - # add 56 bit unix timestamp to ASDU - with_timestamp = false - # the information object address of this signal - ioa = 4202832 - }, - { - # Equivalent to the asdu_type above - asdu_type_id = "M_ME_NA_1" - ioa = 4202852 - }, - { - # A boolean value - asdu_type = "single-point" - with_timestamp = true - ioa = 4206948 - } - ) - } - } + # Common address of this IEC104 slave + ca = 41025 + + # Queue sizes for this node + low_priority_queue = 100 + high_priority_queue = 100 + + out = { + # Map signals to information object addresses and ASDU data types + # one ASDU per specified asdu_type_id/asdu_type+with_timestamp is + # send for each sample. Signals of the same type are collected + # in a single ASDU + signals = ( + { + # The ASDU data type + asdu_type = "normalized-float" + + # Add 56 bit unix timestamp to ASDU + with_timestamp = false + + # The information object address of this signal + ioa = 4202832 + }, + { + # Equivalent to the asdu_type above + asdu_type_id = "M_ME_NA_1" + ioa = 4202852 + }, + { + # A boolean value + asdu_type = "single-point" + with_timestamp = true + ioa = 4206948 + } + ) + } + } } diff --git a/etc/examples/nodes/iec61850-8-1.conf b/etc/examples/nodes/iec61850-8-1.conf index 9b77ca4b8..2fbbab3f9 100644 --- a/etc/examples/nodes/iec61850-8-1.conf +++ b/etc/examples/nodes/iec61850-8-1.conf @@ -3,145 +3,145 @@ nodes = { - goose = { - type = "iec61850-8-1" + goose = { + type = "iec61850-8-1" - out = { - # Ethernet interface to publish on - interface = "lo" + out = { + # Ethernet interface to publish on + interface = "lo" - # Array of goose publisher definitions - publishers = ( - { - # Mandatory GOOSE publisher meta data - go_id = "AA1J1Q01A3LD0/LLN0.gcbdata" - go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbdata" - data_set_ref = "AA1J1Q01A3LD0/LLN0$data" - dst_address = "01:0c:cd:01:00:00" - app_id = 2 - conf_rev = 100 - time_allowed_to_live = 11000 + # Array of goose publisher definitions + publishers = ( + { + # Mandatory GOOSE publisher meta data + go_id = "AA1J1Q01A3LD0/LLN0.gcbdata" + go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbdata" + data_set_ref = "AA1J1Q01A3LD0/LLN0$data" + dst_address = "01:0c:cd:01:00:00" + app_id = 2 + conf_rev = 100 + time_allowed_to_live = 11000 - # Payload description with either constant data or values from a signal - data = ( - { - # Mandatory MMS type - mms_type = "boolean" + # Payload description with either constant data or values from a signal + data = ( + { + # Mandatory MMS type + mms_type = "boolean" - # Name of the signal in the array below - signal = "ABB_cascade_state" - }, - { - # Mandatory MMS type - mms_type = "bitstring" + # Name of the signal in the array below + signal = "ABB_cascade_state" + }, + { + # Mandatory MMS type + mms_type = "bitstring" - # Type meta data - mms_bitstring_size = 13 + # Type meta data + mms_bitstring_size = 13 - # Constant value - value = 2048 - } - ) - }, - { - go_id = "AA1J1Q01A3LD0/LLN0.gcbDataset_1" - go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbDataset_1" - data_set_ref = "AA1J1Q01A3LD0/LLN0$Dataset_1" - dst_address = "01:0c:cd:01:00:01" - app_id = 1 - conf_rev = 300 - time_allowed_to_live = 22000 - data = ( - { - mms_type = "boolean" - signal = "ABB_cascade_state" - }, - { - mms_type = "bitstring" - mms_bitstring_size = 13 - value = 2048 - }, - { - mms_type = "bitstring" - mms_bitstring_size = 2 - value = 0 - }, - { - mms_type = "bitstring" - mms_bitstring_size = 13 - value = 2048 - }, - { - mms_type = "bitstring" - mms_bitstring_size = 13 - value = 2048 - }, - { - mms_type = "bitstring" - mms_bitstring_size = 2 - value = 0 - } - ) - } - ) - signals = ( - { - # The signal name used to identify the signal in a publishers data field - name = "ABB_cascade_state" - type = "boolean" - } - ) - } + # Constant value + value = 2048 + } + ) + }, + { + go_id = "AA1J1Q01A3LD0/LLN0.gcbDataset_1" + go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbDataset_1" + data_set_ref = "AA1J1Q01A3LD0/LLN0$Dataset_1" + dst_address = "01:0c:cd:01:00:01" + app_id = 1 + conf_rev = 300 + time_allowed_to_live = 22000 + data = ( + { + mms_type = "boolean" + signal = "ABB_cascade_state" + }, + { + mms_type = "bitstring" + mms_bitstring_size = 13 + value = 2048 + }, + { + mms_type = "bitstring" + mms_bitstring_size = 2 + value = 0 + }, + { + mms_type = "bitstring" + mms_bitstring_size = 13 + value = 2048 + }, + { + mms_type = "bitstring" + mms_bitstring_size = 13 + value = 2048 + }, + { + mms_type = "bitstring" + mms_bitstring_size = 2 + value = 0 + } + ) + } + ) + signals = ( + { + # The signal name used to identify the signal in a publishers data field + name = "ABB_cascade_state" + type = "boolean" + } + ) + } - in = { - # Ethernet interface to listen on - interface = "lo" + in = { + # Ethernet interface to listen on + interface = "lo" - # Use the goose timestamp for a sample - with_timestamp = true + # Use the goose timestamp for a sample + with_timestamp = true - # List of named subscriber definitions - subscribers = { - relay = { - # Mandatory GoCbRef - go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbdata" + # List of named subscriber definitions + subscribers = { + relay = { + # Mandatory GoCbRef + go_cb_ref = "AA1J1Q01A3LD0/LLN0$GO$gcbdata" - # Optional filter by packet destination MAC address - dst_address = "01:0c:cd:01:00:00" + # Optional filter by packet destination MAC address + dst_address = "01:0c:cd:01:00:00" - # Optional filter by AppID - app_id = 2 + # Optional filter by AppID + app_id = 2 - # Optional trigger specification (either "always" or "change") - # - # "always" = emit an updated sample for each incoming GOOSE message - # "change" = only emit an updated sample when SqNum is 0 - trigger = "change" - } - } + # Optional trigger specification (either "always" or "change") + # + # "always" = emit an updated sample for each incoming GOOSE message + # "change" = only emit an updated sample when SqNum is 0 + trigger = "change" + } + } - signals = ( - { - name = "ABB_relay_state" - type = "boolean" + signals = ( + { + name = "ABB_relay_state" + type = "boolean" - # Mandatory MmsType specification - mms_type = "boolean" + # Mandatory MmsType specification + mms_type = "boolean" - # Mandatory subscriber name - subscriber = "relay" + # Mandatory subscriber name + subscriber = "relay" - # Mandatory index within the received vector of GOOSE values - index = 0 - }, - { - name = "ABB_relay_state_meta_bitset" - type = "integer" - mms_type = "bitstring" - subscriber = "relay" - index = 1 - } - ) - } - } + # Mandatory index within the received vector of GOOSE values + index = 0 + }, + { + name = "ABB_relay_state_meta_bitset" + type = "integer" + mms_type = "bitstring" + subscriber = "relay" + index = 1 + } + ) + } + } } diff --git a/etc/examples/nodes/iec61850-9-2.conf b/etc/examples/nodes/iec61850-9-2.conf index 9f316762f..4fbd00ab7 100644 --- a/etc/examples/nodes/iec61850-9-2.conf +++ b/etc/examples/nodes/iec61850-9-2.conf @@ -2,31 +2,35 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - sampled_values_node = { - type = "iec61850-9-2", + sampled_values_node = { + type = "iec61850-9-2" - interface = "lo", - dst_address = "01:0c:cd:01:00:01", - - out = { - signals = ( - { iec_type = "float32" }, - { iec_type = "float64" }, - { iec_type = "int8" }, - { iec_type = "int32" } - ) - - svid = "test1234", - smpmod = "samples_per_second", - confrev = 55 - }, - in = { - signals = ( - { iec_type = "float32" }, - { iec_type = "float64" }, - { iec_type = "int8" }, - { iec_type = "int32" } - ) - } - } + interface = "lo" + dst_address = "01:0c:cd:01:00:01" + + out = { + signals = ( + { iec_type = "float32" }, + { iec_type = "float64" }, + { iec_type = "int8" }, + { iec_type = "int32" } + ) + + sv_id = "test1234" + smp_mod = "samples_per_second" + smp_synch = "local_clock" + conf_rev = 55 + }, + + in = { + signals = ( + { iec_type = "float32" }, + { iec_type = "float64" }, + { iec_type = "int8" }, + { iec_type = "int32" } + ) + + check_dst_address = false + } + } } diff --git a/etc/examples/nodes/infiniband.conf b/etc/examples/nodes/infiniband.conf index 61a444083..ed4675afb 100644 --- a/etc/examples/nodes/infiniband.conf +++ b/etc/examples/nodes/infiniband.conf @@ -2,73 +2,73 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - results = { - type = "file", + results = { + type = "file", - uri = "logs/ib_results-%Y%m%d_%H-%M-%S.log", - }, + uri = "logs/ib_results-%Y%m%d_%H-%M-%S.log", + }, - siggen = { - type = "signal", + siggen = { + type = "signal", - signal = "mixed", - values = 3, - frequency = 3.0, - rate = 100000.0, - limit = 100000, - }, + signal = "mixed", + values = 3, + frequency = 3.0, + rate = 100000.0, + limit = 100000, + }, - ib_node_source = { - type = "infiniband", + ib_node_source = { + type = "infiniband", - rdma_port_space = "RC", - - in = { - address = "10.0.0.2:1337", + rdma_port_space = "RC", - max_wrs = 8192, - cq_size = 8192, + in = { + address = "10.0.0.2:1337", - vectorize = 1, + max_wrs = 8192, + cq_size = 8192, - buffer_subtraction = 128, - }, + vectorize = 1, - out = { - address = "10.0.0.1:1337", - resolution_timeout = 1000, - - max_wrs = 8192, - cq_size = 256, + buffer_subtraction = 128, + }, - vectorize = 1, + out = { + address = "10.0.0.1:1337", + resolution_timeout = 1000, - send_inline = true, - max_inline_data = 60, + max_wrs = 8192, + cq_size = 256, - use_fallback = true, - } - } + vectorize = 1, - ib_node_target = { - type = "infiniband", + send_inline = true, + max_inline_data = 60, - rdma_port_space = "RC", + use_fallback = true, + } + } - in = { - address = "10.0.0.1:1337", + ib_node_target = { + type = "infiniband", - max_wrs = 8192, - cq_size = 8192, + rdma_port_space = "RC", - vectorize = 1, + in = { + address = "10.0.0.1:1337", - buffer_subtraction = 128, + max_wrs = 8192, + cq_size = 8192, - hooks = ( - { type = "stats", verbose = true } - ) - } - } + vectorize = 1, + + buffer_subtraction = 128, + + hooks = ( + { type = "stats", verbose = true } + ) + } + } } diff --git a/etc/examples/nodes/influxdb.conf b/etc/examples/nodes/influxdb.conf index b4f0ed806..d2b10198c 100644 --- a/etc/examples/nodes/influxdb.conf +++ b/etc/examples/nodes/influxdb.conf @@ -2,10 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - influxdb_node = { - type = "influxdb", + influxdb_node = { + type = "influxdb", - server = "localhost:8089", - key = "villas" - } + server = "localhost:8089", + key = "villas" + } } diff --git a/etc/examples/nodes/kafka.conf b/etc/examples/nodes/kafka.conf index 7ca158fff..8179982b7 100644 --- a/etc/examples/nodes/kafka.conf +++ b/etc/examples/nodes/kafka.conf @@ -2,30 +2,30 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - kafka_node = { - type = "kafka", - - format = "json.kafka", + kafka_node = { + type = "kafka", - server = "localhost:9094", - protocol = "SASL_SSL", - client_id = "villas-node", + format = "json.kafka", - in = { - consume = "test-topic", - group_id = "villas-node" - }, - out = { - produce = "test-topic" - }, + server = "localhost:9094", + protocol = "SASL_SSL", + client_id = "villas-node", - ssl = { - ca = "/etc/ssl/certs/ca.pem", - }, - sasl = { - mechanisms = "SCRAM-SHA-512", - username = "scram-sha-512-usr", - password = "scram-sha-512-pwd" - } - } + in = { + consume = "test-topic", + group_id = "villas-node" + }, + out = { + produce = "test-topic" + }, + + ssl = { + ca = "/etc/ssl/certs/ca.pem", + }, + sasl = { + mechanisms = "SCRAM-SHA-512", + username = "scram-sha-512-usr", + password = "scram-sha-512-pwd" + } + } } diff --git a/etc/examples/nodes/loopback.conf b/etc/examples/nodes/loopback.conf index 25870a3a9..ab1ff9ebf 100644 --- a/etc/examples/nodes/loopback.conf +++ b/etc/examples/nodes/loopback.conf @@ -2,10 +2,15 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - loopback_node = { - type = "loopback", # A loopback node will receive exactly the same data which has been sent to it. - # The internal implementation is based on queue. - queuelen = 1024, # The queue length of the internal queue which buffers the samples. - mode = "polling" # Use busy polling for synchronization of the read and write side of the queue - } + loopback_node = { + # A loopback node will receive exactly the same data which has been sent to it + type = "loopback", + + # The internal implementation is based on queue + # The queue length of the internal queue which buffers the samples + queuelen = 1024, + + # Use busy polling for synchronization of the read and write side of the queue + mode = "polling" + } } diff --git a/etc/examples/nodes/modbus.conf b/etc/examples/nodes/modbus.conf index 4f8bf3a96..3c7fe9d59 100644 --- a/etc/examples/nodes/modbus.conf +++ b/etc/examples/nodes/modbus.conf @@ -2,167 +2,167 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - modbus_node = { - type = "modbus" + modbus_node = { + type = "modbus" - # Required transport type. Can be either "rtu" or "tcp" - transport = "tcp" + # Required transport type. Can be either "rtu" or "tcp" + transport = "tcp" - # Optional timeout in seconds when waiting for responses from a modbus server. - # Default is 1.0. - response_timeout = 1.0 + # Optional timeout in seconds when waiting for responses from a modbus server + # Default is 1.0 + response_timeout = 1.0 - # - # Settings for transport = "tcp". - # + # + # Settings for transport = "tcp" + # - # Required remote IP address. - remote = "127.0.0.1" + # Required remote IP address + remote = "127.0.0.1" - # Optional remote port. - # Default is 502. - port = 502 + # Optional remote port + # Default is 502 + port = 502 - # - # Settings for transport = "rtu" - # + # + # Settings for transport = "rtu" + # - # Required device file. - device = "/dev/ttyS0" + # Required device file + device = "/dev/ttyS0" - # Required baudrate. - baudrate = 9600 + # Required baudrate + baudrate = 9600 - # Required parity. One of "none", "even" and "odd" - parity = "none" + # Required parity. One of "none", "even" and "odd" + parity = "none" - # Required data bits. One of 5, 6, 7, 8 - data_bits = 5 + # Required data bits. One of 5, 6, 7, 8 + data_bits = 5 - # Required stop bits. One of 1, 2 - stop_bits = 1 + # Required stop bits. One of 1, 2 + stop_bits = 1 - # The modbus unit ID. - # Required for transport = "rtu". - # Optional for transport = "tcp". - unit = 1 + # The modbus unit ID + # Required for transport = "rtu" + # Optional for transport = "tcp" + unit = 1 - # Optional polling rate for the modbus remote reads. - # Defaults to 10. - rate = 10 + # Optional polling rate for the modbus remote reads + # Defaults to 10 + rate = 10 - in = { - signals = ( - # A 32-bit IEEE 754 floating point value. - # This spans 2 registers. - { - # Required type = "float". - type = "float" + in = { + signals = ( + # A 32-bit IEEE 754 floating point value + # This spans 2 registers + { + # Required type = "float" + type = "float" - # Required address of the lowest register. - address = 0x50 + # Required address of the lowest register + address = 0x50 - # Optional endianess for joining the 2 16-bit registers into a 32-bit value. - # Defaults to "big". - word_endianess = "big" + # Optional endianess for joining the 2 16-bit registers into a 32-bit value + # Defaults to "big" + word_endianess = "big" - # Optional endianess for the 2 bytes within a register. - # Defaults to "big". - byte_endianess = "big" + # Optional endianess for the 2 bytes within a register + # Defaults to "big" + byte_endianess = "big" - # Optional scale that should be applied to the integer value. - # Defaults to 1. - scale = 10 + # Optional scale that should be applied to the integer value + # Defaults to 1 + scale = 10 - # Optional offset that should be applied to the integer value after scaling. - # Defaults to 0. - offset = 2 - }, - # A single bit within a register as a boolean value. - { - # Required type = "boolean". - type = "boolean" + # Optional offset that should be applied to the integer value after scaling + # Defaults to 0 + offset = 2 + }, + # A single bit within a register as a boolean value + { + # Required type = "boolean" + type = "boolean" - # Required address of the register. - address = 0x54 + # Required address of the register + address = 0x54 - # Required bit within the register. - # Starting at 0. - bit = 0 - }, - # An integer value. - # This may span multiple registers. - { - # Required type = "integer". - type = "integer" + # Required bit within the register + # Starting at 0 + bit = 0 + }, + # An integer value + # This may span multiple registers + { + # Required type = "integer" + type = "integer" - # Required address of the lowest register. - address = 0x52 + # Required address of the lowest register + address = 0x52 - # Optional number of registers that should be joined to form the value. - # Defaults to 1. - integer_registers = 1 + # Optional number of registers that should be joined to form the value + # Defaults to 1 + integer_registers = 1 - # Optional endianess for joining the 16-bit registers into a 32-bit value. - # Defaults to "big". - word_endianess = "big" + # Optional endianess for joining the 16-bit registers into a 32-bit value + # Defaults to "big" + word_endianess = "big" - # Optional endianess for the 2 bytes within a register. - # Defaults to "big". - byte_endianess = "big" - }, - # An float value created by reading an integer and applying an optional offset and scale. - # This may span multiple registers. - { - # Required type = "float". - type = "float" + # Optional endianess for the 2 bytes within a register + # Defaults to "big" + byte_endianess = "big" + }, + # An float value created by reading an integer and applying an optional offset and scale + # This may span multiple registers + { + # Required type = "float" + type = "float" - # Required address of the lowest register. - address = 0x52 + # Required address of the lowest register + address = 0x52 - # Required number of registers that should be joined to form the value. - # A "float" value without the "integer_registers" settings is considered an IEEE 754 float, spanning 2 registers. - integer_registers = 1 + # Required number of registers that should be joined to form the value + # A "float" value without the "integer_registers" settings is considered an IEEE 754 float, spanning 2 registers + integer_registers = 1 - # Optional endianess for joining the 16-bit registers into a 32-bit value. - # Defaults to "big". - word_endianess = "big" + # Optional endianess for joining the 16-bit registers into a 32-bit value + # Defaults to "big" + word_endianess = "big" - # Optional endianess for the 2 bytes within a register. - # Defaults to "big". - byte_endianess = "big" + # Optional endianess for the 2 bytes within a register + # Defaults to "big" + byte_endianess = "big" - # Optional scale that should be applied to the integer value. - # Defaults to 1. - scale = 10 + # Optional scale that should be applied to the integer value + # Defaults to 1 + scale = 10 - # Optional offset that should be applied to the integer value after scaling. - # Defaults to 0. - offset = 2 - } - ) - } + # Optional offset that should be applied to the integer value after scaling + # Defaults to 0 + offset = 2 + } + ) + } - out = { - signals = ( - # All register mappings described for "in" except for "boolean" are supported in the "out" signals. - { - type = "float" - address = 0x50 + out = { + signals = ( + # All register mappings described for "in" except for "boolean" are supported in the "out" signals + { + type = "float" + address = 0x50 - # Scale and offset a applied as attributes of the register that is written to. - # This means the value written to "register" for a "signal" with "offset" and "scale" will be: - # - # register = (signal - offset) / scale - # - # It is fairly common to specify a scale and offset for modbus registers in a device manual. - # You should be able to plug those values into this configuration without conversion. - scale = 10 - offset = 2 - }, - ) - } - } + # Scale and offset a applied as attributes of the register that is written to + # This means the value written to "register" for a "signal" with "offset" and "scale" will be: + # + # register = (signal - offset) / scale + # + # It is fairly common to specify a scale and offset for modbus registers in a device manual + # You should be able to plug those values into this configuration without conversion + scale = 10 + offset = 2 + }, + ) + } + } } diff --git a/etc/examples/nodes/mqtt.conf b/etc/examples/nodes/mqtt.conf index 14e9f6729..9fa35b20b 100644 --- a/etc/examples/nodes/mqtt.conf +++ b/etc/examples/nodes/mqtt.conf @@ -2,32 +2,33 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - mqtt_node = { - type = "mqtt", - - format = "protobuf", - - username = "guest", - password = "guest", - host = "localhost", - port = 1883, - - keepalive = 5, # Send ping every 5 seconds to keep connection alive - retain = false, - qos = 0, + mqtt_node = { + type = "mqtt", - out = { - publish = "test-topic" - }, - in = { - subscribe = "test-topic" - }, - ssl = { - enabled = false, - insecure = true, - cafile = "/etc/ssl/certs/ca-bundle.crt", - certfile = "/etc/ssl/certs/my.crt", - keyfile = "/etc/ssl/keys/my.key" - } - } + format = "protobuf", + + username = "guest", + password = "guest", + host = "localhost", + port = 1883, + + # Send ping every 5 seconds to keep connection alive + keepalive = 5, + retain = false, + qos = 0, + + out = { + publish = "test-topic" + }, + in = { + subscribe = "test-topic" + }, + ssl = { + enabled = false, + insecure = true, + cafile = "/etc/ssl/certs/ca-bundle.crt", + certfile = "/etc/ssl/certs/my.crt", + keyfile = "/etc/ssl/keys/my.key" + } + } } diff --git a/etc/examples/nodes/nanomsg.conf b/etc/examples/nodes/nanomsg.conf index d270ed2b1..40e751d6e 100644 --- a/etc/examples/nodes/nanomsg.conf +++ b/etc/examples/nodes/nanomsg.conf @@ -2,22 +2,27 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - nanomsg_node = { - type = "nanomsg", + nanomsg_node = { + type = "nanomsg", - out = { - endpoints = [ - "tcp://*:12000", # TCP socket - "ipc:///tmp/test.ipc", # Interprocess communication - "inproc://test" # Inprocess communication - ], - } - in = { - endpoints = [ - "tcp://127.0.0.1:12000", - "ipc:///tmp/test.ipc", - "inproc://test" - ] - } - } + out = { + endpoints = [ + # TCP socket + "tcp://*:12000", + + # Interprocess communication + "ipc:///tmp/test.ipc", + + # Inprocess communication + "inproc://test" + ], + } + in = { + endpoints = [ + "tcp://127.0.0.1:12000", + "ipc:///tmp/test.ipc", + "inproc://test" + ] + } + } } diff --git a/etc/examples/nodes/netem.conf b/etc/examples/nodes/netem.conf index 7d8067020..41c4b09bf 100644 --- a/etc/examples/nodes/netem.conf +++ b/etc/examples/nodes/netem.conf @@ -2,29 +2,40 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node = { # The dictionary is indexed by the name of the node. - type = "socket", # For a list of available node-types run: 'villas-node -h' + udp_node = { + type = "socket", - ### The following settings are specific to the socket node-type!! ### + format = "gtnet", - format = "gtnet", # For a list of available node-types run: 'villas-node -h' + in = { + address = "127.0.0.1:12001" + }, + out = { + address = "127.0.0.1:12000", - in = { - address = "127.0.0.1:12001" # This node only received messages on this IP:Port pair - }, - out = { - address = "127.0.0.1:12000", # This node sends outgoing messages to this IP:Port pair - - netem = { # Network emulation settings - enabled = true, - # Those settings can be specified for each node individually! - delay = 100000, # Additional latency in microseconds - jitter = 30000, # Jitter in uS - distribution = "normal", # Distribution of delay: uniform, normal, pareto, paretonormal - loss = 10 # Packet loss in percent - duplicate = 10, # Duplication in percent - corrupt = 10 # Corruption in percent - } - } - } + # Network emulation settings + # Those settings can be specified for each node individually! + netem = { + enabled = true, + + # Additional latency in microseconds + delay = 100000, + + # Jitter in uS + jitter = 30000, + + # Distribution of delay: uniform, normal, pareto, paretonormal + distribution = "normal", + + # Packet loss in percent + loss = 10 + + # Duplication in percent + duplicate = 10, + + # Corruption in percent + corrupt = 10 + } + } + } } diff --git a/etc/examples/nodes/ngsi.conf b/etc/examples/nodes/ngsi.conf index 8b99fd29b..8c468e36f 100644 --- a/etc/examples/nodes/ngsi.conf +++ b/etc/examples/nodes/ngsi.conf @@ -2,43 +2,48 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - ngsi_node = { - type = "ngsi", + ngsi_node = { + type = "ngsi", - ### The following settings are specific to the ngsi node-type!! ### + # The HTTP REST API endpoint of the FIRWARE context broker + endpoint = "http://46.101.131.212:1026", - # The HTTP REST API endpoint of the FIRWARE context broker - endpoint = "http://46.101.131.212:1026", + # Add an 'Auth-Token' token header to each request + access_token = "aig1aaQuohsh5pee9uiC2Bae3loSh9wu" - access_token: "aig1aaQuohsh5pee9uiC2Bae3loSh9wu" # Add an 'Auth-Token' token header to each request + entity_id = "S3_ElectricalGrid", + entity_type = "ElectricalGridMonitoring", - entity_id = "S3_ElectricalGrid", - entity_type = "ElectricalGridMonitoring", + # Create the NGSI entities during startup + create = true - create = true # Create the NGSI entities during startup + # Rate at which we poll the broker for updates + rate = 0.1 - rate = 0.1 # Rate at which we poll the broker for updates - timeout = 1, # Timeout of HTTP request in seconds (default is 1, must be smaller than 1 / rate) - verify_ssl = false, # Verification of SSL server certificates (default is true) + # Timeout of HTTP request in seconds (default is 1, must be smaller than 1 / rate) + timeout = 1, - in = { - signals = ( - { - name = "attr1", - ngsi_attribute_name = "attr1", # defaults to signal 'name' - ngsi_attribute_type = "Volts", # default to signal 'unit' - ngsi_attribute_metadatas = ( - { name="accuracy", type="percent", value="5" } - ) - } - ) - } + # Verification of SSL server certificates (default is true) + verify_ssl = false, - out = { - signals = ( - { name="PTotalLosses", unit="MW" }, - { name="QTotalLosses", unit="Mvar" } - ) - } - } + in = { + signals = ( + { + name = "attr1", + ngsi_attribute_name = "attr1", # Defaults to signal 'name' + ngsi_attribute_type = "Volts", # Default to signal 'unit' + ngsi_attribute_metadatas = ( + { name="accuracy", type="percent", value="5" } + ) + } + ) + } + + out = { + signals = ( + { name="PTotalLosses", unit="MW" }, + { name="QTotalLosses", unit="Mvar" } + ) + } + } } diff --git a/etc/examples/nodes/opal.conf b/etc/examples/nodes/opal.conf index 96d96c199..40ace6a7e 100644 --- a/etc/examples/nodes/opal.conf +++ b/etc/examples/nodes/opal.conf @@ -2,38 +2,17 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - opal_node = { # The server can be started as an Asynchronous process - type = "opal", # from within an OPAL-RT model. + # The server can be started as an Asynchronous process + # from within an OPAL-RT model + opal_node = { + type = "opal", - ### The following settings are specific to the opal node-type!! ### + # It's possible to have multiple send / recv Icons per model + send_id = 1, - send_id = 1, # It's possible to have multiple send / recv Icons per model - recv_id = 1, # Specify the ID here. - reply = true - }, - file_node = { - type = "file", + # Specify the ID here + recv_id = 1, - ### The following settings are specific to the file node-type!! ### - - uri = "logs/input.log", # These options specify the path prefix where the the files are stored - - in = { - epoch_mode = "direct" # One of: direct (default), wait, relative, absolute - epoch = 10 # The interpretation of this value depends on epoch_mode (default is 0). - # Consult the documentation of a full explanation - - rate = 2.0 # A constant rate at which the lines of the input files should be read - # A missing or zero value will use the timestamp in the first column - # of the file to determine the pause between consecutive lines. - - buffer_size = 1000000 - - eof = "rewind" # One of: rewind, exit (default) or wait - }, - out = { - flush = true - buffer_size = 1000000 - } - } + reply = true + } } diff --git a/etc/examples/nodes/redis.conf b/etc/examples/nodes/redis.conf index 3d2ad5317..d17862d57 100644 --- a/etc/examples/nodes/redis.conf +++ b/etc/examples/nodes/redis.conf @@ -2,41 +2,52 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - redis_node = { - type = "redis", + redis_node = { + type = "redis", - format = "json", # only valid for mode = 'channel' and 'key' - # With mode = 'hash' we will use a simple human readable format + # Only valid for mode = 'channel' and 'key' + # With mode = 'hash' we will use a simple human readable format + format = "json", - key = "my_key" # The Redis key to be used for mode = 'key' or 'hash' (default is the node name) - channel = "my_channel" # the Redis channel tp be used for mode = 'channel' (default is the node name) + # The Redis key to be used for mode = 'key' or 'hash' (default is the node name) + key = "my_key" - mode = "key", # one of: - # - 'channel' (publish/subscribe) - # - 'key' (set/get) - # - 'hash' (hmset/hgetall) + # The Redis channel tp be used for mode = 'channel' (default is the node name) + channel = "my_channel" - notify = false # Whether or not to use Redis keyspace event notifications to get notified about updates - - rate = 1.0 # The polling rate when notify = false + # One of: + # - 'channel' (publish/subscribe) + # - 'key' (set/get) + # - 'hash' (hmset/hgetall) + mode = "key", - uri = "tcp://localhost:6379/0", # The Redis connection URI + # Whether or not to use Redis keyspace event notifications to get notified about updates + notify = false - # host = "localhost" # Alternatively the connection options can be specified independently - # port = 6379 # Note: options here will overwrite the respective part of the URI if both are given. - # db = 0 + # The polling rate when notify = false + rate = 1.0 - # path = "/var/run/redis.sock" + # The Redis connection URI + uri = "tcp://localhost:6379/0", - # user = "guest", - # password = "guest" + # Alternatively the connection options can be specified independently + # host = "localhost" - # ssl = { - # enabled: true - # cacert: "/etc/ssl/certs/ca-certificates.crt", - # cacertdir: "/etc/ssl/certs" - # cert: "./my_cert.crt", - # key, "./my_key.key" - # } - } + # Note: options here will overwrite the respective part of the URI if both are given + # port = 6379 + # db = 0 + + # path = "/var/run/redis.sock" + + # user = "guest", + # password = "guest" + + # ssl = { + # enabled = true + # cacert = "/etc/ssl/certs/ca-certificates.crt", + # cacertdir = "/etc/ssl/certs" + # cert = "./my_cert.crt", + # key = "./my_key.key" + # } + } } diff --git a/etc/examples/nodes/rtp.conf b/etc/examples/nodes/rtp.conf index e88889b8e..b7120cbf4 100644 --- a/etc/examples/nodes/rtp.conf +++ b/etc/examples/nodes/rtp.conf @@ -2,51 +2,55 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - rtp_node = { - type = "rtp" + rtp_node = { + type = "rtp" - format = { - type = "raw" - bits = 32 - endianess = "big" - } + format = { + type = "raw" + bits = 32 + endianess = "big" + } - rtcp = false + rtcp = false - aimd = { - a = 10, - b = 0.5 + aimd = { + a = 10, + b = 0.5 - Kp = 1.0 - Ki = 0.0 - Kd = 0 + Kp = 1.0 + Ki = 0.0 + Kd = 0 - rate_min = 100 - rate_init = 2000 - rate_source = 10000 + rate_min = 100 + rate_init = 2000 + rate_source = 10000 - log = "aimd-rates-%Y_%m_%d_%s.log" + log = "aimd-rates-%Y_%m_%d_%s.log" - hook_type = "limit_rate" - } + hook_type = "limit_rate" + } - in = { - address = "0.0.0.0:12000", - signals = { - count = 3 - type = "float" - } - } + in = { + address = "0.0.0.0:12000", + signals = { + count = 3 + type = "float" + } + } - out = { - address = "127.0.0.1:12000" + out = { + address = "127.0.0.1:12000" - netem = { # Network emulation settings - enabled = false, - - delay = 100000, # Additional latency in microseconds - loss = 10 # Packet loss in percent - } - } - } + # Network emulation settings + netem = { + enabled = false, + + # Additional latency in microseconds + delay = 100000, + + # Packet loss in percent + loss = 10 + } + } + } } diff --git a/etc/examples/nodes/shmem.conf b/etc/examples/nodes/shmem.conf index ad1e98ae3..487a5f1af 100644 --- a/etc/examples/nodes/shmem.conf +++ b/etc/examples/nodes/shmem.conf @@ -2,22 +2,27 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - shmem_node = { - type = "shmem", - - in = { - name = "sn1_in" - }, # Name of shared memory segment for receiving side - out = { - name = "sn1_in" # Name of shared memory segment for sending side - }, + shmem_node = { + type = "shmem", - queuelen = 1024, # Length of the queues - mode = "pthread", # We can busy-wait or use pthread condition variables for synchronizations - - # Execute an external process when starting the node which - # then starts the other side of this shared memory channel - # Usually we also pass the shmem names as parameters. - exec = [ "villas-shmem", "sn1_in", "sn1_out" ] - } + in = { + # Name of shared memory segment for receiving side + name = "sn1_in" + }, + out = { + # Name of shared memory segment for sending side + name = "sn1_in" + }, + + # Length of the queues + queuelen = 1024, + + # We can busy-wait or use pthread condition variables for synchronizations + mode = "pthread", + + # Execute an external process when starting the node which + # then starts the other side of this shared memory channel + # Usually we also pass the shmem names as parameters + exec = [ "villas-shmem", "sn1_in", "sn1_out" ] + } } diff --git a/etc/examples/nodes/signal-v2.conf b/etc/examples/nodes/signal-v2.conf index 03c89b50b..a80b9fedb 100644 --- a/etc/examples/nodes/signal-v2.conf +++ b/etc/examples/nodes/signal-v2.conf @@ -2,32 +2,38 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - signal_node = { - type = "signal.v2", + signal_node = { + type = "signal.v2", - rate = 10.0 - realtime = true, # Wait between emitting each sample - limit = 1000, # Only emit 1000 samples, then stop - monitor_missed = true # Count and warn about missed steps + rate = 10.0 - in = { - signals = ( - { name = "sine1", signal = "sine", amplitude = 123.456, frequency = 10, offset = 1.0 }, - { name = "sine2", signal = "sine", amplitude = 12.456, frequency = 20, offset = 10.0 }, - { name = "sine3", signal = "sine", amplitude = 2, frequency = 1, offset = 100.0 }, - { name = "random1", signal = "random", amplitude = 2, stddev = 2, offset = 13.0 }, - { name = "pulse1", signal = "pulse", frequency = 1.0, pulse_width = 1, pulse_high = 100, pulse_low = 50 } - ) - } - }, - signal_node2 = { - type = "signal.v2", + # Wait between emitting each sample + realtime = true, - in = { - signals = { - count = 8, - signal = "mixed" - } - } - } + # Only emit 1000 samples, then stop + limit = 1000, + + # Count and warn about missed steps + monitor_missed = true + + in = { + signals = ( + { name = "sine1", signal = "sine", amplitude = 123.456, frequency = 10, offset = 1.0 }, + { name = "sine2", signal = "sine", amplitude = 12.456, frequency = 20, offset = 10.0 }, + { name = "sine3", signal = "sine", amplitude = 2, frequency = 1, offset = 100.0 }, + { name = "random1", signal = "random", amplitude = 2, stddev = 2, offset = 13.0 }, + { name = "pulse1", signal = "pulse", frequency = 1.0, pulse_width = 1, pulse_high = 100, pulse_low = 50 } + ) + } + }, + signal_node2 = { + type = "signal.v2", + + in = { + signals = { + count = 8, + signal = "mixed" + } + } + } } diff --git a/etc/examples/nodes/signal.conf b/etc/examples/nodes/signal.conf index b25fe9d59..8501f7bd8 100644 --- a/etc/examples/nodes/signal.conf +++ b/etc/examples/nodes/signal.conf @@ -2,20 +2,37 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - signal_node = { - type = "signal", + signal_node = { + type = "signal", - # One of "sine", "square", "ramp", "triangle", "random", "mixed", "counter" - signal = [ "sine", "pulse", "square" ], + # One of "sine", "square", "ramp", "triangle", "random", "mixed", "counter" + signal = [ "sine", "pulse", "square" ], - values = 3, # Number of values per sample - amplitude = [ 1.2, 0.0, 4.0 ], # Amplitude of generated signals - frequency = 10, # Frequency of generated signals - stddev = 2, # Standard deviation of random signals (normal distributed) - rate = 10.0, # Sample rate - offset = 1.0, # Constant offset - realtime = true, # Wait between emitting each sample - limit = 1000, # Only emit 1000 samples, then stop - monitor_missed = true # Count and warn about missed steps - } + # Number of values per sample + values = 3, + + # Amplitude of generated signals + amplitude = [ 1.2, 0.0, 4.0 ], + + # Frequency of generated signals in Hz + frequency = 10, + + # Standard deviation of random signals (normal distributed) + stddev = 2, + + # Sample rate in Hz + rate = 10.0, + + # Constant offset + offset = 1.0, + + # Wait between emitting each sample + realtime = true, + + # Only emit 1000 samples, then stop + limit = 1000, + + # Count and warn about missed steps + monitor_missed = true + } } diff --git a/etc/examples/nodes/socket.conf b/etc/examples/nodes/socket.conf index 68173f1ce..b83d5e911 100644 --- a/etc/examples/nodes/socket.conf +++ b/etc/examples/nodes/socket.conf @@ -2,78 +2,94 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node = { # The dictionary is indexed by the name of the node. - type = "socket", # For a list of available node-types run: 'villas-node -h' - vectorize = 30, # Receive and sent 30 samples per message (combining). - samplelen = 10 # The maximum number of samples this node can receive + udp_node = { + type = "socket", - builtin = false, # By default, all nodes will have a few builtin hooks attached to them. - # When collecting statistics or measurements these are undesired. + # Receive and sent 30 samples per message (combining) + vectorize = 30, - ### The following settings are specific to the socket node-type!! ### + # The maximum number of samples this node can receive + samplelen = 10 - layer = "udp", # Layer can be one of: - # - udp Send / receive L4 UDP packets - # - ip Send / receive L3 IP packets - # - eth Send / receive L2 Ethernet frames (IEEE802.3) + # By default, all nodes will have a few builtin hooks attached to them + # When collecting statistics or measurements these are undesired + builtin = false, - format = "gtnet", # For a list of available node-types run: 'villas-node -h' + # Layer can be one of: + # - udp Send / receive L4 UDP packets + # - ip Send / receive L3 IP packets + # - eth Send / receive L2 Ethernet frames (IEEE802.3) + layer = "udp", - in = { - address = "127.0.0.1:12001" # This node only received messages on this IP:Port pair - - verify_source = true # Check if source address of incoming packets matches the remote address. - }, - out = { - address = "127.0.0.1:12000", # This node sends outgoing messages to this IP:Port pair - } - } - ethernet_node = { - type = "socket", # See above. + format = "gtnet", - ### The following settings are specific to the socket node-type!! ### + in = { + # This node only received messages on this IP:Port pair + address = "127.0.0.1:12001" - layer = "eth", - in = { - address = "12:34:56:78:90:AB%lo:12002" - }, - out = { - address = "12:34:56:78:90:AB%lo:12002" - } - }, + # Check if source address of incoming packets matches the remote address + verify_source = true + }, + out = { + # This node sends outgoing messages to this IP:Port pair + address = "127.0.0.1:12000", + } + } - unix_domain_node = { - type = "socket", - layer = "unix", # Datagram UNIX domain sockets require two endpoints - - in = { - address = "/var/run/villas-node/node.sock" - }, - out = { - address = "/var/run/villas-node/client.sock" - } - } + # Raw Ethernet frames + ethernet_node = { + type = "socket", - udp_multicast_node = { # The dictionary is indexed by the name of the node. - type = "socket", # For a list of available node-types run: 'villas-node -h' + layer = "eth", + in = { + address = "12:34:56:78:90:AB%lo:12002" + }, + out = { + address = "12:34:56:78:90:AB%lo:12002" + } + }, - ### The following settings are specific to the socket node-type!! ### + # Datagram UNIX domain sockets require two endpoints + unix_domain_node = { + type = "socket", + layer = "unix", - in = { - address = "127.0.0.1:12001" # This node only received messages on this IP:Port pair + in = { + address = "/var/run/villas-node/node.sock" + }, + out = { + address = "/var/run/villas-node/client.sock" + } + } - multicast = { # IGMP multicast is only support for layer = (ip|udp) - enabled = true, + udp_multicast_node = { + type = "socket", - group = "224.1.2.3", # The multicast group. Must be within 224.0.0.0/4 - interface = "1.2.3.4", # The IP address of the interface which should receive multicast packets. - ttl = 128, # The time to live for outgoing multicast packets. - loop = false, # Whether or not to loopback outgoing multicast packets to the local host. - } - }, - out = { - address = "127.0.0.1:12000", # This node sends outgoing messages to this IP:Port pair - } - } + in = { + # This node only received messages on this IP:Port pair + address = "127.0.0.1:12001" + + # IGMP multicast is only support for layer = (ip|udp) + multicast = { + enabled = true, + + # The multicast group. Must be within 224.0.0.0/4 + group = "224.1.2.3", + + # The IP address of the interface which should receive multicast packets + interface = "1.2.3.4", + + # The time to live for outgoing multicast packets + ttl = 128, + + # Whether or not to loopback outgoing multicast packets to the local host + loop = false, + } + }, + out = { + # This node sends outgoing messages to this IP:Port pair + address = "127.0.0.1:12000", + } + } } diff --git a/etc/examples/nodes/stats.conf b/etc/examples/nodes/stats.conf index 4ce7c5c59..ce501a2ab 100644 --- a/etc/examples/nodes/stats.conf +++ b/etc/examples/nodes/stats.conf @@ -2,28 +2,28 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node = { - type = "socket" + udp_node = { + type = "socket" - in = { - address = "*:12000" - } - out = { - address = "127.0.0.1:12000" - } - } - stats_node = { - type = "stats" - - node = "udp_node" - rate = 2 + in = { + address = "*:12000" + } + out = { + address = "127.0.0.1:12000" + } + } + stats_node = { + type = "stats" - in = { - signals = ( - { name = "one_way_delay_mean", type = "float", stats = "udp_node.owd.mean" }, - { name = "one_way_delay_min", type = "float", stats = "udp_node.owd.lowest" }, - { name = "one_way_delay_max", type = "float", stats = "udp_node.owd.highest" } - ) - } - } + node = "udp_node" + rate = 2 + + in = { + signals = ( + { name = "one_way_delay_mean", type = "float", stats = "udp_node.owd.mean" }, + { name = "one_way_delay_min", type = "float", stats = "udp_node.owd.lowest" }, + { name = "one_way_delay_max", type = "float", stats = "udp_node.owd.highest" } + ) + } + } } diff --git a/etc/examples/nodes/temper.conf b/etc/examples/nodes/temper.conf index 10c9b4447..9fb25c9db 100644 --- a/etc/examples/nodes/temper.conf +++ b/etc/examples/nodes/temper.conf @@ -2,15 +2,15 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - temper_node = { - type = "temper" + temper_node = { + type = "temper" - calibration = { - scale = 1.0 - offset = 0.0 - } + calibration = { + scale = 1.0 + offset = 0.0 + } - bus = 0x1 - port = 0x1 - } + bus = 0x1 + port = 0x1 + } } diff --git a/etc/examples/nodes/test_rtt.conf b/etc/examples/nodes/test_rtt.conf index 7c5006a98..3ed87f740 100644 --- a/etc/examples/nodes/test_rtt.conf +++ b/etc/examples/nodes/test_rtt.conf @@ -2,44 +2,63 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - rtt_node = { # The "test_rtt" node-type runs a set of test cases for varying - type = "test_rtt", # sending rates, number of values and generates statistics. - cooldown = 2, # The cooldown time between each test case in seconds - - prefix = "test_rtt_%y-%m-%d_%H-%M-%S", # An optional prefix in the filename - output = "./results", # The output directory for all results - # The results of each test case will be written to a separate file. - format = "villas.human", # The output format of the result files. - cases = ( # The list of test cases - # Each test case can specify a single or an array of rates and values - # If arrays are used, we will generate multiple test cases with all - # possible combinations - { - rates = 55.0, # The sending rate in Hz - values = [ 5, 10, 20], # The number of values which should be send in each sample - limit = 100 # The number of samples which should be send during this test case - }, - { - rates = [ 5, 10, 30 ], # An array of rates in Hz - values = [ 2, 10, 20 ],# An array of number of values - duration = 5 # The duration of the test case in seconds (depending on the sending rate) - } - ) - } + # The "test_rtt" node-type runs a set of test cases for varying + # sending rates, number of values and generates statistics + # The cooldown time between each test case in seconds + rtt_node = { + type = "test_rtt", + cooldown = 2, + + # An optional prefix in the filename + prefix = "test_rtt_%y-%m-%d_%H-%M-%S", + + # The output directory for all results + # The results of each test case will be written to a separate file + output = "./results", + + # The output format of the result files + format = "villas.human", + + # Shutdown the process after the cooldown phase of the + # last test case has been completed. + shutdown = true; + + # One of: + # - min + # - max + # - at_least_count + # - at_least_duration + # - stop_after_count + # - stop_after_duration + mode = "at_least_count" + + # The list of test cases + # Each test case can specify a single or an array of rates and values + # If arrays are used, we will generate multiple test cases with all + # possible combinations + cases = ( + { + # The sending rate in Hz + rates = 55.0, + + # The number of values which should be send in each sample + values = [ 5, 10, 20], + + # The number of samples which should be send during this test case + count = 100 + }, + { + # An array of sending rates in Hz + rates = [ 5, 10, 30 ], + + # An array of number of values + values = [ 2, 10, 20 ], + + # The duration of the test case in seconds (depending on the sending rate) + duration = 5 + } + ) + } } - -paths = ( - { - # Simple loopback path to test the node - in = "rtt_node" - out = "rtt_node" - - # hooks = ( - # { - # type = "print" - # } - # ) - } -) diff --git a/etc/examples/nodes/uldaq.conf b/etc/examples/nodes/uldaq.conf index bd9bc9c14..f88bd4c3e 100644 --- a/etc/examples/nodes/uldaq.conf +++ b/etc/examples/nodes/uldaq.conf @@ -2,50 +2,50 @@ # SPDX-License-Identifier: Apache-2.0 http = { - enabled = false + enabled = false } nodes = { - ul201 = { - type = "uldaq" - interface_type = "usb" - in = { - range = "bipolar-10", - input_mode = "single-ended" - signals = ( - { name = "ch0", type = "float", channel = 0 } - ) + ul201 = { + type = "uldaq" + interface_type = "usb" + in = { + range = "bipolar-10", + input_mode = "single-ended" + signals = ( + { name = "ch0", type = "float", channel = 0 } + ) - sample_rate = 5000, - vectorize = 100 - } - }, + sample_rate = 5000, + vectorize = 100 + } + }, - vpmu = { - type = "socket", - layer = "udp", + vpmu = { + type = "socket", + layer = "udp", - format = { - type = "raw" - bits = 32 - endianess = "big" - } + format = { + type = "raw" + bits = 32 + endianess = "big" + } - in = { - address = "*:13001" + in = { + address = "*:13001" - signals = () - }, - out = { - vectorize = 100 - address = "10.100.1.125:13000" - } - } + signals = () + }, + out = { + vectorize = 100 + address = "10.100.1.125:13000" + } + } } paths = ( - { - in = "ul201", - out = "vpmu" - } + { + in = "ul201", + out = "vpmu" + } ) diff --git a/etc/examples/nodes/unix_domain.conf b/etc/examples/nodes/unix_domain.conf index ee18dd86a..785262f8e 100644 --- a/etc/examples/nodes/unix_domain.conf +++ b/etc/examples/nodes/unix_domain.conf @@ -2,16 +2,16 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - unix_domain_node = { - type = "socket", - layer = "unix", - format = "protobuf", - - in = { - address = "/var/run/villas-node.server.sock" - }, - out = { - address = "/var/run/villas-node.client.sock" - } - } + unix_domain_node = { + type = "socket", + layer = "unix", + format = "protobuf", + + in = { + address = "/var/run/villas-node.server.sock" + }, + out = { + address = "/var/run/villas-node.client.sock" + } + } } diff --git a/etc/examples/nodes/webrtc.conf b/etc/examples/nodes/webrtc.conf index 077067077..c3cec5a94 100644 --- a/etc/examples/nodes/webrtc.conf +++ b/etc/examples/nodes/webrtc.conf @@ -2,37 +2,37 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - webrtc_node = { - type = "webrtc", + webrtc_node = { + type = "webrtc", - format = "json" + format = "json" - # A unique session identifier which must be shared between two nodes - session = "my-session-name" + # A unique session identifier which must be shared between two nodes + session = "my-session-name" - # Address to the websocket signaling server - server = "https://villas.k8s.eonerc.rwth-aachen.de/ws/signaling" + # Address to the websocket signaling server + server = "https://villas.k8s.eonerc.rwth-aachen.de/ws/signaling" - # Limit the number of times a channel will retransmit data if not successfully delivered. - # This value may be clamped if it exceeds the maximum value supported. - max_retransmits = 0 + # Limit the number of times a channel will retransmit data if not successfully delivered + # This value may be clamped if it exceeds the maximum value supported + max_retransmits = 0 - # Number of seconds to wait for a WebRTC connection before proceeding the start - # of VILLASnode. Mainly used for testing - wait_seconds = 10 # in seconds + # Number of seconds to wait for a WebRTC connection before proceeding the start + # of VILLASnode. Mainly used for testing + wait_seconds = 10 # In seconds - # Indicates if data is allowed to be delivered out of order. - # The default value of false, does not make guarantees that data will be delivered in order. - ordered = false + # Indicates if data is allowed to be delivered out of order + # The default value of false, does not make guarantees that data will be delivered in order + ordered = false - # Setting for Interactive Connectivity Establishment - ice = { - # List of STUN/TURN servers - servers = ( - "stun:stun.0l.de:3478", - "turn:villas:villas@turn.0l.de:3478?transport=udp", - "turn:villas:villas@turn.0l.de:3478?transport=tcp" - ) - } - } + # Setting for Interactive Connectivity Establishment + ice = { + # List of STUN/TURN servers + servers = ( + "stun:stun.0l.de:3478", + "turn:villas:villas@turn.0l.de:3478?transport=udp", + "turn:villas:villas@turn.0l.de:3478?transport=tcp" + ) + } + } } diff --git a/etc/examples/nodes/websocket.conf b/etc/examples/nodes/websocket.conf index 9cc84e964..1f28df9df 100644 --- a/etc/examples/nodes/websocket.conf +++ b/etc/examples/nodes/websocket.conf @@ -2,17 +2,17 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - ws = { - type = "websocket" + ws = { + type = "websocket" - destinations = [ - "ws://someserver:8080/somenode" - ] - } + destinations = [ + "ws://someserver:8080/somenode" + ] + } } http = { - port = 8080 - ssl_cert = "/etc/ssl/certs/mycert.pem" - ssl_private_key= "/etc/ssl/private/mykey.pem" + port = 8080 + ssl_cert = "/etc/ssl/certs/mycert.pem" + ssl_private_key= "/etc/ssl/private/mykey.pem" } diff --git a/etc/examples/nodes/zeromq.conf b/etc/examples/nodes/zeromq.conf index 63674c035..84aa6b527 100644 --- a/etc/examples/nodes/zeromq.conf +++ b/etc/examples/nodes/zeromq.conf @@ -2,30 +2,41 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - zeromq_node = { - type = "zeromq" + zeromq_node = { + type = "zeromq" - pattern = "pubsub" # The ZeroMQ pattern. One of pubsub, radiodish - ipv6 = false # Enable IPv6 support + # The ZeroMQ pattern. One of pubsub, radiodish + pattern = "pubsub" - curve = { # Z85 encoded Curve25519 keys - enabled = false, - public_key = "Veg+Q.V-c&1k>yVh663gQ^7fL($y47gybE-nZP1L" - secret_key = "HPY.+mFuB[jGs@(zZr6$IZ1H1dZ7Ji*j>oi@O?Pc" - } + # Enable IPv6 support + ipv6 = false - in = { - subscribe = "tcp://*:1234" # The subscribe endpoint. - # See http://api.zeromq.org/2-1:zmq-bind for details. - filter = "ab184" # A filter which is prefix matched for each received msg - } - out = { - publish = [ # The publish endpoints. - "tcp://localhost:1235", # See http://api.zeromq.org/2-1:zmq-connect for details. - "tcp://localhost:12444" - ] + # Z85 encoded Curve25519 keys + curve = { + enabled = false, + public_key = "Veg+Q.V-c&1k>yVh663gQ^7fL($y47gybE-nZP1L" + secret_key = "HPY.+mFuB[jGs@(zZr6$IZ1H1dZ7Ji*j>oi@O?Pc" + } - filter = "ab184" # A prefix which is pre-pended to each message. - } - } + in = { + # The subscribe endpoint + # See http://api.zeromq.org/2-1:zmq-bind for details + subscribe = "tcp://*:1234" + + # A filter which is prefix matched for each received msg + filter = "ab184" + } + out = { + # The publish endpoints + # See http://api.zeromq.org/2-1:zmq-connect for details + publish = [ + + "tcp://localhost:1235", + "tcp://localhost:12444" + ] + + # A prefix which is pre-pended to each message + filter = "ab184" + } + } } diff --git a/etc/examples/paths.conf b/etc/examples/paths.conf index e4ea04b3a..b704c6c88 100644 --- a/etc/examples/paths.conf +++ b/etc/examples/paths.conf @@ -2,20 +2,30 @@ # SPDX-License-Identifier: Apache-2.0 paths = ( - { - enabled = true, # Enable this path (default: true) - reverse = true, # Setup a path in the reverse direction as well (default: false) + { + # Enable this path (default: true) + enabled = true, - in = "udp_node", # Name of the node we receive messages from (see node dictionary) - out = "ethernet_node", # Name of the node we send messages to. + # Setup a path in the reverse direction as well (default: false) + reverse = true, - rate = 10.0 # A rate at which this path will be triggered if no input node receives new data + # Name of the node we receive messages from (see node dictionary) + in = "udp_node", - queuelen = 128, - - mode = "all", # When this path should be triggered - # - "all": After all masked input nodes received new data - # - "any": After any of the masked input nodes received new data - mask = [ "udp_node" ], # A list of input nodes which will trigger the path - } + # Name of the node we send messages to + out = "ethernet_node", + + # A rate at which this path will be triggered if no input node receives new data + rate = 10.0 + + queuelen = 128, + + # When this path should be triggered + # - "all": After all masked input nodes received new data + # - "any": After any of the masked input nodes received new data + mode = "all", + + # A list of input nodes which will trigger the path + mask = [ "udp_node" ], + } ) diff --git a/etc/examples/villas-web.conf b/etc/examples/villas-web.conf index c5065f2f0..d8b883e4b 100644 --- a/etc/examples/villas-web.conf +++ b/etc/examples/villas-web.conf @@ -2,33 +2,33 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - sine = { - type = "signal" - - signal = "mixed" - values = 5 - rate = 25 - frequency = 5 - } + sine = { + type = "signal" - web = { - type = "websocket" + signal = "mixed" + values = 5 + rate = 25 + frequency = 5 + } - destinations = [ - "https://villas.k8s.eonerc.rwth-aachen.de//ws/relay/test_data_1" - ] + web = { + type = "websocket" - in = { - signals = ( - { name = "loopback", unit = "pu", init = 13.37, type = "float" } - ) - } - } + destinations = [ + "https://villas.k8s.eonerc.rwth-aachen.de//ws/relay/test_data_1" + ] + + in = { + signals = ( + { name = "loopback", unit = "pu", init = 13.37, type = "float" } + ) + } + } } paths = ( - { - in = "sine" - out = "web" - } + { + in = "sine" + out = "web" + } ) diff --git a/etc/fpga/alveo-xbar-pcie/alveo-xbar-pcie.json b/etc/fpga/alveo-xbar-pcie/alveo-xbar-pcie.json new file mode 100644 index 000000000..689db2c7b --- /dev/null +++ b/etc/fpga/alveo-xbar-pcie/alveo-xbar-pcie.json @@ -0,0 +1,1616 @@ +{ + "axi_dma_0": { + "vlnv": "xilinx.com:ip:axi_dma:7.1", + "parameters": { + "c_s_axi_lite_addr_width": 10, + "c_s_axi_lite_data_width": 32, + "c_dlytmr_resolution": 125, + "c_prmry_is_aclk_async": 0, + "c_enable_multi_channel": 0, + "c_num_mm2s_channels": 1, + "c_num_s2mm_channels": 1, + "c_include_sg": 1, + "c_sg_include_stscntrl_strm": 0, + "c_sg_use_stsapp_length": 0, + "c_sg_length_width": 14, + "c_m_axi_sg_addr_width": 32, + "c_m_axi_sg_data_width": 32, + "c_m_axis_mm2s_cntrl_tdata_width": 32, + "c_s_axis_s2mm_sts_tdata_width": 32, + "c_micro_dma": 0, + "c_include_mm2s": 1, + "c_include_mm2s_sf": 1, + "c_mm2s_burst_size": 16, + "c_m_axi_mm2s_addr_width": 32, + "c_m_axi_mm2s_data_width": 32, + "c_m_axis_mm2s_tdata_width": 32, + "c_include_mm2s_dre": 0, + "c_include_s2mm": 1, + "c_include_s2mm_sf": 1, + "c_s2mm_burst_size": 16, + "c_m_axi_s2mm_addr_width": 32, + "c_m_axi_s2mm_data_width": 32, + "c_s_axis_s2mm_tdata_width": 32, + "c_include_s2mm_dre": 0, + "c_increase_throughput": 0, + "c_family": "virtexuplusHBM", + "component_name": "design_1_axi_dma_0_0", + "c_addr_width": 32, + "c_single_interface": 0, + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 1023 + }, + "memory-view": { + "M_AXI_SG": { + "xdma_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_MM2S": { + "xdma_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_S2MM": { + "xdma_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + } + }, + "ports": [ + { + "role": "initiator", + "target": "axis_switch_0:S00_AXIS", + "name": "MM2S" + }, + { + "role": "target", + "target": "axis_switch_0:M00_AXIS", + "name": "S2MM" + } + ] + }, + "axis_switch_0": { + "vlnv": "xilinx.com:ip:axis_switch:1.1", + "parameters": { + "c_family": "virtexuplusHBM", + "c_num_si_slots": 2, + "c_log_si_slots": 1, + "c_num_mi_slots": 2, + "c_axis_tdata_width": 32, + "c_axis_tid_width": 1, + "c_axis_tdest_width": 1, + "c_axis_tuser_width": 1, + "c_axis_signal_set": 91, + "c_arb_on_max_xfers": 1, + "c_arb_on_num_cycles": 0, + "c_arb_on_tlast": 0, + "c_include_arbiter": 1, + "c_arb_algorithm": 0, + "c_output_reg": 0, + "c_decoder_reg": 1, + "c_m_axis_connectivity_array": 15, + "c_m_axis_basetdest_array": 2, + "c_m_axis_hightdest_array": 2, + "c_routing_mode": 1, + "c_s_axi_ctrl_addr_width": 7, + "c_s_axi_ctrl_data_width": 32, + "c_common_clock": 0, + "num_si": 2, + "num_mi": 2, + "routing_mode": 1, + "has_tready": 1, + "tdata_num_bytes": 4, + "has_tstrb": 0, + "has_tkeep": 1, + "has_tlast": 1, + "tid_width": 0, + "tdest_width": 1, + "tuser_width": 0, + "has_aclken": 0, + "arb_on_max_xfers": 1, + "arb_on_num_cycles": 0, + "arb_on_tlast": 0, + "arb_algorithm": 0, + "decoder_reg": 1, + "output_reg": 0, + "common_clock": 0, + "m00_axis_basetdest": 0, + "m01_axis_basetdest": 1, + "m02_axis_basetdest": 2, + "m03_axis_basetdest": 3, + "m04_axis_basetdest": 4, + "m05_axis_basetdest": 5, + "m06_axis_basetdest": 6, + "m07_axis_basetdest": 7, + "m08_axis_basetdest": 8, + "m09_axis_basetdest": 9, + "m10_axis_basetdest": 10, + "m11_axis_basetdest": 11, + "m12_axis_basetdest": 12, + "m13_axis_basetdest": 13, + "m14_axis_basetdest": 14, + "m15_axis_basetdest": 15, + "m00_axis_hightdest": 0, + "m01_axis_hightdest": 1, + "m02_axis_hightdest": 2, + "m03_axis_hightdest": 3, + "m04_axis_hightdest": 4, + "m05_axis_hightdest": 5, + "m06_axis_hightdest": 6, + "m07_axis_hightdest": 7, + "m08_axis_hightdest": 8, + "m09_axis_hightdest": 9, + "m10_axis_hightdest": 10, + "m11_axis_hightdest": 11, + "m12_axis_hightdest": 12, + "m13_axis_hightdest": 13, + "m14_axis_hightdest": 14, + "m15_axis_hightdest": 15, + "m00_s00_connectivity": 1, + "m00_s01_connectivity": 1, + "m00_s02_connectivity": 1, + "m00_s03_connectivity": 1, + "m00_s04_connectivity": 1, + "m00_s05_connectivity": 1, + "m00_s06_connectivity": 1, + "m00_s07_connectivity": 1, + "m00_s08_connectivity": 1, + "m00_s09_connectivity": 1, + "m00_s10_connectivity": 1, + "m00_s11_connectivity": 1, + "m00_s12_connectivity": 1, + "m00_s13_connectivity": 1, + "m00_s14_connectivity": 1, + "m00_s15_connectivity": 1, + "m01_s00_connectivity": 1, + "m01_s01_connectivity": 1, + "m01_s02_connectivity": 1, + "m01_s03_connectivity": 1, + "m01_s04_connectivity": 1, + "m01_s05_connectivity": 1, + "m01_s06_connectivity": 1, + "m01_s07_connectivity": 1, + "m01_s08_connectivity": 1, + "m01_s09_connectivity": 1, + "m01_s10_connectivity": 1, + "m01_s11_connectivity": 1, + "m01_s12_connectivity": 1, + "m01_s13_connectivity": 1, + "m01_s14_connectivity": 1, + "m01_s15_connectivity": 1, + "m02_s00_connectivity": 1, + "m02_s01_connectivity": 1, + "m02_s02_connectivity": 1, + "m02_s03_connectivity": 1, + "m02_s04_connectivity": 1, + "m02_s05_connectivity": 1, + "m02_s06_connectivity": 1, + "m02_s07_connectivity": 1, + "m02_s08_connectivity": 1, + "m02_s09_connectivity": 1, + "m02_s10_connectivity": 1, + "m02_s11_connectivity": 1, + "m02_s12_connectivity": 1, + "m02_s13_connectivity": 1, + "m02_s14_connectivity": 1, + "m02_s15_connectivity": 1, + "m03_s00_connectivity": 1, + "m03_s01_connectivity": 1, + "m03_s02_connectivity": 1, + "m03_s03_connectivity": 1, + "m03_s04_connectivity": 1, + "m03_s05_connectivity": 1, + "m03_s06_connectivity": 1, + "m03_s07_connectivity": 1, + "m03_s08_connectivity": 1, + "m03_s09_connectivity": 1, + "m03_s10_connectivity": 1, + "m03_s11_connectivity": 1, + "m03_s12_connectivity": 1, + "m03_s13_connectivity": 1, + "m03_s14_connectivity": 1, + "m03_s15_connectivity": 1, + "m04_s00_connectivity": 1, + "m04_s01_connectivity": 1, + "m04_s02_connectivity": 1, + "m04_s03_connectivity": 1, + "m04_s04_connectivity": 1, + "m04_s05_connectivity": 1, + "m04_s06_connectivity": 1, + "m04_s07_connectivity": 1, + "m04_s08_connectivity": 1, + "m04_s09_connectivity": 1, + "m04_s10_connectivity": 1, + "m04_s11_connectivity": 1, + "m04_s12_connectivity": 1, + "m04_s13_connectivity": 1, + "m04_s14_connectivity": 1, + "m04_s15_connectivity": 1, + "m05_s00_connectivity": 1, + "m05_s01_connectivity": 1, + "m05_s02_connectivity": 1, + "m05_s03_connectivity": 1, + "m05_s04_connectivity": 1, + "m05_s05_connectivity": 1, + "m05_s06_connectivity": 1, + "m05_s07_connectivity": 1, + "m05_s08_connectivity": 1, + "m05_s09_connectivity": 1, + "m05_s10_connectivity": 1, + "m05_s11_connectivity": 1, + "m05_s12_connectivity": 1, + "m05_s13_connectivity": 1, + "m05_s14_connectivity": 1, + "m05_s15_connectivity": 1, + "m06_s00_connectivity": 1, + "m06_s01_connectivity": 1, + "m06_s02_connectivity": 1, + "m06_s03_connectivity": 1, + "m06_s04_connectivity": 1, + "m06_s05_connectivity": 1, + "m06_s06_connectivity": 1, + "m06_s07_connectivity": 1, + "m06_s08_connectivity": 1, + "m06_s09_connectivity": 1, + "m06_s10_connectivity": 1, + "m06_s11_connectivity": 1, + "m06_s12_connectivity": 1, + "m06_s13_connectivity": 1, + "m06_s14_connectivity": 1, + "m06_s15_connectivity": 1, + "m07_s00_connectivity": 1, + "m07_s01_connectivity": 1, + "m07_s02_connectivity": 1, + "m07_s03_connectivity": 1, + "m07_s04_connectivity": 1, + "m07_s05_connectivity": 1, + "m07_s06_connectivity": 1, + "m07_s07_connectivity": 1, + "m07_s08_connectivity": 1, + "m07_s09_connectivity": 1, + "m07_s10_connectivity": 1, + "m07_s11_connectivity": 1, + "m07_s12_connectivity": 1, + "m07_s13_connectivity": 1, + "m07_s14_connectivity": 1, + "m07_s15_connectivity": 1, + "m08_s00_connectivity": 1, + "m08_s01_connectivity": 1, + "m08_s02_connectivity": 1, + "m08_s03_connectivity": 1, + "m08_s04_connectivity": 1, + "m08_s05_connectivity": 1, + "m08_s06_connectivity": 1, + "m08_s07_connectivity": 1, + "m08_s08_connectivity": 1, + "m08_s09_connectivity": 1, + "m08_s10_connectivity": 1, + "m08_s11_connectivity": 1, + "m08_s12_connectivity": 1, + "m08_s13_connectivity": 1, + "m08_s14_connectivity": 1, + "m08_s15_connectivity": 1, + "m09_s00_connectivity": 1, + "m09_s01_connectivity": 1, + "m09_s02_connectivity": 1, + "m09_s03_connectivity": 1, + "m09_s04_connectivity": 1, + "m09_s05_connectivity": 1, + "m09_s06_connectivity": 1, + "m09_s07_connectivity": 1, + "m09_s08_connectivity": 1, + "m09_s09_connectivity": 1, + "m09_s10_connectivity": 1, + "m09_s11_connectivity": 1, + "m09_s12_connectivity": 1, + "m09_s13_connectivity": 1, + "m09_s14_connectivity": 1, + "m09_s15_connectivity": 1, + "m10_s00_connectivity": 1, + "m10_s01_connectivity": 1, + "m10_s02_connectivity": 1, + "m10_s03_connectivity": 1, + "m10_s04_connectivity": 1, + "m10_s05_connectivity": 1, + "m10_s06_connectivity": 1, + "m10_s07_connectivity": 1, + "m10_s08_connectivity": 1, + "m10_s09_connectivity": 1, + "m10_s10_connectivity": 1, + "m10_s11_connectivity": 1, + "m10_s12_connectivity": 1, + "m10_s13_connectivity": 1, + "m10_s14_connectivity": 1, + "m10_s15_connectivity": 1, + "m11_s00_connectivity": 1, + "m11_s01_connectivity": 1, + "m11_s02_connectivity": 1, + "m11_s03_connectivity": 1, + "m11_s04_connectivity": 1, + "m11_s05_connectivity": 1, + "m11_s06_connectivity": 1, + "m11_s07_connectivity": 1, + "m11_s08_connectivity": 1, + "m11_s09_connectivity": 1, + "m11_s10_connectivity": 1, + "m11_s11_connectivity": 1, + "m11_s12_connectivity": 1, + "m11_s13_connectivity": 1, + "m11_s14_connectivity": 1, + "m11_s15_connectivity": 1, + "m12_s00_connectivity": 1, + "m12_s01_connectivity": 1, + "m12_s02_connectivity": 1, + "m12_s03_connectivity": 1, + "m12_s04_connectivity": 1, + "m12_s05_connectivity": 1, + "m12_s06_connectivity": 1, + "m12_s07_connectivity": 1, + "m12_s08_connectivity": 1, + "m12_s09_connectivity": 1, + "m12_s10_connectivity": 1, + "m12_s11_connectivity": 1, + "m12_s12_connectivity": 1, + "m12_s13_connectivity": 1, + "m12_s14_connectivity": 1, + "m12_s15_connectivity": 1, + "m13_s00_connectivity": 1, + "m13_s01_connectivity": 1, + "m13_s02_connectivity": 1, + "m13_s03_connectivity": 1, + "m13_s04_connectivity": 1, + "m13_s05_connectivity": 1, + "m13_s06_connectivity": 1, + "m13_s07_connectivity": 1, + "m13_s08_connectivity": 1, + "m13_s09_connectivity": 1, + "m13_s10_connectivity": 1, + "m13_s11_connectivity": 1, + "m13_s12_connectivity": 1, + "m13_s13_connectivity": 1, + "m13_s14_connectivity": 1, + "m13_s15_connectivity": 1, + "m14_s00_connectivity": 1, + "m14_s01_connectivity": 1, + "m14_s02_connectivity": 1, + "m14_s03_connectivity": 1, + "m14_s04_connectivity": 1, + "m14_s05_connectivity": 1, + "m14_s06_connectivity": 1, + "m14_s07_connectivity": 1, + "m14_s08_connectivity": 1, + "m14_s09_connectivity": 1, + "m14_s10_connectivity": 1, + "m14_s11_connectivity": 1, + "m14_s12_connectivity": 1, + "m14_s13_connectivity": 1, + "m14_s14_connectivity": 1, + "m14_s15_connectivity": 1, + "m15_s00_connectivity": 1, + "m15_s01_connectivity": 1, + "m15_s02_connectivity": 1, + "m15_s03_connectivity": 1, + "m15_s04_connectivity": 1, + "m15_s05_connectivity": 1, + "m15_s06_connectivity": 1, + "m15_s07_connectivity": 1, + "m15_s08_connectivity": 1, + "m15_s09_connectivity": 1, + "m15_s10_connectivity": 1, + "m15_s11_connectivity": 1, + "m15_s12_connectivity": 1, + "m15_s13_connectivity": 1, + "m15_s14_connectivity": 1, + "m15_s15_connectivity": 1, + "component_name": "design_1_axis_switch_0_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 1024, + "c_highaddr": 2047 + }, + "ports": [ + { + "role": "target", + "target": "axi_dma_0:MM2S", + "name": "S00_AXIS" + }, + { + "role": "initiator", + "target": "axi_dma_0:S2MM", + "name": "M00_AXIS" + }, + { + "role": "initiator", + "target": "axis_switch_0:S01_AXIS", + "name": "S01_AXIS" + }, + { + "role": "target", + "target": "axis_switch_0:S01_AXIS", + "name": "S01_AXIS" + }, + { + "role": "target", + "target": "axis_switch_0:M01_AXIS", + "name": "S01_AXIS" + }, + { + "role": "initiator", + "target": "axis_switch_0:S01_AXIS", + "name": "M01_AXIS" + } + ], + "num_ports": 2 + }, + "xdma_0": { + "vlnv": "xilinx.com:ip:xdma:4.1", + "parameters": { + "component_name": "design_1_xdma_0_1", + "pl_upstream_facing": "true", + "tl_legacy_mode_enable": "false", + "pcie_blk_locn": "PCIE4C_X1Y0", + "pl_link_cap_max_link_width": "X1", + "pl_link_cap_max_link_speed": "16.0_GT/s", + "ref_clk_freq": "100_MHz", + "drp_clk_sel": "Internal", + "free_run_freq": "100_MHz", + "axi_addr_width": 32, + "axi_data_width": "64_bit", + "core_clk_freq": 1, + "pll_type": 1, + "user_clk_freq": 2, + "silicon_rev": "Pre-Production", + "pipe_sim": "false", + "vdm_en": "true", + "ext_ch_gt_drp": "false", + "pcie3_drp": "false", + "dedicate_perst": "false", + "sys_reset_polarity": "ACTIVE_LOW", + "mcap_enablement": "None", + "ext_startup_primitive": "false", + "pf0_vendor_id": 4334, + "pf0_device_id": 9041, + "pf0_revision_id": 0, + "pf0_subsystem_vendor_id": "10EE", + "pf0_subsystem_id": "0007", + "pf0_class_code": "058000", + "pf1_vendor_id": "10EE", + "pf1_device_id": 1041, + "pf1_revision_id": 0, + "pf1_subsystem_vendor_id": 4334, + "pf1_subsystem_id": 7, + "pf1_class_code": "070001", + "pf2_device_id": 1040, + "pf2_revision_id": 0, + "pf2_subsystem_id": 7, + "pf3_device_id": 1039, + "pf3_revision_id": 0, + "pf3_subsystem_id": 7, + "axilite_master_aperture_size": 13, + "axilite_master_control": 0, + "xdma_aperture_size": 9, + "xdma_control": 4, + "axist_bypass_aperture_size": 13, + "axist_bypass_control": 0, + "pf0_interrupt_pin": "INTA", + "pf0_msi_cap_multimsgcap": "1_vector", + "c_comp_timeout": 1, + "c_timeout0_sel": 14, + "c_timeout1_sel": 15, + "c_timeout_mult": 3, + "c_old_bridge_timeout": 0, + "shared_logic": 1, + "shared_logic_clk": "false", + "shared_logic_both": "false", + "shared_logic_gtc": "false", + "shared_logic_gtc_7xg2": "false", + "shared_logic_clk_7xg2": "false", + "shared_logic_both_7xg2": "false", + "en_transceiver_status_ports": "false", + "is_board_project": 1, + "en_gt_selection": "false", + "select_quad": "GTY_Quad_227", + "ultrascale": "FALSE", + "ultrascale_plus": "TRUE", + "versal": "false", + "v7_gen3": "FALSE", + "msi_enabled": "TRUE", + "dev_port_type": 0, + "xdma_axi_intf_mm": "AXI_Memory_Mapped", + "xdma_pcie_64bit_en": "false", + "xdma_axilite_master": "FALSE", + "xdma_axist_bypass": "FALSE", + "xdma_rnum_chnl": 1, + "xdma_wnum_chnl": 1, + "xdma_axilite_slave": "true", + "xdma_num_usr_irq": 5, + "xdma_rnum_rids": 32, + "xdma_wnum_rids": 16, + "c_m_axi_id_width": 4, + "c_axibar_num": 1, + "c_family": "virtexuplusHBM", + "xdma_num_pcie_tag": 256, + "en_axi_master_if": "true", + "en_wchnl_0": "TRUE", + "en_wchnl_1": "FALSE", + "en_wchnl_2": "FALSE", + "en_wchnl_3": "FALSE", + "en_wchnl_4": "FALSE", + "en_wchnl_5": "FALSE", + "en_wchnl_6": "FALSE", + "en_wchnl_7": "FALSE", + "en_rchnl_0": "TRUE", + "en_rchnl_1": "FALSE", + "en_rchnl_2": "FALSE", + "en_rchnl_3": "FALSE", + "en_rchnl_4": "FALSE", + "en_rchnl_5": "FALSE", + "en_rchnl_6": "FALSE", + "en_rchnl_7": "FALSE", + "xdma_dsc_bypass": "false", + "c_metering_on": 1, + "rx_detect": "Default", + "c_ats_enable": "false", + "c_ats_cap_nextptr": 0, + "c_pr_cap_nextptr": 0, + "c_pri_enable": "false", + "dsc_bypass_rd": 0, + "dsc_bypass_wr": 0, + "xdma_sts_ports": "false", + "msix_enabled": "FALSE", + "wr_ch0_enabled": "FALSE", + "wr_ch1_enabled": "FALSE", + "wr_ch2_enabled": "FALSE", + "wr_ch3_enabled": "FALSE", + "rd_ch0_enabled": "FALSE", + "rd_ch1_enabled": "FALSE", + "rd_ch2_enabled": "FALSE", + "rd_ch3_enabled": "FALSE", + "cfg_mgmt_if": "true", + "rq_seq_num_ignore": 0, + "cfg_ext_if": "false", + "legacy_cfg_ext_if": "false", + "c_parity_check": 0, + "c_parity_gen": 0, + "c_parity_prop": 0, + "c_ecc_enable": 0, + "en_debug_ports": "false", + "vu9p_board": "false", + "enable_jtag_dbg": "false", + "enable_ltssm_dbg": "false", + "enable_ibert": "false", + "mm_slave_en": 1, + "dma_en": 0, + "c_axibar_0": 0, + "c_axibar_1": 0, + "c_axibar_2": 0, + "c_axibar_3": 0, + "c_axibar_4": 0, + "c_axibar_5": 0, + "c_axibar_highaddr_0": 4294967295, + "c_axibar_highaddr_1": 0, + "c_axibar_highaddr_2": 0, + "c_axibar_highaddr_3": 0, + "c_axibar_highaddr_4": 0, + "c_axibar_highaddr_5": 0, + "c_axibar2pciebar_0": 0, + "c_axibar2pciebar_1": 0, + "c_axibar2pciebar_2": 0, + "c_axibar2pciebar_3": 0, + "c_axibar2pciebar_4": 0, + "c_axibar2pciebar_5": 0, + "en_axi_slave_if": "true", + "c_include_baroffset_reg": 1, + "c_s_axi_id_width": 2, + "c_s_axi_num_read": 8, + "c_m_axi_num_read": 8, + "c_m_axi_num_readq": 2, + "c_s_axi_num_write": 8, + "c_m_axi_num_write": 8, + "c_m_axi_num_write_scale": 1, + "msix_impl_ext": "FALSE", + "axi_aclk_loopback": "false", + "pf0_bar0_aperture_size": 13, + "pf0_bar0_control": 4, + "pf0_bar1_aperture_size": 5, + "pf0_bar1_control": 0, + "pf0_bar2_aperture_size": 5, + "pf0_bar2_control": 0, + "pf0_bar3_aperture_size": 5, + "pf0_bar3_control": 0, + "pf0_bar4_aperture_size": 5, + "pf0_bar4_control": 0, + "pf0_bar5_aperture_size": 5, + "pf0_bar5_control": 0, + "pf0_expansion_rom_aperture_size": 0, + "pf0_expansion_rom_enable": "FALSE", + "pciebar_num": 1, + "c_pciebar2axibar_0": 0, + "c_pciebar2axibar_1": 0, + "c_pciebar2axibar_2": 0, + "c_pciebar2axibar_3": 0, + "c_pciebar2axibar_4": 0, + "c_pciebar2axibar_5": 0, + "c_pciebar2axibar_6": 0, + "barlite1": 0, + "barlite2": 7, + "vcu118_board": "false", + "enable_error_injection": "false", + "split_dma": "false", + "use_standard_interfaces": "false", + "dma_2rp": "false", + "sriov_active_vfs": 252, + "pipe_line_stage": 2, + "axis_pipe_line_stage": 0, + "mult_pf_des": "false", + "pf_swap": "false", + "pf0_msix_tar_id": 8, + "pf1_msix_tar_id": 9, + "runbit_fix": "false", + "usrint_expn": "false", + "xlnx_ref_board": "AU55C", + "gtwiz_in_core": 1, + "gtcom_in_core": 2, + "ins_loss_profile": "Add-in_Card", + "func_mode": 0, + "pf1_enabled": 0, + "dma_reset_source_sel": "User_Reset", + "pf1_bar0_aperture_size": 18, + "pf1_bar0_control": 4, + "pf1_bar1_aperture_size": 10, + "pf1_bar1_control": 4, + "pf1_bar2_aperture_size": 10, + "pf1_bar2_control": 6, + "pf1_bar3_aperture_size": 10, + "pf1_bar3_control": 0, + "pf1_bar4_aperture_size": 10, + "pf1_bar4_control": 6, + "pf1_bar5_aperture_size": 10, + "pf1_bar5_control": 0, + "pf1_expansion_rom_aperture_size": 0, + "pf1_expansion_rom_enable": "FALSE", + "pf1_pciebar2axibar_0": 0, + "pf1_pciebar2axibar_1": 0, + "pf1_pciebar2axibar_2": 0, + "pf1_pciebar2axibar_3": 0, + "pf1_pciebar2axibar_4": 0, + "pf1_pciebar2axibar_5": 0, + "pf1_pciebar2axibar_6": 0, + "c_msix_int_table_en": 0, + "vu9p_tul_ex": "false", + "pcie_blk_type": 1, + "ccix_enable": "FALSE", + "ccix_dvsec": "FALSE", + "ext_sys_clk_bufg": "false", + "c_num_of_sc": 1, + "usr_irq_exdes": "false", + "axi_vip_in_exdes": "false", + "pipe_debug_en": "FALSE", + "xdma_non_incremental_exdes": "false", + "xdma_st_infinite_desc_exdes": "false", + "ext_xvc_vsec_enable": "false", + "acs_ext_cap_enable": "false", + "en_pcie_debug_ports": "FALSE", + "multq_en": 0, + "dma_mm": 0, + "dma_st": 0, + "c_pcie_pfs_supported": 0, + "c_sriov_en": 0, + "barlite_ext_pf0": 0, + "barlite_ext_pf1": 0, + "barlite_ext_pf2": 0, + "barlite_ext_pf3": 0, + "barlite_int_pf0": 0, + "barlite_int_pf1": 0, + "barlite_int_pf2": 0, + "barlite_int_pf3": 0, + "num_vfs_pf0": 0, + "num_vfs_pf1": 0, + "num_vfs_pf2": 0, + "num_vfs_pf3": 0, + "firstvf_offset_pf0": 0, + "firstvf_offset_pf1": 0, + "firstvf_offset_pf2": 0, + "firstvf_offset_pf3": 0, + "vf_barlite_ext_pf0": 0, + "vf_barlite_ext_pf1": 0, + "vf_barlite_ext_pf2": 0, + "vf_barlite_ext_pf3": 0, + "vf_barlite_int_pf0": 1, + "vf_barlite_int_pf1": 1, + "vf_barlite_int_pf2": 1, + "vf_barlite_int_pf3": 1, + "c_c2h_num_chnl": 1, + "c_h2c_num_chnl": 1, + "h2c_xdma_chnl": 15, + "c2h_xdma_chnl": 15, + "axisten_if_enable_msg_route": "27FFF", + "enable_more": "FALSE", + "disable_bram_pipeline": "false", + "disable_eq_synchronizer": "false", + "c_enable_resource_reduction": "FALSE", + "gen4_eieos_0s7": "true", + "c_s_axi_supports_narrow_burst": "false", + "enable_ats_switch": "FALSE", + "c_ats_switch_unique_bdf": 1, + "bridge_burst": "true", + "cfg_space_enable": "false", + "c_last_core_cap_addr": 256, + "c_vsec_cap_addr": 296, + "soft_reset_en": "false", + "interrupt_out_width": 1, + "c_msi_rx_pin_en": 0, + "c_msix_rx_pin_en": 1, + "c_intx_rx_pin_en": 1, + "msix_rx_decode_en": "FALSE", + "pcie_id_if": "FALSE", + "tl_pf_enable_reg": 1, + "axsize_byte_access_en": "false", + "split_dma_single_pf": "false", + "rbar_enable": "false", + "c_smmu_en": 0, + "c_m_axi_awuser_width": 8, + "c_m_axi_aruser_width": 8, + "c_slave_read_64os_en": 0, + "flr_enable": "false", + "shell_bridge": "false", + "msix_pcie_internal": "false", + "versal_part_type": "S80", + "functional_mode": "AXI_Bridge", + "mode_selection": "Basic", + "device_port_type": "PCI_Express_Endpoint_device", + "axisten_freq": 250, + "en_ext_ch_gt_drp": "false", + "en_pcie_drp": "false", + "mcap_fpga_bitstream_version": 0, + "enable_code": 0, + "vendor_id": "10EE", + "pf0_use_class_code_lookup_assistant": "false", + "pf0_base_class_menu": "Memory_controller", + "pf0_class_code_base": "05", + "pf0_sub_class_interface_menu": "Other_memory_controller", + "pf0_class_code_sub": 80, + "pf0_class_code_interface": 0, + "axilite_master_en": "false", + "axilite_master_size": 1, + "axilite_master_scale": "Megabytes", + "xdma_en": "true", + "xdma_size": 64, + "xdma_scale": "Kilobytes", + "axist_bypass_en": "false", + "axist_bypass_size": 1, + "axist_bypass_scale": "Megabytes", + "pciebar2axibar_axil_master": 0, + "pciebar2axibar_xdma": 0, + "pciebar2axibar_axist_bypass": 0, + "pf0_msi_enabled": "true", + "comp_timeout": "50ms", + "timeout0_sel": 14, + "timeout1_sel": 15, + "timeout_mult": 3, + "old_bridge_timeout": "false", + "sys_rst_n_board_interface": "pcie_perstn", + "pcie_board_interface": "Custom", + "rx_ppm_offset": 0, + "rx_ssc_ppm": 0, + "ins_loss_nyq": 15, + "phy_lp_txpreset": 4, + "coreclk_freq": 250, + "plltype": "QPLL0", + "performance": "false", + "pcie_extended_tag": "true", + "pf0_link_status_slot_clock_config": "true", + "pf0_msix_enabled": "false", + "pf0_msix_cap_table_size": 0, + "pf0_msix_cap_table_offset": 0, + "pf0_msix_cap_table_bir": "BAR_0", + "pf0_msix_cap_pba_offset": 0, + "pf0_msix_cap_pba_bir": "BAR_0", + "pf1_msix_enabled": "false", + "pf1_msix_cap_table_size": "01F", + "pf1_msix_cap_table_offset": "00009000", + "pf1_msix_cap_table_bir": "BAR_0", + "pf1_msix_cap_pba_offset": "00009FE0", + "pf1_msix_cap_pba_bir": "BAR_0", + "axil_master_64bit_en": "false", + "axi_bypass_64bit_en": "false", + "axil_master_prefetchable": "false", + "xdma_pcie_prefetchable": "false", + "axi_bypass_prefetchable": "false", + "parity_settings": "None", + "ecc_en": "false", + "axi_id_width": 4, + "type1_membase_memlimit_enable": "Disabled", + "type1_prefetchable_membase_memlimit": "Disabled", + "axibar_num": 1, + "axibar_1": 0, + "axibar_2": 0, + "axibar_3": 0, + "axibar_4": 0, + "axibar_5": 0, + "axibar_highaddr_1": 0, + "axibar_highaddr_2": 0, + "axibar_highaddr_3": 0, + "axibar_highaddr_4": 0, + "axibar_highaddr_5": 0, + "axibar2pciebar_0": 0, + "axibar2pciebar_1": 0, + "axibar2pciebar_2": 0, + "axibar2pciebar_3": 0, + "axibar2pciebar_4": 0, + "axibar2pciebar_5": 0, + "include_baroffset_reg": "true", + "baseaddr": 268435455, + "highaddr": 0, + "s_axi_id_width": 2, + "pf0_msix_impl_locn": "Internal", + "pf0_bar0_enabled": "true", + "pf0_bar0_type": "Memory", + "pf0_bar0_size": 1, + "pf0_bar0_scale": "Megabytes", + "pf0_bar0_64bit": "false", + "pf0_bar0_prefetchable": "false", + "pf0_bar1_enabled": "false", + "pf0_bar1_type": "Memory", + "pf0_bar1_size": 4, + "pf0_bar1_scale": "Kilobytes", + "pf0_bar1_64bit": "false", + "pf0_bar1_prefetchable": "false", + "pf0_bar2_enabled": "false", + "pf0_bar2_type": "Memory", + "pf0_bar2_size": 4, + "pf0_bar2_scale": "Kilobytes", + "pf0_bar2_64bit": "false", + "pf0_bar2_prefetchable": "false", + "pf0_bar3_enabled": "false", + "pf0_bar3_type": "Memory", + "pf0_bar3_size": 4, + "pf0_bar3_scale": "Kilobytes", + "pf0_bar3_64bit": "false", + "pf0_bar3_prefetchable": "false", + "pf0_bar4_enabled": "false", + "pf0_bar4_type": "Memory", + "pf0_bar4_size": 4, + "pf0_bar4_scale": "Kilobytes", + "pf0_bar4_64bit": "false", + "pf0_bar4_prefetchable": "false", + "pf0_bar5_enabled": "false", + "pf0_bar5_type": "Memory", + "pf0_bar5_size": 4, + "pf0_bar5_scale": "Kilobytes", + "pf0_bar5_64bit": "false", + "pf0_bar5_prefetchable": "false", + "pciebar2axibar_0": 0, + "pciebar2axibar_1": 0, + "pciebar2axibar_2": 0, + "pciebar2axibar_3": 0, + "pciebar2axibar_4": 0, + "pciebar2axibar_5": 0, + "pciebar2axibar_6": 0, + "bar_indicator": "BAR_0", + "bar0_indicator": 1, + "bar1_indicator": 0, + "bar2_indicator": 0, + "bar3_indicator": 0, + "bar4_indicator": 0, + "bar5_indicator": 0, + "en_dbg_descramble": "false", + "pf1_use_class_code_lookup_assistant": "false", + "pf1_base_class_menu": "Simple_communication_controllers", + "pf1_class_code_base": "07", + "pf1_class_code_sub": 0, + "pf1_sub_class_interface_menu": "16450_compatible_serial_controller", + "pf1_class_code_interface": "01", + "pf1_interrupt_pin": "NONE", + "pf1_msi_enabled": "false", + "pf1_msi_cap_multimsgcap": "1_vector", + "pf1_bar0_enabled": "true", + "pf1_bar0_type": "Memory", + "pf1_bar0_size": 32, + "pf1_bar0_scale": "Megabytes", + "pf1_bar0_64bit": "false", + "pf1_bar0_prefetchable": "false", + "pf1_bar1_enabled": "true", + "pf1_bar1_type": "Memory", + "pf1_bar1_size": 128, + "pf1_bar1_scale": "Kilobytes", + "pf1_bar1_64bit": "false", + "pf1_bar1_prefetchable": "false", + "pf1_bar2_enabled": "true", + "pf1_bar2_type": "Memory", + "pf1_bar2_size": 128, + "pf1_bar2_scale": "Kilobytes", + "pf1_bar2_64bit": "true", + "pf1_bar2_prefetchable": "false", + "pf1_bar3_enabled": "false", + "pf1_bar3_type": "Memory", + "pf1_bar3_size": 128, + "pf1_bar3_scale": "Kilobytes", + "pf1_bar3_64bit": "false", + "pf1_bar3_prefetchable": "false", + "pf1_bar4_enabled": "true", + "pf1_bar4_type": "Memory", + "pf1_bar4_size": 128, + "pf1_bar4_scale": "Kilobytes", + "pf1_bar4_64bit": "true", + "pf1_bar4_prefetchable": "false", + "pf1_bar5_enabled": "false", + "pf1_bar5_type": "Memory", + "pf1_bar5_size": 128, + "pf1_bar5_scale": "Kilobytes", + "pf1_bar5_prefetchable": "false", + "pf2_class_code": "058000", + "pf2_subsystem_vendor_id": "10EE", + "pf2_use_class_code_lookup_assistant": "false", + "pf2_base_class_menu": "Memory_controller", + "pf2_class_code_base": "05", + "pf2_class_code_sub": 80, + "pf2_sub_class_interface_menu": "Other_memory_controller", + "pf2_class_code_interface": 0, + "pf2_interrupt_pin": "NONE", + "pf2_msi_enabled": "false", + "pf2_msi_cap_multimsgcap": "1_vector", + "pf2_bar0_enabled": "true", + "pf2_bar0_type": "Memory", + "pf2_bar0_size": 128, + "pf2_bar0_scale": "Kilobytes", + "pf2_bar0_64bit": "false", + "pf2_bar0_prefetchable": "false", + "pf2_bar1_enabled": "true", + "pf2_bar1_type": "Memory", + "pf2_bar1_size": 128, + "pf2_bar1_scale": "Kilobytes", + "pf2_bar1_64bit": "false", + "pf2_bar1_prefetchable": "false", + "pf2_bar2_enabled": "true", + "pf2_bar2_type": "Memory", + "pf2_bar2_size": 128, + "pf2_bar2_scale": "Kilobytes", + "pf2_bar2_64bit": "false", + "pf2_bar2_prefetchable": "false", + "pf2_bar3_enabled": "true", + "pf2_bar3_type": "Memory", + "pf2_bar3_size": 128, + "pf2_bar3_scale": "Kilobytes", + "pf2_bar3_64bit": "false", + "pf2_bar3_prefetchable": "false", + "pf2_bar4_enabled": "true", + "pf2_bar4_type": "Memory", + "pf2_bar4_size": 128, + "pf2_bar4_scale": "Kilobytes", + "pf2_bar4_64bit": "false", + "pf2_bar4_prefetchable": "false", + "pf2_bar5_enabled": "true", + "pf2_bar5_type": "Memory", + "pf2_bar5_size": 128, + "pf2_bar5_scale": "Kilobytes", + "pf2_bar5_prefetchable": "false", + "pf3_class_code": "058000", + "pf3_subsystem_vendor_id": "10EE", + "pf3_use_class_code_lookup_assistant": "false", + "pf3_base_class_menu": "Memory_controller", + "pf3_class_code_base": "05", + "pf3_class_code_sub": 80, + "pf3_sub_class_interface_menu": "Other_memory_controller", + "pf3_class_code_interface": 0, + "pf3_interrupt_pin": "NONE", + "pf3_msi_enabled": "false", + "pf3_msi_cap_multimsgcap": "1_vector", + "pf3_bar0_enabled": "true", + "pf3_bar0_type": "Memory", + "pf3_bar0_size": 128, + "pf3_bar0_scale": "Kilobytes", + "pf3_bar0_64bit": "false", + "pf3_bar0_prefetchable": "false", + "pf3_bar1_enabled": "true", + "pf3_bar1_type": "Memory", + "pf3_bar1_size": 128, + "pf3_bar1_scale": "Kilobytes", + "pf3_bar1_64bit": "false", + "pf3_bar1_prefetchable": "false", + "pf3_bar2_enabled": "true", + "pf3_bar2_type": "Memory", + "pf3_bar2_size": 128, + "pf3_bar2_scale": "Kilobytes", + "pf3_bar2_64bit": "false", + "pf3_bar2_prefetchable": "false", + "pf3_bar3_enabled": "true", + "pf3_bar3_type": "Memory", + "pf3_bar3_size": 128, + "pf3_bar3_scale": "Kilobytes", + "pf3_bar3_64bit": "false", + "pf3_bar3_prefetchable": "false", + "pf3_bar4_enabled": "true", + "pf3_bar4_type": "Memory", + "pf3_bar4_size": 128, + "pf3_bar4_scale": "Kilobytes", + "pf3_bar4_64bit": "false", + "pf3_bar4_prefetchable": "false", + "pf3_bar5_enabled": "true", + "pf3_bar5_type": "Memory", + "pf3_bar5_size": 128, + "pf3_bar5_scale": "Kilobytes", + "pf3_bar5_prefetchable": "false", + "prog_usr_irq_vec_map": "false", + "rcfg_nph_fix_en": "false", + "post_synth_sim_en": "false", + "user_pf_two_axilite_bar_en": "false", + "two_bypass_bar": "false", + "en_l23_entry": "false", + "pf2_pciebar2axibar_0": 0, + "pf2_pciebar2axibar_1": 0, + "pf2_pciebar2axibar_2": 0, + "pf2_pciebar2axibar_3": 0, + "pf2_pciebar2axibar_4": 0, + "pf2_pciebar2axibar_5": 0, + "pf3_pciebar2axibar_0": 0, + "pf3_pciebar2axibar_1": 0, + "pf3_pciebar2axibar_2": 0, + "pf3_pciebar2axibar_3": 0, + "pf3_pciebar2axibar_4": 0, + "pf3_pciebar2axibar_5": 0, + "gtwiz_in_core_us": 1, + "gtwiz_in_core_usp": 1, + "en_dma_and_bridge": "false", + "en_coreclk_es1": "false", + "vcu1525_ddr_ex": "false", + "en_bridge": "false", + "enable_ccix": "FALSE", + "enable_dvsec": "FALSE", + "gtcom_in_core_usp": 2, + "en_mqdma": "false", + "sriov_cap_enable": "false", + "pf0_bar0_enabled_mqdma": "true", + "pf0_bar0_type_mqdma": "DMA", + "pf0_bar0_64bit_mqdma": "false", + "pf0_bar0_prefetchable_mqdma": "false", + "pf0_bar0_scale_mqdma": "Kilobytes", + "pf0_bar0_size_mqdma": 128, + "pf0_bar1_enabled_mqdma": "false", + "pf0_bar1_type_mqdma": "N/A", + "pf0_bar1_64bit_mqdma": "false", + "pf0_bar1_prefetchable_mqdma": "false", + "pf0_bar1_scale_mqdma": "Kilobytes", + "pf0_bar1_size_mqdma": 128, + "pf0_bar2_enabled_mqdma": "false", + "pf0_bar2_type_mqdma": "N/A", + "pf0_bar2_64bit_mqdma": "false", + "pf0_bar2_prefetchable_mqdma": "false", + "pf0_bar2_scale_mqdma": "Kilobytes", + "pf0_bar2_size_mqdma": 128, + "pf0_bar3_enabled_mqdma": "false", + "pf0_bar3_type_mqdma": "N/A", + "pf0_bar3_64bit_mqdma": "false", + "pf0_bar3_prefetchable_mqdma": "false", + "pf0_bar3_scale_mqdma": "Kilobytes", + "pf0_bar3_size_mqdma": 128, + "pf0_bar4_enabled_mqdma": "false", + "pf0_bar4_type_mqdma": "N/A", + "pf0_bar4_64bit_mqdma": "false", + "pf0_bar4_prefetchable_mqdma": "false", + "pf0_bar4_scale_mqdma": "Kilobytes", + "pf0_bar4_size_mqdma": 128, + "pf0_bar5_enabled_mqdma": "false", + "pf0_bar5_type_mqdma": "N/A", + "pf0_bar5_prefetchable_mqdma": "false", + "pf0_bar5_scale_mqdma": "Kilobytes", + "pf0_bar5_size_mqdma": 128, + "pf1_bar0_enabled_mqdma": "true", + "pf1_bar0_type_mqdma": "DMA", + "pf1_bar0_64bit_mqdma": "false", + "pf1_bar0_prefetchable_mqdma": "false", + "pf1_bar0_scale_mqdma": "Kilobytes", + "pf1_bar0_size_mqdma": 128, + "pf1_bar1_enabled_mqdma": "false", + "pf1_bar1_type_mqdma": "N/A", + "pf1_bar1_64bit_mqdma": "false", + "pf1_bar1_prefetchable_mqdma": "false", + "pf1_bar1_scale_mqdma": "Kilobytes", + "pf1_bar1_size_mqdma": 128, + "pf1_bar2_enabled_mqdma": "false", + "pf1_bar2_type_mqdma": "N/A", + "pf1_bar2_64bit_mqdma": "false", + "pf1_bar2_prefetchable_mqdma": "false", + "pf1_bar2_scale_mqdma": "Kilobytes", + "pf1_bar2_size_mqdma": 128, + "pf1_bar3_enabled_mqdma": "false", + "pf1_bar3_type_mqdma": "N/A", + "pf1_bar3_64bit_mqdma": "false", + "pf1_bar3_prefetchable_mqdma": "false", + "pf1_bar3_scale_mqdma": "Kilobytes", + "pf1_bar3_size_mqdma": 128, + "pf1_bar4_enabled_mqdma": "false", + "pf1_bar4_type_mqdma": "N/A", + "pf1_bar4_64bit_mqdma": "false", + "pf1_bar4_prefetchable_mqdma": "false", + "pf1_bar4_scale_mqdma": "Kilobytes", + "pf1_bar4_size_mqdma": 128, + "pf1_bar5_enabled_mqdma": "false", + "pf1_bar5_type_mqdma": "N/A", + "pf1_bar5_prefetchable_mqdma": "false", + "pf1_bar5_scale_mqdma": "Kilobytes", + "pf1_bar5_size_mqdma": 128, + "pf2_bar0_enabled_mqdma": "true", + "pf2_bar0_type_mqdma": "DMA", + "pf2_bar0_64bit_mqdma": "false", + "pf2_bar0_prefetchable_mqdma": "false", + "pf2_bar0_scale_mqdma": "Kilobytes", + "pf2_bar0_size_mqdma": 128, + "pf2_bar1_enabled_mqdma": "false", + "pf2_bar1_type_mqdma": "N/A", + "pf2_bar1_64bit_mqdma": "false", + "pf2_bar1_prefetchable_mqdma": "false", + "pf2_bar1_scale_mqdma": "Kilobytes", + "pf2_bar1_size_mqdma": 128, + "pf2_bar2_enabled_mqdma": "false", + "pf2_bar2_type_mqdma": "N/A", + "pf2_bar2_64bit_mqdma": "false", + "pf2_bar2_prefetchable_mqdma": "false", + "pf2_bar2_scale_mqdma": "Kilobytes", + "pf2_bar2_size_mqdma": 128, + "pf2_bar3_enabled_mqdma": "false", + "pf2_bar3_type_mqdma": "N/A", + "pf2_bar3_64bit_mqdma": "false", + "pf2_bar3_prefetchable_mqdma": "false", + "pf2_bar3_scale_mqdma": "Kilobytes", + "pf2_bar3_size_mqdma": 128, + "pf2_bar4_enabled_mqdma": "false", + "pf2_bar4_type_mqdma": "N/A", + "pf2_bar4_64bit_mqdma": "false", + "pf2_bar4_prefetchable_mqdma": "false", + "pf2_bar4_scale_mqdma": "Kilobytes", + "pf2_bar4_size_mqdma": 128, + "pf2_bar5_enabled_mqdma": "false", + "pf2_bar5_type_mqdma": "N/A", + "pf2_bar5_prefetchable_mqdma": "false", + "pf2_bar5_scale_mqdma": "Kilobytes", + "pf2_bar5_size_mqdma": 128, + "pf3_bar0_enabled_mqdma": "true", + "pf3_bar0_type_mqdma": "DMA", + "pf3_bar0_64bit_mqdma": "false", + "pf3_bar0_prefetchable_mqdma": "false", + "pf3_bar0_scale_mqdma": "Kilobytes", + "pf3_bar0_size_mqdma": 128, + "pf3_bar1_enabled_mqdma": "false", + "pf3_bar1_type_mqdma": "N/A", + "pf3_bar1_64bit_mqdma": "false", + "pf3_bar1_prefetchable_mqdma": "false", + "pf3_bar1_scale_mqdma": "Kilobytes", + "pf3_bar1_size_mqdma": 128, + "pf3_bar2_enabled_mqdma": "false", + "pf3_bar2_type_mqdma": "N/A", + "pf3_bar2_64bit_mqdma": "false", + "pf3_bar2_prefetchable_mqdma": "false", + "pf3_bar2_scale_mqdma": "Kilobytes", + "pf3_bar2_size_mqdma": 128, + "pf3_bar3_enabled_mqdma": "false", + "pf3_bar3_type_mqdma": "N/A", + "pf3_bar3_64bit_mqdma": "false", + "pf3_bar3_prefetchable_mqdma": "false", + "pf3_bar3_scale_mqdma": "Kilobytes", + "pf3_bar3_size_mqdma": 128, + "pf3_bar4_enabled_mqdma": "false", + "pf3_bar4_type_mqdma": "N/A", + "pf3_bar4_64bit_mqdma": "false", + "pf3_bar4_prefetchable_mqdma": "false", + "pf3_bar4_scale_mqdma": "Kilobytes", + "pf3_bar4_size_mqdma": 128, + "pf3_bar5_enabled_mqdma": "false", + "pf3_bar5_type_mqdma": "N/A", + "pf3_bar5_prefetchable_mqdma": "false", + "pf3_bar5_scale_mqdma": "Kilobytes", + "pf3_bar5_size_mqdma": 128, + "copy_pf0": "false", + "copy_sriov_pf0": "true", + "pf0_expansion_rom_enabled": "false", + "pf0_expansion_rom_type": "N/A", + "pf0_expansion_rom_scale": "Kilobytes", + "pf0_expansion_rom_size": 4, + "pf1_expansion_rom_type": "N/A", + "pf1_expansion_rom_enabled": "false", + "pf1_expansion_rom_scale": "Kilobytes", + "pf1_expansion_rom_size": 4, + "pf2_expansion_rom_type": "N/A", + "pf2_expansion_rom_enabled": "false", + "pf2_expansion_rom_scale": "Kilobytes", + "pf2_expansion_rom_size": 4, + "pf3_expansion_rom_type": "N/A", + "pf3_expansion_rom_enabled": "false", + "pf3_expansion_rom_scale": "Kilobytes", + "pf3_expansion_rom_size": 4, + "pf0_sriov_bar0_enabled": "true", + "pf0_sriov_bar0_type": "DMA", + "pf0_sriov_bar0_64bit": "false", + "pf0_sriov_bar0_prefetchable": "false", + "pf0_sriov_bar0_size": 2, + "pf0_sriov_bar0_scale": "Kilobytes", + "pf0_sriov_bar1_enabled": "false", + "pf0_sriov_bar1_type": "N/A", + "pf0_sriov_bar1_64bit": "false", + "pf0_sriov_bar1_prefetchable": "false", + "pf0_sriov_bar1_size": 2, + "pf0_sriov_bar1_scale": "Kilobytes", + "pf0_sriov_bar2_enabled": "false", + "pf0_sriov_bar2_type": "N/A", + "pf0_sriov_bar2_64bit": "false", + "pf0_sriov_bar2_prefetchable": "false", + "pf0_sriov_bar2_size": 2, + "pf0_sriov_bar2_scale": "Kilobytes", + "pf0_sriov_bar3_enabled": "false", + "pf0_sriov_bar3_type": "N/A", + "pf0_sriov_bar3_64bit": "false", + "pf0_sriov_bar3_prefetchable": "false", + "pf0_sriov_bar3_size": 2, + "pf0_sriov_bar3_scale": "Kilobytes", + "pf0_sriov_bar4_enabled": "false", + "pf0_sriov_bar4_type": "N/A", + "pf0_sriov_bar4_64bit": "false", + "pf0_sriov_bar4_prefetchable": "false", + "pf0_sriov_bar4_size": 2, + "pf0_sriov_bar4_scale": "Kilobytes", + "pf0_sriov_bar5_enabled": "false", + "pf0_sriov_bar5_type": "N/A", + "pf0_sriov_bar5_64bit": "false", + "pf0_sriov_bar5_prefetchable": "false", + "pf0_sriov_bar5_size": 2, + "pf0_sriov_bar5_scale": "Kilobytes", + "pf1_sriov_bar0_enabled": "true", + "pf1_sriov_bar0_type": "DMA", + "pf1_sriov_bar0_64bit": "false", + "pf1_sriov_bar0_prefetchable": "false", + "pf1_sriov_bar0_size": 2, + "pf1_sriov_bar0_scale": "Kilobytes", + "pf1_sriov_bar1_enabled": "false", + "pf1_sriov_bar1_type": "N/A", + "pf1_sriov_bar1_64bit": "false", + "pf1_sriov_bar1_prefetchable": "false", + "pf1_sriov_bar1_size": 2, + "pf1_sriov_bar1_scale": "Kilobytes", + "pf1_sriov_bar2_enabled": "false", + "pf1_sriov_bar2_type": "N/A", + "pf1_sriov_bar2_64bit": "false", + "pf1_sriov_bar2_prefetchable": "false", + "pf1_sriov_bar2_size": 2, + "pf1_sriov_bar2_scale": "Kilobytes", + "pf1_sriov_bar3_enabled": "false", + "pf1_sriov_bar3_type": "N/A", + "pf1_sriov_bar3_64bit": "false", + "pf1_sriov_bar3_prefetchable": "false", + "pf1_sriov_bar3_size": 2, + "pf1_sriov_bar3_scale": "Kilobytes", + "pf1_sriov_bar4_enabled": "false", + "pf1_sriov_bar4_type": "N/A", + "pf1_sriov_bar4_64bit": "false", + "pf1_sriov_bar4_prefetchable": "false", + "pf1_sriov_bar4_size": 2, + "pf1_sriov_bar4_scale": "Kilobytes", + "pf1_sriov_bar5_enabled": "false", + "pf1_sriov_bar5_type": "N/A", + "pf1_sriov_bar5_64bit": "false", + "pf1_sriov_bar5_prefetchable": "false", + "pf1_sriov_bar5_size": 2, + "pf1_sriov_bar5_scale": "Kilobytes", + "pf2_sriov_bar0_enabled": "true", + "pf2_sriov_bar0_type": "DMA", + "pf2_sriov_bar0_64bit": "false", + "pf2_sriov_bar0_prefetchable": "false", + "pf2_sriov_bar0_size": 2, + "pf2_sriov_bar0_scale": "Kilobytes", + "pf2_sriov_bar1_enabled": "false", + "pf2_sriov_bar1_type": "N/A", + "pf2_sriov_bar1_64bit": "false", + "pf2_sriov_bar1_prefetchable": "false", + "pf2_sriov_bar1_size": 2, + "pf2_sriov_bar1_scale": "Kilobytes", + "pf2_sriov_bar2_enabled": "false", + "pf2_sriov_bar2_type": "N/A", + "pf2_sriov_bar2_64bit": "false", + "pf2_sriov_bar2_prefetchable": "false", + "pf2_sriov_bar2_size": 2, + "pf2_sriov_bar2_scale": "Kilobytes", + "pf2_sriov_bar3_enabled": "false", + "pf2_sriov_bar3_type": "N/A", + "pf2_sriov_bar3_64bit": "false", + "pf2_sriov_bar3_prefetchable": "false", + "pf2_sriov_bar3_size": 2, + "pf2_sriov_bar3_scale": "Kilobytes", + "pf2_sriov_bar4_enabled": "false", + "pf2_sriov_bar4_type": "N/A", + "pf2_sriov_bar4_64bit": "false", + "pf2_sriov_bar4_prefetchable": "false", + "pf2_sriov_bar4_size": 2, + "pf2_sriov_bar4_scale": "Kilobytes", + "pf2_sriov_bar5_enabled": "false", + "pf2_sriov_bar5_type": "N/A", + "pf2_sriov_bar5_64bit": "false", + "pf2_sriov_bar5_prefetchable": "false", + "pf2_sriov_bar5_size": 2, + "pf2_sriov_bar5_scale": "Kilobytes", + "pf3_sriov_bar0_enabled": "true", + "pf3_sriov_bar0_type": "DMA", + "pf3_sriov_bar0_64bit": "false", + "pf3_sriov_bar0_prefetchable": "false", + "pf3_sriov_bar0_size": 2, + "pf3_sriov_bar0_scale": "Kilobytes", + "pf3_sriov_bar1_enabled": "false", + "pf3_sriov_bar1_type": "N/A", + "pf3_sriov_bar1_64bit": "false", + "pf3_sriov_bar1_prefetchable": "false", + "pf3_sriov_bar1_size": 2, + "pf3_sriov_bar1_scale": "Kilobytes", + "pf3_sriov_bar2_enabled": "false", + "pf3_sriov_bar2_type": "N/A", + "pf3_sriov_bar2_64bit": "false", + "pf3_sriov_bar2_prefetchable": "false", + "pf3_sriov_bar2_size": 2, + "pf3_sriov_bar2_scale": "Kilobytes", + "pf3_sriov_bar3_enabled": "false", + "pf3_sriov_bar3_type": "N/A", + "pf3_sriov_bar3_64bit": "false", + "pf3_sriov_bar3_prefetchable": "false", + "pf3_sriov_bar3_size": 2, + "pf3_sriov_bar3_scale": "Kilobytes", + "pf3_sriov_bar4_enabled": "false", + "pf3_sriov_bar4_type": "N/A", + "pf3_sriov_bar4_64bit": "false", + "pf3_sriov_bar4_prefetchable": "false", + "pf3_sriov_bar4_size": 2, + "pf3_sriov_bar4_scale": "Kilobytes", + "pf3_sriov_bar5_enabled": "false", + "pf3_sriov_bar5_type": "N/A", + "pf3_sriov_bar5_64bit": "false", + "pf3_sriov_bar5_prefetchable": "false", + "pf3_sriov_bar5_size": 2, + "pf3_sriov_bar5_scale": "Kilobytes", + "pf0_vendor_id_mqdma": "10EE", + "pf1_vendor_id_mqdma": "10EE", + "pf2_vendor_id_mqdma": "10EE", + "pf3_vendor_id_mqdma": "10EE", + "pf0_device_id_mqdma": 9041, + "pf1_device_id_mqdma": "0007", + "pf2_device_id_mqdma": 9241, + "pf3_device_id_mqdma": 9341, + "pf0_revision_id_mqdma": 0, + "pf1_revision_id_mqdma": 0, + "pf2_revision_id_mqdma": 0, + "pf3_revision_id_mqdma": 0, + "pf0_subsystem_vendor_id_mqdma": "10EE", + "pf1_subsystem_vendor_id_mqdma": "10EE", + "pf2_subsystem_vendor_id_mqdma": "10EE", + "pf3_subsystem_vendor_id_mqdma": "10EE", + "pf0_subsystem_id_mqdma": "0007", + "pf1_subsystem_id_mqdma": "0007", + "pf2_subsystem_id_mqdma": "0007", + "pf3_subsystem_id_mqdma": "0007", + "pf0_use_class_code_lookup_assistant_mqdma": "false", + "pf1_use_class_code_lookup_assistant_mqdma": "false", + "pf2_use_class_code_lookup_assistant_mqdma": "false", + "pf3_use_class_code_lookup_assistant_mqdma": "false", + "pf0_base_class_menu_mqdma": "Memory_controller", + "pf0_class_code_base_mqdma": "05", + "pf0_class_code_sub_mqdma": 80, + "pf0_sub_class_interface_menu_mqdma": "Other_memory_controller", + "pf0_class_code_interface_mqdma": 0, + "pf0_class_code_mqdma": "058000", + "pf1_base_class_menu_mqdma": "Memory_controller", + "pf1_class_code_base_mqdma": "05", + "pf1_class_code_sub_mqdma": 80, + "pf1_sub_class_interface_menu_mqdma": "Other_memory_controller", + "pf1_class_code_interface_mqdma": 0, + "pf1_class_code_mqdma": "058000", + "pf2_base_class_menu_mqdma": "Memory_controller", + "pf2_class_code_base_mqdma": "05", + "pf2_class_code_sub_mqdma": 80, + "pf2_sub_class_interface_menu_mqdma": "Other_memory_controller", + "pf2_class_code_interface_mqdma": 0, + "pf2_class_code_mqdma": "058000", + "pf3_base_class_menu_mqdma": "Memory_controller", + "pf3_class_code_base_mqdma": "05", + "pf3_class_code_sub_mqdma": 80, + "pf3_sub_class_interface_menu_mqdma": "Other_memory_controller", + "pf3_class_code_interface_mqdma": 0, + "pf3_class_code_mqdma": "058000", + "sriov_first_vf_offset": 1, + "pf0_sriov_cap_ver": 1, + "pf0_sriov_cap_initial_vf": 0, + "pf0_sriov_func_dep_link": 0, + "pf0_sriov_first_vf_offset": 0, + "pf0_sriov_vf_device_id": "A041", + "pf0_sriov_supported_page_size": "00000553", + "pf1_sriov_cap_ver": 1, + "pf1_sriov_cap_initial_vf": 0, + "pf1_sriov_first_vf_offset": 0, + "pf1_sriov_func_dep_link": "0001", + "pf1_sriov_supported_page_size": "00000553", + "pf1_sriov_vf_device_id": "A141", + "pf2_sriov_cap_ver": 1, + "pf2_sriov_cap_initial_vf": 0, + "pf2_sriov_first_vf_offset": 0, + "pf2_sriov_func_dep_link": "0002", + "pf2_sriov_supported_page_size": "00000553", + "pf2_sriov_vf_device_id": "A241", + "pf3_sriov_cap_initial_vf": 0, + "pf3_sriov_cap_ver": 1, + "pf3_sriov_first_vf_offset": 0, + "pf3_sriov_func_dep_link": "0003", + "pf3_sriov_supported_page_size": "00000553", + "pf3_sriov_vf_device_id": "A341", + "pf0_ari_enabled": "false", + "pf0_msix_enabled_mqdma": "false", + "pf1_msix_enabled_mqdma": "false", + "pf2_msix_enabled_mqdma": "false", + "pf3_msix_enabled_mqdma": "false", + "pf0_msix_cap_table_size_mqdma": 0, + "pf1_msix_cap_table_size_mqdma": 0, + "pf2_msix_cap_table_size_mqdma": 0, + "pf3_msix_cap_table_size_mqdma": 0, + "pf0_msix_cap_table_offset_mqdma": 0, + "pf1_msix_cap_table_offset_mqdma": 0, + "pf2_msix_cap_table_offset_mqdma": 0, + "pf3_msix_cap_table_offset_mqdma": 0, + "pf0_msix_cap_table_bir_mqdma": "BAR_0", + "pf1_msix_cap_table_bir_mqdma": "BAR_0", + "pf2_msix_cap_table_bir_mqdma": "BAR_0", + "pf3_msix_cap_table_bir_mqdma": "BAR_0", + "pf0_msix_cap_pba_offset_mqdma": 0, + "pf1_msix_cap_pba_offset_mqdma": 0, + "pf2_msix_cap_pba_offset_mqdma": 0, + "pf3_msix_cap_pba_offset_mqdma": 0, + "pf0_msix_cap_pba_bir_mqdma": "BAR_0", + "pf1_msix_cap_pba_bir_mqdma": "BAR_0", + "pf2_msix_cap_pba_bir_mqdma": "BAR_0", + "pf3_msix_cap_pba_bir_mqdma": "BAR_0", + "msi_x_options": "None", + "dsc_bypass_rd_out": 0, + "dsc_bypass_wr_out": 0, + "num_queues": 1, + "enable_auto_rxeq": "False", + "enable_pcie_debug": "False", + "en_axi_mm_mqdma": "true", + "en_axi_st_mqdma": "false", + "enable_more_clk": "false", + "tl_credits_cd": 15, + "tl_credits_ch": 15, + "set_finite_credit": "false", + "enable_resource_reduction": "false", + "usplus_es1_seqnum_bypass": "false", + "bridge_registers_offset_enable": "false", + "enable_gen4": "true", + "tandem_enable_rfsoc": "false", + "local_test": "false", + "ctrl_skip_mask": "true", + "pf0_ats_enabled": "false", + "pf0_pri_enabled": "false", + "aspm_support": "No_ASPM", + "pf0_aer_cap_ecrc_gen_and_check_capable": "false", + "gen_pipe_debug": "false", + "msi_rx_pin_en": "FALSE", + "msix_rx_pin_en": "TRUE", + "intx_rx_pin_en": "true", + "msix_type": "HARD", + "enable_lane_reversal": "false", + "enable_mark_debug": "false", + "master_cal_only": "false", + "enable_multi_pcie": "false", + "pf0_rbar_num": 1, + "pf1_rbar_num": 1, + "pf2_rbar_num": 1, + "pf3_rbar_num": 1, + "pf0_bar0_index": 0, + "pf0_bar1_index": 7, + "pf0_bar2_index": 7, + "pf0_bar3_index": 7, + "pf0_bar4_index": 7, + "pf0_bar5_index": 7, + "pf1_bar0_index": 0, + "pf1_bar1_index": 7, + "pf1_bar2_index": 7, + "pf1_bar3_index": 7, + "pf1_bar4_index": 7, + "pf1_bar5_index": 7, + "pf2_bar0_index": 0, + "pf2_bar1_index": 7, + "pf2_bar2_index": 7, + "pf2_bar3_index": 7, + "pf2_bar4_index": 7, + "pf2_bar5_index": 7, + "pf3_bar0_index": 0, + "pf3_bar1_index": 7, + "pf3_bar2_index": 7, + "pf3_bar3_index": 7, + "pf3_bar4_index": 7, + "pf3_bar5_index": 7, + "pf0_rbar_cap_bar0": 65520, + "pf0_rbar_cap_bar1": 0, + "pf0_rbar_cap_bar2": 0, + "pf0_rbar_cap_bar3": 0, + "pf0_rbar_cap_bar4": 0, + "pf0_rbar_cap_bar5": 0, + "pf1_rbar_cap_bar0": 65520, + "pf1_rbar_cap_bar1": 0, + "pf1_rbar_cap_bar2": 0, + "pf1_rbar_cap_bar3": 0, + "pf1_rbar_cap_bar4": 0, + "pf1_rbar_cap_bar5": 0, + "pf2_rbar_cap_bar0": 65520, + "pf2_rbar_cap_bar1": 0, + "pf2_rbar_cap_bar2": 0, + "pf2_rbar_cap_bar3": 0, + "pf2_rbar_cap_bar4": 0, + "pf2_rbar_cap_bar5": 0, + "pf3_rbar_cap_bar0": 65520, + "pf3_rbar_cap_bar1": 0, + "pf3_rbar_cap_bar2": 0, + "pf3_rbar_cap_bar3": 0, + "pf3_rbar_cap_bar4": 0, + "pf3_rbar_cap_bar5": 0, + "mpsoc_pl_rp_enable": "false", + "enable_slave_read_64os": "false", + "m_axib_num_write_scale": 1, + "disable_gt_loc": "false", + "disable_user_clock_root": "true", + "enable_epyc_chipset_fix": "false", + "broadcom_sbr_wa": "false", + "tl_tx_mux_strict_priority": "false", + "en_slot_cap_reg": "false", + "slot_cap_reg": "00000040", + "sim_model": "NO", + "lane_order": "Bottom", + "gt_loc_num": "X99Y99", + "example_design_type": "RTL", + "performance_exdes": "false", + "descriptor_bypass_exdes": "false", + "virtio_exdes": "false", + "virtio_perf_exdes": "false", + "insert_cips": "false", + "en_bridge_slv": "true", + "edk_iptype": "PERIPHERAL", + "axibar_0": 0, + "axibar_highaddr_0": 4294967295 + }, + "memory-view": { + "M_AXI_B": { + "axi_dma_0": { + "Reg": { + "baseaddr": 0, + "highaddr": 1023, + "size": 1024 + } + }, + "axis_switch_0": { + "Reg": { + "baseaddr": 1024, + "highaddr": 2047, + "size": 1024 + } + } + } + }, + "axi_bars": { + "BAR0": { + "translation": 0, + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + }, + "pcie_bars": { + "BAR0": { + "translation": 0 + } + } + } +} diff --git a/etc/fpga/alveo.json b/etc/fpga/alveo.json new file mode 100644 index 000000000..e873ed4be --- /dev/null +++ b/etc/fpga/alveo.json @@ -0,0 +1,12 @@ +{ + "fpgas": { + "alveo": { + "id": "10ee:9041", + "slot": "0000:5e:00.0", + "do_reset": true, + "ips": "alveo-xbar-pcie/alveo-xbar-pcie.json", + "polling": true, + "interface": "pcie" + } + } +} diff --git a/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino-v2.json b/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino-v2.json new file mode 100644 index 000000000..6afc493d8 --- /dev/null +++ b/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino-v2.json @@ -0,0 +1,1379 @@ +{ + "aurora_aurora_8b10b_ch0": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_0_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "true", + "supportlevel": 1, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "true", + "singleend_gtrefclk": "true", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S00_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M00_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch1": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_1_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S01_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M01_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch2": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_3_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": 1, + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S02_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M02_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch3": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_2_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": 1, + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S03_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M03_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "axi_gpio_0": { + "vlnv": "xilinx.com:ip:axi_gpio:2.0", + "parameters": { + "c_family": "virtex7", + "c_s_axi_addr_width": 9, + "c_s_axi_data_width": 32, + "c_gpio_width": 8, + "c_gpio2_width": 32, + "c_all_inputs": 0, + "c_all_inputs_2": 0, + "c_all_outputs": 1, + "c_all_outputs_2": 0, + "c_interrupt_present": 0, + "c_dout_default": 0, + "c_tri_default": 4294967295, + "c_is_dual": 0, + "c_dout_default_2": 0, + "c_tri_default_2": 4294967295, + "component_name": "design_1_axi_gpio_0_0", + "use_board_flow": "false", + "gpio_board_interface": "led_8bits", + "gpio2_board_interface": "Custom", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 127 + } + }, + "crossbar_axis_interconnect_0_xbar": { + "vlnv": "xilinx.com:ip:axis_switch:1.1", + "parameters": { + "c_family": "virtex7", + "c_num_si_slots": 6, + "c_log_si_slots": 3, + "c_num_mi_slots": 6, + "c_axis_tdata_width": 32, + "c_axis_tid_width": 1, + "c_axis_tdest_width": 1, + "c_axis_tuser_width": 1, + "c_axis_signal_set": 27, + "c_arb_on_max_xfers": 1, + "c_arb_on_num_cycles": 0, + "c_arb_on_tlast": 0, + "c_include_arbiter": 1, + "c_arb_algorithm": 0, + "c_output_reg": 0, + "c_decoder_reg": 1, + "c_m_axis_connectivity_array": 68719476735, + "c_m_axis_basetdest_array": 42, + "c_m_axis_hightdest_array": 42, + "c_routing_mode": 1, + "c_s_axi_ctrl_addr_width": 7, + "c_s_axi_ctrl_data_width": 32, + "c_common_clock": 0, + "num_si": 6, + "num_mi": 6, + "routing_mode": 1, + "has_tready": 1, + "tdata_num_bytes": 4, + "has_tstrb": 0, + "has_tkeep": 1, + "has_tlast": 1, + "tid_width": 0, + "tdest_width": 0, + "tuser_width": 0, + "has_aclken": 0, + "arb_on_max_xfers": 1, + "arb_on_num_cycles": 0, + "arb_on_tlast": 0, + "arb_algorithm": 0, + "decoder_reg": 1, + "output_reg": 0, + "common_clock": 0, + "m00_axis_basetdest": 0, + "m01_axis_basetdest": 1, + "m02_axis_basetdest": 2, + "m03_axis_basetdest": 3, + "m04_axis_basetdest": 4, + "m05_axis_basetdest": 5, + "m06_axis_basetdest": 6, + "m07_axis_basetdest": 7, + "m08_axis_basetdest": 8, + "m09_axis_basetdest": 9, + "m10_axis_basetdest": 10, + "m11_axis_basetdest": 11, + "m12_axis_basetdest": 12, + "m13_axis_basetdest": 13, + "m14_axis_basetdest": 14, + "m15_axis_basetdest": 15, + "m00_axis_hightdest": 0, + "m01_axis_hightdest": 1, + "m02_axis_hightdest": 2, + "m03_axis_hightdest": 3, + "m04_axis_hightdest": 4, + "m05_axis_hightdest": 5, + "m06_axis_hightdest": 6, + "m07_axis_hightdest": 7, + "m08_axis_hightdest": 8, + "m09_axis_hightdest": 9, + "m10_axis_hightdest": 10, + "m11_axis_hightdest": 11, + "m12_axis_hightdest": 12, + "m13_axis_hightdest": 13, + "m14_axis_hightdest": 14, + "m15_axis_hightdest": 15, + "m00_s00_connectivity": 1, + "m00_s01_connectivity": 1, + "m00_s02_connectivity": 1, + "m00_s03_connectivity": 1, + "m00_s04_connectivity": 1, + "m00_s05_connectivity": 1, + "m00_s06_connectivity": 1, + "m00_s07_connectivity": 1, + "m00_s08_connectivity": 1, + "m00_s09_connectivity": 1, + "m00_s10_connectivity": 1, + "m00_s11_connectivity": 1, + "m00_s12_connectivity": 1, + "m00_s13_connectivity": 1, + "m00_s14_connectivity": 1, + "m00_s15_connectivity": 1, + "m01_s00_connectivity": 1, + "m01_s01_connectivity": 1, + "m01_s02_connectivity": 1, + "m01_s03_connectivity": 1, + "m01_s04_connectivity": 1, + "m01_s05_connectivity": 1, + "m01_s06_connectivity": 1, + "m01_s07_connectivity": 1, + "m01_s08_connectivity": 1, + "m01_s09_connectivity": 1, + "m01_s10_connectivity": 1, + "m01_s11_connectivity": 1, + "m01_s12_connectivity": 1, + "m01_s13_connectivity": 1, + "m01_s14_connectivity": 1, + "m01_s15_connectivity": 1, + "m02_s00_connectivity": 1, + "m02_s01_connectivity": 1, + "m02_s02_connectivity": 1, + "m02_s03_connectivity": 1, + "m02_s04_connectivity": 1, + "m02_s05_connectivity": 1, + "m02_s06_connectivity": 1, + "m02_s07_connectivity": 1, + "m02_s08_connectivity": 1, + "m02_s09_connectivity": 1, + "m02_s10_connectivity": 1, + "m02_s11_connectivity": 1, + "m02_s12_connectivity": 1, + "m02_s13_connectivity": 1, + "m02_s14_connectivity": 1, + "m02_s15_connectivity": 1, + "m03_s00_connectivity": 1, + "m03_s01_connectivity": 1, + "m03_s02_connectivity": 1, + "m03_s03_connectivity": 1, + "m03_s04_connectivity": 1, + "m03_s05_connectivity": 1, + "m03_s06_connectivity": 1, + "m03_s07_connectivity": 1, + "m03_s08_connectivity": 1, + "m03_s09_connectivity": 1, + "m03_s10_connectivity": 1, + "m03_s11_connectivity": 1, + "m03_s12_connectivity": 1, + "m03_s13_connectivity": 1, + "m03_s14_connectivity": 1, + "m03_s15_connectivity": 1, + "m04_s00_connectivity": 1, + "m04_s01_connectivity": 1, + "m04_s02_connectivity": 1, + "m04_s03_connectivity": 1, + "m04_s04_connectivity": 1, + "m04_s05_connectivity": 1, + "m04_s06_connectivity": 1, + "m04_s07_connectivity": 1, + "m04_s08_connectivity": 1, + "m04_s09_connectivity": 1, + "m04_s10_connectivity": 1, + "m04_s11_connectivity": 1, + "m04_s12_connectivity": 1, + "m04_s13_connectivity": 1, + "m04_s14_connectivity": 1, + "m04_s15_connectivity": 1, + "m05_s00_connectivity": 1, + "m05_s01_connectivity": 1, + "m05_s02_connectivity": 1, + "m05_s03_connectivity": 1, + "m05_s04_connectivity": 1, + "m05_s05_connectivity": 1, + "m05_s06_connectivity": 1, + "m05_s07_connectivity": 1, + "m05_s08_connectivity": 1, + "m05_s09_connectivity": 1, + "m05_s10_connectivity": 1, + "m05_s11_connectivity": 1, + "m05_s12_connectivity": 1, + "m05_s13_connectivity": 1, + "m05_s14_connectivity": 1, + "m05_s15_connectivity": 1, + "m06_s00_connectivity": 1, + "m06_s01_connectivity": 1, + "m06_s02_connectivity": 1, + "m06_s03_connectivity": 1, + "m06_s04_connectivity": 1, + "m06_s05_connectivity": 1, + "m06_s06_connectivity": 1, + "m06_s07_connectivity": 1, + "m06_s08_connectivity": 1, + "m06_s09_connectivity": 1, + "m06_s10_connectivity": 1, + "m06_s11_connectivity": 1, + "m06_s12_connectivity": 1, + "m06_s13_connectivity": 1, + "m06_s14_connectivity": 1, + "m06_s15_connectivity": 1, + "m07_s00_connectivity": 1, + "m07_s01_connectivity": 1, + "m07_s02_connectivity": 1, + "m07_s03_connectivity": 1, + "m07_s04_connectivity": 1, + "m07_s05_connectivity": 1, + "m07_s06_connectivity": 1, + "m07_s07_connectivity": 1, + "m07_s08_connectivity": 1, + "m07_s09_connectivity": 1, + "m07_s10_connectivity": 1, + "m07_s11_connectivity": 1, + "m07_s12_connectivity": 1, + "m07_s13_connectivity": 1, + "m07_s14_connectivity": 1, + "m07_s15_connectivity": 1, + "m08_s00_connectivity": 1, + "m08_s01_connectivity": 1, + "m08_s02_connectivity": 1, + "m08_s03_connectivity": 1, + "m08_s04_connectivity": 1, + "m08_s05_connectivity": 1, + "m08_s06_connectivity": 1, + "m08_s07_connectivity": 1, + "m08_s08_connectivity": 1, + "m08_s09_connectivity": 1, + "m08_s10_connectivity": 1, + "m08_s11_connectivity": 1, + "m08_s12_connectivity": 1, + "m08_s13_connectivity": 1, + "m08_s14_connectivity": 1, + "m08_s15_connectivity": 1, + "m09_s00_connectivity": 1, + "m09_s01_connectivity": 1, + "m09_s02_connectivity": 1, + "m09_s03_connectivity": 1, + "m09_s04_connectivity": 1, + "m09_s05_connectivity": 1, + "m09_s06_connectivity": 1, + "m09_s07_connectivity": 1, + "m09_s08_connectivity": 1, + "m09_s09_connectivity": 1, + "m09_s10_connectivity": 1, + "m09_s11_connectivity": 1, + "m09_s12_connectivity": 1, + "m09_s13_connectivity": 1, + "m09_s14_connectivity": 1, + "m09_s15_connectivity": 1, + "m10_s00_connectivity": 1, + "m10_s01_connectivity": 1, + "m10_s02_connectivity": 1, + "m10_s03_connectivity": 1, + "m10_s04_connectivity": 1, + "m10_s05_connectivity": 1, + "m10_s06_connectivity": 1, + "m10_s07_connectivity": 1, + "m10_s08_connectivity": 1, + "m10_s09_connectivity": 1, + "m10_s10_connectivity": 1, + "m10_s11_connectivity": 1, + "m10_s12_connectivity": 1, + "m10_s13_connectivity": 1, + "m10_s14_connectivity": 1, + "m10_s15_connectivity": 1, + "m11_s00_connectivity": 1, + "m11_s01_connectivity": 1, + "m11_s02_connectivity": 1, + "m11_s03_connectivity": 1, + "m11_s04_connectivity": 1, + "m11_s05_connectivity": 1, + "m11_s06_connectivity": 1, + "m11_s07_connectivity": 1, + "m11_s08_connectivity": 1, + "m11_s09_connectivity": 1, + "m11_s10_connectivity": 1, + "m11_s11_connectivity": 1, + "m11_s12_connectivity": 1, + "m11_s13_connectivity": 1, + "m11_s14_connectivity": 1, + "m11_s15_connectivity": 1, + "m12_s00_connectivity": 1, + "m12_s01_connectivity": 1, + "m12_s02_connectivity": 1, + "m12_s03_connectivity": 1, + "m12_s04_connectivity": 1, + "m12_s05_connectivity": 1, + "m12_s06_connectivity": 1, + "m12_s07_connectivity": 1, + "m12_s08_connectivity": 1, + "m12_s09_connectivity": 1, + "m12_s10_connectivity": 1, + "m12_s11_connectivity": 1, + "m12_s12_connectivity": 1, + "m12_s13_connectivity": 1, + "m12_s14_connectivity": 1, + "m12_s15_connectivity": 1, + "m13_s00_connectivity": 1, + "m13_s01_connectivity": 1, + "m13_s02_connectivity": 1, + "m13_s03_connectivity": 1, + "m13_s04_connectivity": 1, + "m13_s05_connectivity": 1, + "m13_s06_connectivity": 1, + "m13_s07_connectivity": 1, + "m13_s08_connectivity": 1, + "m13_s09_connectivity": 1, + "m13_s10_connectivity": 1, + "m13_s11_connectivity": 1, + "m13_s12_connectivity": 1, + "m13_s13_connectivity": 1, + "m13_s14_connectivity": 1, + "m13_s15_connectivity": 1, + "m14_s00_connectivity": 1, + "m14_s01_connectivity": 1, + "m14_s02_connectivity": 1, + "m14_s03_connectivity": 1, + "m14_s04_connectivity": 1, + "m14_s05_connectivity": 1, + "m14_s06_connectivity": 1, + "m14_s07_connectivity": 1, + "m14_s08_connectivity": 1, + "m14_s09_connectivity": 1, + "m14_s10_connectivity": 1, + "m14_s11_connectivity": 1, + "m14_s12_connectivity": 1, + "m14_s13_connectivity": 1, + "m14_s14_connectivity": 1, + "m14_s15_connectivity": 1, + "m15_s00_connectivity": 1, + "m15_s01_connectivity": 1, + "m15_s02_connectivity": 1, + "m15_s03_connectivity": 1, + "m15_s04_connectivity": 1, + "m15_s05_connectivity": 1, + "m15_s06_connectivity": 1, + "m15_s07_connectivity": 1, + "m15_s08_connectivity": 1, + "m15_s09_connectivity": 1, + "m15_s10_connectivity": 1, + "m15_s11_connectivity": 1, + "m15_s12_connectivity": 1, + "m15_s13_connectivity": 1, + "m15_s14_connectivity": 1, + "m15_s15_connectivity": 1, + "component_name": "design_1_xbar_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 4096, + "c_highaddr": 5119 + }, + "ports": [ + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch0:USER_DATA_M_AXI_RX", + "name": "S00_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch0:USER_DATA_S_AXI_TX", + "name": "M00_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch1:USER_DATA_M_AXI_RX", + "name": "S01_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch1:USER_DATA_S_AXI_TX", + "name": "M01_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch2:USER_DATA_M_AXI_RX", + "name": "S02_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch2:USER_DATA_S_AXI_TX", + "name": "M02_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch3:USER_DATA_M_AXI_RX", + "name": "S03_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch3:USER_DATA_S_AXI_TX", + "name": "M03_AXIS" + }, + { + "role": "slave", + "target": "dma_pcie_axi_dma_0:MM2S", + "name": "S04_AXIS" + }, + { + "role": "master", + "target": "dma_pcie_axi_dma_0:S2MM", + "name": "M04_AXIS" + }, + { + "role": "slave", + "target": "dino_dinoif_fast_0:M00_AXIS", + "name": "S05_AXIS" + }, + { + "role": "master", + "target": "dino_dinoif_dac_0:S00_AXIS", + "name": "M05_AXIS" + } + ], + "num_ports": 6 + }, + "dino_axi_iic_0": { + "vlnv": "xilinx.com:ip:axi_iic:2.1", + "parameters": { + "c_family": "virtex7", + "c_s_axi_addr_width": 9, + "c_s_axi_data_width": 32, + "c_iic_freq": 100000, + "c_ten_bit_adr": 0, + "c_gpo_width": 1, + "c_s_axi_aclk_freq_hz": 125000000, + "c_scl_inertial_delay": 0, + "c_sda_inertial_delay": 0, + "c_sda_level": 1, + "c_smbus_pmbus_host": 0, + "c_disable_setup_violation_check": 0, + "c_static_timing_reg_width": 0, + "c_timing_reg_width": 32, + "c_default_value": 0, + "component_name": "design_1_axi_iic_0_0", + "ten_bit_adr": "7_bit", + "axi_aclk_freq_mhz": "125.0", + "iic_freq_khz": 100, + "use_board_flow": "false", + "iic_board_interface": "Custom", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 16384, + "c_highaddr": 17407 + }, + "irqs": { + "iic2intc_irpt": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:2" + } + }, + "dino_dinoif_dac_0": { + "vlnv": "xilinx.com:module_ref:dinoif_dac:1.0", + "i2c_channel": 1, + "parameters": { + "component_name": "design_1_dinoif_dac_0_0", + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M05_AXIS", + "name": "S00_AXIS" + } + ] + }, + "dino_dinoif_fast_0": { + "vlnv": "xilinx.com:module_ref:dinoif_fast:1.0", + "i2c_channel": 0, + "parameters": { + "component_name": "design_1_dinoif_fast_0_0", + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S05_AXIS", + "name": "M00_AXIS" + } + ] + }, + "dino_registerif_0": { + "vlnv": "xilinx.com:module_ref:registerif:1.0", + "parameters": { + "c_axi_data_width": 32, + "c_axi_addr_width": 32, + "component_name": "design_1_registerif_0_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 20480, + "c_highaddr": 21503 + } + }, + "dma_pcie_axi_dma_0": { + "vlnv": "xilinx.com:ip:axi_dma:7.1", + "parameters": { + "c_s_axi_lite_addr_width": 10, + "c_s_axi_lite_data_width": 32, + "c_dlytmr_resolution": 125, + "c_prmry_is_aclk_async": 0, + "c_enable_multi_channel": 0, + "c_num_mm2s_channels": 1, + "c_num_s2mm_channels": 1, + "c_include_sg": 1, + "c_sg_include_stscntrl_strm": 0, + "c_sg_use_stsapp_length": 0, + "c_sg_length_width": 14, + "c_m_axi_sg_addr_width": 32, + "c_m_axi_sg_data_width": 32, + "c_m_axis_mm2s_cntrl_tdata_width": 32, + "c_s_axis_s2mm_sts_tdata_width": 32, + "c_micro_dma": 0, + "c_include_mm2s": 1, + "c_include_mm2s_sf": 1, + "c_mm2s_burst_size": 16, + "c_m_axi_mm2s_addr_width": 32, + "c_m_axi_mm2s_data_width": 32, + "c_m_axis_mm2s_tdata_width": 32, + "c_include_mm2s_dre": 0, + "c_include_s2mm": 1, + "c_include_s2mm_sf": 1, + "c_s2mm_burst_size": 16, + "c_m_axi_s2mm_addr_width": 32, + "c_m_axi_s2mm_data_width": 32, + "c_s_axis_s2mm_tdata_width": 32, + "c_include_s2mm_dre": 0, + "c_increase_throughput": 0, + "c_family": "virtex7", + "component_name": "design_1_axi_dma_0_0", + "c_addr_width": 32, + "c_single_interface": 0, + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 12288, + "c_highaddr": 13311 + }, + "memory-view": { + "M_AXI_SG": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_MM2S": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_S2MM": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + } + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S04_AXIS", + "name": "MM2S" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M04_AXIS", + "name": "S2MM" + } + ], + "irqs": { + "mm2s_introut": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:0", + "s2mm_introut": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:1" + } + }, + "dma_pcie_pcie_axi_pcie_0": { + "vlnv": "xilinx.com:ip:axi_pcie:2.9", + "parameters": { + "c_family": "virtex7", + "c_instance": "design_1_axi_pcie_0_1", + "c_s_axi_id_width": 2, + "c_s_axi_addr_width": 32, + "c_s_axi_data_width": 64, + "c_m_axi_addr_width": 32, + "c_m_axi_data_width": 64, + "c_no_of_lanes": 1, + "c_max_link_speed": 1, + "c_pcie_use_mode": "3.0", + "c_device_id": 28705, + "c_vendor_id": 4334, + "c_class_code": 360448, + "c_ref_clk_freq": 0, + "c_rev_id": 0, + "c_subsystem_id": 7, + "c_subsystem_vendor_id": 4334, + "c_pcie_cap_slot_implemented": 0, + "c_slot_clock_config": "TRUE", + "c_msi_decode_enable": "TRUE", + "c_int_fifo_depth": 0, + "c_num_msi_req": 4, + "c_interrupt_pin": 0, + "c_comp_timeout": 0, + "c_include_rc": 0, + "c_s_axi_supports_narrow_burst": 0, + "c_include_baroffset_reg": 1, + "c_axibar_num": 1, + "c_axibar2pciebar_0": 0, + "c_axibar2pciebar_1": 0, + "c_axibar2pciebar_2": 0, + "c_axibar2pciebar_3": 0, + "c_axibar2pciebar_4": 0, + "c_axibar2pciebar_5": 0, + "c_axibar_as_0": 0, + "c_axibar_as_1": 0, + "c_axibar_as_2": 0, + "c_axibar_as_3": 0, + "c_axibar_as_4": 0, + "c_axibar_as_5": 0, + "c_axibar_0": 0, + "c_axibar_highaddr_0": 4294967295, + "c_axibar_1": 4294967295, + "c_axibar_highaddr_1": 0, + "c_axibar_2": 4294967295, + "c_axibar_highaddr_2": 0, + "c_axibar_3": 4294967295, + "c_axibar_highaddr_3": 0, + "c_axibar_4": 4294967295, + "c_axibar_highaddr_4": 0, + "c_axibar_5": 4294967295, + "c_axibar_highaddr_5": 0, + "c_pciebar_num": 1, + "c_pciebar_as": 0, + "c_pciebar_len_0": 20, + "c_pciebar2axibar_0": 0, + "c_pciebar2axibar_0_sec": 1, + "c_pciebar_len_1": 16, + "c_pciebar2axibar_1": 4294967295, + "c_pciebar2axibar_1_sec": 1, + "c_pciebar_len_2": 16, + "c_pciebar2axibar_2": 4294967295, + "c_pciebar2axibar_2_sec": 1, + "c_pcie_blk_locn": 3, + "c_xlnx_ref_board": "VC707", + "pcie_ext_clk": "FALSE", + "pcie_ext_gt_common": "FALSE", + "ext_ch_gt_drp": "FALSE", + "shared_logic_in_core": "false", + "transceiver_ctrl_status_ports": "FALSE", + "ext_pipe_interface": "FALSE", + "c_device": "xc7vx485t", + "c_speed": -2, + "axi_aclk_loopback": "false", + "no_slv_err": "false", + "c_rp_bar_hide": "FALSE", + "enable_jtag_dbg": "false", + "c_axibar_chk_slv_err": "false", + "reduce_oob_freq": "false", + "component_name": "design_1_axi_pcie_0_1", + "include_rc": "PCI_Express_Endpoint_device", + "ref_clk_freq": "100_MHz", + "slot_clock_config": "true", + "pcie_use_mode": "GES_and_Production", + "no_of_lanes": "X1", + "max_link_speed": "5.0_GT/s", + "vendor_id": 4334, + "device_id": 28705, + "rev_id": 0, + "subsystem_vendor_id": 4334, + "subsystem_id": 7, + "enable_class_code": "true", + "class_code": 360448, + "base_class_menu": "Memory_controller", + "sub_class_interface_menu": "Other_memory_controller", + "bar0_enabled": "true", + "bar1_enabled": "false", + "bar2_enabled": "false", + "bar0_type": "Memory", + "bar1_type": "N/A", + "bar2_type": "N/A", + "bar0_scale": "Megabytes", + "bar1_scale": "N/A", + "bar2_scale": "N/A", + "bar0_size": 1, + "bar1_size": 8, + "bar2_size": 8, + "pciebar2axibar_0": 0, + "pciebar2axibar_1": 4294967295, + "pciebar2axibar_2": 4294967295, + "pciebar2axibar_1_sec": 1, + "pciebar2axibar_0_sec": 1, + "pciebar2axibar_2_sec": 1, + "interrupt_pin": "false", + "msi_decode_enabled": "true", + "num_msi_req": 4, + "int_fifo_depth": 16, + "comp_timeout": "50us", + "include_baroffset_reg": "true", + "axibar_as_0": "false", + "axibar_as_1": "false", + "axibar_as_2": "false", + "axibar_as_3": "false", + "axibar_as_4": "false", + "axibar_as_5": "false", + "axibar_1": 4294967295, + "axibar_2": 4294967295, + "axibar_3": 4294967295, + "axibar_4": 4294967295, + "axibar_5": 4294967295, + "axibar_highaddr_1": 0, + "axibar_highaddr_2": 0, + "axibar_highaddr_3": 0, + "axibar_highaddr_4": 0, + "axibar_highaddr_5": 0, + "axibar2pciebar_0": 0, + "axibar2pciebar_1": 0, + "axibar2pciebar_2": 0, + "axibar2pciebar_3": 0, + "axibar2pciebar_4": 0, + "axibar2pciebar_5": 0, + "baseaddr": 4096, + "highaddr": 8191, + "s_axi_id_width": 2, + "s_axi_addr_width": 32, + "s_axi_data_width": 64, + "m_axi_addr_width": 32, + "m_axi_data_width": 64, + "s_axi_supports_narrow_burst": "false", + "bar_64bit": "false", + "xlnx_ref_board": "VC707", + "pcie_blk_locn": "X1Y0", + "axibar_num": 1, + "en_ext_clk": "false", + "en_ext_gt_common": "false", + "en_ext_ch_gt_drp": "false", + "en_transceiver_status_ports": "false", + "en_ext_pipe_interface": "false", + "rp_bar_hide": "false", + "edk_iptype": "PERIPHERAL", + "axibar_0": 0, + "axibar_highaddr_0": 4294967295 + }, + "memory-view": { + "M_AXI": { + "axi_gpio_0": { + "Reg": { + "baseaddr": 0, + "highaddr": 127, + "size": 128 + } + }, + "crossbar_axis_interconnect_0_xbar": { + "Reg": { + "baseaddr": 4096, + "highaddr": 5119, + "size": 1024 + } + }, + "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0": { + "reg0": { + "baseaddr": 8192, + "highaddr": 9215, + "size": 1024 + } + }, + "dma_pcie_axi_dma_0": { + "Reg": { + "baseaddr": 12288, + "highaddr": 13311, + "size": 1024 + } + }, + "dino_axi_iic_0": { + "Reg": { + "baseaddr": 16384, + "highaddr": 17407, + "size": 1024 + } + }, + "dino_registerif_0": { + "reg0": { + "baseaddr": 20480, + "highaddr": 21503, + "size": 1024 + } + } + } + }, + "axi_bars": { + "BAR0": { + "translation": 0, + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + }, + "pcie_bars": { + "BAR0": { + "translation": 0 + } + } + }, + "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0": { + "vlnv": "xilinx.com:module_ref:axi_pcie_intc:1.0", + "parameters": { + "component_name": "design_1_axi_pcie_intc_0_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 8192, + "c_highaddr": 9215 + } + } +} diff --git a/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino.json b/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino.json new file mode 100644 index 000000000..89d1e7780 --- /dev/null +++ b/etc/fpga/vc707-xbar-pcie-dino/vc707-xbar-pcie-dino.json @@ -0,0 +1,1361 @@ +{ + "aurora_aurora_8b10b_ch0": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_0_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "true", + "supportlevel": 1, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "true", + "singleend_gtrefclk": "true", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S00_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M00_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch1": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_1_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S01_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M01_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch2": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_3_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": 1, + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S02_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M02_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_aurora_8b10b_ch3": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_2_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": 1, + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S03_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M03_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "axi_gpio_0": { + "vlnv": "xilinx.com:ip:axi_gpio:2.0", + "parameters": { + "c_family": "virtex7", + "c_s_axi_addr_width": 9, + "c_s_axi_data_width": 32, + "c_gpio_width": 8, + "c_gpio2_width": 32, + "c_all_inputs": 0, + "c_all_inputs_2": 0, + "c_all_outputs": 1, + "c_all_outputs_2": 0, + "c_interrupt_present": 0, + "c_dout_default": 0, + "c_tri_default": 4294967295, + "c_is_dual": 0, + "c_dout_default_2": 0, + "c_tri_default_2": 4294967295, + "component_name": "design_1_axi_gpio_0_0", + "use_board_flow": "false", + "gpio_board_interface": "led_8bits", + "gpio2_board_interface": "Custom", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 127 + } + }, + "crossbar_axis_interconnect_0_xbar": { + "vlnv": "xilinx.com:ip:axis_switch:1.1", + "parameters": { + "c_family": "virtex7", + "c_num_si_slots": 6, + "c_log_si_slots": 3, + "c_num_mi_slots": 6, + "c_axis_tdata_width": 32, + "c_axis_tid_width": 1, + "c_axis_tdest_width": 1, + "c_axis_tuser_width": 1, + "c_axis_signal_set": 27, + "c_arb_on_max_xfers": 1, + "c_arb_on_num_cycles": 0, + "c_arb_on_tlast": 0, + "c_include_arbiter": 1, + "c_arb_algorithm": 0, + "c_output_reg": 0, + "c_decoder_reg": 1, + "c_m_axis_connectivity_array": 68719476735, + "c_m_axis_basetdest_array": 42, + "c_m_axis_hightdest_array": 42, + "c_routing_mode": 1, + "c_s_axi_ctrl_addr_width": 7, + "c_s_axi_ctrl_data_width": 32, + "c_common_clock": 0, + "num_si": 6, + "num_mi": 6, + "routing_mode": 1, + "has_tready": 1, + "tdata_num_bytes": 4, + "has_tstrb": 0, + "has_tkeep": 1, + "has_tlast": 1, + "tid_width": 0, + "tdest_width": 0, + "tuser_width": 0, + "has_aclken": 0, + "arb_on_max_xfers": 1, + "arb_on_num_cycles": 0, + "arb_on_tlast": 0, + "arb_algorithm": 0, + "decoder_reg": 1, + "output_reg": 0, + "common_clock": 0, + "m00_axis_basetdest": 0, + "m01_axis_basetdest": 1, + "m02_axis_basetdest": 2, + "m03_axis_basetdest": 3, + "m04_axis_basetdest": 4, + "m05_axis_basetdest": 5, + "m06_axis_basetdest": 6, + "m07_axis_basetdest": 7, + "m08_axis_basetdest": 8, + "m09_axis_basetdest": 9, + "m10_axis_basetdest": 10, + "m11_axis_basetdest": 11, + "m12_axis_basetdest": 12, + "m13_axis_basetdest": 13, + "m14_axis_basetdest": 14, + "m15_axis_basetdest": 15, + "m00_axis_hightdest": 0, + "m01_axis_hightdest": 1, + "m02_axis_hightdest": 2, + "m03_axis_hightdest": 3, + "m04_axis_hightdest": 4, + "m05_axis_hightdest": 5, + "m06_axis_hightdest": 6, + "m07_axis_hightdest": 7, + "m08_axis_hightdest": 8, + "m09_axis_hightdest": 9, + "m10_axis_hightdest": 10, + "m11_axis_hightdest": 11, + "m12_axis_hightdest": 12, + "m13_axis_hightdest": 13, + "m14_axis_hightdest": 14, + "m15_axis_hightdest": 15, + "m00_s00_connectivity": 1, + "m00_s01_connectivity": 1, + "m00_s02_connectivity": 1, + "m00_s03_connectivity": 1, + "m00_s04_connectivity": 1, + "m00_s05_connectivity": 1, + "m00_s06_connectivity": 1, + "m00_s07_connectivity": 1, + "m00_s08_connectivity": 1, + "m00_s09_connectivity": 1, + "m00_s10_connectivity": 1, + "m00_s11_connectivity": 1, + "m00_s12_connectivity": 1, + "m00_s13_connectivity": 1, + "m00_s14_connectivity": 1, + "m00_s15_connectivity": 1, + "m01_s00_connectivity": 1, + "m01_s01_connectivity": 1, + "m01_s02_connectivity": 1, + "m01_s03_connectivity": 1, + "m01_s04_connectivity": 1, + "m01_s05_connectivity": 1, + "m01_s06_connectivity": 1, + "m01_s07_connectivity": 1, + "m01_s08_connectivity": 1, + "m01_s09_connectivity": 1, + "m01_s10_connectivity": 1, + "m01_s11_connectivity": 1, + "m01_s12_connectivity": 1, + "m01_s13_connectivity": 1, + "m01_s14_connectivity": 1, + "m01_s15_connectivity": 1, + "m02_s00_connectivity": 1, + "m02_s01_connectivity": 1, + "m02_s02_connectivity": 1, + "m02_s03_connectivity": 1, + "m02_s04_connectivity": 1, + "m02_s05_connectivity": 1, + "m02_s06_connectivity": 1, + "m02_s07_connectivity": 1, + "m02_s08_connectivity": 1, + "m02_s09_connectivity": 1, + "m02_s10_connectivity": 1, + "m02_s11_connectivity": 1, + "m02_s12_connectivity": 1, + "m02_s13_connectivity": 1, + "m02_s14_connectivity": 1, + "m02_s15_connectivity": 1, + "m03_s00_connectivity": 1, + "m03_s01_connectivity": 1, + "m03_s02_connectivity": 1, + "m03_s03_connectivity": 1, + "m03_s04_connectivity": 1, + "m03_s05_connectivity": 1, + "m03_s06_connectivity": 1, + "m03_s07_connectivity": 1, + "m03_s08_connectivity": 1, + "m03_s09_connectivity": 1, + "m03_s10_connectivity": 1, + "m03_s11_connectivity": 1, + "m03_s12_connectivity": 1, + "m03_s13_connectivity": 1, + "m03_s14_connectivity": 1, + "m03_s15_connectivity": 1, + "m04_s00_connectivity": 1, + "m04_s01_connectivity": 1, + "m04_s02_connectivity": 1, + "m04_s03_connectivity": 1, + "m04_s04_connectivity": 1, + "m04_s05_connectivity": 1, + "m04_s06_connectivity": 1, + "m04_s07_connectivity": 1, + "m04_s08_connectivity": 1, + "m04_s09_connectivity": 1, + "m04_s10_connectivity": 1, + "m04_s11_connectivity": 1, + "m04_s12_connectivity": 1, + "m04_s13_connectivity": 1, + "m04_s14_connectivity": 1, + "m04_s15_connectivity": 1, + "m05_s00_connectivity": 1, + "m05_s01_connectivity": 1, + "m05_s02_connectivity": 1, + "m05_s03_connectivity": 1, + "m05_s04_connectivity": 1, + "m05_s05_connectivity": 1, + "m05_s06_connectivity": 1, + "m05_s07_connectivity": 1, + "m05_s08_connectivity": 1, + "m05_s09_connectivity": 1, + "m05_s10_connectivity": 1, + "m05_s11_connectivity": 1, + "m05_s12_connectivity": 1, + "m05_s13_connectivity": 1, + "m05_s14_connectivity": 1, + "m05_s15_connectivity": 1, + "m06_s00_connectivity": 1, + "m06_s01_connectivity": 1, + "m06_s02_connectivity": 1, + "m06_s03_connectivity": 1, + "m06_s04_connectivity": 1, + "m06_s05_connectivity": 1, + "m06_s06_connectivity": 1, + "m06_s07_connectivity": 1, + "m06_s08_connectivity": 1, + "m06_s09_connectivity": 1, + "m06_s10_connectivity": 1, + "m06_s11_connectivity": 1, + "m06_s12_connectivity": 1, + "m06_s13_connectivity": 1, + "m06_s14_connectivity": 1, + "m06_s15_connectivity": 1, + "m07_s00_connectivity": 1, + "m07_s01_connectivity": 1, + "m07_s02_connectivity": 1, + "m07_s03_connectivity": 1, + "m07_s04_connectivity": 1, + "m07_s05_connectivity": 1, + "m07_s06_connectivity": 1, + "m07_s07_connectivity": 1, + "m07_s08_connectivity": 1, + "m07_s09_connectivity": 1, + "m07_s10_connectivity": 1, + "m07_s11_connectivity": 1, + "m07_s12_connectivity": 1, + "m07_s13_connectivity": 1, + "m07_s14_connectivity": 1, + "m07_s15_connectivity": 1, + "m08_s00_connectivity": 1, + "m08_s01_connectivity": 1, + "m08_s02_connectivity": 1, + "m08_s03_connectivity": 1, + "m08_s04_connectivity": 1, + "m08_s05_connectivity": 1, + "m08_s06_connectivity": 1, + "m08_s07_connectivity": 1, + "m08_s08_connectivity": 1, + "m08_s09_connectivity": 1, + "m08_s10_connectivity": 1, + "m08_s11_connectivity": 1, + "m08_s12_connectivity": 1, + "m08_s13_connectivity": 1, + "m08_s14_connectivity": 1, + "m08_s15_connectivity": 1, + "m09_s00_connectivity": 1, + "m09_s01_connectivity": 1, + "m09_s02_connectivity": 1, + "m09_s03_connectivity": 1, + "m09_s04_connectivity": 1, + "m09_s05_connectivity": 1, + "m09_s06_connectivity": 1, + "m09_s07_connectivity": 1, + "m09_s08_connectivity": 1, + "m09_s09_connectivity": 1, + "m09_s10_connectivity": 1, + "m09_s11_connectivity": 1, + "m09_s12_connectivity": 1, + "m09_s13_connectivity": 1, + "m09_s14_connectivity": 1, + "m09_s15_connectivity": 1, + "m10_s00_connectivity": 1, + "m10_s01_connectivity": 1, + "m10_s02_connectivity": 1, + "m10_s03_connectivity": 1, + "m10_s04_connectivity": 1, + "m10_s05_connectivity": 1, + "m10_s06_connectivity": 1, + "m10_s07_connectivity": 1, + "m10_s08_connectivity": 1, + "m10_s09_connectivity": 1, + "m10_s10_connectivity": 1, + "m10_s11_connectivity": 1, + "m10_s12_connectivity": 1, + "m10_s13_connectivity": 1, + "m10_s14_connectivity": 1, + "m10_s15_connectivity": 1, + "m11_s00_connectivity": 1, + "m11_s01_connectivity": 1, + "m11_s02_connectivity": 1, + "m11_s03_connectivity": 1, + "m11_s04_connectivity": 1, + "m11_s05_connectivity": 1, + "m11_s06_connectivity": 1, + "m11_s07_connectivity": 1, + "m11_s08_connectivity": 1, + "m11_s09_connectivity": 1, + "m11_s10_connectivity": 1, + "m11_s11_connectivity": 1, + "m11_s12_connectivity": 1, + "m11_s13_connectivity": 1, + "m11_s14_connectivity": 1, + "m11_s15_connectivity": 1, + "m12_s00_connectivity": 1, + "m12_s01_connectivity": 1, + "m12_s02_connectivity": 1, + "m12_s03_connectivity": 1, + "m12_s04_connectivity": 1, + "m12_s05_connectivity": 1, + "m12_s06_connectivity": 1, + "m12_s07_connectivity": 1, + "m12_s08_connectivity": 1, + "m12_s09_connectivity": 1, + "m12_s10_connectivity": 1, + "m12_s11_connectivity": 1, + "m12_s12_connectivity": 1, + "m12_s13_connectivity": 1, + "m12_s14_connectivity": 1, + "m12_s15_connectivity": 1, + "m13_s00_connectivity": 1, + "m13_s01_connectivity": 1, + "m13_s02_connectivity": 1, + "m13_s03_connectivity": 1, + "m13_s04_connectivity": 1, + "m13_s05_connectivity": 1, + "m13_s06_connectivity": 1, + "m13_s07_connectivity": 1, + "m13_s08_connectivity": 1, + "m13_s09_connectivity": 1, + "m13_s10_connectivity": 1, + "m13_s11_connectivity": 1, + "m13_s12_connectivity": 1, + "m13_s13_connectivity": 1, + "m13_s14_connectivity": 1, + "m13_s15_connectivity": 1, + "m14_s00_connectivity": 1, + "m14_s01_connectivity": 1, + "m14_s02_connectivity": 1, + "m14_s03_connectivity": 1, + "m14_s04_connectivity": 1, + "m14_s05_connectivity": 1, + "m14_s06_connectivity": 1, + "m14_s07_connectivity": 1, + "m14_s08_connectivity": 1, + "m14_s09_connectivity": 1, + "m14_s10_connectivity": 1, + "m14_s11_connectivity": 1, + "m14_s12_connectivity": 1, + "m14_s13_connectivity": 1, + "m14_s14_connectivity": 1, + "m14_s15_connectivity": 1, + "m15_s00_connectivity": 1, + "m15_s01_connectivity": 1, + "m15_s02_connectivity": 1, + "m15_s03_connectivity": 1, + "m15_s04_connectivity": 1, + "m15_s05_connectivity": 1, + "m15_s06_connectivity": 1, + "m15_s07_connectivity": 1, + "m15_s08_connectivity": 1, + "m15_s09_connectivity": 1, + "m15_s10_connectivity": 1, + "m15_s11_connectivity": 1, + "m15_s12_connectivity": 1, + "m15_s13_connectivity": 1, + "m15_s14_connectivity": 1, + "m15_s15_connectivity": 1, + "component_name": "design_1_xbar_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 1023 + }, + "ports": [ + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch0:USER_DATA_M_AXI_RX", + "name": "S00_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch0:USER_DATA_S_AXI_TX", + "name": "M00_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch1:USER_DATA_M_AXI_RX", + "name": "S01_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch1:USER_DATA_S_AXI_TX", + "name": "M01_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch2:USER_DATA_M_AXI_RX", + "name": "S02_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch2:USER_DATA_S_AXI_TX", + "name": "M02_AXIS" + }, + { + "role": "slave", + "target": "aurora_aurora_8b10b_ch3:USER_DATA_M_AXI_RX", + "name": "S03_AXIS" + }, + { + "role": "master", + "target": "aurora_aurora_8b10b_ch3:USER_DATA_S_AXI_TX", + "name": "M03_AXIS" + }, + { + "role": "slave", + "target": "dma_pcie_axi_dma_0:MM2S", + "name": "S04_AXIS" + }, + { + "role": "master", + "target": "dma_pcie_axi_dma_0:S2MM", + "name": "M04_AXIS" + }, + { + "role": "slave", + "target": "dino_dinoif_fast_0:M00_AXIS", + "name": "S05_AXIS" + }, + { + "role": "master", + "target": "dino_dinoif_dac_0:S00_AXIS", + "name": "M05_AXIS" + } + ], + "num_ports": 6 + }, + "dino_axi_iic_0": { + "vlnv": "xilinx.com:ip:axi_iic:2.1", + "parameters": { + "c_family": "virtex7", + "c_s_axi_addr_width": 9, + "c_s_axi_data_width": 32, + "c_iic_freq": 100000, + "c_ten_bit_adr": 0, + "c_gpo_width": 1, + "c_s_axi_aclk_freq_hz": 125000000, + "c_scl_inertial_delay": 0, + "c_sda_inertial_delay": 0, + "c_sda_level": 1, + "c_smbus_pmbus_host": 0, + "c_disable_setup_violation_check": 0, + "c_static_timing_reg_width": 0, + "c_timing_reg_width": 32, + "c_default_value": 0, + "component_name": "design_1_axi_iic_0_0", + "ten_bit_adr": "7_bit", + "axi_aclk_freq_mhz": "125.0", + "iic_freq_khz": 100, + "use_board_flow": "false", + "iic_board_interface": "Custom", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 16384, + "c_highaddr": 17407 + }, + "irqs": { + "iic2intc_irpt": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:2" + } + }, + "dino_dinoif_dac_0": { + "vlnv": "xilinx.com:module_ref:dinoif_dac:1.0", + "i2c_channel": 1, + "parameters": { + "component_name": "design_1_dinoif_dac_0_0", + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M05_AXIS", + "name": "S00_AXIS" + } + ] + }, + "dino_dinoif_fast_0": { + "vlnv": "xilinx.com:module_ref:dinoif_fast:1.0", + "i2c_channel": 0, + "parameters": { + "component_name": "design_1_dinoif_fast_0_0", + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S05_AXIS", + "name": "M00_AXIS" + } + ] + }, + "dma_pcie_axi_dma_0": { + "vlnv": "xilinx.com:ip:axi_dma:7.1", + "parameters": { + "c_s_axi_lite_addr_width": 10, + "c_s_axi_lite_data_width": 32, + "c_dlytmr_resolution": 125, + "c_prmry_is_aclk_async": 0, + "c_enable_multi_channel": 0, + "c_num_mm2s_channels": 1, + "c_num_s2mm_channels": 1, + "c_include_sg": 1, + "c_sg_include_stscntrl_strm": 0, + "c_sg_use_stsapp_length": 0, + "c_sg_length_width": 14, + "c_m_axi_sg_addr_width": 32, + "c_m_axi_sg_data_width": 32, + "c_m_axis_mm2s_cntrl_tdata_width": 32, + "c_s_axis_s2mm_sts_tdata_width": 32, + "c_micro_dma": 0, + "c_include_mm2s": 1, + "c_include_mm2s_sf": 1, + "c_mm2s_burst_size": 16, + "c_m_axi_mm2s_addr_width": 32, + "c_m_axi_mm2s_data_width": 32, + "c_m_axis_mm2s_tdata_width": 32, + "c_include_mm2s_dre": 0, + "c_include_s2mm": 1, + "c_include_s2mm_sf": 1, + "c_s2mm_burst_size": 16, + "c_m_axi_s2mm_addr_width": 32, + "c_m_axi_s2mm_data_width": 32, + "c_s_axis_s2mm_tdata_width": 32, + "c_include_s2mm_dre": 0, + "c_increase_throughput": 0, + "c_family": "virtex7", + "component_name": "design_1_axi_dma_0_0", + "c_addr_width": 32, + "c_single_interface": 0, + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 12288, + "c_highaddr": 13311 + }, + "memory-view": { + "M_AXI_SG": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_MM2S": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_S2MM": { + "dma_pcie_pcie_axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + } + }, + "ports": [ + { + "role": "master", + "target": "crossbar_axis_interconnect_0_xbar:S04_AXIS", + "name": "MM2S" + }, + { + "role": "slave", + "target": "crossbar_axis_interconnect_0_xbar:M04_AXIS", + "name": "S2MM" + } + ], + "irqs": { + "mm2s_introut": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:0", + "s2mm_introut": "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0:1" + } + }, + "dma_pcie_pcie_axi_pcie_0": { + "vlnv": "xilinx.com:ip:axi_pcie:2.9", + "parameters": { + "c_family": "virtex7", + "c_instance": "design_1_axi_pcie_0_1", + "c_s_axi_id_width": 2, + "c_s_axi_addr_width": 32, + "c_s_axi_data_width": 64, + "c_m_axi_addr_width": 32, + "c_m_axi_data_width": 64, + "c_no_of_lanes": 1, + "c_max_link_speed": 1, + "c_pcie_use_mode": "3.0", + "c_device_id": 28705, + "c_vendor_id": 4334, + "c_class_code": 360448, + "c_ref_clk_freq": 0, + "c_rev_id": 0, + "c_subsystem_id": 7, + "c_subsystem_vendor_id": 4334, + "c_pcie_cap_slot_implemented": 0, + "c_slot_clock_config": "TRUE", + "c_msi_decode_enable": "TRUE", + "c_int_fifo_depth": 0, + "c_num_msi_req": 4, + "c_interrupt_pin": 0, + "c_comp_timeout": 0, + "c_include_rc": 0, + "c_s_axi_supports_narrow_burst": 0, + "c_include_baroffset_reg": 1, + "c_axibar_num": 1, + "c_axibar2pciebar_0": 0, + "c_axibar2pciebar_1": 0, + "c_axibar2pciebar_2": 0, + "c_axibar2pciebar_3": 0, + "c_axibar2pciebar_4": 0, + "c_axibar2pciebar_5": 0, + "c_axibar_as_0": 0, + "c_axibar_as_1": 0, + "c_axibar_as_2": 0, + "c_axibar_as_3": 0, + "c_axibar_as_4": 0, + "c_axibar_as_5": 0, + "c_axibar_0": 0, + "c_axibar_highaddr_0": 4294967295, + "c_axibar_1": 4294967295, + "c_axibar_highaddr_1": 0, + "c_axibar_2": 4294967295, + "c_axibar_highaddr_2": 0, + "c_axibar_3": 4294967295, + "c_axibar_highaddr_3": 0, + "c_axibar_4": 4294967295, + "c_axibar_highaddr_4": 0, + "c_axibar_5": 4294967295, + "c_axibar_highaddr_5": 0, + "c_pciebar_num": 1, + "c_pciebar_as": 0, + "c_pciebar_len_0": 20, + "c_pciebar2axibar_0": 0, + "c_pciebar2axibar_0_sec": 1, + "c_pciebar_len_1": 16, + "c_pciebar2axibar_1": 4294967295, + "c_pciebar2axibar_1_sec": 1, + "c_pciebar_len_2": 16, + "c_pciebar2axibar_2": 4294967295, + "c_pciebar2axibar_2_sec": 1, + "c_pcie_blk_locn": 3, + "c_xlnx_ref_board": "VC707", + "pcie_ext_clk": "FALSE", + "pcie_ext_gt_common": "FALSE", + "ext_ch_gt_drp": "FALSE", + "shared_logic_in_core": "false", + "transceiver_ctrl_status_ports": "FALSE", + "ext_pipe_interface": "FALSE", + "c_device": "xc7vx485t", + "c_speed": -2, + "axi_aclk_loopback": "false", + "no_slv_err": "false", + "c_rp_bar_hide": "FALSE", + "enable_jtag_dbg": "false", + "c_axibar_chk_slv_err": "false", + "reduce_oob_freq": "false", + "component_name": "design_1_axi_pcie_0_1", + "include_rc": "PCI_Express_Endpoint_device", + "ref_clk_freq": "100_MHz", + "slot_clock_config": "true", + "pcie_use_mode": "GES_and_Production", + "no_of_lanes": "X1", + "max_link_speed": "5.0_GT/s", + "vendor_id": 4334, + "device_id": 28705, + "rev_id": 0, + "subsystem_vendor_id": 4334, + "subsystem_id": 7, + "enable_class_code": "true", + "class_code": 360448, + "base_class_menu": "Memory_controller", + "sub_class_interface_menu": "Other_memory_controller", + "bar0_enabled": "true", + "bar1_enabled": "false", + "bar2_enabled": "false", + "bar0_type": "Memory", + "bar1_type": "N/A", + "bar2_type": "N/A", + "bar0_scale": "Megabytes", + "bar1_scale": "N/A", + "bar2_scale": "N/A", + "bar0_size": 1, + "bar1_size": 8, + "bar2_size": 8, + "pciebar2axibar_0": 0, + "pciebar2axibar_1": 4294967295, + "pciebar2axibar_2": 4294967295, + "pciebar2axibar_1_sec": 1, + "pciebar2axibar_0_sec": 1, + "pciebar2axibar_2_sec": 1, + "interrupt_pin": "false", + "msi_decode_enabled": "true", + "num_msi_req": 4, + "int_fifo_depth": 16, + "comp_timeout": "50us", + "include_baroffset_reg": "true", + "axibar_as_0": "false", + "axibar_as_1": "false", + "axibar_as_2": "false", + "axibar_as_3": "false", + "axibar_as_4": "false", + "axibar_as_5": "false", + "axibar_1": 4294967295, + "axibar_2": 4294967295, + "axibar_3": 4294967295, + "axibar_4": 4294967295, + "axibar_5": 4294967295, + "axibar_highaddr_1": 0, + "axibar_highaddr_2": 0, + "axibar_highaddr_3": 0, + "axibar_highaddr_4": 0, + "axibar_highaddr_5": 0, + "axibar2pciebar_0": 0, + "axibar2pciebar_1": 0, + "axibar2pciebar_2": 0, + "axibar2pciebar_3": 0, + "axibar2pciebar_4": 0, + "axibar2pciebar_5": 0, + "baseaddr": 4096, + "highaddr": 8191, + "s_axi_id_width": 2, + "s_axi_addr_width": 32, + "s_axi_data_width": 64, + "m_axi_addr_width": 32, + "m_axi_data_width": 64, + "s_axi_supports_narrow_burst": "false", + "bar_64bit": "false", + "xlnx_ref_board": "VC707", + "pcie_blk_locn": "X1Y0", + "axibar_num": 1, + "en_ext_clk": "false", + "en_ext_gt_common": "false", + "en_ext_ch_gt_drp": "false", + "en_transceiver_status_ports": "false", + "en_ext_pipe_interface": "false", + "rp_bar_hide": "false", + "edk_iptype": "PERIPHERAL", + "axibar_0": 0, + "axibar_highaddr_0": 4294967295 + }, + "memory-view": { + "M_AXI": { + "axi_gpio_0": { + "Reg": { + "baseaddr": 0, + "highaddr": 127, + "size": 128 + } + }, + "crossbar_axis_interconnect_0_xbar": { + "Reg": { + "baseaddr": 4096, + "highaddr": 5119, + "size": 1024 + } + }, + "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0": { + "reg0": { + "baseaddr": 8192, + "highaddr": 9215, + "size": 1024 + } + }, + "dma_pcie_axi_dma_0": { + "Reg": { + "baseaddr": 12288, + "highaddr": 13311, + "size": 1024 + } + }, + "dino_axi_iic_0": { + "Reg": { + "baseaddr": 16384, + "highaddr": 17407, + "size": 1024 + } + } + } + }, + "axi_bars": { + "BAR0": { + "translation": 0, + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + }, + "pcie_bars": { + "BAR0": { + "translation": 0 + } + } + }, + "dma_pcie_pcie_pcie_interrupts_axi_pcie_intc_0": { + "vlnv": "xilinx.com:module_ref:axi_pcie_intc:1.0", + "parameters": { + "component_name": "design_1_axi_pcie_intc_0_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 8192, + "c_highaddr": 9215 + } + } +} diff --git a/etc/fpga/vc707-xbar-pcie/vc707-xbar-pcie.json b/etc/fpga/vc707-xbar-pcie/vc707-xbar-pcie.json new file mode 100644 index 000000000..2fe40000b --- /dev/null +++ b/etc/fpga/vc707-xbar-pcie/vc707-xbar-pcie.json @@ -0,0 +1,1281 @@ +{ + "aurora_8b10b_ch0": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_0_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "true", + "supportlevel": 1, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "true", + "singleend_gtrefclk": "true", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "axis_interconnect_0_xbar:S00_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "axis_interconnect_0_xbar:M00_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_8b10b_ch1": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_1_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": 1, + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ0", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "axis_interconnect_0_xbar:S01_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "axis_interconnect_0_xbar:M01_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_8b10b_ch2": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_3_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": "X", + "c_gt_loc_26": 1, + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "axis_interconnect_0_xbar:S02_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "axis_interconnect_0_xbar:M02_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "aurora_8b10b_ch3": { + "vlnv": "xilinx.com:ip:aurora_8b10b:11.1", + "parameters": { + "component_name": "design_1_aurora_8b10b_2_0", + "channel_enable": "X0Y0", + "c_refclk_loc_p": "BL8", + "c_refclk_loc_n": "BL7", + "c_column_used": "right", + "c_ucolumn_used": "right", + "c_family": "virtex7", + "c_device": "xc7vx485t", + "c_row_used": "None", + "c_xpackage": "ffg1761", + "c_xspeedgrade": -2, + "c_aurora_lanes": 1, + "c_lane_width": 4, + "c_active_transceiverquads": 1, + "c_start_quad": "X0Y0", + "c_start_lane": "X0Y0", + "c_refclk_source": "none", + "interface_mode": "Framing", + "c_stream": "false", + "dataflow_config": "Duplex", + "backchannel_mode": "Sidebands", + "c_simplex": "false", + "c_simplex_mode": "TX", + "flow_mode": "None", + "c_nfc": "false", + "c_nfc_mode": "IMM", + "c_ufc": "false", + "c_example_simulation": "false", + "c_gtwiz_out": "false", + "c_line_rate": 2, + "cc_line_rate": 2, + "c_refclk_frequency": "250.000", + "cc_refclk_frequency": "250.000", + "c_init_clk": "100.0", + "drp_freq": "100.0", + "c_gt_loc_1": "X", + "c_gt_loc_2": "X", + "c_gt_loc_3": "X", + "c_gt_loc_4": "X", + "c_gt_loc_5": "X", + "c_gt_loc_6": "X", + "c_gt_loc_7": "X", + "c_gt_loc_8": "X", + "c_gt_loc_9": "X", + "c_gt_loc_10": "X", + "c_gt_loc_11": "X", + "c_gt_loc_12": "X", + "c_gt_loc_13": "X", + "c_gt_loc_14": "X", + "c_gt_loc_15": "X", + "c_gt_loc_16": "X", + "c_gt_loc_17": "X", + "c_gt_loc_18": "X", + "c_gt_loc_19": "X", + "c_gt_loc_20": "X", + "c_gt_loc_21": "X", + "c_gt_loc_22": "X", + "c_gt_loc_23": "X", + "c_gt_loc_24": "X", + "c_gt_loc_25": 1, + "c_gt_loc_26": "X", + "c_gt_loc_27": "X", + "c_gt_loc_28": "X", + "c_gt_loc_29": "X", + "c_gt_loc_30": "X", + "c_gt_loc_31": "X", + "c_gt_loc_32": "X", + "c_gt_loc_33": "X", + "c_gt_loc_34": "X", + "c_gt_loc_35": "X", + "c_gt_loc_36": "X", + "c_gt_loc_37": "X", + "c_gt_loc_38": "X", + "c_gt_loc_39": "X", + "c_gt_loc_40": "X", + "c_gt_loc_41": "X", + "c_gt_loc_42": "X", + "c_gt_loc_43": "X", + "c_gt_loc_44": "X", + "c_gt_loc_45": "X", + "c_gt_loc_46": "X", + "c_gt_loc_47": "X", + "c_gt_loc_48": "X", + "c_gt_clock_1": "GTXQ6", + "c_gt_clock_2": "None", + "c_use_scrambler": "false", + "c_use_chipscope": "false", + "c_drp_if": "false", + "transceivercontrol": "false", + "c_use_crc": "false", + "supportlevel": 0, + "c_use_byteswap": "false", + "c_cpll_fbdiv": 2, + "c_cpll_fbdiv_45": 4, + "c_cpll_refclk_div": 1, + "c_rxoutdiv": 2, + "c_txoutdiv": 2, + "user_interface": "AXI_4_Streaming", + "c_ufcbuswidthselect": 32, + "c_ufcrembuswidthselect": 2, + "c_ufcstrbbuswidthselect": 4, + "c_rembuswidthselect": 2, + "isv7gth": "false", + "gtquadcnt": 1, + "port7dmonitorout": 7, + "is_7series": "true", + "singleend_initclk": "false", + "singleend_gtrefclk": "false", + "c_double_gtrxreset": "false", + "c_doccport_enable": "false", + "is_board": "vc707", + "usdrpaddr_width": 8, + "usdmon_width": 16, + "txdiffctrl_width": 3, + "ins_loss_nyq": 14, + "rx_eq_mode": "AUTO", + "rx_coupling": "AC", + "rx_termination": "PROGRAMMABLE", + "rx_termination_prog_value": 800, + "rx_ppm_offset": 200, + "edk_iptype": "PERIPHERAL" + }, + "ports": [ + { + "role": "master", + "target": "axis_interconnect_0_xbar:S03_AXIS", + "name": "USER_DATA_M_AXI_RX" + }, + { + "role": "slave", + "target": "axis_interconnect_0_xbar:M03_AXIS", + "name": "USER_DATA_S_AXI_TX" + } + ] + }, + "axi_dma_0": { + "vlnv": "xilinx.com:ip:axi_dma:7.1", + "parameters": { + "c_s_axi_lite_addr_width": 10, + "c_s_axi_lite_data_width": 32, + "c_dlytmr_resolution": 125, + "c_prmry_is_aclk_async": 0, + "c_enable_multi_channel": 0, + "c_num_mm2s_channels": 1, + "c_num_s2mm_channels": 1, + "c_include_sg": 1, + "c_sg_include_stscntrl_strm": 0, + "c_sg_use_stsapp_length": 0, + "c_sg_length_width": 14, + "c_m_axi_sg_addr_width": 32, + "c_m_axi_sg_data_width": 32, + "c_m_axis_mm2s_cntrl_tdata_width": 32, + "c_s_axis_s2mm_sts_tdata_width": 32, + "c_micro_dma": 0, + "c_include_mm2s": 1, + "c_include_mm2s_sf": 1, + "c_mm2s_burst_size": 16, + "c_m_axi_mm2s_addr_width": 32, + "c_m_axi_mm2s_data_width": 32, + "c_m_axis_mm2s_tdata_width": 32, + "c_include_mm2s_dre": 0, + "c_include_s2mm": 1, + "c_include_s2mm_sf": 1, + "c_s2mm_burst_size": 16, + "c_m_axi_s2mm_addr_width": 32, + "c_m_axi_s2mm_data_width": 32, + "c_s_axis_s2mm_tdata_width": 32, + "c_include_s2mm_dre": 0, + "c_increase_throughput": 0, + "c_family": "virtex7", + "component_name": "design_1_axi_dma_0_0", + "c_addr_width": 32, + "c_single_interface": 0, + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 12288, + "c_highaddr": 13311 + }, + "memory-view": { + "M_AXI_SG": { + "axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_MM2S": { + "axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + }, + "M_AXI_S2MM": { + "axi_pcie_0": { + "BAR0": { + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + } + } + }, + "ports": [ + { + "role": "master", + "target": "axis_interconnect_0_xbar:S04_AXIS", + "name": "MM2S" + }, + { + "role": "slave", + "target": "axis_interconnect_0_xbar:M04_AXIS", + "name": "S2MM" + } + ], + "irqs": { + "mm2s_introut": "axi_pcie_intc_0:0", + "s2mm_introut": "axi_pcie_intc_0:1" + } + }, + "axi_gpio_0": { + "vlnv": "xilinx.com:ip:axi_gpio:2.0", + "parameters": { + "c_family": "virtex7", + "c_s_axi_addr_width": 9, + "c_s_axi_data_width": 32, + "c_gpio_width": 8, + "c_gpio2_width": 32, + "c_all_inputs": 0, + "c_all_inputs_2": 0, + "c_all_outputs": 1, + "c_all_outputs_2": 0, + "c_interrupt_present": 0, + "c_dout_default": 0, + "c_tri_default": 4294967295, + "c_is_dual": 0, + "c_dout_default_2": 0, + "c_tri_default_2": 4294967295, + "component_name": "design_1_axi_gpio_0_0", + "use_board_flow": "false", + "gpio_board_interface": "led_8bits", + "gpio2_board_interface": "Custom", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 127 + } + }, + "axi_pcie_0": { + "vlnv": "xilinx.com:ip:axi_pcie:2.9", + "parameters": { + "c_family": "virtex7", + "c_instance": "design_1_axi_pcie_0_1", + "c_s_axi_id_width": 2, + "c_s_axi_addr_width": 32, + "c_s_axi_data_width": 64, + "c_m_axi_addr_width": 32, + "c_m_axi_data_width": 64, + "c_no_of_lanes": 1, + "c_max_link_speed": 1, + "c_pcie_use_mode": "3.0", + "c_device_id": 28705, + "c_vendor_id": 4334, + "c_class_code": 360448, + "c_ref_clk_freq": 0, + "c_rev_id": 0, + "c_subsystem_id": 7, + "c_subsystem_vendor_id": 4334, + "c_pcie_cap_slot_implemented": 0, + "c_slot_clock_config": "TRUE", + "c_msi_decode_enable": "TRUE", + "c_int_fifo_depth": 0, + "c_num_msi_req": 5, + "c_interrupt_pin": 0, + "c_comp_timeout": 0, + "c_include_rc": 0, + "c_s_axi_supports_narrow_burst": 0, + "c_include_baroffset_reg": 1, + "c_axibar_num": 1, + "c_axibar2pciebar_0": 0, + "c_axibar2pciebar_1": 0, + "c_axibar2pciebar_2": 0, + "c_axibar2pciebar_3": 0, + "c_axibar2pciebar_4": 0, + "c_axibar2pciebar_5": 0, + "c_axibar_as_0": 0, + "c_axibar_as_1": 0, + "c_axibar_as_2": 0, + "c_axibar_as_3": 0, + "c_axibar_as_4": 0, + "c_axibar_as_5": 0, + "c_axibar_0": 0, + "c_axibar_highaddr_0": 4294967295, + "c_axibar_1": 4294967295, + "c_axibar_highaddr_1": 0, + "c_axibar_2": 4294967295, + "c_axibar_highaddr_2": 0, + "c_axibar_3": 4294967295, + "c_axibar_highaddr_3": 0, + "c_axibar_4": 4294967295, + "c_axibar_highaddr_4": 0, + "c_axibar_5": 4294967295, + "c_axibar_highaddr_5": 0, + "c_pciebar_num": 1, + "c_pciebar_as": 0, + "c_pciebar_len_0": 20, + "c_pciebar2axibar_0": 0, + "c_pciebar2axibar_0_sec": 1, + "c_pciebar_len_1": 16, + "c_pciebar2axibar_1": 4294967295, + "c_pciebar2axibar_1_sec": 1, + "c_pciebar_len_2": 16, + "c_pciebar2axibar_2": 4294967295, + "c_pciebar2axibar_2_sec": 1, + "c_pcie_blk_locn": 3, + "c_xlnx_ref_board": "VC707", + "pcie_ext_clk": "FALSE", + "pcie_ext_gt_common": "FALSE", + "ext_ch_gt_drp": "FALSE", + "shared_logic_in_core": "false", + "transceiver_ctrl_status_ports": "FALSE", + "ext_pipe_interface": "FALSE", + "c_device": "xc7vx485t", + "c_speed": -2, + "axi_aclk_loopback": "false", + "no_slv_err": "false", + "c_rp_bar_hide": "FALSE", + "enable_jtag_dbg": "false", + "c_axibar_chk_slv_err": "false", + "reduce_oob_freq": "false", + "component_name": "design_1_axi_pcie_0_1", + "include_rc": "PCI_Express_Endpoint_device", + "ref_clk_freq": "100_MHz", + "slot_clock_config": "true", + "pcie_use_mode": "GES_and_Production", + "no_of_lanes": "X1", + "max_link_speed": "5.0_GT/s", + "vendor_id": 4334, + "device_id": 28705, + "rev_id": 0, + "subsystem_vendor_id": 4334, + "subsystem_id": 7, + "enable_class_code": "true", + "class_code": 360448, + "base_class_menu": "Memory_controller", + "sub_class_interface_menu": "Other_memory_controller", + "bar0_enabled": "true", + "bar1_enabled": "false", + "bar2_enabled": "false", + "bar0_type": "Memory", + "bar1_type": "N/A", + "bar2_type": "N/A", + "bar0_scale": "Megabytes", + "bar1_scale": "N/A", + "bar2_scale": "N/A", + "bar0_size": 1, + "bar1_size": 8, + "bar2_size": 8, + "pciebar2axibar_0": 0, + "pciebar2axibar_1": 4294967295, + "pciebar2axibar_2": 4294967295, + "pciebar2axibar_1_sec": 1, + "pciebar2axibar_0_sec": 1, + "pciebar2axibar_2_sec": 1, + "interrupt_pin": "false", + "msi_decode_enabled": "true", + "num_msi_req": 5, + "int_fifo_depth": 16, + "comp_timeout": "50us", + "include_baroffset_reg": "true", + "axibar_as_0": "false", + "axibar_as_1": "false", + "axibar_as_2": "false", + "axibar_as_3": "false", + "axibar_as_4": "false", + "axibar_as_5": "false", + "axibar_1": 4294967295, + "axibar_2": 4294967295, + "axibar_3": 4294967295, + "axibar_4": 4294967295, + "axibar_5": 4294967295, + "axibar_highaddr_1": 0, + "axibar_highaddr_2": 0, + "axibar_highaddr_3": 0, + "axibar_highaddr_4": 0, + "axibar_highaddr_5": 0, + "axibar2pciebar_0": 0, + "axibar2pciebar_1": 0, + "axibar2pciebar_2": 0, + "axibar2pciebar_3": 0, + "axibar2pciebar_4": 0, + "axibar2pciebar_5": 0, + "baseaddr": 4096, + "highaddr": 8191, + "s_axi_id_width": 2, + "s_axi_addr_width": 32, + "s_axi_data_width": 64, + "m_axi_addr_width": 32, + "m_axi_data_width": 64, + "s_axi_supports_narrow_burst": "false", + "bar_64bit": "false", + "xlnx_ref_board": "VC707", + "pcie_blk_locn": "X1Y0", + "axibar_num": 1, + "en_ext_clk": "false", + "en_ext_gt_common": "false", + "en_ext_ch_gt_drp": "false", + "en_transceiver_status_ports": "false", + "en_ext_pipe_interface": "false", + "rp_bar_hide": "false", + "edk_iptype": "PERIPHERAL", + "axibar_0": 0, + "axibar_highaddr_0": 4294967295 + }, + "memory-view": { + "M_AXI": { + "axi_gpio_0": { + "Reg": { + "baseaddr": 0, + "highaddr": 127, + "size": 128 + } + }, + "axis_interconnect_0_xbar": { + "Reg": { + "baseaddr": 4096, + "highaddr": 5119, + "size": 1024 + } + }, + "axi_pcie_intc_0": { + "reg0": { + "baseaddr": 8192, + "highaddr": 9215, + "size": 1024 + } + }, + "axi_dma_0": { + "Reg": { + "baseaddr": 12288, + "highaddr": 13311, + "size": 1024 + } + } + } + }, + "axi_bars": { + "BAR0": { + "translation": 0, + "baseaddr": 0, + "highaddr": 4294967295, + "size": 4294967296 + } + }, + "pcie_bars": { + "BAR0": { + "translation": 0 + } + } + }, + "axi_pcie_intc_0": { + "vlnv": "xilinx.com:module_ref:axi_pcie_intc:1.0", + "parameters": { + "component_name": "design_1_axi_pcie_intc_0_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 8192, + "c_highaddr": 9215 + } + }, + "axis_interconnect_0_xbar": { + "vlnv": "xilinx.com:ip:axis_switch:1.1", + "parameters": { + "c_family": "virtex7", + "c_num_si_slots": 5, + "c_log_si_slots": 3, + "c_num_mi_slots": 5, + "c_axis_tdata_width": 32, + "c_axis_tid_width": 1, + "c_axis_tdest_width": 1, + "c_axis_tuser_width": 1, + "c_axis_signal_set": 27, + "c_arb_on_max_xfers": 1, + "c_arb_on_num_cycles": 0, + "c_arb_on_tlast": 0, + "c_include_arbiter": 1, + "c_arb_algorithm": 0, + "c_output_reg": 0, + "c_decoder_reg": 1, + "c_m_axis_connectivity_array": 33554431, + "c_m_axis_basetdest_array": 10, + "c_m_axis_hightdest_array": 10, + "c_routing_mode": 1, + "c_s_axi_ctrl_addr_width": 7, + "c_s_axi_ctrl_data_width": 32, + "c_common_clock": 0, + "num_si": 5, + "num_mi": 5, + "routing_mode": 1, + "has_tready": 1, + "tdata_num_bytes": 4, + "has_tstrb": 0, + "has_tkeep": 1, + "has_tlast": 1, + "tid_width": 0, + "tdest_width": 0, + "tuser_width": 0, + "has_aclken": 0, + "arb_on_max_xfers": 1, + "arb_on_num_cycles": 0, + "arb_on_tlast": 0, + "arb_algorithm": 0, + "decoder_reg": 1, + "output_reg": 0, + "common_clock": 0, + "m00_axis_basetdest": 0, + "m01_axis_basetdest": 1, + "m02_axis_basetdest": 2, + "m03_axis_basetdest": 3, + "m04_axis_basetdest": 4, + "m05_axis_basetdest": 5, + "m06_axis_basetdest": 6, + "m07_axis_basetdest": 7, + "m08_axis_basetdest": 8, + "m09_axis_basetdest": 9, + "m10_axis_basetdest": 10, + "m11_axis_basetdest": 11, + "m12_axis_basetdest": 12, + "m13_axis_basetdest": 13, + "m14_axis_basetdest": 14, + "m15_axis_basetdest": 15, + "m00_axis_hightdest": 0, + "m01_axis_hightdest": 1, + "m02_axis_hightdest": 2, + "m03_axis_hightdest": 3, + "m04_axis_hightdest": 4, + "m05_axis_hightdest": 5, + "m06_axis_hightdest": 6, + "m07_axis_hightdest": 7, + "m08_axis_hightdest": 8, + "m09_axis_hightdest": 9, + "m10_axis_hightdest": 10, + "m11_axis_hightdest": 11, + "m12_axis_hightdest": 12, + "m13_axis_hightdest": 13, + "m14_axis_hightdest": 14, + "m15_axis_hightdest": 15, + "m00_s00_connectivity": 1, + "m00_s01_connectivity": 1, + "m00_s02_connectivity": 1, + "m00_s03_connectivity": 1, + "m00_s04_connectivity": 1, + "m00_s05_connectivity": 1, + "m00_s06_connectivity": 1, + "m00_s07_connectivity": 1, + "m00_s08_connectivity": 1, + "m00_s09_connectivity": 1, + "m00_s10_connectivity": 1, + "m00_s11_connectivity": 1, + "m00_s12_connectivity": 1, + "m00_s13_connectivity": 1, + "m00_s14_connectivity": 1, + "m00_s15_connectivity": 1, + "m01_s00_connectivity": 1, + "m01_s01_connectivity": 1, + "m01_s02_connectivity": 1, + "m01_s03_connectivity": 1, + "m01_s04_connectivity": 1, + "m01_s05_connectivity": 1, + "m01_s06_connectivity": 1, + "m01_s07_connectivity": 1, + "m01_s08_connectivity": 1, + "m01_s09_connectivity": 1, + "m01_s10_connectivity": 1, + "m01_s11_connectivity": 1, + "m01_s12_connectivity": 1, + "m01_s13_connectivity": 1, + "m01_s14_connectivity": 1, + "m01_s15_connectivity": 1, + "m02_s00_connectivity": 1, + "m02_s01_connectivity": 1, + "m02_s02_connectivity": 1, + "m02_s03_connectivity": 1, + "m02_s04_connectivity": 1, + "m02_s05_connectivity": 1, + "m02_s06_connectivity": 1, + "m02_s07_connectivity": 1, + "m02_s08_connectivity": 1, + "m02_s09_connectivity": 1, + "m02_s10_connectivity": 1, + "m02_s11_connectivity": 1, + "m02_s12_connectivity": 1, + "m02_s13_connectivity": 1, + "m02_s14_connectivity": 1, + "m02_s15_connectivity": 1, + "m03_s00_connectivity": 1, + "m03_s01_connectivity": 1, + "m03_s02_connectivity": 1, + "m03_s03_connectivity": 1, + "m03_s04_connectivity": 1, + "m03_s05_connectivity": 1, + "m03_s06_connectivity": 1, + "m03_s07_connectivity": 1, + "m03_s08_connectivity": 1, + "m03_s09_connectivity": 1, + "m03_s10_connectivity": 1, + "m03_s11_connectivity": 1, + "m03_s12_connectivity": 1, + "m03_s13_connectivity": 1, + "m03_s14_connectivity": 1, + "m03_s15_connectivity": 1, + "m04_s00_connectivity": 1, + "m04_s01_connectivity": 1, + "m04_s02_connectivity": 1, + "m04_s03_connectivity": 1, + "m04_s04_connectivity": 1, + "m04_s05_connectivity": 1, + "m04_s06_connectivity": 1, + "m04_s07_connectivity": 1, + "m04_s08_connectivity": 1, + "m04_s09_connectivity": 1, + "m04_s10_connectivity": 1, + "m04_s11_connectivity": 1, + "m04_s12_connectivity": 1, + "m04_s13_connectivity": 1, + "m04_s14_connectivity": 1, + "m04_s15_connectivity": 1, + "m05_s00_connectivity": 1, + "m05_s01_connectivity": 1, + "m05_s02_connectivity": 1, + "m05_s03_connectivity": 1, + "m05_s04_connectivity": 1, + "m05_s05_connectivity": 1, + "m05_s06_connectivity": 1, + "m05_s07_connectivity": 1, + "m05_s08_connectivity": 1, + "m05_s09_connectivity": 1, + "m05_s10_connectivity": 1, + "m05_s11_connectivity": 1, + "m05_s12_connectivity": 1, + "m05_s13_connectivity": 1, + "m05_s14_connectivity": 1, + "m05_s15_connectivity": 1, + "m06_s00_connectivity": 1, + "m06_s01_connectivity": 1, + "m06_s02_connectivity": 1, + "m06_s03_connectivity": 1, + "m06_s04_connectivity": 1, + "m06_s05_connectivity": 1, + "m06_s06_connectivity": 1, + "m06_s07_connectivity": 1, + "m06_s08_connectivity": 1, + "m06_s09_connectivity": 1, + "m06_s10_connectivity": 1, + "m06_s11_connectivity": 1, + "m06_s12_connectivity": 1, + "m06_s13_connectivity": 1, + "m06_s14_connectivity": 1, + "m06_s15_connectivity": 1, + "m07_s00_connectivity": 1, + "m07_s01_connectivity": 1, + "m07_s02_connectivity": 1, + "m07_s03_connectivity": 1, + "m07_s04_connectivity": 1, + "m07_s05_connectivity": 1, + "m07_s06_connectivity": 1, + "m07_s07_connectivity": 1, + "m07_s08_connectivity": 1, + "m07_s09_connectivity": 1, + "m07_s10_connectivity": 1, + "m07_s11_connectivity": 1, + "m07_s12_connectivity": 1, + "m07_s13_connectivity": 1, + "m07_s14_connectivity": 1, + "m07_s15_connectivity": 1, + "m08_s00_connectivity": 1, + "m08_s01_connectivity": 1, + "m08_s02_connectivity": 1, + "m08_s03_connectivity": 1, + "m08_s04_connectivity": 1, + "m08_s05_connectivity": 1, + "m08_s06_connectivity": 1, + "m08_s07_connectivity": 1, + "m08_s08_connectivity": 1, + "m08_s09_connectivity": 1, + "m08_s10_connectivity": 1, + "m08_s11_connectivity": 1, + "m08_s12_connectivity": 1, + "m08_s13_connectivity": 1, + "m08_s14_connectivity": 1, + "m08_s15_connectivity": 1, + "m09_s00_connectivity": 1, + "m09_s01_connectivity": 1, + "m09_s02_connectivity": 1, + "m09_s03_connectivity": 1, + "m09_s04_connectivity": 1, + "m09_s05_connectivity": 1, + "m09_s06_connectivity": 1, + "m09_s07_connectivity": 1, + "m09_s08_connectivity": 1, + "m09_s09_connectivity": 1, + "m09_s10_connectivity": 1, + "m09_s11_connectivity": 1, + "m09_s12_connectivity": 1, + "m09_s13_connectivity": 1, + "m09_s14_connectivity": 1, + "m09_s15_connectivity": 1, + "m10_s00_connectivity": 1, + "m10_s01_connectivity": 1, + "m10_s02_connectivity": 1, + "m10_s03_connectivity": 1, + "m10_s04_connectivity": 1, + "m10_s05_connectivity": 1, + "m10_s06_connectivity": 1, + "m10_s07_connectivity": 1, + "m10_s08_connectivity": 1, + "m10_s09_connectivity": 1, + "m10_s10_connectivity": 1, + "m10_s11_connectivity": 1, + "m10_s12_connectivity": 1, + "m10_s13_connectivity": 1, + "m10_s14_connectivity": 1, + "m10_s15_connectivity": 1, + "m11_s00_connectivity": 1, + "m11_s01_connectivity": 1, + "m11_s02_connectivity": 1, + "m11_s03_connectivity": 1, + "m11_s04_connectivity": 1, + "m11_s05_connectivity": 1, + "m11_s06_connectivity": 1, + "m11_s07_connectivity": 1, + "m11_s08_connectivity": 1, + "m11_s09_connectivity": 1, + "m11_s10_connectivity": 1, + "m11_s11_connectivity": 1, + "m11_s12_connectivity": 1, + "m11_s13_connectivity": 1, + "m11_s14_connectivity": 1, + "m11_s15_connectivity": 1, + "m12_s00_connectivity": 1, + "m12_s01_connectivity": 1, + "m12_s02_connectivity": 1, + "m12_s03_connectivity": 1, + "m12_s04_connectivity": 1, + "m12_s05_connectivity": 1, + "m12_s06_connectivity": 1, + "m12_s07_connectivity": 1, + "m12_s08_connectivity": 1, + "m12_s09_connectivity": 1, + "m12_s10_connectivity": 1, + "m12_s11_connectivity": 1, + "m12_s12_connectivity": 1, + "m12_s13_connectivity": 1, + "m12_s14_connectivity": 1, + "m12_s15_connectivity": 1, + "m13_s00_connectivity": 1, + "m13_s01_connectivity": 1, + "m13_s02_connectivity": 1, + "m13_s03_connectivity": 1, + "m13_s04_connectivity": 1, + "m13_s05_connectivity": 1, + "m13_s06_connectivity": 1, + "m13_s07_connectivity": 1, + "m13_s08_connectivity": 1, + "m13_s09_connectivity": 1, + "m13_s10_connectivity": 1, + "m13_s11_connectivity": 1, + "m13_s12_connectivity": 1, + "m13_s13_connectivity": 1, + "m13_s14_connectivity": 1, + "m13_s15_connectivity": 1, + "m14_s00_connectivity": 1, + "m14_s01_connectivity": 1, + "m14_s02_connectivity": 1, + "m14_s03_connectivity": 1, + "m14_s04_connectivity": 1, + "m14_s05_connectivity": 1, + "m14_s06_connectivity": 1, + "m14_s07_connectivity": 1, + "m14_s08_connectivity": 1, + "m14_s09_connectivity": 1, + "m14_s10_connectivity": 1, + "m14_s11_connectivity": 1, + "m14_s12_connectivity": 1, + "m14_s13_connectivity": 1, + "m14_s14_connectivity": 1, + "m14_s15_connectivity": 1, + "m15_s00_connectivity": 1, + "m15_s01_connectivity": 1, + "m15_s02_connectivity": 1, + "m15_s03_connectivity": 1, + "m15_s04_connectivity": 1, + "m15_s05_connectivity": 1, + "m15_s06_connectivity": 1, + "m15_s07_connectivity": 1, + "m15_s08_connectivity": 1, + "m15_s09_connectivity": 1, + "m15_s10_connectivity": 1, + "m15_s11_connectivity": 1, + "m15_s12_connectivity": 1, + "m15_s13_connectivity": 1, + "m15_s14_connectivity": 1, + "m15_s15_connectivity": 1, + "component_name": "design_1_xbar_0", + "edk_iptype": "PERIPHERAL", + "c_baseaddr": 0, + "c_highaddr": 1023 + }, + "ports": [ + { + "role": "slave", + "target": "aurora_8b10b_ch0:USER_DATA_M_AXI_RX", + "name": "S00_AXIS" + }, + { + "role": "master", + "target": "aurora_8b10b_ch0:USER_DATA_S_AXI_TX", + "name": "M00_AXIS" + }, + { + "role": "slave", + "target": "aurora_8b10b_ch1:USER_DATA_M_AXI_RX", + "name": "S01_AXIS" + }, + { + "role": "master", + "target": "aurora_8b10b_ch1:USER_DATA_S_AXI_TX", + "name": "M01_AXIS" + }, + { + "role": "slave", + "target": "aurora_8b10b_ch2:USER_DATA_M_AXI_RX", + "name": "S02_AXIS" + }, + { + "role": "master", + "target": "aurora_8b10b_ch2:USER_DATA_S_AXI_TX", + "name": "M02_AXIS" + }, + { + "role": "slave", + "target": "aurora_8b10b_ch3:USER_DATA_M_AXI_RX", + "name": "S03_AXIS" + }, + { + "role": "master", + "target": "aurora_8b10b_ch3:USER_DATA_S_AXI_TX", + "name": "M03_AXIS" + }, + { + "role": "slave", + "target": "axi_dma_0:MM2S", + "name": "S04_AXIS" + }, + { + "role": "master", + "target": "axi_dma_0:S2MM", + "name": "M04_AXIS" + } + ] + } +} diff --git a/etc/fpga/vc707.json b/etc/fpga/vc707.json new file mode 100644 index 000000000..a4580d57c --- /dev/null +++ b/etc/fpga/vc707.json @@ -0,0 +1,12 @@ +{ + "fpgas": { + "vc707": { + "id": "10ee:7021", + "slot": "0000:88:00.0", + "do_reset": true, + "ips": "vc707-xbar-pcie-dino/vc707-xbar-pcie-dino-v2.json", + "polling": true, + "interface": "pcie" + } + } +} diff --git a/etc/gtnet-skt/emulate_gtnet.conf b/etc/gtnet-skt/emulate_gtnet.conf index 9e8b4921f..131534d7a 100644 --- a/etc/gtnet-skt/emulate_gtnet.conf +++ b/etc/gtnet-skt/emulate_gtnet.conf @@ -1,27 +1,23 @@ -#* GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +#* GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" - format = "gtnet" - - in = { - address = "*:12000" # Local ip:port, use '*' for random port - } - out = { - address = "134.130.169.80:12001" - } - } + node1 = { + type = "socket" + format = "gtnet" + + in = { + address = "*:12000" + } + out = { + address = "134.130.169.80:12001" + } + } } diff --git a/etc/gtnet-skt/test1.conf b/etc/gtnet-skt/test1.conf index 1b7a02a32..295f1b612 100644 --- a/etc/gtnet-skt/test1.conf +++ b/etc/gtnet-skt/test1.conf @@ -1,59 +1,55 @@ -# GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" - format = "villas.binary" + node1 = { + type = "socket" + format = "villas.binary" - in = { - address = "192.168.88.128:12002" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } + in = { + address = "192.168.88.128:12002" + } + out = { + address = "192.168.88.129:12001" + } - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - } - node2 = { - type = "socket" - - format = "villas.binary" + netem = { + enabled = false + delay = 1000000 + jitter = 300000 + distribution = "normal" + } + } + node2 = { + type = "socket" - in = { - address = "*:12004" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12005" - } - } + format = "villas.binary" + + in = { + address = "*:12004" + } + out = { + address = "192.168.88.129:12005" + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node1" # And we loop back to the origin + { + in = "node1" + out = "node1" - hooks = ( - { - type = "print" - } - ) - } + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/gtnet-skt/test2.conf b/etc/gtnet-skt/test2.conf index a2495dc8a..d1e2456bf 100644 --- a/etc/gtnet-skt/test2.conf +++ b/etc/gtnet-skt/test2.conf @@ -1,59 +1,55 @@ -# GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" - format = "villas.binary" + node1 = { + type = "socket" + format = "villas.binary" - in = { - address = "192.168.88.128:12002" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } + in = { + address = "192.168.88.128:12002" + } + out = { + address = "192.168.88.129:12001" + } - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - }, - node2 = { - type = "socket" - - format = "villas.binary" + netem = { + enabled = false + delay = 1000000 + jitter = 300000 + distribution = "normal" + } + }, + node2 = { + type = "socket" - in = { - address = "192.168.88.128:12004" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } - } + format = "villas.binary" + + in = { + address = "192.168.88.128:12004" + } + out = { + address = "192.168.88.129:12001" + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node2" # And we loop back to the origin + { + in = "node1" + out = "node2" - hooks = ( - { - type = "print" - } - ) - } + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/gtnet-skt/test3.conf b/etc/gtnet-skt/test3.conf index df37cbbdc..f233f9296 100644 --- a/etc/gtnet-skt/test3.conf +++ b/etc/gtnet-skt/test3.conf @@ -1,60 +1,56 @@ -# GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" + node1 = { + type = "socket" - format = "gtnet" + format = "gtnet" - in = { - address = "192.168.88.128:12002" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } + in = { + address = "192.168.88.128:12002" + } + out = { + address = "192.168.88.129:12001" + } - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - }, - node2 = { - type = "socket", - - format = "gtnet" + netem = { + enabled = false + delay = 1000000 + jitter = 300000 + distribution = "normal" + } + }, + node2 = { + type = "socket", - in = { - address = "192.168.88.128:12004" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } - } + format = "gtnet" + + in = { + address = "192.168.88.128:12004" + } + out = { + address = "192.168.88.129:12001" + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node2" # And we loop back to the origin + { + in = "node1" + out = "node2" - hooks = ( - { - type = "print" - } - ) - } + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/gtnet-skt/test4.conf b/etc/gtnet-skt/test4.conf index df2b9c711..27a225f51 100644 --- a/etc/gtnet-skt/test4.conf +++ b/etc/gtnet-skt/test4.conf @@ -1,60 +1,56 @@ -# GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" - - format = "gtnet" + node1 = { + type = "socket" - in = { - address = "134.130.169.31:12002" # Local ip:port, use '*' for random port - } - out = { - address = "134.130.169.98:12001" - } + format = "gtnet" - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - }, - node2 = { - type = "socket" - - format = "gtnet" + in = { + address = "134.130.169.31:12002" + } + out = { + address = "134.130.169.98:12001" + } - in = { - address = "192.168.88.128:12004" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } - } + netem = { + enabled = false + delay = 1000000 + jitter = 300000 + distribution = "normal" + } + }, + node2 = { + type = "socket" + + format = "gtnet" + + in = { + address = "192.168.88.128:12004" + } + out = { + address = "192.168.88.129:12001" + } + } } paths = ( - { - in = "node1", # Name of the node we listen to (see above) - out = "node1", # And we loop back to the origin + { + in = "node1", + out = "node1", - hooks = ( - { - type = "print" - } - ) - } + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/gtnet-skt/test5.conf b/etc/gtnet-skt/test5.conf index e2aae0ee1..f7f942bf5 100644 --- a/etc/gtnet-skt/test5.conf +++ b/etc/gtnet-skt/test5.conf @@ -1,63 +1,64 @@ -# GTNET-SKT test configuration. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# GTNET-SKT test configuration # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket" - - format = { - type = "gtnet" - fake = true - } + node1 = { + type = "socket" - in = { - address = "134.130.169.31:12002" # Local ip:port, use '*' for random port - } - out = { - address = "134.130.169.98:12001" - } + format = { + type = "gtnet" + fake = true + } - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - }, - node2 = { - type = "socket" + in = { + # Local ip:port, use '*' for random port + address = "134.130.169.31:12002" + } + out = { + address = "134.130.169.98:12001" + } - format = "gtnet" + netem = { + enabled = false + delay = 1000000 # In micro seconds! + jitter = 300000 + distribution = "normal" + } + }, + node2 = { + type = "socket" - in = { - address = "192.168.88.128:12004" # Local ip:port, use '*' for random port - } - out = { - address = "192.168.88.129:12001" - } - } + format = "gtnet" + + in = { + # Local ip:port, use '*' for random port + address = "192.168.88.128:12004" + } + out = { + address = "192.168.88.129:12001" + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node1" # And we loop back to the origin + { + # Name of the node we listen to (see above) + in = "node1" - hooks = ( - { - type = "print" - } - ) - } + # And we loop back to the origin + out = "node1" + + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/gtnet-skt/test6_gtsync_compare.conf b/etc/gtnet-skt/test6_gtsync_compare.conf index 7ef93e8d0..a0f789cd7 100644 --- a/etc/gtnet-skt/test6_gtsync_compare.conf +++ b/etc/gtnet-skt/test6_gtsync_compare.conf @@ -1,4 +1,4 @@ -# This is an example for a minimal loopback configuration. +# This is an example for a minimal loopback configuration # # All messages will be sent back to the origin using UDP packets. # @@ -26,64 +26,64 @@ # SPDX-License-Identifier: Apache-2.0 logging = { - level = "debug" + level = "debug" } nodes = { - node1 = { - type = "socket", - format = { - type = "gtnet" - fake = true - } - - in = { - address = "134.130.169.31:12002" # Local ip:port, use '*' for random port - } - out = { - address = "134.130.169.98:12001" - } - - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - }, - node2 = { - type = "socket", - format = { - type = "gtnet" - fake = true - } + node1 = { + type = "socket", + format = { + type = "gtnet" + fake = true + } - in = { - address = "134.130.169.31:12004", # Local ip:port, use '*' for random port - } - out = { - address = "134.130.169.99:12003", - } - } + in = { + address = "134.130.169.31:12002" + } + out = { + address = "134.130.169.98:12001" + } + + netem = { + enabled = false + delay = 1000000 + jitter = 300000 + distribution = "normal" + } + }, + node2 = { + type = "socket", + format = { + type = "gtnet" + fake = true + } + + in = { + address = "134.130.169.31:12004", + } + out = { + address = "134.130.169.99:12003", + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node1" # And we loop back to the origin - hooks = ( - { - type = "print" - } - ) - }, - { - in = "node2", - out = "node2", - hooks = ( - { - type = "print" - } - ) - } + { + in = "node1" + out = "node1" + hooks = ( + { + type = "print" + } + ) + }, + { + in = "node2", + out = "node2", + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/js/config.js b/etc/js/config.js index 637cfad22..1d38c5a56 100644 --- a/etc/js/config.js +++ b/etc/js/config.js @@ -24,43 +24,43 @@ var global = require(__dirname + '/global.js') global.plugins = glob.sync('/usr?(/local)/share/villas/node/plugins/*.so'); global.nodes = { - loopback_node : { - vectorize : 1, - type : "loopback", // A loopback node will receive exactly the same data which has been sent to it. - // The internal implementation is based on queue. - queuelen : 10240 // The queue length of the internal queue which buffers the samples. - }, - socket_node : { - type : "socket", + loopback_node : { + vectorize : 1, + type : "loopback", // A loopback node will receive exactly the same data which has been sent to it. + // The internal implementation is based on queue. + queuelen : 10240 // The queue length of the internal queue which buffers the samples. + }, + socket_node : { + type : "socket", - local : "*:12000", - remote : "127.0.0.1:12000" - } + local : "*:12000", + remote : "127.0.0.1:12000" + } }; global.paths = [ - { - in : "test_node", - out : "socket_node", - queuelen : 10000 - }, - { - in : "socket_node", - out : "test_node", - queuelen : 10000, - hooks : [ - { - type : "stats", - warmup : 100, - verbose : true, - format : "human", - output : "./stats.log" - }, - { - type : "convert" - } - ] - } + { + in : "test_node", + out : "socket_node", + queuelen : 10000 + }, + { + in : "socket_node", + out : "test_node", + queuelen : 10000, + hooks : [ + { + type : "stats", + warmup : 100, + verbose : true, + format : "human", + output : "./stats.log" + }, + { + type : "convert" + } + ] + } ]; // Convert Javascript Object to JSON string diff --git a/etc/js/global.js b/etc/js/global.js index 3ea55f673..39e7817b3 100644 --- a/etc/js/global.js +++ b/etc/js/global.js @@ -14,36 +14,36 @@ os = require('os'); var logfile = "/var/log/villas-node_" + new Date().toISOString() + ".log" module.exports = { - affinity : 0x01, // Mask of cores the server should run on - // This also maps the NIC interrupts to those cores! + affinity : 0x01, // Mask of cores the server should run on + // This also maps the NIC interrupts to those cores! - priority : 50, // Priority for the server tasks. - // Usually the server is using a real-time FIFO - // scheduling algorithm + priority : 50, // Priority for the server tasks. + // Usually the server is using a real-time FIFO + // scheduling algorithm - // See: https://github.com/docker/docker/issues/22380 - // on why we cant use real-time scheduling in Docker + // See: https://github.com/docker/docker/issues/22380 + // on why we cant use real-time scheduling in Docker - stats : 3, // The interval in seconds to print path statistics. - // A value of 0 disables the statistics. + stats : 3, // The interval in seconds to print path statistics. + // A value of 0 disables the statistics. - name : os.hostname(), // The name of this VILLASnode. Might by used by node-types - // to identify themselves (default is the hostname). + name : os.hostname(), // The name of this VILLASnode. Might by used by node-types + // to identify themselves (default is the hostname). - log : { - level : 5, // The level of verbosity for debug messages - // Higher number => increased verbosity + log : { + level : 5, // The level of verbosity for debug messages + // Higher number => increased verbosity - faciltities : [ "path", "socket" ], // The list of enabled debug faciltities. - // If omitted, all faciltities are enabled - // For a full list of available faciltities, check lib/log.c + faciltities : [ "path", "socket" ], // The list of enabled debug faciltities. + // If omitted, all faciltities are enabled + // For a full list of available faciltities, check lib/log.c - file : logfile, // File for logs - }, + file : logfile, // File for logs + }, - http : { - enabled : true, // Do not listen on port if true + http : { + enabled : true, // Do not listen on port if true - port : 80 // Port for HTTP connections - } + port : 80 // Port for HTTP connections + } }; diff --git a/etc/labs/lab10_nodes.conf b/etc/labs/lab10_nodes.conf index b3a747eee..86fbcb93f 100644 --- a/etc/labs/lab10_nodes.conf +++ b/etc/labs/lab10_nodes.conf @@ -4,77 +4,77 @@ hugepages = 200 nodes = { - # Node names can be any alphanumeric value - rpi-1 = { - type = "socket" - layer = "udp" - format = "gtnet" # pre-built format to communicate in RTDS GTNET-SKT payload + # Node names can be any alphanumeric value + rpi-1 = { + type = "socket" + layer = "udp" + format = "gtnet" # Pre-built format to communicate in RTDS GTNET-SKT payload - in = { - address = "*:12005" # villas node machine IP and port number + in = { + address = "*:12005" # VILLASnode machine IP and port number - signals = { - count = 8 - type = "float" - } + signals = { + count = 8 + type = "float" + } - hooks = ( - { - type = "stats" - warmup = 3000 - } - ) - }, - out = { - address = "192.168.0.5:12005" # remote machine IP and port number - } - }, - rpi-2 = { - type = "socket" - layer = "udp" - format = "gtnet" # pre-built format to communicate in RTDS GTNET-SKT payload + hooks = ( + { + type = "stats" + warmup = 3000 + } + ) + }, + out = { + address = "192.168.0.5:12005" # Remote machine IP and port number + } + }, + rpi-2 = { + type = "socket" + layer = "udp" + format = "gtnet" # Pre-built format to communicate in RTDS GTNET-SKT payload - in = { - address = "*:12006" # villas node machine IP and port number + in = { + address = "*:12006" # VILLASnode machine IP and port number - signals = { - count = 8 - type = "float" - } + signals = { + count = 8 + type = "float" + } - hooks = ( - { - type = "stats" - warmup = 3000 - } - ) - } - out = { - address = "192.168.0.6:12006" # remote machine IP and port number - } - }, - rtds-1 = { - type = "socket" - layer = "udp" - format = "gtnet" + hooks = ( + { + type = "stats" + warmup = 3000 + } + ) + } + out = { + address = "192.168.0.6:12006" # Remote machine IP and port number + } + }, + rtds-1 = { + type = "socket" + layer = "udp" + format = "gtnet" - in = { - address = "*:12083" # villas node machine IP and port number + in = { + address = "*:12083" # VILLASnode machine IP and port number - signals = { - count = 8 - type = "float" - } + signals = { + count = 8 + type = "float" + } - hooks = ( - { - type = "stats" - warmup = 3000 - } - ) - } - out = { - address = "192.168.0.4:12083" # remote machine IP and port number - } - } + hooks = ( + { + type = "stats" + warmup = 3000 + } + ) + } + out = { + address = "192.168.0.4:12083" # Remote machine IP and port number + } + } } diff --git a/etc/labs/lab10_path_bidir.conf b/etc/labs/lab10_path_bidir.conf index 6c629d02b..dfe94504c 100644 --- a/etc/labs/lab10_path_bidir.conf +++ b/etc/labs/lab10_path_bidir.conf @@ -4,22 +4,22 @@ @include "lab10_nodes.conf" paths = ( - # Each path dictionary corresponds to one way communication - { - in = [ "rpi-1" ], - out = [ "rtds-1" ] - }, - { - in = [ "rtds-1" ], - out = [ "rpi-1" ] - } + # Each path dictionary corresponds to one way communication + { + in = [ "rpi-1" ], + out = [ "rtds-1" ] + }, + { + in = [ "rtds-1" ], + out = [ "rpi-1" ] + } - # Alternatively, you can use a single path specification - # and set reverse = true - # Example: - # { - # in = [ "rpi-1" ], - # out = [ "rtds-1" ], - # reverse = true - # } + # Alternatively, you can use a single path specification + # and set reverse = true + # Example: + # { + # in = [ "rpi-1" ], + # out = [ "rtds-1" ], + # reverse = true + # } ) diff --git a/etc/labs/lab10_path_hook.conf b/etc/labs/lab10_path_hook.conf index d67a69f14..d75d4ced7 100644 --- a/etc/labs/lab10_path_hook.conf +++ b/etc/labs/lab10_path_hook.conf @@ -4,12 +4,12 @@ @include "lab10_nodes.conf" paths = ( - { - in = [ "rpi-1" ], - out = [ "rtds-1" ], + { + in = [ "rpi-1" ], + out = [ "rtds-1" ], - hooks = ( - { type = "print", output = "stdout" } - ) - } + hooks = ( + { type = "print", output = "stdout" } + ) + } ) diff --git a/etc/labs/lab10_path_multiple_destinations.conf b/etc/labs/lab10_path_multiple_destinations.conf index 56cf5267d..7ef2b6e93 100644 --- a/etc/labs/lab10_path_multiple_destinations.conf +++ b/etc/labs/lab10_path_multiple_destinations.conf @@ -4,8 +4,8 @@ @include "lab10_nodes.conf" paths = ( - { - in = [ "rtds-1" ], - out = [ "rpi-1", "rpi-2" ] - } + { + in = [ "rtds-1" ], + out = [ "rpi-1", "rpi-2" ] + } ) diff --git a/etc/labs/lab10_path_uni.conf b/etc/labs/lab10_path_uni.conf index e40b4c139..f2194875a 100644 --- a/etc/labs/lab10_path_uni.conf +++ b/etc/labs/lab10_path_uni.conf @@ -4,8 +4,8 @@ @include "lab10_nodes.conf" paths = ( - { - in = [ "rpi-1" ], - out = [ "rtds-1" ] - } + { + in = [ "rpi-1" ], + out = [ "rtds-1" ] + } ) diff --git a/etc/labs/lab11.conf b/etc/labs/lab11.conf index 3bf31a450..2c74eb15e 100644 --- a/etc/labs/lab11.conf +++ b/etc/labs/lab11.conf @@ -2,87 +2,87 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - rtds_gtnet1 = { - type = "socket" - layer = "udp" - format = "gtnet" + rtds_gtnet1 = { + type = "socket" + layer = "udp" + format = "gtnet" - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8 - type = "float" - } - } - out = { - address = "134.130.169.89:12000" - } - }, - rtds_gtnet2 = { - type = "socket" - layer = "udp" - format = "gtnet" + signals = { + count = 8 + type = "float" + } + } + out = { + address = "134.130.169.89:12000" + } + }, + rtds_gtnet2 = { + type = "socket" + layer = "udp" + format = "gtnet" - in = { - address = "*:12001" + in = { + address = "*:12001" - signals = { - count = 8 - type = "float" - } - } - out = { - address = "134.130.169.90:12001" - } - } - monitoring = { - type = "websocket" - } - monitoring_log = { - type = "file", + signals = { + count = 8 + type = "float" + } + } + out = { + address = "134.130.169.90:12001" + } + } + monitoring = { + type = "websocket" + } + monitoring_log = { + type = "file", - uri = "ftp://acs:fake@134.130.169.32/var/villas/log/monitoring_%Y-%m-%d_%H_%M_%S.dat" + uri = "ftp://acs:fake@134.130.169.32/var/villas/log/monitoring_%Y-%m-%d_%H_%M_%S.dat" - out = { + out = { - } - } + } + } } paths = ( - { - # Combine data from rtds_gtnet1 and rtds_gtnet2 - in = [ - "rtds_gtnet1.ts.origin", - "rtds_gtnet1.hdr.sequence", - "rtds_gtnet1.data[0-6]", + { + # Combine data from rtds_gtnet1 and rtds_gtnet2 + in = [ + "rtds_gtnet1.ts.origin", + "rtds_gtnet1.hdr.sequence", + "rtds_gtnet1.data[0-6]", - "rtds_gtnet2.ts.origin", - "rtds_gtnet2.hdr.sequence", - "rtds_gtnet2.data[0-6]" - ], + "rtds_gtnet2.ts.origin", + "rtds_gtnet2.hdr.sequence", + "rtds_gtnet2.data[0-6]" + ], - out = [ - "monitoring", - "monitoring_log" - ], + out = [ + "monitoring", + "monitoring_log" + ], - reverse = false, + reverse = false, - # The mode of a path determines when the path is triggered - # and forwarding samples to its destination nodes. - mode = "any", + # The mode of a path determines when the path is triggered + # and forwarding samples to its destination nodes + mode = "any", - # List of nodes which trigger the path - mask = [ "rtds_gtnet1", "rtds_gtnet2" ], + # List of nodes which trigger the path + mask = [ "rtds_gtnet1", "rtds_gtnet2" ], - hooks = ( - # We do not want to overload the WebBrowsers - { - type = "decimate", - ratio = 10 - } - ) - } + hooks = ( + # We do not want to overload the WebBrowsers + { + type = "decimate", + ratio = 10 + } + ) + } ) diff --git a/etc/labs/lab12.conf b/etc/labs/lab12.conf index c4cee9a55..c7d9a0b94 100644 --- a/etc/labs/lab12.conf +++ b/etc/labs/lab12.conf @@ -2,49 +2,49 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node1 = { - type = "socket", - layer = "udp", + udp_node1 = { + type = "socket", + layer = "udp", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "127.0.0.1:12001" - } - }, - web_node1 = { - type = "websocket", + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "127.0.0.1:12001" + } + }, + web_node1 = { + type = "websocket", - vectorize = 2, - series = ( - { label = "Random walk", unit = "V" }, - { label = "Sine", unit = "A" }, - { label = "Rect", unit = "Var" }, - { label = "Ramp", unit = "°C" } - ) - } + vectorize = 2, + series = ( + { label = "Random walk", unit = "V" }, + { label = "Sine", unit = "A" }, + { label = "Rect", unit = "Var" }, + { label = "Ramp", unit = "°C" } + ) + } } paths = ( - { - in = [ "udp_node1" ], - out = [ "web_node1" ], + { + in = [ "udp_node1" ], + out = [ "web_node1" ], - hooks = ( - # We do not want to overload the WebBrowsers - { type = "decimate", ratio = 2 } - ) - }, - { - in = [ "web_node1" ], - out = [ "udp_node1" ] + hooks = ( + # We do not want to overload the WebBrowsers + { type = "decimate", ratio = 2 } + ) + }, + { + in = [ "web_node1" ], + out = [ "udp_node1" ] - # Web -> UDP does not require decimation - } + # Web -> UDP does not require decimation + } ) diff --git a/etc/labs/lab13.conf b/etc/labs/lab13.conf index a1cd8876d..32d6054b3 100644 --- a/etc/labs/lab13.conf +++ b/etc/labs/lab13.conf @@ -4,47 +4,47 @@ affinity = 0x8, nodes = { - rtds_gtnet1 = { - type = "socket", - layer = "udp", - format = "gtnet", + rtds_gtnet1 = { + type = "socket", + layer = "udp", + format = "gtnet", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "134.130.169.98:12000" - } - }, - rtds_gtnet2 = { - type = "socket", - layer = "udp", - format = "gtnet", + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "134.130.169.98:12000" + } + }, + rtds_gtnet2 = { + type = "socket", + layer = "udp", + format = "gtnet", - in = { - address = "*:12001" + in = { + address = "*:12001" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "134.130.169.99:12001" - } - } + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "134.130.169.99:12001" + } + } } paths = ( - { - in = "rtds_gtnet1" - out = "rtds_gtnet2" + { + in = "rtds_gtnet1" + out = "rtds_gtnet2" - reverse = true - } + reverse = true + } ) diff --git a/etc/labs/lab17.conf b/etc/labs/lab17.conf index d6d5d7045..eaed0139a 100644 --- a/etc/labs/lab17.conf +++ b/etc/labs/lab17.conf @@ -2,148 +2,147 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - rtds_ss1 = { - type = "socket", - layer = "udp", - format = { - type = "gtnet" - fake = true - } + rtds_ss1 = { + type = "socket", + layer = "udp", + format = { + type = "gtnet" + fake = true + } - in = { # Local address, i.e. address of villas instance - address = "134.130.169.31:12000" + in = { # Local address, i.e. address of villas instance + address = "134.130.169.31:12000" - signals = ( - { name="trigger", type="integer" }, - { name="if1_tx_phA_dp0_mag", type="float" }, - { name="if1_tx_phA_dp0_phase", type="float" }, - { name="if1_tx_phA_dp1_mag", type="float" }, - { name="if1_tx_phA_dp1_phase", type="float" }, - { name="if1_tx_phA_dp2_mag", type="float" }, - { name="if1_tx_phA_dp2_phase", type="float" }, - { name="if1_tx_phA_dp3_mag", type="float" }, - { name="if1_tx_phA_dp3_phase", type="float" }, - { name="if1_tx_phB_dp0_mag", type="float" }, - { name="if1_tx_phB_dp0_phase", type="float" }, - { name="if1_tx_phB_dp1_mag", type="float" }, - { name="if1_tx_phB_dp1_phase", type="float" }, - { name="if1_tx_phB_dp2_mag", type="float" }, - { name="if1_tx_phB_dp2_phase", type="float" }, - { name="if1_tx_phB_dp3_mag", type="float" }, - { name="if1_tx_phB_dp3_phase", type="float" }, - { name="if1_tx_phC_dp0_mag", type="float" }, - { name="if1_tx_phC_dp0_phase", type="float" }, - { name="if1_tx_phC_dp1_mag", type="float" }, - { name="if1_tx_phC_dp1_phase", type="float" }, - { name="if1_tx_phC_dp2_mag", type="float" }, - { name="if1_tx_phC_dp2_phase", type="float" }, - { name="if1_tx_phC_dp3_mag", type="float" }, - { name="if1_tx_phC_dp3_phase", type="float" } - ) - } - - out = { # Remote address, i.e. address of GTNET card - address = "134.130.169.97:12000" # GTNET#4 -> Rack5(GPC4) - } - } - - rtds_ss2 = { - type = "socket", - layer = "udp", - format = { - type = "gtnet" - fake = true - } + signals = ( + { name="trigger", type="integer" }, + { name="if1_tx_phA_dp0_mag", type="float" }, + { name="if1_tx_phA_dp0_phase", type="float" }, + { name="if1_tx_phA_dp1_mag", type="float" }, + { name="if1_tx_phA_dp1_phase", type="float" }, + { name="if1_tx_phA_dp2_mag", type="float" }, + { name="if1_tx_phA_dp2_phase", type="float" }, + { name="if1_tx_phA_dp3_mag", type="float" }, + { name="if1_tx_phA_dp3_phase", type="float" }, + { name="if1_tx_phB_dp0_mag", type="float" }, + { name="if1_tx_phB_dp0_phase", type="float" }, + { name="if1_tx_phB_dp1_mag", type="float" }, + { name="if1_tx_phB_dp1_phase", type="float" }, + { name="if1_tx_phB_dp2_mag", type="float" }, + { name="if1_tx_phB_dp2_phase", type="float" }, + { name="if1_tx_phB_dp3_mag", type="float" }, + { name="if1_tx_phB_dp3_phase", type="float" }, + { name="if1_tx_phC_dp0_mag", type="float" }, + { name="if1_tx_phC_dp0_phase", type="float" }, + { name="if1_tx_phC_dp1_mag", type="float" }, + { name="if1_tx_phC_dp1_phase", type="float" }, + { name="if1_tx_phC_dp2_mag", type="float" }, + { name="if1_tx_phC_dp2_phase", type="float" }, + { name="if1_tx_phC_dp3_mag", type="float" }, + { name="if1_tx_phC_dp3_phase", type="float" } + ) + } - in = { - # Local address, i.e. address of villas instance - address = "134.130.169.31:12001" + out = { # Remote address, i.e. address of GTNET card + address = "134.130.169.97:12000" # GTNET#4 -> Rack5(GPC4) + } + } - signals = ( - { name="trigger", type="integer" }, - { name="if1_tx_phA_dp0_mag", type="float" }, - { name="if1_tx_phA_dp0_phase", type="float" }, - { name="if1_tx_phA_dp1_mag", type="float" }, - { name="if1_tx_phA_dp1_phase", type="float" }, - { name="if1_tx_phA_dp2_mag", type="float" }, - { name="if1_tx_phA_dp2_phase", type="float" }, - { name="if1_tx_phA_dp3_mag", type="float" }, - { name="if1_tx_phA_dp3_phase", type="float" }, - { name="if1_tx_phB_dp0_mag", type="float" }, - { name="if1_tx_phB_dp0_phase", type="float" }, - { name="if1_tx_phB_dp1_mag", type="float" }, - { name="if1_tx_phB_dp1_phase", type="float" }, - { name="if1_tx_phB_dp2_mag", type="float" }, - { name="if1_tx_phB_dp2_phase", type="float" }, - { name="if1_tx_phB_dp3_mag", type="float" }, - { name="if1_tx_phB_dp3_phase", type="float" }, - { name="if1_tx_phC_dp0_mag", type="float" }, - { name="if1_tx_phC_dp0_phase", type="float" }, - { name="if1_tx_phC_dp1_mag", type="float" }, - { name="if1_tx_phC_dp1_phase", type="float" }, - { name="if1_tx_phC_dp2_mag", type="float" }, - { name="if1_tx_phC_dp2_phase", type="float" }, - { name="if1_tx_phC_dp3_mag", type="float" }, - { name="if1_tx_phC_dp3_phase", type="float" } - ) + rtds_ss2 = { + type = "socket", + layer = "udp", + format = { + type = "gtnet" + fake = true + } - } + in = { + # Local address, i.e. address of villas instance + address = "134.130.169.31:12001" - out = { - # Remote address, i.e. address of GTNET card - address = "134.130.169.98:12000" # GTNET#5 -> Rack1(GPC4) - } - } + signals = ( + { name="trigger", type="integer" }, + { name="if1_tx_phA_dp0_mag", type="float" }, + { name="if1_tx_phA_dp0_phase", type="float" }, + { name="if1_tx_phA_dp1_mag", type="float" }, + { name="if1_tx_phA_dp1_phase", type="float" }, + { name="if1_tx_phA_dp2_mag", type="float" }, + { name="if1_tx_phA_dp2_phase", type="float" }, + { name="if1_tx_phA_dp3_mag", type="float" }, + { name="if1_tx_phA_dp3_phase", type="float" }, + { name="if1_tx_phB_dp0_mag", type="float" }, + { name="if1_tx_phB_dp0_phase", type="float" }, + { name="if1_tx_phB_dp1_mag", type="float" }, + { name="if1_tx_phB_dp1_phase", type="float" }, + { name="if1_tx_phB_dp2_mag", type="float" }, + { name="if1_tx_phB_dp2_phase", type="float" }, + { name="if1_tx_phB_dp3_mag", type="float" }, + { name="if1_tx_phB_dp3_phase", type="float" }, + { name="if1_tx_phC_dp0_mag", type="float" }, + { name="if1_tx_phC_dp0_phase", type="float" }, + { name="if1_tx_phC_dp1_mag", type="float" }, + { name="if1_tx_phC_dp1_phase", type="float" }, + { name="if1_tx_phC_dp2_mag", type="float" }, + { name="if1_tx_phC_dp2_phase", type="float" }, + { name="if1_tx_phC_dp3_mag", type="float" }, + { name="if1_tx_phC_dp3_phase", type="float" } + ) + } - rtds_ss1_monitoring = { - type = "socket" - layer = "udp" - format = { - type = "gtnet" - fake = true - } + out = { + # Remote address, i.e. address of GTNET card + address = "134.130.169.98:12000" # GTNET#5 -> Rack1(GPC4) + } + } - in = { # Local address, i.e. address of villas instance - address = "134.130.169.31:12002" - - signals = ( - { name="orgn_V3phRMSintrf", type="float", unit="V" }, - { name="orgn_Pintrf", type="float", unit="W" }, - { name="orgn_Qintrf", type="float", unit="Var" }, - { name="orgn_Sintrf", type="float", unit="VA" }, - { name="if1_V3phRMS", type="float", unit="V" }, - { name="if1_I3phRMS", type="float", unit="A" }, - { name="if1_P", type="float", unit="W" }, - { name="if1_Q", type="float", unit="Var" }, - { name="if1_S", type="float", unit="VA" } - ) - } - - out = { # Remote address, i.e. address of GTNET card - address = "134.130.169.97:12000" - } - } + rtds_ss1_monitoring = { + type = "socket" + layer = "udp" + format = { + type = "gtnet" + fake = true + } + + in = { # Local address, i.e. address of villas instance + address = "134.130.169.31:12002" + + signals = ( + { name="orgn_V3phRMSintrf", type="float", unit="V" }, + { name="orgn_Pintrf", type="float", unit="W" }, + { name="orgn_Qintrf", type="float", unit="Var" }, + { name="orgn_Sintrf", type="float", unit="VA" }, + { name="if1_V3phRMS", type="float", unit="V" }, + { name="if1_I3phRMS", type="float", unit="A" }, + { name="if1_P", type="float", unit="W" }, + { name="if1_Q", type="float", unit="Var" }, + { name="if1_S", type="float", unit="VA" } + ) + } + + out = { # Remote address, i.e. address of GTNET card + address = "134.130.169.97:12000" + } + } - web_monitoring = { - type = "websocket" + web_monitoring = { + type = "websocket" - destinations = [ - "https://villas.k8s.eonerc.rwth-aachen.de//ws/relay/lab17" - ] - } + destinations = [ + "https://villas.k8s.eonerc.rwth-aachen.de//ws/relay/lab17" + ] + } } paths = ( - { - in = "rtds_ss1", - out = "rtds_ss2", - reverse = true - }, - { - enabled = false, - in = "rtds_ss1_monitoring", - out = "web_monitoring", - reverse = true - } + { + in = "rtds_ss1", + out = "rtds_ss2", + reverse = true + }, + { + enabled = false, + in = "rtds_ss1_monitoring", + out = "web_monitoring", + reverse = true + } ) diff --git a/etc/labs/lab3.conf b/etc/labs/lab3.conf index 490ad8564..6a182a2f3 100644 --- a/etc/labs/lab3.conf +++ b/etc/labs/lab3.conf @@ -2,20 +2,20 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node1 = { - type = "socket", - layer = "udp", + udp_node1 = { + type = "socket", + layer = "udp", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 3 - type = "float" - } - }, - out = { - address = "127.0.0.1:12001" - } - } + signals = { + count = 3 + type = "float" + } + }, + out = { + address = "127.0.0.1:12001" + } + } } diff --git a/etc/labs/lab4.conf b/etc/labs/lab4.conf index 0dd83a32d..0b30ec7c9 100644 --- a/etc/labs/lab4.conf +++ b/etc/labs/lab4.conf @@ -2,20 +2,20 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node1 = { - type = "socket", - layer = "udp", + udp_node1 = { + type = "socket", + layer = "udp", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "127.0.0.1:12001" - } - } + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "127.0.0.1:12001" + } + } } diff --git a/etc/labs/lab5.conf b/etc/labs/lab5.conf index 3085dbe74..7706c7675 100644 --- a/etc/labs/lab5.conf +++ b/etc/labs/lab5.conf @@ -2,21 +2,21 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - rtds_gtnet1 = { - type = "socket", - layer = "udp", - format = "gtnet", + rtds_gtnet1 = { + type = "socket", + layer = "udp", + format = "gtnet", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "134.130.169.89:12000" - } - } + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "134.130.169.89:12000" + } + } } diff --git a/etc/labs/lab7.conf b/etc/labs/lab7.conf index 5217a31bb..1950214b6 100644 --- a/etc/labs/lab7.conf +++ b/etc/labs/lab7.conf @@ -2,13 +2,13 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - file_node1 = { - type = "file", + file_node1 = { + type = "file", - uri = "file_send.dat" - - in = { - - } - } + uri = "file_send.dat" + + in = { + + } + } } diff --git a/etc/labs/lab8.conf b/etc/labs/lab8.conf index a4f12ab4e..f8660fd8c 100644 --- a/etc/labs/lab8.conf +++ b/etc/labs/lab8.conf @@ -2,47 +2,47 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node1 = { - type = "socket" - layer = "udp" + udp_node1 = { + type = "socket" + layer = "udp" - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = ( - { name = "sig1", type = "float" }, - { name = "sig2", type = "float" }, - { name = "sig3", type = "float" }, - { name = "sig4", type = "float" } - ) - } - out = { - address = "127.0.0.1:12001" - } - } + signals = ( + { name = "sig1", type = "float" }, + { name = "sig2", type = "float" }, + { name = "sig3", type = "float" }, + { name = "sig4", type = "float" } + ) + } + out = { + address = "127.0.0.1:12001" + } + } } paths = ( - { - in = [ "udp_node1" ] - out = [ "udp_node1" ] + { + in = [ "udp_node1" ] + out = [ "udp_node1" ] - hooks = ( - { - type = "decimate" - priority = 1 + hooks = ( + { + type = "decimate" + priority = 1 - # Hook specific parameters follow - # [parameter1] = [value1] - ratio = 2 - }, - { - type = "scale" + # Hook specific parameters follow + # [parameter1] = [value1] + ratio = 2 + }, + { + type = "scale" - signal = "sig3" - offset = 10.0 - scale = 2.5 - } - ) - } + signal = "sig3" + offset = 10.0 + scale = 2.5 + } + ) + } ) diff --git a/etc/labs/lab9_netem.conf b/etc/labs/lab9_netem.conf index 849a467bb..8810ffe69 100644 --- a/etc/labs/lab9_netem.conf +++ b/etc/labs/lab9_netem.conf @@ -2,30 +2,30 @@ # SPDX-License-Identifier: Apache-2.0 nodes = { - udp_node1 = { - type = "socket", - layer = "udp", + udp_node1 = { + type = "socket", + layer = "udp", - in = { - address = "*:12000" + in = { + address = "*:12000" - signals = { - count = 8, - type = "float" - } - }, - out = { - address = "127.0.0.1:12001", + signals = { + count = 8, + type = "float" + } + }, + out = { + address = "127.0.0.1:12001", - netem = { - enabled = true, - loss = 0, # in % - corrupt = 0, # in % - duplicate = 0, # in % - delay = 100000, # in uS - jitter = 5000, # in uS - distribution = "normal" - } - } - } + netem = { + enabled = true, + loss = 0, # In % + corrupt = 0, # In % + duplicate = 0, # In % + delay = 100000, # In uS + jitter = 5000, # In uS + distribution = "normal" + } + } + } } diff --git a/etc/loopback.conf b/etc/loopback.conf index 75a470151..10eb4aa73 100644 --- a/etc/loopback.conf +++ b/etc/loopback.conf @@ -1,4 +1,4 @@ -# This is an example for a minimal loopback configuration. +# This is an example for a minimal loopback configuration # # All messages will be sent back to the origin using UDP packets. # @@ -21,74 +21,77 @@ # # $ villas pipe etc/loopback.conf node2 # -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files -# # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 nodes = { - node1 = { - type = "socket" - layer = "udp" + node1 = { + type = "socket" + layer = "udp" - in = { - address = "127.0.0.1:12000" # Local ip:port, use '*' for random port - } - out = { - address = "127.0.0.1:12001" + in = { + # Local ip:port, use '*' for random port + address = "127.0.0.1:12000" + } + out = { + address = "127.0.0.1:12001" - netem = { - enabled = false - delay = 1000000 # In micro seconds! - jitter = 300000 - distribution = "normal" - } - } - }, - node2 = { - type = "socket" - layer = "udp" - in = { - address = "127.0.0.1:12001" # Local ip:port, use '*' for random port - } - out = { - address = "127.0.0.1:12002" - } - }, - node3 = { - type = "socket" - layer = "udp" - in = { - address = "127.0.0.1:12002" # Local ip:port, use '*' for random port - } - out = { - address = "127.0.0.1:12000" - } - }, - loopback = { - type = "socket" - layer = "udp" - in = { - address = "127.0.0.1:12003" # Local ip:port, use '*' for random port - } - out = { - address = "127.0.0.1:12003" - } - } + netem = { + enabled = false + delay = 1000000 # In micro seconds! + jitter = 300000 + distribution = "normal" + } + } + }, + node2 = { + type = "socket" + layer = "udp" + in = { + # Local ip:port, use '*' for random port + address = "127.0.0.1:12001" + } + out = { + address = "127.0.0.1:12002" + } + }, + node3 = { + type = "socket" + layer = "udp" + in = { + # Local ip:port, use '*' for random port + address = "127.0.0.1:12002" + } + out = { + address = "127.0.0.1:12000" + } + }, + loopback = { + type = "socket" + layer = "udp" + in = { + # Local ip:port, use '*' for random port + address = "127.0.0.1:12003" + } + out = { + address = "127.0.0.1:12003" + } + } } paths = ( - { - in = "node1" # Name of the node we listen to (see above) - out = "node2" # And we loop back to the origin - - hooks = ( - { - type = "print" - } - ) - } + { + # Name of the node we listen to (see above) + in = "node1" + + # And we loop back to the origin + out = "node2" + + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/loopback.json b/etc/loopback.json index 54929849a..1dde43c6f 100644 --- a/etc/loopback.json +++ b/etc/loopback.json @@ -1,12 +1,12 @@ { - "idle_stop" : false, + "idle_stop" : false, - "http" : { - "port" : 8080 - }, - "nodes" : { - "node1" : { - "type" : "loopback" - } - } + "http" : { + "port" : 8080 + }, + "nodes" : { + "node1" : { + "type" : "loopback" + } + } } diff --git a/etc/python/example.py b/etc/python/example.py index 0132ad884..6be8b623e 100644 --- a/etc/python/example.py +++ b/etc/python/example.py @@ -1,5 +1,5 @@ #!/bin/env python3 -''' Example Python config +""" Example Python config This example demonstrates how you can use Python to generate complex configuration files. @@ -11,7 +11,7 @@ Author: Steffen Vogel SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University SPDX-License-Identifier: Apache-2.0 -''' +""" import json import sys @@ -19,59 +19,38 @@ import sys N = 10 nodes = { - 'raspberry': { - 'type': 'socket', - 'layer': 'udp', - 'format': 'protobuf', - - 'in': { - 'address': '*:12000', + "raspberry": { + "type": "socket", + "layer": "udp", + "format": "protobuf", + "in": { + "address": "*:12000", }, - 'out': { - 'address': '1.2.3.4:12000' - } + "out": {"address": "1.2.3.4:12000"}, } } for i in range(N): - name = f'agent{i}' + name = f"agent{i}" port = 12000 + i nodes[name] = { - 'type': 'socket', - 'layer': 'udp', - 'format': 'protobuf', - - 'in': { - 'address': '*:12000', - 'signals': [ - { - 'name': 'in', - 'type': 'float' - } - ] - }, - 'out': { - 'address': f'5.6.7.8:{port}' - } + "type": "socket", + "layer": "udp", + "format": "protobuf", + "in": {"address": "*:12000", "signals": [{"name": "in", "type": "float"}]}, + "out": {"address": f"5.6.7.8:{port}"}, } paths = [ { - 'in': [f'agent{i}' for i in range(N)], - 'out': 'raspberry', - 'mode': 'any', - 'hooks': [ - { - 'type': 'print' - } - ] + "in": [f"agent{i}" for i in range(N)], + "out": "raspberry", + "mode": "any", + "hooks": [{"type": "print"}], }, ] -config = { - 'nodes': nodes, - 'paths': paths -} +config = {"nodes": nodes, "paths": paths} json.dump(config, sys.stdout, indent=2) diff --git a/etc/shmem_mqtt.conf b/etc/shmem_mqtt.conf index f73c928cb..d25682b6b 100644 --- a/etc/shmem_mqtt.conf +++ b/etc/shmem_mqtt.conf @@ -1,79 +1,82 @@ # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 - + nodes = { - sig = { - type = "signal" + sig = { + type = "signal" - signal = "sine" - } + signal = "sine" + } - dpsim = { - enabled = false, - type = "shmem", - in = { - name = "/dpsim-villas", # Name of shared memory segment for sending side - hooks = ( - { type = "stats" } - ), - signals = { - # count = 2, - # type = "float" - count = 1, - type = "complex" - } - }, - out = { - name = "/villas-dpsim" # Name of shared memory segment for receiving side - signals = { - count = 1, - type = "complex" - } + dpsim = { + enabled = false, + type = "shmem", + in = { + # Name of shared memory segment for sending side + name = "/dpsim-villas", + hooks = ( + { type = "stats" } + ), + signals = { + # count = 2, + # type = "float" + count = 1, + type = "complex" + } + }, + out = { + # Name of shared memory segment for receiving side + name = "/villas-dpsim" + signals = { + count = 1, + type = "complex" + } - }, - queuelen = 1024, # Length of the queues - polling = true, # We can busy-wait or use pthread condition variables for synchronizations - }, + }, + # Length of the queues + queuelen = 1024, - broker = { - type = "mqtt", - format = "json", - #host = "localhost", - host = "137.226.133.157" - port = 1883, - retain = false, + # We can busy-wait or use pthread condition variables for synchronizations + polling = true, + }, - out = { - publish = "dpsim->dist" - } + broker = { + type = "mqtt", + format = "json", + #host = "localhost", + host = "137.226.133.157" + port = 1883, + retain = false, - in = { - subscribe = "dist->dpsim", + out = { + publish = "dpsim->dist" + } - signals = { - count = 1, - type = "complex" - } - } - } + in = { + subscribe = "dist->dpsim", + + signals = { + count = 1, + type = "complex" + } + } + } } paths = ( - { - enabled = false - in = "sig", - out = "broker", - - # mode: any/all - # Condition of which/how many source nodes have to receive - # at least one sample for the path to be triggered - mode = "any", -# reverse = true - } - # ,{ - # in = "nano"; - # out = "dpsim"; - # mode = "any" - # } + { + enabled = false + in = "sig", + out = "broker", + # Condition of which/how many source nodes have to receive + # at least one sample for the path to be triggered + mode = "any", + # reverse = true + } + # ,{ + # in = "nano"; + # out = "dpsim"; + # mode = "any" + # } ) diff --git a/etc/syslab-zmq.conf b/etc/syslab-zmq.conf index fa22731c6..f39c1aba5 100644 --- a/etc/syslab-zmq.conf +++ b/etc/syslab-zmq.conf @@ -1,29 +1,29 @@ # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 - + nodes = { - b2b = { - type = "zeromq" - format = "protobuf" + b2b = { + type = "zeromq" + format = "protobuf" - in = { - subscribe = "tcp://*:12000" - bind = true - filter = "syslab" + in = { + subscribe = "tcp://*:12000" + bind = true + filter = "syslab" - hooks = ( - { - type = "stats" + hooks = ( + { + type = "stats" - warmup = 10 - verbose = true - } - ) - } - out = { - publish = "tcp://*:12001" - bind = true - filter = "syslab" - } - } + warmup = 10 + verbose = true + } + ) + } + out = { + publish = "tcp://*:12001" + bind = true + filter = "syslab" + } + } } diff --git a/etc/test.conf b/etc/test.conf index 3adca8344..2be21ba46 100644 --- a/etc/test.conf +++ b/etc/test.conf @@ -1,22 +1,22 @@ # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 - -nodes = { - signal = { - type = "signal" - signal = "mixed" - values = 5 - } +nodes = { + signal = { + type = "signal" + + signal = "mixed" + values = 5 + } } paths = ( - { - in = "signal" - hooks = ( - { - type = "print" - } - ) - } + { + in = "signal" + hooks = ( + { + type = "print" + } + ) + } ) diff --git a/etc/tricks/nodes/node_sig1.conf b/etc/tricks/nodes/node_sig1.conf index a252fdf13..060f197a1 100644 --- a/etc/tricks/nodes/node_sig1.conf +++ b/etc/tricks/nodes/node_sig1.conf @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 sig1 = { - type = "signal" - signal = "sine" + type = "signal" + signal = "sine" } diff --git a/etc/tricks/nodes/node_sig2.conf b/etc/tricks/nodes/node_sig2.conf index 51880a1c1..c5c19375f 100644 --- a/etc/tricks/nodes/node_sig2.conf +++ b/etc/tricks/nodes/node_sig2.conf @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 sig2 = { - type = "signal" - signal = "sine" + type = "signal" + signal = "sine" } diff --git a/etc/websocket-client.conf b/etc/websocket-client.conf index 7b8744b99..afa13d773 100644 --- a/etc/websocket-client.conf +++ b/etc/websocket-client.conf @@ -1,32 +1,28 @@ -# Example configuration file for VILLASnode. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# Example configuration file for VILLASnode websocket node-type # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 nodes = { - sig = { - type = "signal", + sig = { + type = "signal", - signal = "sine" - } + signal = "sine" + } - relay = { - type = "websocket", + relay = { + type = "websocket", - destinations = [ - "https://villas.k8s.eonerc.rwth-aachen.de/ws/relay/node_1" - ] - } + destinations = [ + "https://villas.k8s.eonerc.rwth-aachen.de/ws/relay/node_1" + ] + } } paths = ( - { - in = "sig" - out = "relay" - } + { + in = "sig" + out = "relay" + } ) diff --git a/etc/websocket-demo.conf b/etc/websocket-demo.conf index 879d54758..de879967f 100644 --- a/etc/websocket-demo.conf +++ b/etc/websocket-demo.conf @@ -1,77 +1,73 @@ -# Example configuration file for VILLASnode. -# -# The syntax of this file is similar to JSON. -# A detailed description of the format can be found here: -# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files +# Example configuration file for VILLASnode websocket node-type # # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 nodes = { - sig = { - type = "signal", + sig = { + type = "signal", - signal = "mixed", - values = 5, - rate = 20, - in = { - hooks = ( - { type = "stats" } - ) - } - }, - ws_sig = { - type = "websocket", - description = "Demo Channel", - out = { - signals = ( - { name = "Random walk", unit = "V", type = "float" }, - { name = "Sine", unit = "A", type = "float" }, - { name = "Rect", unit = "Var", type = "float" }, - { name = "Ramp", unit = "°C", type = "float" } - ), - } - in = { - signals = ( ) - hooks = ( - { type = "stats" }, - { type = "print" } - ) - } - }, + signal = "mixed", + values = 5, + rate = 20, + in = { + hooks = ( + { type = "stats" } + ) + } + }, + ws_sig = { + type = "websocket", + description = "Demo Channel", + out = { + signals = ( + { name = "Random walk", unit = "V", type = "float" }, + { name = "Sine", unit = "A", type = "float" }, + { name = "Rect", unit = "Var", type = "float" }, + { name = "Ramp", unit = "°C", type = "float" } + ), + } + in = { + signals = ( ) + hooks = ( + { type = "stats" }, + { type = "print" } + ) + } + }, - ws_lo = { - type = "websocket", - description = "Loopback", - out = { - signals = ( - { name = "slider", type = "float" }, - { name = "buttons", type = "float" } - ), - } - in = { - signals = ( - { name = "slider", type = "float" }, - { name = "buttons", type = "float" } - ) - hooks = ( - { type = "stats" }, - { type = "print" } - ) - } - } + ws_lo = { + type = "websocket", + description = "Loopback", + out = { + signals = ( + { name = "slider", type = "float" }, + { name = "buttons", type = "float" } + ), + } + in = { + signals = ( + { name = "slider", type = "float" }, + { name = "buttons", type = "float" } + ) + hooks = ( + { type = "stats" }, + { type = "print" } + ) + } + } } ## List of paths paths = ( - { - in = "sig", - out = "ws_sig" - }, - { - in = "ws_lo", - out = "ws_lo" - } + { + in = "sig", + out = "ws_sig" + }, + { + in = "ws_lo", + out = "ws_lo" + } ) diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..53b45cc18 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1723320709, + "narHash": "sha256-DeKCsLQsS58D8TB/cTjXs2x8XMvsyv2JVxcF0Hu6pu8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e1d92cda6fd1bcec60e4938ce92fcee619eea793", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..602a3481f --- /dev/null +++ b/flake.nix @@ -0,0 +1,159 @@ +# SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH +# SPDX-License-Identifier: Apache-2.0 +{ + description = "VILLASnode is a client/server application to connect simulation equipment and software."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = + { self, nixpkgs, ... }: + let + inherit (nixpkgs) lib; + + nixDir = ./packaging/nix; + + # Add separateDebugInfo to a derivation + addSeparateDebugInfo = d: d.overrideAttrs { separateDebugInfo = true; }; + + # Supported systems for native compilation + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + # Generate attributes corresponding to all the supported systems + forSupportedSystems = lib.genAttrs supportedSystems; + + # Initialize nixpkgs for the specified `system` + pkgsFor = + system: + import nixpkgs { + inherit system; + overlays = with self.overlays; [ default ]; + }; + + # Initialize development nixpkgs for the specified `system` + devPkgsFor = + system: + import nixpkgs { + inherit system; + overlays = with self.overlays; [ + default + debug + ]; + }; + + # Build villas and its dependencies for the specified `pkgs` + packagesWith = pkgs: rec { + default = villas-node; + + villas-node-python = pkgs.callPackage (nixDir + "/python.nix") { src = ./.; }; + + villas-node-minimal = pkgs.callPackage (nixDir + "/villas.nix") { + src = ./.; + version = "minimal"; + }; + + villas-node = villas-node-minimal.override { + version = "full"; + withAllExtras = true; + withAllFormats = true; + withAllHooks = true; + withAllNodes = true; + }; + }; + in + { + # Standard flake attribute for normal packages (not cross-compiled) + packages = forSupportedSystems (system: packagesWith (pkgsFor system)); + + # Standard flake attribute allowing you to add the villas packages to your nixpkgs + overlays = { + default = final: prev: packagesWith final; + debug = final: prev: { + jansson = addSeparateDebugInfo prev.jansson; + libmodbus = addSeparateDebugInfo prev.libmodbus; + }; + minimal = final: prev: { + mosquitto = prev.mosquitto.override { systemd = final.systemdMinimal; }; + rdma-core = prev.rdma-core.override { udev = final.systemdMinimal; }; + }; + }; + + # Standard flake attribute for defining developer environments + devShells = forSupportedSystems ( + system: + let + pkgs = devPkgsFor system; + shellHook = ''[ -z "$PS1" ] || exec "$SHELL"''; + hardeningDisable = [ "all" ]; + packages = with pkgs; [ + bashInteractive + bc + boxfort + clang-tools + criterion + jq + libffi + libgit2 + pcre + reuse + cppcheck + ]; + in + rec { + default = full; + + full = pkgs.mkShell { + inherit shellHook hardeningDisable packages; + name = "full"; + inputsFrom = with pkgs; [ villas-node ]; + }; + + python = pkgs.mkShell { + inherit shellHook hardeningDisable; + name = "python"; + inputsFrom = with pkgs; [ villas-node-python ]; + packages = + with pkgs; + packages + ++ [ + (python3.withPackages (python-pkgs: [ + python-pkgs.build + python-pkgs.twine + ])) + ]; + }; + } + ); + + # Standard flake attribute to add additional checks to `nix flake check` + checks = forSupportedSystems ( + system: + let + pkgs = pkgsFor system; + in + { + fmt = pkgs.runCommand "check-fmt" { } '' + cd ${self} + "${pkgs.nixfmt}/bin/nixfmt" --check . 2>> $out + ''; + } + ); + + # Standard flake attribute specifying the formatter invoked on `nix fmt` + formatter = forSupportedSystems (system: (pkgsFor system).alejandra); + + # Standard flake attribute for NixOS modules + nixosModules = rec { + default = villas; + + villas = { + imports = [ (nixDir + "/module.nix") ]; + nixpkgs.overlays = [ self.overlays.default ]; + }; + }; + }; +} diff --git a/fpga b/fpga deleted file mode 160000 index d0c1fbb19..000000000 --- a/fpga +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d0c1fbb192e8df81da5b56a83586c153d0ece2d2 diff --git a/fpga/CMakeLists.txt b/fpga/CMakeLists.txt new file mode 100644 index 000000000..8ab7979e4 --- /dev/null +++ b/fpga/CMakeLists.txt @@ -0,0 +1,55 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +# GPU library is optional, check for CUDA presence +include(CheckLanguage) +check_language(CUDA) + +if(CMAKE_CUDA_COMPILER) + add_subdirectory(gpu) +else() + message("No CUDA support, not building GPU library") +endif() + +include(FindPkgConfig) + +set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig:/usr/lib64/pkgconfig") + +pkg_check_modules(JANSSON REQUIRED IMPORTED_TARGET jansson) + +find_package(Threads) +find_package(Criterion) + +include_directories(thirdparty/CLI11) +include_directories(thirdparty/rang) + +add_subdirectory(thirdparty/libxil) +add_subdirectory(lib) +add_subdirectory(src) + +if(CRITERION_FOUND) + add_subdirectory(tests/unit) +endif() + +# Project settings +set(PROJECT_NAME "VILLASfpga") +set(PROJECT_DESCRIPTION "Host library for configuring and communicating with VILLASfpga") +set(PROJECT_VENDOR "Institute for Automation of Complex Power Systems, RWTH Aachen University") +set(PROJECT_URL "https://www.fein-aachen.org/projects/villas-fpga/") +set(PROJECT_VERSION_MAJOR "0") +set(PROJECT_VERSION_MINOR "1") +set(PROJECT_VERSION_PATCH "0") +set(PROJECT_RELEASE "1") + +# pkg-config +configure_file("libvillas-fpga.pc.in" "libvillas-fpga.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libvillas-fpga.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig") + +# As close as possible to Fedoras naming +set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}") + +set(CPACK_GENERATOR "RPM") +include(CPack) diff --git a/fpga/gpu/CMakeLists.txt b/fpga/gpu/CMakeLists.txt new file mode 100644 index 000000000..5ba17eb58 --- /dev/null +++ b/fpga/gpu/CMakeLists.txt @@ -0,0 +1,38 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(thirdparty/gdrcopy) + +add_library(villas-gpu + SHARED + src/gpu.cpp + src/kernels.cu +) + +target_compile_options(villas-gpu PRIVATE -g) + +set_source_files_properties(src/gpu.cpp PROPERTIES + LANGUAGE CUDA +) + +target_include_directories(villas-gpu + PRIVATE + /opt/cuda/include +) + +target_link_libraries(villas-gpu + PUBLIC + villas-common + gdrapi + cuda +) + +target_include_directories(villas-gpu + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/include + PRIVATE + ${CMAKE_CURRENT_LIST_DIR} +) diff --git a/fpga/gpu/include/villas/gpu.hpp b/fpga/gpu/include/villas/gpu.hpp new file mode 100644 index 000000000..ada9d13a1 --- /dev/null +++ b/fpga/gpu/include/villas/gpu.hpp @@ -0,0 +1,97 @@ +/* GPU managment. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include +#include +#include + +namespace villas { +namespace gpu { + +class GpuAllocator; + +class Gpu { + friend GpuAllocator; + +public: + Gpu(int gpuId); + ~Gpu(); + + bool init(); + + std::string getName() const; + + GpuAllocator &getAllocator() const { return *allocator; } + + bool makeAccessibleToPCIeAndVA(const MemoryBlock &mem); + + // Make some memory block accssible for this GPU + bool makeAccessibleFromPCIeOrHostRam(const MemoryBlock &mem); + + void memcpySync(const MemoryBlock &src, const MemoryBlock &dst, size_t size); + + void memcpyKernel(const MemoryBlock &src, const MemoryBlock &dst, + size_t size); + + MemoryTranslation translate(const MemoryBlock &dst); + +private: + bool registerIoMemory(const MemoryBlock &mem); + bool registerHostMemory(const MemoryBlock &mem); + +private: + class impl; + std::unique_ptr pImpl; + + // Master, will be used to derived slave addr spaces for allocation + MemoryManager::AddressSpaceId masterPciEAddrSpaceId; + + MemoryManager::AddressSpaceId slaveMemoryAddrSpaceId; + + Logger logger; + + int gpuId; + + std::unique_ptr allocator; +}; + +class GpuAllocator : public BaseAllocator { +public: + static constexpr size_t GpuPageSize = 64UL << 10; + + GpuAllocator(Gpu &gpu); + + std::string getName() const; + + std::unique_ptr + allocateBlock(size_t size); + +private: + Gpu &gpu; + // TODO: replace by multimap (key is available memory) + std::list> chunks; +}; + +class GpuFactory : public Plugin { +public: + GpuFactory(); + + std::list> make(); + + void run(void *); + +private: + Logger logger; +}; + +} // namespace gpu +} // namespace villas diff --git a/fpga/gpu/kernels.hpp b/fpga/gpu/kernels.hpp new file mode 100644 index 000000000..4e3727c04 --- /dev/null +++ b/fpga/gpu/kernels.hpp @@ -0,0 +1,23 @@ +/* GPU Kernels. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +namespace villas { +namespace gpu { + +__global__ void kernel_mailbox(volatile uint32_t *mailbox, + volatile uint32_t *counter); + +__global__ void kernel_memcpy(volatile uint8_t *dst, volatile uint8_t *src, + size_t length); + +} // namespace gpu +} // namespace villas diff --git a/fpga/gpu/src/gpu.cpp b/fpga/gpu/src/gpu.cpp new file mode 100644 index 000000000..f80a9521e --- /dev/null +++ b/fpga/gpu/src/gpu.cpp @@ -0,0 +1,481 @@ +/* GPU managment. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "kernels.hpp" + +using namespace villas::gpu; + +static GpuFactory gpuFactory; + +GpuAllocator::GpuAllocator(Gpu &gpu) + : BaseAllocator(gpu.masterPciEAddrSpaceId), gpu(gpu) { + free = [&](MemoryBlock *mem) { + cudaSetDevice(gpu.gpuId); + if (cudaFree(reinterpret_cast(mem->getOffset())) != cudaSuccess) { + logger->warn("cudaFree() failed for {:#x} of size {:#x}", + mem->getOffset(), mem->getSize()); + } + + removeMemoryBlock(*mem); + }; +} + +std::string villas::gpu::GpuAllocator::getName() const { + std::stringstream name; + name << "GpuAlloc" << getAddrSpaceId(); + return name.str(); +} + +GpuFactory::GpuFactory() + : logger(villas::Log::get("gpu:factory")), + Plugin("cuda", "CUDA capable GPUs") {} + +// Required to be defined here for PIMPL to compile +Gpu::~Gpu() { + auto &mm = MemoryManager::get(); + mm.removeAddressSpace(masterPciEAddrSpaceId); +} + +// We use PIMPL in order to hide gdrcopy types from the public header +class Gpu::impl { +public: + gdr_t gdr; + struct pci_device pdev; +}; + +std::string Gpu::getName() const { + cudaDeviceProp deviceProp; + if (cudaGetDeviceProperties(&deviceProp, gpuId) != cudaSuccess) { + // Logger not yet availabe + villas::Log::get("gpu")->error("Cannot retrieve properties for GPU {}", + gpuId); + throw std::exception(); + } + + std::stringstream name; + name << "gpu" << gpuId << "(" << deviceProp.name << ")"; + + return name.str(); +} + +bool Gpu::registerIoMemory(const MemoryBlock &mem) { + auto &mm = MemoryManager::get(); + const auto pciAddrSpaceId = mm.getPciAddressSpace(); + + // Check if we need to map anything at all, maybe it's already reachable + try { + // TODO: there might already be a path through the graph, but there's no + // overlapping window, so this will fail badly! + auto translation = + mm.getTranslation(masterPciEAddrSpaceId, mem.getAddrSpaceId()); + if (translation.getSize() >= mem.getSize()) + // There is already a sufficient path + logger->debug("Already mapped through another mapping"); + return true; + else logger->warn("There's already a mapping, but too small"); + } catch (const std::out_of_range &) { + // Not yet reachable, that's okay, proceed + } + + // In order to register IO memory with CUDA, it has to be mapped to the VA + // space of the current process (requirement of CUDA API). Check this now. + MemoryManager::AddressSpaceId mappedBaseAddrSpaceId; + try { + auto path = mm.findPath(mm.getProcessAddressSpace(), mem.getAddrSpaceId()); + // First node in path is the mapped memory space whose virtual address + // we need to hand to CUDA + mappedBaseAddrSpaceId = path.front(); + } catch (const std::out_of_range &) { + logger->error("Memory not reachable from process, but required by CUDA"); + return false; + } + + // Determine the base address of the mapped memory region needed by CUDA + const auto translationProcess = + mm.getTranslationFromProcess(mappedBaseAddrSpaceId); + const uintptr_t baseAddrForProcess = translationProcess.getLocalAddr(0); + + // Now check that the memory is also reachable via PCIe bus, otherwise GPU + // has no means to access it. + uintptr_t baseAddrOnPci; + size_t sizeOnPci; + try { + auto translationPci = + mm.getTranslation(pciAddrSpaceId, mappedBaseAddrSpaceId); + baseAddrOnPci = translationPci.getLocalAddr(0); + sizeOnPci = translationPci.getSize(); + } catch (const std::out_of_range &) { + logger->error("Memory is not reachable via PCIe bus"); + return false; + } + + if (sizeOnPci < mem.getSize()) { + logger->warn( + "VA mapping of IO memory is too small: {:#x} instead of {:#x} bytes", + sizeOnPci, mem.getSize()); + logger->warn("If something later on fails or behaves strangely, this might " + "be the cause!"); + } + + cudaSetDevice(gpuId); + + auto baseAddrVA = reinterpret_cast(baseAddrForProcess); + if (cudaHostRegister(baseAddrVA, sizeOnPci, cudaHostRegisterIoMemory) != + cudaSuccess) { + logger->error("Cannot register IO memory for block {}", + mem.getAddrSpaceId()); + return false; + } + + void *devicePointer = nullptr; + if (cudaHostGetDevicePointer(&devicePointer, baseAddrVA, 0) != cudaSuccess) { + logger->error("Cannot retrieve device pointer for IO memory"); + return false; + } + + mm.createMapping(reinterpret_cast(devicePointer), baseAddrOnPci, + sizeOnPci, "CudaIoMem", masterPciEAddrSpaceId, + pciAddrSpaceId); + + return true; +} + +bool Gpu::registerHostMemory(const MemoryBlock &mem) { + auto &mm = MemoryManager::get(); + + auto translation = mm.getTranslationFromProcess(mem.getAddrSpaceId()); + auto localBase = reinterpret_cast(translation.getLocalAddr(0)); + + int ret = cudaHostRegister(localBase, mem.getSize(), 0); + if (ret != cudaSuccess) { + logger->error( + "Cannot register memory block {} addr={:p} size={:#x} to CUDA: ret={}", + mem.getAddrSpaceId(), localBase, mem.getSize(), ret); + return false; + } + + void *devicePointer = nullptr; + ret = cudaHostGetDevicePointer(&devicePointer, localBase, 0); + if (ret != cudaSuccess) { + logger->error("Cannot retrieve device pointer for IO memory: ret={}", ret); + return false; + } + + mm.createMapping(reinterpret_cast(devicePointer), 0, mem.getSize(), + "CudaHostMem", masterPciEAddrSpaceId, mem.getAddrSpaceId()); + + return true; +} + +bool Gpu::makeAccessibleToPCIeAndVA(const MemoryBlock &mem) { + if (pImpl->gdr == nullptr) { + logger->warn("GDRcopy not available"); + return false; + } + + auto &mm = MemoryManager::get(); + + try { + auto path = mm.findPath(masterPciEAddrSpaceId, mem.getAddrSpaceId()); + // If first hop is the PCIe bus, we know that memory is off-GPU + if (path.front() == mm.getPciAddressSpace()) + throw std::out_of_range("Memory block is outside of this GPU"); + + } catch (const std::out_of_range &) { + logger->error("Trying to map non-GPU memory block"); + return false; + } + + logger->debug("retrieve complete device pointer from point of view of GPU"); + + // Retrieve complete device pointer from point of view of GPU + auto translation = + mm.getTranslation(masterPciEAddrSpaceId, mem.getAddrSpaceId()); + CUdeviceptr devptr = translation.getLocalAddr(0); + + int ret; + + // Required to set this flag before mapping + unsigned int enable = 1; + ret = + cuPointerSetAttribute(&enable, CU_POINTER_ATTRIBUTE_SYNC_MEMOPS, devptr); + if (ret != CUDA_SUCCESS) { + logger->error("Cannot set pointer attributes on memory block {}: {}", + mem.getAddrSpaceId(), ret); + return false; + } + + gdr_mh_t mh; + ret = gdr_pin_buffer(pImpl->gdr, devptr, mem.getSize(), 0, 0, &mh); + if (ret != 0) { + logger->error("Cannot pin memory block {} via gdrcopy: {}", + mem.getAddrSpaceId(), ret); + return false; + } + + void *bar = nullptr; + ret = gdr_map(pImpl->gdr, mh, &bar, mem.getSize()); + if (ret != 0) { + logger->error("Cannot map memory block {} via gdrcopy: {}", + mem.getAddrSpaceId(), ret); + return false; + } + + gdr_info_t info; + ret = gdr_get_info(pImpl->gdr, mh, &info); + if (ret != 0) { + logger->error("Cannot get info for mapping of memory block {}: {}", + mem.getAddrSpaceId(), ret); + return false; + } + + const uintptr_t offset = info.va - devptr; + const uintptr_t userPtr = reinterpret_cast(bar) + offset; + + logger->debug("BAR ptr: {:p}", bar); + logger->debug("info.va: {:#x}", info.va); + logger->debug("info.mapped_size: {:#x}", info.mapped_size); + logger->debug("info.page_size: {:#x}", info.page_size); + logger->debug("offset: {:#x}", offset); + logger->debug("user pointer: {:#x}", userPtr); + + // Mapping to acceses memory block from process + mm.createMapping(userPtr, 0, info.mapped_size, "GDRcopy", + mm.getProcessAddressSpace(), mem.getAddrSpaceId()); + + // Retrieve bus address + uint64_t addr[8]; + ret = gdr_map_dma(pImpl->gdr, mh, 3, 0, 0, addr, 8); + + for (int i = 0; i < ret; i++) + logger->debug("DMA addr[{}]: {:#x}", i, addr[i]); + + if (ret != 1) { + logger->error("Only one DMA address per block supported at the moment"); + return false; + } + + // Mapping to access memory block from peer devices via PCIe + mm.createMapping(addr[0], 0, mem.getSize(), "GDRcopyDMA", + mm.getPciAddressSpace(), mem.getAddrSpaceId()); + + return true; +} + +bool Gpu::makeAccessibleFromPCIeOrHostRam(const MemoryBlock &mem) { + // Check which kind of memory this is and where it resides + // There are two possibilities: + // - Host memory not managed by CUDA + // - IO memory somewhere on the PCIe bus + + auto &mm = MemoryManager::get(); + + bool isIoMemory = false; + try { + auto path = mm.findPath(mm.getPciAddressSpace(), mem.getAddrSpaceId()); + isIoMemory = true; + } catch (const std::out_of_range &) { + // Not reachable via PCI -> not IO memory + } + + if (isIoMemory) { + logger->debug("Memory block {} is assumed to be IO memory", + mem.getAddrSpaceId()); + + return registerIoMemory(mem); + } else { + logger->debug("Memory block {} is assumed to be non-CUDA host memory", + mem.getAddrSpaceId()); + + return registerHostMemory(mem); + } +} + +void Gpu::memcpySync(const MemoryBlock &src, const MemoryBlock &dst, + size_t size) { + auto &mm = MemoryManager::get(); + + auto src_translation = + mm.getTranslation(masterPciEAddrSpaceId, src.getAddrSpaceId()); + const void *src_buf = + reinterpret_cast(src_translation.getLocalAddr(0)); + + auto dst_translation = + mm.getTranslation(masterPciEAddrSpaceId, dst.getAddrSpaceId()); + void *dst_buf = reinterpret_cast(dst_translation.getLocalAddr(0)); + + cudaSetDevice(gpuId); + cudaMemcpy(dst_buf, src_buf, size, cudaMemcpyDefault); +} + +void Gpu::memcpyKernel(const MemoryBlock &src, const MemoryBlock &dst, + size_t size) { + auto &mm = MemoryManager::get(); + + auto src_translation = + mm.getTranslation(masterPciEAddrSpaceId, src.getAddrSpaceId()); + auto src_buf = reinterpret_cast(src_translation.getLocalAddr(0)); + + auto dst_translation = + mm.getTranslation(masterPciEAddrSpaceId, dst.getAddrSpaceId()); + auto dst_buf = reinterpret_cast(dst_translation.getLocalAddr(0)); + + cudaSetDevice(gpuId); + kernel_memcpy<<<1, 1>>>(dst_buf, src_buf, size); + cudaDeviceSynchronize(); +} + +MemoryTranslation Gpu::translate(const MemoryBlock &dst) { + auto &mm = MemoryManager::get(); + return mm.getTranslation(masterPciEAddrSpaceId, dst.getAddrSpaceId()); +} + +std::unique_ptr +GpuAllocator::allocateBlock(size_t size) { + cudaSetDevice(gpu.gpuId); + + void *addr; + auto &mm = MemoryManager::get(); + + // Search for an existing chunk that has enough free memory + auto chunk = + std::find_if(chunks.begin(), chunks.end(), [&](const auto &chunk) { + return chunk->getAvailableMemory() >= size; + }); + + if (chunk != chunks.end()) { + logger->debug("Found existing chunk that can host the requested block"); + + return (*chunk)->allocateBlock(size); + } else { + // Allocate a new chunk + + // Rounded-up multiple of GPU page size + const size_t chunkSize = size - (size & (GpuPageSize - 1)) + GpuPageSize; + logger->debug("Allocate new chunk of {:#x} bytes", chunkSize); + + if (cudaSuccess != cudaMalloc(&addr, chunkSize)) { + logger->error("cudaMalloc(..., size={}) failed", chunkSize); + throw std::bad_alloc(); + } + + // Assemble name for this block + std::stringstream name; + name << std::showbase << std::hex << reinterpret_cast(addr); + + auto blockName = mm.getSlaveAddrSpaceName(getName(), name.str()); + auto blockAddrSpaceId = mm.getOrCreateAddressSpace(blockName); + + const auto localAddr = reinterpret_cast(addr); + std::unique_ptr mem( + new MemoryBlock(localAddr, chunkSize, blockAddrSpaceId), this->free); + + insertMemoryBlock(*mem); + + // Already make accessible to CPU + gpu.makeAccessibleToPCIeAndVA(*mem); + + // Create a new allocator to manage the chunk and push to chunk list + chunks.push_front(std::make_unique(std::move(mem))); + + // Call again, this time there's a large enough chunk + return allocateBlock(size); + } +} + +Gpu::Gpu(int gpuId) : pImpl{std::make_unique()}, gpuId(gpuId) { + logger = villas::Log::get(getName()); + + pImpl->gdr = gdr_open(); + if (pImpl->gdr == nullptr) { + logger->warn("No GDRcopy support enabled, cannot open /dev/gdrdrv"); + } +} + +bool Gpu::init() { + auto &mm = MemoryManager::get(); + + const auto gpuPciEAddrSpaceName = + mm.getMasterAddrSpaceName(getName(), "pcie"); + masterPciEAddrSpaceId = mm.getOrCreateAddressSpace(gpuPciEAddrSpaceName); + + allocator = std::make_unique(*this); + + cudaDeviceProp deviceProp; + cudaGetDeviceProperties(&deviceProp, gpuId); + + pImpl->pdev.slot = {deviceProp.pciDomainID, deviceProp.pciBusID, + deviceProp.pciDeviceID, 0}; + + struct pci_region *pci_regions = nullptr; + const size_t pci_num_regions = pci_get_regions(&pImpl->pdev, &pci_regions); + for (size_t i = 0; i < pci_num_regions; i++) { + const size_t region_size = pci_regions[i].end - pci_regions[i].start + 1; + logger->info("BAR{}: bus addr={:#x} size={:#x}", pci_regions[i].num, + pci_regions[i].start, region_size); + + char name[] = "BARx"; + name[3] = '0' + pci_regions[i].num; + + auto gpuBarXAddrSpaceName = mm.getSlaveAddrSpaceName(getName(), name); + auto gpuBarXAddrSpaceId = mm.getOrCreateAddressSpace(gpuBarXAddrSpaceName); + + mm.createMapping(pci_regions[i].start, 0, region_size, + std::string("PCI-") + name, mm.getPciAddressSpace(), + gpuBarXAddrSpaceId); + } + + free(pci_regions); + + return true; +} + +std::list> GpuFactory::make() { + int deviceCount = 0; + cudaGetDeviceCount(&deviceCount); + + std::list> gpuList; + + for (int gpuId = 0; gpuId < deviceCount; gpuId++) { + if (cudaSetDevice(gpuId) != cudaSuccess) { + logger->warn("Cannot activate GPU {}", gpuId); + continue; + } + + auto gpu = std::make_unique(gpuId); + + if (not gpu->init()) { + logger->warn("Cannot initialize GPU {}", gpuId); + continue; + } + + gpuList.emplace_back(std::move(gpu)); + } + + logger->info("Initialized {} GPUs", gpuList.size()); + for (auto &gpu : gpuList) { + logger->debug(" - {}", gpu->getName()); + } + + return gpuList; +} diff --git a/fpga/gpu/src/kernels.cu b/fpga/gpu/src/kernels.cu new file mode 100644 index 000000000..2c175d732 --- /dev/null +++ b/fpga/gpu/src/kernels.cu @@ -0,0 +1,46 @@ +/** GPU Kernels. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + *********************************************************************************/ + +#include + +#include + +#include +#include + +#include "kernels.hpp" + +using namespace villas::gpu; + + +__global__ void +kernel_mailbox(volatile uint32_t *mailbox, volatile uint32_t* counter) +{ + printf("[gpu] hello!\n"); + printf("[gpu] mailbox: %p\n", mailbox); + + printf("[kernel] started\n"); + + while (1) { + if (*mailbox == 1) { + *mailbox = 0; + printf("[gpu] counter = %d\n", *counter); + break; + } + } + + printf("[gpu] quit\n"); +} + +__global__ void +kernel_memcpy(volatile uint8_t* dst, volatile uint8_t* src, size_t length) +{ + while (length > 0) { + *dst++ = *src++; + length--; + } +} diff --git a/fpga/gpu/thirdparty/gdrcopy b/fpga/gpu/thirdparty/gdrcopy new file mode 160000 index 000000000..fcf4bc566 --- /dev/null +++ b/fpga/gpu/thirdparty/gdrcopy @@ -0,0 +1 @@ +Subproject commit fcf4bc56687c01e71379c174b6875bd3a99b31c7 diff --git a/fpga/include/villas/fpga/card.hpp b/fpga/include/villas/fpga/card.hpp new file mode 100644 index 000000000..58c7152d0 --- /dev/null +++ b/fpga/include/villas/fpga/card.hpp @@ -0,0 +1,58 @@ +/* FPGA card + * + * This class represents a FPGA device. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include + +namespace villas { +namespace fpga { + +class Card { +public: + bool polling; + + std::string name; // The name of the FPGA card + std::shared_ptr vfioContainer; + std::shared_ptr vfioDevice; + + // Slave address space ID to access the PCIe address space from the + // FPGA + MemoryManager::AddressSpaceId addrSpaceIdDeviceToHost; + + // Address space identifier of the master address space of this FPGA + // card. This will be used for address resolution of all IPs on this + // card. + MemoryManager::AddressSpaceId addrSpaceIdHostToDevice; + + std::list> ips; + + virtual ~Card(); + + virtual bool mapMemoryBlock(const std::shared_ptr block); + virtual bool unmapMemoryBlock(const MemoryBlock &block); + + std::shared_ptr lookupIp(const std::string &name) const; + std::shared_ptr lookupIp(const Vlnv &vlnv) const; + std::shared_ptr lookupIp(const ip::IpIdentifier &id) const; + +protected: + // Keep a map of already mapped memory blocks + std::map> + memoryBlocksMapped; + + Logger logger; +}; + +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/config.h b/fpga/include/villas/fpga/config.h new file mode 100644 index 000000000..ae581d6f1 --- /dev/null +++ b/fpga/include/villas/fpga/config.h @@ -0,0 +1,20 @@ +/* Compile time configuration + * + * This file contains some compiled-in settings. + * This settings are not part of the configuration file. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +// PCIe BAR number of VILLASfpga registers +#define FPGA_PCI_BAR 0 +#define FPGA_PCI_VID_XILINX 0x10ee +#define FPGA_PCI_PID_VFPGA 0x7022 + +/* AXI Bus frequency for all components + * except RTDS AXI Stream bridge which runs at RTDS_HZ (100 Mhz) */ +#define FPGA_AXI_HZ 125000000 // 125 MHz diff --git a/fpga/include/villas/fpga/core.hpp b/fpga/include/villas/fpga/core.hpp new file mode 100644 index 000000000..089aaf8e7 --- /dev/null +++ b/fpga/include/villas/fpga/core.hpp @@ -0,0 +1,274 @@ +/* Interlectual Property component. + * + * This class represents a module within the FPGA. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace fpga { + +// Forward declarations +class Card; + +namespace ip { + +// Forward declarations +class Core; +class CoreFactory; +class InterruptController; + +class IpIdentifier { +public: + IpIdentifier(const Vlnv &vlnv = Vlnv::getWildcard(), + const std::string &name = "") + : vlnv(vlnv), name(name) {} + + IpIdentifier(const std::string &vlnvString, const std::string &name = "") + : vlnv(vlnvString), name(name) {} + + const std::string &getName() const { return name; } + + const Vlnv &getVlnv() const { return vlnv; } + + friend std::ostream &operator<<(std::ostream &stream, + const IpIdentifier &id) { + return stream << id.name << " vlnv=" << id.vlnv; + } + + bool operator==(const IpIdentifier &otherId) const { + const bool vlnvWildcard = otherId.getVlnv() == Vlnv::getWildcard(); + const bool nameWildcard = + this->getName().empty() or otherId.getName().empty(); + + const bool vlnvMatch = vlnvWildcard or this->getVlnv() == otherId.getVlnv(); + const bool nameMatch = nameWildcard or this->getName() == otherId.getName(); + + return vlnvMatch and nameMatch; + } + + bool operator!=(const IpIdentifier &otherId) const { + return !(*this == otherId); + } + +private: + Vlnv vlnv; + std::string name; +}; + +class Core { + friend CoreFactory; + +public: + Core() : card(nullptr) {} + + virtual ~Core() = default; + +public: + // Generic management interface for IPs + + // Runtime setup of IP, should access and initialize hardware + virtual bool init() { return true; } + + // Runtime check of IP, should verify basic functionality + virtual bool check() { return true; } + + // Generic disabling of IP, meaning may depend on IP + virtual bool stop() { return true; } + + // Reset the IP, it should behave like freshly initialized afterwards + virtual bool reset() { return true; } + + // Print some debug information about the IP + virtual void dump(); + +protected: + // Key-type for accessing maps addressTranslations and slaveAddressSpaces + using MemoryBlockName = std::string; + + // Each IP can declare via this function which memory blocks it requires + virtual std::list getMemoryBlocks() const { return {}; } + +public: + size_t getBaseaddr() const { return baseaddr; } + const std::string &getInstanceName() const { return id.getName(); } + + // Operators + + bool operator==(const Vlnv &otherVlnv) const { + return id.getVlnv() == otherVlnv; + } + + bool operator!=(const Vlnv &otherVlnv) const { + return id.getVlnv() != otherVlnv; + } + + bool operator==(const IpIdentifier &otherId) const { + return this->id == otherId; + } + + bool operator!=(const IpIdentifier &otherId) const { + return this->id != otherId; + } + + bool operator==(const std::string &otherName) const { + return getInstanceName() == otherName; + } + + bool operator!=(const std::string &otherName) const { + return getInstanceName() != otherName; + } + + bool operator==(const Core &otherIp) const { return this->id == otherIp.id; } + + bool operator!=(const Core &otherIp) const { return this->id != otherIp.id; } + + friend std::ostream &operator<<(std::ostream &stream, const Core &ip) { + return stream << ip.id; + } + +protected: + uintptr_t getBaseAddr(const MemoryBlockName &block) const { + return getLocalAddr(block, 0); + } + + uintptr_t getLocalAddr(const MemoryBlockName &block, uintptr_t address) const; + + MemoryManager::AddressSpaceId + getAddressSpaceId(const MemoryBlockName &block) const { + return slaveAddressSpaces.at(block); + } + + InterruptController * + getInterruptController(const std::string &interruptName) const; + + MemoryManager::AddressSpaceId + getMasterAddrSpaceByInterface(const std::string &masterInterfaceName) const { + return busMasterInterfaces.at(masterInterfaceName); + } + + template + T readMemory(const std::string &block, uintptr_t address) const { + return *(reinterpret_cast(getLocalAddr(block, address))); + } + + template + void writeMemory(const std::string &block, uintptr_t address, T value) { + T *ptr = reinterpret_cast(getLocalAddr(block, address)); + *ptr = value; + } + +protected: + struct IrqPort { + int num; + InterruptController *irqController; + std::string description; + }; + + // Specialized logger instance with the IPs name set as category + Logger logger; + + // FPGA card this IP is instantiated on (populated by FpgaIpFactory) + Card *card; + + // Identifier of this IP with its instance name and VLNV + IpIdentifier id; + + // All interrupts of this IP with their associated interrupt controller + std::map irqs; + + // Cached translations from the process address space to each memory block + std::map addressTranslations; + + // Lookup for IP's slave address spaces (= memory blocks) + std::map slaveAddressSpaces; + + // AXI bus master interfaces to access memory somewhere + std::map busMasterInterfaces; + + size_t baseaddr = 0; +}; + +class CoreFactory : public plugin::Plugin { +public: + using plugin::Plugin::Plugin; + + static std::list parseIpIdentifier(json_t *json_ips); + static std::list reorderIps(std::list allIps); + static std::list> + configureIps(std::list orderedIps, json_t *json_ips, + Card *card); + static void initIps(std::list> orderedIps, Card *card); + + // Returns a running and checked FPGA IP + static std::list> make(Card *card, json_t *json_ips); + + virtual std::string getType() const { return "core"; } + +protected: + enum PollingMode { + POLL, + IRQ, + }; + + Logger getLogger() { return villas::Log::get(getName()); } + + // Configure IP instance from JSON config + virtual void parse(Core &, json_t *) {} + + static Logger getStaticLogger() { return villas::Log::get("core:factory"); } + +private: + virtual void configurePollingMode(Core &, PollingMode) {} + + virtual Vlnv getCompatibleVlnv() const = 0; + + // Create a concrete IP instance + virtual Core *make() const = 0; + + static CoreFactory *lookup(const Vlnv &vlnv); +}; + +template +class CorePlugin : public CoreFactory { + +public: + virtual std::string getName() const { return name; } + + virtual std::string getDescription() const { return desc; } + +private: + virtual Vlnv getCompatibleVlnv() const { return Vlnv(vlnv); } + + // Create a concrete IP instance + Core *make() const { return new T; }; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/dma.h b/fpga/include/villas/fpga/dma.h new file mode 100644 index 000000000..ebd7ffcc0 --- /dev/null +++ b/fpga/include/villas/fpga/dma.h @@ -0,0 +1,41 @@ +/* C bindings for VILLASfpga + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _VILLASFPGA_DMA_H +#define _VILLASFPGA_DMA_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct villasfpga_handle_t *villasfpga_handle; +typedef struct villasfpga_memory_t *villasfpga_memory; + +villasfpga_handle villasfpga_init(const char *configFile); + +void villasfpga_destroy(villasfpga_handle handle); + +int villasfpga_alloc(villasfpga_handle handle, villasfpga_memory *mem, + size_t size); +int villasfpga_register(villasfpga_handle handle, villasfpga_memory *mem); +int villasfpga_free(villasfpga_memory mem); +void *villasfpga_get_ptr(villasfpga_memory mem); + +int villasfpga_read(villasfpga_handle handle, villasfpga_memory mem, + size_t size); +int villasfpga_read_complete(villasfpga_handle handle, size_t *size); + +int villasfpga_write(villasfpga_handle handle, villasfpga_memory mem, + size_t size); +int villasfpga_write_complete(villasfpga_handle handle, size_t *size); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _VILLASFPGA_DMA_H diff --git a/fpga/include/villas/fpga/ips/aurora.hpp b/fpga/include/villas/fpga/ips/aurora.hpp new file mode 100644 index 000000000..7c969687d --- /dev/null +++ b/fpga/include/villas/fpga/ips/aurora.hpp @@ -0,0 +1,43 @@ +/* Driver for wrapper around Aurora (acs.eonerc.rwth-aachen.de:user:aurora) + * + * Author: Hatim Kanchwala + * SPDX-FileCopyrightText: 2020 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Aurora : public Node { +public: + static constexpr const char *masterPort = "m_axis"; + static constexpr const char *slavePort = "s_axis"; + + virtual void dump() override; + + std::list getMemoryBlocks() const { return {registerMemory}; } + + const StreamVertex &getDefaultSlavePort() const { + return getSlavePort(slavePort); + } + + const StreamVertex &getDefaultMasterPort() const { + return getMasterPort(masterPort); + } + + void setLoopback(bool state); + + void resetFrameCounters(); + +private: + static constexpr const char registerMemory[] = "reg0"; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/aurora_xilinx.hpp b/fpga/include/villas/fpga/ips/aurora_xilinx.hpp new file mode 100644 index 000000000..4da5628f0 --- /dev/null +++ b/fpga/include/villas/fpga/ips/aurora_xilinx.hpp @@ -0,0 +1,32 @@ +/* Driver for wrapper around standard Xilinx Aurora (xilinx.com:ip:aurora_8b10b) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class AuroraXilinx : public Node { +public: + static constexpr const char *masterPort = "USER_DATA_M_AXI_RX"; + static constexpr const char *slavePort = "USER_DATA_S_AXI_TX"; + + const StreamVertex &getDefaultSlavePort() const { + return getSlavePort(slavePort); + } + + const StreamVertex &getDefaultMasterPort() const { + return getMasterPort(masterPort); + } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/bram.hpp b/fpga/include/villas/fpga/ips/bram.hpp new file mode 100644 index 000000000..5381f5afb --- /dev/null +++ b/fpga/include/villas/fpga/ips/bram.hpp @@ -0,0 +1,57 @@ +/* Block-Raam related helper functions + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class BramFactory; + +class Bram : public Core { + friend class BramFactory; + +public: + virtual bool init() override; + + LinearAllocator &getAllocator() { return *allocator; } + +private: + static constexpr const char *memoryBlock = "Mem0"; + + std::list getMemoryBlocks() const { return {memoryBlock}; } + + size_t size; + std::unique_ptr allocator; +}; + +class BramFactory : public CoreFactory { + +public: + virtual std::string getName() const { return "bram"; } + + virtual std::string getDescription() const { return "Block RAM"; } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:ip:axi_bram_ctrl:"); + } + + // Create a concrete IP instance + Core *make() const { return new Bram; }; + +protected: + virtual void parse(Core &, json_t *) override; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/dino.hpp b/fpga/include/villas/fpga/ips/dino.hpp new file mode 100644 index 000000000..56384b9f0 --- /dev/null +++ b/fpga/include/villas/fpga/ips/dino.hpp @@ -0,0 +1,160 @@ +/* Driver for wrapper around Dino + * + * Author: Niklas Eiling + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2024 Niklas Eiling + * SPDX-FileCopyrightText: 2020 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Dino : public Node { +public: + friend class DinoFactory; + union IoextPorts { + struct __attribute__((packed)) { + bool clk_dir : 1; + bool data_dir : 1; + bool status_led : 1; + bool n_we : 1; // write enable (active low) + bool input_zero : 1; + bool sat_detect : 1; + bool gain_lsb : 1; + bool gain_msb : 1; + } fields; + uint8_t raw; + + friend std::ostream &operator<<(std::ostream &stream, + const IoextPorts &ports) { + return stream << "IoextPorts [clk_dir=" << ports.fields.clk_dir + << ", data_dir=" << ports.fields.data_dir + << ", status_led=" << ports.fields.status_led + << ", n_we=" << ports.fields.n_we + << ", input_zero=" << ports.fields.input_zero + << ", sat_detect=" << ports.fields.sat_detect + << ", gain_lsb=" << ports.fields.gain_lsb + << ", gain_msb=" << ports.fields.gain_msb << "]"; + } + std::string toString() { + std::stringstream s; + s << *this; + return s.str(); + } + }; + enum Gain { GAIN_1 = 0, GAIN_2 = 1, GAIN_5 = 2, GAIN_10 = 3 }; + + Dino(); + virtual ~Dino(); + virtual bool init() override; + void setI2c(std::shared_ptr i2cdev, uint8_t i2c_channel) { + this->i2cdev = i2cdev; + this->i2c_channel = i2c_channel; + } + virtual void configureHardware() = 0; + + static constexpr const char *masterPort = "M00_AXIS"; + static constexpr const char *slavePort = "S00_AXIS"; + + const StreamVertex &getDefaultSlavePort() const override { + return getSlavePort(slavePort); + } + + const StreamVertex &getDefaultMasterPort() const override { + return getMasterPort(masterPort); + } + + IoextPorts getIoextDirectionRegister(); + IoextPorts getIoextOutputRegister(); + +protected: + std::shared_ptr i2cdev; + uint8_t i2c_channel; + bool configDone; + + IoextPorts getIoextDir(); + IoextPorts getIoextOut(); + void setIoextDir(IoextPorts ports); + void setIoextOut(IoextPorts ports); +}; + +class DinoAdc : public Dino { +public: + DinoAdc(); + virtual ~DinoAdc(); + virtual void configureHardware() override; + + /** Set the configuration of the ADC registers + * + * @param reg Register to set + * @param sampleRate Sample rate in Hz. The default is 100 Hz. + */ + static void setRegisterConfig(std::shared_ptr reg, + double sampleRate = (1 / 10e-3)); + + static void setRegisterConfigTimestep(std::shared_ptr reg, + double timestep = 10e-3) { + setRegisterConfig(reg, 1 / timestep); + } +}; + +class DinoDac : public Dino { +public: + DinoDac(); + virtual ~DinoDac(); + virtual void configureHardware() override; + void setGain(Gain gain); + Gain getGain(); +}; + +class DinoFactory : NodeFactory { +public: + virtual std::string getDescription() const override { + return "Dino Analog I/O"; + } + +protected: + virtual void parse(Core &ip, json_t *json) override; +}; + +class DinoAdcFactory : DinoFactory { +public: + virtual std::string getName() const { return "dinoAdc"; } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:module_ref:dinoif_fast:"); + } + Core *make() const { return new DinoAdc; }; +}; + +class DinoDacFactory : DinoFactory { +public: + virtual std::string getName() const { return "dinoDac"; } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:module_ref:dinoif_dac:"); + } + Core *make() const { return new DinoDac; }; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/ips/dma.hpp b/fpga/include/villas/fpga/ips/dma.hpp new file mode 100644 index 000000000..b7caa2dbb --- /dev/null +++ b/fpga/include/villas/fpga/ips/dma.hpp @@ -0,0 +1,187 @@ +/* DMA driver + * + * Author: Daniel Krebs + * Author: Steffen Vogel + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Dma : public Node { +public: + friend class DmaFactory; + + virtual ~Dma(); + + virtual bool init() override; + + bool reset() override; + + // Memory-mapped to stream (MM2S) + bool write(const MemoryBlock &mem, size_t len); + + // Stream to memory-mapped (S2MM) + bool read(const MemoryBlock &mem, size_t len); + + struct Completion { + Completion() : bytes(0), bds(0), interrupts(0) {} + size_t bytes; // Number of bytes transferred + size_t bds; // Number of buffer descriptors used (only for scatter-gather) + size_t + interrupts; // Number of interrupts received since last call (only if interrupts enabled) + }; + + Completion writeComplete() { + return hasScatterGather() ? writeCompleteScatterGather() + : writeCompleteSimple(); + } + + bool readScatterGatherPrepare(const MemoryBlock &mem, size_t len); + bool readScatterGatherFast(); + size_t readScatterGatherPoll(bool lock = true); + + bool writeScatterGatherPrepare(const MemoryBlock &mem, size_t len); + bool writeScatterGatherFast(); + size_t writeScatterGatherPoll(bool lock = true); + + Completion readComplete() { + return hasScatterGather() ? readCompleteScatterGather() + : readCompleteSimple(); + } + + bool memcpy(const MemoryBlock &src, const MemoryBlock &dst, size_t len); + + void makeAccesibleFromVA(std::shared_ptr mem); + bool makeInaccesibleFromVA(const MemoryBlock &mem); + + inline bool hasScatterGather() const { return xConfig.HasSg; } + + const StreamVertex &getDefaultSlavePort() const override { + return getSlavePort(s2mmPort); + } + + const StreamVertex &getDefaultMasterPort() const override { + return getMasterPort(mm2sPort); + } + + static constexpr const char *s2mmPort = "S2MM"; + static constexpr const char *mm2sPort = "MM2S"; + + bool isMemoryBlockAccesible(const MemoryBlock &mem, + const std::string &interface); + + virtual void dump() override; + +private: + bool writeScatterGather(const void *buf, size_t len); + bool readScatterGather(void *buf, size_t len); + XAxiDma_Bd *writeScatterGatherSetupBd(const void *buf, size_t len); + Completion writeCompleteScatterGather(); + XAxiDma_Bd *readScatterGatherSetupBd(void *buf, size_t len); + Completion readCompleteScatterGather(); + + bool writeSimple(const void *buf, size_t len); + bool readSimple(void *buf, size_t len); + Completion writeCompleteSimple(); + Completion readCompleteSimple(); + + void setupScatterGather(); + void setupScatterGatherRingRx(uintptr_t physAddr, uintptr_t virtAddr); + void setupScatterGatherRingTx(uintptr_t physAddr, uintptr_t virtAddr); + + static constexpr char registerMemory[] = "Reg"; + + static constexpr char mm2sInterrupt[] = "mm2s_introut"; + static constexpr char mm2sInterface[] = "M_AXI_MM2S"; + + static constexpr char s2mmInterrupt[] = "s2mm_introut"; + static constexpr char s2mmInterface[] = "M_AXI_S2MM"; + + // Optional Scatter-Gather interface to access descriptors + static constexpr char sgInterface[] = "M_AXI_SG"; + + std::list getMemoryBlocks() const override { + return {registerMemory}; + } + + XAxiDma xDma; + XAxiDma_Config xConfig; + + std::mutex hwReadLock; + std::mutex hwWriteLock; + + bool configDone = false; + // use polling to wait for DMA completion or interrupts via efds + bool polling = false; // polling mode is significantly lower latency + bool cyclic = false; // not fully implemented + // Timeout after which the DMA controller issues in interrupt if no data has been received + // Delay is 125 x x (clock period of SG clock). SG clock is 100 MHz by default. + int delay = 0; + // Coalesce is the number of messages/BDs to wait for before issuing an interrupt + uint32_t writeCoalesce = 1; + uint32_t readCoalesce = 1; + + // (maximum) size of a single message on the read channel in bytes. + // The message buffer/BD should have enough room for this many bytes. + size_t readMsgSize = 4; + + // When using SG: ringBdSize is the maximum number of BDs usable in the ring + // Depending on alignment, the actual number of BDs usable can be smaller + // We use a single BD for transfers, because this way we can achieve the best + // latency. The AXI read cache in the FPGA also only supports a single BD. + // TODO: We could make this configurable in the future. + static constexpr size_t requestedRingBdSize = 1; + static constexpr size_t requestedRingBdSizeMemory = + requestedRingBdSize * sizeof(XAxiDma_Bd); + uint32_t actualRingBdSize = 1; + std::shared_ptr sgRing; +}; + +class DmaFactory : NodeFactory { + +public: + virtual std::string getName() const override { return "dma"; } + + virtual std::string getDescription() const override { + return "Xilinx's AXI4 Direct Memory Access Controller"; + } + +private: + virtual Vlnv getCompatibleVlnv() const override { + return Vlnv("xilinx.com:ip:axi_dma:"); + } + + // Create a concrete IP instance + Core *make() const override { return new Dma; }; + +protected: + virtual void parse(Core &ip, json_t *json) override; + + virtual void configurePollingMode(Core &ip, PollingMode mode) override { + dynamic_cast(ip).polling = (mode == POLL); + } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/ips/emc.hpp b/fpga/include/villas/fpga/ips/emc.hpp new file mode 100644 index 000000000..0c93f4094 --- /dev/null +++ b/fpga/include/villas/fpga/ips/emc.hpp @@ -0,0 +1,39 @@ +/* AXI External Memory Controller (EMC) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class EMC : public Core { +public: + virtual bool init() override; + + bool flash(uint32_t offset, const std::string &filename); + bool flash(uint32_t offset, uint32_t length, uint8_t *data); + + bool read(uint32_t offset, uint32_t length, uint8_t *data); + +private: + XFlash xflash; + + static constexpr char registerMemory[] = "Reg"; + + std::list getMemoryBlocks() const { + return {registerMemory}; + } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/fifo.hpp b/fpga/include/villas/fpga/ips/fifo.hpp new file mode 100644 index 000000000..e28c0ef02 --- /dev/null +++ b/fpga/include/villas/fpga/ips/fifo.hpp @@ -0,0 +1,50 @@ +/* Timer related helper functions + * + * These functions present a simpler interface to Xilinx' Timer Counter driver (XTmrCtr_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Fifo : public Node { +public: + friend class FifoFactory; + + virtual bool init() override; + + virtual bool stop() override; + + size_t write(const void *buf, size_t len); + size_t read(void *buf, size_t len); + +private: + static constexpr char registerMemory[] = "Mem0"; + static constexpr char axi4Memory[] = "Mem1"; + static constexpr char irqName[] = "interrupt"; + + std::list getMemoryBlocks() const { + return {registerMemory, axi4Memory}; + } + + XLlFifo xFifo; +}; + +class FifoData : public Node { + friend class FifoDataFactory; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/gpio.hpp b/fpga/include/villas/fpga/ips/gpio.hpp new file mode 100644 index 000000000..c4b85b5ea --- /dev/null +++ b/fpga/include/villas/fpga/ips/gpio.hpp @@ -0,0 +1,31 @@ +/* AXI General Purpose IO (GPIO) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Gpio : public Core { +public: + virtual bool init() override; + +private: + static constexpr char registerMemory[] = "Reg"; + + std::list getMemoryBlocks() const { + return {registerMemory}; + } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/gpu2rtds.hpp b/fpga/include/villas/fpga/ips/gpu2rtds.hpp new file mode 100644 index 000000000..a278d3ff7 --- /dev/null +++ b/fpga/include/villas/fpga/ips/gpu2rtds.hpp @@ -0,0 +1,75 @@ +/* GPU2RTDS IP core + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Gpu2Rtds : public Node, public Hls { +public: + friend class Gpu2RtdsFactory; + + virtual bool init() override; + + void dump(spdlog::level::level_enum logLevel = spdlog::level::info); + bool startOnce(size_t frameSize); + + size_t getMaxFrameSize(); + + const StreamVertex &getDefaultMasterPort() const { + return getMasterPort(rtdsOutputStreamPort); + } + + MemoryBlock getRegisterMemory() const { + return MemoryBlock(0, 1 << 10, getAddressSpaceId(registerMemory)); + } + +private: + bool updateStatus(); + +public: + static constexpr const char *rtdsOutputStreamPort = "rtds_output"; + + struct StatusControlRegister { + uint32_t status_ap_vld : 1, _res : 31; + }; + + using StatusRegister = axilite_reg_status_t; + + static constexpr uintptr_t registerStatusOffset = + XGPU2RTDS_CTRL_ADDR_STATUS_DATA; + static constexpr uintptr_t registerStatusCtrlOffset = + XGPU2RTDS_CTRL_ADDR_STATUS_CTRL; + static constexpr uintptr_t registerFrameSizeOffset = + XGPU2RTDS_CTRL_ADDR_FRAME_SIZE_DATA; + static constexpr uintptr_t registerFrameOffset = + XGPU2RTDS_CTRL_ADDR_FRAME_BASE; + static constexpr uintptr_t registerFrameLength = XGPU2RTDS_CTRL_DEPTH_FRAME; + +public: + StatusRegister *registerStatus; + StatusControlRegister *registerStatusCtrl; + uint32_t *registerFrameSize; + uint32_t *registerFrames; + + size_t maxFrameSize; + + bool started; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/hls.hpp b/fpga/include/villas/fpga/ips/hls.hpp new file mode 100644 index 000000000..e62874b38 --- /dev/null +++ b/fpga/include/villas/fpga/ips/hls.hpp @@ -0,0 +1,133 @@ +/* HLS IP core + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Hls : public virtual Core { +public: + virtual bool init() override { + auto ®isters = addressTranslations.at(registerMemory); + + controlRegister = reinterpret_cast( + registers.getLocalAddr(registerControlAddr)); + globalIntRegister = reinterpret_cast( + registers.getLocalAddr(registerGlobalIntEnableAddr)); + ipIntEnableRegister = reinterpret_cast( + registers.getLocalAddr(registerIntEnableAddr)); + ipIntStatusRegister = reinterpret_cast( + registers.getLocalAddr(registerIntStatusAddr)); + + setAutoRestart(false); + setGlobalInterrupt(false); + + return true; + } + + bool start() { + controlRegister->ap_start = true; + running = true; + + return true; + } + + virtual bool isFinished() { + updateRunningStatus(); + + return !running; + } + + bool isRunning() { + updateRunningStatus(); + + return running; + } + + void setAutoRestart(bool enabled) const { + controlRegister->auto_restart = enabled; + } + + void setGlobalInterrupt(bool enabled) const { + globalIntRegister->globalInterruptEnable = enabled; + } + + void setReadyInterrupt(bool enabled) const { + ipIntEnableRegister->ap_ready = enabled; + } + + void setDoneInterrupt(bool enabled) const { + ipIntEnableRegister->ap_done = enabled; + } + + bool isIdleBit() const { return controlRegister->ap_idle; } + + bool isReadyBit() const { return controlRegister->ap_ready; } + + // Warning: the corresponding bit is cleared on read of the register, so if + // not used correctly, this function may never return true. Only use this + // function if you really know what you are doing! + bool isDoneBit() const { return controlRegister->ap_done; } + + bool isAutoRestartBit() const { return controlRegister->auto_restart; } + +private: + void updateRunningStatus() { + if (running and isIdleBit()) + running = false; + } + +protected: + // Memory block handling + + static constexpr const char *registerMemory = "Reg"; + + virtual std::list getMemoryBlocks() const { + return {registerMemory}; + } + +public: + // Register definitions + + static constexpr uintptr_t registerControlAddr = 0x00; + static constexpr uintptr_t registerGlobalIntEnableAddr = 0x04; + static constexpr uintptr_t registerIntEnableAddr = 0x08; + static constexpr uintptr_t registerIntStatusAddr = 0x0c; + + union ControlRegister { + uint32_t value; + struct { + uint32_t ap_start : 1, ap_done : 1, ap_idle : 1, ap_ready : 1, _res1 : 3, + auto_restart : 1, _res2 : 24; + }; + }; + + struct GlobalIntRegister { + uint32_t globalInterruptEnable : 1, _res : 31; + }; + + struct IpIntRegister { + uint32_t ap_done : 1, ap_ready : 1, _res : 30; + }; + +protected: + ControlRegister *controlRegister; + GlobalIntRegister *globalIntRegister; + IpIntRegister *ipIntEnableRegister; + IpIntRegister *ipIntStatusRegister; + + bool running; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/i2c.hpp b/fpga/include/villas/fpga/ips/i2c.hpp new file mode 100644 index 000000000..3c3ce2cff --- /dev/null +++ b/fpga/include/villas/fpga/ips/i2c.hpp @@ -0,0 +1,130 @@ +/* I2C driver + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +#define I2C_SWTICH_ADDR 0x70 +#define I2C_SWITCH_CHANNEL_MAP {0x20, 0x80, 0x02, 0x08, 0x10, 0x40, 0x01, 0x04} +#define I2C_IOEXT_ADDR 0x20 +#define I2C_IOEXT_REG_DIR 0x03 +#define I2C_IOEXT_REG_OUT 0x01 +#define I2C_EEPROM_ADDR 0x50 +class I2c : public Node { +public: + friend class I2cFactory; + + I2c(); + virtual ~I2c(); + virtual bool init() override; + virtual bool check() override; + virtual bool reset() override; + virtual bool stop() override; + bool write(u8 address, std::vector &data); + bool read(u8 address, std::vector &data, size_t max_read); + bool readRegister(u8 address, u8 reg, std::vector &data, size_t max_read); + + int transmitIntrs; + int receiveIntrs; + int statusIntrs; + + class Switch { + public: + Switch(I2c *i2c, uint8_t address, Logger logger = villas::Log::get("i2c")) + : i2c(i2c), address(address), channel(0), readOnce(false), switchLock(), + logger(logger) {}; + Switch(const Switch &other) = delete; + Switch &operator=(const Switch &other) = delete; + void setChannel(uint8_t channel); + void setAndLockChannel(uint8_t channel) { + switchLock.lock(); + setChannel(channel); + } + void unlockChannel() { switchLock.unlock(); } + uint8_t getChannel(); + void setAddress(uint8_t address) { this->address = address; } + uint8_t getAddress() { return address; } + bool selfTest(); + + private: + I2c *i2c; + uint8_t address; + uint8_t channel; + bool readOnce; + std::mutex switchLock; + Logger logger; + }; + Switch &getSwitch(uint8_t address = I2C_SWTICH_ADDR) { + if (switchInstance == nullptr) { + switchInstance = std::make_unique(this, address, logger); + } else { + switchInstance->setAddress(address); + } + return *switchInstance; + } + +private: + static constexpr char registerMemory[] = "Reg"; + static constexpr char i2cInterrupt[] = "iic2intc_irpt"; + + XIic xIic; + XIic_Config xConfig; + + std::mutex hwLock; + + bool configDone; + bool initDone; + bool polling; + std::unique_ptr switchInstance; + + std::list getMemoryBlocks() const { + return {registerMemory}; + } + // assumes hwLock is locked + void waitForBusNotBusy(); + void driverWriteBlocking(u8 *dataPtr, size_t size); + void driverReadBlocking(u8 *dataPtr, size_t max_read); +}; +class I2cFactory : NodeFactory { + +public: + virtual std::string getName() const { return "i2c"; } + + virtual std::string getDescription() const { return "Xilinx's AXI4 IIC IP"; } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:ip:axi_iic:"); + } + + // Create a concrete IP instance + Core *make() const { return new I2c; }; + +protected: + virtual void parse(Core &ip, json_t *json) override; + virtual void configurePollingMode(Core &ip, PollingMode mode) override { + dynamic_cast(ip).polling = (mode == POLL); + } +}; +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/ips/intc.hpp b/fpga/include/villas/fpga/ips/intc.hpp new file mode 100644 index 000000000..d558f9a82 --- /dev/null +++ b/fpga/include/villas/fpga/ips/intc.hpp @@ -0,0 +1,61 @@ +/* AXI-PCIe Interrupt controller + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class InterruptController : public Core { +public: + using IrqMaskType = uint32_t; + static constexpr int maxIrqs = 32; + + virtual ~InterruptController(); + + virtual bool init() override; + virtual bool stop() override; + + bool enableInterrupt(IrqMaskType mask, bool polling); + bool enableInterrupt(IrqPort irq, bool polling) { + return enableInterrupt(1 << irq.num, polling); + } + + bool disableInterrupt(IrqMaskType mask); + bool disableInterrupt(IrqPort irq) { return disableInterrupt(1 << irq.num); } + + ssize_t waitForInterrupt(int irq); + ssize_t waitForInterrupt(IrqPort irq) { return waitForInterrupt(irq.num); } + +private: + static constexpr char registerMemory[] = "reg0"; + + std::list getMemoryBlocks() const { + return {registerMemory}; + } + + struct Interrupt { + int eventFd; // Event file descriptor + int number; // Interrupt number from /proc/interrupts + bool polling; // Polled or not + }; + + int num_irqs; // Number of available MSI vectors + int efds[maxIrqs]; + int nos[maxIrqs]; + bool polling[maxIrqs]; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/pcie.hpp b/fpga/include/villas/fpga/ips/pcie.hpp new file mode 100644 index 000000000..85960bf8d --- /dev/null +++ b/fpga/include/villas/fpga/ips/pcie.hpp @@ -0,0 +1,87 @@ +/* AXI Stream interconnect related helper functions + * + * These functions present a simpler interface to Xilinx' AXI Stream switch driver (XAxis_Switch_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class AxiPciExpressBridge : public Core { +public: + friend class AxiPciExpressBridgeFactory; + + virtual bool init() override; + +protected: + virtual const char *getAxiInterfaceName() { return "M_AXI"; }; + static constexpr char pcieMemory[] = "BAR0"; + + struct AxiBar { + uintptr_t base; + size_t size; + uintptr_t translation; + }; + + struct PciBar { + uintptr_t translation; + }; + + std::map axiToPcieTranslations; + std::map pcieToAxiTranslations; +}; + +class XDmaBridge : public AxiPciExpressBridge { +protected: + virtual const char *getAxiInterfaceName() { return "M_AXI_B"; }; +}; + +class AxiPciExpressBridgeFactory : CoreFactory { + +public: + virtual std::string getName() const { return "pcie"; } + + virtual std::string getDescription() const { + return "Xilinx's AXI-PCIe Bridge"; + } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:ip:axi_pcie:"); + } + + // Create a concrete IP instance + Core *make() const { return new AxiPciExpressBridge; }; + +protected: + virtual void parse(Core &, json_t *) override; +}; + +class XDmaBridgeFactory : public AxiPciExpressBridgeFactory { + +public: + virtual std::string getDescription() const { + return "Xilinx's XDMA IP configured as AXI-PCIe Bridge"; + } + +private: + virtual Vlnv getCompatibleVlnv() const { return Vlnv("xilinx.com:ip:xdma:"); } + + // Create a concrete IP instance + Core *make() const { return new XDmaBridge; }; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/register.hpp b/fpga/include/villas/fpga/ips/register.hpp new file mode 100644 index 000000000..3ab67bc3e --- /dev/null +++ b/fpga/include/villas/fpga/ips/register.hpp @@ -0,0 +1,46 @@ +/* Driver for register interface 'registerif' + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2024 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Register : public Node { +public: + Register(); + virtual ~Register(); + virtual bool init() override; + virtual bool check() override; + void setRegister(size_t reg, uint32_t value); + void setRegister(size_t reg, float value); + uint32_t getRegister(size_t reg); + float getRegisterFloat(size_t reg); + void resetRegister(size_t reg); + void resetAllRegisters(); + +protected: + const size_t registerNum = 8; + const size_t registerSize = 32; + static constexpr char registerMemory[] = "reg0"; + std::list getMemoryBlocks() const override { + return {registerMemory}; + } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/ips/rtds.hpp b/fpga/include/villas/fpga/ips/rtds.hpp new file mode 100644 index 000000000..5168c0025 --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds.hpp @@ -0,0 +1,50 @@ +/* Driver for AXI Stream wrapper around RTDS_InterfaceModule (rtds_axis ) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class RtdsGtfpga : public Node { +public: + static constexpr const char *masterPort = "m_axis"; + static constexpr const char *slavePort = "s_axis"; + + virtual void dump() override; + + double getDt(); + + std::list getMemoryBlocks() const { return {registerMemory}; } + + const StreamVertex &getDefaultSlavePort() const { + return getSlavePort(slavePort); + } + + const StreamVertex &getDefaultMasterPort() const { + return getMasterPort(masterPort); + } + +private: + static constexpr const char registerMemory[] = "reg0"; + static constexpr const char *irqTs = "irq_ts"; + static constexpr const char *irqOverflow = "irq_overflow"; + static constexpr const char *irqCase = "irq_case"; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/ips/rtds2gpu.hpp b/fpga/include/villas/fpga/ips/rtds2gpu.hpp new file mode 100644 index 000000000..508be3b7f --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds2gpu.hpp @@ -0,0 +1,77 @@ +/* GPU2RTDS IP core + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include "rtds2gpu/register_types.hpp" +#include "rtds2gpu/xrtds2gpu.h" + +namespace villas { +namespace fpga { +namespace ip { + +union ControlRegister { + uint32_t value; + struct { + uint32_t ap_start : 1, ap_done : 1, ap_idle : 1, ap_ready : 1, _res1 : 3, + auto_restart : 1, _res2 : 24; + }; +}; + +class Rtds2Gpu : public Node, public Hls { +public: + friend class Rtds2GpuFactory; + + virtual bool init() override; + + void dump(spdlog::level::level_enum logLevel = spdlog::level::info); + + virtual void dump() override { dump(spdlog::level::info); } + + bool startOnce(const MemoryBlock &mem, size_t frameSize, size_t dataOffset, + size_t doorbellOffset); + + size_t getMaxFrameSize(); + + void dumpDoorbell(uint32_t doorbellRegister) const; + + bool doorbellIsValid(const uint32_t &doorbellRegister) const { + return reinterpret_cast(doorbellRegister).is_valid; + } + + void doorbellReset(uint32_t &doorbellRegister) const { doorbellRegister = 0; } + + std::list getMemoryBlocks() const { + return {registerMemory}; + } + + const StreamVertex &getDefaultSlavePort() const { + return getSlavePort(rtdsInputStreamPort); + } + +private: + bool updateStatus(); + +private: + static constexpr const char *axiInterface = "m_axi_axi_mm"; + static constexpr const char *rtdsInputStreamPort = "rtds_input"; + + XRtds2gpu xInstance; + + axilite_reg_status_t status; + size_t maxFrameSize; + + bool started; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/rtds2gpu/register_types.hpp b/fpga/include/villas/fpga/ips/rtds2gpu/register_types.hpp new file mode 100644 index 000000000..b19fbbb94 --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds2gpu/register_types.hpp @@ -0,0 +1,53 @@ +/* GPU2RTDS register types + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +union axilite_reg_status_t { + uint32_t value; + struct { + uint32_t last_seq_nr : 16, last_count : 6, max_frame_size : 6, + invalid_frame_size : 1, frame_too_short : 1, frame_too_long : 1, + is_running : 1; + }; +}; + +union reg_doorbell_t { + uint32_t value; + struct { + uint32_t seq_nr : 16, count : 6, is_valid : 1; + }; + + constexpr reg_doorbell_t() : value(0) {} +}; + +template struct Rtds2GpuMemoryBuffer { + // This type is only for memory interpretation, it makes no sense to create + // an instance so it's forbidden + Rtds2GpuMemoryBuffer() = delete; + + // T can be a more complex type that wraps multiple values + static constexpr size_t rawValueCount = N * (sizeof(T) / 4); + + // As of C++14, offsetof() is not working for non-standard layout types (i.e. + // composed of non-POD members). This might work in C++17 though. + // More info: https://gist.github.com/graphitemaster/494f21190bb2c63c5516 + //static constexpr size_t doorbellOffset = offsetof(Rtds2GpuMemoryBuffer, doorbell); + //static constexpr size_t dataOffset = offsetof(Rtds2GpuMemoryBuffer, data); + + // HACK: This might break horribly, let's just hope C++17 will be there soon + static constexpr size_t dataOffset = 0; + static constexpr size_t doorbellOffset = + N * sizeof(Rtds2GpuMemoryBuffer::data); + + T data[N]; + reg_doorbell_t doorbell; +}; diff --git a/fpga/include/villas/fpga/ips/rtds2gpu/xgpu2rtds_hw.h b/fpga/include/villas/fpga/ips/rtds2gpu/xgpu2rtds_hw.h new file mode 100644 index 000000000..68e7eeceb --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds2gpu/xgpu2rtds_hw.h @@ -0,0 +1,52 @@ +// ============================================================== +// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC +// Version: 2017.3 +// SPDX-FileCopyrightText: 1986 Xilinx, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +// ============================================================== + +// CTRL +// 0x00 : Control signals +// bit 0 - ap_start (Read/Write/COH) +// bit 1 - ap_done (Read/COR) +// bit 2 - ap_idle (Read) +// bit 3 - ap_ready (Read) +// bit 7 - auto_restart (Read/Write) +// others - reserved +// 0x04 : Global Interrupt Enable Register +// bit 0 - Global Interrupt Enable (Read/Write) +// others - reserved +// 0x08 : IP Interrupt Enable Register (Read/Write) +// bit 0 - Channel 0 (ap_done) +// bit 1 - Channel 1 (ap_ready) +// others - reserved +// 0x0c : IP Interrupt Status Register (Read/TOW) +// bit 0 - Channel 0 (ap_done) +// bit 1 - Channel 1 (ap_ready) +// others - reserved +// 0x10 : Data signal of frame_size +// bit 31~0 - frame_size[31:0] (Read/Write) +// 0x14 : reserved +// 0x80 : Data signal of status +// bit 31~0 - status[31:0] (Read) +// 0x84 : Control signal of status +// bit 0 - status_ap_vld (Read/COR) +// others - reserved +// 0x40 ~ +// 0x7f : Memory 'frame' (16 * 32b) +// Word n : bit [31:0] - frame[n] +// (SC = Self Clear, COR = Clear on Read, TOW = Toggle on Write, COH = Clear on Handshake) + +#define XGPU2RTDS_CTRL_ADDR_AP_CTRL 0x00 +#define XGPU2RTDS_CTRL_ADDR_GIE 0x04 +#define XGPU2RTDS_CTRL_ADDR_IER 0x08 +#define XGPU2RTDS_CTRL_ADDR_ISR 0x0c +#define XGPU2RTDS_CTRL_ADDR_FRAME_SIZE_DATA 0x10 +#define XGPU2RTDS_CTRL_BITS_FRAME_SIZE_DATA 32 +#define XGPU2RTDS_CTRL_ADDR_STATUS_DATA 0x80 +#define XGPU2RTDS_CTRL_BITS_STATUS_DATA 32 +#define XGPU2RTDS_CTRL_ADDR_STATUS_CTRL 0x84 +#define XGPU2RTDS_CTRL_ADDR_FRAME_BASE 0x40 +#define XGPU2RTDS_CTRL_ADDR_FRAME_HIGH 0x7f +#define XGPU2RTDS_CTRL_WIDTH_FRAME 32 +#define XGPU2RTDS_CTRL_DEPTH_FRAME 16 diff --git a/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu.h b/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu.h new file mode 100644 index 000000000..d1de5c0eb --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu.h @@ -0,0 +1,114 @@ +// ============================================================== +// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC +// Version: 2017.3 +// SPDX-FileCopyrightText: 1986 Xilinx, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +// ============================================================== + +#ifndef XRTDS2GPU_H +#define XRTDS2GPU_H + +#ifdef __cplusplus +extern "C" { +#endif + +/***************************** Include Files *********************************/ +#ifndef __linux__ +#include "xil_assert.h" +#include "xil_io.h" +#include "xil_types.h" +#include "xstatus.h" +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#include "xrtds2gpu_hw.h" + +/**************************** Type Definitions ******************************/ +#ifdef __linux__ +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +#else +typedef struct { + u16 DeviceId; + u32 Ctrl_BaseAddress; +} XRtds2gpu_Config; +#endif + +typedef struct { + u32 Ctrl_BaseAddress; + u32 IsReady; +} XRtds2gpu; + +/***************** Macros (Inline Functions) Definitions *********************/ +#ifndef __linux__ +#define XRtds2gpu_WriteReg(BaseAddress, RegOffset, Data) \ + Xil_Out32((BaseAddress) + (RegOffset), (u32)(Data)) +#define XRtds2gpu_ReadReg(BaseAddress, RegOffset) \ + Xil_In32((BaseAddress) + (RegOffset)) +#else +#define XRtds2gpu_WriteReg(BaseAddress, RegOffset, Data) \ + *(volatile u32 *)((BaseAddress) + (RegOffset)) = (u32)(Data) +#define XRtds2gpu_ReadReg(BaseAddress, RegOffset) \ + *(volatile u32 *)((BaseAddress) + (RegOffset)) + +#define Xil_AssertVoid(expr) assert(expr) +#define Xil_AssertNonvoid(expr) assert(expr) + +#define XST_SUCCESS 0 +#define XST_DEVICE_NOT_FOUND 2 +#define XST_OPEN_DEVICE_FAILED 3 +#define XIL_COMPONENT_IS_READY 1 +#endif + +/************************** Function Prototypes *****************************/ +#ifndef __linux__ +int XRtds2gpu_Initialize(XRtds2gpu *InstancePtr, u16 DeviceId); +XRtds2gpu_Config *XRtds2gpu_LookupConfig(u16 DeviceId); +int XRtds2gpu_CfgInitialize(XRtds2gpu *InstancePtr, + XRtds2gpu_Config *ConfigPtr); +#else +int XRtds2gpu_Initialize(XRtds2gpu *InstancePtr, const char *InstanceName); +int XRtds2gpu_Release(XRtds2gpu *InstancePtr); +#endif + +void XRtds2gpu_Start(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_IsDone(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_IsIdle(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_IsReady(XRtds2gpu *InstancePtr); +void XRtds2gpu_EnableAutoRestart(XRtds2gpu *InstancePtr); +void XRtds2gpu_DisableAutoRestart(XRtds2gpu *InstancePtr); + +void XRtds2gpu_Set_baseaddr(XRtds2gpu *InstancePtr, u32 Data); +u32 XRtds2gpu_Get_baseaddr(XRtds2gpu *InstancePtr); +void XRtds2gpu_Set_data_offset(XRtds2gpu *InstancePtr, u32 Data); +u32 XRtds2gpu_Get_data_offset(XRtds2gpu *InstancePtr); +void XRtds2gpu_Set_doorbell_offset(XRtds2gpu *InstancePtr, u32 Data); +u32 XRtds2gpu_Get_doorbell_offset(XRtds2gpu *InstancePtr); +void XRtds2gpu_Set_frame_size(XRtds2gpu *InstancePtr, u32 Data); +u32 XRtds2gpu_Get_frame_size(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_Get_status(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_Get_status_vld(XRtds2gpu *InstancePtr); + +void XRtds2gpu_InterruptGlobalEnable(XRtds2gpu *InstancePtr); +void XRtds2gpu_InterruptGlobalDisable(XRtds2gpu *InstancePtr); +void XRtds2gpu_InterruptEnable(XRtds2gpu *InstancePtr, u32 Mask); +void XRtds2gpu_InterruptDisable(XRtds2gpu *InstancePtr, u32 Mask); +void XRtds2gpu_InterruptClear(XRtds2gpu *InstancePtr, u32 Mask); +u32 XRtds2gpu_InterruptGetEnabled(XRtds2gpu *InstancePtr); +u32 XRtds2gpu_InterruptGetStatus(XRtds2gpu *InstancePtr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu_hw.h b/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu_hw.h new file mode 100644 index 000000000..c68967821 --- /dev/null +++ b/fpga/include/villas/fpga/ips/rtds2gpu/xrtds2gpu_hw.h @@ -0,0 +1,60 @@ +// ============================================================== +// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC +// Version: 2017.3 +// SPDX-FileCopyrightText: 1986 Xilinx, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +// ============================================================== + +// CTRL +// 0x00 : Control signals +// bit 0 - ap_start (Read/Write/COH) +// bit 1 - ap_done (Read/COR) +// bit 2 - ap_idle (Read) +// bit 3 - ap_ready (Read) +// bit 7 - auto_restart (Read/Write) +// others - reserved +// 0x04 : Global Interrupt Enable Register +// bit 0 - Global Interrupt Enable (Read/Write) +// others - reserved +// 0x08 : IP Interrupt Enable Register (Read/Write) +// bit 0 - Channel 0 (ap_done) +// bit 1 - Channel 1 (ap_ready) +// others - reserved +// 0x0c : IP Interrupt Status Register (Read/TOW) +// bit 0 - Channel 0 (ap_done) +// bit 1 - Channel 1 (ap_ready) +// others - reserved +// 0x10 : Data signal of baseaddr +// bit 31~0 - baseaddr[31:0] (Read/Write) +// 0x14 : reserved +// 0x18 : Data signal of data_offset +// bit 31~0 - data_offset[31:0] (Read/Write) +// 0x1c : reserved +// 0x20 : Data signal of doorbell_offset +// bit 31~0 - doorbell_offset[31:0] (Read/Write) +// 0x24 : reserved +// 0x28 : Data signal of frame_size +// bit 31~0 - frame_size[31:0] (Read/Write) +// 0x2c : reserved +// 0x30 : Data signal of status +// bit 31~0 - status[31:0] (Read) +// 0x34 : Control signal of status +// bit 0 - status_ap_vld (Read/COR) +// others - reserved +// (SC = Self Clear, COR = Clear on Read, TOW = Toggle on Write, COH = Clear on Handshake) + +#define XRTDS2GPU_CTRL_ADDR_AP_CTRL 0x00 +#define XRTDS2GPU_CTRL_ADDR_GIE 0x04 +#define XRTDS2GPU_CTRL_ADDR_IER 0x08 +#define XRTDS2GPU_CTRL_ADDR_ISR 0x0c +#define XRTDS2GPU_CTRL_ADDR_BASEADDR_DATA 0x10 +#define XRTDS2GPU_CTRL_BITS_BASEADDR_DATA 32 +#define XRTDS2GPU_CTRL_ADDR_DATA_OFFSET_DATA 0x18 +#define XRTDS2GPU_CTRL_BITS_DATA_OFFSET_DATA 32 +#define XRTDS2GPU_CTRL_ADDR_DOORBELL_OFFSET_DATA 0x20 +#define XRTDS2GPU_CTRL_BITS_DOORBELL_OFFSET_DATA 32 +#define XRTDS2GPU_CTRL_ADDR_FRAME_SIZE_DATA 0x28 +#define XRTDS2GPU_CTRL_BITS_FRAME_SIZE_DATA 32 +#define XRTDS2GPU_CTRL_ADDR_STATUS_DATA 0x30 +#define XRTDS2GPU_CTRL_BITS_STATUS_DATA 32 +#define XRTDS2GPU_CTRL_ADDR_STATUS_CTRL 0x34 diff --git a/fpga/include/villas/fpga/ips/switch.hpp b/fpga/include/villas/fpga/ips/switch.hpp new file mode 100644 index 000000000..c55a4af56 --- /dev/null +++ b/fpga/include/villas/fpga/ips/switch.hpp @@ -0,0 +1,74 @@ +/* AXI Stream interconnect related helper functions + * + * These functions present a simpler interface to Xilinx' AXI Stream switch driver (XAxis_Switch_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +#include + +namespace villas { +namespace fpga { +namespace ip { + +class AxiStreamSwitch : public Node { +public: + friend class AxiStreamSwitchFactory; + + virtual bool init() override; + + bool connectInternal(const std::string &slavePort, + const std::string &masterPort); + + void printConfig() const; + +private: + int portNameToNum(const std::string &portName); + + static constexpr const char *PORT_DISABLED = "DISABLED"; + + static constexpr char registerMemory[] = "Reg"; + + std::list getMemoryBlocks() const { + return {registerMemory}; + } + + XAxis_Switch xSwitch; + XAxis_Switch_Config xConfig; + + std::map portMapping; +}; + +class AxiStreamSwitchFactory : NodeFactory { + +public: + virtual std::string getName() const { return "switch"; } + + virtual std::string getDescription() const { + return "Xilinx's AXI4-Stream switch"; + } + +private: + virtual Vlnv getCompatibleVlnv() const { + return Vlnv("xilinx.com:ip:axis_switch:"); + } + + // Create a concrete IP instance + Core *make() const { return new AxiStreamSwitch; }; + +protected: + virtual void parse(Core &, json_t *) override; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/ips/timer.hpp b/fpga/include/villas/fpga/ips/timer.hpp new file mode 100644 index 000000000..ae81eeabf --- /dev/null +++ b/fpga/include/villas/fpga/ips/timer.hpp @@ -0,0 +1,52 @@ +/* Timer related helper functions + * + * These functions present a simpler interface to Xilinx' Timer Counter driver (XTmrCtr_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include + +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class Timer : public Core { + friend class TimerFactory; + +public: + virtual bool init() override; + + bool start(uint32_t ticks); + bool wait(); + uint32_t remaining(); + + inline bool isRunning() { return remaining() != 0; } + + inline bool isFinished() { return remaining() == 0; } + + static constexpr uint32_t getFrequency() { return FPGA_AXI_HZ; } + +private: + std::list getMemoryBlocks() const { + return {registerMemory}; + } + + static constexpr char irqName[] = "generateout0"; + static constexpr char registerMemory[] = "Reg"; + + XTmrCtr xTmr; +}; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/node.hpp b/fpga/include/villas/fpga/node.hpp new file mode 100644 index 000000000..8bc420752 --- /dev/null +++ b/fpga/include/villas/fpga/node.hpp @@ -0,0 +1,168 @@ +/* Interlectual Property component. + * + * This class represents a module within the FPGA. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +class StreamVertex : public graph::Vertex { +public: + StreamVertex(const std::string &node, const std::string &port, bool isMaster) + : graph::Vertex(), nodeName(node), portName(port), isMaster(isMaster) {} + + std::string getName() const { + return nodeName + "/" + portName + "(" + (isMaster ? "M" : "S") + ")"; + } + + friend std::ostream &operator<<(std::ostream &stream, + const StreamVertex &vertex) { + return stream << vertex.getIdentifier() << ": " << vertex.getName(); + } + +public: + std::string nodeName; + std::string portName; + bool isMaster; +}; + +class StreamGraph : public graph::DirectedGraph { +public: + StreamGraph() : graph::DirectedGraph("stream:graph") {} + + std::shared_ptr getOrCreateStreamVertex(const std::string &node, + const std::string &port, + bool isMaster) { + for (auto &vertexEntry : vertices) { + auto &vertex = vertexEntry.second; + if (vertex->nodeName == node and vertex->portName == port and + vertex->isMaster == isMaster) + return vertex; + } + + // Vertex not found, create new one + auto vertex = std::make_shared(node, port, isMaster); + addVertex(vertex); + + return vertex; + } +}; + +class Node : public virtual Core { +public: + using Ptr = std::shared_ptr; + + friend class NodeFactory; + + const StreamVertex &getMasterPort(const std::string &name) const { + return *portsMaster.at(name); + } + + const std::map> & + getMasterPorts() const { + return portsMaster; + } + + const StreamVertex &getSlavePort(const std::string &name) const { + return *portsSlave.at(name); + } + + const std::map> & + getSlavePorts() const { + return portsSlave; + } + + bool connect(const StreamVertex &from, const StreamVertex &to); + bool connect(const StreamVertex &from, const StreamVertex &to, bool reverse) { + bool ret; + + ret = connect(from, to); + + if (reverse) + ret &= connect(to, from); + + return ret; + } + + // Easy-usage assuming that the slave IP to connect to only has one slave + // port and implements the getDefaultSlavePort() function + bool connect(const Node &slaveNode, bool reverse = false) { + return this->connect(this->getDefaultMasterPort(), + slaveNode.getDefaultSlavePort(), reverse); + } + + // Used by easy-usage connect, will throw if not implemented by derived node + virtual const StreamVertex &getDefaultSlavePort() const; + + // Used by easy-usage connect, will throw if not implemented by derived node + virtual const StreamVertex &getDefaultMasterPort() const; + + static const StreamGraph &getGraph() { return streamGraph; } + + bool loopbackPossible() const; + bool connectLoopback(); + +protected: + virtual bool connectInternal(const std::string &slavePort, + const std::string &masterPort); + +private: + std::pair getLoopbackPorts() const; + +protected: + std::map> portsMaster; + std::map> portsSlave; + + static StreamGraph streamGraph; +}; + +class NodeFactory : public CoreFactory { +public: + using CoreFactory::CoreFactory; + + virtual void parse(Core &, json_t *); +}; + +template +class NodePlugin : public NodeFactory { + +public: + virtual std::string getName() const { return name; } + + virtual std::string getDescription() const { return desc; } + +private: + // Get a VLNV identifier for which this IP / Node type can be used. + virtual Vlnv getCompatibleVlnv() const { return Vlnv(vlnv); } + + // Create a concrete IP instance + Core *make() const { return new T; } +}; + +} // namespace ip +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp new file mode 100644 index 000000000..aff1b23fb --- /dev/null +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -0,0 +1,87 @@ +/* FPGA pciecard + * + * This class represents a FPGA device. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +namespace villas { +namespace fpga { + +// Forward declarations +struct vfio_container; +class PCIeCardFactory; + +class PCIeCard : public Card { +public: + ~PCIeCard(); + + bool init(); + + bool stop() { return true; } + + bool check() { return true; } + + bool reset() { + // TODO: Try via sysfs? + // echo 1 > /sys/bus/pci/devices/0000\:88\:00.0/reset + return true; + } + + void dump() {} + +public: // TODO: make this private + bool doReset; // Reset VILLASfpga during startup? + int affinity; // Affinity for MSI interrupts + + std::shared_ptr pdev; // PCI device handle + +protected: + Logger getLogger() const { return villas::Log::get(name); } +}; + +class PCIeCardFactory : public plugin::Plugin { +public: + static std::shared_ptr + make(json_t *json, std::string card_name, + std::shared_ptr vc, + const std::filesystem::path &searchPath); + + static PCIeCard *make() { return new PCIeCard(); } + + static Logger getStaticLogger() { + return villas::Log::get("pcie:card:factory"); + } + + virtual std::string getName() const { return "pcie"; } + + virtual std::string getDescription() const { + return "Xilinx PCIe FPGA cards"; + } + + virtual std::string getType() const { return "card"; } +}; + +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/utils.hpp b/fpga/include/villas/fpga/utils.hpp new file mode 100644 index 000000000..b078936fb --- /dev/null +++ b/fpga/include/villas/fpga/utils.hpp @@ -0,0 +1,142 @@ +/* Helper function for directly using VILLASfpga outside of VILLASnode + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +namespace villas { +namespace fpga { + +std::shared_ptr setupFpgaCard(const std::string &configFile, + const std::string &fpgaName); + +std::shared_ptr +createCard(json_t *config, const std::filesystem::path &searchPath, + std::shared_ptr vfioContainer, + std::string card_name = "anonymous Card"); + +int createCards( + json_t *config, std::list> &cards, + const std::filesystem::path &searchPath, + std::shared_ptr vfioContainer = nullptr); +int createCards( + json_t *config, std::list> &cards, + const std::string &searchPath, + std::shared_ptr vfioContainer = nullptr); + +std::shared_ptr>> +getAuroraChannels(std::shared_ptr card); + +void setupColorHandling(); + +class ConnectString { +public: + enum class ConnectType { AURORA, DMA, DINO, LOOPBACK }; + ConnectString(std::string &connectString, int maxPortNum = 7); + void parseString(std::string &connectString); + int portStringToInt(std::string &str) const; + void configCrossBar(std::shared_ptr card) const; + bool isBidirectional() const { return bidirectional; }; + bool isDmaLoopback() const { return srcType == ConnectType::LOOPBACK; }; + bool isSrcStdin() const { return srcType == ConnectType::DMA; }; + bool isDstStdout() const { return dstType == ConnectType::DMA; }; + int getSrcAsInt() const { return srcAsInt; }; + int getDstAsInt() const { return dstAsInt; }; + static std::string connectTypeToString(ConnectType type) { + static const std::string connectTypeStrings[] = {"aurora", "dma", "dino", + "loopback"}; + return connectTypeStrings[(int)type]; + } + +protected: + villas::Logger log; + int maxPortNum; + bool bidirectional; + bool invert; + ConnectType srcType; + ConnectType dstType; + int srcAsInt; + int dstAsInt; +}; + +class BufferedSampleFormatter { +public: + virtual void format(float value) = 0; + virtual void output(std::ostream &out) { + out << buf.data() << std::flush; + clearBuf(); + } + virtual void clearBuf() { + for (size_t i = 0; i < bufSamples && buf[i * bufSampleSize] != '\0'; i++) { + buf[i * bufSampleSize] = '\0'; + } + currentBufLoc = 0; + } + +protected: + std::vector buf; + const size_t bufSamples; + const size_t bufSampleSize; + size_t currentBufLoc; + + BufferedSampleFormatter(const size_t bufSamples, const size_t bufSampleSize) + : buf(bufSamples * bufSampleSize + 1), // Leave room for a final `\0' + bufSamples(bufSamples), bufSampleSize(bufSampleSize), + currentBufLoc(0) {}; + BufferedSampleFormatter() = delete; + BufferedSampleFormatter(const BufferedSampleFormatter &) = delete; + virtual char *nextBufPos() { return &buf[(currentBufLoc++) * bufSampleSize]; } +}; + +class BufferedSampleFormatterShort : public BufferedSampleFormatter { +public: + BufferedSampleFormatterShort(size_t bufSizeInSamples) + : BufferedSampleFormatter(bufSizeInSamples, formatStringSize) {}; + + virtual void format(float value) override { + size_t chars; + if ((chars = std::snprintf(nextBufPos(), formatStringSize + 1, formatString, + value)) > (int)formatStringSize) { + throw RuntimeError("Output buffer too small. Expected " + + std::to_string(formatStringSize) + + " characters, got " + std::to_string(chars)); + } + } + +protected: + static constexpr char formatString[] = "%013.6f\n"; + static constexpr size_t formatStringSize = 14; +}; + +class BufferedSampleFormatterLong : public BufferedSampleFormatter { +public: + BufferedSampleFormatterLong(size_t bufSizeInSamples) + : BufferedSampleFormatter(bufSizeInSamples, formatStringSize), + sampleCnt(0) {}; + + virtual void format(float value) override { + if (std::snprintf(nextBufPos(), formatStringSize + 1, formatString, + sampleCnt, value) > (int)formatStringSize) { + throw RuntimeError("Output buffer too small"); + } + sampleCnt = (sampleCnt + 1) % 100000; + } + +protected: + static constexpr char formatString[] = "%05zd: %013.6f\n"; + static constexpr size_t formatStringSize = 22; + size_t sampleCnt; +}; + +std::unique_ptr +getBufferedSampleFormatter(const std::string &format, size_t bufSizeInSamples); + +} // namespace fpga +} // namespace villas diff --git a/fpga/include/villas/fpga/vlnv.hpp b/fpga/include/villas/fpga/vlnv.hpp new file mode 100644 index 000000000..693903cad --- /dev/null +++ b/fpga/include/villas/fpga/vlnv.hpp @@ -0,0 +1,57 @@ +/* Vendor, Library, Name, Version (VLNV) tag. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace villas { +namespace fpga { + +class Vlnv { +public: + static constexpr char delimiter = ':'; + + Vlnv() : vendor(""), library(""), name(""), version("") {} + + Vlnv(const std::string &s) { parseFromString(s); } + + static Vlnv getWildcard() { return Vlnv(); } + + std::string toString() const; + + bool operator==(const Vlnv &other) const; + + bool operator!=(const Vlnv &other) const { return !(*this == other); } + + friend std::ostream &operator<<(std::ostream &stream, const Vlnv &vlnv) { + return stream << (vlnv.vendor.empty() ? "*" : vlnv.vendor) << ":" + << (vlnv.library.empty() ? "*" : vlnv.library) << ":" + << (vlnv.name.empty() ? "*" : vlnv.name) << ":" + << (vlnv.version.empty() ? "*" : vlnv.version); + } + +private: + void parseFromString(std::string vlnv); + + std::string vendor; + std::string library; + std::string name; + std::string version; +}; + +} // namespace fpga +} // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/fpga/lib/CMakeLists.txt b/fpga/lib/CMakeLists.txt new file mode 100644 index 000000000..bc7fd9208 --- /dev/null +++ b/fpga/lib/CMakeLists.txt @@ -0,0 +1,78 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +set(SOURCES + vlnv.cpp + card.cpp + pcie_card.cpp + core.cpp + node.cpp + utils.cpp + dma.cpp + + ips/aurora_xilinx.cpp + ips/aurora.cpp + ips/bram.cpp + ips/dino.cpp + ips/dma.cpp + ips/emc.cpp + ips/fifo.cpp + ips/gpio.cpp + ips/intc.cpp + ips/pcie.cpp + ips/rtds.cpp + ips/switch.cpp + ips/timer.cpp + ips/i2c.cpp + ips/register.cpp + + ips/rtds2gpu/rtds2gpu.cpp + ips/rtds2gpu/xrtds2gpu.c + ips/rtds2gpu/gpu2rtds.cpp +) + +# we don't have much influence on drivers generated by Xilinx, so ignore warnings +set_source_files_properties(ips/rtds2gpu/xrtds2gpu.c + PROPERTIES COMPILE_FLAGS -Wno-int-to-pointer-cast) + +add_library(villas-fpga SHARED ${SOURCES}) + +target_link_libraries(villas-fpga PUBLIC villas-common) + +target_compile_definitions(villas-fpga PRIVATE + BUILDID=\"abc\" + _GNU_SOURCE +) + +target_include_directories(villas-fpga + PUBLIC + ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/fpga/include + ${JANSSON_INCLUDE_DIRS} +) + +target_link_libraries(villas-fpga PUBLIC + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} + m + xil + villas-common + "$<$,$,9.0>>:stdc++fs>" +) + +if(CMAKE_CUDA_COMPILER) + target_link_libraries(villas-fpga PUBLIC villas-gpu) +endif() + +include(GNUInstallDirs) + +install(TARGETS villas-fpga + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static +) + +install(DIRECTORY ../include/villas DESTINATION include) diff --git a/fpga/lib/card.cpp b/fpga/lib/card.cpp new file mode 100644 index 000000000..1048b41b4 --- /dev/null +++ b/fpga/lib/card.cpp @@ -0,0 +1,127 @@ +/* FPGA card + * + * This class represents a FPGA device. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +using namespace villas; +using namespace villas::fpga; + +Card::~Card() { + for (auto ip = ips.rbegin(); ip != ips.rend(); ++ip) { + (*ip)->stop(); + } + // Ensure IP destructors are called before memory is unmapped + ips.clear(); + + auto &mm = MemoryManager::get(); + + // Unmap all memory blocks + for (auto &mappedMemoryBlock : memoryBlocksMapped) { + auto translation = + mm.getTranslation(addrSpaceIdDeviceToHost, mappedMemoryBlock.first); + + const uintptr_t iova = translation.getLocalAddr(0); + const size_t size = translation.getSize(); + + logger->debug("Unmap block {} at IOVA {:#x} of size {:#x}", + mappedMemoryBlock.first, iova, size); + vfioContainer->memoryUnmap(iova, size); + } +} + +std::shared_ptr Card::lookupIp(const std::string &name) const { + for (auto &ip : ips) { + if (*ip == name) { + return ip; + } + } + + return nullptr; +} + +std::shared_ptr Card::lookupIp(const Vlnv &vlnv) const { + for (auto &ip : ips) { + if (*ip == vlnv) { + return ip; + } + } + + return nullptr; +} + +std::shared_ptr Card::lookupIp(const ip::IpIdentifier &id) const { + for (auto &ip : ips) { + if (*ip == id) { + return ip; + } + } + + return nullptr; +} + +bool Card::unmapMemoryBlock(const MemoryBlock &block) { + if (memoryBlocksMapped.find(block.getAddrSpaceId()) == + memoryBlocksMapped.end()) { + throw std::runtime_error( + "Block " + std::to_string(block.getAddrSpaceId()) + + " is not mapped but was requested to be unmapped."); + } + + auto &mm = MemoryManager::get(); + + auto translation = + mm.getTranslation(addrSpaceIdDeviceToHost, block.getAddrSpaceId()); + + const uintptr_t iova = translation.getLocalAddr(0); + const size_t size = translation.getSize(); + + logger->debug("Unmap block {} at IOVA {:#x} of size {:#x}", + block.getAddrSpaceId(), iova, size); + vfioContainer->memoryUnmap(iova, size); + + memoryBlocksMapped.erase(block.getAddrSpaceId()); + + return true; +} + +bool Card::mapMemoryBlock(const std::shared_ptr block) { + if (not vfioContainer->isIommuEnabled()) { + logger->warn("VFIO mapping not supported without IOMMU"); + return false; + } + + auto &mm = MemoryManager::get(); + const auto &addrSpaceId = block->getAddrSpaceId(); + + if (memoryBlocksMapped.find(addrSpaceId) != memoryBlocksMapped.end()) + // Block already mapped + return true; + else + logger->debug("Create VFIO mapping for {}", addrSpaceId); + + auto translationFromProcess = mm.getTranslationFromProcess(addrSpaceId); + uintptr_t processBaseAddr = translationFromProcess.getLocalAddr(0); + uintptr_t iovaAddr = + vfioContainer->memoryMap(processBaseAddr, UINTPTR_MAX, block->getSize()); + + if (iovaAddr == UINTPTR_MAX) { + logger->error("Cannot map memory at {:#x} of size {:#x}", processBaseAddr, + block->getSize()); + return false; + } + + mm.createMapping(iovaAddr, 0, block->getSize(), "VFIO-D2H", + this->addrSpaceIdDeviceToHost, addrSpaceId); + + // Remember that this block has already been mapped for later + memoryBlocksMapped.insert({addrSpaceId, block}); + + return true; +} diff --git a/fpga/lib/core.cpp b/fpga/lib/core.cpp new file mode 100644 index 000000000..0a1f8de1f --- /dev/null +++ b/fpga/lib/core.cpp @@ -0,0 +1,365 @@ +/* FPGA IP component. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +using namespace villas::fpga; +using namespace villas::fpga::ip; + +// Special IPs that have to be initialized first. Will be initialized in the +// same order as they appear in this list, i.e. first here will be initialized +// first. +static std::list vlnvInitializationOrder = { + Vlnv("xilinx.com:ip:axi_pcie:"), + Vlnv("xilinx.com:ip:xdma:"), + Vlnv("xilinx.com:module_ref:axi_pcie_intc:"), + Vlnv("xilinx.com:ip:axis_switch:"), + Vlnv("xilinx.com:ip:axi_iic:"), +}; + +std::list CoreFactory::parseIpIdentifier(json_t *json_ips) { + // Parse all IP instance names and their VLNV into list `allIps` + std::list allIps; + + const char *ipName; + json_t *json_ip; + json_object_foreach(json_ips, ipName, json_ip) { + const char *vlnv; + + json_error_t err; + int ret = json_unpack_ex(json_ip, &err, 0, "{ s: s }", "vlnv", &vlnv); + if (ret != 0) + throw ConfigError(json_ip, err, "", "IP {} has no VLNV", ipName); + + allIps.push_back({vlnv, ipName}); + } + return allIps; +} + +std::list +CoreFactory::reorderIps(std::list allIps) { + // Pick out IPs to be initialized first. + std::list orderedIps; + + // Reverse walktrough, because we push to the + // front of the output list, so that the first element will also be the + // first to be initialized. + for (auto viIt = vlnvInitializationOrder.rbegin(); + viIt != vlnvInitializationOrder.rend(); ++viIt) { + // Iterate over IPs, if VLNV matches, push to front and remove from list + for (auto it = allIps.begin(); it != allIps.end(); ++it) { + if (*viIt == it->getVlnv()) { + orderedIps.push_front(*it); + it = allIps.erase(it); + } + } + } + + // Insert all other IPs at the end + orderedIps.splice(orderedIps.end(), allIps); + + auto loggerStatic = CoreFactory::getStaticLogger(); + loggerStatic->debug("IP initialization order:"); + for (auto &id : orderedIps) { + loggerStatic->debug(" " CLR_BLD("{}"), id.getName()); + } + + return orderedIps; +} + +std::list> +CoreFactory::configureIps(std::list orderedIps, json_t *json_ips, + Card *card) { + std::list> configuredIps; + auto loggerStatic = CoreFactory::getStaticLogger(); + // Configure all IPs + for (auto &id : orderedIps) { + loggerStatic->info("Configuring {}", id); + + // Find the appropriate factory that can create the specified VLNV + // Note: + // This is the magic part! Factories automatically register as a + // plugin as soon as they are instantiated. If there are multiple + // candidates, the first suitable factory will be used. + auto *f = lookup(id.getVlnv()); + if (f == nullptr) { + loggerStatic->warn("No plugin found to handle {}", id.getVlnv()); + continue; + } else + loggerStatic->debug("Using {} for IP {}", f->getName(), id.getVlnv()); + + auto logger = f->getLogger(); + + // Create new IP instance. Since this function is virtual, it will + // construct the right, specialized type without knowing it here + // because we have already picked the right factory. + // If something goes wrong with initialization, the shared_ptr will + // take care to desctruct the Core again as it is not pushed to + // the list and will run out of scope. + auto ip = std::unique_ptr(f->make()); + + if (ip == nullptr) { + logger->warn("Cannot create an instance of {}", f->getName()); + continue; + } + + // Setup generic IP type properties + ip->card = card; + ip->id = id; + ip->logger = villas::Log::get(id.getName()); + + json_t *json_ip = json_object_get(json_ips, id.getName().c_str()); + + // parse ip baseadress + json_t *json_parameters = json_object_get(json_ip, "parameters"); + if (json_is_object(json_parameters)) { + json_int_t c_baseaddr = 0; + int baseaddress_found = + json_unpack(json_parameters, "{ s?: I }", "c_baseaddr", &c_baseaddr); + if (baseaddress_found == 0) + ip->baseaddr = c_baseaddr; + } + + json_t *json_irqs = json_object_get(json_ip, "irqs"); + if (json_is_object(json_irqs)) { + logger->debug("Parse IRQs of {}", *ip); + + const char *irqName; + json_t *json_irq; + json_object_foreach(json_irqs, irqName, json_irq) { + const char *irqEntry = json_string_value(json_irq); + + auto tokens = utils::tokenize(irqEntry, ":"); + if (tokens.size() != 2) { + logger->warn("Cannot parse IRQ '{}' of " CLR_BLD("{}"), irqEntry, + id.getName()); + continue; + } + + const std::string &irqControllerName = tokens[0]; + InterruptController *intc = nullptr; + + for (auto &configuredIp : configuredIps) { + if (*configuredIp == irqControllerName) { + intc = dynamic_cast(configuredIp.get()); + break; + } + } + + if (intc == nullptr) { + logger->error("Interrupt Controller {} for IRQ {} not found", + irqControllerName, irqName); + continue; + } + + int num; + try { + num = std::stoi(tokens[1]); + } catch (const std::invalid_argument &) { + logger->warn("IRQ number is not an integer: '{}'", irqEntry); + continue; + } + logger->debug("IRQ: {} -> {}:{}", irqName, irqControllerName, num); + ip->irqs[irqName] = {num, intc, ""}; + } + } + + json_t *json_memory_view = json_object_get(json_ip, "memory-view"); + if (json_is_object(json_memory_view)) { + logger->debug("Parse memory view of {}", *ip); + + // Now find all slave address spaces this master can access + const char *bus_name; + json_t *json_bus; + json_object_foreach(json_memory_view, bus_name, json_bus) { + + // This IP has a memory view => it is a bus master somewhere + + // Assemble name for master address space + const std::string myAddrSpaceName = + MemoryManager::getMasterAddrSpaceName(ip->getInstanceName(), + bus_name); + // Create a master address space + const MemoryManager::AddressSpaceId myAddrSpaceId = + MemoryManager::get().getOrCreateAddressSpace(myAddrSpaceName); + + ip->busMasterInterfaces[bus_name] = myAddrSpaceId; + + const char *instance_name; + json_t *json_instance; + json_object_foreach(json_bus, instance_name, json_instance) { + + const char *block_name; + json_t *json_block; + json_object_foreach(json_instance, block_name, json_block) { + + json_int_t base, high, size; + json_error_t err; + int ret = json_unpack_ex(json_block, &err, 0, + "{ s: I, s: I, s: I }", "baseaddr", &base, + "highaddr", &high, "size", &size); + if (ret != 0) + throw ConfigError( + json_block, err, "", "Cannot parse address block {}/{}/{}/{}", + ip->getInstanceName(), bus_name, instance_name, block_name); + + // Get or create the slave address space + const std::string slaveAddrSpace = + MemoryManager::getSlaveAddrSpaceName(instance_name, block_name); + + const MemoryManager::AddressSpaceId slaveAddrSpaceId = + MemoryManager::get().getOrCreateAddressSpace(slaveAddrSpace); + + // Create a new mapping to the slave address space + MemoryManager::get().createMapping( + static_cast(base), 0, static_cast(size), + bus_name, myAddrSpaceId, slaveAddrSpaceId); + } + } + } + } + + // IP-specific setup via JSON config + f->parse(*ip, json_ip); + + // Set polling mode + f->configurePollingMode( + *ip, (card->polling ? PollingMode::POLL : PollingMode::IRQ)); + + // IP has been configured now + configuredIps.push_back(std::move(ip)); + } + + return configuredIps; +} + +void CoreFactory::initIps(std::list> configuredIps, + Card *card) { + auto loggerStatic = CoreFactory::getStaticLogger(); + // Start and check IPs now + for (auto &ip : configuredIps) { + loggerStatic->info("Initializing {}", *ip); + + // Translate all memory blocks that the IP needs to be accessible from + // the process and cache in the instance, so this has not to be done at + // runtime. + for (auto &memoryBlock : ip->getMemoryBlocks()) { + // Construct the global name of this address block + const auto addrSpaceName = MemoryManager::getSlaveAddrSpaceName( + ip->getInstanceName(), memoryBlock); + + // Retrieve its address space identifier + const auto addrSpaceId = + MemoryManager::get().findAddressSpace(addrSpaceName); + + // ... and save it in IP + ip->slaveAddressSpaces.emplace(memoryBlock, addrSpaceId); + + // Get the translation to the address space + const auto &translation = + MemoryManager::get().getTranslationFromProcess(addrSpaceId); + + // Cache it in the IP instance only with local name + ip->addressTranslations.emplace(memoryBlock, translation); + } + + if (not ip->init()) { + throw RuntimeError("Failed to initialize IP {}", *ip); + } + + if (not ip->check()) { + throw RuntimeError("Failed to check IP {}", *ip); + } + + // Will only be reached if the IP successfully was initialized + card->ips.push_back(std::move(ip)); + } + + loggerStatic->debug("Initialized IPs:"); + for (auto &ip : card->ips) { + loggerStatic->debug(" {}", *ip); + } +} + +std::list> CoreFactory::make(Card *card, + json_t *json_ips) { + // We only have this logger until we know the factory to build an IP with + auto loggerStatic = getStaticLogger(); + + if (!card->ips.empty()) { + loggerStatic->error("IP list of card {} already contains IPs.", card->name); + throw RuntimeError("IP list of card {} already contains IPs.", card->name); + } + + std::list allIps = + parseIpIdentifier(json_ips); // All IPs available in config + + std::list orderedIps = + reorderIps(allIps); // IPs ordered in initialization order + + std::list> configuredIps = + configureIps(orderedIps, json_ips, card); // Successfully configured IPs + + initIps(configuredIps, card); + + return card->ips; +} + +void Core::dump() { + logger->info("IP: {}", *this); + for (auto &[num, irq] : irqs) { + logger->info(" IRQ {}: {}:{}", num, irq.irqController->getInstanceName(), + irq.num); + } + + for (auto &[block, translation] : addressTranslations) { + logger->info(" Memory {}: {}", block, translation); + } +} + +CoreFactory *CoreFactory::lookup(const Vlnv &vlnv) { + for (auto &ip : plugin::registry->lookup()) { + if (ip->getCompatibleVlnv() == vlnv) + return ip; + } + + return nullptr; +} + +uintptr_t Core::getLocalAddr(const MemoryBlockName &block, + uintptr_t address) const { + // Throws exception if block not present + auto &translation = addressTranslations.at(block); + + return translation.getLocalAddr(address); +} + +InterruptController * +Core::getInterruptController(const std::string &interruptName) const { + try { + const IrqPort irq = irqs.at(interruptName); + return irq.irqController; + } catch (const std::out_of_range &) { + return nullptr; + } +} diff --git a/fpga/lib/dma.cpp b/fpga/lib/dma.cpp new file mode 100644 index 000000000..7ce10b2b5 --- /dev/null +++ b/fpga/lib/dma.cpp @@ -0,0 +1,172 @@ +/* API for interacting with the FPGA DMA Controller. + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace villas; + +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("villasfpga_dma"); + +struct villasfpga_handle_t { + std::shared_ptr card; + std::shared_ptr dma; +}; +struct villasfpga_memory_t { + std::shared_ptr block; +}; + +villasfpga_handle villasfpga_init(const char *configFile) { + std::string fpgaName = "vc707"; + std::string connectStr = "3<->pipe"; + std::string outputFormat = "short"; + bool dumpGraph = false; + bool dumpAuroraChannels = true; + try { + // Logging setup + Log::getInstance().setLevel(spdlog::level::debug); + fpga::setupColorHandling(); + + if (configFile == nullptr || configFile[0] == '\0') { + logger->error( + "No configuration file provided/ Please use -c/--config argument"); + return nullptr; + } + + auto handle = new villasfpga_handle_t; + handle->card = fpga::setupFpgaCard(configFile, fpgaName); + + if (dumpGraph) { + auto &mm = MemoryManager::get(); + mm.getGraph().dump("graph.dot"); + } + + if (dumpAuroraChannels) { + auto aurora_channels = getAuroraChannels(handle->card); + for (auto aurora : *aurora_channels) + aurora->dump(); + } + + // Configure Crossbar switch + const fpga::ConnectString parsedConnectString(connectStr); + parsedConnectString.configCrossBar(handle->card); + + return handle; + } catch (const RuntimeError &e) { + logger->error("Error: {}", e.what()); + return nullptr; + } catch (const std::exception &e) { + logger->error("Error: {}", e.what()); + return nullptr; + } catch (...) { + logger->error("Unknown error"); + return nullptr; + } +} + +void villasfpga_destroy(villasfpga_handle handle) { delete handle; } + +int villasfpga_alloc(villasfpga_handle handle, villasfpga_memory *mem, + size_t size) { + try { + auto &alloc = villas::HostRam::getAllocator(); + *mem = new villasfpga_memory_t; + (*mem)->block = alloc.allocateBlock(size); + return villasfpga_register(handle, mem); + } catch (const RuntimeError &e) { + logger->error("Failed to allocate memory: {}", e.what()); + return -1; + } +} +int villasfpga_register(villasfpga_handle handle, villasfpga_memory *mem) { + try { + handle->dma->makeAccesibleFromVA((*mem)->block); + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to register memory: {}", e.what()); + return -1; + } +} +int villasfpga_free(villasfpga_memory mem) { + try { + delete mem; + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to free memory: {}", e.what()); + return -1; + } +} + +int villasfpga_read(villasfpga_handle handle, villasfpga_memory mem, + size_t size) { + try { + if (!handle->dma->read(*mem->block, size)) { + logger->error("Failed to read from device"); + return -1; + } + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to read memory: {}", e.what()); + return -1; + } +} + +int villasfpga_read_complete(villasfpga_handle handle, size_t *size) { + try { + auto readComp = handle->dma->readComplete(); + logger->debug("Read {} bytes", readComp.bytes); + *size = readComp.bytes; + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to read memory: {}", e.what()); + return -1; + } +} + +int villasfpga_write(villasfpga_handle handle, villasfpga_memory mem, + size_t size) { + try { + if (!handle->dma->write(*mem->block, size)) { + logger->error("Failed to write to device"); + return -1; + } + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to write memory: {}", e.what()); + return -1; + } +} + +int villasfpga_write_complete(villasfpga_handle handle, size_t *size) { + try { + auto writeComp = handle->dma->writeComplete(); + logger->debug("Wrote {} bytes", writeComp.bytes); + *size = writeComp.bytes; + return 0; + } catch (const RuntimeError &e) { + logger->error("Failed to write memory: {}", e.what()); + return -1; + } +} + +void *villasfpga_get_ptr(villasfpga_memory mem) { + return (void *)MemoryManager::get() + .getTranslationFromProcess(mem->block->getAddrSpaceId()) + .getLocalAddr(0); +} diff --git a/fpga/lib/ips/aurora.cpp b/fpga/lib/ips/aurora.cpp new file mode 100644 index 000000000..40a2f68b0 --- /dev/null +++ b/fpga/lib/ips/aurora.cpp @@ -0,0 +1,117 @@ +/* Driver for wrapper around Aurora (acs.eonerc.rwth-aachen.de:user:aurora) + * + * Author: Hatim Kanchwala + * SPDX-FileCopyrightText: 2020 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include + +// Register offsets +#define AURORA_AXIS_SR_OFFSET 0x00 // Status Register (read-only) +#define AURORA_AXIS_CR_OFFSET 0x04 // Control Register (read/write) +#define AURORA_AXIS_CNTR_IN_HIGH_OFFSET \ + 0x0C // Higher 32-bits of incoming frame counter +#define AURORA_AXIS_CNTR_IN_LOW_OFFSET \ + 0x08 // Lower 32-bits of incoming frame counter +#define AURORA_AXIS_CNTR_OUT_HIGH_OFFSET \ + 0x18 // Higher 32-bits of outgoing frame counter +#define AURORA_AXIS_CNTR_OUT_LOW_OFFSET \ + 0x1C // Lower 32-bits of outgoing frame counter + +// Status register bits +#define AURORA_AXIS_SR_CHAN_UP \ + (1 \ + << 0) // 1-bit, asserted when channel initialisation is complete and is ready for data transfer +#define AURORA_AXIS_SR_LANE_UP \ + (1 << 1) // 1-bit, asserted for each lane upon successful lane initialisation +#define AURORA_AXIS_SR_HARD_ERR (1 << 2) // 1-bit hard rror status +#define AURORA_AXIS_SR_SOFT_ERR (1 << 3) // 1-bit soft error status +#define AURORA_AXIS_SR_FRAME_ERR (1 << 4) // 1-bit frame error status + +// Control register bits +// 1-bit, assert to put Aurora IP in loopback mode. +#define AURORA_AXIS_CR_LOOPBACK (1 << 0) + +// 1-bit, assert to reset counters, incoming and outgoing frame counters. +#define AURORA_AXIS_CR_RST_CTRS (1 << 1) + +// 1-bit, assert to turn off any sequence number handling by Aurora IP +// Sequence number must be handled in software then. +#define AURORA_AXIS_CR_SEQ_MODE (1 << 2) + +/* 1-bit, assert to strip the received frame of the trailing sequence + * number. Sequence number mode must be set to handled by Aurora IP, + * otherwise this bit is ignored. */ +#define AURORA_AXIS_CR_SEQ_STRIP (1 << 3) + +/* 1-bit, assert to use the same sequence number in the outgoing + * NovaCor-bound frames as the sequence number received from the + * incoming frames from NovaCor. Sequence number mode must be set to + * handled by Aurora IP, otherwise this bit is ignored.*/ +#define AURORA_AXIS_CR_SEQ_ECHO (1 << 4) + +using namespace villas::fpga::ip; + +void Aurora::dump() { + // Check Aurora AXI4 registers + const uint32_t sr = + readMemory(registerMemory, AURORA_AXIS_SR_OFFSET); + + logger->info("Aurora-NovaCor AXI-Stream interface details:"); + logger->info("Aurora status: {:#x}", sr); + logger->info(" Channel up: {}", + sr & AURORA_AXIS_SR_CHAN_UP ? CLR_GRN("yes") : CLR_RED("no")); + logger->info(" Lane up: {}", + sr & AURORA_AXIS_SR_LANE_UP ? CLR_GRN("yes") : CLR_RED("no")); + logger->info(" Hard error: {}", + sr & AURORA_AXIS_SR_HARD_ERR ? CLR_RED("yes") : CLR_GRN("no")); + logger->info(" Soft error: {}", + sr & AURORA_AXIS_SR_SOFT_ERR ? CLR_RED("yes") : CLR_GRN("no")); + logger->info(" Frame error: {}", + sr & AURORA_AXIS_SR_FRAME_ERR ? CLR_RED("yes") : CLR_GRN("no")); + + const uint64_t inCntLow = + readMemory(registerMemory, AURORA_AXIS_CNTR_IN_LOW_OFFSET); + const uint64_t inCntHigh = + readMemory(registerMemory, AURORA_AXIS_CNTR_IN_HIGH_OFFSET); + const uint64_t inCnt = (inCntHigh << 32) | inCntLow; + + const uint64_t outCntLow = + readMemory(registerMemory, AURORA_AXIS_CNTR_OUT_LOW_OFFSET); + const uint64_t outCntHigh = + readMemory(registerMemory, AURORA_AXIS_CNTR_OUT_HIGH_OFFSET); + const uint64_t outCnt = (outCntHigh << 32) | outCntLow; + + logger->info("Aurora frames received: {}", inCnt); + logger->info("Aurora frames sent: {}", outCnt); +} + +void Aurora::setLoopback(bool state) { + auto cr = readMemory(registerMemory, AURORA_AXIS_CR_OFFSET); + + if (state) + cr |= AURORA_AXIS_CR_LOOPBACK; + else + cr &= ~AURORA_AXIS_CR_LOOPBACK; + + writeMemory(registerMemory, AURORA_AXIS_CR_OFFSET, cr); +} + +void Aurora::resetFrameCounters() { + auto cr = readMemory(registerMemory, AURORA_AXIS_CR_OFFSET); + + cr |= AURORA_AXIS_CR_RST_CTRS; + + writeMemory(registerMemory, AURORA_AXIS_CR_OFFSET, cr); +} + +static char n[] = "aurora"; +static char d[] = "Aurora 8B/10B and additional support modules, like an " + "AXI4-Lite register interface."; +static char v[] = "acs.eonerc.rwth-aachen.de:user:aurora_axis:"; +static NodePlugin f; diff --git a/fpga/lib/ips/aurora_xilinx.cpp b/fpga/lib/ips/aurora_xilinx.cpp new file mode 100644 index 000000000..e516512cd --- /dev/null +++ b/fpga/lib/ips/aurora_xilinx.cpp @@ -0,0 +1,19 @@ +/* Driver for wrapper around standard Xilinx Aurora (xilinx.com:ip:aurora_8b10b) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include + +using namespace villas::fpga::ip; + +static char n[] = "aurora_xilinx"; +static char d[] = "Xilinx Aurora 8B/10B."; +static char v[] = "xilinx.com:ip:aurora_8b10b:"; +static NodePlugin f; diff --git a/fpga/lib/ips/bram.cpp b/fpga/lib/ips/bram.cpp new file mode 100644 index 000000000..4f2032542 --- /dev/null +++ b/fpga/lib/ips/bram.cpp @@ -0,0 +1,32 @@ +/* Block RAM IP. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +using namespace villas; +using namespace villas::fpga::ip; + +void BramFactory::parse(Core &ip, json_t *cfg) { + CoreFactory::parse(ip, cfg); + + auto &bram = dynamic_cast(ip); + + json_error_t err; + int ret = json_unpack_ex(cfg, &err, 0, "{ s: i }", "size", &bram.size); + if (ret != 0) + throw ConfigError(cfg, err, "", "Cannot parse BRAM config"); +} + +bool Bram::init() { + allocator = std::make_unique(getAddressSpaceId(memoryBlock), + this->size, 0); + + return true; +} + +static BramFactory f; diff --git a/fpga/lib/ips/dino.cpp b/fpga/lib/ips/dino.cpp new file mode 100644 index 000000000..64e158af7 --- /dev/null +++ b/fpga/lib/ips/dino.cpp @@ -0,0 +1,263 @@ +/* Driver for wrapper around standard Xilinx Aurora (xilinx.com:ip:aurora_8b10b) + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023-2024 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include + +using namespace villas::fpga::ip; + +Dino::Dino() : Node(), i2cdev(nullptr), i2c_channel(0), configDone(false) {} + +Dino::~Dino() {} + +bool Dino::init() { + if (!configDone) { + logger->error("Dino configuration not done yet"); + throw RuntimeError("Dino configuration not done yet"); + } + if (i2cdev == nullptr) { + i2cdev = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_iic:"))); + if (i2cdev == nullptr) { + logger->error("No I2C found on FPGA"); + throw RuntimeError( + "Dino requires and I2C device but none was found on FPGA"); + } else { + logger->debug("Found I2C on FPGA"); + } + } + configureHardware(); + return true; +} + +void Dino::setIoextDir(IoextPorts ports) { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + std::vector data = {I2C_IOEXT_REG_DIR, ports.raw}; + i2cdev->write(I2C_IOEXT_ADDR, data); +} + +void Dino::setIoextOut(IoextPorts ports) { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + std::vector data = {I2C_IOEXT_REG_OUT, ports.raw}; + i2cdev->write(I2C_IOEXT_ADDR, data); +} + +Dino::IoextPorts Dino::getIoextDir() { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + std::vector data; + i2cdev->readRegister(I2C_IOEXT_ADDR, I2C_IOEXT_REG_DIR, data, 1); + IoextPorts ports; + ports.raw = data[0]; + return ports; +} + +Dino::IoextPorts Dino::getIoextDirectionRegister() { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + auto ret = getIoextDir(); + i2cdev->getSwitch().unlockChannel(); + return ret; +} + +Dino::IoextPorts Dino::getIoextOut() { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + std::vector data; + i2cdev->readRegister(I2C_IOEXT_ADDR, I2C_IOEXT_REG_OUT, data, 1); + IoextPorts ports; + ports.raw = data[0]; + return ports; +} + +Dino::IoextPorts Dino::getIoextOutputRegister() { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + auto ret = getIoextOut(); + i2cdev->getSwitch().unlockChannel(); + return ret; +} + +DinoAdc::DinoAdc() : Dino() {} + +DinoAdc::~DinoAdc() {} + +void DinoAdc::configureHardware() { + if (!configDone) { + logger->error("ADC configuration not done yet"); + throw RuntimeError("ADC configuration not done yet"); + } + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + IoextPorts ioext = {.raw = 0}; + ioext.fields.sat_detect = true; + setIoextDir(ioext); + auto readback = getIoextDir(); + if (readback.raw != ioext.raw) { + logger->error("Ioext direction register readback incorrect: {:#x} != {:#x}", + readback.raw, ioext.raw); + throw RuntimeError("Failed to set IOEXT direction register"); + } + logger->debug("ADC Ioext: Direction register configured to {}", readback); + ioext.raw = 0; + ioext.fields.data_dir = true; + ioext.fields.status_led = true; + ioext.fields.n_we = true; + ioext.fields.input_zero = true; + setIoextOut(ioext); + ioext.fields.n_we = false; + setIoextOut(ioext); + readback = getIoextOut(); + if (readback.raw != ioext.raw) { + logger->error("Ioext output register readback incorrect: {:#x} != {:#x}", + readback.raw, ioext.raw); + throw RuntimeError("Failed to set IOEXT output register"); + } + i2cdev->getSwitch().unlockChannel(); + logger->debug("ADC Ioext: Output register configured to {}", readback); +} + +void DinoAdc::setRegisterConfig(std::shared_ptr reg, + double sampleRate) { + constexpr double dinoClk = 25e6; // Dino is clocked with 25 Mhz + constexpr size_t dinoRegisterTimer = 0; + constexpr size_t dinoRegisterAdcScale = 1; + constexpr size_t dinoRegisterAdcOffset = 2; + constexpr size_t dinoRegisterDacExternalTrig = 4; + constexpr size_t dinoRegisterStsActive = 5; + constexpr size_t dinoRegisterDacScale = 6; + constexpr size_t dinoRegisterDacOffset = 7; + + uint32_t dinoTimerVal = static_cast(dinoClk / sampleRate); + double rateError = dinoClk / dinoTimerVal - sampleRate; + reg->setRegister( + dinoRegisterTimer, + dinoTimerVal); // Timer value for generating ADC trigger signal + // The following are calibration values for the ADC and DAC. Scale + // sets an factor to be multiplied with the input value. This is the + // raw 16 bit ADC value for the ADC and the float value from VILLAS for + // the DAC. Offset is a value to be added to the result of the multiplication. + // All values are IEE 754 single precision floating point values. + reg->setRegister(dinoRegisterAdcScale, + -0.001615254F); // Scale factor for ADC value + reg->setRegister(dinoRegisterAdcOffset, 10.8061F); // Offset for ADC value + reg->setRegister(dinoRegisterDacScale, + 3448.53852516F); // Scale factor for DAC value + reg->setRegister(dinoRegisterDacOffset, 32767.5F); // Offset for DAC value + uint32_t rate = reg->getRegister(dinoRegisterTimer); + float adcScale = reg->getRegisterFloat(dinoRegisterAdcScale); + float adcOffset = reg->getRegisterFloat(dinoRegisterAdcOffset); + float dacScale = reg->getRegisterFloat(dinoRegisterDacScale); + float dacOffset = reg->getRegisterFloat(dinoRegisterDacOffset); + uint32_t dacExternalTrig = reg->getRegister(dinoRegisterDacExternalTrig); + uint32_t stsActive = reg->getRegister(dinoRegisterStsActive); + Log::get("Dino")->info( + "Check: Register configuration: TimerThresh: {}, Rate-Error: {} Hz, ADC " + "Scale: {}, ADC Offset: {}, DAC Scale: {}, DAC Offset: {}, DAC External " + "Trig: {:#x}, STS Active: {:#x}", + rate, rateError, adcScale, adcOffset, dacScale, dacOffset, + dacExternalTrig, stsActive); +} + +DinoDac::DinoDac() : Dino() {} + +DinoDac::~DinoDac() {} + +void DinoDac::configureHardware() { + if (!configDone) { + logger->error("DAC configuration not done yet"); + throw RuntimeError("DAC configuration not done yet"); + } + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + IoextPorts ioext = {.raw = 0}; + setIoextDir(ioext); + auto readback = getIoextDir(); + if (readback.raw != ioext.raw) { + logger->error("Ioext direction register readback incorrect: {:#x} != {:#x}", + readback.raw, ioext.raw); + throw RuntimeError("Failed to set IOEXT direction register"); + } + logger->debug("DAC Ioext: Direction register configured to {}", readback); + ioext.fields.status_led = true; + // Default gain is 1. Although not really necessary, let's be explicit here + ioext.fields.gain_lsb = Gain::GAIN_1 & 0x1; + ioext.fields.gain_msb = Gain::GAIN_1 & 0x2; + setIoextOut(ioext); + readback = getIoextOut(); + if (readback.raw != ioext.raw) { + logger->error("Ioext output register readback incorrect: {:#x} != {:#x}", + readback.raw, ioext.raw); + throw RuntimeError("Failed to set IOEXT output register"); + } + i2cdev->getSwitch().unlockChannel(); + logger->debug("DAC Ioext: Output register configured to {}", readback); +} + +void DinoDac::setGain(Gain gain) { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + IoextPorts ioext = getIoextOut(); + ioext.fields.gain_lsb = gain & 0x1; + ioext.fields.gain_msb = gain & 0x2; + setIoextOut(ioext); + i2cdev->getSwitch().unlockChannel(); +} + +Dino::Gain DinoDac::getGain() { + if (i2cdev == nullptr) { + throw RuntimeError("I2C device not set"); + } + i2cdev->getSwitch().setAndLockChannel(i2c_channel); + IoextPorts ioext = getIoextOut(); + auto ret = + static_cast((ioext.fields.gain_msb << 1) | ioext.fields.gain_lsb); + i2cdev->getSwitch().unlockChannel(); + return ret; +} + +void DinoFactory::parse(Core &ip, json_t *cfg) { + NodeFactory::parse(ip, cfg); + + auto &dino = dynamic_cast(ip); + json_error_t err; + int i2c_channel; + int ret = + json_unpack_ex(cfg, &err, 0, "{ s: i }", "i2c_channel", &i2c_channel); + if (ret != 0) { + throw ConfigError(cfg, err, "", "Failed to parse Dino configuration"); + } + if (i2c_channel < 0 || i2c_channel >= 8) { + throw ConfigError(cfg, err, "", "Invalid I2C channel"); + } + dino.i2c_channel = static_cast(i2c_channel); + + dino.configDone = true; +} + +static DinoAdcFactory fAdc; +static DinoDacFactory fDac; diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp new file mode 100644 index 000000000..b8e9c7213 --- /dev/null +++ b/fpga/lib/ips/dma.cpp @@ -0,0 +1,945 @@ +/* DMA driver + * + * Author: Niklas Eiling + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2018-2024 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +// Max. size of a DMA transfer in simple mode +#define FPGA_DMA_BOUNDARY 0x1000 + +using namespace villas::fpga::ip; + +bool Dma::init() { + // Check if configJson has been called + if (!configDone) + throw RuntimeError("DMA device not configured"); + + if (hasScatterGather()) + logger->info("Scatter-Gather support: {}", hasScatterGather()); + + xConfig.BaseAddr = getBaseAddr(registerMemory); + + hwReadLock.lock(); + hwWriteLock.lock(); + if (XAxiDma_CfgInitialize(&xDma, &xConfig) != XST_SUCCESS) { + logger->error("Cannot initialize Xilinx DMA driver"); + return false; + } + + if (XAxiDma_Selftest(&xDma) != XST_SUCCESS) { + logger->error("DMA selftest failed"); + return false; + } else { + logger->debug("DMA selftest passed"); + } + + hwWriteLock.unlock(); + hwReadLock.unlock(); + // Map buffer descriptors + if (hasScatterGather()) { + if (actualRingBdSize < readCoalesce || actualRingBdSize < writeCoalesce) { + throw RuntimeError( + "Ring buffer size is too small for coalesce value {} < {}", + actualRingBdSize, std::max(readCoalesce, writeCoalesce)); + } + setupScatterGather(); + } + + if (!polling) { + irqs[mm2sInterrupt].irqController->enableInterrupt(irqs[mm2sInterrupt], + polling); + irqs[s2mmInterrupt].irqController->enableInterrupt(irqs[s2mmInterrupt], + polling); + } + return true; +} + +void Dma::setupScatterGather() { + // Allocate and map space for BD ring in host RAM + auto &alloc = villas::HostRam::getAllocator(); + sgRing = alloc.allocateBlock(2 * requestedRingBdSizeMemory); + + if (not card->mapMemoryBlock(sgRing)) + throw RuntimeError("Memory not accessible by DMA"); + + auto &mm = MemoryManager::get(); + auto trans = mm.getTranslation(busMasterInterfaces[sgInterface], + sgRing->getAddrSpaceId()); + + auto physAddr = reinterpret_cast(trans.getLocalAddr(0)); + auto virtAddr = reinterpret_cast( + mm.getTranslationFromProcess(sgRing->getAddrSpaceId()).getLocalAddr(0)); + setupScatterGatherRingRx(physAddr, virtAddr); + + setupScatterGatherRingTx(physAddr + requestedRingBdSizeMemory, + virtAddr + requestedRingBdSizeMemory); +} + +void Dma::setupScatterGatherRingRx(uintptr_t physAddr, uintptr_t virtAddr) { + int ret; + + hwReadLock.lock(); + auto *rxRingPtr = XAxiDma_GetRxRing(&xDma); + + // Disable all RX interrupts before RxBD space setup + XAxiDma_BdRingIntDisable(rxRingPtr, XAXIDMA_IRQ_ALL_MASK); + + // Set delay and coalescing + XAxiDma_BdRingSetCoalesce(rxRingPtr, readCoalesce, delay); + + // Setup Rx BD space + ret = XAxiDma_BdRingCreate(rxRingPtr, physAddr, virtAddr, + XAXIDMA_BD_MINIMUM_ALIGNMENT, actualRingBdSize); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to create RX ring: {}", ret); + + // Setup an all-zero BD as the template for the Rx channel. + XAxiDma_Bd bdTemplate; + XAxiDma_BdClear(&bdTemplate); + + ret = XAxiDma_BdRingClone(rxRingPtr, &bdTemplate); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to clone BD template: {}", ret); + + if (cyclic) { + // Enable Cyclic DMA mode + XAxiDma_BdRingEnableCyclicDMA(rxRingPtr); + XAxiDma_SelectCyclicMode(&xDma, XAXIDMA_DEVICE_TO_DMA, 1); + } + // Enable completion interrupt + if (!polling) { + XAxiDma_IntrEnable(&xDma, XAXIDMA_IRQ_IOC_MASK, XAXIDMA_DEVICE_TO_DMA); + } + // Start the RX channel + ret = XAxiDma_BdRingStart(rxRingPtr); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to start TX ring: {}", ret); + + hwReadLock.unlock(); +} + +void Dma::setupScatterGatherRingTx(uintptr_t physAddr, uintptr_t virtAddr) { + int ret; + + hwWriteLock.lock(); + auto *txRingPtr = XAxiDma_GetTxRing(&xDma); + + // Disable all TX interrupts before TxBD space setup + XAxiDma_BdRingIntDisable(txRingPtr, XAXIDMA_IRQ_ALL_MASK); + + // Set TX delay and coalesce + XAxiDma_BdRingSetCoalesce(txRingPtr, writeCoalesce, delay); + + // Setup TxBD space + ret = XAxiDma_BdRingCreate(txRingPtr, physAddr, virtAddr, + XAXIDMA_BD_MINIMUM_ALIGNMENT, actualRingBdSize); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to create TX BD ring: {}", ret); + + // We create an all-zero BD as the template. + XAxiDma_Bd BdTemplate; + XAxiDma_BdClear(&BdTemplate); + + ret = XAxiDma_BdRingClone(txRingPtr, &BdTemplate); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to clone TX ring BD: {}", ret); + + // Enable completion interrupt + if (!polling) { + XAxiDma_IntrEnable(&xDma, XAXIDMA_IRQ_IOC_MASK, XAXIDMA_DMA_TO_DEVICE); + } + // Start the TX channel + ret = XAxiDma_BdRingStart(txRingPtr); + if (ret != XST_SUCCESS) + throw RuntimeError("Failed to start TX ring: {}", ret); + hwWriteLock.unlock(); +} + +bool Dma::reset() { + if (xDma.RegBase == 0) { + return true; + } + + hwReadLock.lock(); + hwWriteLock.lock(); + XAxiDma_IntrDisable(&xDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE); + XAxiDma_IntrDisable(&xDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA); + + XAxiDma_Reset(&xDma); + + // Value taken from libxil implementation + int timeout = 500; + + while (timeout > 0) { + if (XAxiDma_ResetIsDone(&xDma)) { + logger->info("DMA has been reset."); + hwReadLock.unlock(); + hwWriteLock.unlock(); + return true; + } + + timeout--; + } + hwReadLock.unlock(); + hwWriteLock.unlock(); + logger->error("DMA reset timed out"); + + return false; +} + +Dma::~Dma() { + // Unmap memory in our ownership, MemoryBlock gets deleted and removed from + // graph by this destructor as well. + if (hasScatterGather()) { + // Fix memory leak in upstream Xilinx code + auto txRingPtr = XAxiDma_GetTxRing(&xDma); + auto rxRingPtr = XAxiDma_GetRxRing(&xDma); + if (txRingPtr) { + free(txRingPtr->CyclicBd); + txRingPtr->CyclicBd = nullptr; + } + if (rxRingPtr) { + free(rxRingPtr->CyclicBd); + rxRingPtr->CyclicBd = nullptr; + } + // Unmap SG memory Blocks + if (sgRing) { + card->unmapMemoryBlock(*sgRing); + } + } + Dma::reset(); +} + +bool Dma::memcpy(const MemoryBlock &src, const MemoryBlock &dst, size_t len) { + if (len == 0) + return true; + + if (not connectLoopback()) + return false; + + if (this->read(dst, len) == 0) + return false; + + if (this->write(src, len) == 0) + return false; + + if (not this->writeComplete().bds) + return false; + + if (not this->readComplete().bds) + return false; + + return true; +} + +bool Dma::write(const MemoryBlock &mem, size_t len) { + if (len == 0) + return true; + + if (len > FPGA_DMA_BOUNDARY) + return false; + + auto &mm = MemoryManager::get(); + + // User has to make sure that memory is accessible, otherwise this will throw + auto trans = mm.getTranslation(busMasterInterfaces[mm2sInterface], + mem.getAddrSpaceId()); + const void *buf = reinterpret_cast(trans.getLocalAddr(0)); + if (buf == nullptr) + throw RuntimeError("Buffer was null"); + + logger->trace("Write to stream from address {:p}", buf); + + return hasScatterGather() ? writeScatterGather(buf, len) + : writeSimple(buf, len); +} + +bool Dma::read(const MemoryBlock &mem, size_t len) { + if (len == 0) + return true; + + if (len > FPGA_DMA_BOUNDARY) + return false; + + auto &mm = MemoryManager::get(); + + // User has to make sure that memory is accessible, otherwise this will throw + auto trans = mm.getTranslation(busMasterInterfaces[s2mmInterface], + mem.getAddrSpaceId()); + void *buf = reinterpret_cast(trans.getLocalAddr(0)); + if (buf == nullptr) + throw RuntimeError("Buffer was null"); + + return hasScatterGather() ? readScatterGather(buf, len) + : readSimple(buf, len); +} + +// Reuse existing single BD bypassing BdRingFree, Alloc, ToHw +bool Dma::writeScatterGatherFast() { + hwWriteLock.lock(); + auto *txRing = XAxiDma_GetTxRing(&xDma); + if (txRing == nullptr) { + hwWriteLock.unlock(); + throw RuntimeError("RxRing was null."); + } + XAxiDma_Bd *CurBdPtr = txRing->HwHead; + + // Clear the bit we are polling on in complete + uint32_t BdSts = XAxiDma_ReadReg((UINTPTR)CurBdPtr, XAXIDMA_BD_STS_OFFSET); + BdSts &= ~XAXIDMA_BD_STS_COMPLETE_MASK; + XAxiDma_BdWrite(CurBdPtr, XAXIDMA_BD_STS_OFFSET, BdSts); + + uintptr_t tdesc = ((uintptr_t)txRing->HwTail + + (txRing->FirstBdPhysAddr - txRing->FirstBdAddr)) & + XAXIDMA_DESC_LSB_MASK; + XAxiDma_WriteReg(txRing->ChanBase, XAXIDMA_TDESC_OFFSET, tdesc); + + hwWriteLock.unlock(); + return true; +} + +bool Dma::writeScatterGatherPrepare(const MemoryBlock &mem, size_t len) { + + auto &mm = MemoryManager::get(); + + // User has to make sure that memory is accessible, otherwise this will throw + auto trans = mm.getTranslation(busMasterInterfaces[mm2sInterface], + mem.getAddrSpaceId()); + void *buf = reinterpret_cast(trans.getLocalAddr(0)); + if (buf == nullptr) { + throw RuntimeError("Buffer was null"); + } + hwWriteLock.lock(); + + auto bd = writeScatterGatherSetupBd(buf, len); + + hwWriteLock.unlock(); + + return bd != nullptr; +} + +XAxiDma_Bd *Dma::writeScatterGatherSetupBd(const void *buf, size_t len) { + uint32_t ret = XST_FAILURE; + if (len == 0) + return nullptr; + + if (len > FPGA_DMA_BOUNDARY) + return nullptr; + + auto *txRing = XAxiDma_GetTxRing(&xDma); + if (txRing == nullptr) { + hwWriteLock.unlock(); + throw RuntimeError("TxRing was null."); + } + + XAxiDma_Bd *bd; + ret = XAxiDma_BdRingAlloc(txRing, 1, &bd); + if (ret != XST_SUCCESS) { + hwWriteLock.unlock(); + throw RuntimeError("Write: BdRingAlloc returned {}.", ret); + } + + ret = XAxiDma_BdSetBufAddr(bd, (uintptr_t)buf); + if (ret != XST_SUCCESS) { + hwWriteLock.unlock(); + throw RuntimeError("Setting BdBufAddr to {} returned {}.", buf, ret); + } + + ret = XAxiDma_BdSetLength(bd, len, txRing->MaxTransferLen); + if (ret != XST_SUCCESS) { + hwWriteLock.unlock(); + throw RuntimeError("Setting BdBufLength to {} returned {}.", len, ret); + } + + // We have a single descriptor so it is both start and end of the list + XAxiDma_BdSetCtrl(bd, + XAXIDMA_BD_CTRL_TXEOF_MASK | XAXIDMA_BD_CTRL_TXSOF_MASK); + + // TODO: Check if we really need this + XAxiDma_BdSetId(bd, (uintptr_t)buf); + return bd; +} + +// Write a single message +bool Dma::writeScatterGather(const void *buf, size_t len) { + // buf is address from view of DMA controller + + int ret = XST_FAILURE; + hwWriteLock.lock(); + auto *txRing = XAxiDma_GetTxRing(&xDma); + if (txRing == nullptr) { + hwWriteLock.unlock(); + throw RuntimeError("TxRing was null."); + } + + XAxiDma_Bd *bd = writeScatterGatherSetupBd(buf, len); + // Give control of BD to HW. We should not access it until transfer is finished. + // Failure could also indicate that EOF is not set on last Bd + ret = XAxiDma_BdRingToHw(txRing, 1, bd); + if (ret != XST_SUCCESS) { + hwWriteLock.unlock(); + throw RuntimeError("Enqueuing Bd and giving control to HW failed {}", ret); + } + + hwWriteLock.unlock(); + + return true; +} + +// Reuse existing single BD bypassing BdRingFree, Alloc, ToHw +bool Dma::readScatterGatherFast() { + hwReadLock.lock(); + auto *rxRing = XAxiDma_GetRxRing(&xDma); + if (rxRing == nullptr) { + hwReadLock.unlock(); + throw RuntimeError("RxRing was null."); + } + XAxiDma_Bd *CurBdPtr = rxRing->HwHead; + // Poll BD status to avoid accessing PCIe address space + uint32_t BdSts = XAxiDma_ReadReg((UINTPTR)CurBdPtr, XAXIDMA_BD_STS_OFFSET); + + // Clear the bit we are polling on in complete + BdSts &= ~XAXIDMA_BD_STS_COMPLETE_MASK; + XAxiDma_BdWrite(CurBdPtr, XAXIDMA_BD_STS_OFFSET, BdSts); + + uintptr_t tdesc = ((uintptr_t)rxRing->HwTail + + (rxRing->FirstBdPhysAddr - rxRing->FirstBdAddr)) & + XAXIDMA_DESC_LSB_MASK; + XAxiDma_WriteReg(rxRing->ChanBase, XAXIDMA_TDESC_OFFSET, tdesc); + + hwReadLock.unlock(); + return true; +} + +bool Dma::readScatterGatherPrepare(const MemoryBlock &mem, size_t len) { + + auto &mm = MemoryManager::get(); + + // User has to make sure that memory is accessible, otherwise this will throw + auto trans = mm.getTranslation(busMasterInterfaces[s2mmInterface], + mem.getAddrSpaceId()); + void *buf = reinterpret_cast(trans.getLocalAddr(0)); + if (buf == nullptr) { + throw RuntimeError("Buffer was null"); + } + hwReadLock.lock(); + + auto bd = readScatterGatherSetupBd(buf, len); + + hwReadLock.unlock(); + + return bd != nullptr; +} + +XAxiDma_Bd *Dma::readScatterGatherSetupBd(void *buf, size_t len) { + uint32_t ret = XST_FAILURE; + if (len == 0) + return nullptr; + + if (len > FPGA_DMA_BOUNDARY) + return nullptr; + + auto *rxRing = XAxiDma_GetRxRing(&xDma); + if (rxRing == nullptr) { + hwReadLock.unlock(); + throw RuntimeError("RxRing was null."); + } + + XAxiDma_Bd *bd; + ret = XAxiDma_BdRingAlloc(rxRing, readCoalesce, &bd); + if (ret != XST_SUCCESS) { + hwReadLock.unlock(); + throw RuntimeError("Failed to alloc BD in RX ring: {}", ret); + } + + auto curBd = bd; + char *curBuf = (char *)buf; + for (size_t i = 0; i < readCoalesce; i++) { + ret = XAxiDma_BdSetBufAddr(curBd, (uintptr_t)curBuf); + if (ret != XST_SUCCESS) { + hwReadLock.unlock(); + throw RuntimeError("Failed to set buffer address {:x} on BD {:x}: {}", + (uintptr_t)buf, (uintptr_t)bd, ret); + } + + ret = XAxiDma_BdSetLength(curBd, len, rxRing->MaxTransferLen); + if (ret != XST_SUCCESS) { + hwReadLock.unlock(); + throw RuntimeError("Rx set length {} on BD {:x} failed {}", len, + (uintptr_t)bd, ret); + } + + // Receive BDs do not need to set anything for the control + // The hardware will set the SOF/EOF bits per stream status + XAxiDma_BdSetCtrl(curBd, 0); + + // TODO: Check if we really need this + XAxiDma_BdSetId(curBd, (uintptr_t)buf); + + curBuf += len; + curBd = (XAxiDma_Bd *)XAxiDma_BdRingNext(rxRing, curBd); + } + return bd; +} + +bool Dma::readScatterGather(void *buf, size_t len) { + uint32_t ret = XST_FAILURE; + + if (len < readCoalesce * readMsgSize) { + throw RuntimeError( + "Read size is smaller than readCoalesce*msgSize. Cannot setup BDs."); + } + + hwReadLock.lock(); + auto *rxRing = XAxiDma_GetRxRing(&xDma); + if (rxRing == nullptr) { + hwReadLock.unlock(); + throw RuntimeError("RxRing was null."); + } + + XAxiDma_Bd *bd = readScatterGatherSetupBd(buf, len); + + ret = XAxiDma_BdRingToHw(rxRing, readCoalesce, bd); + if (ret != XST_SUCCESS) { + hwReadLock.unlock(); + throw RuntimeError("Failed to submit BD to RX ring: {}", ret); + } + + hwReadLock.unlock(); + return true; +} + +size_t Dma::writeScatterGatherPoll(bool lock) { + if (lock) { + hwWriteLock.lock(); + } + auto txRing = XAxiDma_GetTxRing(&xDma); + XAxiDma_Bd *CurBdPtr = txRing->HwHead; + volatile uint32_t BdSts; + // Poll BD status to avoid accessing PCIe address space + do { + BdSts = XAxiDma_ReadReg((UINTPTR)CurBdPtr, XAXIDMA_BD_STS_OFFSET); + } while (!(BdSts & XAXIDMA_BD_STS_COMPLETE_MASK)); + // At this point, we know that the transmission is complete, but we haven't accessed the + // PCIe address space, yet. We know that we have received at least one BD. + if (lock) { + hwWriteLock.unlock(); + } + return XAxiDma_BdGetActualLength(CurBdPtr, XAXIDMA_MCHAN_MAX_TRANSFER_LEN); +} + +Dma::Completion Dma::writeCompleteScatterGather() { + Completion c; + XAxiDma_Bd *bd = nullptr, *curBd; + auto txRing = XAxiDma_GetTxRing(&xDma); + uint32_t ret = XST_FAILURE; + static size_t errcnt = 32; + + uint32_t irqStatus = 0; + if (polling) { + hwWriteLock.lock(); + writeScatterGatherPoll(false); + } else { + c.interrupts = irqs[mm2sInterrupt].irqController->waitForInterrupt( + irqs[mm2sInterrupt].num); + hwWriteLock.lock(); + } + + if ((c.bds = XAxiDma_BdRingFromHw(txRing, writeCoalesce, &bd)) < + writeCoalesce) { + logger->warn("Send partial batch of {}/{} BDs.", c.bds, writeCoalesce); + if (errcnt-- == 0) { + hwWriteLock.unlock(); + throw RuntimeError("too many partial batches"); + } + } + + // Acknowledge the interrupt + if (!polling) { + irqStatus = XAxiDma_BdRingGetIrq(txRing); + XAxiDma_BdRingAckIrq(txRing, irqStatus); + } + + if (c.bds == 0) { + c.bytes = 0; + hwWriteLock.unlock(); + return c; + } + + if (bd == nullptr) { + hwWriteLock.unlock(); + throw RuntimeError("Bd was null."); + } + + curBd = bd; + for (size_t i = 0; i < c.bds; i++) { + ret = XAxiDma_BdGetSts(curBd); + if ((ret & XAXIDMA_BD_STS_ALL_ERR_MASK) || + (!(ret & XAXIDMA_BD_STS_COMPLETE_MASK))) { + hwWriteLock.unlock(); + throw RuntimeError("Write: Bd Status register shows error: {:#x}", ret); + } + + c.bytes += XAxiDma_BdGetLength(bd, txRing->MaxTransferLen); + curBd = (XAxiDma_Bd *)XAxiDma_BdRingNext(txRing, curBd); + } + + ret = XAxiDma_BdRingFree(txRing, c.bds, bd); + if (ret != XST_SUCCESS) { + hwWriteLock.unlock(); + throw RuntimeError("Failed to free {} TX BDs {}", c.bds, ret); + } + + hwWriteLock.unlock(); + return c; +} + +size_t Dma::readScatterGatherPoll(bool lock) { + if (lock) { + hwReadLock.lock(); + } + auto rxRing = XAxiDma_GetRxRing(&xDma); + XAxiDma_Bd *CurBdPtr = rxRing->HwHead; + volatile uint32_t BdSts; + // Poll BD status to avoid accessing PCIe address space + do { + BdSts = XAxiDma_ReadReg((UINTPTR)CurBdPtr, XAXIDMA_BD_STS_OFFSET); + } while (!(BdSts & XAXIDMA_BD_STS_COMPLETE_MASK)); + // At this point, we know that the transmission is complete, but we haven't accessed the + // PCIe address space, yet. We know that we have received at least one BD. + if (lock) { + hwReadLock.unlock(); + } + return XAxiDma_BdGetActualLength(CurBdPtr, XAXIDMA_MCHAN_MAX_TRANSFER_LEN); +} + +Dma::Completion Dma::readCompleteScatterGather() { + Completion c; + XAxiDma_Bd *bd = nullptr, *curBd; + auto rxRing = XAxiDma_GetRxRing(&xDma); + int ret = XST_FAILURE; + static size_t errcnt = 32; + + ssize_t intrs = 0; + uint32_t irqStatus = 0; + if (polling) { + hwReadLock.lock(); + readScatterGatherPoll(false); + intrs = 1; + } else { + intrs = irqs[s2mmInterrupt].irqController->waitForInterrupt( + irqs[s2mmInterrupt].num); + hwReadLock.lock(); + } + + if (intrs < 0) { + logger->warn("Interrupt error or timeout: {}", intrs); + + // Free all RX BDs for future transmission. + int bds = XAxiDma_BdRingFromHw(rxRing, XAXIDMA_ALL_BDS, &bd); + XAxiDma_BdRingFree(rxRing, bds, bd); + hwReadLock.unlock(); + + c.interrupts = 0; + return c; + } else { + c.interrupts = intrs; + } + if (!polling) { + irqStatus = XAxiDma_BdRingGetIrq(rxRing); + XAxiDma_BdRingAckIrq(rxRing, irqStatus); + if (!(irqStatus & XAXIDMA_IRQ_IOC_MASK)) { + logger->error("Expected IOC interrupt but IRQ status is: {:#x}", + irqStatus); + return c; + } + } + // Wait until the data has been received by the RX channel. + if ((c.bds = XAxiDma_BdRingFromHw(rxRing, readCoalesce, &bd)) < + readCoalesce) { + logger->warn("Got partial batch of {}/{} BDs.", c.bds, readCoalesce); + if (errcnt-- == 0) { + hwReadLock.unlock(); + throw RuntimeError("too many partial batches"); + } + } else { + errcnt = 32; + } + + if (c.bds == 0) { + c.bytes = 0; + hwReadLock.unlock(); + return c; + } + + if (bd == nullptr) { + hwReadLock.unlock(); + throw RuntimeError("Bd was null."); + } + + curBd = bd; + for (size_t i = 0; i < c.bds; i++) { + // logger->trace("Read BD {}/{}: {:#x}", i, c.bds, + // XAxiDma_BdGetBufAddr(curBd)); + ret = XAxiDma_BdGetSts(curBd); + if ((ret & XAXIDMA_BD_STS_ALL_ERR_MASK) || + (!(ret & XAXIDMA_BD_STS_COMPLETE_MASK))) { + hwReadLock.unlock(); + throw RuntimeError("Read: Bd Status register shows error: {}", ret); + } + + c.bytes += XAxiDma_BdGetActualLength(bd, rxRing->MaxTransferLen); + curBd = (XAxiDma_Bd *)XAxiDma_BdRingNext(rxRing, curBd); + } + + // Free all processed RX BDs for future transmission. + ret = XAxiDma_BdRingFree(rxRing, c.bds, bd); + if (ret != XST_SUCCESS) { + hwReadLock.unlock(); + throw RuntimeError("Failed to free {} TX BDs {}.", c.bds, ret); + } + + hwReadLock.unlock(); + return c; +} + +bool Dma::writeSimple(const void *buf, size_t len) { + hwWriteLock.lock(); + XAxiDma_BdRing *ring = XAxiDma_GetTxRing(&xDma); + + if (not ring->HasDRE) { + const uint32_t mask = xDma.MicroDmaMode ? XAXIDMA_MICROMODE_MIN_BUF_ALIGN + : ring->DataWidth - 1; + + if (reinterpret_cast(buf) & mask) { + hwWriteLock.unlock(); + return false; + } + } + + const bool dmaChannelHalted = + XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_SR_OFFSET) & XAXIDMA_HALTED_MASK; + + const bool dmaToDeviceBusy = XAxiDma_Busy(&xDma, XAXIDMA_DMA_TO_DEVICE); + + // If the engine is doing a transfer, cannot submit + if (not dmaChannelHalted and dmaToDeviceBusy) { + hwWriteLock.unlock(); + return false; + } + + // Set lower 32 bit of source address + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_SRCADDR_OFFSET, + LOWER_32_BITS(reinterpret_cast(buf))); + + // If neccessary, set upper 32 bit of source address + if (xDma.AddrWidth > 32) + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_SRCADDR_MSB_OFFSET, + UPPER_32_BITS(reinterpret_cast(buf))); + + // Start DMA channel + auto channelControl = XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_CR_OFFSET); + channelControl |= XAXIDMA_CR_RUNSTOP_MASK; + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_CR_OFFSET, channelControl); + + // Set tail descriptor pointer + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_BUFFLEN_OFFSET, len); + hwWriteLock.unlock(); + return true; +} + +bool Dma::readSimple(void *buf, size_t len) { + hwReadLock.lock(); + XAxiDma_BdRing *ring = XAxiDma_GetRxRing(&xDma); + + if (not ring->HasDRE) { + const uint32_t mask = xDma.MicroDmaMode ? XAXIDMA_MICROMODE_MIN_BUF_ALIGN + : ring->DataWidth - 1; + + if (reinterpret_cast(buf) & mask) { + hwReadLock.unlock(); + return false; + } + } + + const bool dmaChannelHalted = + XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_SR_OFFSET) & XAXIDMA_HALTED_MASK; + const bool deviceToDmaBusy = XAxiDma_Busy(&xDma, XAXIDMA_DEVICE_TO_DMA); + + // If the engine is doing a transfer, cannot submit + if (not dmaChannelHalted and deviceToDmaBusy) { + hwReadLock.unlock(); + return false; + } + + // Set lower 32 bit of destination address + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_DESTADDR_OFFSET, + LOWER_32_BITS(reinterpret_cast(buf))); + + // If neccessary, set upper 32 bit of destination address + if (xDma.AddrWidth > 32) + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_DESTADDR_MSB_OFFSET, + UPPER_32_BITS(reinterpret_cast(buf))); + + // Start DMA channel + auto channelControl = XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_CR_OFFSET); + channelControl |= XAXIDMA_CR_RUNSTOP_MASK; + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_CR_OFFSET, channelControl); + + // Set tail descriptor pointer + XAxiDma_WriteReg(ring->ChanBase, XAXIDMA_BUFFLEN_OFFSET, len); + + hwReadLock.unlock(); + return true; +} + +Dma::Completion Dma::writeCompleteSimple() { + Completion c; + while (!(XAxiDma_IntrGetIrq(&xDma, XAXIDMA_DMA_TO_DEVICE) & + XAXIDMA_IRQ_IOC_MASK)) + c.interrupts = irqs[mm2sInterrupt].irqController->waitForInterrupt( + irqs[mm2sInterrupt]); + + hwWriteLock.lock(); + XAxiDma_IntrAckIrq(&xDma, XAXIDMA_IRQ_IOC_MASK, XAXIDMA_DMA_TO_DEVICE); + + const XAxiDma_BdRing *ring = XAxiDma_GetTxRing(&xDma); + const size_t bytesWritten = + XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_BUFFLEN_OFFSET); + hwWriteLock.unlock(); + c.bytes = bytesWritten; + return c; +} + +Dma::Completion Dma::readCompleteSimple() { + Completion c; + while (!(XAxiDma_IntrGetIrq(&xDma, XAXIDMA_DEVICE_TO_DMA) & + XAXIDMA_IRQ_IOC_MASK)) + c.interrupts = irqs[s2mmInterrupt].irqController->waitForInterrupt( + irqs[s2mmInterrupt]); + + hwReadLock.lock(); + XAxiDma_IntrAckIrq(&xDma, XAXIDMA_IRQ_IOC_MASK, XAXIDMA_DEVICE_TO_DMA); + + const XAxiDma_BdRing *ring = XAxiDma_GetRxRing(&xDma); + const size_t bytesRead = + XAxiDma_ReadReg(ring->ChanBase, XAXIDMA_BUFFLEN_OFFSET); + hwReadLock.unlock(); + + c.bytes = bytesRead; + return c; +} + +void Dma::makeAccesibleFromVA(std::shared_ptr mem) { + // Only symmetric mapping supported currently + if (isMemoryBlockAccesible(*mem, s2mmInterface) and + isMemoryBlockAccesible(*mem, mm2sInterface)) + return; + + // Try mapping via FPGA-card (VFIO) + if (not card->mapMemoryBlock(mem)) + throw RuntimeError("Memory not accessible by DMA"); + + // Sanity-check if mapping worked, this shouldn't be neccessary + if (not isMemoryBlockAccesible(*mem, s2mmInterface) or + not isMemoryBlockAccesible(*mem, mm2sInterface)) + throw RuntimeError( + "Mapping memory via card didn't work, but reported success?!"); +} + +bool Dma::isMemoryBlockAccesible(const MemoryBlock &mem, + const std::string &interface) { + auto &mm = MemoryManager::get(); + + try { + mm.findPath(getMasterAddrSpaceByInterface(interface), mem.getAddrSpaceId()); + } catch (const std::out_of_range &) { + return false; // Not (yet) accessible + } + + return true; +} + +void Dma::dump() { + Core::dump(); + + logger->info( + "S2MM_DMACR: {:x}", + XAxiDma_ReadReg(xDma.RegBase, XAXIDMA_RX_OFFSET + XAXIDMA_CR_OFFSET)); + logger->info( + "S2MM_DMASR: {:x}", + XAxiDma_ReadReg(xDma.RegBase, XAXIDMA_RX_OFFSET + XAXIDMA_SR_OFFSET)); + + if (!hasScatterGather()) + logger->info("S2MM_LENGTH: {:x}", + XAxiDma_ReadReg(xDma.RegBase, + XAXIDMA_RX_OFFSET + XAXIDMA_BUFFLEN_OFFSET)); + + logger->info( + "MM2S_DMACR: {:x}", + XAxiDma_ReadReg(xDma.RegBase, XAXIDMA_TX_OFFSET + XAXIDMA_CR_OFFSET)); + logger->info( + "MM2S_DMASR: {:x}", + XAxiDma_ReadReg(xDma.RegBase, XAXIDMA_TX_OFFSET + XAXIDMA_SR_OFFSET)); +} + +void DmaFactory::parse(Core &ip, json_t *cfg) { + NodeFactory::parse(ip, cfg); + + auto &dma = dynamic_cast(ip); + + dma.polling = dma.card->polling; + // Sensible default configuration + dma.xConfig.HasStsCntrlStrm = 0; + dma.xConfig.HasMm2S = 1; + dma.xConfig.HasMm2SDRE = 0; + dma.xConfig.Mm2SDataWidth = 32; + dma.xConfig.HasS2Mm = 1; + dma.xConfig.HasS2MmDRE = 0; + dma.xConfig.HasSg = 1; + dma.xConfig.S2MmDataWidth = 32; + dma.xConfig.Mm2sNumChannels = 1; + dma.xConfig.S2MmNumChannels = 1; + dma.xConfig.Mm2SBurstSize = 16; + dma.xConfig.S2MmBurstSize = 16; + dma.xConfig.MicroDmaMode = 0; + dma.xConfig.AddrWidth = 32; + dma.xConfig.SgLengthWidth = 14; + + json_error_t err; + int ret = json_unpack_ex( + cfg, &err, 0, + "{ s: { s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, " + "s?: i, s?: i, s?: i, s?: i } }", + "parameters", "c_sg_include_stscntrl_strm", &dma.xConfig.HasStsCntrlStrm, + "c_include_mm2s", &dma.xConfig.HasMm2S, "c_include_mm2s_dre", + &dma.xConfig.HasMm2SDRE, "c_m_axi_mm2s_data_width", + &dma.xConfig.Mm2SDataWidth, "c_include_s2mm", &dma.xConfig.HasS2Mm, + "c_include_s2mm_dre", &dma.xConfig.HasS2MmDRE, "c_m_axi_s2mm_data_width", + &dma.xConfig.S2MmDataWidth, "c_include_sg", &dma.xConfig.HasSg, + "c_num_mm2s_channels", &dma.xConfig.Mm2sNumChannels, + "c_num_s2mm_channels", &dma.xConfig.S2MmNumChannels, "c_micro_dma", + &dma.xConfig.MicroDmaMode, "c_addr_width", &dma.xConfig.AddrWidth, + "c_sg_length_width", &dma.xConfig.SgLengthWidth); + if (ret != 0) + throw ConfigError(cfg, err, "", "Failed to parse DMA configuration"); + + dma.configDone = true; +} + +static DmaFactory f; diff --git a/fpga/lib/ips/emc.cpp b/fpga/lib/ips/emc.cpp new file mode 100644 index 000000000..a4b34f9d5 --- /dev/null +++ b/fpga/lib/ips/emc.cpp @@ -0,0 +1,145 @@ +/* AXI External Memory Controller (EMC) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +using namespace villas::fpga::ip; + +bool EMC::init() { + int ret; + const uintptr_t base = getBaseAddr(registerMemory); + + const int busWidth = 2; + +#if defined(XPAR_XFL_DEVICE_FAMILY_INTEL) && XFL_TO_ASYNCMODE + // Set Flash to Async mode. + if (busWidth == 1) { + WRITE_FLASH_8(base + ASYNC_ADDR, 0x60); + WRITE_FLASH_8(base + ASYNC_ADDR, 0x03); + } else if (busWidth == 2) { + WRITE_FLASH_16(base + ASYNC_ADDR, INTEL_CMD_CONFIG_REG_SETUP); + WRITE_FLASH_16(base + ASYNC_ADDR, INTEL_CMD_CONFIG_REG_CONFIRM); + } +#endif + + ret = XFlash_Initialize(&xflash, base, busWidth, 0); + if (ret != XST_SUCCESS) + return false; + + return XFlash_IsReady(&xflash); +} + +bool EMC::read(uint32_t offset, uint32_t length, uint8_t *data) { + int ret; + + /* Reset the Flash Device. This clears the ret registers and puts + * the device in Read mode. + */ + ret = XFlash_Reset(&xflash); + if (ret != XST_SUCCESS) + return false; + + // Perform the read operation. + ret = XFlash_Read(&xflash, offset, length, data); + if (ret != XST_SUCCESS) + return false; + + return false; +} + +// objcopy -I ihex -O binary somefile.mcs somefile.bin + +bool EMC::flash(uint32_t offset, const std::string &filename) { + bool result; + uint32_t length; + uint8_t *buffer; + + std::ifstream is(filename, std::ios::binary); + + // Get length of file: + is.seekg(0, std::ios::end); + length = is.tellg(); + + is.seekg(0, std::ios::beg); + // Allocate memory: + + buffer = new uint8_t[length]; + is.read(reinterpret_cast(buffer), length); + is.close(); + + result = flash(offset, length, buffer); + + delete[] buffer; + + return result; +} + +// Based on xilflash_readwrite_example.c +bool EMC::flash(uint32_t offset, uint32_t length, uint8_t *data) { + int ret = XST_FAILURE; + uint32_t start = offset; + + /* Reset the Flash Device. This clears the ret registers and puts + * the device in Read mode. */ + ret = XFlash_Reset(&xflash); + if (ret != XST_SUCCESS) { + return false; + } + + /* Perform an unlock operation before the erase operation for the Intel + * Flash. The erase operation will result in an error if the block is + * locked. */ + if ((xflash.CommandSet == XFL_CMDSET_INTEL_STANDARD) || + (xflash.CommandSet == XFL_CMDSET_INTEL_EXTENDED) || + (xflash.CommandSet == XFL_CMDSET_INTEL_G18)) { + ret = XFlash_Unlock(&xflash, offset, 0); + if (ret != XST_SUCCESS) { + return false; + } + } + + // Perform the Erase operation. + ret = XFlash_Erase(&xflash, start, length); + if (ret != XST_SUCCESS) { + ; + return false; + } + + // Perform the Write operation. + ret = XFlash_Write(&xflash, start, length, data); + if (ret != XST_SUCCESS) { + return false; + } + + // Perform the read operation. + uint8_t *verify_data = new uint8_t[length]; + ret = XFlash_Read(&xflash, start, length, verify_data); + if (ret != XST_SUCCESS) { + delete[] verify_data; + return false; + } + + // Compare the data read against the data Written. + for (unsigned i = 0; i < length; i++) { + if (verify_data[i] != data[i]) { + delete[] verify_data; + return false; + } + } + + delete[] verify_data; + + return true; +} + +static char n[] = "emc"; +static char d[] = "Xilinx's AXI External Memory Controller"; +static char v[] = "xilinx.com:ip:axi_emc:"; +static CorePlugin f; diff --git a/fpga/lib/ips/fifo.cpp b/fpga/lib/ips/fifo.cpp new file mode 100644 index 000000000..fcc95bcdc --- /dev/null +++ b/fpga/lib/ips/fifo.cpp @@ -0,0 +1,98 @@ +/* FIFO related helper functions + * + * These functions present a simpler interface to Xilinx' FIFO driver (XLlFifo_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include +#include + +using namespace villas::fpga::ip; + +bool Fifo::init() { + XLlFifo_Config fifo_cfg; + + try { + // If this throws an exception, then there's no AXI4 data interface + fifo_cfg.Axi4BaseAddress = getBaseAddr(axi4Memory); + fifo_cfg.Datainterface = 1; + } catch (const std::out_of_range &) { + fifo_cfg.Datainterface = 0; + } + + if (XLlFifo_CfgInitialize(&xFifo, &fifo_cfg, getBaseAddr(registerMemory)) != + XST_SUCCESS) + return false; + + if (irqs.find(irqName) == irqs.end()) { + logger->error("IRQ '{}' not found but required", irqName); + return false; + } + + // Receive complete IRQ + XLlFifo_IntEnable(&xFifo, XLLF_INT_RC_MASK); + irqs[irqName].irqController->enableInterrupt(irqs[irqName], false); + + return true; +} + +bool Fifo::stop() { + // Receive complete IRQ + XLlFifo_IntDisable(&xFifo, XLLF_INT_RC_MASK); + irqs[irqName].irqController->disableInterrupt(irqs[irqName]); + + return true; +} + +size_t Fifo::write(const void *buf, size_t len) { + + uint32_t tdfv; + + tdfv = XLlFifo_TxVacancy(&xFifo); + if (tdfv < len) + return -1; + + // Buf has to be re-casted because Xilinx driver doesn't use const + XLlFifo_Write(&xFifo, (void *)buf, len); + XLlFifo_TxSetLen(&xFifo, len); + + return len; +} + +size_t Fifo::read(void *buf, size_t len) { + size_t nextlen = 0; + size_t rxlen; + + while (!XLlFifo_IsRxDone(&xFifo)) + irqs[irqName].irqController->waitForInterrupt(irqs[irqName]); + + XLlFifo_IntClear(&xFifo, XLLF_INT_RC_MASK); + + // Get length of next frame + rxlen = XLlFifo_RxGetLen(&xFifo); + nextlen = std::min(rxlen, len); + + // Read from FIFO + XLlFifo_Read(&xFifo, buf, nextlen); + + return nextlen; +} + +static char n1[] = "fifo"; +static char d1[] = "Xilinx's AXI4 FIFO data mover"; +static char v1[] = "xilinx.com:ip:axi_fifo_mm_s:"; +static NodePlugin p1; + +static char n2[] = "fifo_data"; +static char d2[] = "Xilinx's AXI4 data stream FIFO"; +static char v2[] = "xilinx.com:ip:axis_data_fifo:"; +static NodePlugin p2; diff --git a/fpga/lib/ips/gpio.cpp b/fpga/lib/ips/gpio.cpp new file mode 100644 index 000000000..b3abb42bf --- /dev/null +++ b/fpga/lib/ips/gpio.cpp @@ -0,0 +1,23 @@ +/* AXI General Purpose IO (GPIO) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +using namespace villas::fpga::ip; + +bool Gpio::init() { + //const uintptr_t base = getBaseAddr(registerMemory); + + return true; +} + +static char n[] = "gpio"; +static char d[] = "Xilinx's AXI4 general purpose IO"; +static char v[] = "xilinx.com:ip:axi_gpio:"; +static CorePlugin f; diff --git a/fpga/lib/ips/i2c.cpp b/fpga/lib/ips/i2c.cpp new file mode 100644 index 000000000..6243f73cf --- /dev/null +++ b/fpga/lib/ips/i2c.cpp @@ -0,0 +1,337 @@ +/* I2C driver + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +I2c::I2c() + : Node(), transmitIntrs(0), receiveIntrs(0), statusIntrs(0), xIic(), + xConfig(), hwLock(), configDone(false), initDone(false), polling(false), + switchInstance(nullptr) {} + +I2c::~I2c() {} + +static void SendHandler(I2c *i2c, __attribute__((unused)) int bytesSend) { + i2c->transmitIntrs++; +} +static void ReceiveHandler(I2c *i2c, __attribute__((unused)) int bytesSend) { + i2c->receiveIntrs++; +} +static void StatusHandler(I2c *i2c, __attribute__((unused)) int event) { + i2c->statusIntrs++; +} + +bool I2c::init() { + int ret; + if (!configDone) { + throw RuntimeError("I2C configuration not done"); + } + if (initDone) { + logger->warn("I2C already initialized"); + return true; + } + xConfig.BaseAddress = getBaseAddr(registerMemory); + logger->debug("I2C base address: {:#x}", xConfig.BaseAddress); + hwLock.lock(); + ret = XIic_CfgInitialize(&xIic, &xConfig, xConfig.BaseAddress); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to initialize I2C"); + } + + XIic_SetSendHandler(&xIic, this, (XIic_Handler)SendHandler); + XIic_SetRecvHandler(&xIic, this, (XIic_Handler)ReceiveHandler); + XIic_SetStatusHandler(&xIic, this, (XIic_StatusHandler)StatusHandler); + + irqs[i2cInterrupt].irqController->enableInterrupt(irqs[i2cInterrupt], + 0); //polling); + hwLock.unlock(); + initDone = true; + return true; +} + +bool I2c::check() { + if (!initDone) { + throw RuntimeError("I2C not initialized"); + } + return getSwitch().selfTest(); +} + +bool I2c::stop() { return reset(); } + +bool I2c::reset() { + logger->debug("I2C reset"); + // we cannot lock here because this may be called in a destructor + XIic_Reset(&xIic); + irqs[i2cInterrupt].irqController->disableInterrupt(irqs[i2cInterrupt]); + initDone = false; + return true; +} + +void I2c::driverWriteBlocking(u8 *dataPtr, size_t size) { + int ret; + int intrRetries; + int sendRetries = 10; + int bbRetries; + transmitIntrs = 0; + // We retry the entire transmission a few times before giving up. + while (transmitIntrs == 0 && sendRetries > 0) { + xIic.Stats.TxErrors = 0; + bbRetries = 1; + intrRetries = 10; + // We retry once when the bus is busy. + do { + ret = XIic_MasterSend(&xIic, dataPtr, size); + if (ret == XST_IIC_BUS_BUSY) { + waitForBusNotBusy(); + } else if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to send I2C data. code: {}", ret); + } + } while (ret == XST_IIC_BUS_BUSY && --bbRetries >= 0); + // We need to wait for several interrupts as sending the stop condition involves generating + // multiple interrupts before the transmission is complete. + while (transmitIntrs == 0 && intrRetries > 0) { + ssize_t intrs = irqs[i2cInterrupt].irqController->waitForInterrupt( + irqs[i2cInterrupt].num); + if (intrs == -1) { + break; + } + // logger->trace("I2C write interrupt eventfd read: {}, ISR: {}", numIntr, + // irqStatus); + XIic_InterruptHandler(&xIic); + --intrRetries; + } + --sendRetries; + } + if (sendRetries == 0) { + throw RuntimeError( + "Failed to send I2C data: No transmit interrupt after 10 tries."); + } + if (xIic.Stats.TxErrors > 0) { + throw RuntimeError("Failed to send I2C data: {} TX errors", + xIic.Stats.TxErrors); + } +} + +void I2c::driverReadBlocking(u8 *dataPtr, size_t max_read) { + int ret; + int intrRetries; + int readRetries = 10; + int bbRetries; + receiveIntrs = 0; + while (receiveIntrs == 0 && readRetries > 0) { + intrRetries = 10; + bbRetries = 1; + do { + ret = XIic_MasterRecv(&xIic, dataPtr, max_read); + if (ret == XST_IIC_BUS_BUSY) { + waitForBusNotBusy(); + } else if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to receive I2C data: code {}", ret); + } + } while (ret == XST_IIC_BUS_BUSY && --bbRetries >= 0); + while (receiveIntrs == 0 && intrRetries > 0) { + ssize_t intrs = irqs[i2cInterrupt].irqController->waitForInterrupt( + irqs[i2cInterrupt].num); + if (intrs == -1) { + break; + } + XIic_InterruptHandler(&xIic); + --intrRetries; + } + --readRetries; + } + if (readRetries == 0) { + throw RuntimeError( + "Failed to receive I2C data: No receive interrupt after 10 tries."); + } +} + +void I2c::waitForBusNotBusy() { + int retries = 10; + uint32_t irqStatus; + do { + irqs[i2cInterrupt].irqController->waitForInterrupt(irqs[i2cInterrupt].num); + irqStatus = + XIic_ReadIisr(xIic.BaseAddress) & XIic_ReadIier(xIic.BaseAddress); + } while (!(irqStatus & XIIC_INTR_BNB_MASK) && --retries > 0); + // logger->trace("I2C bus not busy after {} interrupts", 10 - retries); + //Deactivate BusNotBusy interrupt + XIic_WriteIier(xIic.BaseAddress, + XIic_ReadIier(xIic.BaseAddress) & ~(XIIC_INTR_BNB_MASK)); + uint32_t clear = XIIC_INTR_BNB_MASK; + XIic_WriteIisr(xIic.BaseAddress, clear); + if (retries == 0) { + throw RuntimeError("I2C bus stayed busy after 10 interrupts"); + } +} + +bool I2c::write(u8 address, std::vector &data) { + int ret; + + if (!initDone) { + throw RuntimeError("I2C not initialized"); + } + + hwLock.lock(); + ret = + XIic_SetAddress(&xIic, XII_ADDR_TO_SEND_TYPE, static_cast(address)); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to set I2C address"); + } + + ret = XIic_Start(&xIic); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to start I2C"); + } + + driverWriteBlocking(data.data(), data.size()); + + ret = XIic_Stop(&xIic); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to stop I2C"); + } + hwLock.unlock(); + return true; +} + +bool I2c::read(u8 address, std::vector &data, size_t max_read) { + int ret; + + if (!initDone) { + throw RuntimeError("I2C not initialized"); + } + + data.resize(data.size() + max_read); + u8 *dataPtr = data.data() + data.size() - max_read; + + hwLock.lock(); + ret = + XIic_SetAddress(&xIic, XII_ADDR_TO_SEND_TYPE, static_cast(address)); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to set I2C address"); + } + + ret = XIic_Start(&xIic); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to start I2C"); + } + + driverReadBlocking(dataPtr, max_read); + + ret = XIic_Stop(&xIic); + if (ret != XST_SUCCESS) { + throw RuntimeError("Failed to stop I2C"); + } + hwLock.unlock(); + + return XST_SUCCESS; +} + +bool I2c::readRegister(u8 address, u8 reg, std::vector &data, + size_t max_read) { + + std::vector regData = {reg}; + bool ret; + ret = write(address, regData); + ret &= read(address, data, max_read); + return ret; +} + +static const uint8_t CHANNEL_MAP[] = I2C_SWITCH_CHANNEL_MAP; +void I2c::Switch::setChannel(uint8_t channel) { + if (channel >= sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0])) { + throw RuntimeError("Invalid channel number {}", channel); + } + this->channel = channel; + readOnce = true; + std::vector data = {CHANNEL_MAP[channel]}; + i2c->write(address, data); +} + +uint8_t I2c::Switch::getChannel() { + std::vector data; + int retries = 10; + do { + i2c->read(address, data, 1); + } while (readOnce && data[0] != CHANNEL_MAP[channel] && --retries >= 0); + if (retries == 0) { + throw RuntimeError( + "Invalid channel readback after 10 retries: {:x} != {:x}", data[0], + CHANNEL_MAP[channel]); + } + if (!readOnce) { + for (size_t i = 0; i < sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0]); ++i) { + if (data[0] == CHANNEL_MAP[i]) { + channel = i; + break; + } + } + readOnce = true; + } + return channel; +} + +bool I2c::Switch::selfTest() { + uint8_t readback; + logger->debug("I2c::Switch self test. Testing {} channels of device {:#x}", + sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0]), address); + for (size_t i = 0; i < sizeof(CHANNEL_MAP) / sizeof(CHANNEL_MAP[0]); ++i) { + logger->debug("Setting switch to channel {}, data byte {:#x}", i, + CHANNEL_MAP[i]); + setAndLockChannel(i); + try { + readback = getChannel(); + logger->debug("Readback channel: {}", readback); + } catch (const RuntimeError &e) { + logger->debug("Encoutered error on readback: {}", e.what()); + return false; + } + unlockChannel(); + } + return true; +} + +void I2cFactory::parse(Core &ip, json_t *cfg) { + NodeFactory::parse(ip, cfg); + + auto &i2c = dynamic_cast(ip); + + int i2c_frequency = 0; + char *component_name = nullptr; + + json_error_t err; + int ret = json_unpack_ex(cfg, &err, 0, "{ s: { s?: i, s?: i, s?: i, s?: s} }", + "parameters", "c_iic_freq", &i2c_frequency, + "c_ten_bit_adr", &i2c.xConfig.Has10BitAddr, + "c_gpo_width", &i2c.xConfig.GpOutWidth, + "component_name", &component_name); + if (ret != 0) { + throw ConfigError(cfg, err, "", "Failed to parse DMA configuration for {}", + ip.getInstanceName()); + } + if (component_name != nullptr) { + char last_letter = component_name[strlen(component_name) - 1]; + if (last_letter >= '0' && last_letter <= '9') { + i2c.xConfig.DeviceId = last_letter - '0'; + } else { + throw RuntimeError("Invalid device ID in component name {} for {}", + component_name, ip.getInstanceName()); + } + } + + i2c.configDone = true; +} + +static I2cFactory f; diff --git a/fpga/lib/ips/intc.cpp b/fpga/lib/ips/intc.cpp new file mode 100644 index 000000000..70b80f7df --- /dev/null +++ b/fpga/lib/ips/intc.cpp @@ -0,0 +1,169 @@ +/* AXI-PCIe Interrupt controller + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +InterruptController::~InterruptController() {} + +bool InterruptController::stop() { + return card->vfioDevice->pciMsiDeinit(this->efds) > 0; +} + +bool InterruptController::init() { + const uintptr_t base = getBaseAddr(registerMemory); + + num_irqs = card->vfioDevice->pciMsiInit(efds); + if (num_irqs < 0) + return false; + + if (not card->vfioDevice->pciMsiFind(nos)) { + return false; + } + + // For each IRQ + for (int i = 0; i < num_irqs; i++) { + + // Try pinning to core + PCIeCard *pciecard = dynamic_cast(card); + int ret = kernel::setIRQAffinity(nos[i], pciecard->affinity, nullptr); + + switch (ret) { + case 0: + // Everything is fine + break; + case EACCES: + logger->warn("No permission to change affinity of VFIO-MSI interrupt, " + "performance may be degraded!"); + break; + default: + logger->error("Failed to change affinity of VFIO-MSI interrupt"); + return false; + } + + // Setup vector + XIntc_Out32(base + XIN_IVAR_OFFSET + i * 4, i); + } + + XIntc_Out32(base + XIN_IMR_OFFSET, + 0x00000000); // Use manual acknowlegement for all IRQs + XIntc_Out32(base + XIN_IAR_OFFSET, + 0xFFFFFFFF); // Acknowlege all pending IRQs manually + XIntc_Out32(base + XIN_IMR_OFFSET, + 0xFFFFFFFF); // Use fast acknowlegement for all IRQs + XIntc_Out32(base + XIN_IER_OFFSET, 0x00000000); // Disable all IRQs by default + XIntc_Out32(base + XIN_MER_OFFSET, + XIN_INT_HARDWARE_ENABLE_MASK | XIN_INT_MASTER_ENABLE_MASK); + + logger->debug("enabled interrupts"); + + return true; +} + +bool InterruptController::enableInterrupt(InterruptController::IrqMaskType mask, + bool polling) { + const uintptr_t base = getBaseAddr(registerMemory); + + // Current state of INTC + const uint32_t ier = XIntc_In32(base + XIN_IER_OFFSET); + const uint32_t imr = XIntc_In32(base + XIN_IMR_OFFSET); + + // Clear pending IRQs + XIntc_Out32(base + XIN_IAR_OFFSET, mask); + + for (int i = 0; i < num_irqs; i++) { + if (mask & (1 << i)) + this->polling[i] = polling; + } + + if (polling) { + XIntc_Out32(base + XIN_IMR_OFFSET, imr & ~mask); + XIntc_Out32(base + XIN_IER_OFFSET, ier & ~mask); + } else { + XIntc_Out32(base + XIN_IER_OFFSET, ier | mask); + XIntc_Out32(base + XIN_IMR_OFFSET, imr | mask); + } + + logger->debug("New ier = {:x}", XIntc_In32(base + XIN_IER_OFFSET)); + logger->debug("New imr = {:x}", XIntc_In32(base + XIN_IMR_OFFSET)); + logger->debug("New isr = {:x}", XIntc_In32(base + XIN_ISR_OFFSET)); + logger->debug("Interupts enabled: mask={:x} polling={:d}", mask, polling); + + return true; +} + +bool InterruptController::disableInterrupt( + InterruptController::IrqMaskType mask) { + const uintptr_t base = getBaseAddr(registerMemory); + uint32_t ier = XIntc_In32(base + XIN_IER_OFFSET); + + XIntc_Out32(base + XIN_IER_OFFSET, ier & ~mask); + + return true; +} + +ssize_t InterruptController::waitForInterrupt(int irq) { + assert(irq < maxIrqs); + + if (this->polling[irq]) { + const uintptr_t base = getBaseAddr(registerMemory); + uint32_t isr, mask = 1 << irq; + + do { + // Poll status register + isr = XIntc_In32(base + XIN_ISR_OFFSET); + pthread_testcancel(); + } while ((isr & mask) != mask); + + // Acknowledge interrupt + XIntc_Out32(base + XIN_IAR_OFFSET, mask); + + // We can only tell that there has been (at least) one interrupt + return 1; + } else { + uint64_t count; + int sret; + fd_set rfds; + struct timeval tv = {.tv_sec = 1, .tv_usec = 0}; + FD_ZERO(&rfds); + FD_SET(efds[irq], &rfds); + + sret = select(efds[irq] + 1, &rfds, NULL, NULL, &tv); + if (sret == -1) { + logger->error("select() failed: {}", strerror(errno)); + return -1; + } else if (sret == 0) { + logger->warn("timeout waiting for interrupt {}", irq); + + return -1; + } + // Block until there has been an interrupt, read number of interrupts + ssize_t ret = read(efds[irq], &count, sizeof(count)); + if (ret != sizeof(count)) { + logger->error("Failed to read from eventfd: {}", strerror(errno)); + return -1; + } + + return count; + } +} + +static char n[] = "intc"; +static char d[] = "Xilinx's programmable interrupt controller"; +static char v[] = "xilinx.com:module_ref:axi_pcie_intc:"; +static CorePlugin f; diff --git a/fpga/lib/ips/pcie.cpp b/fpga/lib/ips/pcie.cpp new file mode 100644 index 000000000..17529a41b --- /dev/null +++ b/fpga/lib/ips/pcie.cpp @@ -0,0 +1,142 @@ +/* AXI PCIe bridge + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +bool AxiPciExpressBridge::init() { + auto &mm = MemoryManager::get(); + + // Throw an exception if the is no bus master interface and thus no + // address space we can use for translation -> error + card->addrSpaceIdHostToDevice = busMasterInterfaces.at(getAxiInterfaceName()); + + // Map PCIe BAR0 via VFIO + const void *bar0_mapped = + card->vfioDevice->regionMap(VFIO_PCI_BAR0_REGION_INDEX); + if (bar0_mapped == MAP_FAILED) { + logger->error("Failed to mmap() BAR0"); + return false; + } + + // Determine size of BAR0 region + const size_t bar0_size = + card->vfioDevice->regionGetSize(VFIO_PCI_BAR0_REGION_INDEX); + + // Create a mapping from process address space to the FPGA card via vfio + mm.createMapping(reinterpret_cast(bar0_mapped), 0, bar0_size, + "vfio-h2d", mm.getProcessAddressSpace(), + card->addrSpaceIdHostToDevice); + + // Make PCIe (IOVA) address space available to FPGA via BAR0 + + // IPs that can access this address space will know it via their memory view + const auto addrSpaceNameDeviceToHost = + mm.getSlaveAddrSpaceName(getInstanceName(), pcieMemory); + + // Save ID in card so we can create mappings later when needed (e.g. when + // allocating DMA memory in host RAM) + card->addrSpaceIdDeviceToHost = + mm.getOrCreateAddressSpace(addrSpaceNameDeviceToHost); + + auto pciAddrSpaceId = mm.getPciAddressSpace(); + + auto regions = dynamic_cast(card)->pdev->getRegions(); + + int i = 0; + for (auto region : regions) { + const size_t region_size = region.end - region.start + 1; + + char barName[] = "BARx"; + barName[3] = '0' + region.num; + auto pciBar = pcieToAxiTranslations.at(barName); + + logger->info("PCI-BAR{}: bus addr={:#x} size={:#x}", region.num, + region.start, region_size); + logger->info("PCI-BAR{}: AXI translation offset {:#x}", i, + pciBar.translation); + + mm.createMapping(region.start, pciBar.translation, region_size, + std::string("PCI-") + barName, pciAddrSpaceId, + card->addrSpaceIdHostToDevice); + } + + for (auto &[barName, axiBar] : axiToPcieTranslations) { + logger->info("AXI-{}: bus addr={:#x} size={:#x}", barName, axiBar.base, + axiBar.size); + logger->info("AXI-{}: PCI translation offset: {:#x}", barName, + axiBar.translation); + + auto barXAddrSpaceName = + mm.getSlaveAddrSpaceName(getInstanceName(), barName); + auto barXAddrSpaceId = mm.getOrCreateAddressSpace(barXAddrSpaceName); + + // Base is already incorporated into mapping of each IP by Vivado, so + // the mapping src has to be 0 + mm.createMapping(0, axiBar.translation, axiBar.size, + std::string("AXI-") + barName, barXAddrSpaceId, + pciAddrSpaceId); + + i++; + } + + return true; +} + +void AxiPciExpressBridgeFactory::parse(Core &ip, json_t *cfg) { + CoreFactory::parse(ip, cfg); + + auto logger = getLogger(); + auto &pcie = dynamic_cast(ip); + + for (auto barType : std::list{"axi_bars", "pcie_bars"}) { + json_t *json_bars = json_object_get(cfg, barType.c_str()); + if (not json_is_object(json_bars)) + throw ConfigError(cfg, "", "Missing BAR config: {}", barType); + + json_t *json_bar; + const char *bar_name; + json_object_foreach(json_bars, bar_name, json_bar) { + unsigned int translation; + + json_error_t err; + int ret = json_unpack_ex(json_bar, &err, 0, "{ s: i }", "translation", + &translation); + if (ret != 0) + throw ConfigError(json_bar, err, "", "Cannot parse {}/{}", barType, + bar_name); + + if (barType == "axi_bars") { + json_int_t base, high, size; + int ret = + json_unpack_ex(json_bar, &err, 0, "{ s: I, s: I, s: I }", + "baseaddr", &base, "highaddr", &high, "size", &size); + if (ret != 0) + throw ConfigError(json_bar, err, "", "Cannot parse {}/{}", barType, + bar_name); + + pcie.axiToPcieTranslations[bar_name] = { + .base = static_cast(base), + .size = static_cast(size), + .translation = translation}; + } else + pcie.pcieToAxiTranslations[bar_name] = {.translation = translation}; + } + } +} + +static AxiPciExpressBridgeFactory p; +static XDmaBridgeFactory p2; diff --git a/fpga/lib/ips/register.cpp b/fpga/lib/ips/register.cpp new file mode 100644 index 000000000..a58ab5c4f --- /dev/null +++ b/fpga/lib/ips/register.cpp @@ -0,0 +1,105 @@ +/* Driver for register interface 'registerif' + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2024 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +using namespace villas::fpga::ip; + +#define REGISTER_RESET (512) +#define REGISTER_OUT(NUM) (4 * NUM) + +Register::Register() : Node() {} + +bool Register::init() { return true; } + +bool Register::check() { + + logger->debug("Checking register interface: Base address: 0x{:08x}", + getBaseAddr(registerMemory)); + uint32_t buf; + // we shouldn't change the rate register, because this can lead to hardware fault, so start at 1 + for (size_t i = 1; i < registerNum; i++) { + setRegister(i, static_cast(i)); + } + + for (size_t i = 1; i < registerNum; i++) { + buf = getRegister(i); + if (buf != i) { + logger->error("Register {}: 0x{:08x} != 0x{:08x}", i, buf, i); + return false; + } + } + + resetAllRegisters(); + + for (size_t i = 0; i < registerNum; i++) { + logger->debug("Register {}: 0x{:08x}", i, getRegister(i)); + } + + return true; +} + +void Register::setRegister(size_t reg, uint32_t value) { + if (reg >= registerNum) { + logger->error("Register index out of range: {}/{}", reg, registerNum); + throw std::out_of_range("Register index out of range"); + } + Xil_Out32(getBaseAddr(registerMemory) + REGISTER_OUT(reg), value); +} + +void Register::setRegister(size_t reg, float value) { + if (reg >= registerNum) { + logger->error("Register index out of range: {}/{}", reg, registerNum); + throw std::out_of_range("Register index out of range"); + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + Xil_Out32(getBaseAddr(registerMemory) + REGISTER_OUT(reg), + reinterpret_cast(value)); +#pragma GCC diagnostic pop +} + +uint32_t Register::getRegister(size_t reg) { + if (reg >= registerNum) { + logger->error("Register index out of range: {}/{}", reg, registerNum); + throw std::out_of_range("Register index out of range"); + } + return Xil_In32(getBaseAddr(registerMemory) + REGISTER_OUT(reg)); +} + +float Register::getRegisterFloat(size_t reg) { + if (reg >= registerNum) { + logger->error("Register index out of range: {}/{}", reg, registerNum); + throw std::out_of_range("Register index out of range"); + } + uint32_t value = Xil_In32(getBaseAddr(registerMemory) + REGISTER_OUT(reg)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + return reinterpret_cast(value); +#pragma GCC diagnostic pop +} + +void Register::resetRegister(size_t reg) { + if (reg >= registerNum) { + logger->error("Register index out of range: {}/{}", reg, registerNum); + throw std::out_of_range("Register index out of range"); + } + Xil_Out32(getBaseAddr(registerMemory) + REGISTER_RESET, (1 << reg)); +} + +void Register::resetAllRegisters() { + Xil_Out32(getBaseAddr(registerMemory) + REGISTER_RESET, 0xFFFFFFFF); +} + +Register::~Register() {} + +static char n[] = "register"; +static char d[] = "Register interface VHDL module 'registerif'"; +static char v[] = "xilinx.com:module_ref:registerif:"; +static CorePlugin f; diff --git a/fpga/lib/ips/rtds.cpp b/fpga/lib/ips/rtds.cpp new file mode 100644 index 000000000..78f266572 --- /dev/null +++ b/fpga/lib/ips/rtds.cpp @@ -0,0 +1,99 @@ +/* Driver for AXI Stream wrapper around RTDS_InterfaceModule (rtds_axis ) + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include + +#define RTDS_HZ 100000000 // 100 MHz + +#define RTDS_AXIS_MAX_TX \ + 64 // The amount of values which is supported by the VIILASfpga card +#define RTDS_AXIS_MAX_RX \ + 64 // The amount of values which is supported by the VIILASfpga card + +// Register offsets +#define RTDS_AXIS_SR_OFFSET \ + 0x00 // Status Register (read-only). See RTDS_AXIS_SR_* constant. +#define RTDS_AXIS_CR_OFFSET 0x04 // Control Register (read/write) +#define RTDS_AXIS_TSCNT_LOW_OFFSET \ + 0x08 // Lower 32 bits of timestep counter (read-only). +#define RTDS_AXIS_TSCNT_HIGH_OFFSET \ + 0x0C // Higher 32 bits of timestep counter (read-only). +#define RTDS_AXIS_TS_PERIOD_OFFSET \ + 0x10 // Period in clock cycles of previous timestep (read-only). +#define RTDS_AXIS_COALESC_OFFSET 0x14 // IRQ Coalescing register (read/write). +#define RTDS_AXIS_VERSION_OFFSET \ + 0x18 // 16 bit version field passed back to the rack for version reporting (visible from “status” command, read/write). +#define RTDS_AXIS_MRATE 0x1C // Multi-rate register + +// Status register bits +#define RTDS_AXIS_SR_CARDDETECTED \ + (1 << 0) // ‘1’ when RTDS software has detected and configured card. +#define RTDS_AXIS_SR_LINKUP \ + (1 << 1) // ‘1’ when RTDS communication link has been negotiated. +#define RTDS_AXIS_SR_TX_FULL \ + (1 \ + << 2) // Tx buffer is full, writes that happen when UserTxFull=’1’ will be dropped (Throttling / buffering is performed by hardware). +#define RTDS_AXIS_SR_TX_INPROGRESS \ + (1 << 3) // Indicates when data is being put on link. +#define RTDS_AXIS_SR_CASE_RUNNING \ + (1 << 4) // There is currently a simulation running. + +// Control register bits +#define RTDS_AXIS_CR_DISABLE_LINK 0 // Disable SFP TX when set + +using namespace villas::fpga::ip; + +void RtdsGtfpga::dump() { + // Check RTDS_Axis registers + const uint32_t sr = readMemory(registerMemory, RTDS_AXIS_SR_OFFSET); + + logger->info("RTDS AXI Stream interface details:"); + logger->info("RTDS status: {:#x}", sr); + logger->info(" Card detected: {}", + sr & RTDS_AXIS_SR_CARDDETECTED ? CLR_GRN("yes") : CLR_RED("no")); + logger->info(" Link up: {}", + sr & RTDS_AXIS_SR_LINKUP ? CLR_GRN("yes") : CLR_RED("no")); + logger->info(" TX queue full: {}", + sr & RTDS_AXIS_SR_TX_FULL ? CLR_RED("yes") : CLR_GRN("no")); + logger->info(" TX in progress: {}", + sr & RTDS_AXIS_SR_TX_INPROGRESS ? CLR_YEL("yes") : "no"); + logger->info(" Case running: {}", + sr & RTDS_AXIS_SR_CASE_RUNNING ? CLR_GRN("yes") : CLR_RED("no")); + + logger->info("RTDS control: {:#x}", + readMemory(registerMemory, RTDS_AXIS_CR_OFFSET)); + logger->info("RTDS IRQ coalesc: {}", + readMemory(registerMemory, RTDS_AXIS_COALESC_OFFSET)); + logger->info("RTDS IRQ version: {:#x}", + readMemory(registerMemory, RTDS_AXIS_VERSION_OFFSET)); + logger->info("RTDS IRQ multi-rate: {}", + readMemory(registerMemory, RTDS_AXIS_MRATE)); + + const uint64_t timestepLow = + readMemory(registerMemory, RTDS_AXIS_TSCNT_LOW_OFFSET); + const uint64_t timestepHigh = + readMemory(registerMemory, RTDS_AXIS_TSCNT_HIGH_OFFSET); + const uint64_t timestep = (timestepHigh << 32) | timestepLow; + + logger->info("RTDS timestep counter: {}", timestep); + logger->info("RTDS timestep period: {:.3f} us", getDt() * 1e6); +} + +double RtdsGtfpga::getDt() { + const auto dt = + readMemory(registerMemory, RTDS_AXIS_TS_PERIOD_OFFSET); + return (dt == 0xFFFF) ? 0.0 : (double)dt / RTDS_HZ; +} + +static char n[] = "rtds_gtfpga"; +static char d[] = "RTDS's AXI4-Stream - GTFPGA interface"; +static char v[] = "acs.eonerc.rwth-aachen.de:user:rtds_axis:"; +static NodePlugin f; diff --git a/fpga/lib/ips/rtds2gpu/gpu2rtds.cpp b/fpga/lib/ips/rtds2gpu/gpu2rtds.cpp new file mode 100644 index 000000000..ad0845854 --- /dev/null +++ b/fpga/lib/ips/rtds2gpu/gpu2rtds.cpp @@ -0,0 +1,141 @@ +/* GPU2RTDS IP core + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +bool Gpu2Rtds::init() { + Hls::init(); + + auto ®isters = addressTranslations.at(registerMemory); + + registerStatus = reinterpret_cast( + registers.getLocalAddr(registerStatusOffset)); + registerStatusCtrl = reinterpret_cast( + registers.getLocalAddr(registerStatusCtrlOffset)); + registerFrameSize = reinterpret_cast( + registers.getLocalAddr(registerFrameSizeOffset)); + registerFrames = + reinterpret_cast(registers.getLocalAddr(registerFrameOffset)); + + maxFrameSize = getMaxFrameSize(); + logger->info("Max. frame size supported: {}", maxFrameSize); + + return true; +} + +bool Gpu2Rtds::startOnce(size_t frameSize) { + *registerFrameSize = frameSize; + + start(); + + return true; +} + +void Gpu2Rtds::dump(spdlog::level::level_enum logLevel) { + const auto frame_size = *registerFrameSize; + auto status = *registerStatus; + + logger->log(logLevel, "Gpu2Rtds registers:"); + logger->log(logLevel, " Frame size (words): {:#x}", frame_size); + logger->log(logLevel, " Status: {:#x}", status.value); + logger->log(logLevel, " Running: {}", + (status.is_running ? "yes" : "no")); + logger->log(logLevel, " Frame too short: {}", + (status.frame_too_short ? "yes" : "no")); + logger->log(logLevel, " Frame too long: {}", + (status.frame_too_long ? "yes" : "no")); + logger->log(logLevel, " Frame size invalid: {}", + (status.invalid_frame_size ? "yes" : "no")); + logger->log(logLevel, " Last count: {}", (int)status.last_count); + logger->log(logLevel, " Last seq. number: {}", (int)status.last_seq_nr); + logger->log(logLevel, " Max. frame size: {}", + (int)status.max_frame_size); +} + +//bool Gpu2Rtds::startOnce(const MemoryBlock &mem, size_t frameSize, size_t dataOffset, size_t doorbellOffset) +//{ +// auto &mm = MemoryManager::get(); + +// if (frameSize > maxFrameSize) { +// logger->error("Requested frame size of {} exceeds max. frame size of {}", +// frameSize, maxFrameSize); +// return false; +// } + +// auto translationFromIp = mm.getTranslation( +// getMasterAddrSpaceByInterface(axiInterface), +// mem.getAddrSpaceId()); + +// // Set address of memory block in HLS IP +// XGpu2Rtds_Set_baseaddr(&xInstance, translationFromIp.getLocalAddr(0)); + +// XGpu2Rtds_Set_doorbell_offset(&xInstance, doorbellOffset); +// XGpu2Rtds_Set_data_offset(&xInstance, dataOffset); +// XGpu2Rtds_Set_frame_size(&xInstance, frameSize); + +// // Prepare memory with all zeroes +// auto translationFromProcess = mm.getTranslationFromProcess(mem.getAddrSpaceId()); +// auto memory = reinterpret_cast(translationFromProcess.getLocalAddr(0)); +// memset(memory, 0, mem.getSize()); + +// // Start IP +// return start(); +//} + +//bool +//Gpu2Rtds::updateStatus() +//{ +// if (not XGpu2Rtds_Get_status_vld(&xInstance)) +// return false; + +// status.value = XGpu2Rtds_Get_status(&xInstance); + +// return true; +//} + +size_t Gpu2Rtds::getMaxFrameSize() { + *registerFrameSize = 0; + + start(); + while (not isFinished()) + ; + + while (not registerStatusCtrl->status_ap_vld) + ; + + axilite_reg_status_t status = *registerStatus; + + // logger->debug("(*registerStatus).max_frame_size: {}", (*registerStatus).max_frame_size); + // logger->debug("status.max_frame_size: {}", status.max_frame_size); + + // assert(status.max_frame_size == (*registerStatus).max_frame_size); + + return status.max_frame_size; +} + +//void +//Gpu2Rtds::dumpDoorbell(uint32_t doorbellRegister) const +//{ +// auto &doorbell = reinterpret_cast(doorbellRegister); + +// logger->info("Doorbell register: {:#08x}", doorbell.value); +// logger->info(" Valid: {}", (doorbell.is_valid ? "yes" : "no")); +// logger->info(" Count: {}", doorbell.count); +// logger->info(" Seq. number: {}", (int) doorbell.seq_nr); +//} + +static char n[] = "gpu2rtds"; +static char d[] = "HLS Gpu2Rtds IP"; +static char v[] = "acs.eonerc.rwth-aachen.de:hls:gpu2rtds:"; +static NodePlugin p; diff --git a/fpga/lib/ips/rtds2gpu/rtds2gpu.cpp b/fpga/lib/ips/rtds2gpu/rtds2gpu.cpp new file mode 100644 index 000000000..7efb9c150 --- /dev/null +++ b/fpga/lib/ips/rtds2gpu/rtds2gpu.cpp @@ -0,0 +1,123 @@ +/* GPU2RTDS IP core + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +bool Rtds2Gpu::init() { + Hls::init(); + + xInstance.IsReady = XIL_COMPONENT_IS_READY; + xInstance.Ctrl_BaseAddress = getBaseAddr(registerMemory); + + status.value = 0; + started = false; + + // maxFrameSize = getMaxFrameSize(); + maxFrameSize = 16; + logger->info("Max. frame size supported: {}", maxFrameSize); + + return true; +} + +void Rtds2Gpu::dump(spdlog::level::level_enum logLevel) { + const auto baseaddr = XRtds2gpu_Get_baseaddr(&xInstance); + const auto data_offset = XRtds2gpu_Get_data_offset(&xInstance); + const auto doorbell_offset = XRtds2gpu_Get_doorbell_offset(&xInstance); + const auto frame_size = XRtds2gpu_Get_frame_size(&xInstance); + + logger->log(logLevel, "Rtds2Gpu registers (IP base {:#x}):", + xInstance.Ctrl_BaseAddress); + logger->log(logLevel, " Base address (bytes): {:#x}", baseaddr); + logger->log(logLevel, " Doorbell offset (bytes): {:#x}", doorbell_offset); + logger->log(logLevel, " Data offset (bytes): {:#x}", data_offset); + logger->log(logLevel, " Frame size (words): {:#x}", frame_size); + logger->log(logLevel, " Status: {:#x}", status.value); + logger->log(logLevel, " Running: {}", + (status.is_running ? "yes" : "no")); + logger->log(logLevel, " Frame too short: {}", + (status.frame_too_short ? "yes" : "no")); + logger->log(logLevel, " Frame too long: {}", + (status.frame_too_long ? "yes" : "no")); + logger->log(logLevel, " Frame size invalid: {}", + (status.invalid_frame_size ? "yes" : "no")); + logger->log(logLevel, " Last count: {}", (int)status.last_count); + logger->log(logLevel, " Last seq. number: {}", (int)status.last_seq_nr); + logger->log(logLevel, " Max. frame size: {}", + (int)status.max_frame_size); +} + +bool Rtds2Gpu::startOnce(const MemoryBlock &mem, size_t frameSize, + size_t dataOffset, size_t doorbellOffset) { + auto &mm = MemoryManager::get(); + + if (frameSize > maxFrameSize) { + logger->error("Requested frame size of {} exceeds max. frame size of {}", + frameSize, maxFrameSize); + return false; + } + + auto translationFromIp = mm.getTranslation( + getMasterAddrSpaceByInterface(axiInterface), mem.getAddrSpaceId()); + + // Set address of memory block in HLS IP + XRtds2gpu_Set_baseaddr(&xInstance, translationFromIp.getLocalAddr(0)); + + XRtds2gpu_Set_doorbell_offset(&xInstance, doorbellOffset); + XRtds2gpu_Set_data_offset(&xInstance, dataOffset); + XRtds2gpu_Set_frame_size(&xInstance, frameSize); + + // Prepare memory with all zeroes + auto translationFromProcess = + mm.getTranslationFromProcess(mem.getAddrSpaceId()); + auto memory = + reinterpret_cast(translationFromProcess.getLocalAddr(0)); + memset(memory, 0, mem.getSize()); + + // Start IP + return start(); +} + +bool Rtds2Gpu::updateStatus() { + if (not XRtds2gpu_Get_status_vld(&xInstance)) + return false; + + status.value = XRtds2gpu_Get_status(&xInstance); + + return true; +} + +size_t Rtds2Gpu::getMaxFrameSize() { + XRtds2gpu_Set_frame_size(&xInstance, 0); + + start(); + while (not isFinished()) + ; + updateStatus(); + + return status.max_frame_size; +} + +void Rtds2Gpu::dumpDoorbell(uint32_t doorbellRegister) const { + auto &doorbell = reinterpret_cast(doorbellRegister); + + logger->info("Doorbell register: {:#08x}", doorbell.value); + logger->info(" Valid: {}", doorbell.is_valid ? "yes" : "no"); + logger->info(" Count: {}", (int)doorbell.count); + logger->info(" Seq. number: {}", (int)doorbell.seq_nr); +} + +static char n[] = "Rtds2Gpu"; +static char d[] = "HLS RTDS2GPU IP"; +static char v[] = "acs.eonerc.rwth-aachen.de:hls:rtds2gpu:"; +static NodePlugin f; diff --git a/fpga/lib/ips/rtds2gpu/xrtds2gpu.c b/fpga/lib/ips/rtds2gpu/xrtds2gpu.c new file mode 100644 index 000000000..475c15b30 --- /dev/null +++ b/fpga/lib/ips/rtds2gpu/xrtds2gpu.c @@ -0,0 +1,246 @@ +// ============================================================== +// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC +// Version: 2017.3 +// SPDX-FileCopyrightText: 1986 Xilinx, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +// ============================================================== + +/***************************** Include Files *********************************/ +#include + +/************************** Function Implementation *************************/ +#ifndef __linux__ +int XRtds2gpu_CfgInitialize(XRtds2gpu *InstancePtr, + XRtds2gpu_Config *ConfigPtr) { + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(ConfigPtr != NULL); + + InstancePtr->Ctrl_BaseAddress = ConfigPtr->Ctrl_BaseAddress; + InstancePtr->IsReady = XIL_COMPONENT_IS_READY; + + return XST_SUCCESS; +} +#endif + +void XRtds2gpu_Start(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_AP_CTRL) & + 0x80; + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_AP_CTRL, + Data | 0x01); +} + +u32 XRtds2gpu_IsDone(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_AP_CTRL); + return (Data >> 1) & 0x1; +} + +u32 XRtds2gpu_IsIdle(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_AP_CTRL); + return (Data >> 2) & 0x1; +} + +u32 XRtds2gpu_IsReady(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_AP_CTRL); + // Check ap_start to see if the pcore is ready for next input + return !(Data & 0x1); +} + +void XRtds2gpu_EnableAutoRestart(XRtds2gpu *InstancePtr) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_AP_CTRL, + 0x80); +} + +void XRtds2gpu_DisableAutoRestart(XRtds2gpu *InstancePtr) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_AP_CTRL, + 0); +} + +void XRtds2gpu_Set_baseaddr(XRtds2gpu *InstancePtr, u32 Data) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_BASEADDR_DATA, Data); +} + +u32 XRtds2gpu_Get_baseaddr(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_BASEADDR_DATA); + return Data; +} + +void XRtds2gpu_Set_data_offset(XRtds2gpu *InstancePtr, u32 Data) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_DATA_OFFSET_DATA, Data); +} + +u32 XRtds2gpu_Get_data_offset(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_DATA_OFFSET_DATA); + return Data; +} + +void XRtds2gpu_Set_doorbell_offset(XRtds2gpu *InstancePtr, u32 Data) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_DOORBELL_OFFSET_DATA, Data); +} + +u32 XRtds2gpu_Get_doorbell_offset(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_DOORBELL_OFFSET_DATA); + return Data; +} + +void XRtds2gpu_Set_frame_size(XRtds2gpu *InstancePtr, u32 Data) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_FRAME_SIZE_DATA, Data); +} + +u32 XRtds2gpu_Get_frame_size(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_FRAME_SIZE_DATA); + return Data; +} + +u32 XRtds2gpu_Get_status(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_STATUS_DATA); + return Data; +} + +u32 XRtds2gpu_Get_status_vld(XRtds2gpu *InstancePtr) { + u32 Data; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Data = XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_STATUS_CTRL); + return Data & 0x1; +} + +void XRtds2gpu_InterruptGlobalEnable(XRtds2gpu *InstancePtr) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_GIE, 1); +} + +void XRtds2gpu_InterruptGlobalDisable(XRtds2gpu *InstancePtr) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_GIE, 0); +} + +void XRtds2gpu_InterruptEnable(XRtds2gpu *InstancePtr, u32 Mask) { + u32 Register; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Register = + XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_IER); + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_IER, + Register | Mask); +} + +void XRtds2gpu_InterruptDisable(XRtds2gpu *InstancePtr, u32 Mask) { + u32 Register; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + Register = + XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_IER); + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_IER, + Register & (~Mask)); +} + +void XRtds2gpu_InterruptClear(XRtds2gpu *InstancePtr, u32 Mask) { + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + XRtds2gpu_WriteReg(InstancePtr->Ctrl_BaseAddress, XRTDS2GPU_CTRL_ADDR_ISR, + Mask); +} + +u32 XRtds2gpu_InterruptGetEnabled(XRtds2gpu *InstancePtr) { + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + return XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_IER); +} + +u32 XRtds2gpu_InterruptGetStatus(XRtds2gpu *InstancePtr) { + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + return XRtds2gpu_ReadReg(InstancePtr->Ctrl_BaseAddress, + XRTDS2GPU_CTRL_ADDR_ISR); +} diff --git a/fpga/lib/ips/switch.cpp b/fpga/lib/ips/switch.cpp new file mode 100644 index 000000000..6f8e232ab --- /dev/null +++ b/fpga/lib/ips/switch.cpp @@ -0,0 +1,159 @@ +/* AXI Stream interconnect related helper functions + * + * These functions present a simpler interface to Xilinx' AXI Stream switch driver (XAxis_Switch_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +namespace villas { +namespace fpga { +namespace ip { + +bool AxiStreamSwitch::init() { + if (XAxisScr_CfgInitialize(&xSwitch, &xConfig, getBaseAddr(registerMemory)) != + XST_SUCCESS) { + logger->error("Cannot initialize switch"); + return false; + } + + // Disable all masters + XAxisScr_RegUpdateDisable(&xSwitch); + XAxisScr_MiPortDisableAll(&xSwitch); + XAxisScr_RegUpdateEnable(&xSwitch); + + for (auto &[masterName, masterPort] : portsMaster) { + + // Initialize internal mapping + portMapping[masterName] = PORT_DISABLED; + + // Each slave port may be internally routed to a master port + for (auto &[slaveName, slavePort] : portsSlave) { + (void)slaveName; + + streamGraph.addDefaultEdge(slavePort->getIdentifier(), + masterPort->getIdentifier()); + } + } + + return true; +} + +void AxiStreamSwitch::printConfig() const { + u32 MiPortAddr; + u32 RegValue; + u8 Enable; + logger->info( + "Switch configuration: {} Master Interfaces, {} Slave Interfaces", + xConfig.MaxNumMI, xConfig.MaxNumSI); + + for (int i = 0; i < xConfig.MaxNumMI; i++) { + /* Calculate MI port address to be enabled */ + MiPortAddr = XAXIS_SCR_MI_MUX_START_OFFSET + 4 * i; + + /* Read MI port data */ + RegValue = XAxisScr_ReadReg(xSwitch.Config.BaseAddress, MiPortAddr); + + /* Fetch enable bit */ + Enable = RegValue >> XAXIS_SCR_MI_X_DISABLE_SHIFT; + + /* Fetch SI value */ + RegValue &= XAXIS_SCR_MI_X_MUX_MASK; + + logger->info("Master Interface {}: {} (enabled: {})", i, RegValue, Enable); + } +} + +bool AxiStreamSwitch::connectInternal(const std::string &portSlave, + const std::string &portMaster) { + // Check if slave port exists + try { + getSlavePort(portSlave); + } catch (const std::out_of_range &) { + logger->error("Switch doesn't have a slave port named '{}'", portSlave); + return false; + } + + // Check if master port exists + try { + getMasterPort(portMaster); + } catch (const std::out_of_range &) { + logger->error("Switch doesn't have a master port named '{}'", portMaster); + return false; + } + + if (portSlave.substr(0, 1) != "S" or portMaster.substr(0, 1) != "M") { + logger->error("sanity check failed: master {} slave {}", portMaster, + portSlave); + return false; + } + + if (portMapping[portMaster] == portSlave) { + logger->debug("Ports already connected (slave {} to master {}", portSlave, + portMaster); + return true; + } + + for (auto [master, slave] : portMapping) { + if (slave == portSlave) { + logger->warn("Slave {} has already been connected to master {}. " + "Disabling master {}.", + slave, master, master); + + XAxisScr_RegUpdateDisable(&xSwitch); + XAxisScr_MiPortDisable(&xSwitch, portNameToNum(master)); + XAxisScr_RegUpdateEnable(&xSwitch); + + portMapping[master] = PORT_DISABLED; + } + } + + // Reconfigure switch + XAxisScr_RegUpdateDisable(&xSwitch); + XAxisScr_MiPortEnable(&xSwitch, portNameToNum(portMaster), + portNameToNum(portSlave)); + XAxisScr_RegUpdateEnable(&xSwitch); + + portMapping[portMaster] = portSlave; + + logger->debug("Connect slave {} to master {}", portSlave, portMaster); + + return true; +} + +int AxiStreamSwitch::portNameToNum(const std::string &portName) { + const std::string number = portName.substr(1, 2); + return std::stoi(number); +} + +void AxiStreamSwitchFactory::parse(Core &ip, json_t *cfg) { + NodeFactory::parse(ip, cfg); + + auto logger = getLogger(); + + auto &axiSwitch = dynamic_cast(ip); + + int num_si, num_mi; + json_error_t err; + auto ret = json_unpack_ex(cfg, &err, 0, "{ s: { s: i, s: i } }", "parameters", + "num_si", &num_si, "num_mi", &num_mi); + if (ret != 0) + throw ConfigError(cfg, err, "", "Cannot parse switch config"); + + axiSwitch.xConfig.MaxNumMI = num_mi; + axiSwitch.xConfig.MaxNumSI = num_si; +} + +static AxiStreamSwitchFactory f; + +} // namespace ip +} // namespace fpga +} // namespace villas diff --git a/fpga/lib/ips/timer.cpp b/fpga/lib/ips/timer.cpp new file mode 100644 index 000000000..0af2e73a5 --- /dev/null +++ b/fpga/lib/ips/timer.cpp @@ -0,0 +1,60 @@ +/* Timer related helper functions + * + * These functions present a simpler interface to Xilinx' Timer Counter driver (XTmrCtr_*) + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include + +using namespace villas::fpga::ip; + +bool Timer::init() { + XTmrCtr_Config xtmr_cfg; + xtmr_cfg.SysClockFreqHz = getFrequency(); + + XTmrCtr_CfgInitialize(&xTmr, &xtmr_cfg, getBaseAddr(registerMemory)); + XTmrCtr_InitHw(&xTmr); + + if (irqs.find(irqName) == irqs.end()) { + logger->error("IRQ '{}' not found but required", irqName); + return false; + } + + // Disable so we don't receive any stray interrupts + irqs[irqName].irqController->disableInterrupt(irqs[irqName]); + + return true; +} + +bool Timer::start(uint32_t ticks) { + irqs[irqName].irqController->enableInterrupt(irqs[irqName], false); + + XTmrCtr_SetOptions(&xTmr, 0, XTC_EXT_COMPARE_OPTION | XTC_DOWN_COUNT_OPTION); + XTmrCtr_SetResetValue(&xTmr, 0, ticks); + XTmrCtr_Start(&xTmr, 0); + + return true; +} + +bool Timer::wait() { + int count = irqs[irqName].irqController->waitForInterrupt(irqs[irqName]); + irqs[irqName].irqController->disableInterrupt(irqs[irqName]); + + return (count == 1); +} + +uint32_t Timer::remaining() { return XTmrCtr_GetValue(&xTmr, 0); } + +static char n[] = "timer"; +static char d[] = "Xilinx's programmable timer / counter"; +static char v[] = "xilinx.com:ip:axi_timer:"; +static CorePlugin f; diff --git a/fpga/lib/memory.cpp b/fpga/lib/memory.cpp new file mode 100644 index 000000000..3a213a158 --- /dev/null +++ b/fpga/lib/memory.cpp @@ -0,0 +1,24 @@ +/* Memory managment. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +using namespace villas; + +bool HostRam::free(void *addr, size_t length) { + return munmap(addr, length) == 0; +} + +void *HostRam::allocate(size_t length, int flags) { + const int mmap_flags = flags | MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT; + const int mmap_protection = PROT_READ | PROT_WRITE; + + return mmap(nullptr, length, mmap_protection, mmap_flags, 0, 0); +} diff --git a/fpga/lib/node.cpp b/fpga/lib/node.cpp new file mode 100644 index 000000000..d0a4f1f4a --- /dev/null +++ b/fpga/lib/node.cpp @@ -0,0 +1,171 @@ +/* An IP node. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +using namespace villas::fpga::ip; + +StreamGraph Node::streamGraph; + +void NodeFactory::parse(Core &ip, json_t *cfg) { + CoreFactory::parse(ip, cfg); + + auto &Node = dynamic_cast(ip); + auto logger = getLogger(); + + json_t *json_ports = json_object_get(cfg, "ports"); + if (json_ports && json_is_array(json_ports)) { + size_t index; + json_t *json_port; + json_array_foreach(json_ports, index, json_port) { + if (not json_is_object(json_port)) + throw ConfigError(json_port, "", "Port {} is not an object", index); + + const char *role_raw, *target_raw, *name_raw; + + json_error_t err; + int ret = + json_unpack_ex(json_port, &err, 0, "{ s: s, s: s, s: s }", "role", + &role_raw, "target", &target_raw, "name", &name_raw); + if (ret != 0) + throw ConfigError(json_port, err, "", "Cannot parse port {}", index); + + const auto tokens = utils::tokenize(target_raw, ":"); + if (tokens.size() != 2) + throw ConfigError(json_port, err, "", + "Cannot parse 'target' of port {}", index); + + const std::string role(role_raw); + const bool isMaster = (role == "master" or role == "initiator"); + + auto thisVertex = Node::streamGraph.getOrCreateStreamVertex( + ip.getInstanceName(), name_raw, isMaster); + + auto connectedVertex = Node::streamGraph.getOrCreateStreamVertex( + tokens[0], tokens[1], not isMaster); + + if (isMaster) { + Node::streamGraph.addDefaultEdge(thisVertex->getIdentifier(), + connectedVertex->getIdentifier()); + Node.portsMaster[name_raw] = thisVertex; + } else // Slave + Node.portsSlave[name_raw] = thisVertex; + } + } else if (json_ports) { + throw ConfigError(json_ports, "", "IP port list of {} must be an array", + ip.getInstanceName()); + } +} + +std::pair Node::getLoopbackPorts() const { + for (auto &[masterName, masterVertex] : portsMaster) { + for (auto &[slaveName, slaveVertex] : portsSlave) { + StreamGraph::Path path; + if (streamGraph.getPath(masterVertex->getIdentifier(), + slaveVertex->getIdentifier(), path)) { + return {masterName, slaveName}; + } + } + } + + return {"", ""}; +} + +bool Node::connect(const StreamVertex &from, const StreamVertex &to) { + if (from.nodeName != getInstanceName()) { + logger->error("Cannot connect from a foreign StreamVertex: {}", from); + return false; + } + + StreamGraph::Path path; + if (not streamGraph.getPath(from.getIdentifier(), to.getIdentifier(), path)) { + logger->error("No path from {} to {}", from, to); + return false; + } + + if (path.size() == 0) { + return true; + } + + auto currentEdge = path.begin(); + auto firstEdge = streamGraph.getEdge(*currentEdge); + auto firstHopNode = streamGraph.getVertex(firstEdge->getVertexTo()); + + auto nextHopNode = firstHopNode; + + // Check if next hop is an internal connection + if (firstHopNode->nodeName == getInstanceName()) { + if (not connectInternal(from.portName, firstHopNode->portName)) { + logger->error("Making internal connection from {} to {} failed", from, + *firstHopNode); + return false; + } + + // We have to advance to next hop + if (++currentEdge == path.end()) + return true; // Arrived at the end of path + + auto secondEdge = streamGraph.getEdge(*currentEdge); + auto secondHopNode = streamGraph.getVertex(secondEdge->getVertexTo()); + nextHopNode = secondHopNode; + } + + auto nextHopNodeIp = + std::dynamic_pointer_cast(card->lookupIp(nextHopNode->nodeName)); + + if (nextHopNodeIp == nullptr) { + logger->error("Cannot find IP {}, this shouldn't happen!", + nextHopNode->nodeName); + return false; + } + + return nextHopNodeIp->connect(*nextHopNode, to); +} + +const StreamVertex &Node::getDefaultSlavePort() const { + logger->error("No default slave port available"); + throw std::exception(); +} + +const StreamVertex &Node::getDefaultMasterPort() const { + logger->error("No default master port available"); + throw std::exception(); +} + +bool Node::loopbackPossible() const { + auto ports = getLoopbackPorts(); + return (not ports.first.empty()) and (not ports.second.empty()); +} + +bool Node::connectInternal(const std::string &slavePort, + const std::string &masterPort) { + (void)slavePort; + (void)masterPort; + + logger->warn("This IP doesn't implement an internal connection"); + return false; +} + +bool Node::connectLoopback() { + auto ports = getLoopbackPorts(); + const auto &portMaster = portsMaster[ports.first]; + const auto &portSlave = portsSlave[ports.second]; + + logger->debug("master port: {}", ports.first); + logger->debug("slave port: {}", ports.second); + + return connect(*portMaster, *portSlave); +} diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp new file mode 100644 index 000000000..a43632f97 --- /dev/null +++ b/fpga/lib/pcie_card.cpp @@ -0,0 +1,198 @@ +/* FPGA pciecard. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace villas; +using namespace villas::fpga; + +// Instantiate factory to register +static PCIeCardFactory PCIeCardFactoryInstance; + +static const kernel::devices::PciDevice defaultFilter( + (kernel::devices::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); + +std::shared_ptr +PCIeCardFactory::make(json_t *json_card, std::string card_name, + std::shared_ptr vc, + const std::filesystem::path &searchPath) { + auto logger = getStaticLogger(); + + // make sure the vfio container has the required modules + kernel::loadModule("vfio_pci"); + kernel::loadModule("vfio_iommu_type1"); + + json_t *json_ips = nullptr; + json_t *json_paths = nullptr; + const char *pci_slot = nullptr; + const char *pci_id = nullptr; + int do_reset = 0; + int affinity = 0; + int polling = 0; + + json_error_t err; + int ret = json_unpack_ex( + json_card, &err, 0, "{ s: o, s?: i, s?: b, s?: s, s?: s, s?: b, s?: o }", + "ips", &json_ips, "affinity", &affinity, "do_reset", &do_reset, "slot", + &pci_slot, "id", &pci_id, "polling", &polling, "paths", &json_paths); + + if (ret != 0) + throw ConfigError(json_card, err, "", "Failed to parse card"); + + auto card = std::shared_ptr(make()); + + // Populate generic properties + card->name = std::string(card_name); + card->vfioContainer = vc; + card->affinity = affinity; + card->doReset = do_reset != 0; + card->polling = (polling != 0); + + kernel::devices::PciDevice filter = defaultFilter; + + if (pci_id) + filter.id = kernel::devices::Id(pci_id); + if (pci_slot) + filter.slot = kernel::devices::Slot(pci_slot); + + // Search for FPGA card + card->pdev = + kernel::devices::PciDeviceList::getInstance()->lookupDevice(filter); + if (!card->pdev) { + logger->warn("Failed to find PCI device"); + return nullptr; + } + + if (not card->init()) { + logger->warn("Cannot start FPGA card {}", card_name); + return nullptr; + } + + // Load IPs from a separate json file + if (!json_is_string(json_ips)) { + logger->debug("FPGA IP cores config item is not a string."); + throw ConfigError(json_ips, "node-config-fpga-ips", + "FPGA IP cores config item is not a string."); + } + if (!searchPath.empty()) { + std::filesystem::path json_ips_path = + searchPath / json_string_value(json_ips); + logger->debug("searching for FPGA IP cors config at {}", + json_ips_path.string()); + json_ips = json_load_file(json_ips_path.c_str(), 0, nullptr); + } else { + json_ips = json_load_file(json_string_value(json_ips), 0, nullptr); + } + if (json_ips == nullptr) { + json_ips = json_load_file(json_string_value(json_ips), 0, nullptr); + logger->debug("searching for FPGA IP cors config at {}", + json_string_value(json_ips)); + if (json_ips == nullptr) { + throw ConfigError(json_ips, "node-config-fpga-ips", + "Failed to find FPGA IP cores config"); + } + } + + if (not json_is_object(json_ips)) + throw ConfigError(json_ips, "node-config-fpga-ips", + "FPGA IP core list must be an object!"); + + ip::CoreFactory::make(card.get(), json_ips); + if (card->ips.empty()) + throw ConfigError(json_ips, "node-config-fpga-ips", + "Cannot initialize IPs of FPGA card {}", card_name); + + if (not card->check()) + throw RuntimeError("Checking of FPGA card {} failed", card_name); + + // Additional static paths for AXI-Steram switch + if (json_paths != nullptr) { + if (not json_is_array(json_paths)) + throw ConfigError(json_paths, err, "", + "Switch path configuration must be an array"); + + size_t i; + json_t *json_path; + json_array_foreach(json_paths, i, json_path) { + const char *from, *to; + int reverse = 0; + + ret = json_unpack_ex(json_path, &err, 0, "{ s: s, s: s, s?: b }", "from", + &from, "to", &to, "reverse", &reverse); + if (ret != 0) + throw ConfigError(json_path, err, "", + "Cannot parse switch path config"); + + auto masterIpCore = card->lookupIp(from); + if (!masterIpCore) + throw ConfigError(json_path, "", "Unknown IP {}", from); + + auto slaveIpCore = card->lookupIp(to); + if (!slaveIpCore) + throw ConfigError(json_path, "", "Unknown IP {}", to); + + auto masterIpNode = std::dynamic_pointer_cast(masterIpCore); + if (!masterIpNode) + throw ConfigError(json_path, "", "IP {} is not a streaming node", from); + + auto slaveIpNode = std::dynamic_pointer_cast(slaveIpCore); + if (!slaveIpNode) + throw ConfigError(json_path, "", "IP {} is not a streaming node", to); + + if (not masterIpNode->connect(*slaveIpNode, reverse != 0)) + throw ConfigError(json_path, "", "Failed to connect node {} to {}", + from, to); + } + } + // Deallocate JSON config + json_decref(json_ips); + return card; +} + +PCIeCard::~PCIeCard() {} + +bool PCIeCard::init() { + logger = getLogger(); + + logger->info("Initializing FPGA card {}", name); + + // Attach PCIe card to VFIO container + vfioDevice = vfioContainer->attachDevice(*pdev); + + // Enable memory access and PCI bus mastering for DMA + if (not vfioDevice->pciEnable()) { + logger->error("Failed to enable PCI device"); + return false; + } + + // Reset system? + if (doReset) { + // Reset / detect PCI device + if (not vfioDevice->pciHotReset()) { + logger->error("Failed to reset PCI device"); + return false; + } + + if (not reset()) { + logger->error("Failed to reset FGPA card"); + return false; + } + } + + return true; +} diff --git a/fpga/lib/utils.cpp b/fpga/lib/utils.cpp new file mode 100644 index 000000000..be0f20b8a --- /dev/null +++ b/fpga/lib/utils.cpp @@ -0,0 +1,340 @@ +/* Helper function for directly using VILLASfpga outside of VILLASnode + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2022-2023 Steffen Vogel + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace villas; + +static auto logger = villas::Log::get("streamer"); + +std::shared_ptr>> +fpga::getAuroraChannels(std::shared_ptr card) { + auto aurora_channels = + std::make_shared>>(); + for (int i = 0; i < 4; i++) { + auto name = fmt::format("aurora_aurora_8b10b_ch{}", i); + auto id = fpga::ip::IpIdentifier("xilinx.com:ip:aurora_8b10b:", name); + auto aurora = std::dynamic_pointer_cast(card->lookupIp(id)); + if (aurora == nullptr) { + logger->warn("No Aurora interface found on FPGA"); + break; + } + + aurora_channels->push_back(aurora); + } + return aurora_channels; +} + +fpga::ConnectString::ConnectString(std::string &connectString, int maxPortNum) + : log(villas::Log::get("ConnectString")), maxPortNum(maxPortNum), + bidirectional(false), invert(false), srcType(ConnectType::LOOPBACK), + dstType(ConnectType::LOOPBACK), srcAsInt(-1), dstAsInt(-1) { + parseString(connectString); +} + +void fpga::ConnectString::parseString(std::string &connectString) { + if (connectString.empty()) + return; + + if (connectString == "loopback") { + logger->info("Connecting loopback"); + srcType = ConnectType::LOOPBACK; + dstType = ConnectType::LOOPBACK; + bidirectional = true; + return; + } + static const std::regex regex("([0-9]+|stdin|stdout|pipe|dma|dino)([<\\->]+)(" + "[0-9]+|stdin|stdout|pipe|dma|dino)"); + std::smatch match; + + if (!std::regex_match(connectString, match, regex) || match.size() != 4) { + logger->error("Invalid connect string: {}", connectString); + throw std::runtime_error("Invalid connect string"); + } + + if (match[2] == "<->") { + bidirectional = true; + } else if (match[2] == "<-") { + invert = true; + } + + std::string srcStr = (invert ? match[3] : match[1]); + std::string dstStr = (invert ? match[1] : match[3]); + + srcAsInt = portStringToInt(srcStr); + dstAsInt = portStringToInt(dstStr); + if (srcAsInt == -1) { + if (srcStr == "dino") { + srcType = ConnectType::DINO; + } else if (srcStr == "dma" || srcStr == "pipe" || srcStr == "stdin" || + srcStr == "stdout") { + srcType = ConnectType::DMA; + } else { + throw std::runtime_error("Invalid source type"); + } + } else { + srcType = ConnectType::AURORA; + } + if (dstAsInt == -1) { + if (dstStr == "dino") { + dstType = ConnectType::DINO; + } else if (dstStr == "dma" || dstStr == "pipe" || dstStr == "stdin" || + dstStr == "stdout") { + dstType = ConnectType::DMA; + } else { + throw std::runtime_error("Invalid destination type"); + } + } else { + dstType = ConnectType::AURORA; + } +} + +int fpga::ConnectString::portStringToInt(std::string &str) const { + if (str == "stdin" || str == "stdout" || str == "pipe" || str == "dma" || + str == "dino") { + return -1; + } else { + const int port = std::stoi(str); + + if (port > maxPortNum || port < 0) + throw std::runtime_error("Invalid port number"); + + return port; + } +} + +// parses a string like "1->2" or "1<->stdout" and configures the crossbar accordingly +void fpga::ConnectString::configCrossBar( + std::shared_ptr card) const { + + auto dma = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:"))); + if (dma == nullptr) { + logger->error("No DMA found on FPGA "); + throw std::runtime_error("No DMA found on FPGA"); + } + + if (isDmaLoopback()) { + log->info("Configuring DMA loopback"); + dma->connectLoopback(); + return; + } + + auto aurora_channels = getAuroraChannels(card); + + auto dinoDac = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:module_ref:dinoif_dac:"))); + if (dinoDac == nullptr) { + logger->warn("No Dino DAC found on FPGA "); + } + + auto dinoAdc = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:module_ref:dinoif_fast:"))); + if (dinoAdc == nullptr) { + logger->warn("No Dino ADC found on FPGA "); + } + + log->info("Connecting {} to {}, {}directional", + (srcAsInt == -1 ? connectTypeToString(srcType) + : std::to_string(srcAsInt)), + (dstAsInt == -1 ? connectTypeToString(dstType) + : std::to_string(dstAsInt)), + (bidirectional ? "bi" : "uni")); + + std::shared_ptr src; + std::shared_ptr dest; + if (dinoAdc && srcType == ConnectType::DINO) { + src = dinoAdc; + } else if (dma && srcType == ConnectType::DMA) { + src = dma; + } else if (aurora_channels->size() > 0) { + src = (*aurora_channels)[srcAsInt]; + } else { + throw std::runtime_error("No Aurora channels found on FPGA"); + } + + if (dinoDac && dstType == ConnectType::DINO) { + dest = dinoDac; + } else if (dma && dstType == ConnectType::DMA) { + dest = dma; + } else if (aurora_channels->size() > 0) { + dest = (*aurora_channels)[dstAsInt]; + } + + src->connect(src->getDefaultMasterPort(), dest->getDefaultSlavePort()); + if (bidirectional) { + if (dinoDac && srcType == ConnectType::DINO) { + src = dinoDac; + } + if (dinoAdc && dstType == ConnectType::DINO) { + dest = dinoAdc; + } + dest->connect(dest->getDefaultMasterPort(), src->getDefaultSlavePort()); + } +} + +void fpga::setupColorHandling() { + // Handle Control-C nicely + struct sigaction sigIntHandler; + sigIntHandler.sa_handler = [](int) { + std::cout << std::endl << rang::style::reset << rang::fgB::red; + std::cout << "Control-C detected, exiting..." << rang::style::reset + << std::endl; + std::exit( + 1); // Will call the correct exit func, no unwinding of the stack though + }; + + sigemptyset(&sigIntHandler.sa_mask); + sigIntHandler.sa_flags = 0; + sigaction(SIGINT, &sigIntHandler, nullptr); + + // Reset color if exiting not by signal + std::atexit([]() { std::cout << rang::style::reset; }); +} + +std::shared_ptr +fpga::createCard(json_t *config, const std::filesystem::path &searchPath, + std::shared_ptr vfioContainer, + std::string card_name) { + auto configDir = std::filesystem::path().parent_path(); + + const char *interfaceName; + json_error_t err; + logger->info("Found config for FPGA card {}", card_name); + int ret = + json_unpack_ex(config, &err, 0, "{s: s}", "interface", &interfaceName); + if (ret) { + throw ConfigError(config, err, "interface", + "Failed to parse interface name for card {}", card_name); + } + std::string interfaceNameStr(interfaceName); + if (interfaceNameStr == "pcie") { + auto card = fpga::PCIeCardFactory::make(config, std::string(card_name), + vfioContainer, searchPath); + if (card) { + return card; + } + return nullptr; + } else if (interfaceNameStr == "platform") { + throw RuntimeError("Platform interface not implemented yet"); + } else { + throw RuntimeError("Unknown interface type {}", interfaceNameStr); + } +} + +int fpga::createCards(json_t *config, + std::list> &cards, + const std::filesystem::path &searchPath, + std::shared_ptr vfioContainer) { + int numFpgas = 0; + if (vfioContainer == nullptr) { + vfioContainer = std::make_shared(); + } + auto configDir = std::filesystem::path().parent_path(); + + json_t *fpgas = json_object_get(config, "fpgas"); + if (fpgas == nullptr) { + logger->info("No section 'fpgas' found in config"); + return 0; + } + + const char *card_name; + json_t *json_card; + std::shared_ptr card; + json_object_foreach(fpgas, card_name, json_card) { + card = createCard(json_card, searchPath, vfioContainer, card_name); + if (card != nullptr) { + cards.push_back(card); + numFpgas++; + } + } + return numFpgas; +} + +int fpga::createCards(json_t *config, + std::list> &cards, + const std::string &searchPath, + std::shared_ptr vfioContainer) { + const auto fsPath = std::filesystem::path(searchPath); + return createCards(config, cards, fsPath, vfioContainer); +} + +std::shared_ptr fpga::setupFpgaCard(const std::string &configFile, + const std::string &fpgaName) { + auto configDir = std::filesystem::path(configFile).parent_path(); + + // Parse FPGA configuration + FILE *f = fopen(configFile.c_str(), "r"); + if (!f) + throw RuntimeError("Cannot open config file: {}", configFile); + + json_t *json = json_loadf(f, 0, nullptr); + if (!json) { + logger->error("Cannot parse JSON config"); + fclose(f); + throw RuntimeError("Cannot parse JSON config"); + } + + fclose(f); + + // Create all FPGA card instances using the corresponding plugin + auto cards = std::list>(); + createCards(json, cards, configDir); + + std::shared_ptr card = nullptr; + for (auto &fpgaCard : cards) { + if (fpgaCard->name == fpgaName) { + card = fpgaCard; + break; + } + } + // Deallocate JSON config + json_decref(json); + + if (!card) { + throw RuntimeError("FPGA card {} not found in config or not working", + fpgaName); + } + + return card; +} + +std::unique_ptr +fpga::getBufferedSampleFormatter(const std::string &format, + size_t bufSizeInSamples) { + if (format == "long") { + return std::make_unique( + bufSizeInSamples); + } else if (format == "short") { + return std::make_unique( + bufSizeInSamples); + } else { + throw RuntimeError("Unknown output format '{}'", format); + } +} diff --git a/fpga/lib/vlnv.cpp b/fpga/lib/vlnv.cpp new file mode 100644 index 000000000..ae16d5298 --- /dev/null +++ b/fpga/lib/vlnv.cpp @@ -0,0 +1,57 @@ +/* Vendor, Library, Name, Version (VLNV) tag + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +using namespace villas::fpga; + +bool Vlnv::operator==(const Vlnv &other) const { + // If a field is empty, it means wildcard matching everything + const bool vendorWildcard = vendor.empty() or other.vendor.empty(); + const bool libraryWildcard = library.empty() or other.library.empty(); + const bool nameWildcard = name.empty() or other.name.empty(); + const bool versionWildcard = version.empty() or other.version.empty(); + + const bool vendorMatch = vendorWildcard or vendor == other.vendor; + const bool libraryMatch = libraryWildcard or library == other.library; + const bool nameMatch = nameWildcard or name == other.name; + const bool versionMatch = versionWildcard or version == other.version; + + return vendorMatch and libraryMatch and nameMatch and versionMatch; +} + +void Vlnv::parseFromString(std::string vlnv) { + // Tokenize by delimiter + std::stringstream sstream(vlnv); + std::getline(sstream, vendor, delimiter); + std::getline(sstream, library, delimiter); + std::getline(sstream, name, delimiter); + std::getline(sstream, version, delimiter); + + // Represent wildcard internally as empty string + if (vendor == "*") + vendor = ""; + if (library == "*") + library = ""; + if (name == "*") + name = ""; + if (version == "*") + version = ""; +} + +std::string Vlnv::toString() const { + std::stringstream stream; + std::string string; + + stream << *this; + stream >> string; + + return string; +} diff --git a/fpga/libvillas-fpga.pc.in b/fpga/libvillas-fpga.pc.in new file mode 100644 index 000000000..a837c35cd --- /dev/null +++ b/fpga/libvillas-fpga.pc.in @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${exec_prefix}/lib + +Name: @PROJECT_NAME@ +Description: @CPACK_PACKAGE_DESCRIPTION_SUMMARY@ +URL: @PROJECT_URL@ +Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@ +Cflags: -I${includedir} diff --git a/fpga/past-commits.txt b/fpga/past-commits.txt new file mode 100644 index 000000000..234cbf163 --- /dev/null +++ b/fpga/past-commits.txt @@ -0,0 +1,196 @@ +SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University +SPDX-License-Identifier: Apache-2.0 + +I, Niklas Eiling hereby sign-off-by all of my past commits to this repo subject to the Developer Certificate of Origin (DCO), Version 1.1. In the past I have used emails: niklas.eiling@eonerc.rwth-aachen.de + +b22a741785f38ee5f86d46c287e523ddd8f94a46 update contact and copyright notice +9f43181c688bac915f6c10a3318c6bedb455b8fb add villas-fpga-xbar-select; improve DMA parameters in ips/dma +092ccfe8b232a6e41dee7e3a0faba38aff58ab2d fix villas-fpga-cat interpreting floats wrong +4b8cca9420b7dda0f7d8f9c24bff4a9ab07db0cf clean up and comment ips/dma.cpp +749406976f595d8f25ab862d44dfa18126b18c86 villas-fpga-cat: fix double value being constructed wrong +edc36f793afe3152a754b707e3f4531b0172cbfc ips/dma: comment debug outputs to improve villas-fpga-cat performance fix rebase artifacts +abf63eefa972606f55291b12767fa2fe07711572 add villas-fpga-cat app that outputs a stream of data +833acb8fab609e71570a62899b78d994b722dfc2 move helper functions from villas-fpga-pipe into separate file +ceddd1ce96fabcc8d6b14ab5e780d31631ca283f Merge branch 'fix-gitlabyml' into 'master' +b2746556210784fc06f65858b169816d1e0db748 fix image reference in gitlab.yml +ca970e8c33c013f7416cc3ee8c1ce9a6482f5c7b migrate dockerfile to rocky9 +75d80447afb10f01dc90b9afa518425f4c25f8b8 ips/dma: fix hasScatterGather using wrong member variable; Throw error used on unconfigured Dma +8db35907dd306422bcda5ec395a383b04e9c83b7 ips: fix some formatting issues +a16468c61c83a20bd223a05eeb3187954e35b98d ips/dma: use NodeFactory's configureJson to setup memory graph +1ae00c1f59413a6c726b7c34d839c56fdc13e281 ips/dma: use json_unpack +da10c4db59344c9ac1a387cb408d4bc57f36ec46 add card config option "polling" to configure polling mode in IP cores; add json parsing of hwdef to dma IP core to replace hardcoded DMA settings. +4db2153330af2c830b258152f3badbd4ecc51b61 ip/dma: fix spelling +a4120eda2d327aa537fa874885c200c858202fcc ips/dma: acknowledge interrupts in DMA controller and correctly set coalescing parameter. +277858f881499821334f0f27303fea8380b549d6 make dma.cpp use interrupts instead of polling + +--- + +I, Steffen Vogel hereby sign-off-by all of my past commits to this repo subject to the Developer Certificate of Origin (DCO), Version 1.1. In the past I have used emails: post@steffenvogel.de, post@steffenvogel.de + +e256a94957294714d6bf645fa9c9f17253fa154e Merge branch 'fix-dockerfile' into 'master' +44fcb85aebeedc531b061d41c847eabbc8cee478 minor code-style fixes +c8b20ec18863091fe92d1913a329b0d54a03434f move VILLASnode configs to VILLASnode repo +69f63d9ef61f37628a11f6c4ff62675a2aa2d487 update VILLAScommon submodule +b13589aa55c0ad4e497daaaf122142b99095b966 add libxil as a submodule +1e9e46b35a872332d92b16ce6fe276655f8d2fc6 updated VILLAScommon submodule +f4e7fcdac329600de2a3838ab8d773c3a6910932 core: avoid reversing initialization order list +15a9ae0806a7618b80f635f1563e90a1c547aa94 dma: first successful test with scatter gather +9e8c4ef132d005d025a5d960531635a869eba8c1 adapt villas-fpga-pipe to new DMA code +ecb9fac96fb3bd24d59163c7a9c67f4a98dce019 update IPs config for new bitstream using MSI IRQs +c1749d052ab96c99d33efa6231c8c30f698120c3 dma: added second version of scatter-gather support +0b4bc73b0a897a8bbee501f977bfbe661a92ed31 update gitignore +1ef3952d62cd47177a9527ca6c67a0e3aad430be minor code style and comment fixes +d6ee75febcc7c41525c0a7722b160383a6988147 dma: throw exception in makeAccesibleFromVA instead of returning bool +09106c3a9c8b67d8b72a3680263ceab1fbc0780b fix script to reset PCIe card +dd03a196008cb7276de2bab4289320d12e6b3e97 remove useless includes +72d92a5223ec4ee95ac25169356894c0bfe92ef2 intc: fix VLNV for Niklas' new bistream +1a47f70281db2108629777c4d92d731802388fe9 aurora: fix names of AXI-S interfaces +b91e6d102dc68f491885bc37e925ed9ae3976bc0 fix coding style +3661b25532e0f10e4a24a66b9e54e743b4f92b65 remove old C code +a5a2dcf992ce9fa7b3f73a9ba585f010feb1b456 dma: start implementing scatter-gather support +b4d39159d5b28b59662efbb1a4976ab307af4783 add example config for VILLASnode integration +ae681cc3073ce90b459428ad5ed0bf06931aa756 remove broken symlink +afb45d88d15c63d5910de0c0864dc7d7fbffabdd add latest vc707 config +bfffd71b71a2b21ec88cad766baaa254d13a3273 remove last pieces of hardware submodule +3ccb99b9ecd5046765041bc4cfa8b1a4f8a02da5 bump libxil version requirement +3e61b1ef0d2abfe332bc3fa490afe91ec46d19b5 villas-fpga-pipe: whitespaces and syntax fixes +2ed26572eb202d3fb1f9272ad8263f6c3db524fc adjust DMA IP core to new DMA parameters of Niklas' bitstream +3612b9a203d5b679b2e6f5bded9d8a5d435da4c2 update VILLAScommon submodule +17d03d6d7cc4144ffecc3ce3f7a9efd6fd0cfb05 add missing parentheses +d887eb56836a0f224606a59b86d8cce6aeb45a09 update year in copyright notices +bd2844d5400d3a7077c9d1f3ab6af265c8720060 fixes for villas-fpga-pipe +fbb0a7c8b6f0352b35a1fdb6722caa2fd8355bac cleanup of comments +0b197052daff92a8b388eaa10b084ac98c40ff6e add new IP core for standard Xilinx Aurora cores +501f12762503308026c7724fccba2ccbd197bcd7 card: allow loading IPs devicetree from extra file +033f8ef9fced5b6483dcd300d2be42b232d176a1 update gitignore +7bdd26371fb2e00158c965f3cb00e069dd8a83ec add VSCode configuration for GDB debugging as root +ec8dc2c5e44dda0146b8b7fe7664caa7c347f618 harmonize logger names +02635501d44dfbf31b959141995dea65f3d0adb3 update code to latest common submodule +f2ef1dfaf2e96c623512e73b78b5db40bdbd5ca6 remove old configs +7ea5d43b162247c81b2ee6a106dd36807b6a626f update hardware submodule +16d856753ffb49a3cac4690faf31bc6b55dc1b1c update gitignore +1202b4edb1d47c77d06488ffd741e88dac4fab1f fix CI +aabe56f5dcacfc40dba169f5502eb6738031f525 fix format strings +0a7e12b357fc6b662c35922027a961a9887f8a8b update config include +b5a9c11a9118d096b25a76d1d7b547d5abb7d861 adapt to new plugin registry +3ccb25a2118b6ad211255215e08ed30168049b56 remove obsolete htdocs setting +bda5171c23404deedf2fbfc16b0ccefcc1311698 remove hardware submodule +66aaf9e062efdedb857968acf50625907ee522c8 Merge branch 'fix-cmake' into 'master' +8172f3868657cdb1930f9eb9419a68320761a722 cmake: allow linking libxil from non-standard location +34874fb2ff78ae5a9c02eb4015d4730017a2868d Merge branch 'cppcheck' into 'master' +e61bb67c91bdd7142dc8ae492bf85ab4b8f6adad ci: add cppcheck +7e0ca3ecdfb7acb10db79c28ebc8409ba979a9ef remove unused submodules +6bb3567acddb015f51a44c094f8dd46c321549d3 Merge branch 'fix-codestyle' into 'master' +c89145731b176b5fcb081bc6d9ffe933ae3a7c9c fix code-style +e73d84f1d4a3778aef71e025f494f96229620761 emc: add initial code to flash FPGA bitstream via PCIe +e54aabff4da52c26df8606b88457b60b15008be2 update submodules +7e1c6bd9898ab1e4a57c472c44d1f5b506bb67d9 emc: add stub IP +db59fdb5022f4d1192aef5fb0f677ff8d9cf9850 fix naming of factories +472f66993e0e8a05364958372211ea79fbb245aa update hardware submodule and move hwdef-parse script into hardware repo +0796f835af6be0235835df581541b5d386ea7453 update libxil submodule +53ea7b2289b427977c901b88113f5e073be6e3e8 cmake: make unit-tests optional +21340e7bc56417b9967f5a066f93ac2f99777ab1 Merge branch 'refactoring' into 'master' +86959cedb3b3bd604e98b1cafdc3fc809d8cd1a1 ci: update CI config +71c0f8984ce8292462ae5450bb89def54ce0f89c docker: add missing deps +43f94f4509362539e52802c5e64384ac6f79c490 docker: add mising ssl headers +2bc1b5c771d372fcee5af067396d7adcd4c4be6f docker: fix location of FEIN e.V. repo +5b5da9f2cdd44f1ca233a65f649b3ee8644dc7a3 node: add connect() with reverse path +2fa22b797166046993d9344b658d9c8836bdef1e update VILLAScommon submodule +692d9721fbb6e9c05c2b68215338ec43eab46839 refactor: more code-style improvements +01dcab9e493a121d3cea5da61ace5c9070cc33c1 refactor: no namespace scopes in source files +393c5f3564387dba1af107516320bb69e68d4252 cmake: fixups for inclusion into VILLASnode +ff07bc3946157422c06628ccf8c5c58be067add3 refactor: no namespace scoeps in source files +1eb8f5233981732b7c649fad30a87adc5530da16 refactor: whitespaces for references +1f6a181af64d806df12611ab0c5d0db33aa53cc8 update VILLAScommon submodule +972377d03dfa8c1f820b0eb5f2fbbb37cdd75255 refactor IpNode and IpCore class names +8a13d8ad9b5ec4456f49ab4dca2020858bfea1a7 several cleanups and bugfixes +2affde11e1061d6a7ca978099da9603a7a4a56fc use new getter for graph +2a62ea92721fb55d2bcbdcdc7ca04b2c3d383d1a pipe: use correct DMA instance +4ab00cdc4ef8284ae1fb5a32cc811401d7280ce3 harmonize codestyle +c5cdee6a4517267a4c93c64243ac43a5a9feec0a use new vlnv id for aurora_axis +111199c5f628914c1044fa5c590d7a7e5ef6b9da use new plugin mechanism +5f3dd901a566ad087180b59541098bd740ffb9a3 unit-tests: allow FPGA configuration to provided via env var +183c47d0db4d84f48a33ee0bc571a6b4efc12210 plugin: fix lookup +a6202d3d56871315c9d52001cf09dd2eb1c662f6 gpio: add new IP for AXI programmable GPIO +e524ec9be43110237e7e4fcef44bc87363b42698 intc: fix name of register space +127419d8fa5a4cdd85ee4924a55d0fe6c2eaf0e6 harmonize code-style with VILLAScommon/node +143b950aaf7948712f927d21d405e0be0dd9c8e9 update to latest VILLAScommon submodule +506f319014128e5c9a2b0336274edcb42266a558 aurora_axis: add two functions to reset counters and configure loopback mode +f608e83991b5ca1c558c6b9bf0b10da50e3b3fc4 aurora_axis: dump frame counters +9fd833cb27a54d60ec2b1a6416cee75e19222c25 aurora_axis: harmonize with HDL changes +1571a4ef3288b7fa7e615dbbb5ac31d8efcbe8b4 update submodule urls +981c0eadee39209b287f050f7502ace5e62c1479 add a writeMemory function to IpCore class +77eee178e652218919735aae5455158ef303fa80 update bitstream configs +0b589626a0de626240cdb9d7f867159c35209a77 update common submodule +a2a66c9539f28181b8714fbc64c1bd246c2ddaf5 several fixes for villas-fpga-pipe +6b893d2fbc35c3f2c259fa85b09eefa0148b988b dma: add dump() method +8f8bd1af121bfcc7e7529d59beb2a4a1c8de8c4e add note to cite our publication +09b0a852725cae3bd4fdb1917f5feaf8ddfae05e move gpu module to top level directory +545d47f030edc20ac75329b4340f0f5ca2fb7ca8 ci: some tweaks to fix unit-tests +fc7c1e08957064320e163104635a91cd8c71efd0 do not call copy-ctor of villas::HostRamAllocator +74b3d58781ebb4eef3348a3e0682a1392d9f18d9 fix include paths +5fc8d527c0b55f4ab214341a21db76a23e5ec052 tests: remove obsolete unit tests which have been moved to VILLAScommon +a87df1b576586fa244b1aa4418db21a5fe70ea93 Merge branch 'feature/hls-rtds2gpu' into develop +86fab24844d86c42a21d78a7699986c1aed3bb1f pipe: rename streamer to pipe (closes #19) +fdf1b64f7120c9b91c4378e86f6f8789aa0dca59 fix gdrcopy submodule +e51c98223f26deef5dd7f54babaa2215675255e5 gpu: fix include paths and some linker settings +437380ff773c62334a9876eec37519211720106b move more code to VILLAScommon repo +4a05d63e02d5775d225d353855c364207f1838b3 ci: use Centos 7 based Docker Image with CUDA dev env from Nvidia +b165227fe11524efcfe587243f9f0c8a1b0979db ci: use relative path in gitmodules for proper access rights +db9dd3b6633ee6b5822c7112277fd4b6cf3d661c update common submodule +fa0b0dcc272c011e7da51d8ef1168e6d5131288a streamer: use new memory api +a4c1ad57c5fe644cf3fff34ac799ac16c37dfade fix include paths +3657778896bce9922927e515e6983de6334dbdf1 move common code to VILLAScommon submodule +5c02b41fab1eb088382b2c869001bbc31f580688 remove some obsolete C code files +dca0951f4503f8af5a80c1ba8fa9023d0f6caa63 add more copyright / license headers +30325d42a6662fe86bcedb6c95805f05a7ac677a add Daniel to README +a0eb211d6ada6b9dde40cb9d8e0494ededac03d9 added submodule to VILLASfpga-hardware repo +5a6aa1855e03bcd6394f55b5ee9ae57a6c2d3dcd update Fedora version in Dockerfile +d44c06227760cbf91f2d1d2fd8fc4db36f946bdb add pcimem.c +bed6dd5e4435f095f2a66835449a6921d9f491a8 update copyright years +1a05612237d2677ff9a13c8f3bf0cdff1079c28c do not store bitstreams here +4cbba96972d5764c0a33cfd8ac9299322e7d3cc3 Merge branch 'feature/gpu' into 'develop' +9439b26ce42c2d60355fa4c1e5200c9b40852f22 Merge branch 'feature/villas-common' into 'develop' +bbeb017a14387918528c25b445c446759fd94410 Merge branch 'feature/blockram' into 'develop' +a481afc7f0300e3d98db41f9619d5c5293dcacf3 Merge branch 'feature/packaging' into 'develop' +ad47e712dcacf553b46666a32a16ed97814a93a0 Merge branch 'develop' into 'feature/packaging' +48d2f6d7d8f0ca3f450a138259d94a256a0c1848 Merge branch 'feature/dma-and-memory' into 'develop' +3504340b15d93880b2dbec5e1d078b900af59c72 cpack: fix name of source tarbar +f545e6ab3316948a5a680e3e008e2c49e9b79893 added pkg-config file and CMake configuration for building RPM packages +82d92d926026f5fa4228952afb9d2c48c2363043 Merge branch 'feature/memory-manager-rebased' into 'develop' +487da0794b54664ef40642479ecd94238f0b7eb4 Merge branch 'fix/directed_graph_loop_detection_bug' into 'develop' +18552b03eb37c13a6ad74ef44b37094f8e0de37d Merge branch 'feature/cpp_warnings' into 'develop' +1ee36fac3f78f0b2280dd917dd66f9853f8e0f5b Merge branch 'feature/criterion-spdlog' into develop +ee440f1de2d1294e35034e218ccdb8a224cf0161 Merge branch 'develop' of git.rwth-aachen.de:acs/public/villas/VILLASfpga-code into develop +fa1348a2e7039f11efed493b03550e246d3d5411 logging: use similar log style in all modules +e2ab3d43e0d8d05bc20f9ddd9716c9a588749aef tests: override some criteriod_log() functions in order to use spdlog style log output +c08050d1c51d141077fe916264cef8fdfface0ad tests: some cleanups +51124b8fd8d64ea7cc8b196d115376a4fb6c1566 tests: readd missing graph test suite +35fa5afa08c06ed8bc39adcc7ef21071b1bc2f05 tests: automatically detect whether or not we can run tests in parallel +2de9aa97b23d59fd8372f16a5c515df58f0920c7 tests: moved initialization of FPGA stuff to fpga.cpp +8f76da0f41e0250e0e6126a417c9555630da0a92 Merge branch 'feature/hw-testing' into feature/cpp (closes #14 and #15) +5004a8fb971ab3cffff4d781a05cc555a8d06d2d do parallel build +3f0049567601ab1b1762d5aaf250db4147843850 cleanup build dir before building +0f8c498b7d15a6d41eeff9b97032fbf479710472 tiny change +e3b10c1e79855e21ea6d251c5b0501d606500f03 FPGA tests fail if we attempt to run them in parallel +507f6d77d16f8d35afa9bda9516aeb49039ad436 Merge branch 'feature/non-root' into feature/hw-testing +3ae1290ddc2e6194f68948dee235cb6243e25c79 add script to configure system for non-root access to FPGA +8dad0435be9905c80acaccb5a045d9d20ac737f9 vfio: only rebind pci device to VFIO driver if not already bound +49c7dfb81b6e9e5e6fc5e9bc87cfadff7fe6706d pci: add function to get currently loaded kernel driver +3495777a7aae14bb2afcf7555bc5fa4352b081e0 install libraries to fix loading of libvillas-fpga.so +20d0efcf2216b05143ec31061f248b879dd4789a execute FPGA unit on acs-villas +fcf45a95ca7f9f045725188c1f5da073665aed63 fix wrong tag in gitlab-ci.yml +499d92db66a95f12c0ebe6b400f545c64259b0cd use official Fedora image as base +410210c421c834456a525c28f7ef9b9ffd00aabd enable unit tests on CI +d63d9e83378de00fd84e307b8149b3ca29238970 docker: fix invalid tag name +b42f181094625fe4e6921fe35438efc7f948fd2f fix path of submodule +5733c8f02597495b96a99676631f0d09ff61714c fix CI +3874cadcec0f035055d7ebc089246937a07c507f add LAPACK dependency to Dockerfile +d3822919261974215e31804d83bd3b32546ea6e1 fix CI +b1c61eb26ba42a9e8d4fa04aad0b6f687f761109 use https submodules +cff953d82c6f8872d48e012ad9c1fea53bc99cd0 add missing benchmarks +e986dc94bf82883c5b96e75feda20d807384c77f added gitignore +9d31c0058348eed286bcf56c15c3c4da389613e1 added fodler for bitstreams +8f78034705b0797c5591e33add60330eb8715d91 imported source code from VILLASfpga repo and made it compile +c8db2e0b54b4436fb663ea2f35de4352495db51b added simple Dockerfile for development +15bb988510a3d4d896dd583179922760a78081a5 created new repo for VILLASfpga diff --git a/fpga/src/CMakeLists.txt b/fpga/src/CMakeLists.txt new file mode 100644 index 000000000..ae3df6add --- /dev/null +++ b/fpga/src/CMakeLists.txt @@ -0,0 +1,20 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +add_executable(villas-fpga-ctrl villas-fpga-ctrl.cpp) + +target_link_libraries(villas-fpga-ctrl PUBLIC + villas-fpga +) + +add_executable(villas-fpga-pipe villas-fpga-pipe.cpp) + +target_link_libraries(villas-fpga-pipe PUBLIC + villas-fpga +) + + +add_executable(pcimem pcimem.c) diff --git a/fpga/src/README.pcimem.md b/fpga/src/README.pcimem.md new file mode 100644 index 000000000..17cb89f1e --- /dev/null +++ b/fpga/src/README.pcimem.md @@ -0,0 +1,149 @@ +# pcimem tool + +## License + +- SPDX-FileCopyrightText: 2010 Bill Farrow +- SPDX-FileCopyrightText: 2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +- SPDX-FileCopyrightText: 2000 Jan-Derk Bakker +- SPDX-License-Identifier: GPL-2.0-or-later + +## Overview + +The pcimem application provides a simple method of reading and writing +to memory registers on a PCI card. + +Usage: ./pcimem { sys file } { offset } [ type [ data ] ] + sys file: sysfs file for the pci resource to act on + offset : offset into pci memory region to act upon + type : access operation type : [b]yte, [h]alfword, [w]ord + data : data to be written + +## Platform Support + +**WARNING!** This method is platform dependent and may not work on your +particular target architecture. Refer to the PowerPC section below. + +## Example + +bash# ./pcimem /sys/devices/pci0001\:00/0001\:00\:07.0/resource0 0 w + /sys/devices/pci0001:00/0001:00:07.0/resource0 opened. + Target offset is 0x0, page size is 4096 + mmap(0, 4096, 0x3, 0x1, 3, 0x0) + PCI Memory mapped to address 0x4801f000. + Value at offset 0x0 (0x4801f000): 0xC0BE0100 + +## Why do this at all? + +When I start working on a new PCI device driver I generally go through a +discovery phase of reading and writing to certain registers on the PCI card. +Over the years I have written lots of small kernel modules to probe addresses +within the PCI memory space, constantly iterating: modify code, recompile, scp +to target, load module, unload module, dmesg. + +Urk! There has to be a better way - sysfs and mmap() to the rescue. + +## Sysfs + +Let's start at with the PCI files under sysfs: + +```bash +bash# ls -l /sys/devices/pci0001\:00/0001\:00\:07.0/ +total 0 +-rw-r--r-- 1 root root     4096 Jul  2 20:13 broken_parity_status +lrwxrwxrwx 1 root root        0 Jul  2 20:13 bus -> ../../../bus/pci +-r--r--r-- 1 root root     4096 Jul  2 20:13 class +-rw-r--r-- 1 root root      256 Jul  2 20:13 config +-r--r--r-- 1 root root     4096 Jul  2 20:13 device +-r--r--r-- 1 root root     4096 Jul  2 20:13 devspec +-rw------- 1 root root     4096 Jul  2 20:13 enable +-r--r--r-- 1 root root     4096 Jul  2 20:13 irq +-r--r--r-- 1 root root     4096 Jul  2 20:13 local_cpus +-r--r--r-- 1 root root     4096 Jul  2 20:13 modalias +-rw-r--r-- 1 root root     4096 Jul  2 20:13 msi_bus +-r--r--r-- 1 root root     4096 Jul  2 20:13 resource +-rw------- 1 root root     4096 Jul  2 20:13 resource0 +-rw------- 1 root root    65536 Jul  2 20:13 resource1 +-rw------- 1 root root 16777216 Jul  2 20:13 resource2 +lrwxrwxrwx 1 root root        0 Jul  2 20:13 subsystem -> ../../../bus/pci +-r--r--r-- 1 root root     4096 Jul  2 20:13 subsystem_device +-r--r--r-- 1 root root     4096 Jul  2 20:13 subsystem_vendor +-rw-r--r-- 1 root root     4096 Jul  2 20:13 uevent +-r--r--r-- 1 root root     4096 Jul  2 20:13 vendor +``` + +The vendor and device files report the PCI vendor ID and device ID: + +```bash +bash# cat device +0x0001 +``` + +This info is also available from lspci + +````bash +bash# lspci -v +0001:00:07.0 Class 0680: Unknown device bec0:0001 (rev 01) +    Flags: bus master, 66MHz, medium devsel, latency 128, IRQ 31 +    Memory at 8d010000 (32-bit, non-prefetchable) [size=4K] +    Memory at 8d000000 (32-bit, non-prefetchable) [size=64K] +    Memory at 8c000000 (32-bit, non-prefetchable) [size=16M] +``` + +This PCI card makes 3 seperate regions of memory available to the host +computer. The sysfs resource0 file corresponds to the first memory region. The +PCI card lets the host computer know about these memory regions using the BAR +registers in the PCI config. + +## `mmap()` + +These sysfs resource can be used with mmap() to map the PCI memory into a +userspace applications memory space.  The application then has a pointer to the +start of the PCI memory region and can read and write values directly. (There +is a bit more going on here with respect to memory pointers, but that is all +taken care of by the kernel). + +```c +fd = open("/sys/devices/pci0001\:00/0001\:00\:07.0/resource0", O_RDWR | O_SYNC); +ptr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); +printf("PCI BAR0 0x0000 = 0x%4x\n",  *((unsigned short *) ptr); +``` + +## PowerPC + +To make this work on a PowerPC architecture you also need to make a small +change to the pci core. My example is from kernel 2.6.34, and hopefully this +will be fixed for us in a later kernel version. + +```bash +bash# vi arch/powerpc/kernel/pci-common.c +    /* If memory, add on the PCI bridge address offset */ +     if (mmap_state == pci_mmap_mem) { +-#if 0 /* See comment in pci_resource_to_user() for why this is disabled */ ++#if 1 /* See comment in pci_resource_to_user() for why this is disabled */ +         *offset += hose->pci_mem_offset; + #endif +         res_bit = IORESOURCE_MEM; +  +         /* We pass a fully fixed up address to userland for MMIO instead of +         * a BAR value because X is lame and expects to be able to use that +         * to pass to /dev/mem ! +         * +         * That means that we'll have potentially 64 bits values where some +         * userland apps only expect 32 (like X itself since it thinks only +         * Sparc has 64 bits MMIO) but if we don't do that, we break it on +         * 32 bits CHRPs :-( +         * +         * Hopefully, the sysfs insterface is immune to that gunk. Once X +         * has been fixed (and the fix spread enough), we can re-enable the +         * 2 lines below and pass down a BAR value to userland. In that case +         * we'll also have to re-enable the matching code in +         * __pci_mmap_make_offset(). +         * +         * BenH. +         */ +-#if 0 ++#if 1 +        else if (rsrc->flags & IORESOURCE_MEM) +                offset = hose->pci_mem_offset; +#endif +``` diff --git a/fpga/src/pcimem.c b/fpga/src/pcimem.c new file mode 100644 index 000000000..5e5e11c9e --- /dev/null +++ b/fpga/src/pcimem.c @@ -0,0 +1,132 @@ +/* Simple program to read/write from/to a pci device from userspace. + * + * SPDX-FileCopyrightText: 2010 Bill Farrow + * SPDX-FileCopyrightText: 2023 Institute for Automation of Complex Power Systems, RWTH Aachen University + * + * Based on the devmem2.c code + * + * SPDX-FileCopyrightText: 2000 Jan-Derk Bakker + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PRINT_ERROR \ + do { \ + fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", __LINE__, \ + __FILE__, errno, strerror(errno)); \ + exit(1); \ + } while (0) + +#define MAP_SIZE 4096UL +#define MAP_MASK (MAP_SIZE - 1) + +int main(int argc, char **argv) { + int fd; + void *map_base, *virt_addr; + unsigned read_result, writeval; + char *filename; + off_t target; + int access_type = 'w'; + + if (argc < 3) { + // pcimem /sys/bus/pci/devices/0001\:00\:07.0/resource0 0x100 w 0x00 + // argv[0] [1] [2] [3] [4] + fprintf(stderr, + "\nUsage:\t%s { sys file } { offset } [ type [ data ] ]\n" + "\tsys file: sysfs file for the pci resource to act on\n" + "\toffset : offset into pci memory region to act upon\n" + "\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n" + "\tdata : data to be written\n\n", + argv[0]); + exit(1); + } + + filename = argv[1]; + target = strtoul(argv[2], 0, 0); + + if (argc > 3) + access_type = tolower(argv[3][0]); + + fd = open(filename, O_RDWR | O_SYNC); + if (fd < 0) + PRINT_ERROR; + + printf("%s opened.\n", filename); + printf("Target offset is %#jx, page size is %lu\n", (uintmax_t)target, + sysconf(_SC_PAGE_SIZE)); + + fflush(stdout); + + // Map one page + printf("mmap(%d, %lu, %#x, %#x, %d, %#jx)\n", 0, MAP_SIZE, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, (uintmax_t)target); + + map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + target & ~MAP_MASK); + + if (map_base == (void *)-1) + PRINT_ERROR; + + printf("PCI Memory mapped to address %p.\n", map_base); + fflush(stdout); + + virt_addr = (uint8_t *)map_base + (target & MAP_MASK); + + switch (access_type) { + case 'b': + read_result = *((unsigned char *)virt_addr); + break; + case 'h': + read_result = *((unsigned short *)virt_addr); + break; + case 'w': + read_result = *((unsigned int *)virt_addr); + break; + default: + fprintf(stderr, "Illegal data type '%c'.\n", access_type); + exit(2); + } + + printf("Value at offset %#jx (%p): %#x\n", (uintmax_t)target, virt_addr, + read_result); + fflush(stdout); + + if (argc > 4) { + writeval = strtoul(argv[4], 0, 0); + switch (access_type) { + case 'b': + *((unsigned char *)virt_addr) = writeval; + read_result = *((unsigned char *)virt_addr); + break; + case 'h': + *((unsigned short *)virt_addr) = writeval; + read_result = *((unsigned short *)virt_addr); + break; + case 'w': + *((unsigned int *)virt_addr) = writeval; + read_result = *((unsigned int *)virt_addr); + break; + } + printf("Written %#x; readback %#x\n", writeval, read_result); + fflush(stdout); + } + + if (munmap(map_base, MAP_SIZE) == -1) + PRINT_ERROR; + + close(fd); + + return 0; +} diff --git a/fpga/src/villas-fpga-ctrl.cpp b/fpga/src/villas-fpga-ctrl.cpp new file mode 100644 index 000000000..6232ac782 --- /dev/null +++ b/fpga/src/villas-fpga-ctrl.cpp @@ -0,0 +1,292 @@ +/* Streaming data from STDIN/OUT to FPGA. + * + * Author: Daniel Krebs + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-FileCopyrightText: 2022-2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace villas; + +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("ctrl"); + +void writeToDmaFromStdIn(std::shared_ptr dma) { + auto &alloc = villas::HostRam::getAllocator(); + const std::shared_ptr block = + alloc.allocateBlock(0x200 * sizeof(float)); + villas::MemoryAccessor mem = *block; + dma->makeAccesibleFromVA(block); + + logger->info("Please enter values to write to the device, separated by ';'"); + + while (true) { + // Read values from stdin + std::string line; + std::getline(std::cin, line); + auto values = villas::utils::tokenize(line, ";"); + + size_t i = 0; + for (auto &value : values) { + if (value.empty()) + continue; + + const float number = std::stof(value); + mem[i++] = number; + } + + // Initiate write transfer + bool state = dma->write(*block, i * sizeof(float)); + if (!state) + logger->error("Failed to write to device"); + + auto writeComp = dma->writeComplete(); + logger->debug("Wrote {} bytes", writeComp.bytes); + } + // auto &alloc = villas::HostRam::getAllocator(); + + // const std::shared_ptr block[] = { + // alloc.allocateBlock(0x200 * sizeof(uint32_t)), + // alloc.allocateBlock(0x200 * sizeof(uint32_t)) + // }; + // villas::MemoryAccessor mem[] = {*block[0], *block[1]}; + + // for (auto b : block) { + // dma->makeAccesibleFromVA(b); + // } + + // size_t cur = 0, next = 1; + // std::ios::sync_with_stdio(false); + // std::string line; + // bool firstXfer = true; + + // while(true) { + // // Read values from stdin + + // std::getline(std::cin, line); + // auto values = villas::utils::tokenize(line, ";"); + + // size_t i = 0; + // for (auto &value: values) { + // if (value.empty()) continue; + + // const float number = std::stof(value); + // mem[cur][i++] = number; + // } + + // // Initiate write transfer + // bool state = dma->write(*block[cur], i * sizeof(float)); + // if (!state) + // logger->error("Failed to write to device"); + + // if (!firstXfer) { + // auto bytesWritten = dma->writeComplete(); + // logger->debug("Wrote {} bytes", bytesWritten.bytes); + // } else { + // firstXfer = false; + // } + + // cur = next; + // next = (next + 1) % (sizeof(mem) / sizeof(mem[0])); + // } +} + +void readFromDmaToStdOut( + std::shared_ptr dma, + std::unique_ptr formatter) { + + auto &alloc = villas::HostRam::getAllocator(); + + const std::shared_ptr block[] = { + alloc.allocateBlock(0x200 * sizeof(uint32_t)), + alloc.allocateBlock(0x200 * sizeof(uint32_t))}; + villas::MemoryAccessor mem[] = {*block[0], *block[1]}; + + for (auto b : block) { + dma->makeAccesibleFromVA(b); + } + + size_t cur = 0, next = 1; + std::ios::sync_with_stdio(false); + + // Setup read transfer + dma->read(*block[0], block[0]->getSize()); + + int cnt = 0; + while (true) { + logger->trace("Read from stream and write to address {}:{:#x}", + block[next]->getAddrSpaceId(), block[next]->getOffset()); + // We could use the number of interrupts to determine if we missed a chunk of data + dma->read(*block[next], block[next]->getSize()); + auto c = dma->readComplete(); + + if (c.interrupts > 1) { + logger->warn("Missed {} interrupts", c.interrupts - 1); + } + + logger->trace("bytes: {}, intrs: {}, bds: {}", c.bytes, c.interrupts, + c.bds); + try { + for (size_t i = 0; i * 4 < c.bytes; i++) { + int32_t ival = mem[cur][i]; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + float fval = + *((float *)(&ival)); // cppcheck-suppress invalidPointerCast +#pragma GCC diagnostic pop + formatter->format(fval); + printf("%d: %#x\n", cnt++, ival); + } + formatter->output(std::cout); + } catch (const std::exception &e) { + logger->warn("Failed to output data: {}", e.what()); + } + + cur = next; + next = (next + 1) % (sizeof(mem) / sizeof(mem[0])); + } +} + +int main(int argc, char *argv[]) { + // Command Line Parser + CLI::App app{"VILLASfpga data output"}; + + try { + std::string configFile; + app.add_option("-c,--config", configFile, "Configuration file") + ->check(CLI::ExistingFile); + + std::string fpgaName = "vc707"; + app.add_option("--fpga", fpgaName, "Which FPGA to use"); + std::vector connectStr; + app.add_option("-x,--connect", connectStr, + "Connect a FPGA port with another or stdin/stdout"); + bool noDma = false; + app.add_flag("--no-dma", noDma, + "Do not setup DMA, only setup FPGA and Crossbar links"); + std::string outputFormat = "short"; + app.add_option("--output-format", outputFormat, + "Output format (short, long)"); + bool dumpGraph = false; + app.add_flag("--dump-graph", dumpGraph, + "Dumps the graph of memory regions into \"graph.dot\""); + bool dumpAuroraChannels = true; + app.add_flag("--dump-aurora", dumpAuroraChannels, + "Dumps the detected Aurora channels."); + app.parse(argc, argv); + + // Logging setup + + Log::getInstance().setLevel(spdlog::level::trace); + logger->set_level(spdlog::level::trace); + fpga::setupColorHandling(); + + if (configFile.empty()) { + logger->error( + "No configuration file provided/ Please use -c/--config argument"); + return 1; + } + + auto card = fpga::setupFpgaCard(configFile, fpgaName); + + if (dumpGraph) { + auto &mm = MemoryManager::get(); + mm.getGraph().dump("graph.dot"); + } + + if (dumpAuroraChannels) { + auto aurora_channels = getAuroraChannels(card); + for (auto aurora : *aurora_channels) + aurora->dump(); + } + bool writeToStdout = false; + bool readFromStdin = false; + // Configure Crossbar switch + for (std::string str : connectStr) { + const fpga::ConnectString parsedConnectString(str); + parsedConnectString.configCrossBar(card); + if (parsedConnectString.isSrcStdin()) { + readFromStdin = true; + if (parsedConnectString.isBidirectional()) { + writeToStdout = true; + } + } + if (parsedConnectString.isDstStdout()) { + writeToStdout = true; + if (parsedConnectString.isBidirectional()) { + readFromStdin = true; + } + } + } + auto reg = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:module_ref:registerif:"))); + + if (reg != nullptr && + card->lookupIp(fpga::Vlnv("xilinx.com:module_ref:dinoif_fast:"))) { + fpga::ip::DinoAdc::setRegisterConfigTimestep(reg, 10e-3); + } + + if (writeToStdout || readFromStdin) { + auto dma = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:"))); + if (dma == nullptr) { + logger->error("No DMA found on FPGA "); + throw std::runtime_error("No DMA found on FPGA"); + } + std::unique_ptr stdInThread = nullptr; + if (!noDma && writeToStdout) { + auto formatter = fpga::getBufferedSampleFormatter(outputFormat, 16); + // We copy the dma shared ptr but move the fomatter unqiue ptr as we don't need it + // in this thread anymore + stdInThread = std::make_unique(readFromDmaToStdOut, dma, + std::move(formatter)); + } + if (!noDma && readFromStdin) { + writeToDmaFromStdIn(dma); + } + + if (stdInThread) { + stdInThread->join(); + } + } + } catch (const RuntimeError &e) { + logger->error("Error: {}", e.what()); + return -1; + } catch (const CLI::ParseError &e) { + return app.exit(e); + } catch (const std::exception &e) { + logger->error("Error: {}", e.what()); + return -1; + } catch (...) { + logger->error("Unknown error"); + return -1; + } + + return 0; +} diff --git a/fpga/src/villas-fpga-pipe.cpp b/fpga/src/villas-fpga-pipe.cpp new file mode 100644 index 000000000..b059501c0 --- /dev/null +++ b/fpga/src/villas-fpga-pipe.cpp @@ -0,0 +1,146 @@ +/* Streaming data from STDIN/OUT to FPGA. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace villas; + +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("streamer"); + +int main(int argc, char *argv[]) { + // Command Line Parser + CLI::App app{"VILLASfpga data streamer"}; + + try { + std::string configFile; + app.add_option("-c,--config", configFile, "Configuration file") + ->check(CLI::ExistingFile); + + std::string fpgaName = "vc707"; + app.add_option("--fpga", fpgaName, "Which FPGA to use"); + app.parse(argc, argv); + + // Logging setup + spdlog::set_level(spdlog::level::debug); + fpga::setupColorHandling(); + + if (configFile.empty()) { + logger->error( + "No configuration file provided/ Please use -c/--config argument"); + return 1; + } + + auto card = fpga::setupFpgaCard(configFile, fpgaName); + + std::vector> aurora_channels; + for (int i = 0; i < 4; i++) { + auto name = fmt::format("aurora_8b10b_ch{}", i); + auto id = fpga::ip::IpIdentifier("xilinx.com:ip:aurora_8b10b:", name); + auto aurora = + std::dynamic_pointer_cast(card->lookupIp(id)); + if (aurora == nullptr) { + logger->error("No Aurora interface found on FPGA"); + return 1; + } + + aurora_channels.push_back(aurora); + } + + auto dma = std::dynamic_pointer_cast( + card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:"))); + if (dma == nullptr) { + logger->error("No DMA found on FPGA "); + return 1; + } + + for (auto aurora : aurora_channels) + aurora->dump(); + + // Configure Crossbar switch +#if 1 + aurora_channels[3]->connect(aurora_channels[3]->getDefaultMasterPort(), + dma->getDefaultSlavePort()); + dma->connect(dma->getDefaultMasterPort(), + aurora_channels[3]->getDefaultSlavePort()); +#else + dma->connectLoopback(); +#endif + auto &alloc = villas::HostRam::getAllocator(); + const std::shared_ptr block[] = { + alloc.allocateBlock(0x200 * sizeof(uint32_t)), + alloc.allocateBlock(0x200 * sizeof(uint32_t))}; + villas::MemoryAccessor mem[] = {*block[0], *block[1]}; + + for (auto b : block) { + dma->makeAccesibleFromVA(b); + } + auto &mm = MemoryManager::get(); + mm.getGraph().dump("graph.dot"); + + while (true) { + // Setup read transfer + dma->read(*block[0], block[0]->getSize()); + + // Read values from stdin + std::string line; + std::getline(std::cin, line); + auto values = villas::utils::tokenize(line, ";"); + + size_t i = 0; + for (auto &value : values) { + if (value.empty()) + continue; + + const int32_t number = std::stoi(value); + mem[1][i++] = number; + } + + // Initiate write transfer + bool state = dma->write(*block[1], i * sizeof(int32_t)); + if (!state) + logger->error("Failed to write to device"); + + auto writeComp = dma->writeComplete(); + logger->info("Wrote {} bytes", writeComp.bytes); + + auto readComp = dma->readComplete(); + auto valuesRead = readComp.bytes / sizeof(int32_t); + logger->info("Read {} bytes, {} bds, {} interrupts", readComp.bytes, + readComp.bds, readComp.interrupts); + + for (size_t i = 0; i < valuesRead; i++) + std::cerr << mem[0][i] << ";"; + std::cerr << std::endl; + } + } catch (const RuntimeError &e) { + logger->error("Error: {}", e.what()); + return -1; + } catch (const CLI::ParseError &e) { + return app.exit(e); + } + + return 0; +} diff --git a/fpga/tests/unit/CMakeLists.txt b/fpga/tests/unit/CMakeLists.txt new file mode 100644 index 000000000..e5bbc2a66 --- /dev/null +++ b/fpga/tests/unit/CMakeLists.txt @@ -0,0 +1,47 @@ +## CMakeLists.txt +# +# Author: Daniel Krebs +# SPDX-FileCopyrightText: 2018 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +set(SOURCES + dma.cpp + fifo.cpp + fpga.cpp + logging.cpp + main.cpp + rtds.cpp + timer.cpp +) + +# rtds_rtt.cpp +# hls.cpp +# intc.cpp + +add_executable(unit-tests-fpga ${SOURCES}) + +if (CMAKE_CUDA_COMPILER) + enable_language(CUDA) + target_sources(unit-tests-fpga PRIVATE + gpu.cpp rtds2gpu.cpp gpu_kernels.cu) +endif () + +target_include_directories(unit-tests-fpga PUBLIC + ../include + ${CRITERION_INCLUDE_DIRECTORIES} +) + +target_link_libraries(unit-tests-fpga PUBLIC + villas-fpga + ${CRITERION_LIBRARIES} +) + +add_executable(villasfpga-dma dma.c) + +target_include_directories(villasfpga-dma PUBLIC + ../include +) + +target_link_libraries(villasfpga-dma PUBLIC + villas-fpga +) diff --git a/fpga/tests/unit/dma.c b/fpga/tests/unit/dma.c new file mode 100644 index 000000000..466a1ea2c --- /dev/null +++ b/fpga/tests/unit/dma.c @@ -0,0 +1,100 @@ +/* Testing the C bindings for the VILLASfpga DMA interface. + * + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +int main(int argc, char *argv[]) { + int ret; + villasfpga_handle vh; + villasfpga_memory mem1, mem2; + void *mem1ptr, *mem2ptr; + size_t size; + + if (argv == NULL) { + return 1; + } + if (argc != 2 || argv[1] == NULL) { + fprintf(stderr, "Usage: %s \n", argv[0]); + } + + if ((vh = villasfpga_init(argv[1])) == NULL) { + fprintf(stderr, "Failed to initialize FPGA\n"); + ret = 1; + goto out; + } + + if (villasfpga_alloc(vh, &mem1, 0x200 * sizeof(uint32_t)) != 0) { + fprintf(stderr, "Failed to allocate DMA memory 1\n"); + ret = 1; + goto out; + } + + if (villasfpga_alloc(vh, &mem2, 0x200 * sizeof(uint32_t)) != 0) { + fprintf(stderr, "Failed to allocate DMA memory 2\n"); + ret = 1; + goto out; + } + + if ((mem1ptr = villasfpga_get_ptr(mem1)) == NULL) { + fprintf(stderr, "Failed to get pointer to DMA memory 1\n"); + ret = 1; + goto out; + } + + if ((mem2ptr = villasfpga_get_ptr(mem2)) == NULL) { + fprintf(stderr, "Failed to get pointer to DMA memory 2\n"); + ret = 1; + goto out; + } + + printf("DMA memory 1: %p, DMA memory 2: %p\n", mem1ptr, mem2ptr); + + while (1) { + // Setup read transfer + if ((ret = villasfpga_read(vh, mem1, 0x200 * sizeof(uint32_t))) != 0) { + fprintf(stderr, "Failed to initiate read transfer\n"); + ret = 1; + goto out; + } + + printf("Enter a float:\n"); + if ((ret = scanf("%f", (float *)mem2ptr)) != 1) { + fprintf(stderr, "Failed to parse input: sscanf returned %d\n", ret); + ret = 1; + goto out; + } + printf("sending %f (%zu bytes)\n", ((float *)mem2ptr)[0], sizeof(float)); + // Initiate write transfer + if ((ret = villasfpga_write(vh, mem2, sizeof(float))) != 0) { + fprintf(stderr, "Failed to initiate write transfer\n"); + ret = 1; + goto out; + } + + if ((ret = villasfpga_write_complete(vh, &size)) != 0) { + fprintf(stderr, "Failed to write complete\n"); + ret = 1; + goto out; + } + + if ((ret = villasfpga_read_complete(vh, &size)) != 0) { + fprintf(stderr, "Failed to write complete\n"); + ret = 1; + goto out; + } + + printf("Read %f (%zu bytes)\n", ((float *)mem1ptr)[0], size); + } + + ret = 0; +out: + return ret; +} diff --git a/fpga/tests/unit/dma.cpp b/fpga/tests/unit/dma.cpp new file mode 100644 index 000000000..6700266dd --- /dev/null +++ b/fpga/tests/unit/dma.cpp @@ -0,0 +1,98 @@ +/* DMA unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "global.hpp" + +using namespace villas; + +// cppcheck-suppress unknownMacro +Test(fpga, dma, .description = "DMA") { + auto logger = Log::get("unit-test:dma"); + + std::list> dmaIps; + + for (auto &ip : state.cards.front()->ips) { + if (*ip == fpga::Vlnv("xilinx.com:ip:axi_dma:")) { + auto dma = std::dynamic_pointer_cast(ip); + dmaIps.push_back(dma); + } + } + + size_t count = 0; + for (auto &dma : dmaIps) { + logger->info("Testing {}", *dma); + + if (not dma->loopbackPossible()) { + logger->info("Loopback test not possible for {}", *dma); + continue; + } + + dma->connectLoopback(); + + // Simple DMA can only transfer up to 4 kb due to PCIe page size burst + // limitation + size_t len = 4 * (1 << 10); + +#if 0 + // Allocate memory to use with DMA + auto src = HostDmaRam::getAllocator().allocate(len); + auto dst = HostDmaRam::getAllocator().allocate(len); +#elif 0 + // ... only works with IOMMU enabled currently + + // Find a block RAM IP to write to + auto bramIp = state.cards.front()->lookupIp( + fpga::Vlnv("xilinx.com:ip:axi_bram_ctrl:")); + auto bram = std::dynamic_pointer_cast(bramIp); + cr_assert_not_null(bram, "Couldn't find BRAM"); + + auto src = bram->getAllocator().allocate(len); + auto dst = bram->getAllocator().allocate(len); +#else + // ... only works with IOMMU enabled currently + auto &alloc = villas::HostRam::getAllocator(); + const std::shared_ptr srcBlock = + alloc.allocateBlock(len); + const std::shared_ptr dstBlock = + alloc.allocateBlock(len); + villas::MemoryAccessor src(*srcBlock); + villas::MemoryAccessor dst(*dstBlock); +#endif + // Make sure memory is accessible for DMA + dma->makeAccesibleFromVA(srcBlock); + dma->makeAccesibleFromVA(dstBlock); + + // Get new random data + const size_t lenRandom = utils::readRandom(&src, len); + cr_assert(len == lenRandom, "Failed to get random data"); + + // Start transfer + cr_assert(dma->memcpy(src.getMemoryBlock(), dst.getMemoryBlock(), len), + "DMA ping pong failed"); + + // Compare data + cr_assert(memcmp(&src, &dst, len) == 0, "Data not equal"); + + logger->info(CLR_GRN("Passed")); + + count++; + } + + cr_assert(count > 0, "No DMA found"); + + MemoryManager::get().getGraph().dump(); + fpga::ip::Node::getGraph().dump(); +} diff --git a/fpga/tests/unit/fifo.cpp b/fpga/tests/unit/fifo.cpp new file mode 100644 index 000000000..f875aa30d --- /dev/null +++ b/fpga/tests/unit/fifo.cpp @@ -0,0 +1,75 @@ +/* FIFO unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include +#include + +#include "global.hpp" + +using namespace villas; + +// cppcheck-suppress unknownMacro +Test(fpga, fifo, .description = "FIFO") { + ssize_t len; + char src[255], dst[255]; + size_t count = 0; + + auto logger = Log::get("unit-test:fifo"); + + for (auto &ip : state.cards.front()->ips) { + // Skip non-fifo IPs + if (*ip != fpga::Vlnv("xilinx.com:ip:axi_fifo_mm_s:")) + continue; + + logger->info("Testing {}", *ip); + + auto fifo = std::dynamic_pointer_cast(ip); + + if (not fifo->loopbackPossible()) { + logger->info("Loopback test not possible for {}", *ip); + continue; + } + + if (not fifo->connectLoopback()) { + continue; + } + + // Get some random data to compare + memset(dst, 0, sizeof(dst)); + len = utils::readRandom((char *)src, sizeof(src)); + if (len != sizeof(src)) { + logger->error("Failed to get random data"); + continue; + } + + len = fifo->write(src, sizeof(src)); + if (len != sizeof(src)) { + logger->error("Failed to send to FIFO"); + continue; + } + + len = fifo->read(dst, sizeof(dst)); + if (len != sizeof(dst)) { + logger->error("Failed to read from FIFO"); + continue; + } + + // Compare data + cr_assert_eq(memcmp(src, dst, sizeof(src)), 0, "Data not equal"); + + logger->info(CLR_GRN("Passed")); + + count++; + } + + cr_assert(count > 0, "No FIFO found"); +} diff --git a/fpga/tests/unit/fpga.cpp b/fpga/tests/unit/fpga.cpp new file mode 100644 index 000000000..587cc0264 --- /dev/null +++ b/fpga/tests/unit/fpga.cpp @@ -0,0 +1,83 @@ +/* FPGA related code for bootstrapping the unit-tests + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2018 Steffen Vogel + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023 Niklas Eiling + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include + +#include "global.hpp" + +#include + +#define FPGA_CARD "vc707" +#define TEST_CONFIG "../etc/fpga.json" +#define TEST_LEN 0x1000 + +#define CPU_HZ 3392389000 +#define FPGA_AXI_HZ 125000000 + +using namespace villas; + +static kernel::devices::PciDeviceList *pciDevices; + +FpgaState state; + +static void init() { + FILE *f; + json_error_t err; + + spdlog::set_level(spdlog::level::debug); + spdlog::set_pattern("[%T] [%l] [%n] %v"); + + plugin::registry->dump(); + + pciDevices = kernel::devices::PciDeviceList::getInstance(); + + auto vfioContainer = std::make_shared(); + + // Parse FPGA configuration + char *fn = getenv("TEST_CONFIG"); + f = fopen(fn ? fn : TEST_CONFIG, "r"); + cr_assert_not_null(f, "Cannot open config file"); + + json_t *json = json_loadf(f, 0, &err); + cr_assert_not_null(json, "Cannot load JSON config"); + + fclose(f); + + json_t *fpgas = json_object_get(json, "fpgas"); + cr_assert_not_null(fpgas, "No section 'fpgas' found in config"); + cr_assert(json_object_size(json) > 0, "No FPGAs defined in config"); + + // Get the FPGA card plugin + auto fpgaCardFactory = + plugin::registry->lookup("pcie"); + cr_assert_not_null(fpgaCardFactory, "No plugin for FPGA card found"); + + // Create all FPGA card instances using the corresponding plugin + auto configDir = std::filesystem::path(fn).parent_path(); + auto cards = std::list>(); + fpga::createCards(json, cards, configDir); + state.cards = cards; + + cr_assert(state.cards.size() != 0, "No FPGA cards found!"); + + json_decref(json); +} + +static void fini() { + // Release all cards + state.cards.clear(); +} + +// cppcheck-suppress unknownMacro +TestSuite(fpga, .init = init, .fini = fini, .description = "VILLASfpga"); diff --git a/fpga/tests/unit/global.hpp b/fpga/tests/unit/global.hpp new file mode 100644 index 000000000..01f35799a --- /dev/null +++ b/fpga/tests/unit/global.hpp @@ -0,0 +1,21 @@ +/* Global include for tests. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include + +class FpgaState { +public: + // List of all available FPGA cards, only first will be tested at the moment + std::list> cards; +}; + +// Global state to be shared by unittests +extern FpgaState state; diff --git a/fpga/tests/unit/gpu.cpp b/fpga/tests/unit/gpu.cpp new file mode 100644 index 000000000..e9bbfe194 --- /dev/null +++ b/fpga/tests/unit/gpu.cpp @@ -0,0 +1,135 @@ +/* GPU unit tests. + * +* Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include "global.hpp" + +#include +#include + +using namespace villas; + +// cppcheck-suppress unknownMacro +Test(fpga, gpu_dma, .description = "GPU DMA tests") { + auto logger = Log::get("unit-test:dma"); + + auto &card = state.cards.front(); + + auto gpuPlugin = Plugin::Registry("cuda"); + cr_assert_not_null(gpuPlugin, "No GPU plugin found"); + + auto gpus = gpuPlugin->make(); + cr_assert(gpus.size() > 0, "No GPUs found"); + + // Just get first cpu + auto &gpu = gpus.front(); + + size_t count = 0; + for (auto &ip : card->ips) { + // Skip non-dma IPs + if (*ip != fpga::Vlnv("xilinx.com:ip:axi_bram_ctrl:")) + continue; + + logger->info("Testing {}", *ip); + + auto bram = dynamic_cast(ip.get()); + cr_assert_not_null(bram, "Couldn't find BRAM"); + + count++; + + size_t len = 4 * (1 << 10); + + // Allocate memory to use with DMA + + auto bram0 = bram->getAllocator().allocate(len); + auto bram1 = bram->getAllocator().allocate(len); + + gpu->makeAccessibleFromPCIeOrHostRam(bram0.getMemoryBlock()); + gpu->makeAccessibleFromPCIeOrHostRam(bram1.getMemoryBlock()); + + auto hostRam0 = HostRam::getAllocator().allocate(len); + auto hostRam1 = HostRam::getAllocator().allocate(len); + + gpu->makeAccessibleFromPCIeOrHostRam(hostRam0.getMemoryBlock()); + gpu->makeAccessibleFromPCIeOrHostRam(hostRam1.getMemoryBlock()); + + auto dmaRam0 = HostDmaRam::getAllocator().allocate(len); + auto dmaRam1 = HostDmaRam::getAllocator().allocate(len); + + gpu->makeAccessibleFromPCIeOrHostRam(dmaRam0.getMemoryBlock()); + gpu->makeAccessibleFromPCIeOrHostRam(dmaRam1.getMemoryBlock()); + + auto gpuMem0 = gpu->getAllocator().allocate(64 << 10); + auto gpuMem1 = gpu->getAllocator().allocate(64 << 10); + + gpu->makeAccessibleToPCIeAndVA(gpuMem0.getMemoryBlock()); + gpu->makeAccessibleToPCIeAndVA(gpuMem1.getMemoryBlock()); + + // auto &src = bram0; + // auto &dst = bram1; + + // auto &src = hostRam0; + // auto &dst = hostRam1; + + auto &src = dmaRam0; + // auto &dst = dmaRam1; + + // auto &src = gpuMem0; + auto &dst = gpuMem1; + + std::list>> memcpyFuncs = { + {"cudaMemcpy", + [&]() { + gpu->memcpySync(src.getMemoryBlock(), dst.getMemoryBlock(), len); + }}, + {"CUDA kernel", + [&]() { + gpu->memcpyKernel(src.getMemoryBlock(), dst.getMemoryBlock(), len); + }}, + }; + + auto dmaIp = card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:")); + auto dma = std::dynamic_pointer_cast(dmaIp); + + if (dma != nullptr and dma->connectLoopback()) { + memcpyFuncs.push_back({"DMA memcpy", [&]() { + dma->makeAccesibleFromVA(src.getMemoryBlock()); + dma->makeAccesibleFromVA(dst.getMemoryBlock()); + dma->memcpy(src.getMemoryBlock(), + dst.getMemoryBlock(), len); + }}); + } + + for (auto &[name, memcpyFunc] : memcpyFuncs) { + logger->info("Testing {}", name); + + // Get new random data + const size_t lenRandom = utils::read_random(&src, len); + cr_assert(len == lenRandom, "Failed to get random data"); + + memcpyFunc(); + const bool success = memcmp(&src, &dst, len) == 0; + + logger->info(" {}", success ? CLR_GRN("Passed") : CLR_RED("Failed")); + } + + MemoryManager::getGraph().dump(); + } + + cr_assert(count > 0, "No BRAM found"); +} diff --git a/fpga/tests/unit/gpu_kernels.cu b/fpga/tests/unit/gpu_kernels.cu new file mode 100644 index 000000000..3e6676ff0 --- /dev/null +++ b/fpga/tests/unit/gpu_kernels.cu @@ -0,0 +1,79 @@ +/** GPU CUDA kernel + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + *********************************************************************************/ + +#include +#include + +#include +#include + +#include +#include + +__global__ void +gpu_rtds_rtt_kernel(volatile uint32_t* dataIn, volatile reg_doorbell_t* doorbellIn, + volatile uint32_t* dataOut, volatile villas::fpga::ip::ControlRegister* controlRegister, + int* run) +{ + printf("[gpu] gpu kernel go\n"); + + printf("dataIn: %p\n", dataIn); + printf("doorbellIn: %p\n", doorbellIn); + printf("dataOut: %p\n", dataOut); + printf("control: %p\n", controlRegister); + printf("run: %p\n", run); + +// *run = reinterpret_cast(malloc(sizeof(bool))); +// **run = true; + + uint32_t last_seq; + while (*run) { + // wait for data +// printf("[gpu] wait for data, last_seq=%u\n", last_seq); + while (not (doorbellIn->is_valid and (last_seq != doorbellIn->seq_nr)) and *run); +// printf("doorbell: 0x%08x\n", doorbellIn->value); + + last_seq = doorbellIn->seq_nr; + +// printf("[gpu] copy data\n"); + for (size_t i = 0; i < doorbellIn->count; i++) { + dataOut[i] = dataIn[i]; + } + + // reset doorbell +// printf("[gpu] reset doorbell\n"); +// doorbellIn->value = 0; + +// printf("[gpu] signal go for gpu2rtds\n"); + controlRegister->ap_start = 1; + } + + printf("kernel done\n"); +} + +static int* run = nullptr; + +void gpu_rtds_rtt_start(volatile uint32_t* dataIn, volatile reg_doorbell_t* doorbellIn, + volatile uint32_t* dataOut, volatile villas::fpga::ip::ControlRegister* controlRegister) +{ + printf("run: %p\n", run); + if (run == nullptr) { + run = (int*)malloc(sizeof(uint32_t)); + cudaHostRegister(run, sizeof(uint32_t), 0); + } + printf("run: %p\n", run); + + *run = 1; + gpu_rtds_rtt_kernel<<<1, 1>>>(dataIn, doorbellIn, dataOut, controlRegister, run); + printf("[cpu] kernel launched\n"); +} + +void gpu_rtds_rtt_stop() +{ + *run = 0; + cudaDeviceSynchronize(); +} diff --git a/fpga/tests/unit/logging.cpp b/fpga/tests/unit/logging.cpp new file mode 100644 index 000000000..46abafdbc --- /dev/null +++ b/fpga/tests/unit/logging.cpp @@ -0,0 +1,114 @@ +/* Logging utilities for unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include +#include + +extern "C" { +// We override criterions function here +void criterion_log_noformat(enum criterion_severity severity, const char *msg); +void criterion_plog(enum criterion_logging_level level, + const struct criterion_prefix_data *prefix, const char *msg, + ...); +void criterion_vlog(enum criterion_logging_level level, const char *msg, + va_list args); +} + +struct criterion_prefix_data { + const char *prefix; + const char *color; +}; + +static int format_msg(char *buf, size_t buflen, const char *msg, va_list args) { + int len = vsnprintf(buf, buflen, msg, args); + + // Strip new line + char *nl = strchr(buf, '\n'); + if (nl) + *nl = 0; + + return len; +} + +void criterion_log_noformat(enum criterion_severity severity, const char *msg) { + auto logger = villas::Log::get("criterion"); + + switch (severity) { + case CR_LOG_INFO: + logger->info(msg); + break; + + case CR_LOG_WARNING: + logger->warn(msg); + break; + + case CR_LOG_ERROR: + logger->error(msg); + break; + } +} + +void criterion_vlog(enum criterion_logging_level level, const char *msg, + va_list args) { + char formatted_msg[1024]; + + if (level < criterion_options.logging_threshold) + return; + + format_msg(formatted_msg, sizeof(formatted_msg), msg, args); + + auto logger = villas::Log::get("criterion"); + logger->info(formatted_msg); +} + +void criterion_plog(enum criterion_logging_level level, + const struct criterion_prefix_data *prefix, const char *msg, + ...) { + char formatted_msg[1024]; + + va_list args; + + if (level < criterion_options.logging_threshold) + return; + + va_start(args, msg); + format_msg(formatted_msg, sizeof(formatted_msg), msg, args); + va_end(args); + + auto logger = villas::Log::get("criterion"); + + if (strstr(formatted_msg, "Warning")) + logger->warn(formatted_msg); + else if (strstr(formatted_msg, "Failed")) + logger->error(formatted_msg); + else if (!strcmp(prefix->prefix, "----") && + !strcmp(prefix->color, "\33[0;34m")) + logger->info(formatted_msg); + else if (!strcmp(prefix->prefix, "----") && + !strcmp(prefix->color, "\33[1;30m")) + logger->debug(formatted_msg); + else if (!strcmp(prefix->prefix, "====")) + logger->info(formatted_msg); + else if (!strcmp(prefix->prefix, "RUN ")) + logger->info("Run: {}", formatted_msg); + else if (!strcmp(prefix->prefix, "SKIP")) + logger->info("Skip: {}", formatted_msg); + else if (!strcmp(prefix->prefix, "PASS")) + logger->info("Pass: {}", formatted_msg); + else if (!strcmp(prefix->prefix, "FAIL")) + logger->error("Fail: {}", formatted_msg); + else if (!strcmp(prefix->prefix, "WARN")) + logger->warn(formatted_msg); + else if (!strcmp(prefix->prefix, "ERR ")) + logger->error(formatted_msg); +} diff --git a/fpga/tests/unit/main.cpp b/fpga/tests/unit/main.cpp new file mode 100644 index 000000000..8aeb32d7d --- /dev/null +++ b/fpga/tests/unit/main.cpp @@ -0,0 +1,61 @@ +/* Main Unit Test entry point. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include + +#include + +// Returns true if there is at least one enabled test in this suite +static bool suite_enabled(struct criterion_test_set *tests, const char *name) { + FOREACH_SET(void *suite_ptr, tests->suites) { + struct criterion_suite_set *suite = (struct criterion_suite_set *)suite_ptr; + + if (!strcmp(suite->suite.name, name)) { + FOREACH_SET(void *test_ptr, suite->tests) { + struct criterion_test *test = (struct criterion_test *)test_ptr; + + if (!test->data->disabled) + return true; + } + } + } + + return false; +} + +// Limit number of parallel jobs to 1 in case we use the FPGA +ReportHook(PRE_ALL)(struct criterion_test_set *tests) { + if (suite_enabled(tests, "fpga")) { + auto logger = villas::Log::get("unittest"); + + logger->info("FPGA tests enabled. Only 1 job is executed in parallel!."); + criterion_options.jobs = 1; + } +} + +int main(int argc, char *argv[]) { + int ret; + + spdlog::set_level(spdlog::level::debug); + spdlog::set_pattern("[%T] [%l] [%n] %v"); + + // Run criterion tests + auto tests = criterion_initialize(); + + ret = criterion_handle_args(argc, argv, true); + if (ret) + ret = !criterion_run_all_tests(tests); + + criterion_finalize(tests); + + return ret; +} diff --git a/fpga/tests/unit/rtds.cpp b/fpga/tests/unit/rtds.cpp new file mode 100644 index 000000000..b5728667b --- /dev/null +++ b/fpga/tests/unit/rtds.cpp @@ -0,0 +1,120 @@ +/* RTDS AXI-Stream RTT unit test. + * + * Author: Steffen Vogel + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2018 Steffen Vogel + * SPDX-FileCopyrightText: 2018 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "global.hpp" + +using namespace villas::fpga::ip; + +// cppcheck-suppress unknownMacro +Test(fpga, rtds, .description = "RTDS") { + auto logger = villas::Log::get("unit-test:rtds"); + + std::list rtdsIps; + std::list dmaIps; + + for (auto &ip : state.cards.front()->ips) { + if (*ip == + villas::fpga::Vlnv("acs.eonerc.rwth-aachen.de:user:rtds_axis:")) { + auto rtds = reinterpret_cast(ip.get()); + rtdsIps.push_back(rtds); + } + + if (*ip == villas::fpga::Vlnv("xilinx.com:ip:axi_dma:")) { + auto dma = reinterpret_cast(ip.get()); + dmaIps.push_back(dma); + } + } + + cr_assert(rtdsIps.size() > 0, "No RTDS IPs available to test"); + cr_assert(dmaIps.size() > 0, "No DMA IPs available to test RTDS with"); + + for (auto rtds : rtdsIps) { + for (auto dma : dmaIps) { + logger->info("Testing {} with DMA {}", *rtds, *dma); + + rtds->dump(); + + auto rtdsMaster = rtds->getMasterPort(rtds->masterPort); + auto rtdsSlave = rtds->getSlavePort(rtds->slavePort); + + auto dmaMaster = dma->getMasterPort(dma->mm2sPort); + auto dmaSlave = dma->getSlavePort(dma->s2mmPort); + + // rtds->connect(*rtds); + // logger->info("loopback"); + // while (1); + + // rtds->connect(rtdsMaster, dmaSlave); + // dma->connect(dmaMaster, rtdsSlave); + + auto mem = villas::HostRam::getAllocator().allocate( + 0x100 / sizeof(int32_t)); + + // auto start = std::chrono::high_resolution_clock::now(); + + for (int i = 1; i < 5; i++) { + logger->info("RTT iteration {}", i); + + // logger->info("Prepare read"); + cr_assert( + dma->read(mem.getMemoryBlock(), mem.getMemoryBlock().getSize()), + "Failed to initiate DMA read"); + + // logger->info("Wait read"); + const size_t bytesRead = dma->readComplete().bytes; + cr_assert(bytesRead > 0, "Failed to complete DMA read"); + + // logger->info("Bytes received: {}", bytesRead); + // logger->info("Prepare write"); + cr_assert(dma->write(mem.getMemoryBlock(), bytesRead), + "Failed to initiate DMA write"); + + // logger->info("Wait write"); + // const size_t bytesWritten = dma->writeComplete(); + // cr_assert(bytesWritten > 0, + // "Failed to complete DMA write"); + + // usleep(5); + // sched_yield(); + + // for (int i = 0;) + // rdtsc_sleep(); + + // static constexpr int loopCount = 10000; + // if (i % loopCount == 0) { + // const auto end = std::chrono::high_resolution_clock::now(); + + // auto durationUs = std::chrono::duration_cast(end - start) / loopCount; + + // logger->info("Avg. loop duration: {} us", durationUs.count()); + + // start = std::chrono::high_resolution_clock::now(); + // } + } + + logger->info(CLR_GRN("Passed")); + } + } +} diff --git a/fpga/tests/unit/rtds2gpu.cpp b/fpga/tests/unit/rtds2gpu.cpp new file mode 100644 index 000000000..20ba0890a --- /dev/null +++ b/fpga/tests/unit/rtds2gpu.cpp @@ -0,0 +1,334 @@ +/* FIFO unit test. + * + * Author: Daniel Krebs + * SPDX-FileCopyrightText: 2017 Daniel Krebs + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "global.hpp" + +using namespace villas; + +static constexpr size_t SAMPLE_SIZE = 4; +static constexpr size_t SAMPLE_COUNT = 1; +static constexpr size_t FRAME_SIZE = SAMPLE_COUNT * SAMPLE_SIZE; + +static constexpr size_t DOORBELL_OFFSET = SAMPLE_COUNT; +static constexpr size_t DATA_OFFSET = 0; + +static void dumpMem(const uint32_t *addr, size_t len) { + const size_t bytesPerLine = 16; + const size_t lines = (len) / bytesPerLine + 1; + const uint8_t *buf = reinterpret_cast(addr); + + size_t bytesRead = 0; + + for (size_t line = 0; line < lines; line++) { + const unsigned base = line * bytesPerLine; + printf("0x%04x: ", base); + + for (size_t i = 0; i < bytesPerLine && bytesRead < len; i++) { + printf("0x%02x ", buf[base + i]); + bytesRead++; + } + puts(""); + } +} + +// cppcheck-suppress unknownMacro +Test(fpga, rtds2gpu_loopback_dma, .description = "Rtds2Gpu") { + auto logger = Log::get("unit-test:rtds2gpu"); + + for (auto &ip : state.cards.front()->ips) { + if (*ip != fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:rtds2gpu:")) + continue; + + logger->info("Testing {}", *ip); + + // Collect neccessary IPs + auto rtds2gpu = std::dynamic_pointer_cast(ip); + + auto axiSwitch = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("xilinx.com:ip:axis_switch:"))); + + auto dma = std::dynamic_pointer_cast( + state.cards.front()->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:"))); + + auto gpu2rtds = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:gpu2rtds:"))); + + auto rtds = + std::dynamic_pointer_cast(state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:user:rtds_axis:"))); + + cr_assert_not_null(axiSwitch, "No AXI switch IP found"); + cr_assert_not_null(dma, "No DMA IP found"); + cr_assert_not_null(gpu2rtds, "No Gpu2Rtds IP found"); + cr_assert_not_null(rtds, "RTDS IP not found"); + + rtds2gpu.dump(spdlog::level::debug); + gpu2rtds->dump(spdlog::level::debug); + + // Allocate and prepare memory + + // Allocate space for all samples and doorbell register + auto dmaMemSrc = + HostDmaRam::getAllocator(0).allocate(SAMPLE_COUNT + 1); + auto dmaMemDst = + HostDmaRam::getAllocator(0).allocate(SAMPLE_COUNT + 1); + auto dmaMemDst2 = + HostDmaRam::getAllocator(0).allocate(SAMPLE_COUNT + 1); + + memset(&dmaMemSrc, 0x11, dmaMemSrc.getMemoryBlock().getSize()); + memset(&dmaMemDst, 0x55, dmaMemDst.getMemoryBlock().getSize()); + memset(&dmaMemDst2, 0x77, dmaMemDst2.getMemoryBlock().getSize()); + + const uint32_t *dataSrc = &dmaMemSrc[DATA_OFFSET]; + const uint32_t *dataDst = &dmaMemDst[DATA_OFFSET]; + const uint32_t *dataDst2 = &dmaMemDst2[0]; + + dumpMem(dataSrc, dmaMemSrc.getMemoryBlock().getSize()); + dumpMem(dataDst, dmaMemDst.getMemoryBlock().getSize()); + dumpMem(dataDst2, dmaMemDst2.getMemoryBlock().getSize()); + + // Connect AXI Stream from DMA to Rtds2Gpu IP + cr_assert(dma->connect(rtds2gpu)); + + cr_assert(rtds2gpu.startOnce(dmaMemDst.getMemoryBlock(), SAMPLE_COUNT, + DATA_OFFSET * 4, DOORBELL_OFFSET * 4), + "Preparing Rtds2Gpu IP failed"); + + cr_assert(dma->write(dmaMemSrc.getMemoryBlock(), FRAME_SIZE), + "Starting DMA MM2S transfer failed"); + + cr_assert(dma->writeComplete(), "DMA failed"); + + while (not rtds2gpu.isFinished()) + ; + + const uint32_t *doorbellDst = &dmaMemDst[DOORBELL_OFFSET]; + rtds2gpu.dump(spdlog::level::info); + rtds2gpu.dumpDoorbell(*doorbellDst); + + cr_assert(memcmp(dataSrc, dataDst, FRAME_SIZE) == 0, "Memory not equal"); + + for (size_t i = 0; i < SAMPLE_COUNT; i++) + gpu2rtds->registerFrames[i] = dmaMemDst[i]; + + // Connect AXI Stream from Gpu2Rtds IP to DMA + cr_assert(gpu2rtds->connect(*dma)); + + cr_assert(dma->read(dmaMemDst2.getMemoryBlock(), FRAME_SIZE), + "Starting DMA S2MM transfer failed"); + + cr_assert(gpu2rtds->startOnce(SAMPLE_COUNT), + "Preparing Gpu2Rtds IP failed"); + + cr_assert(dma->readComplete(), "DMA failed"); + + while (not gpu2rtds->isFinished()) + ; + + cr_assert(memcmp(dataSrc, dataDst2, FRAME_SIZE) == 0, "Memory not equal"); + + dumpMem(dataSrc, dmaMemSrc.getMemoryBlock().getSize()); + dumpMem(dataDst, dmaMemDst.getMemoryBlock().getSize()); + dumpMem(dataDst2, dmaMemDst2.getMemoryBlock().getSize()); + + logger->info(CLR_GRN("Passed")); + } +} + +// cppcheck-suppress unknownMacro +Test(fpga, rtds2gpu_rtt_cpu, .description = "Rtds2Gpu RTT via CPU") { + auto logger = Log::get("unit-test:rtds2gpu"); + + // Collect neccessary IPs + auto gpu2rtds = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:gpu2rtds:"))); + + auto rtds2gpu = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:rtds2gpu:"))); + + cr_assert_not_null(gpu2rtds, "No Gpu2Rtds IP found"); + cr_assert_not_null(rtds2gpu, "No Rtds2Gpu IP not found"); + + for (auto &ip : state.cards.front()->ips) { + if (*ip != fpga::Vlnv("acs.eonerc.rwth-aachen.de:user:rtds_axis:")) + continue; + + auto &rtds = dynamic_cast(*ip); + logger->info("Testing {}", rtds); + + auto dmaRam = + HostDmaRam::getAllocator().allocate(SAMPLE_COUNT + 1); + uint32_t *data = &dmaRam[DATA_OFFSET]; + uint32_t *doorbell = &dmaRam[DOORBELL_OFFSET]; + + // TEST: rtds loopback via switch, this should always work and have RTT=1 + //cr_assert(rtds.connect(rtds)); + //logger->info("loopback"); + //while (1); + + cr_assert(rtds.connect(*rtds2gpu)); + cr_assert(gpu2rtds->connect(rtds)); + + for (size_t i = 1; i <= 10000;) { + rtds2gpu->doorbellReset(*doorbell); + rtds2gpu->startOnce(dmaRam.getMemoryBlock(), SAMPLE_COUNT, + DATA_OFFSET * 4, DOORBELL_OFFSET * 4); + + // Wait by polling rtds2gpu IP or ... + // while (not rtds2gpu->isFinished()); + + // Wait by polling (local) doorbell register (= just memory) + while (not rtds2gpu->doorbellIsValid(*doorbell)) + ; + + // Copy samples to gpu2rtds IP + for (size_t i = 0; i < SAMPLE_COUNT; i++) { + gpu2rtds->registerFrames[i] = data[i]; + } + + // Waiting for gpu2rtds is not strictly required + gpu2rtds->startOnce(SAMPLE_COUNT); + //while (not gpu2rtds->isFinished()); + + if (i % 1000 == 0) { + logger->info("Successful iterations {}, data {}", i, data[0]); + rtds2gpu->dump(); + rtds2gpu->dumpDoorbell(data[1]); + } + } + + logger->info(CLR_GRN("Passed")); + } +} + +void gpu_rtds_rtt_start(volatile uint32_t *dataIn, + volatile reg_doorbell_t *doorbellIn, + volatile uint32_t *dataOut, + volatile fpga::ip::ControlRegister *controlRegister); + +void gpu_rtds_rtt_stop(); + +// cppcheck-suppress unknownMacro +Test(fpga, rtds2gpu_rtt_gpu, .description = "Rtds2Gpu RTT via GPU") { + auto logger = Log::get("unit-test:rtds2gpu"); + + // Collect neccessary IPs + auto gpu2rtds = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:gpu2rtds:"))); + + auto rtds2gpu = std::dynamic_pointer_cast( + state.cards.front()->lookupIp( + fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:rtds2gpu:"))); + + cr_assert_not_null(gpu2rtds, "No Gpu2Rtds IP found"); + cr_assert_not_null(rtds2gpu, "No Rtds2Gpu IP not found"); + + auto gpuPlugin = Registry::lookup("cuda"); + cr_assert_not_null(gpuPlugin, "No GPU plugin found"); + + auto gpus = gpuPlugin->make(); + cr_assert(gpus.size() > 0, "No GPUs found"); + + // Just get first cpu + auto &gpu = gpus.front(); + + // Allocate memory on GPU and make accessible by to PCIe/FPGA + auto gpuRam = gpu->getAllocator().allocate(SAMPLE_COUNT + 1); + cr_assert(gpu->makeAccessibleToPCIeAndVA(gpuRam.getMemoryBlock())); + + // Make Gpu2Rtds IP register memory on FPGA accessible to GPU + cr_assert( + gpu->makeAccessibleFromPCIeOrHostRam(gpu2rtds->getRegisterMemory())); + + auto tr = gpu->translate(gpuRam.getMemoryBlock()); + + auto dataIn = reinterpret_cast( + tr.getLocalAddr(DATA_OFFSET * sizeof(uint32_t))); + auto doorbellIn = reinterpret_cast( + tr.getLocalAddr(DOORBELL_OFFSET * sizeof(uint32_t))); + + auto gpu2rtdsRegisters = gpu->translate(gpu2rtds->getRegisterMemory()); + + auto frameRegister = reinterpret_cast( + gpu2rtdsRegisters.getLocalAddr(gpu2rtds->registerFrameOffset)); + auto controlRegister = reinterpret_cast( + gpu2rtdsRegisters.getLocalAddr(gpu2rtds->registerControlAddr)); + + // auto doorbellInCpu = reinterpret_cast(&gpuRam[DOORBELL_OFFSET]); + + for (auto &ip : state.cards.front()->ips) { + if (*ip != fpga::Vlnv("acs.eonerc.rwth-aachen.de:user:rtds_axis:")) + continue; + + auto &rtds = dynamic_cast(*ip); + logger->info("Testing {}", rtds); + + // TEST: rtds loopback via switch, this should always work and have RTT=1 + //cr_assert(rtds.connect(rtds)); + //logger->info("loopback"); + //while (1); + + cr_assert(rtds.connect(*rtds2gpu)); + cr_assert(gpu2rtds->connect(rtds)); + + // Launch once so they are configured + cr_assert(rtds2gpu->startOnce(gpuRam.getMemoryBlock(), SAMPLE_COUNT, + DATA_OFFSET * 4, DOORBELL_OFFSET * 4)); + cr_assert(gpu2rtds->startOnce(SAMPLE_COUNT)); + + rtds2gpu->setAutoRestart(true); + rtds2gpu->start(); + + logger->info("GPU RTT RTDS"); + + std::string dummy; + + gpu_rtds_rtt_start(dataIn, doorbellIn, frameRegister, controlRegister); + + // while (1) { + // cr_assert(rtds2gpu->startOnce(gpuRam.getMemoryBlock(), SAMPLE_COUNT, DATA_OFFSET * 4, DOORBELL_OFFSET * 4)); + // } + + // for (int i = 0; i < 10000; i++) { + // while (not doorbellInCpu->is_valid); + // logger->debug("received data"); + // } + + // logger->info("Press enter to cancel"); + // std::cin >> dummy; + + while (1) { + sleep(1); + // logger->debug("Current sequence number: {}", doorbellInCpu->seq_nr); + logger->debug("Still running"); + } + + gpu_rtds_rtt_stop(); + + logger->info(CLR_GRN("Passed")); + } +} diff --git a/fpga/tests/unit/rtds_rtt.cpp b/fpga/tests/unit/rtds_rtt.cpp new file mode 100644 index 000000000..273b46404 --- /dev/null +++ b/fpga/tests/unit/rtds_rtt.cpp @@ -0,0 +1,82 @@ +/* RTDS AXI-Stream RTT unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include +#include +#include + +extern struct fpga_card *card; + +// cppcheck-suppress unknownMacro +Test(fpga, rtds_rtt, .description = "RTDS: tight rtt") { + int ret; + struct fpga_ip *ip, *rtds; + struct dma_mem buf; + size_t recvlen; + + std::list rtdsIps; + std::list dmaIps; + + // Get IP cores + for (auto &ip : state.cards.front()->ips) { + if (*ip == + villas::fpga::Vlnv("acs.eonerc.rwth-aachen.de:user:rtds_axis:")) { + auto rtds = reinterpret_cast(ip.get()); + rtdsIps.push_back(rtds); + } + + if (*ip == villas::fpga::Vlnv("xilinx.com:ip:axi_dma:")) { + auto dma = reinterpret_cast(ip.get()); + dmaIps.push_back(dma); + } + } + + for (auto rtds : rtdsIps) { + for (auto dma : dmaIps) { + + rtds->connect + } + } + + ret = switch_connect(card->sw, rtds, ip); + cr_assert_eq(ret, 0, "Failed to configure switch"); + + ret = switch_connect(card->sw, ip, rtds); + cr_assert_eq(ret, 0, "Failed to configure switch"); + + ret = dma_alloc(ip, &buf, 0x100, 0); + cr_assert_eq(ret, 0, "Failed to allocate DMA memory"); + + while (1) { + + ret = dma_read(ip, buf.base_phys, buf.len); + cr_assert_eq(ret, 0, "Failed to start DMA read: %d", ret); + + ret = dma_read_complete(ip, NULL, &recvlen); + cr_assert_eq(ret, 0, "Failed to complete DMA read: %d", ret); + + ret = dma_write(ip, buf.base_phys, recvlen); + cr_assert_eq(ret, 0, "Failed to start DMA write: %d", ret); + + ret = dma_write_complete(ip, NULL, NULL); + cr_assert_eq(ret, 0, "Failed to complete DMA write: %d", ret); + } + + ret = switch_disconnect(card->sw, rtds, ip); + cr_assert_eq(ret, 0, "Failed to configure switch"); + + ret = switch_disconnect(card->sw, ip, rtds); + cr_assert_eq(ret, 0, "Failed to configure switch"); + + ret = dma_free(ip, &buf); + cr_assert_eq(ret, 0, "Failed to release DMA memory"); +} diff --git a/fpga/tests/unit/timer.cpp b/fpga/tests/unit/timer.cpp new file mode 100644 index 000000000..37e3e87cc --- /dev/null +++ b/fpga/tests/unit/timer.cpp @@ -0,0 +1,59 @@ +/* Timer/Counter unit test. + * + * Author: Steffen Vogel + * SPDX-FileCopyrightText: 2017 Steffen Vogel + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include "global.hpp" +#include + +// cppcheck-suppress unknownMacro +Test(fpga, timer, .description = "Timer Counter") { + auto logger = villas::Log::get("unit-test:timer"); + + size_t count = 0; + for (auto &ip : state.cards.front()->ips) { + // Skip non-timer IPs + if (*ip != villas::fpga::Vlnv("xilinx.com:ip:axi_timer:")) + continue; + + logger->info("Testing {}", *ip); + + auto timer = dynamic_cast(*ip); + + logger->info("Test simple waiting"); + timer.start(timer.getFrequency() / 10); + cr_assert(timer.wait(), "Waiting failed"); + + logger->info(CLR_GRN("Passed")); + + logger->info("Measure waiting time (1s)"); + + timer.start(timer.getFrequency()); + const auto start = std::chrono::high_resolution_clock::now(); + + timer.wait(); + const auto stop = std::chrono::high_resolution_clock::now(); + + const int oneSecondInUs = 1000000; + const auto duration = stop - start; + const auto durationUs = + std::chrono::duration_cast(duration).count(); + + cr_assert(std::abs(durationUs - oneSecondInUs) < 0.01 * oneSecondInUs, + "Timer deviation > 1%%"); + + logger->info(CLR_GRN("Passed:") " Time passed: {} us", durationUs); + + count++; + } + + cr_assert(count > 0, "No timer found"); +} diff --git a/fpga/thirdparty/CLI11/CLI11.hpp b/fpga/thirdparty/CLI11/CLI11.hpp new file mode 100644 index 000000000..382620f73 --- /dev/null +++ b/fpga/thirdparty/CLI11/CLI11.hpp @@ -0,0 +1,10966 @@ +// CLI11: Version 2.4.1 +// Originally designed by Henry Schreiner +// https://github.com/CLIUtils/CLI11 +// +// This is a standalone header file generated by MakeSingleHeader.py in CLI11/scripts +// from: v2.4.1 +// +// SPDX-FileCopyrightText: 2017-2024 University of Cincinnati, developed by Henry, Schreiner under NSF AWARD 1414736. All rights reserved. +// SPDX-License-Identifier: BSD-3-Clause +// +// Redistribution and use in source and binary forms of CLI11, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors +// may be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +// Standard combined includes: +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define CLI11_VERSION_MAJOR 2 +#define CLI11_VERSION_MINOR 4 +#define CLI11_VERSION_PATCH 1 +#define CLI11_VERSION "2.4.1" + + + + +// The following version macro is very similar to the one in pybind11 +#if !(defined(_MSC_VER) && __cplusplus == 199711L) && !defined(__INTEL_COMPILER) +#if __cplusplus >= 201402L +#define CLI11_CPP14 +#if __cplusplus >= 201703L +#define CLI11_CPP17 +#if __cplusplus > 201703L +#define CLI11_CPP20 +#endif +#endif +#endif +#elif defined(_MSC_VER) && __cplusplus == 199711L +// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) +// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer +#if _MSVC_LANG >= 201402L +#define CLI11_CPP14 +#if _MSVC_LANG > 201402L && _MSC_VER >= 1910 +#define CLI11_CPP17 +#if _MSVC_LANG > 201703L && _MSC_VER >= 1910 +#define CLI11_CPP20 +#endif +#endif +#endif +#endif + +#if defined(CLI11_CPP14) +#define CLI11_DEPRECATED(reason) [[deprecated(reason)]] +#elif defined(_MSC_VER) +#define CLI11_DEPRECATED(reason) __declspec(deprecated(reason)) +#else +#define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason))) +#endif + +// GCC < 10 doesn't ignore this in unevaluated contexts +#if !defined(CLI11_CPP17) || \ + (defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 10 && __GNUC__ > 4) +#define CLI11_NODISCARD +#else +#define CLI11_NODISCARD [[nodiscard]] +#endif + +/** detection of rtti */ +#ifndef CLI11_USE_STATIC_RTTI +#if(defined(_HAS_STATIC_RTTI) && _HAS_STATIC_RTTI) +#define CLI11_USE_STATIC_RTTI 1 +#elif defined(__cpp_rtti) +#if(defined(_CPPRTTI) && _CPPRTTI == 0) +#define CLI11_USE_STATIC_RTTI 1 +#else +#define CLI11_USE_STATIC_RTTI 0 +#endif +#elif(defined(__GCC_RTTI) && __GXX_RTTI) +#define CLI11_USE_STATIC_RTTI 0 +#else +#define CLI11_USE_STATIC_RTTI 1 +#endif +#endif + +/** availability */ +#if defined CLI11_CPP17 && defined __has_include && !defined CLI11_HAS_FILESYSTEM +#if __has_include() +// Filesystem cannot be used if targeting macOS < 10.15 +#if defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 +#define CLI11_HAS_FILESYSTEM 0 +#elif defined(__wasi__) +// As of wasi-sdk-14, filesystem is not implemented +#define CLI11_HAS_FILESYSTEM 0 +#else +#include +#if defined __cpp_lib_filesystem && __cpp_lib_filesystem >= 201703 +#if defined _GLIBCXX_RELEASE && _GLIBCXX_RELEASE >= 9 +#define CLI11_HAS_FILESYSTEM 1 +#elif defined(__GLIBCXX__) +// if we are using gcc and Version <9 default to no filesystem +#define CLI11_HAS_FILESYSTEM 0 +#else +#define CLI11_HAS_FILESYSTEM 1 +#endif +#else +#define CLI11_HAS_FILESYSTEM 0 +#endif +#endif +#endif +#endif + +/** availability */ +#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 5 +#define CLI11_HAS_CODECVT 0 +#else +#define CLI11_HAS_CODECVT 1 +#include +#endif + +/** disable deprecations */ +#if defined(__GNUC__) // GCC or clang +#define CLI11_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +#define CLI11_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") + +#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + +#elif defined(_MSC_VER) +#define CLI11_DIAGNOSTIC_PUSH __pragma(warning(push)) +#define CLI11_DIAGNOSTIC_POP __pragma(warning(pop)) + +#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED __pragma(warning(disable : 4996)) + +#else +#define CLI11_DIAGNOSTIC_PUSH +#define CLI11_DIAGNOSTIC_POP + +#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED + +#endif + +/** Inline macro **/ +#ifdef CLI11_COMPILE +#define CLI11_INLINE +#else +#define CLI11_INLINE inline +#endif + + + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +#include // NOLINT(build/include) +#else +#include +#include +#endif + + + + +#ifdef CLI11_CPP17 +#include +#endif // CLI11_CPP17 + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +#include +#include // NOLINT(build/include) +#endif // CLI11_HAS_FILESYSTEM + + + +#if defined(_WIN32) +#if !(defined(_AMD64_) || defined(_X86_) || defined(_ARM_)) +#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || \ + defined(_M_AMD64) +#define _AMD64_ +#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(__i386__) || defined(_M_IX86) +#define _X86_ +#elif defined(__arm__) || defined(_M_ARM) || defined(_M_ARMT) +#define _ARM_ +#elif defined(__aarch64__) || defined(_M_ARM64) +#define _ARM64_ +#elif defined(_M_ARM64EC) +#define _ARM64EC_ +#endif +#endif + +// first +#ifndef NOMINMAX +// if NOMINMAX is already defined we don't want to mess with that either way +#define NOMINMAX +#include +#undef NOMINMAX +#else +#include +#endif + +// second +#include +// third +#include +#include +#endif + + +namespace CLI { + + +/// Convert a wide string to a narrow string. +CLI11_INLINE std::string narrow(const std::wstring &str); +CLI11_INLINE std::string narrow(const wchar_t *str); +CLI11_INLINE std::string narrow(const wchar_t *str, std::size_t size); + +/// Convert a narrow string to a wide string. +CLI11_INLINE std::wstring widen(const std::string &str); +CLI11_INLINE std::wstring widen(const char *str); +CLI11_INLINE std::wstring widen(const char *str, std::size_t size); + +#ifdef CLI11_CPP17 +CLI11_INLINE std::string narrow(std::wstring_view str); +CLI11_INLINE std::wstring widen(std::string_view str); +#endif // CLI11_CPP17 + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +/// Convert a char-string to a native path correctly. +CLI11_INLINE std::filesystem::path to_path(std::string_view str); +#endif // CLI11_HAS_FILESYSTEM + + + + +namespace detail { + +#if !CLI11_HAS_CODECVT +/// Attempt to set one of the acceptable unicode locales for conversion +CLI11_INLINE void set_unicode_locale() { + static const std::array unicode_locales{{"C.UTF-8", "en_US.UTF-8", ".UTF-8"}}; + + for(const auto &locale_name : unicode_locales) { + if(std::setlocale(LC_ALL, locale_name) != nullptr) { + return; + } + } + throw std::runtime_error("CLI::narrow: could not set locale to C.UTF-8"); +} + +template struct scope_guard_t { + F closure; + + explicit scope_guard_t(F closure_) : closure(closure_) {} + ~scope_guard_t() { closure(); } +}; + +template CLI11_NODISCARD CLI11_INLINE scope_guard_t scope_guard(F &&closure) { + return scope_guard_t{std::forward(closure)}; +} + +#endif // !CLI11_HAS_CODECVT + +CLI11_DIAGNOSTIC_PUSH +CLI11_DIAGNOSTIC_IGNORE_DEPRECATED + +CLI11_INLINE std::string narrow_impl(const wchar_t *str, std::size_t str_size) { +#if CLI11_HAS_CODECVT +#ifdef _WIN32 + return std::wstring_convert>().to_bytes(str, str + str_size); + +#else + return std::wstring_convert>().to_bytes(str, str + str_size); + +#endif // _WIN32 +#else // CLI11_HAS_CODECVT + (void)str_size; + std::mbstate_t state = std::mbstate_t(); + const wchar_t *it = str; + + std::string old_locale = std::setlocale(LC_ALL, nullptr); + auto sg = scope_guard([&] { std::setlocale(LC_ALL, old_locale.c_str()); }); + set_unicode_locale(); + + std::size_t new_size = std::wcsrtombs(nullptr, &it, 0, &state); + if(new_size == static_cast(-1)) { + throw std::runtime_error("CLI::narrow: conversion error in std::wcsrtombs at offset " + + std::to_string(it - str)); + } + std::string result(new_size, '\0'); + std::wcsrtombs(const_cast(result.data()), &str, new_size, &state); + + return result; + +#endif // CLI11_HAS_CODECVT +} + +CLI11_INLINE std::wstring widen_impl(const char *str, std::size_t str_size) { +#if CLI11_HAS_CODECVT +#ifdef _WIN32 + return std::wstring_convert>().from_bytes(str, str + str_size); + +#else + return std::wstring_convert>().from_bytes(str, str + str_size); + +#endif // _WIN32 +#else // CLI11_HAS_CODECVT + (void)str_size; + std::mbstate_t state = std::mbstate_t(); + const char *it = str; + + std::string old_locale = std::setlocale(LC_ALL, nullptr); + auto sg = scope_guard([&] { std::setlocale(LC_ALL, old_locale.c_str()); }); + set_unicode_locale(); + + std::size_t new_size = std::mbsrtowcs(nullptr, &it, 0, &state); + if(new_size == static_cast(-1)) { + throw std::runtime_error("CLI::widen: conversion error in std::mbsrtowcs at offset " + + std::to_string(it - str)); + } + std::wstring result(new_size, L'\0'); + std::mbsrtowcs(const_cast(result.data()), &str, new_size, &state); + + return result; + +#endif // CLI11_HAS_CODECVT +} + +CLI11_DIAGNOSTIC_POP + +} // namespace detail + +CLI11_INLINE std::string narrow(const wchar_t *str, std::size_t str_size) { return detail::narrow_impl(str, str_size); } +CLI11_INLINE std::string narrow(const std::wstring &str) { return detail::narrow_impl(str.data(), str.size()); } +// Flawfinder: ignore +CLI11_INLINE std::string narrow(const wchar_t *str) { return detail::narrow_impl(str, std::wcslen(str)); } + +CLI11_INLINE std::wstring widen(const char *str, std::size_t str_size) { return detail::widen_impl(str, str_size); } +CLI11_INLINE std::wstring widen(const std::string &str) { return detail::widen_impl(str.data(), str.size()); } +// Flawfinder: ignore +CLI11_INLINE std::wstring widen(const char *str) { return detail::widen_impl(str, std::strlen(str)); } + +#ifdef CLI11_CPP17 +CLI11_INLINE std::string narrow(std::wstring_view str) { return detail::narrow_impl(str.data(), str.size()); } +CLI11_INLINE std::wstring widen(std::string_view str) { return detail::widen_impl(str.data(), str.size()); } +#endif // CLI11_CPP17 + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +CLI11_INLINE std::filesystem::path to_path(std::string_view str) { + return std::filesystem::path{ +#ifdef _WIN32 + widen(str) +#else + str +#endif // _WIN32 + }; +} +#endif // CLI11_HAS_FILESYSTEM + + + + +namespace detail { +#ifdef _WIN32 +/// Decode and return UTF-8 argv from GetCommandLineW. +CLI11_INLINE std::vector compute_win32_argv(); +#endif +} // namespace detail + + + +namespace detail { + +#ifdef _WIN32 +CLI11_INLINE std::vector compute_win32_argv() { + std::vector result; + int argc = 0; + + auto deleter = [](wchar_t **ptr) { LocalFree(ptr); }; + // NOLINTBEGIN(*-avoid-c-arrays) + auto wargv = std::unique_ptr(CommandLineToArgvW(GetCommandLineW(), &argc), deleter); + // NOLINTEND(*-avoid-c-arrays) + + if(wargv == nullptr) { + throw std::runtime_error("CommandLineToArgvW failed with code " + std::to_string(GetLastError())); + } + + result.reserve(static_cast(argc)); + for(size_t i = 0; i < static_cast(argc); ++i) { + result.push_back(narrow(wargv[i])); + } + + return result; +} +#endif + +} // namespace detail + + + + +/// Include the items in this namespace to get free conversion of enums to/from streams. +/// (This is available inside CLI as well, so CLI11 will use this without a using statement). +namespace enums { + +/// output streaming for enumerations +template ::value>::type> +std::ostream &operator<<(std::ostream &in, const T &item) { + // make sure this is out of the detail namespace otherwise it won't be found when needed + return in << static_cast::type>(item); +} + +} // namespace enums + +/// Export to CLI namespace +using enums::operator<<; + +namespace detail { +/// a constant defining an expected max vector size defined to be a big number that could be multiplied by 4 and not +/// produce overflow for some expected uses +constexpr int expected_max_vector_size{1 << 29}; +// Based on http://stackoverflow.com/questions/236129/split-a-string-in-c +/// Split a string by a delim +CLI11_INLINE std::vector split(const std::string &s, char delim); + +/// Simple function to join a string +template std::string join(const T &v, std::string delim = ",") { + std::ostringstream s; + auto beg = std::begin(v); + auto end = std::end(v); + if(beg != end) + s << *beg++; + while(beg != end) { + s << delim << *beg++; + } + return s.str(); +} + +/// Simple function to join a string from processed elements +template ::value>::type> +std::string join(const T &v, Callable func, std::string delim = ",") { + std::ostringstream s; + auto beg = std::begin(v); + auto end = std::end(v); + auto loc = s.tellp(); + while(beg != end) { + auto nloc = s.tellp(); + if(nloc > loc) { + s << delim; + loc = nloc; + } + s << func(*beg++); + } + return s.str(); +} + +/// Join a string in reverse order +template std::string rjoin(const T &v, std::string delim = ",") { + std::ostringstream s; + for(std::size_t start = 0; start < v.size(); start++) { + if(start > 0) + s << delim; + s << v[v.size() - start - 1]; + } + return s.str(); +} + +// Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string + +/// Trim whitespace from left of string +CLI11_INLINE std::string <rim(std::string &str); + +/// Trim anything from left of string +CLI11_INLINE std::string <rim(std::string &str, const std::string &filter); + +/// Trim whitespace from right of string +CLI11_INLINE std::string &rtrim(std::string &str); + +/// Trim anything from right of string +CLI11_INLINE std::string &rtrim(std::string &str, const std::string &filter); + +/// Trim whitespace from string +inline std::string &trim(std::string &str) { return ltrim(rtrim(str)); } + +/// Trim anything from string +inline std::string &trim(std::string &str, const std::string filter) { return ltrim(rtrim(str, filter), filter); } + +/// Make a copy of the string and then trim it +inline std::string trim_copy(const std::string &str) { + std::string s = str; + return trim(s); +} + +/// remove quotes at the front and back of a string either '"' or '\'' +CLI11_INLINE std::string &remove_quotes(std::string &str); + +/// remove quotes from all elements of a string vector and process escaped components +CLI11_INLINE void remove_quotes(std::vector &args); + +/// Add a leader to the beginning of all new lines (nothing is added +/// at the start of the first line). `"; "` would be for ini files +/// +/// Can't use Regex, or this would be a subs. +CLI11_INLINE std::string fix_newlines(const std::string &leader, std::string input); + +/// Make a copy of the string and then trim it, any filter string can be used (any char in string is filtered) +inline std::string trim_copy(const std::string &str, const std::string &filter) { + std::string s = str; + return trim(s, filter); +} +/// Print a two part "help" string +CLI11_INLINE std::ostream & +format_help(std::ostream &out, std::string name, const std::string &description, std::size_t wid); + +/// Print subcommand aliases +CLI11_INLINE std::ostream &format_aliases(std::ostream &out, const std::vector &aliases, std::size_t wid); + +/// Verify the first character of an option +/// - is a trigger character, ! has special meaning and new lines would just be annoying to deal with +template bool valid_first_char(T c) { + return ((c != '-') && (static_cast(c) > 33)); // space and '!' not allowed +} + +/// Verify following characters of an option +template bool valid_later_char(T c) { + // = and : are value separators, { has special meaning for option defaults, + // and control codes other than tab would just be annoying to deal with in many places allowing space here has too + // much potential for inadvertent entry errors and bugs + return ((c != '=') && (c != ':') && (c != '{') && ((static_cast(c) > 32) || c == '\t')); +} + +/// Verify an option/subcommand name +CLI11_INLINE bool valid_name_string(const std::string &str); + +/// Verify an app name +inline bool valid_alias_name_string(const std::string &str) { + static const std::string badChars(std::string("\n") + '\0'); + return (str.find_first_of(badChars) == std::string::npos); +} + +/// check if a string is a container segment separator (empty or "%%") +inline bool is_separator(const std::string &str) { + static const std::string sep("%%"); + return (str.empty() || str == sep); +} + +/// Verify that str consists of letters only +inline bool isalpha(const std::string &str) { + return std::all_of(str.begin(), str.end(), [](char c) { return std::isalpha(c, std::locale()); }); +} + +/// Return a lower case version of a string +inline std::string to_lower(std::string str) { + std::transform(std::begin(str), std::end(str), std::begin(str), [](const std::string::value_type &x) { + return std::tolower(x, std::locale()); + }); + return str; +} + +/// remove underscores from a string +inline std::string remove_underscore(std::string str) { + str.erase(std::remove(std::begin(str), std::end(str), '_'), std::end(str)); + return str; +} + +/// Find and replace a substring with another substring +CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to); + +/// check if the flag definitions has possible false flags +inline bool has_default_flag_values(const std::string &flags) { + return (flags.find_first_of("{!") != std::string::npos); +} + +CLI11_INLINE void remove_default_flag_values(std::string &flags); + +/// Check if a string is a member of a list of strings and optionally ignore case or ignore underscores +CLI11_INLINE std::ptrdiff_t find_member(std::string name, + const std::vector names, + bool ignore_case = false, + bool ignore_underscore = false); + +/// Find a trigger string and call a modify callable function that takes the current string and starting position of the +/// trigger and returns the position in the string to search for the next trigger string +template inline std::string find_and_modify(std::string str, std::string trigger, Callable modify) { + std::size_t start_pos = 0; + while((start_pos = str.find(trigger, start_pos)) != std::string::npos) { + start_pos = modify(str, start_pos); + } + return str; +} + +/// close a sequence of characters indicated by a closure character. Brackets allows sub sequences +/// recognized bracket sequences include "'`[(<{ other closure characters are assumed to be literal strings +CLI11_INLINE std::size_t close_sequence(const std::string &str, std::size_t start, char closure_char); + +/// Split a string '"one two" "three"' into 'one two', 'three' +/// Quote characters can be ` ' or " or bracket characters [{(< with matching to the matching bracket +CLI11_INLINE std::vector split_up(std::string str, char delimiter = '\0'); + +/// get the value of an environmental variable or empty string if empty +CLI11_INLINE std::string get_environment_value(const std::string &env_name); + +/// This function detects an equal or colon followed by an escaped quote after an argument +/// then modifies the string to replace the equality with a space. This is needed +/// to allow the split up function to work properly and is intended to be used with the find_and_modify function +/// the return value is the offset+1 which is required by the find_and_modify function. +CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset); + +/// @brief detect if a string has escapable characters +/// @param str the string to do the detection on +/// @return true if the string has escapable characters +CLI11_INLINE bool has_escapable_character(const std::string &str); + +/// @brief escape all escapable characters +/// @param str the string to escape +/// @return a string with the escapble characters escaped with '\' +CLI11_INLINE std::string add_escaped_characters(const std::string &str); + +/// @brief replace the escaped characters with their equivalent +CLI11_INLINE std::string remove_escaped_characters(const std::string &str); + +/// generate a string with all non printable characters escaped to hex codes +CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escape); + +CLI11_INLINE bool is_binary_escaped_string(const std::string &escaped_string); + +/// extract an escaped binary_string +CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string); + +/// process a quoted string, remove the quotes and if appropriate handle escaped characters +CLI11_INLINE bool process_quoted_string(std::string &str, char string_char = '\"', char literal_char = '\''); + +} // namespace detail + + + + +namespace detail { +CLI11_INLINE std::vector split(const std::string &s, char delim) { + std::vector elems; + // Check to see if empty string, give consistent result + if(s.empty()) { + elems.emplace_back(); + } else { + std::stringstream ss; + ss.str(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(item); + } + } + return elems; +} + +CLI11_INLINE std::string <rim(std::string &str) { + auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch, std::locale()); }); + str.erase(str.begin(), it); + return str; +} + +CLI11_INLINE std::string <rim(std::string &str, const std::string &filter) { + auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(str.begin(), it); + return str; +} + +CLI11_INLINE std::string &rtrim(std::string &str) { + auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch, std::locale()); }); + str.erase(it.base(), str.end()); + return str; +} + +CLI11_INLINE std::string &rtrim(std::string &str, const std::string &filter) { + auto it = + std::find_if(str.rbegin(), str.rend(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(it.base(), str.end()); + return str; +} + +CLI11_INLINE std::string &remove_quotes(std::string &str) { + if(str.length() > 1 && (str.front() == '"' || str.front() == '\'' || str.front() == '`')) { + if(str.front() == str.back()) { + str.pop_back(); + str.erase(str.begin(), str.begin() + 1); + } + } + return str; +} + +CLI11_INLINE std::string &remove_outer(std::string &str, char key) { + if(str.length() > 1 && (str.front() == key)) { + if(str.front() == str.back()) { + str.pop_back(); + str.erase(str.begin(), str.begin() + 1); + } + } + return str; +} + +CLI11_INLINE std::string fix_newlines(const std::string &leader, std::string input) { + std::string::size_type n = 0; + while(n != std::string::npos && n < input.size()) { + n = input.find('\n', n); + if(n != std::string::npos) { + input = input.substr(0, n + 1) + leader + input.substr(n + 1); + n += leader.size(); + } + } + return input; +} + +CLI11_INLINE std::ostream & +format_help(std::ostream &out, std::string name, const std::string &description, std::size_t wid) { + name = " " + name; + out << std::setw(static_cast(wid)) << std::left << name; + if(!description.empty()) { + if(name.length() >= wid) + out << "\n" << std::setw(static_cast(wid)) << ""; + for(const char c : description) { + out.put(c); + if(c == '\n') { + out << std::setw(static_cast(wid)) << ""; + } + } + } + out << "\n"; + return out; +} + +CLI11_INLINE std::ostream &format_aliases(std::ostream &out, const std::vector &aliases, std::size_t wid) { + if(!aliases.empty()) { + out << std::setw(static_cast(wid)) << " aliases: "; + bool front = true; + for(const auto &alias : aliases) { + if(!front) { + out << ", "; + } else { + front = false; + } + out << detail::fix_newlines(" ", alias); + } + out << "\n"; + } + return out; +} + +CLI11_INLINE bool valid_name_string(const std::string &str) { + if(str.empty() || !valid_first_char(str[0])) { + return false; + } + auto e = str.end(); + for(auto c = str.begin() + 1; c != e; ++c) + if(!valid_later_char(*c)) + return false; + return true; +} + +CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std::string to) { + + std::size_t start_pos = 0; + + while((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); + } + + return str; +} + +CLI11_INLINE void remove_default_flag_values(std::string &flags) { + auto loc = flags.find_first_of('{', 2); + while(loc != std::string::npos) { + auto finish = flags.find_first_of("},", loc + 1); + if((finish != std::string::npos) && (flags[finish] == '}')) { + flags.erase(flags.begin() + static_cast(loc), + flags.begin() + static_cast(finish) + 1); + } + loc = flags.find_first_of('{', loc + 1); + } + flags.erase(std::remove(flags.begin(), flags.end(), '!'), flags.end()); +} + +CLI11_INLINE std::ptrdiff_t +find_member(std::string name, const std::vector names, bool ignore_case, bool ignore_underscore) { + auto it = std::end(names); + if(ignore_case) { + if(ignore_underscore) { + name = detail::to_lower(detail::remove_underscore(name)); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::to_lower(detail::remove_underscore(local_name)) == name; + }); + } else { + name = detail::to_lower(name); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::to_lower(local_name) == name; + }); + } + + } else if(ignore_underscore) { + name = detail::remove_underscore(name); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::remove_underscore(local_name) == name; + }); + } else { + it = std::find(std::begin(names), std::end(names), name); + } + + return (it != std::end(names)) ? (it - std::begin(names)) : (-1); +} + +static const std::string escapedChars("\b\t\n\f\r\"\\"); +static const std::string escapedCharsCode("btnfr\"\\"); +static const std::string bracketChars{"\"'`[(<{"}; +static const std::string matchBracketChars("\"'`])>}"); + +CLI11_INLINE bool has_escapable_character(const std::string &str) { + return (str.find_first_of(escapedChars) != std::string::npos); +} + +CLI11_INLINE std::string add_escaped_characters(const std::string &str) { + std::string out; + out.reserve(str.size() + 4); + for(char s : str) { + auto sloc = escapedChars.find_first_of(s); + if(sloc != std::string::npos) { + out.push_back('\\'); + out.push_back(escapedCharsCode[sloc]); + } else { + out.push_back(s); + } + } + return out; +} + +CLI11_INLINE std::uint32_t hexConvert(char hc) { + int hcode{0}; + if(hc >= '0' && hc <= '9') { + hcode = (hc - '0'); + } else if(hc >= 'A' && hc <= 'F') { + hcode = (hc - 'A' + 10); + } else if(hc >= 'a' && hc <= 'f') { + hcode = (hc - 'a' + 10); + } else { + hcode = -1; + } + return static_cast(hcode); +} + +CLI11_INLINE char make_char(std::uint32_t code) { return static_cast(static_cast(code)); } + +CLI11_INLINE void append_codepoint(std::string &str, std::uint32_t code) { + if(code < 0x80) { // ascii code equivalent + str.push_back(static_cast(code)); + } else if(code < 0x800) { // \u0080 to \u07FF + // 110yyyyx 10xxxxxx; 0x3f == 0b0011'1111 + str.push_back(make_char(0xC0 | code >> 6)); + str.push_back(make_char(0x80 | (code & 0x3F))); + } else if(code < 0x10000) { // U+0800...U+FFFF + if(0xD800 <= code && code <= 0xDFFF) { + throw std::invalid_argument("[0xD800, 0xDFFF] are not valid UTF-8."); + } + // 1110yyyy 10yxxxxx 10xxxxxx + str.push_back(make_char(0xE0 | code >> 12)); + str.push_back(make_char(0x80 | (code >> 6 & 0x3F))); + str.push_back(make_char(0x80 | (code & 0x3F))); + } else if(code < 0x110000) { // U+010000 ... U+10FFFF + // 11110yyy 10yyxxxx 10xxxxxx 10xxxxxx + str.push_back(make_char(0xF0 | code >> 18)); + str.push_back(make_char(0x80 | (code >> 12 & 0x3F))); + str.push_back(make_char(0x80 | (code >> 6 & 0x3F))); + str.push_back(make_char(0x80 | (code & 0x3F))); + } +} + +CLI11_INLINE std::string remove_escaped_characters(const std::string &str) { + + std::string out; + out.reserve(str.size()); + for(auto loc = str.begin(); loc < str.end(); ++loc) { + if(*loc == '\\') { + if(str.end() - loc < 2) { + throw std::invalid_argument("invalid escape sequence " + str); + } + auto ecloc = escapedCharsCode.find_first_of(*(loc + 1)); + if(ecloc != std::string::npos) { + out.push_back(escapedChars[ecloc]); + ++loc; + } else if(*(loc + 1) == 'u') { + // must have 4 hex characters + if(str.end() - loc < 6) { + throw std::invalid_argument("unicode sequence must have 4 hex codes " + str); + } + std::uint32_t code{0}; + std::uint32_t mplier{16 * 16 * 16}; + for(int ii = 2; ii < 6; ++ii) { + std::uint32_t res = hexConvert(*(loc + ii)); + if(res > 0x0F) { + throw std::invalid_argument("unicode sequence must have 4 hex codes " + str); + } + code += res * mplier; + mplier = mplier / 16; + } + append_codepoint(out, code); + loc += 5; + } else if(*(loc + 1) == 'U') { + // must have 8 hex characters + if(str.end() - loc < 10) { + throw std::invalid_argument("unicode sequence must have 8 hex codes " + str); + } + std::uint32_t code{0}; + std::uint32_t mplier{16 * 16 * 16 * 16 * 16 * 16 * 16}; + for(int ii = 2; ii < 10; ++ii) { + std::uint32_t res = hexConvert(*(loc + ii)); + if(res > 0x0F) { + throw std::invalid_argument("unicode sequence must have 8 hex codes " + str); + } + code += res * mplier; + mplier = mplier / 16; + } + append_codepoint(out, code); + loc += 9; + } else if(*(loc + 1) == '0') { + out.push_back('\0'); + ++loc; + } else { + throw std::invalid_argument(std::string("unrecognized escape sequence \\") + *(loc + 1) + " in " + str); + } + } else { + out.push_back(*loc); + } + } + return out; +} + +CLI11_INLINE std::size_t close_string_quote(const std::string &str, std::size_t start, char closure_char) { + std::size_t loc{0}; + for(loc = start + 1; loc < str.size(); ++loc) { + if(str[loc] == closure_char) { + break; + } + if(str[loc] == '\\') { + // skip the next character for escaped sequences + ++loc; + } + } + return loc; +} + +CLI11_INLINE std::size_t close_literal_quote(const std::string &str, std::size_t start, char closure_char) { + auto loc = str.find_first_of(closure_char, start + 1); + return (loc != std::string::npos ? loc : str.size()); +} + +CLI11_INLINE std::size_t close_sequence(const std::string &str, std::size_t start, char closure_char) { + + auto bracket_loc = matchBracketChars.find(closure_char); + switch(bracket_loc) { + case 0: + return close_string_quote(str, start, closure_char); + case 1: + case 2: + case std::string::npos: + return close_literal_quote(str, start, closure_char); + default: + break; + } + + std::string closures(1, closure_char); + auto loc = start + 1; + + while(loc < str.size()) { + if(str[loc] == closures.back()) { + closures.pop_back(); + if(closures.empty()) { + return loc; + } + } + bracket_loc = bracketChars.find(str[loc]); + if(bracket_loc != std::string::npos) { + switch(bracket_loc) { + case 0: + loc = close_string_quote(str, loc, str[loc]); + break; + case 1: + case 2: + loc = close_literal_quote(str, loc, str[loc]); + break; + default: + closures.push_back(matchBracketChars[bracket_loc]); + break; + } + } + ++loc; + } + if(loc > str.size()) { + loc = str.size(); + } + return loc; +} + +CLI11_INLINE std::vector split_up(std::string str, char delimiter) { + + auto find_ws = [delimiter](char ch) { + return (delimiter == '\0') ? std::isspace(ch, std::locale()) : (ch == delimiter); + }; + trim(str); + + std::vector output; + while(!str.empty()) { + if(bracketChars.find_first_of(str[0]) != std::string::npos) { + auto bracketLoc = bracketChars.find_first_of(str[0]); + auto end = close_sequence(str, 0, matchBracketChars[bracketLoc]); + if(end >= str.size()) { + output.push_back(std::move(str)); + str.clear(); + } else { + output.push_back(str.substr(0, end + 1)); + if(end + 2 < str.size()) { + str = str.substr(end + 2); + } else { + str.clear(); + } + } + + } else { + auto it = std::find_if(std::begin(str), std::end(str), find_ws); + if(it != std::end(str)) { + std::string value = std::string(str.begin(), it); + output.push_back(value); + str = std::string(it + 1, str.end()); + } else { + output.push_back(str); + str.clear(); + } + } + trim(str); + } + return output; +} + +CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset) { + auto next = str[offset + 1]; + if((next == '\"') || (next == '\'') || (next == '`')) { + auto astart = str.find_last_of("-/ \"\'`", offset - 1); + if(astart != std::string::npos) { + if(str[astart] == ((str[offset] == '=') ? '-' : '/')) + str[offset] = ' '; // interpret this as a space so the split_up works properly + } + } + return offset + 1; +} + +CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escape) { + // s is our escaped output string + std::string escaped_string{}; + // loop through all characters + for(char c : string_to_escape) { + // check if a given character is printable + // the cast is necessary to avoid undefined behaviour + if(isprint(static_cast(c)) == 0) { + std::stringstream stream; + // if the character is not printable + // we'll convert it to a hex string using a stringstream + // note that since char is signed we have to cast it to unsigned first + stream << std::hex << static_cast(static_cast(c)); + std::string code = stream.str(); + escaped_string += std::string("\\x") + (code.size() < 2 ? "0" : "") + code; + + } else { + escaped_string.push_back(c); + } + } + if(escaped_string != string_to_escape) { + auto sqLoc = escaped_string.find('\''); + while(sqLoc != std::string::npos) { + escaped_string.replace(sqLoc, sqLoc + 1, "\\x27"); + sqLoc = escaped_string.find('\''); + } + escaped_string.insert(0, "'B\"("); + escaped_string.push_back(')'); + escaped_string.push_back('"'); + escaped_string.push_back('\''); + } + return escaped_string; +} + +CLI11_INLINE bool is_binary_escaped_string(const std::string &escaped_string) { + size_t ssize = escaped_string.size(); + if(escaped_string.compare(0, 3, "B\"(") == 0 && escaped_string.compare(ssize - 2, 2, ")\"") == 0) { + return true; + } + return (escaped_string.compare(0, 4, "'B\"(") == 0 && escaped_string.compare(ssize - 3, 3, ")\"'") == 0); +} + +CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string) { + std::size_t start{0}; + std::size_t tail{0}; + size_t ssize = escaped_string.size(); + if(escaped_string.compare(0, 3, "B\"(") == 0 && escaped_string.compare(ssize - 2, 2, ")\"") == 0) { + start = 3; + tail = 2; + } else if(escaped_string.compare(0, 4, "'B\"(") == 0 && escaped_string.compare(ssize - 3, 3, ")\"'") == 0) { + start = 4; + tail = 3; + } + + if(start == 0) { + return escaped_string; + } + std::string outstring; + + outstring.reserve(ssize - start - tail); + std::size_t loc = start; + while(loc < ssize - tail) { + // ssize-2 to skip )" at the end + if(escaped_string[loc] == '\\' && (escaped_string[loc + 1] == 'x' || escaped_string[loc + 1] == 'X')) { + auto c1 = escaped_string[loc + 2]; + auto c2 = escaped_string[loc + 3]; + + std::uint32_t res1 = hexConvert(c1); + std::uint32_t res2 = hexConvert(c2); + if(res1 <= 0x0F && res2 <= 0x0F) { + loc += 4; + outstring.push_back(static_cast(res1 * 16 + res2)); + continue; + } + } + outstring.push_back(escaped_string[loc]); + ++loc; + } + return outstring; +} + +CLI11_INLINE void remove_quotes(std::vector &args) { + for(auto &arg : args) { + if(arg.front() == '\"' && arg.back() == '\"') { + remove_quotes(arg); + // only remove escaped for string arguments not literal strings + arg = remove_escaped_characters(arg); + } else { + remove_quotes(arg); + } + } +} + +CLI11_INLINE bool process_quoted_string(std::string &str, char string_char, char literal_char) { + if(str.size() <= 1) { + return false; + } + if(detail::is_binary_escaped_string(str)) { + str = detail::extract_binary_string(str); + return true; + } + if(str.front() == string_char && str.back() == string_char) { + detail::remove_outer(str, string_char); + if(str.find_first_of('\\') != std::string::npos) { + str = detail::remove_escaped_characters(str); + } + return true; + } + if((str.front() == literal_char || str.front() == '`') && str.back() == str.front()) { + detail::remove_outer(str, str.front()); + return true; + } + return false; +} + +std::string get_environment_value(const std::string &env_name) { + char *buffer = nullptr; + std::string ename_string; + +#ifdef _MSC_VER + // Windows version + std::size_t sz = 0; + if(_dupenv_s(&buffer, &sz, env_name.c_str()) == 0 && buffer != nullptr) { + ename_string = std::string(buffer); + free(buffer); + } +#else + // This also works on Windows, but gives a warning + buffer = std::getenv(env_name.c_str()); + if(buffer != nullptr) { + ename_string = std::string(buffer); + } +#endif + return ename_string; +} + +} // namespace detail + + + +// Use one of these on all error classes. +// These are temporary and are undef'd at the end of this file. +#define CLI11_ERROR_DEF(parent, name) \ + protected: \ + name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {} \ + name(std::string ename, std::string msg, ExitCodes exit_code) \ + : parent(std::move(ename), std::move(msg), exit_code) {} \ + \ + public: \ + name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \ + name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} + +// This is added after the one above if a class is used directly and builds its own message +#define CLI11_ERROR_SIMPLE(name) \ + explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {} + +/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, +/// int values from e.get_error_code(). +enum class ExitCodes { + Success = 0, + IncorrectConstruction = 100, + BadNameString, + OptionAlreadyAdded, + FileError, + ConversionError, + ValidationError, + RequiredError, + RequiresError, + ExcludesError, + ExtrasError, + ConfigError, + InvalidError, + HorribleError, + OptionNotFound, + ArgumentMismatch, + BaseClass = 127 +}; + +// Error definitions + +/// @defgroup error_group Errors +/// @brief Errors thrown by CLI11 +/// +/// These are the errors that can be thrown. Some of them, like CLI::Success, are not really errors. +/// @{ + +/// All errors derive from this one +class Error : public std::runtime_error { + int actual_exit_code; + std::string error_name{"Error"}; + + public: + CLI11_NODISCARD int get_exit_code() const { return actual_exit_code; } + + CLI11_NODISCARD std::string get_name() const { return error_name; } + + Error(std::string name, std::string msg, int exit_code = static_cast(ExitCodes::BaseClass)) + : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {} + + Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast(exit_code)) {} +}; + +// Note: Using Error::Error constructors does not work on GCC 4.7 + +/// Construction errors (not in parsing) +class ConstructionError : public Error { + CLI11_ERROR_DEF(Error, ConstructionError) +}; + +/// Thrown when an option is set to conflicting values (non-vector and multi args, for example) +class IncorrectConstruction : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, IncorrectConstruction) + CLI11_ERROR_SIMPLE(IncorrectConstruction) + static IncorrectConstruction PositionalFlag(std::string name) { + return IncorrectConstruction(name + ": Flags cannot be positional"); + } + static IncorrectConstruction Set0Opt(std::string name) { + return IncorrectConstruction(name + ": Cannot set 0 expected, use a flag instead"); + } + static IncorrectConstruction SetFlag(std::string name) { + return IncorrectConstruction(name + ": Cannot set an expected number for flags"); + } + static IncorrectConstruction ChangeNotVector(std::string name) { + return IncorrectConstruction(name + ": You can only change the expected arguments for vectors"); + } + static IncorrectConstruction AfterMultiOpt(std::string name) { + return IncorrectConstruction( + name + ": You can't change expected arguments after you've changed the multi option policy!"); + } + static IncorrectConstruction MissingOption(std::string name) { + return IncorrectConstruction("Option " + name + " is not defined"); + } + static IncorrectConstruction MultiOptionPolicy(std::string name) { + return IncorrectConstruction(name + ": multi_option_policy only works for flags and exact value options"); + } +}; + +/// Thrown on construction of a bad name +class BadNameString : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, BadNameString) + CLI11_ERROR_SIMPLE(BadNameString) + static BadNameString OneCharName(std::string name) { return BadNameString("Invalid one char name: " + name); } + static BadNameString MissingDash(std::string name) { + return BadNameString("Long names strings require 2 dashes " + name); + } + static BadNameString BadLongName(std::string name) { return BadNameString("Bad long name: " + name); } + static BadNameString BadPositionalName(std::string name) { + return BadNameString("Invalid positional Name: " + name); + } + static BadNameString DashesOnly(std::string name) { + return BadNameString("Must have a name, not just dashes: " + name); + } + static BadNameString MultiPositionalNames(std::string name) { + return BadNameString("Only one positional name allowed, remove: " + name); + } +}; + +/// Thrown when an option already exists +class OptionAlreadyAdded : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, OptionAlreadyAdded) + explicit OptionAlreadyAdded(std::string name) + : OptionAlreadyAdded(name + " is already added", ExitCodes::OptionAlreadyAdded) {} + static OptionAlreadyAdded Requires(std::string name, std::string other) { + return {name + " requires " + other, ExitCodes::OptionAlreadyAdded}; + } + static OptionAlreadyAdded Excludes(std::string name, std::string other) { + return {name + " excludes " + other, ExitCodes::OptionAlreadyAdded}; + } +}; + +// Parsing errors + +/// Anything that can error in Parse +class ParseError : public Error { + CLI11_ERROR_DEF(Error, ParseError) +}; + +// Not really "errors" + +/// This is a successful completion on parsing, supposed to exit +class Success : public ParseError { + CLI11_ERROR_DEF(ParseError, Success) + Success() : Success("Successfully completed, should be caught and quit", ExitCodes::Success) {} +}; + +/// -h or --help on command line +class CallForHelp : public Success { + CLI11_ERROR_DEF(Success, CallForHelp) + CallForHelp() : CallForHelp("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// Usually something like --help-all on command line +class CallForAllHelp : public Success { + CLI11_ERROR_DEF(Success, CallForAllHelp) + CallForAllHelp() + : CallForAllHelp("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// -v or --version on command line +class CallForVersion : public Success { + CLI11_ERROR_DEF(Success, CallForVersion) + CallForVersion() + : CallForVersion("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// Does not output a diagnostic in CLI11_PARSE, but allows main() to return with a specific error code. +class RuntimeError : public ParseError { + CLI11_ERROR_DEF(ParseError, RuntimeError) + explicit RuntimeError(int exit_code = 1) : RuntimeError("Runtime error", exit_code) {} +}; + +/// Thrown when parsing an INI file and it is missing +class FileError : public ParseError { + CLI11_ERROR_DEF(ParseError, FileError) + CLI11_ERROR_SIMPLE(FileError) + static FileError Missing(std::string name) { return FileError(name + " was not readable (missing?)"); } +}; + +/// Thrown when conversion call back fails, such as when an int fails to coerce to a string +class ConversionError : public ParseError { + CLI11_ERROR_DEF(ParseError, ConversionError) + CLI11_ERROR_SIMPLE(ConversionError) + ConversionError(std::string member, std::string name) + : ConversionError("The value " + member + " is not an allowed value for " + name) {} + ConversionError(std::string name, std::vector results) + : ConversionError("Could not convert: " + name + " = " + detail::join(results)) {} + static ConversionError TooManyInputsFlag(std::string name) { + return ConversionError(name + ": too many inputs for a flag"); + } + static ConversionError TrueFalse(std::string name) { + return ConversionError(name + ": Should be true/false or a number"); + } +}; + +/// Thrown when validation of results fails +class ValidationError : public ParseError { + CLI11_ERROR_DEF(ParseError, ValidationError) + CLI11_ERROR_SIMPLE(ValidationError) + explicit ValidationError(std::string name, std::string msg) : ValidationError(name + ": " + msg) {} +}; + +/// Thrown when a required option is missing +class RequiredError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiredError) + explicit RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {} + static RequiredError Subcommand(std::size_t min_subcom) { + if(min_subcom == 1) { + return RequiredError("A subcommand"); + } + return {"Requires at least " + std::to_string(min_subcom) + " subcommands", ExitCodes::RequiredError}; + } + static RequiredError + Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) { + if((min_option == 1) && (max_option == 1) && (used == 0)) + return RequiredError("Exactly 1 option from [" + option_list + "]"); + if((min_option == 1) && (max_option == 1) && (used > 1)) { + return {"Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) + + " were given", + ExitCodes::RequiredError}; + } + if((min_option == 1) && (used == 0)) + return RequiredError("At least 1 option from [" + option_list + "]"); + if(used < min_option) { + return {"Requires at least " + std::to_string(min_option) + " options used and only " + + std::to_string(used) + "were given from [" + option_list + "]", + ExitCodes::RequiredError}; + } + if(max_option == 1) + return {"Requires at most 1 options be given from [" + option_list + "]", ExitCodes::RequiredError}; + + return {"Requires at most " + std::to_string(max_option) + " options be used and " + std::to_string(used) + + "were given from [" + option_list + "]", + ExitCodes::RequiredError}; + } +}; + +/// Thrown when the wrong number of arguments has been received +class ArgumentMismatch : public ParseError { + CLI11_ERROR_DEF(ParseError, ArgumentMismatch) + CLI11_ERROR_SIMPLE(ArgumentMismatch) + ArgumentMismatch(std::string name, int expected, std::size_t received) + : ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name + + ", got " + std::to_string(received)) + : ("Expected at least " + std::to_string(-expected) + " arguments to " + name + + ", got " + std::to_string(received)), + ExitCodes::ArgumentMismatch) {} + + static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received) { + return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required but received " + + std::to_string(received)); + } + static ArgumentMismatch AtMost(std::string name, int num, std::size_t received) { + return ArgumentMismatch(name + ": At Most " + std::to_string(num) + " required but received " + + std::to_string(received)); + } + static ArgumentMismatch TypedAtLeast(std::string name, int num, std::string type) { + return ArgumentMismatch(name + ": " + std::to_string(num) + " required " + type + " missing"); + } + static ArgumentMismatch FlagOverride(std::string name) { + return ArgumentMismatch(name + " was given a disallowed flag override"); + } + static ArgumentMismatch PartialType(std::string name, int num, std::string type) { + return ArgumentMismatch(name + ": " + type + " only partially specified: " + std::to_string(num) + + " required for each element"); + } +}; + +/// Thrown when a requires option is missing +class RequiresError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiresError) + RequiresError(std::string curname, std::string subname) + : RequiresError(curname + " requires " + subname, ExitCodes::RequiresError) {} +}; + +/// Thrown when an excludes option is present +class ExcludesError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExcludesError) + ExcludesError(std::string curname, std::string subname) + : ExcludesError(curname + " excludes " + subname, ExitCodes::ExcludesError) {} +}; + +/// Thrown when too many positionals or options are found +class ExtrasError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExtrasError) + explicit ExtrasError(std::vector args) + : ExtrasError((args.size() > 1 ? "The following arguments were not expected: " + : "The following argument was not expected: ") + + detail::rjoin(args, " "), + ExitCodes::ExtrasError) {} + ExtrasError(const std::string &name, std::vector args) + : ExtrasError(name, + (args.size() > 1 ? "The following arguments were not expected: " + : "The following argument was not expected: ") + + detail::rjoin(args, " "), + ExitCodes::ExtrasError) {} +}; + +/// Thrown when extra values are found in an INI file +class ConfigError : public ParseError { + CLI11_ERROR_DEF(ParseError, ConfigError) + CLI11_ERROR_SIMPLE(ConfigError) + static ConfigError Extras(std::string item) { return ConfigError("INI was not able to parse " + item); } + static ConfigError NotConfigurable(std::string item) { + return ConfigError(item + ": This option is not allowed in a configuration file"); + } +}; + +/// Thrown when validation fails before parsing +class InvalidError : public ParseError { + CLI11_ERROR_DEF(ParseError, InvalidError) + explicit InvalidError(std::string name) + : InvalidError(name + ": Too many positional arguments with unlimited expected args", ExitCodes::InvalidError) { + } +}; + +/// This is just a safety check to verify selection and parsing match - you should not ever see it +/// Strings are directly added to this error, but again, it should never be seen. +class HorribleError : public ParseError { + CLI11_ERROR_DEF(ParseError, HorribleError) + CLI11_ERROR_SIMPLE(HorribleError) +}; + +// After parsing + +/// Thrown when counting a non-existent option +class OptionNotFound : public Error { + CLI11_ERROR_DEF(Error, OptionNotFound) + explicit OptionNotFound(std::string name) : OptionNotFound(name + " not found", ExitCodes::OptionNotFound) {} +}; + +#undef CLI11_ERROR_DEF +#undef CLI11_ERROR_SIMPLE + +/// @} + + + + +// Type tools + +// Utilities for type enabling +namespace detail { +// Based generally on https://rmf.io/cxx11/almost-static-if +/// Simple empty scoped class +enum class enabler {}; + +/// An instance to use in EnableIf +constexpr enabler dummy = {}; +} // namespace detail + +/// A copy of enable_if_t from C++14, compatible with C++11. +/// +/// We could check to see if C++14 is being used, but it does not hurt to redefine this +/// (even Google does this: https://github.com/google/skia/blob/main/include/private/SkTLogic.h) +/// It is not in the std namespace anyway, so no harm done. +template using enable_if_t = typename std::enable_if::type; + +/// A copy of std::void_t from C++17 (helper for C++11 and C++14) +template struct make_void { + using type = void; +}; + +/// A copy of std::void_t from C++17 - same reasoning as enable_if_t, it does not hurt to redefine +template using void_t = typename make_void::type; + +/// A copy of std::conditional_t from C++14 - same reasoning as enable_if_t, it does not hurt to redefine +template using conditional_t = typename std::conditional::type; + +/// Check to see if something is bool (fail check by default) +template struct is_bool : std::false_type {}; + +/// Check to see if something is bool (true if actually a bool) +template <> struct is_bool : std::true_type {}; + +/// Check to see if something is a shared pointer +template struct is_shared_ptr : std::false_type {}; + +/// Check to see if something is a shared pointer (True if really a shared pointer) +template struct is_shared_ptr> : std::true_type {}; + +/// Check to see if something is a shared pointer (True if really a shared pointer) +template struct is_shared_ptr> : std::true_type {}; + +/// Check to see if something is copyable pointer +template struct is_copyable_ptr { + static bool const value = is_shared_ptr::value || std::is_pointer::value; +}; + +/// This can be specialized to override the type deduction for IsMember. +template struct IsMemberType { + using type = T; +}; + +/// The main custom type needed here is const char * should be a string. +template <> struct IsMemberType { + using type = std::string; +}; + +namespace detail { + +// These are utilities for IsMember and other transforming objects + +/// Handy helper to access the element_type generically. This is not part of is_copyable_ptr because it requires that +/// pointer_traits be valid. + +/// not a pointer +template struct element_type { + using type = T; +}; + +template struct element_type::value>::type> { + using type = typename std::pointer_traits::element_type; +}; + +/// Combination of the element type and value type - remove pointer (including smart pointers) and get the value_type of +/// the container +template struct element_value_type { + using type = typename element_type::type::value_type; +}; + +/// Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost nothing. +template struct pair_adaptor : std::false_type { + using value_type = typename T::value_type; + using first_type = typename std::remove_const::type; + using second_type = typename std::remove_const::type; + + /// Get the first value (really just the underlying value) + template static auto first(Q &&pair_value) -> decltype(std::forward(pair_value)) { + return std::forward(pair_value); + } + /// Get the second value (really just the underlying value) + template static auto second(Q &&pair_value) -> decltype(std::forward(pair_value)) { + return std::forward(pair_value); + } +}; + +/// Adaptor for map-like structure (true version, must have key_type and mapped_type). +/// This wraps a mapped container in a few utilities access it in a general way. +template +struct pair_adaptor< + T, + conditional_t, void>> + : std::true_type { + using value_type = typename T::value_type; + using first_type = typename std::remove_const::type; + using second_type = typename std::remove_const::type; + + /// Get the first value (really just the underlying value) + template static auto first(Q &&pair_value) -> decltype(std::get<0>(std::forward(pair_value))) { + return std::get<0>(std::forward(pair_value)); + } + /// Get the second value (really just the underlying value) + template static auto second(Q &&pair_value) -> decltype(std::get<1>(std::forward(pair_value))) { + return std::get<1>(std::forward(pair_value)); + } +}; + +// Warning is suppressed due to "bug" in gcc<5.0 and gcc 7.0 with c++17 enabled that generates a Wnarrowing warning +// in the unevaluated context even if the function that was using this wasn't used. The standard says narrowing in +// brace initialization shouldn't be allowed but for backwards compatibility gcc allows it in some contexts. It is a +// little fuzzy what happens in template constructs and I think that was something GCC took a little while to work out. +// But regardless some versions of gcc generate a warning when they shouldn't from the following code so that should be +// suppressed +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnarrowing" +#endif +// check for constructibility from a specific type and copy assignable used in the parse detection +template class is_direct_constructible { + template + static auto test(int, std::true_type) -> decltype( +// NVCC warns about narrowing conversions here +#ifdef __CUDACC__ +#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__ +#pragma nv_diag_suppress 2361 +#else +#pragma diag_suppress 2361 +#endif +#endif + TT{std::declval()} +#ifdef __CUDACC__ +#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__ +#pragma nv_diag_default 2361 +#else +#pragma diag_default 2361 +#endif +#endif + , + std::is_move_assignable()); + + template static auto test(int, std::false_type) -> std::false_type; + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0, typename std::is_constructible::type()))::value; +}; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +// Check for output streamability +// Based on https://stackoverflow.com/questions/22758291/how-can-i-detect-if-a-type-can-be-streamed-to-an-stdostream + +template class is_ostreamable { + template + static auto test(int) -> decltype(std::declval() << std::declval(), std::true_type()); + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Check for input streamability +template class is_istreamable { + template + static auto test(int) -> decltype(std::declval() >> std::declval(), std::true_type()); + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Check for complex +template class is_complex { + template + static auto test(int) -> decltype(std::declval().real(), std::declval().imag(), std::true_type()); + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Templated operation to get a value from a stream +template ::value, detail::enabler> = detail::dummy> +bool from_stream(const std::string &istring, T &obj) { + std::istringstream is; + is.str(istring); + is >> obj; + return !is.fail() && !is.rdbuf()->in_avail(); +} + +template ::value, detail::enabler> = detail::dummy> +bool from_stream(const std::string & /*istring*/, T & /*obj*/) { + return false; +} + +// check to see if an object is a mutable container (fail by default) +template struct is_mutable_container : std::false_type {}; + +/// type trait to test if a type is a mutable container meaning it has a value_type, it has an iterator, a clear, and +/// end methods and an insert function. And for our purposes we exclude std::string and types that can be constructed +/// from a std::string +template +struct is_mutable_container< + T, + conditional_t().end()), + decltype(std::declval().clear()), + decltype(std::declval().insert(std::declval().end())>(), + std::declval()))>, + void>> : public conditional_t::value || + std::is_constructible::value, + std::false_type, + std::true_type> {}; + +// check to see if an object is a mutable container (fail by default) +template struct is_readable_container : std::false_type {}; + +/// type trait to test if a type is a container meaning it has a value_type, it has an iterator, a clear, and an end +/// methods and an insert function. And for our purposes we exclude std::string and types that can be constructed from +/// a std::string +template +struct is_readable_container< + T, + conditional_t().end()), decltype(std::declval().begin())>, void>> + : public std::true_type {}; + +// check to see if an object is a wrapper (fail by default) +template struct is_wrapper : std::false_type {}; + +// check if an object is a wrapper (it has a value_type defined) +template +struct is_wrapper, void>> : public std::true_type {}; + +// Check for tuple like types, as in classes with a tuple_size type trait +template class is_tuple_like { + template + // static auto test(int) + // -> decltype(std::conditional<(std::tuple_size::value > 0), std::true_type, std::false_type>::type()); + static auto test(int) -> decltype(std::tuple_size::type>::value, std::true_type{}); + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Convert an object to a string (directly forward if this can become a string) +template ::value, detail::enabler> = detail::dummy> +auto to_string(T &&value) -> decltype(std::forward(value)) { + return std::forward(value); +} + +/// Construct a string from the object +template ::value && !std::is_convertible::value, + detail::enabler> = detail::dummy> +std::string to_string(const T &value) { + return std::string(value); // NOLINT(google-readability-casting) +} + +/// Convert an object to a string (streaming must be supported for that type) +template ::value && !std::is_constructible::value && + is_ostreamable::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&value) { + std::stringstream stream; + stream << value; + return stream.str(); +} + +/// If conversion is not supported, return an empty string (streaming is not supported for that type) +template ::value && !is_ostreamable::value && + !is_readable_container::type>::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&) { + return {}; +} + +/// convert a readable container to a string +template ::value && !is_ostreamable::value && + is_readable_container::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&variable) { + auto cval = variable.begin(); + auto end = variable.end(); + if(cval == end) { + return {"{}"}; + } + std::vector defaults; + while(cval != end) { + defaults.emplace_back(CLI::detail::to_string(*cval)); + ++cval; + } + return {"[" + detail::join(defaults) + "]"}; +} + +/// special template overload +template ::value, detail::enabler> = detail::dummy> +auto checked_to_string(T &&value) -> decltype(to_string(std::forward(value))) { + return to_string(std::forward(value)); +} + +/// special template overload +template ::value, detail::enabler> = detail::dummy> +std::string checked_to_string(T &&) { + return std::string{}; +} +/// get a string as a convertible value for arithmetic types +template ::value, detail::enabler> = detail::dummy> +std::string value_string(const T &value) { + return std::to_string(value); +} +/// get a string as a convertible value for enumerations +template ::value, detail::enabler> = detail::dummy> +std::string value_string(const T &value) { + return std::to_string(static_cast::type>(value)); +} +/// for other types just use the regular to_string function +template ::value && !std::is_arithmetic::value, detail::enabler> = detail::dummy> +auto value_string(const T &value) -> decltype(to_string(value)) { + return to_string(value); +} + +/// template to get the underlying value type if it exists or use a default +template struct wrapped_type { + using type = def; +}; + +/// Type size for regular object types that do not look like a tuple +template struct wrapped_type::value>::type> { + using type = typename T::value_type; +}; + +/// This will only trigger for actual void type +template struct type_count_base { + static const int value{0}; +}; + +/// Type size for regular object types that do not look like a tuple +template +struct type_count_base::value && !is_mutable_container::value && + !std::is_void::value>::type> { + static constexpr int value{1}; +}; + +/// the base tuple size +template +struct type_count_base::value && !is_mutable_container::value>::type> { + static constexpr int value{std::tuple_size::value}; +}; + +/// Type count base for containers is the type_count_base of the individual element +template struct type_count_base::value>::type> { + static constexpr int value{type_count_base::value}; +}; + +/// Set of overloads to get the type size of an object + +/// forward declare the subtype_count structure +template struct subtype_count; + +/// forward declare the subtype_count_min structure +template struct subtype_count_min; + +/// This will only trigger for actual void type +template struct type_count { + static const int value{0}; +}; + +/// Type size for regular object types that do not look like a tuple +template +struct type_count::value && !is_tuple_like::value && !is_complex::value && + !std::is_void::value>::type> { + static constexpr int value{1}; +}; + +/// Type size for complex since it sometimes looks like a wrapper +template struct type_count::value>::type> { + static constexpr int value{2}; +}; + +/// Type size of types that are wrappers,except complex and tuples(which can also be wrappers sometimes) +template struct type_count::value>::type> { + static constexpr int value{subtype_count::value}; +}; + +/// Type size of types that are wrappers,except containers complex and tuples(which can also be wrappers sometimes) +template +struct type_count::value && !is_complex::value && !is_tuple_like::value && + !is_mutable_container::value>::type> { + static constexpr int value{type_count::value}; +}; + +/// 0 if the index > tuple size +template +constexpr typename std::enable_if::value, int>::type tuple_type_size() { + return 0; +} + +/// Recursively generate the tuple type name +template + constexpr typename std::enable_if < I::value, int>::type tuple_type_size() { + return subtype_count::type>::value + tuple_type_size(); +} + +/// Get the type size of the sum of type sizes for all the individual tuple types +template struct type_count::value>::type> { + static constexpr int value{tuple_type_size()}; +}; + +/// definition of subtype count +template struct subtype_count { + static constexpr int value{is_mutable_container::value ? expected_max_vector_size : type_count::value}; +}; + +/// This will only trigger for actual void type +template struct type_count_min { + static const int value{0}; +}; + +/// Type size for regular object types that do not look like a tuple +template +struct type_count_min< + T, + typename std::enable_if::value && !is_tuple_like::value && !is_wrapper::value && + !is_complex::value && !std::is_void::value>::type> { + static constexpr int value{type_count::value}; +}; + +/// Type size for complex since it sometimes looks like a wrapper +template struct type_count_min::value>::type> { + static constexpr int value{1}; +}; + +/// Type size min of types that are wrappers,except complex and tuples(which can also be wrappers sometimes) +template +struct type_count_min< + T, + typename std::enable_if::value && !is_complex::value && !is_tuple_like::value>::type> { + static constexpr int value{subtype_count_min::value}; +}; + +/// 0 if the index > tuple size +template +constexpr typename std::enable_if::value, int>::type tuple_type_size_min() { + return 0; +} + +/// Recursively generate the tuple type name +template + constexpr typename std::enable_if < I::value, int>::type tuple_type_size_min() { + return subtype_count_min::type>::value + tuple_type_size_min(); +} + +/// Get the type size of the sum of type sizes for all the individual tuple types +template struct type_count_min::value>::type> { + static constexpr int value{tuple_type_size_min()}; +}; + +/// definition of subtype count +template struct subtype_count_min { + static constexpr int value{is_mutable_container::value + ? ((type_count::value < expected_max_vector_size) ? type_count::value : 0) + : type_count_min::value}; +}; + +/// This will only trigger for actual void type +template struct expected_count { + static const int value{0}; +}; + +/// For most types the number of expected items is 1 +template +struct expected_count::value && !is_wrapper::value && + !std::is_void::value>::type> { + static constexpr int value{1}; +}; +/// number of expected items in a vector +template struct expected_count::value>::type> { + static constexpr int value{expected_max_vector_size}; +}; + +/// number of expected items in a vector +template +struct expected_count::value && is_wrapper::value>::type> { + static constexpr int value{expected_count::value}; +}; + +// Enumeration of the different supported categorizations of objects +enum class object_category : int { + char_value = 1, + integral_value = 2, + unsigned_integral = 4, + enumeration = 6, + boolean_value = 8, + floating_point = 10, + number_constructible = 12, + double_constructible = 14, + integer_constructible = 16, + // string like types + string_assignable = 23, + string_constructible = 24, + wstring_assignable = 25, + wstring_constructible = 26, + other = 45, + // special wrapper or container types + wrapper_value = 50, + complex_number = 60, + tuple_value = 70, + container_value = 80, + +}; + +/// Set of overloads to classify an object according to type + +/// some type that is not otherwise recognized +template struct classify_object { + static constexpr object_category value{object_category::other}; +}; + +/// Signed integers +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_same::value && std::is_signed::value && + !is_bool::value && !std::is_enum::value>::type> { + static constexpr object_category value{object_category::integral_value}; +}; + +/// Unsigned integers +template +struct classify_object::value && std::is_unsigned::value && + !std::is_same::value && !is_bool::value>::type> { + static constexpr object_category value{object_category::unsigned_integral}; +}; + +/// single character values +template +struct classify_object::value && !std::is_enum::value>::type> { + static constexpr object_category value{object_category::char_value}; +}; + +/// Boolean values +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::boolean_value}; +}; + +/// Floats +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::floating_point}; +}; +#if defined _MSC_VER +// in MSVC wstring should take precedence if available this isn't as useful on other compilers due to the broader use of +// utf-8 encoding +#define WIDE_STRING_CHECK \ + !std::is_assignable::value && !std::is_constructible::value +#define STRING_CHECK true +#else +#define WIDE_STRING_CHECK true +#define STRING_CHECK !std::is_assignable::value && !std::is_constructible::value +#endif + +/// String and similar direct assignment +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_integral::value && WIDE_STRING_CHECK && + std::is_assignable::value>::type> { + static constexpr object_category value{object_category::string_assignable}; +}; + +/// String and similar constructible and copy assignment +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_integral::value && + !std::is_assignable::value && (type_count::value == 1) && + WIDE_STRING_CHECK && std::is_constructible::value>::type> { + static constexpr object_category value{object_category::string_constructible}; +}; + +/// Wide strings +template +struct classify_object::value && !std::is_integral::value && + STRING_CHECK && std::is_assignable::value>::type> { + static constexpr object_category value{object_category::wstring_assignable}; +}; + +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_integral::value && + !std::is_assignable::value && (type_count::value == 1) && + STRING_CHECK && std::is_constructible::value>::type> { + static constexpr object_category value{object_category::wstring_constructible}; +}; + +/// Enumerations +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::enumeration}; +}; + +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::complex_number}; +}; + +/// Handy helper to contain a bunch of checks that rule out many common types (integers, string like, floating point, +/// vectors, and enumerations +template struct uncommon_type { + using type = typename std::conditional< + !std::is_floating_point::value && !std::is_integral::value && + !std::is_assignable::value && !std::is_constructible::value && + !std::is_assignable::value && !std::is_constructible::value && + !is_complex::value && !is_mutable_container::value && !std::is_enum::value, + std::true_type, + std::false_type>::type; + static constexpr bool value = type::value; +}; + +/// wrapper type +template +struct classify_object::value && is_wrapper::value && + !is_tuple_like::value && uncommon_type::value)>::type> { + static constexpr object_category value{object_category::wrapper_value}; +}; + +/// Assignable from double or int +template +struct classify_object::value && type_count::value == 1 && + !is_wrapper::value && is_direct_constructible::value && + is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::number_constructible}; +}; + +/// Assignable from int +template +struct classify_object::value && type_count::value == 1 && + !is_wrapper::value && !is_direct_constructible::value && + is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::integer_constructible}; +}; + +/// Assignable from double +template +struct classify_object::value && type_count::value == 1 && + !is_wrapper::value && is_direct_constructible::value && + !is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::double_constructible}; +}; + +/// Tuple type +template +struct classify_object< + T, + typename std::enable_if::value && + ((type_count::value >= 2 && !is_wrapper::value) || + (uncommon_type::value && !is_direct_constructible::value && + !is_direct_constructible::value) || + (uncommon_type::value && type_count::value >= 2))>::type> { + static constexpr object_category value{object_category::tuple_value}; + // the condition on this class requires it be like a tuple, but on some compilers (like Xcode) tuples can be + // constructed from just the first element so tuples of can be constructed from a string, which + // could lead to issues so there are two variants of the condition, the first isolates things with a type size >=2 + // mainly to get tuples on Xcode with the exception of wrappers, the second is the main one and just separating out + // those cases that are caught by other object classifications +}; + +/// container type +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::container_value}; +}; + +// Type name print + +/// Was going to be based on +/// http://stackoverflow.com/questions/1055452/c-get-name-of-type-in-template +/// But this is cleaner and works better in this case + +template ::value == object_category::char_value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "CHAR"; +} + +template ::value == object_category::integral_value || + classify_object::value == object_category::integer_constructible, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "INT"; +} + +template ::value == object_category::unsigned_integral, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "UINT"; +} + +template ::value == object_category::floating_point || + classify_object::value == object_category::number_constructible || + classify_object::value == object_category::double_constructible, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "FLOAT"; +} + +/// Print name for enumeration types +template ::value == object_category::enumeration, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "ENUM"; +} + +/// Print name for enumeration types +template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "BOOLEAN"; +} + +/// Print name for enumeration types +template ::value == object_category::complex_number, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "COMPLEX"; +} + +/// Print for all other types +template ::value >= object_category::string_assignable && + classify_object::value <= object_category::other, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "TEXT"; +} +/// typename for tuple value +template ::value == object_category::tuple_value && type_count_base::value >= 2, + detail::enabler> = detail::dummy> +std::string type_name(); // forward declaration + +/// Generate type name for a wrapper or container value +template ::value == object_category::container_value || + classify_object::value == object_category::wrapper_value, + detail::enabler> = detail::dummy> +std::string type_name(); // forward declaration + +/// Print name for single element tuple types +template ::value == object_category::tuple_value && type_count_base::value == 1, + detail::enabler> = detail::dummy> +inline std::string type_name() { + return type_name::type>::type>(); +} + +/// Empty string if the index > tuple size +template +inline typename std::enable_if::value, std::string>::type tuple_name() { + return std::string{}; +} + +/// Recursively generate the tuple type name +template +inline typename std::enable_if<(I < type_count_base::value), std::string>::type tuple_name() { + auto str = std::string{type_name::type>::type>()} + ',' + + tuple_name(); + if(str.back() == ',') + str.pop_back(); + return str; +} + +/// Print type name for tuples with 2 or more elements +template ::value == object_category::tuple_value && type_count_base::value >= 2, + detail::enabler>> +inline std::string type_name() { + auto tname = std::string(1, '[') + tuple_name(); + tname.push_back(']'); + return tname; +} + +/// get the type name for a type that has a value_type member +template ::value == object_category::container_value || + classify_object::value == object_category::wrapper_value, + detail::enabler>> +inline std::string type_name() { + return type_name(); +} + +// Lexical cast + +/// Convert to an unsigned integral +template ::value, detail::enabler> = detail::dummy> +bool integral_conversion(const std::string &input, T &output) noexcept { + if(input.empty() || input.front() == '-') { + return false; + } + char *val{nullptr}; + errno = 0; + std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + if(val == (input.c_str() + input.size()) && static_cast(output) == output_ll) { + return true; + } + val = nullptr; + std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0); + if(val == (input.c_str() + input.size())) { + output = (output_sll < 0) ? static_cast(0) : static_cast(output_sll); + return (static_cast(output) == output_sll); + } + // remove separators + if(input.find_first_of("_'") != std::string::npos) { + std::string nstring = input; + nstring.erase(std::remove(nstring.begin(), nstring.end(), '_'), nstring.end()); + nstring.erase(std::remove(nstring.begin(), nstring.end(), '\''), nstring.end()); + return integral_conversion(nstring, output); + } + if(input.compare(0, 2, "0o") == 0) { + val = nullptr; + errno = 0; + output_ll = std::strtoull(input.c_str() + 2, &val, 8); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + return (val == (input.c_str() + input.size()) && static_cast(output) == output_ll); + } + if(input.compare(0, 2, "0b") == 0) { + val = nullptr; + errno = 0; + output_ll = std::strtoull(input.c_str() + 2, &val, 2); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + return (val == (input.c_str() + input.size()) && static_cast(output) == output_ll); + } + return false; +} + +/// Convert to a signed integral +template ::value, detail::enabler> = detail::dummy> +bool integral_conversion(const std::string &input, T &output) noexcept { + if(input.empty()) { + return false; + } + char *val = nullptr; + errno = 0; + std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + if(val == (input.c_str() + input.size()) && static_cast(output) == output_ll) { + return true; + } + if(input == "true") { + // this is to deal with a few oddities with flags and wrapper int types + output = static_cast(1); + return true; + } + // remove separators + if(input.find_first_of("_'") != std::string::npos) { + std::string nstring = input; + nstring.erase(std::remove(nstring.begin(), nstring.end(), '_'), nstring.end()); + nstring.erase(std::remove(nstring.begin(), nstring.end(), '\''), nstring.end()); + return integral_conversion(nstring, output); + } + if(input.compare(0, 2, "0o") == 0) { + val = nullptr; + errno = 0; + output_ll = std::strtoll(input.c_str() + 2, &val, 8); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + return (val == (input.c_str() + input.size()) && static_cast(output) == output_ll); + } + if(input.compare(0, 2, "0b") == 0) { + val = nullptr; + errno = 0; + output_ll = std::strtoll(input.c_str() + 2, &val, 2); + if(errno == ERANGE) { + return false; + } + output = static_cast(output_ll); + return (val == (input.c_str() + input.size()) && static_cast(output) == output_ll); + } + return false; +} + +/// Convert a flag into an integer value typically binary flags sets errno to nonzero if conversion failed +inline std::int64_t to_flag_value(std::string val) noexcept { + static const std::string trueString("true"); + static const std::string falseString("false"); + if(val == trueString) { + return 1; + } + if(val == falseString) { + return -1; + } + val = detail::to_lower(val); + std::int64_t ret = 0; + if(val.size() == 1) { + if(val[0] >= '1' && val[0] <= '9') { + return (static_cast(val[0]) - '0'); + } + switch(val[0]) { + case '0': + case 'f': + case 'n': + case '-': + ret = -1; + break; + case 't': + case 'y': + case '+': + ret = 1; + break; + default: + errno = EINVAL; + return -1; + } + return ret; + } + if(val == trueString || val == "on" || val == "yes" || val == "enable") { + ret = 1; + } else if(val == falseString || val == "off" || val == "no" || val == "disable") { + ret = -1; + } else { + char *loc_ptr{nullptr}; + ret = std::strtoll(val.c_str(), &loc_ptr, 0); + if(loc_ptr != (val.c_str() + val.size()) && errno == 0) { + errno = EINVAL; + } + } + return ret; +} + +/// Integer conversion +template ::value == object_category::integral_value || + classify_object::value == object_category::unsigned_integral, + detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + return integral_conversion(input, output); +} + +/// char values +template ::value == object_category::char_value, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + if(input.size() == 1) { + output = static_cast(input[0]); + return true; + } + return integral_conversion(input, output); +} + +/// Boolean values +template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + errno = 0; + auto out = to_flag_value(input); + if(errno == 0) { + output = (out > 0); + } else if(errno == ERANGE) { + output = (input[0] != '-'); + } else { + return false; + } + return true; +} + +/// Floats +template ::value == object_category::floating_point, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + if(input.empty()) { + return false; + } + char *val = nullptr; + auto output_ld = std::strtold(input.c_str(), &val); + output = static_cast(output_ld); + if(val == (input.c_str() + input.size())) { + return true; + } + // remove separators + if(input.find_first_of("_'") != std::string::npos) { + std::string nstring = input; + nstring.erase(std::remove(nstring.begin(), nstring.end(), '_'), nstring.end()); + nstring.erase(std::remove(nstring.begin(), nstring.end(), '\''), nstring.end()); + return lexical_cast(nstring, output); + } + return false; +} + +/// complex +template ::value == object_category::complex_number, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + using XC = typename wrapped_type::type; + XC x{0.0}, y{0.0}; + auto str1 = input; + bool worked = false; + auto nloc = str1.find_last_of("+-"); + if(nloc != std::string::npos && nloc > 0) { + worked = lexical_cast(str1.substr(0, nloc), x); + str1 = str1.substr(nloc); + if(str1.back() == 'i' || str1.back() == 'j') + str1.pop_back(); + worked = worked && lexical_cast(str1, y); + } else { + if(str1.back() == 'i' || str1.back() == 'j') { + str1.pop_back(); + worked = lexical_cast(str1, y); + x = XC{0}; + } else { + worked = lexical_cast(str1, x); + y = XC{0}; + } + } + if(worked) { + output = T{x, y}; + return worked; + } + return from_stream(input, output); +} + +/// String and similar direct assignment +template ::value == object_category::string_assignable, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = input; + return true; +} + +/// String and similar constructible and copy assignment +template < + typename T, + enable_if_t::value == object_category::string_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = T(input); + return true; +} + +/// Wide strings +template < + typename T, + enable_if_t::value == object_category::wstring_assignable, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = widen(input); + return true; +} + +template < + typename T, + enable_if_t::value == object_category::wstring_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = T{widen(input)}; + return true; +} + +/// Enumerations +template ::value == object_category::enumeration, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + typename std::underlying_type::type val; + if(!integral_conversion(input, val)) { + return false; + } + output = static_cast(val); + return true; +} + +/// wrapper types +template ::value == object_category::wrapper_value && + std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + typename T::value_type val; + if(lexical_cast(input, val)) { + output = val; + return true; + } + return from_stream(input, output); +} + +template ::value == object_category::wrapper_value && + !std::is_assignable::value && std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + typename T::value_type val; + if(lexical_cast(input, val)) { + output = T{val}; + return true; + } + return from_stream(input, output); +} + +/// Assignable from double or int +template < + typename T, + enable_if_t::value == object_category::number_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + int val = 0; + if(integral_conversion(input, val)) { + output = T(val); + return true; + } + + double dval = 0.0; + if(lexical_cast(input, dval)) { + output = T{dval}; + return true; + } + + return from_stream(input, output); +} + +/// Assignable from int +template < + typename T, + enable_if_t::value == object_category::integer_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + int val = 0; + if(integral_conversion(input, val)) { + output = T(val); + return true; + } + return from_stream(input, output); +} + +/// Assignable from double +template < + typename T, + enable_if_t::value == object_category::double_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + double val = 0.0; + if(lexical_cast(input, val)) { + output = T{val}; + return true; + } + return from_stream(input, output); +} + +/// Non-string convertible from an int +template ::value == object_category::other && std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + int val = 0; + if(integral_conversion(input, val)) { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4800) +#endif + // with Atomic this could produce a warning due to the conversion but if atomic gets here it is an old style + // so will most likely still work + output = val; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + return true; + } + // LCOV_EXCL_START + // This version of cast is only used for odd cases in an older compilers the fail over + // from_stream is tested elsewhere an not relevant for coverage here + return from_stream(input, output); + // LCOV_EXCL_STOP +} + +/// Non-string parsable by a stream +template ::value == object_category::other && !std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + static_assert(is_istreamable::value, + "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it " + "is convertible from another type use the add_option(...) with XC being the known type"); + return from_stream(input, output); +} + +/// Assign a value through lexical cast operations +/// Strings can be empty so we need to do a little different +template ::value && + (classify_object::value == object_category::string_assignable || + classify_object::value == object_category::string_constructible || + classify_object::value == object_category::wstring_assignable || + classify_object::value == object_category::wstring_constructible), + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + return lexical_cast(input, output); +} + +/// Assign a value through lexical cast operations +template ::value && std::is_assignable::value && + classify_object::value != object_category::string_assignable && + classify_object::value != object_category::string_constructible && + classify_object::value != object_category::wstring_assignable && + classify_object::value != object_category::wstring_constructible, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + if(input.empty()) { + output = AssignTo{}; + return true; + } + + return lexical_cast(input, output); +} + +/// Assign a value through lexical cast operations +template ::value && !std::is_assignable::value && + classify_object::value == object_category::wrapper_value, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + if(input.empty()) { + typename AssignTo::value_type emptyVal{}; + output = emptyVal; + return true; + } + return lexical_cast(input, output); +} + +/// Assign a value through lexical cast operations for int compatible values +/// mainly for atomic operations on some compilers +template ::value && !std::is_assignable::value && + classify_object::value != object_category::wrapper_value && + std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + if(input.empty()) { + output = 0; + return true; + } + int val{0}; + if(lexical_cast(input, val)) { +#if defined(__clang__) +/* on some older clang compilers */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wsign-conversion" +#endif + output = val; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + return true; + } + return false; +} + +/// Assign a value converted from a string in lexical cast to the output value directly +template ::value && std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + ConvertTo val{}; + bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true; + if(parse_result) { + output = val; + } + return parse_result; +} + +/// Assign a value from a lexical cast through constructing a value and move assigning it +template < + typename AssignTo, + typename ConvertTo, + enable_if_t::value && !std::is_assignable::value && + std::is_move_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, AssignTo &output) { + ConvertTo val{}; + bool parse_result = input.empty() ? true : lexical_cast(input, val); + if(parse_result) { + output = AssignTo(val); // use () form of constructor to allow some implicit conversions + } + return parse_result; +} + +/// primary lexical conversion operation, 1 string to 1 type of some kind +template ::value <= object_category::other && + classify_object::value <= object_category::wrapper_value, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + return lexical_assign(strings[0], output); +} + +/// Lexical conversion if there is only one element but the conversion type is for two, then call a two element +/// constructor +template ::value <= 2) && expected_count::value == 1 && + is_tuple_like::value && type_count_base::value == 2, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + // the remove const is to handle pair types coming from a container + using FirstType = typename std::remove_const::type>::type; + using SecondType = typename std::tuple_element<1, ConvertTo>::type; + FirstType v1; + SecondType v2; + bool retval = lexical_assign(strings[0], v1); + retval = retval && lexical_assign((strings.size() > 1) ? strings[1] : std::string{}, v2); + if(retval) { + output = AssignTo{v1, v2}; + } + return retval; +} + +/// Lexical conversion of a container types of single elements +template ::value && is_mutable_container::value && + type_count::value == 1, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + output.erase(output.begin(), output.end()); + if(strings.empty()) { + return true; + } + if(strings.size() == 1 && strings[0] == "{}") { + return true; + } + bool skip_remaining = false; + if(strings.size() == 2 && strings[0] == "{}" && is_separator(strings[1])) { + skip_remaining = true; + } + for(const auto &elem : strings) { + typename AssignTo::value_type out; + bool retval = lexical_assign(elem, out); + if(!retval) { + return false; + } + output.insert(output.end(), std::move(out)); + if(skip_remaining) { + break; + } + } + return (!output.empty()); +} + +/// Lexical conversion for complex types +template ::value, detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + + if(strings.size() >= 2 && !strings[1].empty()) { + using XC2 = typename wrapped_type::type; + XC2 x{0.0}, y{0.0}; + auto str1 = strings[1]; + if(str1.back() == 'i' || str1.back() == 'j') { + str1.pop_back(); + } + auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y); + if(worked) { + output = ConvertTo{x, y}; + } + return worked; + } + return lexical_assign(strings[0], output); +} + +/// Conversion to a vector type using a particular single type as the conversion type +template ::value && (expected_count::value == 1) && + (type_count::value == 1), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + bool retval = true; + output.clear(); + output.reserve(strings.size()); + for(const auto &elem : strings) { + + output.emplace_back(); + retval = retval && lexical_assign(elem, output.back()); + } + return (!output.empty()) && retval; +} + +// forward declaration + +/// Lexical conversion of a container types with conversion type of two elements +template ::value && is_mutable_container::value && + type_count_base::value == 2, + detail::enabler> = detail::dummy> +bool lexical_conversion(std::vector strings, AssignTo &output); + +/// Lexical conversion of a vector types with type_size >2 forward declaration +template ::value && is_mutable_container::value && + type_count_base::value != 2 && + ((type_count::value > 2) || + (type_count::value > type_count_base::value)), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output); + +/// Conversion for tuples +template ::value && is_tuple_like::value && + (type_count_base::value != type_count::value || + type_count::value > 2), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output); // forward declaration + +/// Conversion for operations where the assigned type is some class but the conversion is a mutable container or large +/// tuple +template ::value && !is_mutable_container::value && + classify_object::value != object_category::wrapper_value && + (is_mutable_container::value || type_count::value > 2), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + + if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) { + ConvertTo val; + auto retval = lexical_conversion(strings, val); + output = AssignTo{val}; + return retval; + } + output = AssignTo{}; + return true; +} + +/// function template for converting tuples if the static Index is greater than the tuple size +template +inline typename std::enable_if<(I >= type_count_base::value), bool>::type +tuple_conversion(const std::vector &, AssignTo &) { + return true; +} + +/// Conversion of a tuple element where the type size ==1 and not a mutable container +template +inline typename std::enable_if::value && type_count::value == 1, bool>::type +tuple_type_conversion(std::vector &strings, AssignTo &output) { + auto retval = lexical_assign(strings[0], output); + strings.erase(strings.begin()); + return retval; +} + +/// Conversion of a tuple element where the type size !=1 but the size is fixed and not a mutable container +template +inline typename std::enable_if::value && (type_count::value > 1) && + type_count::value == type_count_min::value, + bool>::type +tuple_type_conversion(std::vector &strings, AssignTo &output) { + auto retval = lexical_conversion(strings, output); + strings.erase(strings.begin(), strings.begin() + type_count::value); + return retval; +} + +/// Conversion of a tuple element where the type is a mutable container or a type with different min and max type sizes +template +inline typename std::enable_if::value || + type_count::value != type_count_min::value, + bool>::type +tuple_type_conversion(std::vector &strings, AssignTo &output) { + + std::size_t index{subtype_count_min::value}; + const std::size_t mx_count{subtype_count::value}; + const std::size_t mx{(std::min)(mx_count, strings.size() - 1)}; + + while(index < mx) { + if(is_separator(strings[index])) { + break; + } + ++index; + } + bool retval = lexical_conversion( + std::vector(strings.begin(), strings.begin() + static_cast(index)), output); + if(strings.size() > index) { + strings.erase(strings.begin(), strings.begin() + static_cast(index) + 1); + } else { + strings.clear(); + } + return retval; +} + +/// Tuple conversion operation +template +inline typename std::enable_if<(I < type_count_base::value), bool>::type +tuple_conversion(std::vector strings, AssignTo &output) { + bool retval = true; + using ConvertToElement = typename std:: + conditional::value, typename std::tuple_element::type, ConvertTo>::type; + if(!strings.empty()) { + retval = retval && tuple_type_conversion::type, ConvertToElement>( + strings, std::get(output)); + } + retval = retval && tuple_conversion(std::move(strings), output); + return retval; +} + +/// Lexical conversion of a container types with tuple elements of size 2 +template ::value && is_mutable_container::value && + type_count_base::value == 2, + detail::enabler>> +bool lexical_conversion(std::vector strings, AssignTo &output) { + output.clear(); + while(!strings.empty()) { + + typename std::remove_const::type>::type v1; + typename std::tuple_element<1, typename ConvertTo::value_type>::type v2; + bool retval = tuple_type_conversion(strings, v1); + if(!strings.empty()) { + retval = retval && tuple_type_conversion(strings, v2); + } + if(retval) { + output.insert(output.end(), typename AssignTo::value_type{v1, v2}); + } else { + return false; + } + } + return (!output.empty()); +} + +/// lexical conversion of tuples with type count>2 or tuples of types of some element with a type size>=2 +template ::value && is_tuple_like::value && + (type_count_base::value != type_count::value || + type_count::value > 2), + detail::enabler>> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + static_assert( + !is_tuple_like::value || type_count_base::value == type_count_base::value, + "if the conversion type is defined as a tuple it must be the same size as the type you are converting to"); + return tuple_conversion(strings, output); +} + +/// Lexical conversion of a vector types for everything but tuples of two elements and types of size 1 +template ::value && is_mutable_container::value && + type_count_base::value != 2 && + ((type_count::value > 2) || + (type_count::value > type_count_base::value)), + detail::enabler>> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + bool retval = true; + output.clear(); + std::vector temp; + std::size_t ii{0}; + std::size_t icount{0}; + std::size_t xcm{type_count::value}; + auto ii_max = strings.size(); + while(ii < ii_max) { + temp.push_back(strings[ii]); + ++ii; + ++icount; + if(icount == xcm || is_separator(temp.back()) || ii == ii_max) { + if(static_cast(xcm) > type_count_min::value && is_separator(temp.back())) { + temp.pop_back(); + } + typename AssignTo::value_type temp_out; + retval = retval && + lexical_conversion(temp, temp_out); + temp.clear(); + if(!retval) { + return false; + } + output.insert(output.end(), std::move(temp_out)); + icount = 0; + } + } + return retval; +} + +/// conversion for wrapper types +template ::value == object_category::wrapper_value && + std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + if(strings.empty() || strings.front().empty()) { + output = ConvertTo{}; + return true; + } + typename ConvertTo::value_type val; + if(lexical_conversion(strings, val)) { + output = ConvertTo{val}; + return true; + } + return false; +} + +/// conversion for wrapper types +template ::value == object_category::wrapper_value && + !std::is_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, AssignTo &output) { + using ConvertType = typename ConvertTo::value_type; + if(strings.empty() || strings.front().empty()) { + output = ConvertType{}; + return true; + } + ConvertType val; + if(lexical_conversion(strings, val)) { + output = val; + return true; + } + return false; +} + +/// Sum a vector of strings +inline std::string sum_string_vector(const std::vector &values) { + double val{0.0}; + bool fail{false}; + std::string output; + for(const auto &arg : values) { + double tv{0.0}; + auto comp = lexical_cast(arg, tv); + if(!comp) { + errno = 0; + auto fv = detail::to_flag_value(arg); + fail = (errno != 0); + if(fail) { + break; + } + tv = static_cast(fv); + } + val += tv; + } + if(fail) { + for(const auto &arg : values) { + output.append(arg); + } + } else { + std::ostringstream out; + out.precision(16); + out << val; + output = out.str(); + } + return output; +} + +} // namespace detail + + + +namespace detail { + +// Returns false if not a short option. Otherwise, sets opt name and rest and returns true +CLI11_INLINE bool split_short(const std::string ¤t, std::string &name, std::string &rest); + +// Returns false if not a long option. Otherwise, sets opt name and other side of = and returns true +CLI11_INLINE bool split_long(const std::string ¤t, std::string &name, std::string &value); + +// Returns false if not a windows style option. Otherwise, sets opt name and value and returns true +CLI11_INLINE bool split_windows_style(const std::string ¤t, std::string &name, std::string &value); + +// Splits a string into multiple long and short names +CLI11_INLINE std::vector split_names(std::string current); + +/// extract default flag values either {def} or starting with a ! +CLI11_INLINE std::vector> get_default_flag_values(const std::string &str); + +/// Get a vector of short names, one of long names, and a single name +CLI11_INLINE std::tuple, std::vector, std::string> +get_names(const std::vector &input); + +} // namespace detail + + + +namespace detail { + +CLI11_INLINE bool split_short(const std::string ¤t, std::string &name, std::string &rest) { + if(current.size() > 1 && current[0] == '-' && valid_first_char(current[1])) { + name = current.substr(1, 1); + rest = current.substr(2); + return true; + } + return false; +} + +CLI11_INLINE bool split_long(const std::string ¤t, std::string &name, std::string &value) { + if(current.size() > 2 && current.compare(0, 2, "--") == 0 && valid_first_char(current[2])) { + auto loc = current.find_first_of('='); + if(loc != std::string::npos) { + name = current.substr(2, loc - 2); + value = current.substr(loc + 1); + } else { + name = current.substr(2); + value = ""; + } + return true; + } + return false; +} + +CLI11_INLINE bool split_windows_style(const std::string ¤t, std::string &name, std::string &value) { + if(current.size() > 1 && current[0] == '/' && valid_first_char(current[1])) { + auto loc = current.find_first_of(':'); + if(loc != std::string::npos) { + name = current.substr(1, loc - 1); + value = current.substr(loc + 1); + } else { + name = current.substr(1); + value = ""; + } + return true; + } + return false; +} + +CLI11_INLINE std::vector split_names(std::string current) { + std::vector output; + std::size_t val = 0; + while((val = current.find(',')) != std::string::npos) { + output.push_back(trim_copy(current.substr(0, val))); + current = current.substr(val + 1); + } + output.push_back(trim_copy(current)); + return output; +} + +CLI11_INLINE std::vector> get_default_flag_values(const std::string &str) { + std::vector flags = split_names(str); + flags.erase(std::remove_if(flags.begin(), + flags.end(), + [](const std::string &name) { + return ((name.empty()) || (!(((name.find_first_of('{') != std::string::npos) && + (name.back() == '}')) || + (name[0] == '!')))); + }), + flags.end()); + std::vector> output; + output.reserve(flags.size()); + for(auto &flag : flags) { + auto def_start = flag.find_first_of('{'); + std::string defval = "false"; + if((def_start != std::string::npos) && (flag.back() == '}')) { + defval = flag.substr(def_start + 1); + defval.pop_back(); + flag.erase(def_start, std::string::npos); // NOLINT(readability-suspicious-call-argument) + } + flag.erase(0, flag.find_first_not_of("-!")); + output.emplace_back(flag, defval); + } + return output; +} + +CLI11_INLINE std::tuple, std::vector, std::string> +get_names(const std::vector &input) { + + std::vector short_names; + std::vector long_names; + std::string pos_name; + for(std::string name : input) { + if(name.length() == 0) { + continue; + } + if(name.length() > 1 && name[0] == '-' && name[1] != '-') { + if(name.length() == 2 && valid_first_char(name[1])) + short_names.emplace_back(1, name[1]); + else if(name.length() > 2) + throw BadNameString::MissingDash(name); + else + throw BadNameString::OneCharName(name); + } else if(name.length() > 2 && name.substr(0, 2) == "--") { + name = name.substr(2); + if(valid_name_string(name)) + long_names.push_back(name); + else + throw BadNameString::BadLongName(name); + } else if(name == "-" || name == "--") { + throw BadNameString::DashesOnly(name); + } else { + if(!pos_name.empty()) + throw BadNameString::MultiPositionalNames(name); + if(valid_name_string(name)) { + pos_name = name; + } else { + throw BadNameString::BadPositionalName(name); + } + } + } + return std::make_tuple(short_names, long_names, pos_name); +} + +} // namespace detail + + + +class App; + +/// Holds values to load into Options +struct ConfigItem { + /// This is the list of parents + std::vector parents{}; + + /// This is the name + std::string name{}; + /// Listing of inputs + std::vector inputs{}; + + /// The list of parents and name joined by "." + CLI11_NODISCARD std::string fullname() const { + std::vector tmp = parents; + tmp.emplace_back(name); + return detail::join(tmp, "."); + } +}; + +/// This class provides a converter for configuration files. +class Config { + protected: + std::vector items{}; + + public: + /// Convert an app into a configuration + virtual std::string to_config(const App *, bool, bool, std::string) const = 0; + + /// Convert a configuration into an app + virtual std::vector from_config(std::istream &) const = 0; + + /// Get a flag value + CLI11_NODISCARD virtual std::string to_flag(const ConfigItem &item) const { + if(item.inputs.size() == 1) { + return item.inputs.at(0); + } + if(item.inputs.empty()) { + return "{}"; + } + throw ConversionError::TooManyInputsFlag(item.fullname()); // LCOV_EXCL_LINE + } + + /// Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure + CLI11_NODISCARD std::vector from_file(const std::string &name) const { + std::ifstream input{name}; + if(!input.good()) + throw FileError::Missing(name); + + return from_config(input); + } + + /// Virtual destructor + virtual ~Config() = default; +}; + +/// This converter works with INI/TOML files; to write INI files use ConfigINI +class ConfigBase : public Config { + protected: + /// the character used for comments + char commentChar = '#'; + /// the character used to start an array '\0' is a default to not use + char arrayStart = '['; + /// the character used to end an array '\0' is a default to not use + char arrayEnd = ']'; + /// the character used to separate elements in an array + char arraySeparator = ','; + /// the character used separate the name from the value + char valueDelimiter = '='; + /// the character to use around strings + char stringQuote = '"'; + /// the character to use around single characters and literal strings + char literalQuote = '\''; + /// the maximum number of layers to allow + uint8_t maximumLayers{255}; + /// the separator used to separator parent layers + char parentSeparatorChar{'.'}; + /// Specify the configuration index to use for arrayed sections + int16_t configIndex{-1}; + /// Specify the configuration section that should be used + std::string configSection{}; + + public: + std::string + to_config(const App * /*app*/, bool default_also, bool write_description, std::string prefix) const override; + + std::vector from_config(std::istream &input) const override; + /// Specify the configuration for comment characters + ConfigBase *comment(char cchar) { + commentChar = cchar; + return this; + } + /// Specify the start and end characters for an array + ConfigBase *arrayBounds(char aStart, char aEnd) { + arrayStart = aStart; + arrayEnd = aEnd; + return this; + } + /// Specify the delimiter character for an array + ConfigBase *arrayDelimiter(char aSep) { + arraySeparator = aSep; + return this; + } + /// Specify the delimiter between a name and value + ConfigBase *valueSeparator(char vSep) { + valueDelimiter = vSep; + return this; + } + /// Specify the quote characters used around strings and literal strings + ConfigBase *quoteCharacter(char qString, char literalChar) { + stringQuote = qString; + literalQuote = literalChar; + return this; + } + /// Specify the maximum number of parents + ConfigBase *maxLayers(uint8_t layers) { + maximumLayers = layers; + return this; + } + /// Specify the separator to use for parent layers + ConfigBase *parentSeparator(char sep) { + parentSeparatorChar = sep; + return this; + } + /// get a reference to the configuration section + std::string §ionRef() { return configSection; } + /// get the section + CLI11_NODISCARD const std::string §ion() const { return configSection; } + /// specify a particular section of the configuration file to use + ConfigBase *section(const std::string §ionName) { + configSection = sectionName; + return this; + } + + /// get a reference to the configuration index + int16_t &indexRef() { return configIndex; } + /// get the section index + CLI11_NODISCARD int16_t index() const { return configIndex; } + /// specify a particular index in the section to use (-1) for all sections to use + ConfigBase *index(int16_t sectionIndex) { + configIndex = sectionIndex; + return this; + } +}; + +/// the default Config is the TOML file format +using ConfigTOML = ConfigBase; + +/// ConfigINI generates a "standard" INI compliant output +class ConfigINI : public ConfigTOML { + + public: + ConfigINI() { + commentChar = ';'; + arrayStart = '\0'; + arrayEnd = '\0'; + arraySeparator = ' '; + valueDelimiter = '='; + } +}; + + + +class Option; + +/// @defgroup validator_group Validators + +/// @brief Some validators that are provided +/// +/// These are simple `std::string(const std::string&)` validators that are useful. They return +/// a string if the validation fails. A custom struct is provided, as well, with the same user +/// semantics, but with the ability to provide a new type name. +/// @{ + +/// +class Validator { + protected: + /// This is the description function, if empty the description_ will be used + std::function desc_function_{[]() { return std::string{}; }}; + + /// This is the base function that is to be called. + /// Returns a string error message if validation fails. + std::function func_{[](std::string &) { return std::string{}; }}; + /// The name for search purposes of the Validator + std::string name_{}; + /// A Validator will only apply to an indexed value (-1 is all elements) + int application_index_ = -1; + /// Enable for Validator to allow it to be disabled if need be + bool active_{true}; + /// specify that a validator should not modify the input + bool non_modifying_{false}; + + Validator(std::string validator_desc, std::function func) + : desc_function_([validator_desc]() { return validator_desc; }), func_(std::move(func)) {} + + public: + Validator() = default; + /// Construct a Validator with just the description string + explicit Validator(std::string validator_desc) : desc_function_([validator_desc]() { return validator_desc; }) {} + /// Construct Validator from basic information + Validator(std::function op, std::string validator_desc, std::string validator_name = "") + : desc_function_([validator_desc]() { return validator_desc; }), func_(std::move(op)), + name_(std::move(validator_name)) {} + /// Set the Validator operation function + Validator &operation(std::function op) { + func_ = std::move(op); + return *this; + } + /// This is the required operator for a Validator - provided to help + /// users (CLI11 uses the member `func` directly) + std::string operator()(std::string &str) const; + + /// This is the required operator for a Validator - provided to help + /// users (CLI11 uses the member `func` directly) + std::string operator()(const std::string &str) const { + std::string value = str; + return (active_) ? func_(value) : std::string{}; + } + + /// Specify the type string + Validator &description(std::string validator_desc) { + desc_function_ = [validator_desc]() { return validator_desc; }; + return *this; + } + /// Specify the type string + CLI11_NODISCARD Validator description(std::string validator_desc) const; + + /// Generate type description information for the Validator + CLI11_NODISCARD std::string get_description() const { + if(active_) { + return desc_function_(); + } + return std::string{}; + } + /// Specify the type string + Validator &name(std::string validator_name) { + name_ = std::move(validator_name); + return *this; + } + /// Specify the type string + CLI11_NODISCARD Validator name(std::string validator_name) const { + Validator newval(*this); + newval.name_ = std::move(validator_name); + return newval; + } + /// Get the name of the Validator + CLI11_NODISCARD const std::string &get_name() const { return name_; } + /// Specify whether the Validator is active or not + Validator &active(bool active_val = true) { + active_ = active_val; + return *this; + } + /// Specify whether the Validator is active or not + CLI11_NODISCARD Validator active(bool active_val = true) const { + Validator newval(*this); + newval.active_ = active_val; + return newval; + } + + /// Specify whether the Validator can be modifying or not + Validator &non_modifying(bool no_modify = true) { + non_modifying_ = no_modify; + return *this; + } + /// Specify the application index of a validator + Validator &application_index(int app_index) { + application_index_ = app_index; + return *this; + } + /// Specify the application index of a validator + CLI11_NODISCARD Validator application_index(int app_index) const { + Validator newval(*this); + newval.application_index_ = app_index; + return newval; + } + /// Get the current value of the application index + CLI11_NODISCARD int get_application_index() const { return application_index_; } + /// Get a boolean if the validator is active + CLI11_NODISCARD bool get_active() const { return active_; } + + /// Get a boolean if the validator is allowed to modify the input returns true if it can modify the input + CLI11_NODISCARD bool get_modifying() const { return !non_modifying_; } + + /// Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the + /// same. + Validator operator&(const Validator &other) const; + + /// Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the + /// same. + Validator operator|(const Validator &other) const; + + /// Create a validator that fails when a given validator succeeds + Validator operator!() const; + + private: + void _merge_description(const Validator &val1, const Validator &val2, const std::string &merger); +}; + +/// Class wrapping some of the accessors of Validator +class CustomValidator : public Validator { + public: +}; +// The implementation of the built in validators is using the Validator class; +// the user is only expected to use the const (static) versions (since there's no setup). +// Therefore, this is in detail. +namespace detail { + +/// CLI enumeration of different file types +enum class path_type { nonexistent, file, directory }; + +/// get the type of the path from a file name +CLI11_INLINE path_type check_path(const char *file) noexcept; + +/// Check for an existing file (returns error message if check fails) +class ExistingFileValidator : public Validator { + public: + ExistingFileValidator(); +}; + +/// Check for an existing directory (returns error message if check fails) +class ExistingDirectoryValidator : public Validator { + public: + ExistingDirectoryValidator(); +}; + +/// Check for an existing path +class ExistingPathValidator : public Validator { + public: + ExistingPathValidator(); +}; + +/// Check for an non-existing path +class NonexistentPathValidator : public Validator { + public: + NonexistentPathValidator(); +}; + +/// Validate the given string is a legal ipv4 address +class IPV4Validator : public Validator { + public: + IPV4Validator(); +}; + +class EscapedStringTransformer : public Validator { + public: + EscapedStringTransformer(); +}; + +} // namespace detail + +// Static is not needed here, because global const implies static. + +/// Check for existing file (returns error message if check fails) +const detail::ExistingFileValidator ExistingFile; + +/// Check for an existing directory (returns error message if check fails) +const detail::ExistingDirectoryValidator ExistingDirectory; + +/// Check for an existing path +const detail::ExistingPathValidator ExistingPath; + +/// Check for an non-existing path +const detail::NonexistentPathValidator NonexistentPath; + +/// Check for an IP4 address +const detail::IPV4Validator ValidIPV4; + +/// convert escaped characters into their associated values +const detail::EscapedStringTransformer EscapedString; + +/// Validate the input as a particular type +template class TypeValidator : public Validator { + public: + explicit TypeValidator(const std::string &validator_name) + : Validator(validator_name, [](std::string &input_string) { + using CLI::detail::lexical_cast; + auto val = DesiredType(); + if(!lexical_cast(input_string, val)) { + return std::string("Failed parsing ") + input_string + " as a " + detail::type_name(); + } + return std::string(); + }) {} + TypeValidator() : TypeValidator(detail::type_name()) {} +}; + +/// Check for a number +const TypeValidator Number("NUMBER"); + +/// Modify a path if the file is a particular default location, can be used as Check or transform +/// with the error return optionally disabled +class FileOnDefaultPath : public Validator { + public: + explicit FileOnDefaultPath(std::string default_path, bool enableErrorReturn = true); +}; + +/// Produce a range (factory). Min and max are inclusive. +class Range : public Validator { + public: + /// This produces a range with min and max inclusive. + /// + /// Note that the constructor is templated, but the struct is not, so C++17 is not + /// needed to provide nice syntax for Range(a,b). + template + Range(T min_val, T max_val, const std::string &validator_name = std::string{}) : Validator(validator_name) { + if(validator_name.empty()) { + std::stringstream out; + out << detail::type_name() << " in [" << min_val << " - " << max_val << "]"; + description(out.str()); + } + + func_ = [min_val, max_val](std::string &input) { + using CLI::detail::lexical_cast; + T val; + bool converted = lexical_cast(input, val); + if((!converted) || (val < min_val || val > max_val)) { + std::stringstream out; + out << "Value " << input << " not in range ["; + out << min_val << " - " << max_val << "]"; + return out.str(); + } + return std::string{}; + }; + } + + /// Range of one value is 0 to value + template + explicit Range(T max_val, const std::string &validator_name = std::string{}) + : Range(static_cast(0), max_val, validator_name) {} +}; + +/// Check for a non negative number +const Range NonNegativeNumber((std::numeric_limits::max)(), "NONNEGATIVE"); + +/// Check for a positive valued number (val>0.0), ::min here is the smallest positive number +const Range PositiveNumber((std::numeric_limits::min)(), (std::numeric_limits::max)(), "POSITIVE"); + +/// Produce a bounded range (factory). Min and max are inclusive. +class Bound : public Validator { + public: + /// This bounds a value with min and max inclusive. + /// + /// Note that the constructor is templated, but the struct is not, so C++17 is not + /// needed to provide nice syntax for Range(a,b). + template Bound(T min_val, T max_val) { + std::stringstream out; + out << detail::type_name() << " bounded to [" << min_val << " - " << max_val << "]"; + description(out.str()); + + func_ = [min_val, max_val](std::string &input) { + using CLI::detail::lexical_cast; + T val; + bool converted = lexical_cast(input, val); + if(!converted) { + return std::string("Value ") + input + " could not be converted"; + } + if(val < min_val) + input = detail::to_string(min_val); + else if(val > max_val) + input = detail::to_string(max_val); + + return std::string{}; + }; + } + + /// Range of one value is 0 to value + template explicit Bound(T max_val) : Bound(static_cast(0), max_val) {} +}; + +namespace detail { +template ::type>::value, detail::enabler> = detail::dummy> +auto smart_deref(T value) -> decltype(*value) { + return *value; +} + +template < + typename T, + enable_if_t::type>::value, detail::enabler> = detail::dummy> +typename std::remove_reference::type &smart_deref(T &value) { + return value; +} +/// Generate a string representation of a set +template std::string generate_set(const T &set) { + using element_t = typename detail::element_type::type; + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + std::string out(1, '{'); + out.append(detail::join( + detail::smart_deref(set), + [](const iteration_type_t &v) { return detail::pair_adaptor::first(v); }, + ",")); + out.push_back('}'); + return out; +} + +/// Generate a string representation of a map +template std::string generate_map(const T &map, bool key_only = false) { + using element_t = typename detail::element_type::type; + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + std::string out(1, '{'); + out.append(detail::join( + detail::smart_deref(map), + [key_only](const iteration_type_t &v) { + std::string res{detail::to_string(detail::pair_adaptor::first(v))}; + + if(!key_only) { + res.append("->"); + res += detail::to_string(detail::pair_adaptor::second(v)); + } + return res; + }, + ",")); + out.push_back('}'); + return out; +} + +template struct has_find { + template + static auto test(int) -> decltype(std::declval().find(std::declval()), std::true_type()); + template static auto test(...) -> decltype(std::false_type()); + + static const auto value = decltype(test(0))::value; + using type = std::integral_constant; +}; + +/// A search function +template ::value, detail::enabler> = detail::dummy> +auto search(const T &set, const V &val) -> std::pair { + using element_t = typename detail::element_type::type; + auto &setref = detail::smart_deref(set); + auto it = std::find_if(std::begin(setref), std::end(setref), [&val](decltype(*std::begin(setref)) v) { + return (detail::pair_adaptor::first(v) == val); + }); + return {(it != std::end(setref)), it}; +} + +/// A search function that uses the built in find function +template ::value, detail::enabler> = detail::dummy> +auto search(const T &set, const V &val) -> std::pair { + auto &setref = detail::smart_deref(set); + auto it = setref.find(val); + return {(it != std::end(setref)), it}; +} + +/// A search function with a filter function +template +auto search(const T &set, const V &val, const std::function &filter_function) + -> std::pair { + using element_t = typename detail::element_type::type; + // do the potentially faster first search + auto res = search(set, val); + if((res.first) || (!(filter_function))) { + return res; + } + // if we haven't found it do the longer linear search with all the element translations + auto &setref = detail::smart_deref(set); + auto it = std::find_if(std::begin(setref), std::end(setref), [&](decltype(*std::begin(setref)) v) { + V a{detail::pair_adaptor::first(v)}; + a = filter_function(a); + return (a == val); + }); + return {(it != std::end(setref)), it}; +} + +// the following suggestion was made by Nikita Ofitserov(@himikof) +// done in templates to prevent compiler warnings on negation of unsigned numbers + +/// Do a check for overflow on signed numbers +template +inline typename std::enable_if::value, T>::type overflowCheck(const T &a, const T &b) { + if((a > 0) == (b > 0)) { + return ((std::numeric_limits::max)() / (std::abs)(a) < (std::abs)(b)); + } + return ((std::numeric_limits::min)() / (std::abs)(a) > -(std::abs)(b)); +} +/// Do a check for overflow on unsigned numbers +template +inline typename std::enable_if::value, T>::type overflowCheck(const T &a, const T &b) { + return ((std::numeric_limits::max)() / a < b); +} + +/// Performs a *= b; if it doesn't cause integer overflow. Returns false otherwise. +template typename std::enable_if::value, bool>::type checked_multiply(T &a, T b) { + if(a == 0 || b == 0 || a == 1 || b == 1) { + a *= b; + return true; + } + if(a == (std::numeric_limits::min)() || b == (std::numeric_limits::min)()) { + return false; + } + if(overflowCheck(a, b)) { + return false; + } + a *= b; + return true; +} + +/// Performs a *= b; if it doesn't equal infinity. Returns false otherwise. +template +typename std::enable_if::value, bool>::type checked_multiply(T &a, T b) { + T c = a * b; + if(std::isinf(c) && !std::isinf(a) && !std::isinf(b)) { + return false; + } + a = c; + return true; +} + +} // namespace detail +/// Verify items are in a set +class IsMember : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction using an initializer list + template + IsMember(std::initializer_list values, Args &&...args) + : IsMember(std::vector(values), std::forward(args)...) {} + + /// This checks to see if an item is in a set (empty function) + template explicit IsMember(T &&set) : IsMember(std::forward(set), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit IsMember(T set, F filter_function) { + + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + + using local_item_t = typename IsMemberType::type; // This will convert bad types to good ones + // (const char * to std::string) + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + // This is the type name for help, it will take the current version of the set contents + desc_function_ = [set]() { return detail::generate_set(detail::smart_deref(set)); }; + + // This is the function that validates + // It stores a copy of the set pointer-like, so shared_ptr will stay alive + func_ = [set, filter_fn](std::string &input) { + using CLI::detail::lexical_cast; + local_item_t b; + if(!lexical_cast(input, b)) { + throw ValidationError(input); // name is added later + } + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(set, b, filter_fn); + if(res.first) { + // Make sure the version in the input string is identical to the one in the set + if(filter_fn) { + input = detail::value_string(detail::pair_adaptor::first(*(res.second))); + } + + // Return empty error string (success) + return std::string{}; + } + + // If you reach this point, the result was not found + return input + " not in " + detail::generate_set(detail::smart_deref(set)); + }; + } + + /// You can pass in as many filter functions as you like, they nest (string only currently) + template + IsMember(T &&set, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&...other) + : IsMember( + std::forward(set), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// definition of the default transformation object +template using TransformPairs = std::vector>; + +/// Translate named items to other or a value set +class Transformer : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction + template + Transformer(std::initializer_list> values, Args &&...args) + : Transformer(TransformPairs(values), std::forward(args)...) {} + + /// direct map of std::string to std::string + template explicit Transformer(T &&mapping) : Transformer(std::forward(mapping), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit Transformer(T mapping, F filter_function) { + + static_assert(detail::pair_adaptor::type>::value, + "mapping must produce value pairs"); + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + using local_item_t = typename IsMemberType::type; // Will convert bad types to good ones + // (const char * to std::string) + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + // This is the type name for help, it will take the current version of the set contents + desc_function_ = [mapping]() { return detail::generate_map(detail::smart_deref(mapping)); }; + + func_ = [mapping, filter_fn](std::string &input) { + using CLI::detail::lexical_cast; + local_item_t b; + if(!lexical_cast(input, b)) { + return std::string(); + // there is no possible way we can match anything in the mapping if we can't convert so just return + } + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(mapping, b, filter_fn); + if(res.first) { + input = detail::value_string(detail::pair_adaptor::second(*res.second)); + } + return std::string{}; + }; + } + + /// You can pass in as many filter functions as you like, they nest + template + Transformer(T &&mapping, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&...other) + : Transformer( + std::forward(mapping), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// translate named items to other or a value set +class CheckedTransformer : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction + template + CheckedTransformer(std::initializer_list> values, Args &&...args) + : CheckedTransformer(TransformPairs(values), std::forward(args)...) {} + + /// direct map of std::string to std::string + template explicit CheckedTransformer(T mapping) : CheckedTransformer(std::move(mapping), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit CheckedTransformer(T mapping, F filter_function) { + + static_assert(detail::pair_adaptor::type>::value, + "mapping must produce value pairs"); + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + using local_item_t = typename IsMemberType::type; // Will convert bad types to good ones + // (const char * to std::string) + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + auto tfunc = [mapping]() { + std::string out("value in "); + out += detail::generate_map(detail::smart_deref(mapping)) + " OR {"; + out += detail::join( + detail::smart_deref(mapping), + [](const iteration_type_t &v) { return detail::to_string(detail::pair_adaptor::second(v)); }, + ","); + out.push_back('}'); + return out; + }; + + desc_function_ = tfunc; + + func_ = [mapping, tfunc, filter_fn](std::string &input) { + using CLI::detail::lexical_cast; + local_item_t b; + bool converted = lexical_cast(input, b); + if(converted) { + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(mapping, b, filter_fn); + if(res.first) { + input = detail::value_string(detail::pair_adaptor::second(*res.second)); + return std::string{}; + } + } + for(const auto &v : detail::smart_deref(mapping)) { + auto output_string = detail::value_string(detail::pair_adaptor::second(v)); + if(output_string == input) { + return std::string(); + } + } + + return "Check " + input + " " + tfunc() + " FAILED"; + }; + } + + /// You can pass in as many filter functions as you like, they nest + template + CheckedTransformer(T &&mapping, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&...other) + : CheckedTransformer( + std::forward(mapping), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// Helper function to allow ignore_case to be passed to IsMember or Transform +inline std::string ignore_case(std::string item) { return detail::to_lower(item); } + +/// Helper function to allow ignore_underscore to be passed to IsMember or Transform +inline std::string ignore_underscore(std::string item) { return detail::remove_underscore(item); } + +/// Helper function to allow checks to ignore spaces to be passed to IsMember or Transform +inline std::string ignore_space(std::string item) { + item.erase(std::remove(std::begin(item), std::end(item), ' '), std::end(item)); + item.erase(std::remove(std::begin(item), std::end(item), '\t'), std::end(item)); + return item; +} + +/// Multiply a number by a factor using given mapping. +/// Can be used to write transforms for SIZE or DURATION inputs. +/// +/// Example: +/// With mapping = `{"b"->1, "kb"->1024, "mb"->1024*1024}` +/// one can recognize inputs like "100", "12kb", "100 MB", +/// that will be automatically transformed to 100, 14448, 104857600. +/// +/// Output number type matches the type in the provided mapping. +/// Therefore, if it is required to interpret real inputs like "0.42 s", +/// the mapping should be of a type or . +class AsNumberWithUnit : public Validator { + public: + /// Adjust AsNumberWithUnit behavior. + /// CASE_SENSITIVE/CASE_INSENSITIVE controls how units are matched. + /// UNIT_OPTIONAL/UNIT_REQUIRED throws ValidationError + /// if UNIT_REQUIRED is set and unit literal is not found. + enum Options { + CASE_SENSITIVE = 0, + CASE_INSENSITIVE = 1, + UNIT_OPTIONAL = 0, + UNIT_REQUIRED = 2, + DEFAULT = CASE_INSENSITIVE | UNIT_OPTIONAL + }; + + template + explicit AsNumberWithUnit(std::map mapping, + Options opts = DEFAULT, + const std::string &unit_name = "UNIT") { + description(generate_description(unit_name, opts)); + validate_mapping(mapping, opts); + + // transform function + func_ = [mapping, opts](std::string &input) -> std::string { + Number num{}; + + detail::rtrim(input); + if(input.empty()) { + throw ValidationError("Input is empty"); + } + + // Find split position between number and prefix + auto unit_begin = input.end(); + while(unit_begin > input.begin() && std::isalpha(*(unit_begin - 1), std::locale())) { + --unit_begin; + } + + std::string unit{unit_begin, input.end()}; + input.resize(static_cast(std::distance(input.begin(), unit_begin))); + detail::trim(input); + + if(opts & UNIT_REQUIRED && unit.empty()) { + throw ValidationError("Missing mandatory unit"); + } + if(opts & CASE_INSENSITIVE) { + unit = detail::to_lower(unit); + } + if(unit.empty()) { + using CLI::detail::lexical_cast; + if(!lexical_cast(input, num)) { + throw ValidationError(std::string("Value ") + input + " could not be converted to " + + detail::type_name()); + } + // No need to modify input if no unit passed + return {}; + } + + // find corresponding factor + auto it = mapping.find(unit); + if(it == mapping.end()) { + throw ValidationError(unit + + " unit not recognized. " + "Allowed values: " + + detail::generate_map(mapping, true)); + } + + if(!input.empty()) { + using CLI::detail::lexical_cast; + bool converted = lexical_cast(input, num); + if(!converted) { + throw ValidationError(std::string("Value ") + input + " could not be converted to " + + detail::type_name()); + } + // perform safe multiplication + bool ok = detail::checked_multiply(num, it->second); + if(!ok) { + throw ValidationError(detail::to_string(num) + " multiplied by " + unit + + " factor would cause number overflow. Use smaller value."); + } + } else { + num = static_cast(it->second); + } + + input = detail::to_string(num); + + return {}; + }; + } + + private: + /// Check that mapping contains valid units. + /// Update mapping for CASE_INSENSITIVE mode. + template static void validate_mapping(std::map &mapping, Options opts) { + for(auto &kv : mapping) { + if(kv.first.empty()) { + throw ValidationError("Unit must not be empty."); + } + if(!detail::isalpha(kv.first)) { + throw ValidationError("Unit must contain only letters."); + } + } + + // make all units lowercase if CASE_INSENSITIVE + if(opts & CASE_INSENSITIVE) { + std::map lower_mapping; + for(auto &kv : mapping) { + auto s = detail::to_lower(kv.first); + if(lower_mapping.count(s)) { + throw ValidationError(std::string("Several matching lowercase unit representations are found: ") + + s); + } + lower_mapping[detail::to_lower(kv.first)] = kv.second; + } + mapping = std::move(lower_mapping); + } + } + + /// Generate description like this: NUMBER [UNIT] + template static std::string generate_description(const std::string &name, Options opts) { + std::stringstream out; + out << detail::type_name() << ' '; + if(opts & UNIT_REQUIRED) { + out << name; + } else { + out << '[' << name << ']'; + } + return out.str(); + } +}; + +inline AsNumberWithUnit::Options operator|(const AsNumberWithUnit::Options &a, const AsNumberWithUnit::Options &b) { + return static_cast(static_cast(a) | static_cast(b)); +} + +/// Converts a human-readable size string (with unit literal) to uin64_t size. +/// Example: +/// "100" => 100 +/// "1 b" => 100 +/// "10Kb" => 10240 // you can configure this to be interpreted as kilobyte (*1000) or kibibyte (*1024) +/// "10 KB" => 10240 +/// "10 kb" => 10240 +/// "10 kib" => 10240 // *i, *ib are always interpreted as *bibyte (*1024) +/// "10kb" => 10240 +/// "2 MB" => 2097152 +/// "2 EiB" => 2^61 // Units up to exibyte are supported +class AsSizeValue : public AsNumberWithUnit { + public: + using result_t = std::uint64_t; + + /// If kb_is_1000 is true, + /// interpret 'kb', 'k' as 1000 and 'kib', 'ki' as 1024 + /// (same applies to higher order units as well). + /// Otherwise, interpret all literals as factors of 1024. + /// The first option is formally correct, but + /// the second interpretation is more wide-spread + /// (see https://en.wikipedia.org/wiki/Binary_prefix). + explicit AsSizeValue(bool kb_is_1000); + + private: + /// Get mapping + static std::map init_mapping(bool kb_is_1000); + + /// Cache calculated mapping + static std::map get_mapping(bool kb_is_1000); +}; + +namespace detail { +/// Split a string into a program name and command line arguments +/// the string is assumed to contain a file name followed by other arguments +/// the return value contains is a pair with the first argument containing the program name and the second +/// everything else. +CLI11_INLINE std::pair split_program_name(std::string commandline); + +} // namespace detail +/// @} + + + + +CLI11_INLINE std::string Validator::operator()(std::string &str) const { + std::string retstring; + if(active_) { + if(non_modifying_) { + std::string value = str; + retstring = func_(value); + } else { + retstring = func_(str); + } + } + return retstring; +} + +CLI11_NODISCARD CLI11_INLINE Validator Validator::description(std::string validator_desc) const { + Validator newval(*this); + newval.desc_function_ = [validator_desc]() { return validator_desc; }; + return newval; +} + +CLI11_INLINE Validator Validator::operator&(const Validator &other) const { + Validator newval; + + newval._merge_description(*this, other, " AND "); + + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + const std::function &f2 = other.func_; + + newval.func_ = [f1, f2](std::string &input) { + std::string s1 = f1(input); + std::string s2 = f2(input); + if(!s1.empty() && !s2.empty()) + return std::string("(") + s1 + ") AND (" + s2 + ")"; + return s1 + s2; + }; + + newval.active_ = active_ && other.active_; + newval.application_index_ = application_index_; + return newval; +} + +CLI11_INLINE Validator Validator::operator|(const Validator &other) const { + Validator newval; + + newval._merge_description(*this, other, " OR "); + + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + const std::function &f2 = other.func_; + + newval.func_ = [f1, f2](std::string &input) { + std::string s1 = f1(input); + std::string s2 = f2(input); + if(s1.empty() || s2.empty()) + return std::string(); + + return std::string("(") + s1 + ") OR (" + s2 + ")"; + }; + newval.active_ = active_ && other.active_; + newval.application_index_ = application_index_; + return newval; +} + +CLI11_INLINE Validator Validator::operator!() const { + Validator newval; + const std::function &dfunc1 = desc_function_; + newval.desc_function_ = [dfunc1]() { + auto str = dfunc1(); + return (!str.empty()) ? std::string("NOT ") + str : std::string{}; + }; + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + + newval.func_ = [f1, dfunc1](std::string &test) -> std::string { + std::string s1 = f1(test); + if(s1.empty()) { + return std::string("check ") + dfunc1() + " succeeded improperly"; + } + return std::string{}; + }; + newval.active_ = active_; + newval.application_index_ = application_index_; + return newval; +} + +CLI11_INLINE void +Validator::_merge_description(const Validator &val1, const Validator &val2, const std::string &merger) { + + const std::function &dfunc1 = val1.desc_function_; + const std::function &dfunc2 = val2.desc_function_; + + desc_function_ = [=]() { + std::string f1 = dfunc1(); + std::string f2 = dfunc2(); + if((f1.empty()) || (f2.empty())) { + return f1 + f2; + } + return std::string(1, '(') + f1 + ')' + merger + '(' + f2 + ')'; + }; +} + +namespace detail { + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +CLI11_INLINE path_type check_path(const char *file) noexcept { + std::error_code ec; + auto stat = std::filesystem::status(to_path(file), ec); + if(ec) { + return path_type::nonexistent; + } + switch(stat.type()) { + case std::filesystem::file_type::none: // LCOV_EXCL_LINE + case std::filesystem::file_type::not_found: + return path_type::nonexistent; // LCOV_EXCL_LINE + case std::filesystem::file_type::directory: + return path_type::directory; + case std::filesystem::file_type::symlink: + case std::filesystem::file_type::block: + case std::filesystem::file_type::character: + case std::filesystem::file_type::fifo: + case std::filesystem::file_type::socket: + case std::filesystem::file_type::regular: + case std::filesystem::file_type::unknown: + default: + return path_type::file; + } +} +#else +CLI11_INLINE path_type check_path(const char *file) noexcept { +#if defined(_MSC_VER) + struct __stat64 buffer; + if(_stat64(file, &buffer) == 0) { + return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file; + } +#else + struct stat buffer; + if(stat(file, &buffer) == 0) { + return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file; + } +#endif + return path_type::nonexistent; +} +#endif + +CLI11_INLINE ExistingFileValidator::ExistingFileValidator() : Validator("FILE") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "File does not exist: " + filename; + } + if(path_result == path_type::directory) { + return "File is actually a directory: " + filename; + } + return std::string(); + }; +} + +CLI11_INLINE ExistingDirectoryValidator::ExistingDirectoryValidator() : Validator("DIR") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "Directory does not exist: " + filename; + } + if(path_result == path_type::file) { + return "Directory is actually a file: " + filename; + } + return std::string(); + }; +} + +CLI11_INLINE ExistingPathValidator::ExistingPathValidator() : Validator("PATH(existing)") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "Path does not exist: " + filename; + } + return std::string(); + }; +} + +CLI11_INLINE NonexistentPathValidator::NonexistentPathValidator() : Validator("PATH(non-existing)") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result != path_type::nonexistent) { + return "Path already exists: " + filename; + } + return std::string(); + }; +} + +CLI11_INLINE IPV4Validator::IPV4Validator() : Validator("IPV4") { + func_ = [](std::string &ip_addr) { + auto result = CLI::detail::split(ip_addr, '.'); + if(result.size() != 4) { + return std::string("Invalid IPV4 address must have four parts (") + ip_addr + ')'; + } + int num = 0; + for(const auto &var : result) { + using CLI::detail::lexical_cast; + bool retval = lexical_cast(var, num); + if(!retval) { + return std::string("Failed parsing number (") + var + ')'; + } + if(num < 0 || num > 255) { + return std::string("Each IP number must be between 0 and 255 ") + var; + } + } + return std::string{}; + }; +} + +CLI11_INLINE EscapedStringTransformer::EscapedStringTransformer() { + func_ = [](std::string &str) { + try { + if(str.size() > 1 && (str.front() == '\"' || str.front() == '\'' || str.front() == '`') && + str.front() == str.back()) { + process_quoted_string(str); + } else if(str.find_first_of('\\') != std::string::npos) { + if(detail::is_binary_escaped_string(str)) { + str = detail::extract_binary_string(str); + } else { + str = remove_escaped_characters(str); + } + } + return std::string{}; + } catch(const std::invalid_argument &ia) { + return std::string(ia.what()); + } + }; +} +} // namespace detail + +CLI11_INLINE FileOnDefaultPath::FileOnDefaultPath(std::string default_path, bool enableErrorReturn) + : Validator("FILE") { + func_ = [default_path, enableErrorReturn](std::string &filename) { + auto path_result = detail::check_path(filename.c_str()); + if(path_result == detail::path_type::nonexistent) { + std::string test_file_path = default_path; + if(default_path.back() != '/' && default_path.back() != '\\') { + // Add folder separator + test_file_path += '/'; + } + test_file_path.append(filename); + path_result = detail::check_path(test_file_path.c_str()); + if(path_result == detail::path_type::file) { + filename = test_file_path; + } else { + if(enableErrorReturn) { + return "File does not exist: " + filename; + } + } + } + return std::string{}; + }; +} + +CLI11_INLINE AsSizeValue::AsSizeValue(bool kb_is_1000) : AsNumberWithUnit(get_mapping(kb_is_1000)) { + if(kb_is_1000) { + description("SIZE [b, kb(=1000b), kib(=1024b), ...]"); + } else { + description("SIZE [b, kb(=1024b), ...]"); + } +} + +CLI11_INLINE std::map AsSizeValue::init_mapping(bool kb_is_1000) { + std::map m; + result_t k_factor = kb_is_1000 ? 1000 : 1024; + result_t ki_factor = 1024; + result_t k = 1; + result_t ki = 1; + m["b"] = 1; + for(std::string p : {"k", "m", "g", "t", "p", "e"}) { + k *= k_factor; + ki *= ki_factor; + m[p] = k; + m[p + "b"] = k; + m[p + "i"] = ki; + m[p + "ib"] = ki; + } + return m; +} + +CLI11_INLINE std::map AsSizeValue::get_mapping(bool kb_is_1000) { + if(kb_is_1000) { + static auto m = init_mapping(true); + return m; + } + static auto m = init_mapping(false); + return m; +} + +namespace detail { + +CLI11_INLINE std::pair split_program_name(std::string commandline) { + // try to determine the programName + std::pair vals; + trim(commandline); + auto esp = commandline.find_first_of(' ', 1); + while(detail::check_path(commandline.substr(0, esp).c_str()) != path_type::file) { + esp = commandline.find_first_of(' ', esp + 1); + if(esp == std::string::npos) { + // if we have reached the end and haven't found a valid file just assume the first argument is the + // program name + if(commandline[0] == '"' || commandline[0] == '\'' || commandline[0] == '`') { + bool embeddedQuote = false; + auto keyChar = commandline[0]; + auto end = commandline.find_first_of(keyChar, 1); + while((end != std::string::npos) && (commandline[end - 1] == '\\')) { // deal with escaped quotes + end = commandline.find_first_of(keyChar, end + 1); + embeddedQuote = true; + } + if(end != std::string::npos) { + vals.first = commandline.substr(1, end - 1); + esp = end + 1; + if(embeddedQuote) { + vals.first = find_and_replace(vals.first, std::string("\\") + keyChar, std::string(1, keyChar)); + } + } else { + esp = commandline.find_first_of(' ', 1); + } + } else { + esp = commandline.find_first_of(' ', 1); + } + + break; + } + } + if(vals.first.empty()) { + vals.first = commandline.substr(0, esp); + rtrim(vals.first); + } + + // strip the program name + vals.second = (esp < commandline.length() - 1) ? commandline.substr(esp + 1) : std::string{}; + ltrim(vals.second); + return vals; +} + +} // namespace detail +/// @} + + + + +class Option; +class App; + +/// This enum signifies the type of help requested +/// +/// This is passed in by App; all user classes must accept this as +/// the second argument. + +enum class AppFormatMode { + Normal, ///< The normal, detailed help + All, ///< A fully expanded help + Sub, ///< Used when printed as part of expanded subcommand +}; + +/// This is the minimum requirements to run a formatter. +/// +/// A user can subclass this is if they do not care at all +/// about the structure in CLI::Formatter. +class FormatterBase { + protected: + /// @name Options + ///@{ + + /// The width of the first column + std::size_t column_width_{30}; + + /// @brief The required help printout labels (user changeable) + /// Values are Needs, Excludes, etc. + std::map labels_{}; + + ///@} + /// @name Basic + ///@{ + + public: + FormatterBase() = default; + FormatterBase(const FormatterBase &) = default; + FormatterBase(FormatterBase &&) = default; + FormatterBase &operator=(const FormatterBase &) = default; + FormatterBase &operator=(FormatterBase &&) = default; + + /// Adding a destructor in this form to work around bug in GCC 4.7 + virtual ~FormatterBase() noexcept {} // NOLINT(modernize-use-equals-default) + + /// This is the key method that puts together help + virtual std::string make_help(const App *, std::string, AppFormatMode) const = 0; + + ///@} + /// @name Setters + ///@{ + + /// Set the "REQUIRED" label + void label(std::string key, std::string val) { labels_[key] = val; } + + /// Set the column width + void column_width(std::size_t val) { column_width_ = val; } + + ///@} + /// @name Getters + ///@{ + + /// Get the current value of a name (REQUIRED, etc.) + CLI11_NODISCARD std::string get_label(std::string key) const { + if(labels_.find(key) == labels_.end()) + return key; + return labels_.at(key); + } + + /// Get the current column width + CLI11_NODISCARD std::size_t get_column_width() const { return column_width_; } + + ///@} +}; + +/// This is a specialty override for lambda functions +class FormatterLambda final : public FormatterBase { + using funct_t = std::function; + + /// The lambda to hold and run + funct_t lambda_; + + public: + /// Create a FormatterLambda with a lambda function + explicit FormatterLambda(funct_t funct) : lambda_(std::move(funct)) {} + + /// Adding a destructor (mostly to make GCC 4.7 happy) + ~FormatterLambda() noexcept override {} // NOLINT(modernize-use-equals-default) + + /// This will simply call the lambda function + std::string make_help(const App *app, std::string name, AppFormatMode mode) const override { + return lambda_(app, name, mode); + } +}; + +/// This is the default Formatter for CLI11. It pretty prints help output, and is broken into quite a few +/// overridable methods, to be highly customizable with minimal effort. +class Formatter : public FormatterBase { + public: + Formatter() = default; + Formatter(const Formatter &) = default; + Formatter(Formatter &&) = default; + Formatter &operator=(const Formatter &) = default; + Formatter &operator=(Formatter &&) = default; + + /// @name Overridables + ///@{ + + /// This prints out a group of options with title + /// + CLI11_NODISCARD virtual std::string + make_group(std::string group, bool is_positional, std::vector opts) const; + + /// This prints out just the positionals "group" + virtual std::string make_positionals(const App *app) const; + + /// This prints out all the groups of options + std::string make_groups(const App *app, AppFormatMode mode) const; + + /// This prints out all the subcommands + virtual std::string make_subcommands(const App *app, AppFormatMode mode) const; + + /// This prints out a subcommand + virtual std::string make_subcommand(const App *sub) const; + + /// This prints out a subcommand in help-all + virtual std::string make_expanded(const App *sub) const; + + /// This prints out all the groups of options + virtual std::string make_footer(const App *app) const; + + /// This displays the description line + virtual std::string make_description(const App *app) const; + + /// This displays the usage line + virtual std::string make_usage(const App *app, std::string name) const; + + /// This puts everything together + std::string make_help(const App * /*app*/, std::string, AppFormatMode) const override; + + ///@} + /// @name Options + ///@{ + + /// This prints out an option help line, either positional or optional form + virtual std::string make_option(const Option *opt, bool is_positional) const { + std::stringstream out; + detail::format_help( + out, make_option_name(opt, is_positional) + make_option_opts(opt), make_option_desc(opt), column_width_); + return out.str(); + } + + /// @brief This is the name part of an option, Default: left column + virtual std::string make_option_name(const Option *, bool) const; + + /// @brief This is the options part of the name, Default: combined into left column + virtual std::string make_option_opts(const Option *) const; + + /// @brief This is the description. Default: Right column, on new line if left column too large + virtual std::string make_option_desc(const Option *) const; + + /// @brief This is used to print the name on the USAGE line + virtual std::string make_option_usage(const Option *opt) const; + + ///@} +}; + + + + +using results_t = std::vector; +/// callback function definition +using callback_t = std::function; + +class Option; +class App; + +using Option_p = std::unique_ptr