Skip to content

Commit

Permalink
WR Timing Integration: Initial sample and a bit of documentation (#129)
Browse files Browse the repository at this point in the history
Update readme with with information about building timing dependencies and switch from meson to cmake.

Add a simple UI example on how to get timing messages, which is not yet a GNU Radio Block.
  • Loading branch information
wirew0rm committed Dec 8, 2023
1 parent fe402e9 commit ac6fee3
Show file tree
Hide file tree
Showing 18 changed files with 2,921 additions and 14 deletions.
32 changes: 29 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,52 @@ jobs:
if: matrix.configurations.compiler == 'gcc13' && matrix.cmake-build-type == 'Debug'
uses: SonarSource/sonarcloud-github-c-cpp@v2

- name: "Install timing system dependencies: etherbone"
if: matrix.configurations.compiler != 'emscripten'
shell: bash
run: |
git clone --branch v2.1.3 --depth=1 https://ohwr.org/project/etherbone-core.git
cd etherbone-core/api
touch ChangeLog # add an empty changelog file which is required by autotools
sed -e "s%AC_MSG_ERROR%AC_MSG_NOTICE%g" -i configure.ac
autoreconf -i
./configure
make -j
sudo make install
- name: "Install timing system dependencies: saftlib"
if: matrix.configurations.compiler != 'emscripten'
shell: bash
run: |
sudo apt-get -y install libsigc++-2.0-dev libxslt1-dev libboost-all-dev
git clone --branch v3.0.3 --depth=1 https://github.com/GSI-CS-CO/saftlib.git
cd saftlib
./autogen.sh
./configure
make
sudo make install
- name: Install picoscope libraries
if: matrix.configurations.compiler != 'emscripten'
run: |
# https://www.picotech.com/downloads/linux
wget -O - https://labs.picotech.com/Release.gpg.key|sudo apt-key add -
sudo add-apt-repository 'deb https://labs.picotech.com/rc/picoscope7/debian/ picoscope main'
sudo apt update
sudo apt install -y udev libusb-1.0-0-dev libps3000a libps4000a libps5000a libps6000 libps6000a || true # ignore udev errors in post install because of udev in container
sudo apt install -y udev libusb-1.0-0-dev libps3000a libps4000a libps5000a libps6000 libps6000a libx11-dev libgl1-mesa-dev libsdl2-dev || true # ignore udev errors in post install because of udev in container
- name: Configure CMake
if: matrix.configurations.compiler != 'emscripten'
shell: bash
run: |
cmake -S . -B ../build -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DENABLE_COVERAGE=${{ matrix.configurations.compiler == 'gcc13' && matrix.cmake-build-type == 'Debug'}}
cmake -S . -B ../build -DENABLE_PICOSCOPE=TRUE -DENABLE_TIMING=TRUE -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DENABLE_COVERAGE=${{ matrix.configurations.compiler == 'gcc13' && matrix.cmake-build-type == 'Debug'}}
- name: Configure CMake Emscripten
if: matrix.configurations.compiler == 'emscripten'
shell: bash
run: |
source ~/emsdk/emsdk_env.sh
emcmake cmake -S . -B ../build -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DENABLE_COVERAGE=OFF
emcmake cmake -S . -B ../build -DENABLE_PICOSCOPE=FALSE -DENABLE_TIMING=FALSE -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DENABLE_COVERAGE=OFF
- name: Build
if: matrix.configurations.compiler != 'gcc13' || matrix.cmake-build-type != 'Debug'
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ language.settings.xml

# python venv files
virtualenv/

# cmake build directories
cmake-build-*/
build/
63 changes: 60 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_CXX_STANDARD 23)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)

include(cmake/CMakeRC.cmake)
include(FetchContent)

set(ENABLE_TESTING OFF)
Expand All @@ -20,7 +21,57 @@ FetchContent_Declare(
GIT_TAG bf8388f61103571dee3061a4ef23292a320d9dbf # head as of 2023-08-21
)

FetchContent_MakeAvailable(graph-prototype ut)
if (EMSCRIPTEN)
FetchContent_MakeAvailable(graph-prototype ut)
else ()
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90
)

# Enables 32 bit vertex indices for ImGui
add_compile_definitions("ImDrawIdx=unsigned int")
FetchContent_Declare(
implot
GIT_REPOSITORY https://github.com/epezent/implot.git
GIT_TAG v0.16
)
FetchContent_MakeAvailable(imgui implot graph-prototype ut)

find_package(SDL2 REQUIRED)
find_package(OpenGL REQUIRED COMPONENTS OpenGL)

# imgui and implot are not CMake Projects, so we have to define their targets manually here
add_library(imgui
OBJECT
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
)
target_link_libraries(imgui PUBLIC SDL2::SDL2 OpenGL::GL)
target_compile_options(imgui PRIVATE -w) # imgui does lots of oldstyle casts and pointer arithmethic leading to many warnings
target_include_directories(imgui BEFORE
PUBLIC SYSTEM
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
)

