Discussion:
help with qnx timer interrupt
(too old to reply)
Cheng Chen
2013-10-16 08:23:00 UTC
Permalink
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
2013-10-18 13:06:32 UTC
Permalink
Post by Cheng Chen
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.
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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.

Which system are you using ?
Nicolas
2013-10-18 13:12:20 UTC
Permalink
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Cheng Chen
2013-10-22 03:13:24 UTC
Permalink
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Nicolas
2013-10-22 07:08:45 UTC
Permalink
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Cheng Chen
2013-10-23 01:26:35 UTC
Permalink
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.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Nicolas
2013-10-23 09:45:23 UTC
Permalink
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Cheng Chen
2013-10-28 03:17:05 UTC
Permalink
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.
Post by Nicolas
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Nicolas
2013-10-28 08:20:31 UTC
Permalink
Post by Cheng Chen
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.
Post by Cheng Chen
Post by Nicolas
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
Cheng Chen
2013-11-11 02:01:30 UTC
Permalink
OK, I got it. Thank you, so much.
Post by Nicolas
Post by Cheng Chen
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.
Post by Cheng Chen
Post by Nicolas
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
h***@gmail.com
2014-01-18 21:37:21 UTC
Permalink
Post by Cheng Chen
OK, I got it. Thank you, so much.
Post by Nicolas
Post by Cheng Chen
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.
Post by Cheng Chen
Post by Nicolas
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
@Cheng Chen : If you are calling a specific task at 500ms - why don't you use sigevent in QNX to trigger an event at 500ms ??
h***@gmail.com
2014-01-18 21:40:31 UTC
Permalink
Post by Cheng Chen
OK, I got it. Thank you, so much.
Post by Nicolas
Post by Cheng Chen
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.
Post by Cheng Chen
Post by Nicolas
Post by Cheng Chen
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 ?
Post by Cheng Chen
Thanks.
Post by Nicolas
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
Post by Cheng Chen
then, what should i use if i want a timer to fire at defined period ?
Post by Nicolas
Post by Nicolas
Post by Cheng Chen
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.
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*/
{
%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;
}
On my system, your example is working perfectly when
"ThreadCtl(_NTO_TCTL_IO, 0);" is called.
Which system are you using ?
However, you should not use SIGEV_INTR with timers.
@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.
s***@gmail.com
2018-11-12 15:01:39 UTC
Permalink
/*
scriptname: timer_code.c
author: Kurt Stewart
purpose: assignment 3 pt2
description:
adapted from example code from timer_create() qnx documentation the following code has two threads
that wait on monotonic timer interrupts

*/



#include <stdio.h>
#include <time.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>

#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL
#define Other _PULSE_CODE_MAXAVAIL

static void *myfunction( void *args );
static void *myfunction2( void *args );

typedef union {
struct _pulse pulse;
/* your other message structures would go
here too */
} my_message_t;

int chid; //chan
int rcvid; // receive id
my_message_t msg; // message object

int chid2; //chan
int rcvid2; // receive id
my_message_t msg2; // message object


main()
{
struct sigevent event; //create signal event struct
struct itimerspec itime; //create timer struct
timer_t timer_id; //timer object


int result;
// Create Channel
chid = ChannelCreate(0);
SIGEV_INTR_INIT(&event); //Add interrupt ability to the signal event
InterruptAttachEvent(10,&event,0); // attach the IRQ10 with the signal event interrupt with no flag
//event.sigev_intr_init()
event.sigev_notify = SIGEV_PULSE; //the notification of the signal event is pulse type
event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid,_NTO_SIDE_CHANNEL, 0); //the channel on which the signal will be listening is the created channel
event.sigev_priority = getprio(0); //priority of 0
event.sigev_code = MY_PULSE_CODE; //the code that executes upon the signal event is MY_PULSE_CODE
timer_create(CLOCK_MONOTONIC, &event, &timer_id); //create a monotonic timer which signals the event of timerid

itime.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime.it_value.tv_nsec = 500000000;
itime.it_interval.tv_sec = 10;
/* 500 million nsecs = .5 secs */
itime.it_interval.tv_nsec = 500000000;
timer_settime(timer_id, 0, &itime, NULL);


pthread_t tid;
result = pthread_create( &tid, NULL, myfunction, NULL );
//pthread_setschedprio( tid,9 );
//----------------------------------------------------------------------------------------------------
struct sigevent event2; //create signal event struct
struct itimerspec itime2; //create timer struct
timer_t timer_id2; //timer object


int result2;
// Create Channel
chid2 = ChannelCreate(0);
SIGEV_INTR_INIT(&event2); //Add interrupt ability to the signal event
InterruptAttachEvent(9,&event2,0); // attach the IRQ10 with the signal event interrupt with no flag
//event.sigev_intr_init()
event2.sigev_notify = SIGEV_PULSE; //the notification of the signal event is pulse type
event2.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid2,_NTO_SIDE_CHANNEL, 0); //the channel on which the signal will be listening is the created channel
event2.sigev_priority = getprio(0); //priority of 0
event2.sigev_code = MY_PULSE_CODE; //the code that executes upon the signal event is MY_PULSE_CODE
timer_create(CLOCK_MONOTONIC, &event2, &timer_id2); //create a monotonic timer which signals the event of timerid

