#ifndef __armirq_h__
#define __armirq_h__

#ifndef __GNUC__
#  define __asm__ asm
#endif

#include "config.h"

#ifdef __cplusplus
extern "C" {
#endif

unsigned int disableIRQ(void);
unsigned int restoreIRQ(unsigned int oldCPSR);
unsigned int enableIRQ(void);

#ifdef __cplusplus
}
#endif

#ifdef CONFIG_ARCH_LPC2XXX

#ifdef CONFIG_TOOLCHAIN_ROWLEY
// #define ISR_ENTER() asm("stmfd sp!, {r0-r12, lr}\n" "mrs r0, spsr\n" "stmfd sp!, {r0}\n"); 
// #define ISR_LEAVE() asm("ldmfd sp!,{r0}\n" "msr spsr_c, r0\n" "ldmfd sp!,{r0-r12,lr}\n" "subs pc, lr, #4\n");

#define ISR_ENTER() {}
#define ISR_LEAVE() {}

#if 0
#define IRQ_ENABLE() __ARMLIB_enableIRQ()
#define IRQ_DISABLE() __ARMLIB_disableIRQ()
#else
#define IRQ_ENABLE() do { unsigned int dummy = enableIRQ(); } while(0)
#define IRQ_DISABLE() do { unsigned int dummy = disableIRQ(); } while(0)
#endif
#define DECLARE_ISR(isrName) static void isrName(void) __attribute__((interrupt("IRQ")))
#define ISR_FUNCTION(funcName) static void funcName(void)

#define INLINE_KEYWORD __inline

#endif

#ifdef CONFIG_TOOLCHAIN_IAR

#define IRQ_ENABLE() __enable_interrupt()
#define IRQ_DISABLE() __disable_interrupt()

#define ISR_ENTER() {}
#define ISR_LEAVE() {}

#define DECLARE_ISR(isrName) __irq __nested __arm static void isrName(void)
#define ISR_FUNCTION(funcName) __irq __nested __arm static void funcName(void)

#define INLINE_KEYWORD

// TODO: add nested function
#endif

#endif

#endif /* __armirq_h__ */