add_library(implot
OBJECT ${implot_SOURCE_DIR}/implot_demo.cpp ${implot_SOURCE_DIR}/implot_items.cpp ${implot_SOURCE_DIR}/implot.cpp
)
target_compile_options(implot PRIVATE -w) # implot does lots of oldstyle casts and pointer arithmethic leading to many warnings
target_include_directories(implot BEFORE
PUBLIC SYSTEM
${implot_SOURCE_DIR}
)
target_link_libraries(implot PUBLIC imgui)
endif ()

add_library(gr-digitizers-options INTERFACE)
include(cmake/CompilerWarnings.cmake)
Expand All @@ -33,15 +84,22 @@ endif()

if(NOT EMSCRIPTEN)
option(ENABLE_PICOSCOPE "Enable PicoScope support" ON)
option(ENABLE_TIMING "Enable TimingReceiver support" ON)
set(PICOSCOPE_PREFIX "/opt/picoscope" CACHE PATH "Picoscope drivers prefix") # TODO use proper find_package
endif()

find_package(PkgConfig REQUIRED)

if(ENABLE_PICOSCOPE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(zlib REQUIRED IMPORTED_TARGET zlib)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)
endif()

if(ENABLE_TIMING AND NOT EMSCRIPTEN)
pkg_check_modules(saftlib REQUIRED IMPORTED_TARGET saftlib)
pkg_check_modules(etherbone REQUIRED IMPORTED_TARGET etherbone)
endif()

option(ENABLE_GR_DIGITIZERS_TESTING "Enable gr-digitizers Test Builds" ON)
if (ENABLE_GR_DIGITIZERS_TESTING AND UNIX AND NOT APPLE)
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
Expand All @@ -66,4 +124,3 @@ if (ENABLE_GR_DIGITIZERS_TESTING AND UNIX AND NOT APPLE)
endif ()

add_subdirectory(blocklib)

15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# gr-digitizers

