#ifndef __BIWAK_HANDLER_LINK_PICO_H
#define __BIWAK_HANDLER_LINK_PICO_H
//-----------------------------------------------------------------------------
//
// \brief   Link IRQ handler symbols to implementations
//
// \author  Maximilian Seesslen <mes@seesslen.net>
//
//-----------------------------------------------------------------------------


#include <biwak/handler.h>


//----------------------------------------------------------------------------
//
// We need to specify which IRQ-Handlers should get linked into our binary
// without recompiling libbiwak.
//
// The mechanism is a little bit tricky;
//
// libstm implements weak empty IRQ-Handlers.
// libbiwak implements global IRQ-Handler-implementation.
// this implements weak empty IRQ-Handlers-implementation.
// this defines alias from IRQ-Handlers to IRQ-Handlers-implementation
//
// Other mechanisms did not work reliable.
//
//----------------------------------------------------------------------------

#define tostr(text) "" #text ""
#if 0
#define link_handler( name ) \
   extern "C" \
   { \
      void name ## _imp(void) __attribute__( ( weak, isr ) ); \
      void name(void) __attribute__( ( isr ) ); \
   } \
    \
   void name ## _imp(void) \
   { \
    \
   }; \
   void name(void) __attribute__( ( alias ( tostr ( name ## _imp ) ) ) ); \
   ;
#endif

#if 0
#define ____link_handler( name ) \
   asm( \
   "   .text\n" \
   "   .extern	" tostr ( name ## _imp ) "\n" \
   "   .global	" tostr ( name  ) "\n" \
   "   .global	" tostr ( name ## _imp ) "\n" \
   "   .set " tostr ( name  ) "," tostr ( name ## _imp ) "\n" \
   );

// link_handler(USART2_IRQHandler)
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/*
 * void USART2_IRQHandler_imp(void);
asm(
".text\n"
".globl function\n"
".set function, function_imp\n"
""
);
*/

#ifdef __cplusplus
}
#endif


//---fin-----------------------------------------------------------------------
#endif // ? ! __BIWAK_HANDLER_LINK_PICO_H
