#include "sys/alt_irq.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_timer_regs.h"

volatile int counter = 0;

static void irr(){
	counter++;
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, counter );
	IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 0);
}

int main()
{ 
	/* TIMER */
	IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,
			ALTERA_AVALON_TIMER_CONTROL_START_MSK |
			ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
			ALTERA_AVALON_TIMER_CONTROL_ITO_MSK
			);

	/* IRQ */
	alt_ic_isr_register(TIMER_0_IRQ_INTERRUPT_CONTROLLER_ID,TIMER_0_IRQ, irr, NULL, 0);
	alt_ic_irq_enable(0,0);

	/*loop*/
  while (1){}

  return 0;
}
