The frank example of rtlinux 2.2 does not work. I have added two rtl_printf-s
for debugging purposes:
void *thread_code(void *t)
{
int fifo = (int) t;
int taskno = fifo - 1;
struct my_msg_struct msg;
while (1) {
int ret;
int err;
rtl_printf("Task %d: going to sleep\n", fifo-1); /* extra print */
ret = pthread_wait_np();
rtl_printf("Task %d: woken up\n", fifo-1); /* extra print */
if ((err = rtf_get (taskno + TASK_CONTROL_FIFO_OFFSET, &msg,
sizeof(msg))) == sizeof(msg)) {
rtl_printf("Task %d: executing the \"%d\" command to task %d;
period %d\n", fifo - 1, msg.command, msg.task, msg.period);
switch (msg.command) {
case START_TASK:
pthread_make_periodic_np(pthread_self(),
gethrtime(), msg.period * 1000);
break;
case STOP_TASK:
pthread_suspend_np(pthread_self());
break;
default:
rtl_printf("RTL task: bad command\n");
return 0;
}
}
rtf_put(fifo, data[fifo - 1], 6);
}
return 0;
}
make test produces the following output:
...
Now start the real-time tasks module
Type <return> to continue
Fifo return 1=0 2=0 3=0
Task 0: going to sleep
Task 1: going to sleep
Now start the application
Type <return> to continue
FIFO handler: sending the "1" command to task 0; period 500000
Task 0: woken up
Task 0: executing the "1" command to task 0; period 500000
Task 0: going to sleep
Task 0: woken up
Task 0: going to sleep
FIFO handler: sending the "1" command to task 1; period 200000
Task 1: woken up
Task 1: executing the "1" command to task 1; period 200000
Task 1: going to sleep
Task 1: woken up
Task 1: going to sleep
FIFO 1: Frank Frank
FIFO 2: Zappa Zappa
<-------------------------- 100 seconds pause here!!!
frank_app: now sFIFO handler: sending the "2" command to task 0; period 200000
Task 0: woken up
Task 0: executing the "2" command to task 0; period 200000
Task 0: going to sleep
ending commands FIFO handler: sending the "2" command to task 1; period 200000
Task 1: woken up
Task 1: executing the "2" command to task 1; period 200000
Task 1: going to sleep
to stop RT-tasks
# Task 1: woken up
Task 1: going to sleep
<-------------------------- several minutes pause here, module unlodaded
I think that pthread_make_periodic_np(pthread_self()...)
restarts function thread_code() from the beginning so it executes
pthread_wait_np() again but it won't get any wakeup signal from
fifo handler until frank_app sends the command STOP_TASK 100 seconds later.
Meanwhile the first instance of the thread is looping forever within while(1)
and catched up also by pthread_wait_np(). The result is unpredictable.
The whole program structure is counfusing a bit for me.
Am I dumb?
(Yes I am, but this code needs clarification anyway. ;-)
Gabor
-- [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/