Embedded Invasion

Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.
Highlighted

The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ (gcc Method)

1. Introduction

This document is part of The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++. Here, we detail the use of a gcc redistributable to program these controllers. We assume you have followed the previous guide and have downloaded the appropriate gcc distribution for your target and version of VxWorks.

A note on operating system compatibility: gcc compiler 3.3.2 with VxWorks 6.1 distribution uses shell scripting techniques that are not compatible with Windows Vista or Windows 7. Upgrade to LabVIEW Real-Time 2009 or 2010 and use gcc compiler 3.4.4 with VxWorks 6.3 distribution, or use Windows XP.

2. Installing and Configuring gcc with VxWorks Redistributable

2.1 Extract the gcc Redistributable

Extract the gcc redistributable to your hard drive. We suggest using paths without spaces or special characters, i.e. c:\gccdist . You will see the following directory structure:

gccdist.jpg

Figure 2.1a: gcc redistributable extracted.

The docs folder contains documents for using the gcc compiler. The supplemental folder contains example projects and tools to setup environment variables. The WindRiver folder contains the gcc distribution and VxWorks 6.x redistributable.

2.2 Configure Environment Variables Script

gcc is a command-line tool, and projects are compiled with GNU Make. Make requires that tools be available in the command-line path; in addition, VxWorks references a license file that must be stored in an environment variable. These variables are set for each command-line session using a batch script. Before this script is executed the first time, confirm that the script is correctly pointing to the folder where you extracted the gcc distribution. Edit the file supplemental/setup-gcc.bat and verify that the installation location is correct:

gccdistscript.jpg

Figure 2.2a: Confirming the correct location of the gcc distribution in the setup batch file.

This script must be executed for each command-line shell, since environment variables are not stored across sessions. Alternately, you may configure machine-level environment variables through the Windows operating system. See the tutorial, Environment Variables in Windows XP for instructions. View the file supplemental\setup-gcc.bat to see which environment variables are set for your distribution.

3. Compile

3.1 Set Environment Variables

Navigate to the supplemental folder and execute setup-gcc.bat. You may skip this step if you have configured environment variables at you user-account level.

commandWindow.jpg

Figure 3.1a: Configuring the command-line environment for compilation.

Note that the environment variables are stored for this session of the command-line only; closing the command-line window and opening another requires this step be repeated.

3.2 Compile the Example Project

We compile the example project Fib, which exports two library functions for generating Fiboncci numbers. The source for fib.c is shown below:

#include <math.h>
#include <types/vxTypes.h>

/* Binet's formula for the nth element of the Fibonacci sequence */
#define goldenRatio ((1 + sqrt(5)) / 2)
extern uint32_t fib(const uint32_t n){
return (pow(goldenRatio, n) - pow(1 - goldenRatio, n)) / sqrt(5);
}

/* Returns the next element of the Fibonacci sequence (stateful) */
extern uint32_t nextFib(void){
static uint32_t F1 = 0;
static uint32_t F2 = 1;
const uint32_t F0 = F1;
F1 = F2;
F2 += F0; /* F[2] = F[1] + F[0] */
return F0;
}

Compile the code by using the provided makefile. Navigate to supplemental\examples\fib\c code\ and type make :

make.jpg

Figure 3.2a: Output of the make command in the Fib project.

The file PPC603GNU\fib.out is the binary library that may be executed on the target. Refer to the top-level document, The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ for instructions on how to upload your binary to the target and execute your code.

3.3 Customizing the Makefile

The provided template makefile should be customized for your project, specifically the .out file generated needs to be associated with the top-level source file for your library. See the comments in the makefile for more detail. In short, you should change the first line of the makefile to match the name of the top-level .c or .cpp file:

# Specific to this library; expects NAME.c or NAME.cpp, and produces NAME.out

LIBRARY = myLibrary

4. Debugging with the VxWorks Kernel Shell

4.1 Disable the CPU Exception Handler

Instructions for disabling the CPU Exception Handler are found in the top-level guide, The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++.

4.2 Shell Debugging

The VxWorks Kernel Shell can print debug statements compiled into the library, and can set breakpoints at functional scope. Consult VxWorks documentation for more details. Visit the references in the top-level document for a walkthrough of debugging using the VxWorks Kernel Shell.

0 Kudos
Message 1 of 5
(11,731 Views)
4 REPLIES

Re: The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ (gcc Method)

Thanks for the article! You helped me a lot

0 Kudos
Message 2 of 5
(2,195 Views)

Re: The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ (gcc Method)

Yes, the makefiles in other NI links did not work, but this one did the job. Thanks a lot..

0 Kudos
Message 3 of 5
(2,195 Views)

Re: The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ (gcc Method)

Yes, my bad - in the batch file, rename the directory "supp" to "supplemental" and it should work.

0 Kudos
Message 4 of 5
(2,195 Views)

Re: The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ (gcc Method)

I doubt if its because of different directory folder. I tried now, it did not work. Apparently the makefiles themselves were different in the download files given in NI links like http://www.ni.com/white-paper/5694/en/ and the one here. Earlier, when I had tried those downloaded files in my Windows 8 OS, the execution had stopped abruptly, but may be once in, say 15 - 20 times, it would successfully give results.

0 Kudos
Message 5 of 5
(2,195 Views)
Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.