QNX Momentics Development Suite 6.3.0 SP3 with IDE 4.0

28
QNX Momentics Development Suite 6.3.0 SP3 with IDE 4.0.1 Quickstart Guide: Ten Steps to Your First QNX Program This guide will help you install and configure the QNX Momentics tools and the QNX Neutrino operating system, so you can start developing right away! This guide assumes you’re using the Integrated Development Environment (IDE) 4.0.1. If you aren’t, then: If you’ve installed QNX Momentics 6.3.0 Service Pack 1, but not Service Pack 2 or later, use the SP1 version of this guide. If you’ve installed QNX Momentics 6.3.0 Service Pack 2 or later, use the SP2 version of this guide. 1. Requirements To write programs that run under the QNX Neutrino realtime operating system (RTOS), the first thing you need is the QNX Momentics development suite. You can install it on Windows 2000, Windows XP,Linux, or Solaris, or as a self-hosted QNX Neutrino system. If you don’t have a QNX Momentics CD, you can download an ISO image of QNX Momentics 6.3.0 Service Pack 3 from www.qnx.com/products/eval. The QNX Product Evaluation website. In addition to a development system, you also need a target platform that runs the QNX Neutrino RTOS itself plus all the programs you’re going to develop. Page 1 of 28

Transcript of QNX Momentics Development Suite 6.3.0 SP3 with IDE 4.0

QNX Momentics Development Suite6.3.0 SP3 with IDE 4.0.1

Quickstart Guide: Ten Steps to Your First QNX Program

This guide will help you install and configure the QNX Momentics tools and the QNXNeutrino operating system, so you can start developing right away!

This guide assumes you’re using the Integrated Development Environment (IDE)4.0.1. If you aren’t, then:

• If you’ve installed QNX Momentics 6.3.0 Service Pack 1, but not Service Pack 2 orlater, use the SP1 version of this guide.

• If you’ve installed QNX Momentics 6.3.0 Service Pack 2 or later, use the SP2version of this guide.

1. RequirementsTo write programs that run under the QNX Neutrino realtime operating system(RTOS), the first thing you need is the QNX Momentics development suite. You caninstall it on Windows 2000, Windows XP, Linux, or Solaris, or as a self-hosted QNXNeutrino system.

If you don’t have a QNX Momentics CD, you can download an ISO image of QNXMomentics 6.3.0 Service Pack 3 from www.qnx.com/products/eval.

The QNX Product Evaluation website.

In addition to a development system, you also need a target platform that runs theQNX Neutrino RTOS itself plus all the programs you’re going to develop.

Page 1 of 28

To become familiar with QNX Neutrino, you have several choices:

• You can install QNX Neutrino as an operating system on a normal PC. On its harddisk, it should have a free partition of about 300 MB (if you want to install only theOS and its runtime components) up to 2.5 GB (if you prefer to install thedevelopment environment under QNX Neutrino for all supported processors).

Installing QNX Neutrino won’t damage a Windows operating system that’sinstalled on another partition. You can also boot QNX Neutrino directly from CD,in case you don’t have enough room on your hard disk.

• You can run QNX Neutrino on a reference platform, a reference design made by aCPU vendor (e.g. with a PPC, XScale, or SH4 CPU). You’ll need a QNX BoardSupport Package for your platform. The documentation that comes with each BSPexplains how to install QNX Neutrino on that target system.

• You can run QNX Neutrino as a virtual machine in a VMware session.

Although VMware is a handy way to try QNX Neutrino, you should note that virtualmachines don’t necessarily support hard realtime.

Since QNX Neutrino is designed the same way for all platforms and is used the sameway, for this Quickstart guide we’ll use the PC installation.

If you don’t have a QNX Momentics Neutrino Host CD, you can download it as anISO image from www.qnx.com/products/eval.

Page 2 of 28

2. Installing the QNX Momentics development suiteQNX Momentics contains everything you need to develop programs that run under theQNX Neutrino RTOS: an extensive Integrated Development Environment (IDE),compiler, linker, libraries and other QNX Neutrino components, precompiled for allCPU architectures that QNX Neutrino supports.

Boot your Windows 2000 or XP system and insert the QNX Momentics WindowsHost CD. If the installation doesn’t start automatically, simply run the programqnxSetupWin32.exe on the CD. You will be guided through the installation process.For more information, see the installation note.

Installing the QNX development environment under Windows.

The installation program will ask you for a license key. If you downloaded QNXMomentics as an ISO image, you should have received an email containing the key.Otherwise, you should have received your key when you bought a QNX Momenticsdevelopment seat.

The Installer will ask you which components to install. The default is to installeverything, which we recommend for evaluation, since you don’t know yet what youwill need.