`gr-digitizers` is a collection of gnuradio blocks for signal processing.
Expand All @@ -15,6 +14,7 @@ In a nutshell, we have three main dependencies:
- [ROOT](https://root.cern/)
- [PicoScope Drivers](https://www.picotech.com/downloads/linux) (optional)
- [LimeSuite](https://github.com/myriadrf/LimeSuite) (optional)
- [etherbone](https://ohwr.org/project/etherbone-core/tree/master/api) and [saftlib](https://github.com/GSI-CS-CO/saftlib) (optional for the timing receiver blocks)

In the following it is assumed that ROOT is installed to `/opt/root`, and the picoscope drivers
to `/opt/picoscope` (which is e.g. done when using the Ubuntu packages).
Expand All @@ -35,15 +35,18 @@ ninja
sudo ninja install
```

### Build etherbone and saftlib
To build and test the timing related dependencies, see the [readme for the timing block](blocklib/timing/README.md)

### Build gr-digitizers

To build gr-digitizers, run:

```shell
$ meson setup builddir . -Dlibpicoscope_prefix=/opt/picoscope -Dlibroot_prefix=/opt/root -Dlimesuite_prefix=/opt/limesuite
$ cd builddir
$ ninja
$ LD_LIBRARY_PATH=/opt/root/lib ninja test # run unit tests, optional
$ cmake -S . -B build -Dlibpicoscope_prefix=/opt/picoscope -Dlibroot_prefix=/opt/root -Dlimesuite_prefix=/opt/limesuite
$ cmake --build build -j
$ cd build
$ LD_LIBRARY_PATH=/opt/root/lib ctest --output-on-failure # run unit tests, optional
$ ninja install
```

Expand All @@ -55,7 +58,7 @@ By default, only unit tests without any hardware dependencies are executed. In o
related tests, execute the below command:

```shell
$ LD_LIBRARY_PATH=/opt/root/lib PICOSCOPE_RUN_TESTS=3000a ninja test
$ LD_LIBRARY_PATH=/opt/root/lib PICOSCOPE_RUN_TESTS=3000a ctest --output-on-failure # run unit tests, optional
```

Running multiple hardware tests together, like `PICOSCOPE_RUN_TESTS=3000a,4000a`, is technically possible
Expand Down
4 changes: 4 additions & 0 deletions blocklib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ add_subdirectory(digitizers)
if (ENABLE_PICOSCOPE)
add_subdirectory(picoscope)
endif ()

if (ENABLE_TIMING)
add_subdirectory(timing)
endif ()
2 changes: 1 addition & 1 deletion blocklib/picoscope/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TODO do not hardcode
add_library(ps4000a SHARED IMPORTED)
add_library(ps4000a SHARED IMPORTED GLOBAL)
set_property(TARGET ps4000a PROPERTY
IMPORTED_LOCATION ${PICOSCOPE_PREFIX}/lib/libps4000a.so)
target_link_libraries(ps4000a INTERFACE PkgConfig::zlib PkgConfig::libusb)
Expand Down
19 changes: 19 additions & 0 deletions blocklib/timing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if (NOT EMSCRIPTEN)
cmrc_add_resource_library(
ui_assets
NAMESPACE
ui_assets
WHENCE
${imgui_SOURCE_DIR}/misc/fonts
${imgui_SOURCE_DIR}/misc/fonts/Roboto-Medium.ttf)

add_library(timing INTERFACE)
target_include_directories(timing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include/)

add_executable(test-timing src/test-timing.cpp)
target_link_libraries(test-timing PRIVATE gr-digitizers-options timing PkgConfig::saftlib PkgConfig::etherbone imgui implot gnuradio-algorithm gnuradio-core ui_assets)
endif ()

if (ENABLE_GR_DIGITIZERS_TESTING)
add_subdirectory(test)
endif ()
73 changes: 73 additions & 0 deletions blocklib/timing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# White-Rabbit based timing blocks and test utilities

This directory contains the timing realated gnuradio blocks along with some testing utilites and setup instructions.

# Dependencies
For actually using the blocks and utilities built by this you will also need actual timing receiver hardware, the
[wishbone kernel module](https://ohwr.org/project/fpga-config-space/tree/realtime_fixes/pcie-wb) has to be loaded and the saftlibd daemon has to be running and configured properly.

```shell
git clone --branch v2.1.3 --depth=1 https://ohwr.org/project/etherbone-core.git
cd etherbone-core/api
./autogen.sh
./configure
make -j
sudo make install
```

```shell
git clone --branch v3.0.3 --depth=1 https://github.com/GSI-CS-CO/saftlib.git
cd saftlib
./autogen.sh
./configure
make -j
sudo make install
```

# Setting up usage with an actual timing card

- build etherbone and saftlib as described above
- build gr-digitizers with `-DENABLE_TIMING=True`
- load the required kernel modules if the card is connected via PCIe: `modprobe pcie_wb`
- verify they are loaded correctly: `lsmod | grep wb`, `dmesg | tail`
- start saftd demon and attach timing card: `saftd tr0:dev/wbm0` (where `dev/wbm0` is the device path of the wishbone device without leading slash)
- if there is no physical timing signal plugged into the card, the card has to be switched to master mode:
- `eb-console /dev/wbm0` and enter `mode master` and hit return. The console should print a message that the timing mode is changed.
- eb-console is included in [bel_projects](https://github.com/GSI-CS-CO/bel_projects).
If you only need the single tool and have installed etherbone on your system by other means you can build only eb-console:
```bash
$ git clone https://github.com/GSI-CS-CO/bel_projects
$ cd bel_projects/tools
$ make EB=/usr/include eb-console # or point the EB variable to whatever prefix you installed etherbone to
$ ./eb-console dev/wbm0 # or dev/ttyUSB0
```
- verify that everything works with saft-ctl:
- ``` bash
$ saft-ctl tr0 -ijkst
saftlib source version : saftlib 3.0.3 (6aab401-dirty): Aug 29 2023 09:50:19
saftlib build info : built by unknown on Jan 1 1980 00:00:00 with localhost running
devices attached on this host : 1
device: /de/gsi/saftlib/tr0, name: tr0, path: dev/wbm0, gatewareVersion : 6.1.2
--gateware version info:
---- Mon Aug 09 08:48:31 CEST 2021
---- fallout-v6.1.2
---- Arria V (5agxma3d4f27i3)
---- CentOS Linux release 7.9.2009 (Core), kernel 3.10.0-1160.36.2.el7.x86_64
---- pexaria5 +db[12] +wrex1
---- Timing Group Jenkins <[email protected]>
---- tsl021.acc.gsi.de
---- pci_control
---- Version 18.1.0 Build 625 09/12/2018 SJ Standard Edition
---- fallout-3847
6.1.2
current temperature (Celsius): 48
WR locked, time: 0x001181787bda0268
receiver free conditions: 255, max (capacity of HW): 0(256), early threshold: 4294967296 ns, latency: 4096 ns
sinks instantiated on this host: 1
/de/gsi/saftlib/tr0/software/_77 (minOffset: -1000000000 ns, maxOffset: 1000000000 ns)
-- actions: 0, delayed: 0, conflict: 0, late: 0, early: 0, overflow: 0 (max signalRate: 10Hz)
-- conditions: 0
```
- snoop on all events: `saft-ctl tr0 snoop 0x0 0x0 0x0` and on another terminal inject an event: `saft-ctl tr0 inject 0x1154000140000000 0x15 1000000` to verify it arrives.
- finally launch `build/blocklib/timing/test-timing` to show the UI

Loading

0 comments on commit ac6fee3

Please sign in to comment.