InterruptWait timeout using QNX timer ?

Hi,

I am trying to use the QNX Timer functionality to setup and run a
timer which times out my InterruptWait() function. The idea is to set
the timer sigevent structure up so that it delivers a SIGEV_INTR when
timed out. This SIGEV_INTR will deliver an interrupt to the
InterruptWait(), thus forcing it out of its waiting state, and into
the post interrupt, processing phase.

My code section from the timer setup to InterruptWait() is given
below.



// -----------------
// QNX Timeout Setup
// -----------------

SIGEV_INTR_INIT (&timerEvent);

//timerEvent.sigev_notify = SIGEV_INTR;

timer_create(CLOCK_REALTIME, &timerEvent, &timerID);

timeDefine.it_value.tv_sec = 5;
timeDefine.it_value.tv_nsec = 0;

timeDefine.it_interval.tv_sec = 0;
timeDefine.it_interval.tv_nsec = 0;

timer_settime(timerID, 0, &timeDefine, NULL);

// ----------------------
// QNX Timeout Setup Ends
// ----------------------


// --------------------------
// Interrupt Wait and Service
// --------------------------

// Wait for interrupt event

InterruptWait(0,NULL);



What is the logical or programming flaw in this approach?

Thanks
Ninad

Just call TimerTimeout before calling InterruptWait.
Check the return value from InterruptWait; if it is < 0 and
errno has a value of ETIMEDOUT, a timeout has occured.
Almost any call in QNX that can block can be timed out
in this way.

John Nagle

ninadpradhan wrote:

Hi,

I am trying to use the QNX Timer functionality to setup and run a
timer which times out my InterruptWait() function. The idea is to set
the timer sigevent structure up so that it delivers a SIGEV_INTR when
timed out. This SIGEV_INTR will deliver an interrupt to the
InterruptWait(), thus forcing it out of its waiting state, and into
the post interrupt, processing phase.

My code section from the timer setup to InterruptWait() is given
below.



// -----------------
// QNX Timeout Setup
// -----------------

SIGEV_INTR_INIT (&timerEvent);

//timerEvent.sigev_notify = SIGEV_INTR;

timer_create(CLOCK_REALTIME, &timerEvent, &timerID);

timeDefine.it_value.tv_sec = 5;
timeDefine.it_value.tv_nsec = 0;

timeDefine.it_interval.tv_sec = 0;
timeDefine.it_interval.tv_nsec = 0;

timer_settime(timerID, 0, &timeDefine, NULL);

// ----------------------
// QNX Timeout Setup Ends
// ----------------------


// --------------------------
// Interrupt Wait and Service
// --------------------------

// Wait for interrupt event

InterruptWait(0,NULL);



What is the logical or programming flaw in this approach?

Thanks
Ninad

Hi,

Thanks a lot. Using TimerTimeout worked for me. Here is the corrected
code which uses TimerTimeout, which times out InterruptWait() after
10 seconds.

When I try to print the remaining time, after giving an interrupt
before timeout, the remaining time variable still shows zero. Any
reason why this should happen?

Ninad



struct sigevent timerEvent;
uint64_t timeoutSetTime, timeoutRemTime, oneSecond;

// -----------------
// QNX Timeout Setup
// -----------------

SIGEV_INTR_INIT (&timerEvent);


oneSecond = 1000000000;

timeoutSetTime = 10 * oneSecond;

TimerTimeout( CLOCK_REALTIME, _NTO_TIMEOUT_INTR, &timerEvent,
&timeoutSetTime, &timeoutRemTime);

// ----------------------
// QNX Timeout Setup Ends
// ----------------------


// --------------------------
// Interrupt Wait and Service
// --------------------------

// Wait for interrupt event

InterruptWait(0,NULL);

ninadpradhan wrote:

Hi,

Thanks a lot. Using TimerTimeout worked for me. Here is the corrected
code which uses TimerTimeout, which times out InterruptWait() after
10 seconds.

Sounds good.

When I try to print the remaining time, after giving an interrupt
before timeout, the remaining time variable still shows zero. Any
reason why this should happen?

You only get a remaining time value when the waiting system call is
aborted by a signal. There are three basic cases - call completes
normally, call is aborted by the timer, and call is aborted by
some other signal. When a call is aborted by some other signal,
TimerTimeout isn’t involved; the call would have been aborted
by the signal anyway.

Use clock_gettime for the current time if you need to measure
elapsed time.

John Nagle