Building a C/C++ Application

FPGA Interface C API Help

Edition Date: August 2014

Part Number: 372928H-01

»View Product Info
Download Help (Windows Only)

Creating a Project

Use your development tools to create a project or makefile that includes the two header files and the source file. Add a new source file to the project or makefile. In the new source file, use #include to include the generated .h header file. The generated .h header file uses #include to include NiFpga.h.

Note Note  The Examples directory contains examples of project files and makefiles for different operating systems.
Note Note  If you are developing an application for an NI Linux Real-Time target, use the C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition 2013 or later. For information about the development tools, go to and enter the Info Code EclipseIDE.
Note Note  If you are developing an application for a VxWorks target, refer to the NI tutorials The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ and Developing Shared Libraries for the cRIO-901x and Other VxWorks Targets.
Note Note  If you are developing an application for an R Series device, refer to the NI tutorial Building a R Series FPGA Interface Host Application in C.

Writing C/C++ Code Using FPGA Interface C API Functions

Write your code using the functions described in the API Reference book of this help file. All C/C++ applications must call the required functions. In order to interact with FPGA VIs, your application must call a session function to open an FPGA session. From there, call other functions in NiFpga.h to read and write to controls and indicators, use interrupts, or use other C/C++ functions.

Refer to the installed examples to see how to use C API functions.

Developing and Maintaining the C/C++ Application

The constants in the generated header file are tied to the specific bitfile used to generate them. If you modify the FPGA VI, you must recompile the VI, regenerate the C API, and rebuild any C/C++ application that used the original C API. This is because the register offsets for controls and indicators may have changed unexpectedly. If you do not regenerate and rebuild, and instead try to use a new bitfile with an older application, you will get the NiFpga_Status_SignatureMismatch error, because the signature of the bitfile does not match the signature passed to the NiFpga_Open function.

The names of generated constants can change if you rename your FPGA VI or any of the controls, indicators, or FIFOs in it. If you change only the name of the FPGA VI, you can match the previous name by using a custom prefix when you regenerate the C API. If you do not rename anything, you should be able to rebuild your C/C++ application without further modification.

Tip Tip  To avoid having to recompile your entire C/C++ application every time you regenerate the C API, consider creating a shared library (.dll, .out, or .so, depending on your operating system) containing all your C API function calls. A shared library can abstract lower-level FPGA calls to higher-level ones, so that you do not have to rebuild your main application (.exe, .dll, or .out) every time you rebuild the shared library. Additionally, you can make field updates to your C/C++ application, wherein you deploy a new .lvbitx and shared library without having to update the entire application.


Not Helpful