#ifdef STM32
   #include <biwak/handler.h>
   #define __STATIC_INLINE static inline
   #define __ASM asm
   //#include <stm/cmsis_gcc.h>
#endif

// Usually in <stm/cmsis_gcc.h>; problems with stm32g4 compiling
void __disable_irq(void)
{
    #if defined STM32
        __ASM volatile ("cpsid i" : : : "memory");
    #endif
}

#ifdef STM32
   #define FREEZE_SEPARATE_HANDLER(handler) \
		 extern "C" { void handler(void) __attribute__ ( ( interrupt, isr ) ); \
         void handler(void) \
            { __disable_irq(); while(1) asm("nop;\n"); } }
#else
   #define FREEZE_SEPARATE_HANDLER(handler) \
       extern "C" { void handler(void) \
       { while(1) asm("nop;\n"); } }
#endif


#if defined (BIWAK_USE_FREEZE_HANDLER)
   #define FREEZE_HANDLER(handler) FREEZE_SEPARATE_HANDLER(handler)
#else
   #define FREEZE_HANDLER(handler)
#endif

int handlerFreezerKeeper=0;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"

FREEZE_HANDLER( ADC1_IRQHandler);
FREEZE_HANDLER( ADC1_2_IRQHandler);
FREEZE_HANDLER( AES_IRQHandler );

FREEZE_HANDLER( BusFault_Handler );

FREEZE_HANDLER( CAN_TX_IRQHandler);
FREEZE_HANDLER( CAN_RX0_IRQHandler);
FREEZE_HANDLER( CAN_RX1_IRQHandler);
FREEZE_HANDLER( CAN_SCE_IRQHandler);
FREEZE_HANDLER( CAN1_RX1_IRQHandler );
FREEZE_HANDLER( CAN1_SCE_IRQHandler );
FREEZE_HANDLER( CEC_CAN_IRQHandler );

FREEZE_HANDLER( COMP_IRQHandler);
FREEZE_HANDLER( COMP1_2_3_IRQHandler );
FREEZE_HANDLER( COMP2_IRQHandler);
FREEZE_HANDLER( COMP4_6_IRQHandler);
FREEZE_HANDLER( COMP4_IRQHandler );
FREEZE_HANDLER( CORDIC_IRQHandler );
FREEZE_HANDLER( CRS_IRQHandler );
FREEZE_HANDLER( DebugMon_Handler );
//FREEZE_HANDLER( Default_Handler );
FREEZE_HANDLER( DMA1_Channel1_IRQHandler);
FREEZE_HANDLER( DMA1_Channel2_IRQHandler);
FREEZE_HANDLER( DMA1_Channel3_IRQHandler);
FREEZE_HANDLER( DMA1_Channel4_IRQHandler);
//FREEZE_HANDLER( DMA1_Channel5_IRQHandler);
FREEZE_HANDLER( DMA1_Channel6_IRQHandler);
FREEZE_HANDLER( DMA1_Channel7_IRQHandler);
FREEZE_HANDLER( DMA1_Channel4_5_IRQHandler);
FREEZE_HANDLER( DMA1_Channel2_3_IRQHandler);
FREEZE_HANDLER( DMA2_Channel1_IRQHandler );
FREEZE_HANDLER( DMA2_Channel2_IRQHandler );
FREEZE_HANDLER( DMA2_Channel3_IRQHandler );
FREEZE_HANDLER( DMA2_Channel4_IRQHandler );
FREEZE_HANDLER( DMA2_Channel5_IRQHandler );
FREEZE_HANDLER( DMA2_Channel6_IRQHandler );
FREEZE_HANDLER( DMA2_Channel7_IRQHandler );
FREEZE_HANDLER( DMAMUX_OVR_IRQHandler );

FREEZE_HANDLER( EXTI0_IRQHandler );
FREEZE_HANDLER( EXTI0_1_IRQHandler );
FREEZE_HANDLER( EXTI1_IRQHandler );
FREEZE_HANDLER( EXTI2_IRQHandler );
FREEZE_HANDLER( EXTI2_3_IRQHandler );
FREEZE_HANDLER( EXTI3_IRQHandler );
FREEZE_HANDLER( EXTI4_IRQHandler );
FREEZE_HANDLER( EXTI4_15_IRQHandler );
FREEZE_HANDLER( EXTI9_5_IRQHandler);
FREEZE_HANDLER( EXTI15_10_IRQHandler );

