Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help with qnx timer interrupt

926 views
Skip to first unread message

Cheng Chen

unread,
Oct 16, 2013, 4:23:00 AM10/16/13
to
I am now working on qnx 6.5 timer. I want to fire the timer every 500ms to tackle something.

The problem is with the function
ThreadCtl(_NTO_TCTL_IO, 0);
If this function is called, the timer fires every 1ms;
If this function is not called, the interrupt_id returned by InterruptAttachEvent is -1. If the -1 is ignored, the timer fires every 500ms.

Why ? Is the routine right or not ?
Please help me, thanks a lot.

The source code is:

void * WriterThread2(void* arg)
{
printf( "writer thread, thread id: %d\n", pthread_self() );

/**initialize the timer*/


timer_t writer_timer;
struct sigevent timer_event;
//SIGEV_INTR_INIT(&timer_event);
timer_event.sigev_notify = SIGEV_INTR;/** set the timer event to interrrupt*/

struct itimerspec timer_spec;/**setting the timer to fire every 100ms*/
timer_spec.it_interval.tv_sec = 0;
timer_spec.it_interval.tv_nsec = 500000000;
timer_spec.it_value.tv_sec = 0;
timer_spec.it_value.tv_nsec = 500000000;
//
if(0!=timer_create( CLOCK_REALTIME, &timer_event, &writer_timer)) /** create timer*/
{
fprintf(stderr, "create timer error, at file: %s, function: %s, line: %d\n, error info: %s\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno));
return (0);
}

//ThreadCtl(_NTO_TCTL_IO, 0);/** before calling InterruptAttach, the thread must request I/O privilege,for timer interrupt, this should not be executed. why ?*/
int interrupt_id = InterruptAttachEvent(0, &timer_event, 0);/**attach timer interrrupt event*/
// if(-1==interrupt_id)
// {
// fprintf(stderr, "attach timer interrupt event error, at file: %s, function: %s, line: %d\n, error info: %s\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno));
// return (0);
// }

/** set and start the timer */
if(0!=timer_settime(writer_timer, 0, &timer_spec, NULL))/** automatically unmask the timer interrrupt*/
{
fprintf(stderr, "set and start timer error, at file: %s, function: %s, line: %d\n, error info: %s\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno));
return (0);
}


InterruptUnmask(0, interrupt_id);/**unmask the interrupt, this line could be omitted as the timer_settime function automatically unmask the timer interrupt*/

struct timespec current_time;
while(1)
{
InterruptWait(0, NULL);/**wait for timer interrupt*/
clock_gettime(CLOCK_REALTIME, &current_time);
fprintf(stdout, "timer fired, timestamp: %lf\n", current_time.tv_sec+current_time.tv_nsec/1000000000.0);

InterruptUnmask(0, interrupt_id);/**unmask the interrupt*/
}

return( 0 );
}

int main( void )
{

printf("main thread, thread id: %d\n", pthread_self());

pthread_t writer_thread;
if(EOK!=pthread_create( &writer_thread, NULL, &WriterThread2, NULL ))
{
fprintf(stderr, "write lock error, at file: %s, function: %s, line: %d\n, error info: %s\n", __FILE__, __FUNCTION__, __LINE__, strerror(errno));
return (-1);
}

fprintf(stdout, "main thread waiting...\n");

pthread_join(writer_thread, NULL);
printf("writer thread joined, main thread ending...");
return EXIT_SUCCESS;
}

Nicolas

unread,
Oct 18, 2013, 9:06:32 AM10/18/13
to
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.

Which system are you using ?

Nicolas

unread,
Oct 18, 2013, 9:12:20 AM10/18/13
to
However, you should not use SIGEV_INTR with timers.

Cheng Chen

unread,
Oct 21, 2013, 11:12:17 PM10/21/13
to
Hi, Nicolas,
I am using QNX 6.5.0.
thk u

Cheng Chen

unread,
Oct 21, 2013, 11:13:24 PM10/21/13
to
then, what should i use if i want a timer to fire at defined period ?

Nicolas

unread,
Oct 22, 2013, 3:08:45 AM10/22/13
to

Cheng Chen

unread,
Oct 22, 2013, 9:26:35 PM10/22/13
to
I get it, thank u so much.

However, I also want to know whether i can use timer interrupt or not. Or, is there any example ?

Thanks.

Nicolas

unread,
Oct 23, 2013, 5:45:23 AM10/23/13
to
Le 23/10/2013 03:26, Cheng Chen a �crit :
> I get it, thank u so much.
>
> However, I also want to know whether i can use timer interrupt or not. Or, is there any example ?

Why do you want to use interrupts with timers ?

>
> Thanks.
>
> On Tuesday, October 22, 2013 3:08:45 PM UTC+8, Nicolas wrote:
>> Please, read this page :
>>
>> http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Ft%2Ftimer_create.html&resultof=%22timer_create%22
>>
>>
>>
>> Le 22/10/2013 05:13, Cheng Chen a �crit :
>>
>>> then, what should i use if i want a timer to fire at defined period ?
>>
>>>
>>
>>> On Friday, October 18, 2013 9:12:20 PM UTC+8, Nicolas wrote:
>>
>>>> Le 18/10/2013 15:06, Nicolas a �crit :
>>
>>>>
>>
>>>>> Le 16/10/2013 10:23, Cheng Chen a �crit :

Cheng Chen

unread,
Oct 27, 2013, 11:17:05 PM10/27/13
to
For us, we have used interrupts on qnx for other hardware, serial, can etc.
The timer has interrupt id 0. I just want to try if i can use interrupt on timer. Maybe it is just an obsession.
Thank you and sorry for the late reply.

On Wednesday, October 23, 2013 5:45:23 PM UTC+8, Nicolas wrote:
> Le 23/10/2013 03:26, Cheng Chen a �crit :
>
> > I get it, thank u so much.
>
> >
>
> > However, I also want to know whether i can use timer interrupt or not. Or, is there any example ?
>
>
>
> Why do you want to use interrupts with timers ?
>
>
>
> >
>
> > Thanks.
>
> >
>
> > On Tuesday, October 22, 2013 3:08:45 PM UTC+8, Nicolas wrote:
>
> >> Please, read this page :
>
> >>
>
> >> http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Ft%2Ftimer_create.html&resultof=%22timer_create%22
>
> >>
>
> >>
>
> >>
>
> >> Le 22/10/2013 05:13, Cheng Chen a �crit :
>
> >>
>
> >>> then, what should i use if i want a timer to fire at defined period ?
>
> >>
>
> >>>
>
> >>
>
> >>> On Friday, October 18, 2013 9:12:20 PM UTC+8, Nicolas wrote:
>
> >>
>
> >>>> Le 18/10/2013 15:06, Nicolas a �crit :
>
> >>
>
> >>>>
>
> >>
>
> >>>>> Le 16/10/2013 10:23, Cheng Chen a �crit :

Nicolas

unread,
Oct 28, 2013, 4:20:31 AM10/28/13
to
Le 28/10/2013 04:17, Cheng Chen a �crit :
> For us, we have used interrupts on qnx for other hardware, serial, can etc.
> The timer has interrupt id 0. I just want to try if i can use interrupt on timer. Maybe it is just an obsession.
> Thank you and sorry for the late reply.

You can use interrups with hardware. You can also use interrupts with
timers not managed by QNX.
Here, you try to use interrups with QNX timers. This is not the way to
go. Of course, QNX uses interrupts internaly to manage timers.



>
> On Wednesday, October 23, 2013 5:45:23 PM UTC+8, Nicolas wrote:
>> Le 23/10/2013 03:26, Cheng Chen a �crit :
>>
>>> I get it, thank u so much.
>>
>>>
>>
>>> However, I also want to know whether i can use timer interrupt or not. Or, is there any example ?
>>
>>
>>
>> Why do you want to use interrupts with timers ?
>>
>>
>>
>>>
>>
>>> Thanks.
>>
>>>
>>
>>> On Tuesday, October 22, 2013 3:08:45 PM UTC+8, Nicolas wrote:
>>
>>>> Please, read this page :
>>
>>>>
>>
>>>> http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Ft%2Ftimer_create.html&resultof=%22timer_create%22
>>
>>>>
>>
>>>>
>>
>>>>
>>
>>>> Le 22/10/2013 05:13, Cheng Chen a �crit :
>>
>>>>
>>
>>>>> then, what should i use if i want a timer to fire at defined period ?
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> On Friday, October 18, 2013 9:12:20 PM UTC+8, Nicolas wrote:
>>
>>>>
>>
>>>>>> Le 18/10/2013 15:06, Nicolas a �crit :
>>
>>>>
>>
>>>>>>
>>
>>>>
>>
>>>>>>> Le 16/10/2013 10:23, Cheng Chen a �crit :

Cheng Chen

unread,
Nov 10, 2013, 9:01:30 PM11/10/13
to
OK, I got it. Thank you, so much.

On Monday, October 28, 2013 4:20:31 PM UTC+8, Nicolas wrote:
> Le 28/10/2013 04:17, Cheng Chen a �crit :
>
> > For us, we have used interrupts on qnx for other hardware, serial, can etc.
>
> > The timer has interrupt id 0. I just want to try if i can use interrupt on timer. Maybe it is just an obsession.
>
> > Thank you and sorry for the late reply.
>
>
>
> You can use interrups with hardware. You can also use interrupts with
>
> timers not managed by QNX.
>
> Here, you try to use interrups with QNX timers. This is not the way to
>
> go. Of course, QNX uses interrupts internaly to manage timers.
>
>
>
>
>
>
>
> >
>
> > On Wednesday, October 23, 2013 5:45:23 PM UTC+8, Nicolas wrote:
>
> >> Le 23/10/2013 03:26, Cheng Chen a �crit :
>
> >>
>
> >>> I get it, thank u so much.
>
> >>
>
> >>>
>
> >>
>
> >>> However, I also want to know whether i can use timer interrupt or not. Or, is there any example ?
>
> >>
>
> >>
>
> >>
>
> >> Why do you want to use interrupts with timers ?
>
> >>
>
> >>
>
> >>
>
> >>>
>
> >>
>
> >>> Thanks.
>
> >>
>
> >>>
>
> >>
>
> >>> On Tuesday, October 22, 2013 3:08:45 PM UTC+8, Nicolas wrote:
>
> >>
>
> >>>> Please, read this page :
>
> >>
>
> >>>>
>
> >>
>
> >>>> http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Ft%2Ftimer_create.html&resultof=%22timer_create%22
>
> >>
>
> >>>>
>
> >>
>
> >>>>
>
> >>
>
> >>>>
>
> >>
>
> >>>> Le 22/10/2013 05:13, Cheng Chen a �crit :
>
> >>
>
> >>>>
>
> >>
>
> >>>>> then, what should i use if i want a timer to fire at defined period ?
>
> >>
>
> >>>>
>
> >>
>
> >>>>>
>
> >>
>
> >>>>
>
> >>
>
> >>>>> On Friday, October 18, 2013 9:12:20 PM UTC+8, Nicolas wrote:
>
> >>
>
> >>>>
>
> >>
>
> >>>>>> Le 18/10/2013 15:06, Nicolas a �crit :
>
> >>
>
> >>>>
>
> >>
>
> >>>>>>
>
> >>
>
> >>>>
>
> >>
>
> >>>>>>> Le 16/10/2013 10:23, Cheng Chen a �crit :
Message has been deleted

hemanthv...@gmail.com

unread,
Jan 18, 2014, 4:40:31 PM1/18/14
to
On Sunday, 19 January 2014 03:07:21 UTC+5:30, hemanthv...@gmail.com wrote:
> @Cheng Chen : If you are calling a specific task at 500ms - why don't you use sigevent (SIGEV_SIGNAL) in QNX to trigger an event at 500ms ??
So that you can create multiple timer with signal handler.
Message has been deleted
Message has been deleted
0 new messages