itime2.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime2.it_value.tv_nsec = 500000000;
itime2.it_interval.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime2.it_interval.tv_nsec = 500000000;
timer_settime(timer_id2, 0, &itime2, NULL);
pthread_t tid2;

result2 = pthread_create( &tid2, NULL, myfunction2, NULL );
//pthread_setschedprio( tid2,9 );

//loop forever
while(1){}
}//end of main

static void *myfunction( void *args ){
while(1){
rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL); //wait for message on the channel
if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our timer\n");
} /* else other pulses ... */
} /* else other messages ... */
}
}

static void *myfunction2( void *args ){
while(1){
rcvid2 = MsgReceive(chid2, &msg2, sizeof(msg2), NULL); //wait for message on the channel
if (rcvid2 == 0) { /* we got a pulse */
if (msg2.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our second timer\n");
} /* else other pulses ... */
} /* else other messages ... */
}
}
s***@gmail.com
2018-11-12 15:02:08 UTC
Permalink
/*
scriptname: timer_code.c
author: Kurt Stewart
purpose: assignment 3 pt2
description:
adapted from example code from timer_create() qnx documentation the following code has two threads
that wait on monotonic timer interrupts

*/



#include <stdio.h>
#include <time.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>

#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL
#define Other _PULSE_CODE_MAXAVAIL

static void *myfunction( void *args );
static void *myfunction2( void *args );

typedef union {
struct _pulse pulse;
/* your other message structures would go
here too */
} my_message_t;

int chid; //chan
int rcvid; // receive id
my_message_t msg; // message object

int chid2; //chan
int rcvid2; // receive id
my_message_t msg2; // message object


main()
{
struct sigevent event; //create signal event struct
struct itimerspec itime; //create timer struct
timer_t timer_id; //timer object


int result;
// Create Channel
chid = ChannelCreate(0);
SIGEV_INTR_INIT(&event); //Add interrupt ability to the signal event
InterruptAttachEvent(10,&event,0); // attach the IRQ10 with the signal event interrupt with no flag
//event.sigev_intr_init()
event.sigev_notify = SIGEV_PULSE; //the notification of the signal event is pulse type
event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid,_NTO_SIDE_CHANNEL, 0); //the channel on which the signal will be listening is the created channel
event.sigev_priority = getprio(0); //priority of 0
event.sigev_code = MY_PULSE_CODE; //the code that executes upon the signal event is MY_PULSE_CODE
timer_create(CLOCK_MONOTONIC, &event, &timer_id); //create a monotonic timer which signals the event of timerid

itime.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime.it_value.tv_nsec = 500000000;
itime.it_interval.tv_sec = 10;
/* 500 million nsecs = .5 secs */
itime.it_interval.tv_nsec = 500000000;
timer_settime(timer_id, 0, &itime, NULL);


pthread_t tid;
result = pthread_create( &tid, NULL, myfunction, NULL );
//pthread_setschedprio( tid,9 );
//----------------------------------------------------------------------------------------------------
struct sigevent event2; //create signal event struct
struct itimerspec itime2; //create timer struct
timer_t timer_id2; //timer object


int result2;
// Create Channel
chid2 = ChannelCreate(0);
SIGEV_INTR_INIT(&event2); //Add interrupt ability to the signal event
InterruptAttachEvent(9,&event2,0); // attach the IRQ10 with the signal event interrupt with no flag
//event.sigev_intr_init()
event2.sigev_notify = SIGEV_PULSE; //the notification of the signal event is pulse type
event2.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid2,_NTO_SIDE_CHANNEL, 0); //the channel on which the signal will be listening is the created channel
event2.sigev_priority = getprio(0); //priority of 0
event2.sigev_code = MY_PULSE_CODE; //the code that executes upon the signal event is MY_PULSE_CODE
timer_create(CLOCK_MONOTONIC, &event2, &timer_id2); //create a monotonic timer which signals the event of timerid

itime2.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime2.it_value.tv_nsec = 500000000;
itime2.it_interval.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime2.it_interval.tv_nsec = 500000000;
timer_settime(timer_id2, 0, &itime2, NULL);
pthread_t tid2;

result2 = pthread_create( &tid2, NULL, myfunction2, NULL );
//pthread_setschedprio( tid2,9 );

//loop forever
while(1){}
}//end of main

static void *myfunction( void *args ){
while(1){
rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL); //wait for message on the channel
if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our timer\n");
} /* else other pulses ... */
} /* else other messages ... */
}
}

static void *myfunction2( void *args ){
while(1){
rcvid2 = MsgReceive(chid2, &msg2, sizeof(msg2), NULL); //wait for message on the channel
if (rcvid2 == 0) { /* we got a pulse */
if (msg2.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our second timer\n");
} /* else other pulses ... */
} /* else other messages ... */
}
}

Cheng Chen
2013-10-22 03:12:17 UTC
Permalink
Hi, Nicolas,
I am using QNX 6.5.0.
thk u
Loading...