myRIO C library The T1 target computer, the NI myRIO, has an associated C library that is included in the D1 VM distribution workspace under the C Support for myRIO directory. This contains several helpful functions and data types in files under source for interacting with myRIO I/O. For speed, nearly all of the I/O is handled by the FPGA.Target system!computer!field-programmable gate array (FPGA) The FPGA comes preconfigured with a "personality" (i.e., a bitstream configuration file) that defines how C programs running on the microprocessor (i.e., the programs we write) can access the I/O.Target system!computer!input/output (I/O) Interfacing with the I/O through the FPGA comprises the majority of the myRIO's C library.
Of special importance is the header file MyRio.h,MyRio.h which we will include in each program written for the myRIO: #include "MyRio.h". This header file includes MyRio1900.hMyRio1900.h, which in turn includes NiFpga.hNiFpga.h, which declares the primary I/O data types and functions. Whenever we want to open a myRIO FPGA session, we call
NiFpga_Status status; // declare status type
status = MyRio_Open(); // open myRIO FPGA session The NiFpga_Status type is defined in the NiFpga.h header file with
typedef int32_t NiFpga_Status; The C facility typedeftypedef creates a new data type (e.g., int, double) in terms of some other data type. In this sense, it is more of an alias than a proper new data type. In the typedef code given previously, NiFpga_StatusNiFpga_Status is defined to be synonymous with the built-in C type int32_t,C programming language!fixed-width integer types a fixed-width integer of width 32 bits.1 A value of 0 indicates proper status, negative integers correspond to error codes, and positive integers are warnings.
MyRio_Open() The MyRio_Open() function's prototype is declared in MyRio.h as follows:
NiFpga_Status MyRio_Open();Its function is to open a communication session between the microprocessor and the FPGA. This must be called before any other FPGA function.
As we have already mentioned, an NiFpga_Status of 0 indicates the successful opening of a session. The constant NiFpga_Status_SuccessNiFpga_Status_Success is the name for this. There are several other NiFpga_Statuses defined in NiFpga.h, like the error status NiFpga_Status_MemoryFull, which has integer value -52000.
It is important to test the status after calling MyRio_Open(). In MyRio.h, the function MyRio_IsNotSuccess()MyRio_IsNotSuccess() is defined. It accepts an argument of type NiFpga_Status and returns another custom type, NiFpga_Bool,NiFpga_Bool defined as
typedef uint8_t NiFpga_Bool; This is the C unsigned eight-bit integer type and can take on the value NiFpga_FalseNiFpga_False (0) or NiFpga_TrueNiFpga_True (1). Assigning names to logical true and false is common practice in C, which contents itself with 0 and 1 to serve this purpose. Testing for the successful opening of an FPGA session, then, is a matter of
status = MyRio_Open(); // open myRIO FPGA session
if (MyRio_IsNotSuccess(status)) { // test if sess. opened successfully
return status; // if not, return error/warning code
}Placing this in a main() function attempts to open an FPGA session, but if it is not successful, the execution will terminate and return an error code. Given that I/O is necessary for virtually all interesting programming of the myRIO, these statements should appear in all main() programs that we write. MyRio_Open()
MyRio_Close() An open FPGA session should be closed before the end of main(). The session can be closed with
status = MyRio_Close(); // close myRIO FPGA sessionAgain, a nonzero returned status is an error code or warning.
MyRio_Close()
Of course, after we open a session and before we close it, we will want to actually interact with the myRIO I/O through the FPGA. In the lab exercises that follow, we will do just that!
csupport6, fpgaPersonality6
myRIO C library
A fixed-width integer differs from an int in that the width of int depends on the compiler.↩︎