/******************************************************************************
 *   irq.h:  Interrupt related Header file for NXP LPC23xx/24xx Family 
 *   Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.01  ver 1.00    Prelimnary version, first Release
 *
 *   200?     Modified by mthomas.
 *   2008-9   Modified extensively by Ackley for the SFB project
 ******************************************************************************/
#ifndef __IRQ_H 
#define __IRQ_H

#include "SFBTypes.h"           /* For IRQHandler */

#ifdef __cplusplus
extern "C" {
#endif

#define I_Bit			0x80
#define F_Bit			0x40

#define SYS32Mode		0x1F
#define IRQ32Mode		0x12
#define FIQ32Mode		0x11

#define HIGHEST_PRIORITY	0x01
#define HIGH_PRIORITY           0x04
#define MEDIUM_PRIORITY         0x08
#define LOW_PRIORITY            0x0C
#define LOWEST_PRIORITY		0x0F

#define	WDT_INT			0
#define SWI_INT			1
#define ARM_CORE0_INT		2
#define	ARM_CORE1_INT		3
#define	TIMER0_INT		4
#define TIMER1_INT		5
#define UART0_INT		6
#define	UART1_INT		7
#define	PWM0_1_INT		8
#define I2C0_INT		9
#define SPI0_INT		10			/* SPI and SSP0 share VIC slot */
#define SSP0_INT		10
#define	SSP1_INT		11
#define	PLL_INT			12
#define RTC_INT			13
#define EINT0_INT		14
#define EINT1_INT		15
#define EINT2_INT		16
#define EINT3_INT		17
#define	ADC0_INT		18
#define I2C1_INT		19
#define BOD_INT			20
#define EMAC_INT		21
#define USB_INT			22
#define CAN_INT			23
#define MCI_INT			24
#define GPDMA_INT		25
#define TIMER2_INT		26
#define TIMER3_INT		27
#define UART2_INT		28
#define UART3_INT		29
#define I2C2_INT		30
#define I2S_INT			31

#define VIC_SIZE		32

#define VECT_ADDR_INDEX	0x100
#define VECT_CNTL_INDEX 0x200

/* Be aware that, from compiler to compiler, nested interrupt will have to
be handled differently. More details can be found in Philips LPC2000
family app-note AN10381 */
 
#include "SFBTypes.h"

extern void init_VIC(void) ;

u32 install_irq( u32 IntNumber, IRQHandler *HandlerAddr, u32 Priority );

/* Mon Apr 13 05:22:01 2009 Ackley: Added for symmetry.  Disables interrupt, clears handler */
u32 uninstall_irq( u32 IntNumber );

#define enableInterrupts()                                                \
  __asm__ __volatile__ (                                                  \
               "MRS r0, CPSR\n\t"     /* Read status register */          \
               "BIC r0, r0, #0x80\n\t"/* Clear the I bit to allow IRQ */  \
               "MSR CPSR_c, r0"       /* Update status */                 \
               ::: "r0")              /* We clobbered r0 */
extern void enableInterruptsFunction();

#define disableInterrupts()                                               \
  __asm__ __volatile__ (                                                  \
               "MRS r0, CPSR\n\t"     /* Read status register */          \
               "ORR r0, r0, #0x80\n\t"/* Set the I bit to disallow IRQ */ \
               "MSR CPSR_c, r0"       /* Update status */                 \
               ::: "r0")              /* We clobbered r0 */
extern void disableInterruptsFunction();

#define suspendInterrupts(u32var)                                         \
  __asm__ __volatile__ (                                                  \
               "MRS %0, CPSR\n\t"     /* Read status register */          \
               "ORR r0, %0, #0x80\n\t"/* Set the I bit to disallow IRQ */ \
               "MSR CPSR_c, r0"       /* Update status */                 \
               : "=r" (u32var) : : "r0")  /* We clobbered r0 */

#define restoreInterrupts(u32var)                                         \
  __asm__ __volatile__ (                                                  \
               "MSR CPSR_c, %0\n"     /* Restore status from supplied */  \
               : : "r" (u32var) : )


#ifdef __cplusplus
}
#endif


#endif /* end __IRQ_H */

/******************************************************************************
**                            End Of File
******************************************************************************/

