#include <rtai_lxrt.h>
#include <sys/mman.h>
#include <sys/io.h>
#include <pthread.h>

volatile int stop = 0;
void* rt_task(void *arg)
{
	RT_TASK *task;
	task = rt_task_init(nam2num("rt1"), 0, 4096,0);
	iopl(3);
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	while(!stop) {
		outb(0xff, 0x378);
		rt_sleep(nano2count(500000000));
		outb(0x0, 0x378);
		rt_sleep(nano2count(500000000));
	}
	rt_make_soft_real_time();
	rt_task_delete(task);
	
}

int main(int argc, char **argv)
{
	RT_TASK *task;
	int priority = 10, i;
	int stack_size = 4096;
	int message_size = 0; /* Use default of 256 */
	pthread_t t1;

	task = rt_task_init(nam2num("main"), 
                            priority, stack_size, message_size);
	if(task == 0) exit(1);
	rt_set_oneshot_mode();
	start_rt_timer(0);
	pthread_create(&t1, 0, rt_task, 0);
	getchar();
	stop = 1;
	pthread_join(t1, 0);
	stop_rt_timer();
	rt_task_delete(task);
	return 0; 
}
