#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
#define LPT_IRQ 7
#define RTC_IRQ 8

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 */
                outb(flag1+flag2, LPT_PORT);            /* write 
on the parallel port */
                if (flag1==0)
                        flag1=0x01;
                else
                        flag1=0;
                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 =gethrtime();
 hrtime_t delay = now + 1*100L*1000L; /*Dealy 1 
ms*/ 
 flag2 =0;      
                                
        while (1) {
         pthread_wait_np();

     now = gethrtime();
         delay = now + i * 100L * 1000L;
         flag2=0x02;
                                                                                 
     while (now<delay) {
                now = gethrtime();
         }
         i=i+5;
         if (i>1025)
           i = 900;

         flag2=0;
        }
 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, delay2);

        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/

Reply via email to