SQUARE WAVE GENERATION
    in Real-Time Linux

      //
      // rt_sqr.c
      //

      #define MODULE
      #include <linux/module.h>
      #include <linux/kernel.h>
      #include <linux/version.h>
      #include <linux/cons.h>
      #include <asm/io.h>
      #include <linux/rt_sched.h>

      // My address of the parallel port
      #define LPT 0x378

      RT_TASK mytask;
      RT_TASK mytask2;

      // Period of the square wave
      int per = 40000;

      void fun(int t) {
      while (1) {
      outb(t, LPT);
      rt_task_wait();
      }
      }

      int init_module(void)
      {
      RTIME now = rt_get_time();

      per = per * 1.19343;

      // this task sets the bit
      rt_task_init(&mytask, fun, 2, 3000, 4);

      / this task resets the bit
      rt_task_init(&mytask2, fun, 0, 3000, 5);

      // the 2 tasks run periodically with an offset
      rt_task_make_periodic(&mytask, now + 3000, per);
      rt_task_make_periodic(&mytask2, now + 3000 + ( per/2 ), per);
      return 0;
      }

      void cleanup_module(void)
      {
      rt_task_delete(&mytask);
      rt_task_delete(&mytask2);
      }