26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advanced topics<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

Real Time <strong>Neutrino</strong> Time Activity<br />

11:22:05 11:22:00 Wake up at “now” + 00:00:30 (see below)<br />

11:22:15 11:22:15 Clock gets adjusted as before<br />

11:22:20 11:22:20 Power management turns off CPU<br />

11:22:30 11:22:30 CLOCK_REALTIME wakes up<br />

11:22:35 11:22:35 CLOCK_MONOTONIC wakes up<br />

11:45:07 11:45:07 Power management turns on CPU, and<br />

CLOCK_SOFTTIME wakes up<br />

Using different clock sources<br />

There are a few things to note here:<br />

• We precomputed our wakeup time as “now” plus 30 seconds and used an absolute<br />

timer to wake us up at the computed time. This is different from waking up in 30<br />

seconds using a relative timer.<br />

• Note that for convenience of putting the example on one time-line, we’ve lied a<br />

little bit. If the CLOCK_REALTIME thread did indeed wake up, (and later the same<br />

for CLOCK_MONOTONIC) it would have caused us to exit out of power<br />

management mode at that time, which would then cause CLOCK_SOFTTIME to<br />

wake up.<br />

When CLOCK_SOFTTIME “over-sleeps,” it wakes up as soon as it’s able — it doesn’t<br />

stop “timing” while the CPU is powered down, it’s just not in a position to wake up<br />

until after the CPU powers up. Other than that, CLOCK_SOFTTIME is just like<br />

CLOCK_REALTIME.<br />

To specify one of the different clock source, use a POSIX timing function that accepts<br />

a clock ID. For example:<br />

#include <br />

int<br />

clock_nanosleep (clockid_t clock_id,<br />

int flags,<br />

const struct timespec *rqtp,<br />

struct timespec *rmtp);<br />

The clock_nanosleep() function accepts the clock_id parameter (telling it which clock<br />

source to use), a flag (which determines if the time is relative or absolute), a<br />

“requested sleep time” parameter (rqtp), as well as a pointer to an area where the<br />

function can fill in the amount of time remaining (in the rmtp parameter, which can be<br />

NULL if you don’t care).<br />

162 Chapter 3 • Clocks, Timers, and <strong>Getting</strong> a Kick Every So Often April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!