Hi folks,
some questions about waiting in RTLinux.
I have an application using the old evoC library for evolutionary
computation combined with communication with a external machine via
RS232 and realtime sampling of an incremental rotary encoder.
Sometimes the machine needs to handled with care and I have to wait for
its answer. So I tried to use simple sleep and usleep calls and found
they not working in the fuction called by evo(), the main part of
evolutionary computing. In ´main´ all sleep and usleep calls work - in
´quality´, the mentioned function called by evo again and again, it
doesnt.
Select works neither.
Some stuff leads sleep to an immediate return without have sleeped.
printf("return_value: %d", sleep(2));
-> "0" in the terminal when called in main
-> "20" in the terminal when called in quality
I have no handler, exepted for SIGIO and CTRL-C, which could catch an
timer Signal at all and this handlers do not.
So I tried to do an quick hack and used my RT Module as an timer. I
added an case TIMER_SET to the handler and this code calls:
case TIMER_SET:
timer_intervall = msg.value;
printk("(IGR-Timer Set) Timer soll in so vielen nsec feuern (ueberg)
%d %ld\n", timer_intervall, (gethrtime() + NSECS_PER_SEC *
timer_intervall));
//pthread_make_periodic_np(timertask, rt_get_time() + NSECS_PER_SEC *
timer_intervall, 100000);
//pthread_make_periodic_np(timertask, gethrtime() + NSECS_PER_SEC *
timer_intervall, 100000);
pthread_make_periodic_np(timertask, clock_gethrtime() +
timer_intervall, 100000);
break;
The init_module got an new task to initialize:
//Timer Task
pthread_attr_init(&attr_timer);
sched_param_timer.sched_priority = 3;
pthread_attr_setschedparam(&attr_timer, &sched_param_timer);
pthread_create(&timertask, &attr, eieruhr, (void *)1);
//pthread_setfp_np(timertask,1);
And the new task was made public with:
void *eieruhr(void *t)
{
int timer_dummy_data, timer_hilfe;
pthread_wait_np();
timer_hilfe = 0x00ff;
timer_dummy_data = 0x30;
if (rtf_put(10, (char *) &timer_dummy_data, 2) < 0)
{
printk("konnte Dummy Data des Timers nicht loswerden");
rtf_put(9, (char *) &timer_hilfe, sizeof(timer_hilfe));
}
printk("(Eieruhr) es ist jetzt: %ld\n", clock_gethrtime() );
pthread_exit(0);
//pthread_wait_np();
} //void eieruhr
The intention is to create an task after request in the handler which
lives only one period - killed after its work is done.
The Task should start some useconds after now - the wished delay - write
some sensless stuff to a rtfifo (the application waits for this) and at
last kill itself.
But this doesnt work propper too.
Will I have to call pthread_wait_np() once in the entry section of the
thread ?
What is the cleanest way to solve the given problem - making a timer in
the module for some useconds?
What are the examples for that?
What could be the reason for the misbehaviour of sleep, usleep and
select in a function?
thanks in advance
--jens
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/