FREEZE_HANDLER( FDCAN1_IT0_IRQHandler );
FREEZE_HANDLER( FDCAN1_IT1_IRQHandler );
FREEZE_HANDLER( FLASH_IRQHandler );
FREEZE_HANDLER( FMAC_IRQHandler );
FREEZE_HANDLER( FPU_IRQHandler );

FREEZE_HANDLER( HardFault_Handler );

FREEZE_HANDLER( I2C1_EV_IRQHandler);
FREEZE_HANDLER( I2C1_ER_IRQHandler);
FREEZE_HANDLER( I2C1_IRQHandler );
FREEZE_HANDLER( I2C2_EV_IRQHandler );
FREEZE_HANDLER( I2C2_ER_IRQHandler );
FREEZE_HANDLER( I2C2_IRQHandler );
FREEZE_HANDLER( I2C3_EV_IRQHandler );
FREEZE_HANDLER( I2C3_ER_IRQHandler );

FREEZE_HANDLER( LPTIM1_IRQHandler );
FREEZE_HANDLER( LPTIM2_IRQHandler );
FREEZE_HANDLER( LPUART1_IRQHandler );

FREEZE_HANDLER( MemManage_Handler );
FREEZE_HANDLER( NMI_Handler );

FREEZE_HANDLER( PendSV_Handler );
FREEZE_HANDLER( PVD_IRQHandler );
FREEZE_HANDLER( PVD_PVM_IRQHandler );
FREEZE_HANDLER( PVD_VDDIO2_IRQHandler );

FREEZE_HANDLER( RCC_CRS_IRQHandler );
FREEZE_HANDLER( RCC_IRQHandler);
FREEZE_HANDLER( RNG_IRQHandler );
FREEZE_HANDLER( RTC_Alarm_IRQHandler);
FREEZE_HANDLER( RTC_WKUP_IRQHandler );
FREEZE_HANDLER( RTC_IRQHandler );
FREEZE_HANDLER( RTC_TAMP_LSECSS_IRQHandler );

FREEZE_HANDLER( SAI1_IRQHandler );
FREEZE_HANDLER( SPI1_IRQHandler );
FREEZE_HANDLER( SPI2_IRQHandler );
FREEZE_HANDLER( SPI3_IRQHandler );
FREEZE_HANDLER( SVC_Handler );
FREEZE_HANDLER( SWPMI1_IRQHandler );
FREEZE_HANDLER( SysTick_Handler );

FREEZE_HANDLER( TAMP_STAMP_IRQHandler );
FREEZE_HANDLER( TAMPER_IRQHandler );

FREEZE_HANDLER( TIM1_IRQHandler );
FREEZE_HANDLER( TIM1_BRK_TIM15_IRQHandler);
FREEZE_HANDLER( TIM1_BRK_UP_TRG_COM_IRQHandler );
FREEZE_HANDLER( TIM1_CC_IRQHandler);
FREEZE_HANDLER( TIM1_TRG_COM_TIM17_IRQHandler);
FREEZE_HANDLER( TIM1_TRG_COM_IRQHandler);
FREEZE_HANDLER( TIM1_UP_TIM16_IRQHandler);
FREEZE_HANDLER( TIM2_IRQHandler);
FREEZE_HANDLER( TIM3_IRQHandler );
FREEZE_HANDLER( TIM4_IRQHandler );
FREEZE_HANDLER( TIM6_DAC_IRQHandler );
FREEZE_HANDLER( TIM6_DAC1_IRQHandler );
FREEZE_HANDLER( TIM7_DAC2_IRQHandler );
FREEZE_HANDLER( TIM7_IRQHandler );
FREEZE_HANDLER( TIM8_BRK_IRQHandler );
FREEZE_HANDLER( TIM8_TRG_COM_IRQHandler );
FREEZE_HANDLER( TIM8_UP_IRQHandler );
FREEZE_HANDLER( TIM8_CC_IRQHandler );
FREEZE_HANDLER( TIM14_IRQHandler );
FREEZE_HANDLER( TIM15_IRQHandler );
FREEZE_HANDLER( TIM16_IRQHandler );
FREEZE_HANDLER( TIM17_IRQHandler );

