#ifndef MODULE
#define MODULE
#endif

#ifndef __KERNEL__
#define __KERNEL__
#endif



#include <rtai.h>
#include <rtai_lxrt.h>
#include <asm/io.h>
#include <rtai_sched.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include "ece4220lab4.h"
#include <rtai_fifos.h>

RTIME period;

static RT_TASK mytask1;


MODULE_LICENSE("GPL");


static void display(){
	int button = 0;
	rtf_create(2, sizeof(10 * button));
clear_button();

	        	while(1){

	     				if(check_button() == 1){
	        			button = 1;
	        			rtf_put(2, &button, sizeof(button));

	        			}
	        			else{
	        			button = 0;
	        			rtf_put(2, &button, sizeof(button));
	        			}

	        		rt_task_wait_period();
	        	}

}


int init_module(void) {

		period = start_rt_timer(nano2count(1000000));
				rt_task_init(&mytask1, display, 0, 256, 0,0,0);
			    rt_task_make_periodic(&mytask1, rt_get_time()+period,  1000 * period);


		return 0;
}


void cleanup_module(void){
	rt_task_delete(&mytask1);
	rtf_destroy(2);
}