#include <startup.h>
#include <LPC214X.h>
#include <armVIC.h>
#include <type.h>
#include <irq.h>
// LED P0.31
#define LED 0x80000000

#define	INT_VECT_NUM	0

static void IRQ_Timer0(void) __attribute__ ((interrupt("IRQ")));
void IRQ_Timer0 (void)
{
	if ((IOSET0 & LED) == 0)
		IOSET0 = LED;
	else
		IOCLR0 = LED;
	
	T0IR = 0x01;
	VICVectAddr = 0x00;
}

int main (void) {
	Initialize();
	IODIR0  = LED;

	T0TC   = 0;			/* timer0										*/
	T0PR   = 0;			/* no pre											*/
	T0MCR  = 0x03;		/* when is T0MR0 set T0TC				*/
	T0MR0  = 60000000;	/* 1s interrupt  		*/
	T0TCR  = 0x01;		/* start											*/

	VICIntSelect &= ~(1<<TIMER0_INT);
	VICIntEnable |= (1<<TIMER0_INT);

	(*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | TIMER0_INT; // choose highest priority ISR slot 	
	(*(&VICVectAddr0+INT_VECT_NUM)) = (int)IRQ_Timer0;

	enableIRQ();
	IOSET0 = LED;

	for(;;);
	}
