rt_task_delay() waits _until_ the time specified, not _for_ the
amount of time specified.  Use the RELATIVE_TIME() macro:

rt_task_delay(RELATIVE_TIME(interval));

or, better:

RTIME next = rt_get_time();
while (1)
{
        rt_task_delay(next += interval);
        rtl_printf("P2 is also here\n");
}

Jerry

Magnus Johansson wrote:
> 
> Sorry if this a stupid question but I'm quite new to RTL.
> In one of my programs I'm using the IPC/semaphore package. Everything is
> ok until I try to use the rt_task_delay() function, which crashes the
> system. So, I created a little test program with two tasks, one task
> declared periodic and the other not declared periodic but running
> periodicly using rt_task_delay. (See code below)   This little program
> also ends up with system crash and now I would like to know why? Am I
> using rt_task_delay wrong in any way? What would I need to do to make
> this tiny example work?
> I'd be grateful for any answer.
> 
> Regards,
> Magnus Johansson
> 
> --------------------------------------
> test.c
> --------------------------------------
> 
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/version.h>
> #include <linux/errno.h>
> 
> #include <rtl_sched.h>
> #include "../semaphores/rt_ipc.h"
> 
> RT_TASK_IPC p1, p2;
> 
> RTIME now;
> RTIME interval = HRTICKS_PER_SEC * 2;
> 
> void p1_code(int not_used) {
>         while(1) {
>                 rt_task_wait();
>                 rtl_printf("P1 is here\n");
>         }
> }
> 
> void p2_code(int not_used) {
>         while(1) {
>                 rt_task_delay(interval);
>                 rtl_printf("P2 is also here\n");
>         }
> }
> 
> int init_module(void) {
> 
>         now = rt_get_time();
> 
>         rt_task_ipc_init( &p1, p1_code, 0, 3000, 5 );
>         rt_task_ipc_init( &p2, p2_code, 0, 3000, 6 );
> 
>         rt_task_make_periodic( MAKE_RT_TASK( &p1 ), now, interval );
> 
>         rt_task_wakeup( MAKE_RT_TASK( &p1 ) );
>         rt_task_wakeup( MAKE_RT_TASK( &p2 ) );
> 
>     return 0;
> }
> 
> void cleanup_module(void) {
> 
>         rt_task_ipc_delete( &p1 );
>         rt_task_ipc_delete( &p2 );
> }
> -- [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/
-- [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/

Reply via email to