Skip navigation.
Home
The QNX Community Portal

View topic - Timer waking process

Timer waking process

For discussion of realtime and/or embedded programming.

Timer waking process

Postby molie » Thu Jun 12, 2003 2:21 pm

I want to set a timer from a process and then block the process until the timer expires or a certain interrupt is received.

Any ideas on what is the best way to do this??

Molie
molie
New Member
 
Posts: 5
Joined: Thu Jun 12, 2003 2:19 pm

Postby rgallen » Thu Jun 12, 2003 8:29 pm

QNX has a very rich mechanism for doing this. How best to do it depends on your architecture. Generally, creating a pulse event is the mechanism I favor.

This requires you to initialize a sigevent struct for a pulse, and then create the timer with this sigevent struct.

The beauty of the QNX architecture, is that you can do exactly the same thing for the interrupt. Simply populate another sigevent structure for pulse (different pulse code, so you can differentiate it from the timer expiry), and attach it to an interrupt via the attach event API.

Then you simply program the timer and recieve block. When the timer expires you'll receive a pulse with the pulse code you chose for the timer, and when the interrupt fires, you'll get a pulse with the pulse code you chose for the interrupt. Simple and elegant.

The functions you are interested in:

timer_create()
timer_settime()
InterruptAttachEvent()

Also, the following macro will most likely prove useful:

SIGEV_PULSE_INIT( event, coid, priority, code, value ).

The QNX docs should fill in all the details...
rgallen
QNX Master
 
Posts: 671
Joined: Thu Jul 11, 2002 6:48 pm

Postby drodrigueza » Fri Jun 13, 2003 7:03 am

I give you another idea.

If you want to receive not only pulses from timer, also messages
from other threads or processes, you can create a sigevent to receive pulses and wait for them in your program with MsgReceive.
If rcvid equals 0, you have received a pulse. If not, you have received
a message from another thread or process.

rcvid=MsgReceive(....);

if (rcvid==0) // You get a pulse
{
// Do what you want with the timer
}
else
{
// You receive a message!
}
drodrigueza
Active Member
 
Posts: 92
Joined: Wed Jul 24, 2002 3:22 pm
Location: Madrid, Spain

Postby molie » Fri Jun 13, 2003 11:19 am

I have now used rcvid=MsgReceive(....); to wait for a pulse/message.

This works for my timer and Interrupt but i am having a problem.

I decided to test my code using the Keyboard interrupt.
I am using interruptAttachEvent() to attach a pulse event to the interrupt.
I have my program start, sleep for 5s econds, then attach timer and interrupt events, this ensures enter used to start program is not seen as keyboard interrupt by my program.

When I run the program I wait for the initial sleep to be over. Then I press a key.
I receive my message that the interrupt has been received and the program exits, as expected.
A command prompt is shown and the key which I pressed, eg letter, is displayed.
Then the screen freezes, ie keyboard and mouse don't work, but I can still telnet into the machine.

Any ideas??, I have tried deataching the event from the interrupt, using InterruptDetach(), before exiting my program but this doesn't seem to work.

Cheers
molie
New Member
 
Posts: 5
Joined: Thu Jun 12, 2003 2:19 pm

Postby drodrigueza » Fri Jun 13, 2003 12:33 pm

I am sorry. I have never used InterruptAttach.

I have read you must use ThreadCtl( _NTO_TCTL_IO, 0 ) before using
InterruptAttach.
To use it, you must be root.

To try if your timer works ok, use ClockCyles(), you can know the time
between the pulses you receive.

You can test if you receive messages writing an easy client who ask
your program (just an idea). It can be just a thread in the same process
of your program, so you dont need to know the pid and so on to use
ConnectAttach.

I hope it helps ( I am amateur in QNX, ;))
drodrigueza
Active Member
 
Posts: 92
Joined: Wed Jul 24, 2002 3:22 pm
Location: Madrid, Spain


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 1 guest

cron