Page 3 of 28

After installing QNX Momentics 6.3.0 SP3, you’ll need to download IDE 4.0.1 fromour website and install it.

After the installation, you’ll find an icon for the QNX Momentics IDE on yourWindows desktop:

along with an HTML file that contains some interesting information about QNXMomentics and QNX Neutrino.

Page 4 of 28

3. Installing the QNX Neutrino RTOSNow insert the QNX Momentics Neutrino Host CD in the drive of your secondmachine and boot from it. At this point, you can choose to start the OS directly fromCD (ideal for initial testing) or install QNX Neutrino onto your hard disk. Pleasechoose the installation to hard disk and follow the onscreen instructions. For moredetails, see the installation note.

During installation, you will be asked if you also want to install the SoftwareDevelopment Kit under Neutrino. If you say yes, the complete QNX Momenticsdevelopment environment (including our Eclipse-based IDE) will also be installed onyour QNX Neutrino system. You can then develop, compile, and directly test on thesame system running QNX Neutrino.

If you want to use IDE 4.0.1 on your QNX Neutrino system, you’ll have to downloadit from our website and install it.

After rebooting, your hardware will automatically be detected. Once you select thegraphics mode, you can log in as root without a password.

Page 5 of 28

Logging into a self-hosted QNX Neutrino system.

You now are sitting in front of a preconfigured, fully featured QNX Neutrino realtimeoperating system including the QNX Photon microGUI windowing system. (Of courseyou can run QNX Neutrino without graphics, too.) Make sure you also install the latestavailable QNX Neutrino Service Pack from the Download Center on our website.

On the right side of the screen, you’ll find an icon bar. From there, open a shell byclicking on Terminal. To see a list of the processes that currently exist in your system,type:

pidin | less

Each process is optional, which means that later in your design, you can removeprocesses to save resources — or you can add other processes to increase the system’sfunctionality. This also applies for graphics, network, or audio; each QNX Neutrinocomponent is a single process that you can load dynamically. Type q to exit the lesscommand.

With the QNX Neutrino installation that you just created, you can easily familiarizeyourself with many QNX capabilities and features. And all this without the need tocreate and configure a boot image yourself!

Page 6 of 28

Lots of features and still capable of hard realtime: a self-hosted QNX Neutrino

system.

Page 7 of 28

4. Networking with QNX NeutrinoNow connect your QNX Neutrino machine (your target) to the network. Yourdevelopment machine should be on the same network. With a DHCP server available,your QNX Neutrino machine will receive an IP address automatically. You can view itusing the ifconfig en0 command:

In the terminal window you can use the command:

ifconfig en0 address

to manually assign an IP address (replacing address with the IP address you wouldlike to assign to your system).

Alternatively, you can use the network configuration tool that comes with the QNXNeutrino installation. You’ll find it under the Configure item on the icon bar on theright side of the screen, or in the Launch menu. Under Devices, you can selectwhether you would like to use DHCP or a manually assigned IP address. UnderNetwork, please enter the IP addresses of the Gateway and DNS:

Page 8 of 28

Using ping IP_address, you now can check that your development machine (host)can reach your QNX Neutrino system (target) on the network:

and your target can reach your host:

Page 9 of 28

If your host machine uses a firewall, you might not be able to ping it from the target.On Windows XP SP2, you might have to enable Allow incoming echo request in theICMP settings; choose Control Panel from the Start menu, then choose SecurityCenter, and then choose the Advanced tab.

If the network doesn’t work properly, you may be using an unsupported network card.For a full list of supported hardware, visitwww.qnx.com/developers/hardware_support. If you have further questionsregarding hardware support, please call your local sales representative.

The full Neutrino installation uses automatic hardware detection to start thecorresponding device drivers. With the command enum-devices -n you can seewhich hardware was detected by the enumerators and which drivers have been startedaccordingly during booting.

Page 10 of 28

5. Creating a program projectStart the QNX Momentics IDE on your development host. The first time you start theIDE, it asks you to choose a workspace, a folder where it can store your projects andother files. The IDE then displays its Welcome page. When you’re ready to start, clickthe Workbench icon:

Now create a QNX C Project: from the File menu, select New→QNX C Project:

In the resulting dialog, give your project a name:

Page 11 of 28

and then click Next. You now need to select a CPU architecture for the binary you’recreating. To do this, go to the Build Variants tab. For a PC as target, choose x86. Forprojects on other processors, select the corresponding CPU type: PPC, SH4, ARM, orMIPS. You can also select compilation with or without debug information; we’ll beusing both later, so make sure the debug and release variants are both checked.

Page 12 of 28

Selecting build variants.

