This example features NTASKS real-time tasks running periodically.
On each period one of them sets a bit on the parallel
port, another one resets it. By choosing an appropriate timings
one can produce a rectangular wave on the parallel port
which can be watched on an oscilloscope plugged into it.
Be carefull about the macro TICK_PERIOD its value is now set for a 200Mhz
PPro, which can be to much for a less powerfull machine.

To run this example you must first compile and boot the RT-kernel,
then have the RT-scheduler module of this variant installed.

To run the example type `make' and `insmod rt_process'.


/* Produce a rectangular wave on output 0 of a parallel port */


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

#include <rtl_sched.h>

/* the address of the parallel port -- you probably should change this */

#define ONE_SHOT

#define LPT 0x378

#define TICK_PERIOD 2000

#define STACK_SIZE 2000

#define LOOPS 1000000

#define NTASKS 18

RT_TASK task[NTASKS];

void fun(int t)
{
	unsigned int loops = LOOPS;
	while(loops--) {
		outb(t, LPT);
		rt_task_wait_period();
	}
}


int init_module(void)
{
	RTIME tick_period;
	RTIME now;
	int i, k;

#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	k = 1;
	for (i = 0; i < NTASKS; i++) {
		rt_task_init(&task[i], fun, k = ~k, STACK_SIZE, 0, 0, 0);
	}
	tick_period = start_rt_timer(nano2count(TICK_PERIOD));
	now = rt_get_time() + tick_period;
	for (i = 0; i < NTASKS; i++) {
		rt_task_make_periodic(&task[i], now + (i+1)*tick_period, NTASKS*tick_period);
	}
	return 0;
}


void cleanup_module(void)
{
	int i;

	stop_rt_timer();
	for (i = 0; i < NTASKS; i++) {
		rt_task_delete(&task[i]);
	}
}