Issue
138 January 2002
EXPLORING QNX
NEUTRINO
by
Duane Mattern
Start
Installation
Tools Hardware
Examples
What's Missing?
What You Get
Sources & PDF
Examples
Most
likely you’ll be interested in QNX if you are doing real-time
work. So, the first example shows a timer callback function
in a high-priority process. The timer is set to trigger
every 10 ms, and because this is just an example, the
timer callback function copies the time to a buffer. The
buffer is printed to the screen after 50 iterations. Code
segments for the key function calls are shown in Listing
1. As you can see demonstrated in the listing, Pthread
function calls are used to change the process priority
from 10 to 28.
| Listing
1—This code is used to change the priority
of a thread and create and configure a timer. |
The
main thread sits in an idle task until the timer triggers,
and then the timer callback function is run. The results
show a consistent time, but there is a finite resolution
and the timer resolution can be obtained programmatically
using the clock_ getres() function. The x86 result is
999847 ns (about 1 ms). You will have to use a different
approach if you need better timing than this (see Table
2).
| Table
2—Running the timer.c program produces these
results. The program measures the resolution of the
default system timer in QNX Neutrino. The resolution
is approximately 1 ms. |
As
a second example, the code in Listing 2 demonstrates the
functionality of the watchdog timer on the Versalogic
Panther platform. The watchdog timer first must be enabled
in the BIOS. Next, the port must be enabled programmatically.
After enabling the watchdog, the system will restart unless
the watchdog timer is written to within 250 ms. When run,
the example routine in Listing 2 will reboot because the
watchdog timer will time-out.
| Listing
2—Here is a complete C program for
starting the watchdog timer on the VersaLogic Platform.
Assuming that the watchdog timer has been enabled
in the BIOS, running this application will cause the
system to reboot following a watchdog time-out. |
As
a third example, I created two bootable images and then
relocated them to their prospective boot devices, one
on CompactFlash and the other on DiskOnChip. There isn’t
enough space here to go into the details, but I included
code on Circuit Cellar’s ftp site that specifies the steps
used to perform these tasks and how to make a bootable
image.