Following is the source program.
I have two RT threads of different priority. One is periodic, and the other
sets its wakeup time before going to sleep (using start time = wakup and period
= 0).
I checked on the box 2 hours after running the task (on a pentium 75Mhz), and
the second thread stopped running. This was observed by having each task
toggling a different parallel port bit (but both tasks output to the port).
After a certain period of time the second task stopped toggling the bit, but
the first task continued as usual.
I am using minilinux version 2.2.14-V2.2 #686 SMP. This is only a single
processor machine however.
I am still diagnosing the approx delay time but its between 10 mins to 2 hours
(estimated).
===========================================================
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <rtl.h>
#include <rtl_sync.h>
#include <time.h>
#include <asm/io.h>
#include <pthread.h>
#define LPT_PORT 0x378
pthread_t mytask;
pthread_t stalltask;
volatile int flag1;
volatile int flag2;
void *fun (void *t)
{
hrtime_t now =gethrtime();
/*hrtime_t stop = gethrtime()+ 120*(hrtime_t)NSECS_PER_SEC; */
flag1 = 0;
while (1/*now<stop*/) {
pthread_wait_np();
/* Do The Work Here */
if (flag1==0)
flag1=0x01;
else
flag1=0;
outb(flag1+flag2, LPT_PORT); /* write on the parallel port
*/
now = gethrtime();
}
outb(0, LPT_PORT); /* write on the parallel port */
return 0;
}
void *fun2 (void *t)
{
unsigned long int i=1L;
hrtime_t now;
hrtime_t tstart;
hrtime_t delay;
pthread_t selfid;
flag2 =0;
selfid = pthread_self(); /* Get current thread ID */
while (1) {
now = gethrtime();
tstart= now;
delay = now + 10*1000L*1000L;
flag2=0x02;
while (now<delay) {
now= gethrtime();
outb(flag1+flag2, LPT_PORT); /* write on the
parallel port */
}
flag2=0;
outb(flag1+flag2, LPT_PORT); /* write on the parallel port
*/
delay = tstart + i;
i = i + 5*1000L*1000L; /* Add 5ms to next scheduled event time */
if (i >= 100*1000L*1000L) /* Reset Delay loop at 100ms */
i = 20*1000L*1000L;
pthread_make_periodic_np (selfid,delay, 0); /* One Shot, set next
wakeup */
pthread_wait_np();
}
return 0;
}
int init_module (void)
{
struct sched_param p1, p2;
hrtime_t now =gethrtime();
hrtime_t delay = 50 * 1000L;
hrtime_t delay2 = 100 *1000L * 1000L;
pthread_create (&mytask, NULL, fun, (void *) 1);
pthread_make_periodic_np (mytask, now + delay, delay);
pthread_create (&stalltask, NULL, fun2, (void *) 1);
pthread_make_periodic_np (stalltask, now + delay2, 0);
p1 . sched_priority = 2;
pthread_setschedparam (mytask, SCHED_FIFO, &p1);
p2 . sched_priority = 1;
pthread_setschedparam (stalltask, SCHED_FIFO, &p2);
return 0;
}
void cleanup_module (void)
{
pthread_delete_np (mytask);
pthread_delete_np (stalltask);
}
-- [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/