Introduction to QNX Momentics IDE

This is a brief introduction to start you into the QMX Momentics IDE. It is an Eclipse-based tool for developing QNX applications that will run on the purplebox target systems in the lab. If you are familiar working in Eclipse and using the CDT, you will probably be very comfortable working with Momentics.

The first step is to start up the QNX Momentics IDE. Be patient because this takes a fairly long time to get up and running.
The first time that you start Momentics, you will be asked where to place your workspace. The default puts it on the C: drive which will not work. You must change this to a directory in your Z: drive. Unless you plan on using separate workspaces, you can check the box so you will not get asked again what workspace to use.
Eclipse interface is based on "perspectives". Each perspective presents a particular layout of the IDE screen tailored for a particular activity. If Momentics does not come up in the C/C++ perspective with the C/C++ Projects view in the upper left corner, open this perspective. If it does not appear in the list of perspectives, find it under Other... This will be be perspective that you use for writing your application code.
The first step will be to create a new C project for a "Hello purplebox" program.
Name the project something appropriate. It will be an Application type. You should be able to use the default location.
Momentics will tell you that you have an error, even though you have barely done anything yet. Select the Build Variants tab so that this error can be cleared.
For the work that you will do, you most likely want to be able to debug your application. Select the debug variant for the X86 architecture. You do not need the release variant, and having that variant unchecked saves time when you build your application. By default, Momentics will rebuild all selected variants for an application.
You probably noticed that the default project is a simple "hello world" type of application. In its stock version, it can be built and run. Right click on the project name in the C/C++ Projects view and select Build Project.
When the project is building, you have the option to run the build in the background. If you have other work you can do in Momentics while the build runs, this option will be useful. Most of your projects will be small enough that it probably does not matter too much.
If all goes well, the build should produce no errors in the console window at the lower part of your window. Momentics will parse the build output, and place in the Problems tab any errors and warnings that it detects. You will do your build debugging mostly from the Problems tab.
The next step is to power up the purplebox next to your workstation. Make sure that you have a keyboard and Ethernet cable connected to the top of the purplebox, and a VGA cable attached to the end of a ribbon cable sticking out the side of the purpleboxbox. Turn on the purplebox by plugging the power cable into the purplebox's power supply. Switch to viewing the purplebox monitor by pressing the middle of the three small buttons on the lower right of the monitor. You will see the purplebox bios and QNX startup. The OS startup should end with a login prompt. Switch back to view the development system.
While you are working with the purplebox targets, you will need to restart the target from time to time. The simplest way to do this is to press the fancy yellow reset button on the top of the purplebox. Any alternate approach is to cycle power on the purple box by disconnecting and then reconnecting the AC power cord from the power supply.
Now you will try to download the project to the purplebox and run it. Right click on the project name in the C/C++ Projects view. Select C/C++ QNX Application Dialog ...

Give the configuration an appropriate name. Momentics will make a guess at the Project and C/C++ Application fields. If either of these are incorrect, use the Browse button to find the correct project, and the Search Project... button to find the debug variant of your project.

You will need to specify the target on which to run the project. Press Add New Target... Specify a target name and the hostname of the target. All of the purplebox target systems are named purplebox#, where # is the number of the purplebox. The purplebox will print this during booting, and it is also printed on the white label on top of the purplebox. You should not need to entire the full domain (se.rit.edu). Click Finish to complete the target definition.

In the lower right corner of your screen, you should have a Target Navigator view. If you do not, bring it up by going to the top menu and selecting Window -> Show View -> Target Navigator. Once you defined the target it should appear as a connected target in the navigator view.
Back on the run dialog, select the purplebox target and click Run.

As you may sit at different workstations through the term, you will need to define additional targets. Any of those targets that are turned on will appear in your Target Options window. Make sure that you choose the correct one for the workstation you are at.

After a short period of time for downloading, the application should run on your purplebox, and the generated output will appear in the Console tab at the bottom of the Momentics window.

You now have gone through the very basic workflow for creating and running a QNX application on our purplebox target systems.

Now you will working with QNX's threading system. QNX is a POSIX compliant operating system, so any information that you can find about threading in POSIX would apply to QNX. Each thread starts execution by calling a function that you specify during thread creation. The code at the right defines this function for this exercise. Insert it at the end of your program file. You will need to add includes of pthread.h and unistd.h for this to compile without errors. #define CYCLES 3

void* thread(void* arg) {
    // threadNum is an identifier for our thread and the period of the sleep time
    unsigned int threadNum = *(unsigned int*)arg;

    for(int i = 0; i < CYCLES; i++) {
        // N.B. Anytime that you see sleep within one of your programs, alarm bells
        // should ring in your head looking for a better, and more accurate, way to
        // wait until some point of time in the future. We will talk about better
        // ways to do this later in the course. This is done here simply for
        // expediency and laziness. Don't do it in your own programs.
        sleep(threadNum);

        std::cout << "Thread " << threadNum << " cycled." << std::endl;
    }

    return NULL;

}

In your main function after the hello message, add a loop that creates three threads that start execution at the beginning of the thread function. To create a thread, look up information regarding the usage of the pthread_create function. Use different argument values for each thread that you start.

After the loop that creates the threads, add a second loop that will wait for each thread to terminate. When this loop exits, all three threads should have completed execution. The pthread_join function will be useful here.

Finally, at the end of your main function just before the return statement, add a line which prints out a goodbye message.

Before the end of the class session, run the program and copy the console output into a text file. Place your HelloPurplebox program file and the text file with the console output of your program running into the Introduction to QNX dropbox.


Revision: $Id: Startup.html 49 2009-09-09 00:26:58Z rtembed $