Beispiel #1
0
static void task_hard_routine(void * cookie) {
    unsigned long n = 0; /* how many IRQ since init? */
    RTIME time_prev = 0; /* when was the previous IRQ? */
    RTIME time_curr = 0; /* when was the current IRQ? */

    /* last IRQ is now! (init value) */
    time_prev = rt_timer_read();

    while (1) {
        /* wait for an IRQ */
        rt_intr_wait(&intr, TM_INFINITE);

        /* fetch current timestamp */
        time_curr = rt_timer_read();

        /*
           Ok, now we've got to check two things:
           - is it a "good transition" (edge triggering, two IRQ = 1 hit)?
           - is it a "real wheel rotation" (our crappy sensor wire sometimes
             decides to become an antenna, so here's a nasty software filter...)
        */
#define EPSILON 100 * 1000 * 1000
        if (++n % 2 && time_curr > time_prev + EPSILON) {
#undef  EPSILON
            /* post the current timestamp to the message queue */
            rt_queue_write(&queue, &time_curr, sizeof time_curr, Q_NORMAL);
            
            /* our job is done, we are now the previous IRQ */
            time_prev = time_curr;
        }
    }

    (void) cookie;
}
Beispiel #2
0
void task(void *arg)
{
    int err = 0;

    rt_printf("Task started. This is computer 1\n");

    if(run == 0) err = rt_task_set_periodic(NULL, TM_NOW, PERIOD);
    if(err != 0)  rt_printf("scheduling task filed with err %d: %s\n", err), strerror(-err);

    outb(inb(0x378) | 0x01, 0x378); //set D0 HIGH
    
    while(run<NUMRUNS){
      RTIME s = rt_timer_read();
      //set D0 LOW and HIGH again
      outb(inb(0x378) & 0xfe, 0x378);
      outb(inb(0x378) | 0x01, 0x378);
      //wait for respons:
      rt_intr_wait(&keypress, TM_INFINITE);
      diffs[run] = rt_timer_read() - s;
      run++;
      rt_task_wait_period(NULL);
    }
    rt_printf("Done listening, saving to file\n");
    write_RTIMES(FILEO, NUMRUNS, diffs);
    rt_printf("Done\n");
}
Beispiel #3
0
void keyboard_handler(void *arg)
{
	RT_INTR intr;
	rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
	int kps = 0;
	while(1){
		rt_printf("#Kbd interrupt %d\n",
                kps += rt_intr_wait(&intr, TM_INFINITE));
	}
}
Beispiel #4
0
void handler()
{
	rt_printf("Begin interrupt handler van PC2\n");
	int nr_waiting_interrupts = 0;
	while(1)
	{
		nr_waiting_interrupts = rt_intr_wait(&PC1_intr,TM_INFINITE);
		if (nr_waiting_interrupts > 0)
		{
			rt_printf("Generating interrupt to pc 1...\n");
			generate_interrupt_to_pc1();
		}
	}
}
void irq_server (void *cookie) {
	int fd ,iomask=0x00;
	if (rt_intr_enable(&intr_desc) != 0) {
		printf("Error : enabling IT\n");
		return;
	}
	if ((fd = open(INTERRUPT_OUTPUT_DEV, O_RDWR))<0) {
		printf("Open error on /dev/gpio/portD\n");
		return;
	}

	for (;;) {
    		/* Wait for the next interrupt. */
    		if (rt_intr_wait(&intr_desc,TM_INFINITE) > 0) {
			write(fd,&iomask,sizeof(iomask));
			iomask^=1;
    		}
  	}
}
Beispiel #6
0
void key_handler(void *arg)
{
	int count = 0;
	int nr_interrupts_waiting;
	
    RT_TASK *curtask;
    RT_TASK_INFO curtaskinfo;

	while(1) {
		//rt_printf("%d\n",count++);
		nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE);
		if (nr_interrupts_waiting>0)
		{
			// inquire current task
			curtask=rt_task_self();
			rt_task_inquire(curtask,&curtaskinfo);
			rt_printf("Current priority of handler task: %d \n", curtaskinfo.cprio);
		}
	}
}
Beispiel #7
0
void handler()
{
	rt_printf("Begin interrupt handler of lightsensor\n");
	int nr_waiting_interrupts = 0;
	int lr = 0;
  int counter = 0;
  RTIME time1,time2;
  RTIME results[MEASUREMENTS];
	while(counter < MEASUREMENTS)
	{
		nr_waiting_interrupts = rt_intr_wait(&lightsens_intr,TM_INFINITE);
		if (nr_waiting_interrupts > 0)
		{
      if(lr == 0)
      {
        //do stuff
        time1 = rt_timer_read();
        lr = 1;
        if (counter > 0)
        {
          results[counter] = time1-time2;
          counter++;
        }

      }
      else
      {
        //doe andere shit
        time2 = rt_timer_read();
        lr = 0;
        results[counter] = time2-time1;
        counter++;
      }
		}	
	}
  int j;
  for (j = 0;j<MEASUREMENTS;j++)
  {
    rt_printf("%d\n",results[j]);
  }
}
Beispiel #8
0
void handler()
{
	rt_printf("Begin interrupt handler of lightsensor\n");
	int nr_waiting_interrupts = 0;
	int counter = 0;
	while(1)
	{
		nr_waiting_interrupts = rt_intr_wait(&lightsens_intr,TM_INFINITE);
		if (nr_waiting_interrupts > 0)
		{
			//stap 1
			char byte;
			byte = byte | 0x63; //0110011
			outb(byte, 0x378); //set D to first phase of X
			rt_task_wait_period(NULL);
			//stap 2
			byte = 0x14;
			outb(byte, 0x378);
			rt_task_wait_period(NULL);
			//stap 3
			byte = 0x08;
			outb(byte,0x378);
			rt_task_wait_period(NULL);
			//stap 4
			byte = 0x14;
			outb(byte,0x378);
			rt_task_wait_period(NULL);
			//stap 5
			byte = 0x63;
			outb(byte,0x378);
			rt_task_wait_period(NULL);
			//leegmaken
			byte = 0x00;
			outb(byte,0x378);
		}	
	}
}