Building C/C++ Applications for NI Linux Real-Time


This tutorial is part of a series that describes software architectures for targeting NI Linux Real-Time hardware. Consider reading Choosing a Software Architecture for Programming NI Linux Real-Time Applications to learn about real-time concepts and design patterns. Continue reading to learn about the steps necessary to start writing an NI Linux Real-Time application in C/C++ and using the LabVIEW FPGA Module.


With NI Linux Real-Time, you can develop, debug, and deploy applications to the open embedded processor written entirely in C or C++ using the development environment of your choice while gaining the benefits of LabVIEW for programming the FPGA. The FPGA Interface C API provides a communication layer between the FPGA and real-time application for I/O control and data streaming. This offers an interface for accessing FPGA controls, indicators, DMA FIFOs, interrupts, and arrays. 

Figure 1: Use C/C++ to develop your NI Linux Real-Time application, LabVIEW FPGA to design custom FPGA personalities, and the FPGA C Interface API for communication between the two.

Introduction to NI Linux Real-Time

Over the last decade, NI has supported several real-time operating systems (RTOSs) with the LabVIEW Real-Time Module. However, none of them received the level of in-house R&D investment, external collaboration, and market reception that NI Linux Real-Time represents. Before getting started with your real-time software development, it is valuable to understand the background, benefits, and performance considerations behind NI Linux Real-Time.

Because of its open-source and community-developed nature, Linux has developed a strong presence in the embedded system design field. Its ubiquity is based off the diverse IP and applications available both within proprietary repositories and on the web. Historically, however, most embedded Linux solutions lacked the reliability and determinism that an RTOS offers; this meant that they were unsuitable for executing event response, closed-loop control, and embedded monitoring applications. NI Linux Real-Time brings together the real-time and Linux worlds, giving you the ability to take advantage of the vast ecosystem of in-house and public Linux IP in your real-time embedded systems. To gain further insight about this unique convergence between real-time and Linux, see the Introduction to NI Linux Real-Time.

If you are already proficient in Linux and interested in learning how to use functionality like Linux shell commands, file transfer over FTP, or command line execution on NI targets, read Under the Hood of NI Linux Real-Time. NI also maintains an active Community page where NI Linux Real-Time developers exchange example code, upload tutorials, and ask questions about a variety of topics.

C/C++ Toolchain

To target NI Linux Real-Time in C/C++, you need a cross-compiler and an integrated development environment (IDE). NI provides extensive documentation based on GNU C & C++ Compile Tools as well as Visual Studio Code you can use to create your own toolchain. To illustrate the steps for choosing a toolchain and to provide you with a proven set of tools, the documentation you provides background information on cross-compiling as well as information about a number of other topics. 

FPGA Design

With the upfront choices of real-time software architecture and development tools resolved, many developers choose to start designing their embedded system at the I/O level. For NI embedded hardware, I/O ports are routed through FPGAs, or silicon chips whose gates can be reconfigured in software. Because the chip’s configuration is a physical manifestation of your software design, it requires no operating system to execute; this means the FPGA delivers the highest degree of reliability and fastest response time in your system.

Describe FPGA functionality graphically with LabVIEW FPGA

Figure 2: Describe FPGA functionality graphically with LabVIEW FPGA.

Depending on your application needs, you may want to route I/O straight through the FPGA to the real-time processor or incorporate custom timing, control, and signal processing algorithms at the FPGA level. You can also use third-party IP from Xilinx or the NI community in your FPGA code. Whichever design you choose, the LabVIEW FPGA Module is the method with which you target the FPGA in your NI hardware. Unlike traditional hardware description languages like VHDL or Verilog, LabVIEW FPGA gives you the ability to describe the FPGA functionality graphically; this complements the parallel nature of FPGA processors. 

»View Getting Started With LabVIEW FPGA for an introduction to various functions

Communication Layer: FPGA Interface C API

After you have defined your target’s FPGA personality, you need a way to communicate with it from your real-time application written in C/C++. The FPGA Interface C API is the tool that provides this link. It supports communication between the real-time host application and FPGA via variables that represent controls and indicators on the LabVIEW FPGA VI and through DMA FIFOs.

The FPGA Interface C API generates C header files based on the LabVIEW FPGA bitfile; you can then pull these generated files into your C project to interface with the FPGA registers. The tool must be downloaded separately from and includes extensive documentation.

Next Steps


The registered trademark Linux® is used pursuant to a sublicense from LMI, the exclusive licensee of Linus Torvalds, owner of the mark on a worldwide basis.