#include <stdlib.h>
#include <stdio.h>
#include <string.h>    
#include <unistd.h>    
#include <errno.h>    
#include <sys/neutrino.h>    


unsigned irq_counter;

const struct sigevent *my_irq_handler(void *p, int id)
{

irq_counter++;

return NULL;

}


int main(int argc, char *argv[]) 
{

if (ThreadCtl(_NTO_TCTL_IO, 0) == -1)
  {
  fprintf(stderr,"Unable to get I/O privilege, %s\n",strerror(errno));
  exit(EXIT_FAILURE);
  }

if (InterruptAttach(0,my_irq_handler,NULL,0,_NTO_INTR_FLAGS_TRK_MSK) < 0)
  {
  perror("InterruptAttach()");
  return EXIT_FAILURE;
  }

for (;;)
  {
  delay(1000);
  printf("Irq counter:%u\n", irq_counter);
  fflush(stdout);
  }

return EXIT_SUCCESS;

}