Click Finish. A ready-to-use project structure with a Makefile is created for you,including a small program (“Welcome to the QNX Momentics IDE”), which you willfind in an automatically generated source code file.

The IDE now switches to the C/C++ perspective, which features the navigator, theeditor, and other useful views, areas that display information that’s relevant to the taskat hand:

Page 13 of 28

Page 14 of 28

6. Communicating with QNX NeutrinoYour target system must be able to respond to requests from the developmentenvironment. To make this possible, start the program qconn.

Make sure that you’re running the correct version of qconn. For more information,see the IDE 4.0.1 installation note.

On a PC running QNX Neutrino, you can start qconn from a terminal window:

To access your target system from the IDE, you have to create a Target Project. Openthe System Information Perspective. In the Window menu, select Open Perspective,and then click Other.... Now choose QNX System Information, and then OK.

In the empty Target Navigator view, press the right mouse button and select New QNXTarget... from the context menu:

Now provide a name for your target system and enter its IP address in thecorresponding field:

Page 15 of 28

Click Finish, and then select your new target in the Target Navigator. You will nowsee a list of all the processes in your QNX Neutrino system. The views (the tabs at thetop) provide other information to you. You can find even more useful views in theWindow menu under Show View.

Page 16 of 28

Here you see what’s going on inside your QNX Neutrino system.

Page 17 of 28

7. Compiling and linkingNow switch back to the C/C++ perspective by doing one of the following:

• Choose the C/C++ perspective from the drop-down menu in the upper right of thedisplay:

Or:

• Hold down the Ctrl key, press F8 repeatedly until C/C++ is highlighted in thepop-up menu, and then release both keys:

Or:

• Choose Window→Navigation→Next Perspective and choose C/C++ from thepop-up menu.

Before you compile, you may want to select compilation with or without debuginformation. To do so, right-click the project name in the C/C++ Projects view, andthen choose Properties. Click QNX C/C++ Project, click Build Variants, and thenclick on the small + symbol next to x86. Make sure that both the debug and releasevariants are checked. Click OK; the IDE offers to rebuild the project.

During the creation of the QNX C Project, a QNX-made directory structure withMakefiles was generated. Now to create a binary, please right-click the projectname, and then select Build Project. The compiler and linker will now do their work.

You will find the compiler output in the C-Build output in the Console view, includingany errors (you shouldn’t see any errors, but we’ve added one in the examples below):

Page 18 of 28

However, if errors occur during compiling, you will find the Problems view moreuseful, because it displays the output of the compiler in an interpreted and morereadable fashion than the Console view:

The Editor view also gives you information about an error if you leave the pointer overit:

After the build operation, your binaries will be displayed in the Binaries folder.Physically, they’re located in the CPU directory under o (for object) and o-g (-g forthe debug option passed to the compiler). The IDE automatically created thecorresponding Makefiles.

Page 19 of 28

The QNX library libc.so, which contains many basic functions, is linkeddynamically to your binary by default. If you want to add other libraries later, you cando this under the Project→Properties section, too. From there, click on Linker andchoose Extra Libraries in the Category field:

Click Add, and type the name of the library, without the lib prefix or the extension.For example, to add the math library, libm.so, you just have to type m in the Namefield:

Click OK. The linker will now link the library when you build the project.

Page 20 of 28

8. Preparing to launch the programTo run and debug the newly built program on your target system, you need to create alaunch configuration. It consists of various settings that affect how the program starts(e.g. command-line parameters, environment variables). You enter these once, andthen you can use this collection of settings again and again.

Now create your own launch configuration: from the dropdown menu beside the “bug”icon on the toolbar, select Debug. . . :

A dialog window opens, where you can start existing launch configurations, changethem, or create new ones. On the left, select C/C++ QNX QConn (IP). This type oflaunch configuration is meant for network-based (cross) development with QNXNeutrino running on the target system, using the qconn program. Now click on Newicon to create a new launch configuration:

You will now be presented with many configuration possibilities that all deal withstarting your executable program. Right now, only the Main tab needs your input.Later, however, you should also take a look at what the other tabs have to offer.

Next to the C/C++ Application field, press the Search Project button and chooseyour binary. If you compiled it with debug information, its name includes a suffix of_g. If you compiled it without debug information, its name doesn’t include this suffix.Since we would like to start the Debugger in the next step, please choose the binarywith the debug information. Click OK.

Make your target system is listed under Target Options, and then click Apply — thelaunch configuration is now ready:

Page 21 of 28

Page 22 of 28

9. Starting and debuggingYou should still be in the Launch Configuration dialog. You just created aconfiguration for launching your program, which you now can start in the debugger.To do this, please click Debug.

