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++ (Workbench 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 Wind River Workbench to program these controllers.

2. Compiling with Wind River Workbench

We use Wind River Workbench 3.0.1 with VxWorks 6.x configuration. This configuration installs the PowerPC target and the necessary library and header files for VxWorks.

2.1 Configuring a Project

Open Wind River Workbench, and select from the top menu bar, File -> New  -> VxWorks Downloadable Kernel Module Project. A project configuration wizard opens.

Wind River Opening Screen.jpg

Figure 2.1a: Workbench getting started window.

We are building an example application to generate Fibonacci numbers. Enter "fib" for the project name, and select Next. The defaults for the Project Structure, Build Defaults, and Build Support are correct; press Next to advance to the Build Specs dialog. The correct build specification is PPC603gnu (PPC603 instruction set using the GNU toolchain); deselect all build specifications except for PPC603gnu.

Build Spec.jpg

Figure 2.1b: Compile architecture settings..

You may optinally deselect Debug Mode if you do not plan to debug your application. The project settings are now complete; press Finish to view your new project in Workbench.

2.2 Create Source File

To create a new source file, in the Project Explorer view, right click on the "fib" project, and select from the context menu, New -> File. Name the file fib.c. Paste the following code into the editor for fib.c:

#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;
}

Your environment window should resemble ours below:

blinky code.jpg

Figure 2.2a: Environment window for the Fib project.

2.3 Configure Compiler

Open the build properties dialog by right-clicking on your project and selecting Properties. Within the properties dialog, select the Build Properties filter, and then the Build Settings tab. Add the text –mlongcall to the Build Flags textbox.

compilerLongCall.jpg

Figure 2.3a: Compiler tool flag settings, showing the addition of -mlongcall.

Also add the option to the linker tool flags:

mlongCall_linker.jpg

Figure 2.3b: Compiler tool flag settings, showing the addition of -mlongcall.

2.4 Compile

Select from the top menu bar, Project ->  Build All. Workbench compiles your code into an executable library, shown in your project:

Build output file.jpg

Figure 2.4a: Project navigator showing an output binary file for the Fib project.

The file 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 executable to the target and execute your code.

3. Debugging in Wind River Workbench

3.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++.

3.2 Start the Debugging Task

Workbench uses low-level debugging capabilities that are not enabled by default on RIO targets. Debugging is enabled by starting a task from the VxWorks Kernel Shell. Refer to the top-level document, The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ for instructions on how to connect to the VxWorks Kernel Shell.

From the VxWorks Kernel Shell, enter the command debuggingInit. The response should be similar to ours below:

consoleDebuggingInit.jpg

Figure 3.2a: Starting the debugging task.

3.3 Download the Target VxWorks Kernel

Using FTP, download the file ni-rt/system/vxWorks to your computer using BINARY transfer mode. We suggest downloading to a path that does not contain spaces, i.e. c:\target\VxWorks . This file will be referenced when connecting the debugger to the target.

3.4 Create a Workbench Target Connection

Select from the Workbench menu bar, Target -> New Connection .When prompted to select the remote system type, choose Wind River VxWorks 6.x Target Server Connection When and then click Next. Enter the IP address or hostname of your target, and the filesystem location of the VxWorks kernel you downloaded in the previous step, into the Target Server Options dialog and press Finish.

new target connection.jpg

Figure 3.4a: Connecting to the target.

Workbench will automatically connect to the target if possible. The target will appear in a Debug Targets view. Right-click on the target to launch a console to the VxWorks Kernel Shell on the target, which communicates over ethernet instead of serial.

To debug, first connect to all kernel tasks by first right clicking on Kernel Tasks and selecting "Connect All Kernel Tasks". Right click on Kernel Tasks again to select Run or Debug Kernel Task, which will download your library to the target and either execute the library or start a debug session. We refer you to the Wind River Workbench 3.0 User's Guide for instructions on using the Workbench debugger.

0 Kudos
Message 1 of 2
(9,247 Views)
1 REPLY

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

Is there any way to get the latest kernel and service configuration for VxWorks 6.3 on CRIO (9014). Which filesystem(s) are configured?  Is virtual memory running? What caching options are configured?  Basically, is there a way to get the configAll.h?

I ask because our company is evaluating data storage/management options for our RT application, which may include embedded db or custom libraries "under-the-hood" of LabView RT. 

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