FREEZE_HANDLER( TSC_IRQHandler );
FREEZE_HANDLER( UCPD1_IRQHandler );
FREEZE_HANDLER( USB_HP_CAN1_TX_IRQHandler );
FREEZE_HANDLER( USB_HP_IRQHandler );
FREEZE_HANDLER( USB_LP_CAN1_RX0_IRQHandler );
FREEZE_HANDLER( USB_LP_IRQHandler );
FREEZE_HANDLER( USBWakeUp_IRQHandler );

FREEZE_HANDLER( UsageFault_Handler );
FREEZE_HANDLER( USART1_IRQHandler );
FREEZE_HANDLER( USART2_IRQHandler );
FREEZE_HANDLER( USART3_IRQHandler );
FREEZE_HANDLER( USART3_4_IRQHandler );
FREEZE_HANDLER( UART4_IRQHandler );
FREEZE_HANDLER( USB_IRQHandler );

FREEZE_HANDLER( WWDG_IRQHandler );

#if 0
FREEZE_HANDLER( PVD_PVM_IRQHandler );
FREEZE_HANDLER( RTC_TAMP_LSECSS_IRQHandler );
FREEZE_HANDLER( RTC_WKUP_IRQHandler );
FREEZE_HANDLER( ADC1_2_IRQHandler );
FREEZE_HANDLER( USB_HP_IRQHandler );
FREEZE_HANDLER( USB_LP_IRQHandler );
FREEZE_HANDLER( FDCAN1_IT0_IRQHandler );
FREEZE_HANDLER( FDCAN1_IT1_IRQHandler );
FREEZE_HANDLER( EXTI9_5_IRQHandler );
FREEZE_HANDLER( TIM1_BRK_TIM15_IRQHandler );
FREEZE_HANDLER( TIM1_UP_TIM16_IRQHandler );
FREEZE_HANDLER( TIM1_TRG_COM_TIM17_IRQHandler );
FREEZE_HANDLER( TIM1_CC_IRQHandler );
FREEZE_HANDLER( TIM2_IRQHandler );
FREEZE_HANDLER( TIM3_IRQHandler );
FREEZE_HANDLER( TIM4_IRQHandler );
FREEZE_HANDLER( I2C1_EV_IRQHandler );
FREEZE_HANDLER( I2C1_ER_IRQHandler );
FREEZE_HANDLER( I2C2_EV_IRQHandler );
FREEZE_HANDLER( I2C2_ER_IRQHandler );
FREEZE_HANDLER( SPI1_IRQHandler );
FREEZE_HANDLER( SPI2_IRQHandler );
FREEZE_HANDLER( USART1_IRQHandler );
FREEZE_HANDLER( USART2_IRQHandler );
FREEZE_HANDLER( USART3_IRQHandler );
FREEZE_HANDLER( EXTI15_10_IRQHandler );
FREEZE_HANDLER( RTC_Alarm_IRQHandler );
FREEZE_HANDLER( USBWakeUp_IRQHandler );
FREEZE_HANDLER( TIM8_BRK_IRQHandler );
FREEZE_HANDLER( TIM8_UP_IRQHandler );
FREEZE_HANDLER( TIM8_TRG_COM_IRQHandler );
FREEZE_HANDLER( TIM8_CC_IRQHandler );
FREEZE_HANDLER( LPTIM1_IRQHandler );
FREEZE_HANDLER( SPI3_IRQHandler );
FREEZE_HANDLER( UART4_IRQHandler );
FREEZE_HANDLER( TIM6_DAC_IRQHandler );
FREEZE_HANDLER( TIM7_IRQHandler );
FREEZE_HANDLER( DMA2_Channel1_IRQHandler );
FREEZE_HANDLER( DMA2_Channel2_IRQHandler );
FREEZE_HANDLER( DMA2_Channel3_IRQHandler );
FREEZE_HANDLER( DMA2_Channel4_IRQHandler );
FREEZE_HANDLER( DMA2_Channel5_IRQHandler );
FREEZE_HANDLER( UCPD1_IRQHandler );
FREEZE_HANDLER( COMP1_2_3_IRQHandler );
FREEZE_HANDLER( COMP4_IRQHandler );
FREEZE_HANDLER( CRS_IRQHandler );
FREEZE_HANDLER( SAI1_IRQHandler );
FREEZE_HANDLER( FPU_IRQHandler );
#endif

#pragma GCC diagnostic pop

//---fin----------------------------------------------------------------------