The IDE now switches to the Debug perspective and transfers your program from yourdevelopment machine across the network to your target QNX Neutrino system, thenstarts it in the debugger. You will see that the debugger stops in the first line of yourprogram. In the Debug view, you’ll see an overview of your process, including the callstack. Using the buttons in the main bar of the Debug view, you can control thedebugger.

The Debug perspective.

When you run or debug your application from the IDE, any input is read from theIDE’s console, and any output goes to it. Once execution has passed the line that calls

Page 23 of 28

printf(), you should see the “Welcome to the Momentics IDE” message in the Consolewindow.

Using the Step Over button, you can jump to the next line of code:

During debugging, you can watch the Variables view on the right, which displays howyour variables change. You can use the Step Into button to let the debugger go into thecode of a function (which, of course, is useful only if you have the source code for thisfunction).

To set a breakpoint, place the mouse pointer over the left border of the source display,press the right mouse button and choose Toggle Breakpoint from the context menu.The breakpoint is shown as a little circle with a check mark, which you can also set orremove while you write your code.

Setting breakpoints.

When the running program hits a breakpoint, it stops in the debugger, and you can, forexample, examine your variables. If you click the Resume button, your programcontinues until it hits the next breakpoint:

To abort program execution, use the Terminate button:

Page 24 of 28

The debugger keeps the project’s files open while the program is running. Be sure toterminate the debug session before you try to rebuild your project, or else the buildwill fail.

After the program has finished running, use the button Remove All TerminatedLaunches to end the debugger and have your binary (which was previouslytransferred) deleted from your target system.

To run your program as a standalone binary (without the debugger), open thedropdown menu beside the Run icon and choose Run. . . :

Then you can use the launch configuration (described in the previous step) to startyour program. Or create a new launch configuration and select the binary withoutdebug information. You can also transfer your binary manually using the SystemInformation Perspective’s Target File System Navigator (Window→Show View) andstart it from the terminal. Mounting a shared network drive is also possible (see theentry for fs-cifs in the QNX Neutrino Utilities Reference).

Page 25 of 28

10. Making the program your ownTo turn the whole thing into your own first QNX program, you can modify and extendthe source code we just created. Try some of our sample programs and copy code fromthem into your project. And, now that you’ve started, you’ll probably want a lot moreinformation, e.g. how to create your own threads, how the QNX Neutrinomessage-passing works, which process-synchronization methods are available, how toget access to I/O areas, or how to build a QNX Neutrino resource manager. But don’tworry: all this is (almost) as simple as the quick start you just experienced!

The IDE includes a number of tutorials to help you get started. ChooseHelp→Welcome from the IDE’s toolbar, and then click the Tutorials icon:

The IDE’s Help system includes the QNX documentation, along with informationabout the Eclipse platform. In the Help menu, click Help Contents:

The Welcome to QNX Momentics guide helps you find out where to look for theinformation you need. We recommend browsing the QNX Neutrino SystemArchitecture guide, the IDE User’s Guide, and the QNX Neutrino Programmer’sGuide.

In the Help window, please choose:

Page 26 of 28

• QNX Momentics Professional Edition for information about QNX Momenticsand the QNX Neutrino RTOS

• IDE 4.0 User’s Guide for information about using the IDE

The links from the QNX Momentics documents to the IDE 4.0 User’s Guide don’tcurrently work.

Be sure to try the Search function! Printed documentation is also available.

Source code examples covering thread creation, usage of mutexes, message-passingand other methods of interprocess communication as well as a QNX resource-managertemplate can be found on our FTP server ftp.qnx.de; just use an FTP client to login as user qnx with the password qnx!neutrino and download the source package.It contains a readme.txt file that explains how to import the source examples intothe QNX Momentics IDE. The source features extensive comments, explaining what

Page 27 of 28

is done there. For every function you are interested in, you also should consult theQNX Neutrino Library Reference.

While you explore the QNX Momentics tools and the QNX Neutrino RTOS, you willprobably have further questions. Please contact your QNX Account Manager, FieldApplication Engineer, or our support department. We want to be with you from thestart, because we are successful only if you are!

2005–2007, QNX Software Systems GmbH & Co. KG. All rights reserved.

Published under license by:

QNX Software Systems International Corporation175 Terence Matthews CrescentKanata, OntarioK2M 1W8CanadaVoice: +1 613 591-0931Fax: +1 613 591-3579Email: [email protected]: http://www.qnx.com/

QNX, Neutrino, Photon, Photon microGUI, Momentics, and “Build a More Reliable World”are trademarks, registered in certain jurisdictions, of QNX Software Systems GmbH & Co. KGand are used under license by QNX Software Systems International Corporation. All othertrademarks belong to their respective owners.

Page 28 of 28