#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/cons.h>
#include <rtl_sched.h>
#include <rtl_fifo.h>
#include <math.h>
#define DOSIN 1
#define DOCOS 2
double  cosradians = 0;

RT_TASK tasks[2];

void fun(int t) {
	double  radians = 0;
	double result;

	while(radians < 100){
		if(t == DOSIN)result = sin(radians);
		else result= cos(radians);
		rtf_put(t, &result, sizeof(result));
		radians += 1.0;
		conpr(( (t == DOSIN)? "S":"C"));
		rt_task_wait();
	}
}

int init_module (void)
{
	rtf_create (DOSIN, 4000);
	rtf_create (DOCOS, 4000);
	rt_task_init (&tasks[0], fun, DOSIN, 3000, 4);
	rt_task_use_fp (&tasks[0], 1);
	rt_task_make_periodic (&tasks[0], rt_get_time (), 5000);
	conpr ("First started\n");
	rt_task_init (&tasks[1], fun, DOCOS, 3000, 5);
	rt_task_use_fp (&tasks[1], 1);
	rt_task_make_periodic (&tasks[1], rt_get_time (), 5000);
	conpr ("Second started\n");

	return 0;
}


void cleanup_module (void)
{
	rtf_destroy (1);
	rtf_destroy (2);
	rt_task_delete (&tasks[0]);
	rt_task_delete (&tasks[1]);
}
