SciSDK Library
SDK for SciCompiler projects
|
The Software Development kit for SciCompiler User Firmware
The SciSDK is a cross-platform library to write custom control and readout software for SciCompiler generated user firmware.
SciCompiler is a Nuclear Instruments (http://www.nuclearinstruments.eu) tool to generate FPGA firmware con NI/Caen OpenHardware FPGA (https://www.caen.it/families/open-fpga-digitizers/)
The SciCompiler convert a block diagram description of the user firmware is a hardware compatible bitstream managing also the readout of the data from the hardware. This library is intended to be used to write the control and readout software for the user firmware and works only with firmware generated by SciCompiler.
Several processing block of SciCompiler does not require any software support. Typically they are the algorithm processing blocks. Other components require to be configured. For example the trigger requires a configurable threshold to adopt the trigger level to the signal, indeed software configurable parameters are required. Other elemets in the diagram, like lists, oscilloscopes, digitizers, histograms produce as output a stream of value rappresenting the result of the measurament indeed they require to be readout.
Scicompiler implements for every readout/processing board a custom I/O bus (readout bus) to set paramenters and perform readout of the data. On one side of the bus are connected all the elements mapped in memory space like registers, oscilloscope, lists, etc...; on the other side, the bus is connected to an interface to the world external to the board like the readout workstation. The physical interface used for the transport of the data it's completely transparent to the user, it can be a network interface, a USB port, an optical link etc... The SciSDK library provides a set of functions to perform the readout of the data from the board and to set the parameters of the processing blocks that are completely indipendent from the physical interface used.
The SciCompiler generate a JSON file that describe the user firmware. The SciSDK library uses this file to detect each Memory Mapped Component (MMC), i.e: registers, oscilloscope, list present in the firmware and use this information perform the readout of the data and to set the parameters of the processing blocks. The JSON file include, for each element, the address of the element in the memory space, the size of the element, the type of the element, the name of the element, the configuration registers addresses and the actual configuration used to build the MMC component (i.e: for the oscilloscope the number of samples). In order to connect a board to the library the user has to provide the JSON file (generated by SciCompiler) and the connection string of the board. The JSON is a full description of the firmware and any further information is not required to the library to readout and configure the elements in the board. Read more on SciCompiler local bus and SciCompiler generated firmware description JSON file
SciCompiler generate readout libraries for the custom firmware starting from the first version of the software. Up to the version 2022.10.0.3 the library was named Legacy SDK. The Legacy SDK is still supported and maintained but the SciSDK is the new library to use for the new firmware generated by SciCompiler. The main difference between the two libraries (SciSDK and Legacy SDK) is the way the library is generated. The Legacy SDK does not use the JSON file to decode the firmware structure. The library was generated by SciCompiler during the compiling process (Generate SDK phase) and all elements of the library were taylored on the firmware structure. For example, if the firmware contain three oscilloscope and one list, the library will contain three functions to readout the oscilloscopes and one function to readout the list. The three oscilloscope functions had three different names (OSCILLOSCOPE_0_ReadData, OSCILLOSCOPE_1_ReadData, OSCILLOSCOPE_2_ReadData) and the list function had a different name (LIST_0_ReadData). The C code generated for each function was different, in function of the configuration of each element. For example if one oscilloscope has 1024 and the others 2048 samples, the function to readout the oscilloscope with 1024 samples will be different from the function to readout the oscilloscope with 2048 samples, because the number of samples is embedded in the C code of the library as well as the base address of the each element. This approach has the advantage to work very well with IntelliSense and all code editor that can parse the C code and provide code completion and syntax highlighting. The disadvantage is that the library must be regenerated every time the firmware is changed. If the user edit the library, he will need to backup the modifications and manually merge the new code and the older one. Sometimes the user must edit the autogenerate code, for example with custom packet where the decode function require to be customized More over, because all elements has a different name is not possible to cycle on the elements of the firmware to readout the data or to configure the elements. This appoach is not very flexible and make the library not very easy to use on large projects with hundreds of elements to be configured and readout. So in the end the Legacy Library has a several function for each element of the firmware: at least there were one function to readout the data and a function to configure each parameter of the MMC element.
For example for the oscilloscope the library has the following functions:
The download of the data was always in raw and the user has to reconstruct the data from the raw data. The reconstruct function was generated by SciCompiler but the user must call the _STATUS, _POSITION, _DOWNLOAD and _RECOSTRUCT functions in the right order to readout the data. The user must also know how to correct allocate the buffers because the size of the buffers is not known in advance.
The approch with the new SciSDK is completely different. We decided to minimize the number of function and demands to the JSON file the description of the firmware structure. The library is no more generated at runtime but it's a library that we provide ready-to-use and indipendend by the firmware. The library can be installed in the system using the setup provided in the release section on github or downloading from CAEN website and installing the SDK. See SciSDK installation for more information. The library can also be compiled in Windows or Linux to generate a dynamic or a static library that can be linked to the user application. See compile SciSDK for more information. Each element in the SciCompiler project is described in the Firmware JSON file. When the library connect a new board, it requires a connection string and the JSON file. The library will parse the JSON file and will create a list of all elements present in the firmware. Multiple etherogenous board can be connected to the same application. The library will create a list of all elements present in the firmware of each board and will create a unique list of all elements present in all the connected boards. Each element (oscilloscope, list, etc) will have a unique path in the list of all elements. To access to any of the parameters of a component or perform the readout the full path of the elements is required to be known
The Path to the element
The path of each element is composed by the following elements
The element if the firmware are divided in three root types:
For example the Oscilloscope0 of the board0 will have the following path for the ReadData endpoint:
The trigger level parameter will have the following path
The register thredhold in the top page of the design will have the following path
while the register threshold in the page "page1" will have the following path
The SciSDK Function Set
The SciSDK library has a set of function to readout and configure parameters. We decided to keep limited the number of function in order to siplify the use of the library. The library has the following function set:
With this very limited number of function is possible to perform all operations. The section Usage of this document will show how to use the library to perform all operations.
A detailed list with function description can be found in the src/SciSDK_DLL.h
The SciSDK is capable to connect to several different devices each one has an indipendent readout library. The SciSDK is a wrapper of the board specific readout library. For example:
Each of these library is itself an SDK for the specific board. They have different functions to access to register, read/write memory, read/write fifo. The SciSDK wrapper all board specific functions and make a common interface to access to the hardware. This allows to connect to different boards at the same time with the same application and with just one library and to use the same function to access to the hardware.
The SciSDK is not just a wrapper for the underlining board specific library. It also has a set of function to readout and configure memory mapped component generated by SciCompiler. The SciSDK include drivers for all memory mapped components generated by the SciCompiler. The driver makes trasparent easy to the user the access to the component to configure and readout the data. The user does not need to know how to access to the hardware to readout the data. The user just need to know the path of the element and the properties of the element to be configured.
The following example shows how to readout the data from the oscilloscope of the board0.
The code above configure the oscilloscope in self trigger mode, set the pregtrigger to 150 samples, disable the decimator on X axe, enable the internal library data decoder and set the acquisition mode to blocking (in means that the library wait for a waveform up to the timeout). All the parameter of the oscilloscope are descibed in the oscilloscope driver documentation Than the library allocate the correct buffer to readout the data. The buffer is allocated using the function SCISDK_AllocateBuffer. The function takes the path of the element and the type of the buffer to allocate (RAW/Decoded). The function use the information in the firmware JSON file to allocate the correct buffer. In the end the library readout the data from the oscilloscope using the function SCISDK_ReadData. The function takes the path of the element and the pointer to the buffer (pre-allocated with SCISDK_AllocateBuffer ) where to store the data. Because the oscilloscope is in blocking mode the function will wait for a waveform up to the timeout. If the timeout is reached the function will return an error (NI_NO_DATA_AVAILABLE).
SciSDK dymanically load the SDK of each specific board. The SDK is a shared library (.so) or a dynamic library (.dll) that is loaded at runtime. It is important to note that the SciSDK needs the specific SDK .so or .dll to be in the same folder of the SciSDK or installed in the system path.
If the library is installed using the installer the SDK and all board specific library are installed in the system folder and in the bin folder of the installation path (See windows and linux installation section) When the libraries are in the system path the SciSDK will automatically load without needing to copy libraries in the executable folder, it the SciSDK is not installed in the system path the library must be copied in the executable folder as well as all the board specific libraries.
This is the file structure of the SciSDK
WINODOWS
When installed in windows these files are copied in c:\openhardware\SciSDK\bin, and both x64 and x86 as well as release and debug version are installed. More over the installer copy these files in the system path (c:\windows\system32) and in the system path (c:\windows\sysWOW64) for x64 and x86 version respectively.
LINUX
in Linux it in necessary to install zmq and sodium library
When installed in linux these files are copied in /usr/local/lib and the installer select the x64 or x86 version depending on the architecture of the system.
Check the release page for the latest version of the library. Execute the installer as administrator and follow the instruction.
At the end of the installation the library will be installed in the system path (c:\windows\system32) and in the system path (c:\windows\sysWOW64) for x64 and x86 version respectively. You will also find:
In order to compile the library from source you need to install Visual Studio 2022 with C++ support. Clone this repository and open the solution file (SciSDK_VC++/SciSDK.sln) in Visual Studio. From build menu select batch build and select the configuration you want to build (x64/Release or x64/Debug), or just right click on the project and select build. The output will be in the folder bin/<arch>/<configuration> (e.g. bin/x64/Release).
Please note that this repository just compile the SciSDK_DLL.dll. In order to compile the board specific library you need to clone the specific repository and compile the library. The list of the repository is the following:
Each one contains the detailed instruction to compile the library.
This library uses autotools. The tool will generate both the static (.a) and the shared library (.so)
In order to install autoconf
We strogly suggest to compile the library in the linuxbuild folder in order to do not generate output file in the main folder
It's very important to make with CPPFLAGS+=-DSCISDK_DLL_EXPORTS flags otherwise the library will be compiled with C++ function names and will be not compatible with C programs
In order to install the library in the os default library folder
library will be installed in /usr/local/lib. Some OS will not export automatically this path in LD_LIBRARY_PATH indeed it is necessary to add it to LD_LIBRARY_PATH
check that /usr/local/lib is in your LD_LIBRARY_PATH.
if not you can add it simply (temporany)
or permanent
add to user profile
add to user bashrc
Compile library to a target directory It is also possible to compile the library and install them in a local folder
Please note that this repository just compile the SciSDK_DLL.dll. In order to compile the board specific library you need to clone the specific repository and compile the library. The list of the repository is the following:
Each one contains the detailed instruction to compile the library.
This is a self contained example that explain how to download compile and install the two libraries in your Linux OS (Ubunto or any Debian), write a small dummy example and test the connection to the DT1260
The following link may change in the time. Check the last version on FTDI site
create test.c file
paste the following code
create a dummy RegisterFile.json
check that /usr/local/lib is in your LD_LIBRARY_PATH.
if not you can add it simply (temporany)
or permanent (you must log out and login again to apply it)
In the bin\x64 folder or bin\Win32 folder you can find the executable file "SciSDK_DLL_Info.exe" that prints the version of the library installed in your system.
The tool will print the path of the library and the version of the library.
Execute this file in the folder you want to use the library (for example the folder where you are compiling your application ) and run it.
It will display the information of the library that will be used by your application.
This tool will also print the board low level library path.
In folder tools/src you can find the source code of the tool "SciSDK_DLL_Info.cpp" that prints the version of the library installed in your system.
g++ SciSDK_DLL_Info.cpp -o scisdk_info -ldl
Execute this file in the folder you want to use the library (for example the folder where you are compiling your application ) and run it.
It will display the information of the library that will be used by your application.
The SciSDK is available as PyPI packet. It requires Python > 3.5 You can simply install it system wide
The Python SciSDK PyPI packet is just a wrapper of the C library. You need to install in your system the SciSDK library (DLL/so) as explained (for Windows) in 4, (for Linux) in 6.2
SciSDK can be used in Java with a wrapper.
To use this wrapper library you must have SciSDK installed on your computer.
SciSDK java wrapper can be included in projects that use different build tools, here is explained how to include JSciSDK in Ant and Maven managed projects:
To use SciSDK in an Ant managed java project you need to:
To use SciSDK in a Maven managed java project you need to:
In a Maven managed project you don't need to include JNA dependency like in a Java with Ant project because it will be automatically included as dependency of SciSDK java wrapper.
To initialize the library use the default SciSDK constructor:
This constructor creates a pointer to the SciSDK native code object instance so when you no longer need to use the SciSDK in your program (for example before the end of the program) free up memory with:
The following example explains how to connect to a dt1260 board.
The following example explains how to set the value of a register:
The following example explains how to read the value of a register:
The following example explains how to allocate buffer for readout:
The following example explains how to read data from the board:
Buffer parameter is the buffer that has been allocated in the previous example
You can find more examples in each component description page and in the examples folder
You can use SciSDK in LabView with a wrapper library
SciSDK can be included in Labview in different ways:
When you're installing SciSDK with the installer you can check the component Labview wrapper library
to install the Labview wrapper library, this will copy the SciSDK labview library inside the user.lib
directory in LabView installation folder. When you restart Labview VIs will appear in functions palette under User Libraries section.
To install SciSDK manually you need to follow this steps:
user.lib
folder (you can find it inside the installation folder of LabView on your computer)SciSDK
(this will be the name used to display the VIs group inside the LabView palette)
To use SciSDK LabView wrapper VIs without adding them to palette you can download the SciSDK LabView wrapper folder and open the library file (SciSDK_Labview.lvlib), now you can drag and drop VIs from the library's window.
To initizialize the library use LV SCISDK Init Lib
VI, this VI will allocate memory for a native library's object instance.
When you no longer need to use the SciSDK in your program (for example before the end of the program) free up memory with LV SCISDK Free Lib
VI:
You can find the labview file for this example here
To attach a board to SciSDK use LV SCISDK ADD BOARD
VI. This VI requires five arguments:
LV SCISDK Init Lib
VI.The VI returns an handle that you'll have to pass to all SciSDK VIs; this handle is a cluster that contains:
When you no longer need to use the board detach it with the VI LV SCISDK Detach Board
.
You can find the labview file for this example here
To set the value of a register you need to use LV SET REGISTER
VI. This VI requires three arguments:
LV SCISDK ADD BOARD
VI.
You can find the labview file for this example here
To get the value of a register you need to use LV GET REGISTER
VI. This VI requires two arguments:
LV SCISDK ADD BOARD
VI.The VI returns the value of the register and the board handle.
You can find the labview file for this example here
To read data from a board you need to use two VIs: one to initialize the component and one to read data, for example:
LV SciSDK INIT OSCILLOSCOPE
VI to initizalize the oscilloscope and the LV SciSDK OSCILLOSCOPE
to read dataLV SciSDK DIGITIZER START
to initialize and start to listen and the LV SciSDK DIGITIZER
to readout data
Also, there are other VIs used to execute other components' commands like LV SciSDK DIGITIZER STOP
or LV SciSDK Spectrum Reset
VIs.
You can find the labview file for this example here
You can find more examples in each component description page and in the examples folder