Philip N Daly wrote:
>
> Content-MD5: fVT3+tdeWfB8vwdyUSaZXQ==
>
> Hi,
>
> Not specifically a RTL/RTAI question but does anyone know how to
> "sleep" in a kernel module? Not something I want to do very often
> but I have a need right now. udelay appears to crash my kernel.
>
> Ta,
>
> +==================================================================+
> Phil Daly, NOAO/AURA, 950 N. Cherry Avenue, Tucson AZ 85719, U S A
> E-mail: [EMAIL PROTECTED] V-mail: (520) 318 8438 Fax: (520) 318 8360
>
> --- [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/
Hi Phil,
For periods greater than a timer tick you can set current->timeout and
sleep on a wait queue. The timeout value is compared with jiffies every
time the scheduler runs, and if it is smaller than or equal to the
current time the scheduler will wake the process. For example:
unsigned long time_delay;
time_delay = jiffies + my_delay;
current->timeout = time_delay;
current->state = TASK_INTERRUPTIBLE;
schedule();
current->timeout = 0;
An alternative to this is to use kernel timers to dispatch a function at
some time in the future. For example:
unsigned long time_delay;
struct timer_list my_timer;
init_timer(&my_timer);
my_timer.function = <function to be called>;
my_timer.data = <any data to pass to the function>;
my_timer.expires = jiffies + time_delay;
add_timer(&my_timer);
For very short delays use the kernel function udelay:
#include <linux/udelay.h>
void udelay(unsigned long usecs);
Remember that udelay is a busy waiting function, so other tasks cannot
run during the time lapse. The suggested maximum for this function is 1
millisecond.
For more information on this topic Chapter 6 of Linux Device Drivers by
Rubini has some very useful details,
Best regards,
Steve
--- [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/