#ifndef BIWAK_HANDLER_H
#define BIWAK_HANDLER_H
//-----------------------------------------------------------------------------
//
// \brief   Helper macros for implementing ISRs in libbiwak
//
// \author  Maximilian Seesslen <devel@seesslen.net>
//
//-----------------------------------------------------------------------------


#include <biwak/biwak.h>


#define callInterrupt(i) \
   if(i) { i->interrupt(); }

#define callInterruptOrException(i) \
if(i) { i->interrupt(); } else { exception("ISRNS"); }

#define callInterruptFix(i) \
   { i->interrupt(); }

#define HANDLER_DEF interrupt

#define IRQ_Funcion_decl(name)  extern "C" void name##_imp(void) __attribute__ (( HANDLER_DEF )); \
                           extern "C" void name      (void) __attribute__ (( HANDLER_DEF ));

#define IRQ_Funcion_weak_dummy(name)  extern "C" void name(void) __attribute__ (( HANDLER_DEF, weak )); \
                           void name(void){};

#define IRQ_Start \
   _Pragma("GCC diagnostic push") \
   _Pragma("GCC diagnostic ignored \"-Wattributes\"")
#define IRQ_End \
   _Pragma("GCC diagnostic pop")

#define IRQ_Funcion_imp(name) \
            extern "C" void name##_imp(void) __attribute__ (( HANDLER_DEF )); \
                           extern "C" void name##_imp(void)

#define IRQ_Funcion_weak(name)  extern "C" void name##_imp(void) __attribute__ ( ( HANDLER_DEF, weak ) ); \
                           extern "C" void name##_imp(void)

#define IRQ_Funcion_imp_force(name)  extern "C" void name(void) __attribute__ ( ( HANDLER_DEF ) ); \
                           extern "C" void name(void)

#define IRQ_Funcion_imp_name(name)  name##_imp


#if defined (MCU_PLATFORM_STM32)
   #define INTERRUPT_ROUTINE __attribute__ ( ( isr ) )
   #define FAULT_HANDLER __attribute__( ( naked ) )
#else
   #define INTERRUPT_ROUTINE
   #define FAULT_HANDLER
#endif


//---fin-----------------------------------------------------------------------
#endif // ? ! BIWAK_HANDLER_H
