/*****************************************************************************
*
*
*****************************************************************************/

/***************************** Include Files ********************************/

#include "chip_uip_interrupt.h"
#include "uip_kernel_api.h"
#include "demo.h"

/**********************************************************************************************************************************************                                                                                                
void SysTick_Handler         (void)    {  uipIntTableID = Int_ID_SysTick_IRQHandler           ; uipInterruptServiceEngine();  } 
***********************************************************************************************************************************************/

void WWDG_IRQHandler                   (void)    {  uipIntTableID = Int_ID_WWDG_IRQHandler                   ; uipInterruptServiceEngine();  } 
void PVD_IRQHandler                    (void)    {  uipIntTableID = Int_ID_PVD_IRQHandler                    ; uipInterruptServiceEngine();  } 
void TAMPER_IRQHandler                 (void)    {  uipIntTableID = Int_ID_TAMPER_IRQHandler                 ; uipInterruptServiceEngine();  } 
void RTC_IRQHandler                    (void)    {  uipIntTableID = Int_ID_RTC_IRQHandler                    ; uipInterruptServiceEngine();  } 
void FLASH_IRQHandler                  (void)    {  uipIntTableID = Int_ID_FLASH_IRQHandler                  ; uipInterruptServiceEngine();  } 
void RCC_IRQHandler                    (void)    {  uipIntTableID = Int_ID_RCC_IRQHandler                    ; uipInterruptServiceEngine();  } 
void EXTI0_IRQHandler                  (void)    {  uipIntTableID = Int_ID_EXTI0_IRQHandler                  ; uipInterruptServiceEngine();  } 
void EXTI1_IRQHandler                  (void)    {  uipIntTableID = Int_ID_EXTI1_IRQHandler                  ; uipInterruptServiceEngine();  } 
void EXTI2_IRQHandler                  (void)    {  uipIntTableID = Int_ID_EXTI2_IRQHandler                  ; uipInterruptServiceEngine();  } 
void EXTI3_IRQHandler                  (void)    {  uipIntTableID = Int_ID_EXTI3_IRQHandler                  ; uipInterruptServiceEngine();  } 
void EXTI4_IRQHandler                  (void)    {  uipIntTableID = Int_ID_EXTI4_IRQHandler                  ; uipInterruptServiceEngine();  } 
void DMA1_Channel1_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel1_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel2_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel2_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel3_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel3_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel4_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel4_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel5_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel5_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel6_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel6_IRQHandler          ; uipInterruptServiceEngine();  } 
void DMA1_Channel7_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA1_Channel7_IRQHandler          ; uipInterruptServiceEngine();  } 
void ADC1_2_IRQHandler                 (void)    {  uipIntTableID = Int_ID_ADC1_2_IRQHandler                 ; uipInterruptServiceEngine();  } 
void USB_HP_CAN1_TX_IRQHandler         (void)    {  uipIntTableID = Int_ID_USB_HP_CAN1_TX_IRQHandler         ; uipInterruptServiceEngine();  } 
void USB_LP_CAN1_RX0_IRQHandler        (void)    {  uipIntTableID = Int_ID_USB_LP_CAN1_RX0_IRQHandler        ; uipInterruptServiceEngine();  } 
void CAN1_RX1_IRQHandler               (void)    {  uipIntTableID = Int_ID_CAN1_RX1_IRQHandler               ; uipInterruptServiceEngine();  } 
void CAN1_SCE_IRQHandler               (void)    {  uipIntTableID = Int_ID_CAN1_SCE_IRQHandler               ; uipInterruptServiceEngine();  } 
void EXTI9_5_IRQHandler                (void)    {  uipIntTableID = Int_ID_EXTI9_5_IRQHandler                ; uipInterruptServiceEngine();  } 
void TIM1_BRK_IRQHandler               (void)    {  uipIntTableID = Int_ID_TIM1_BRK_IRQHandler               ; uipInterruptServiceEngine();  } 
void TIM1_UP_IRQHandler                (void)    {  uipIntTableID = Int_ID_TIM1_UP_IRQHandler                ; uipInterruptServiceEngine();  }                                                                 
void TIM1_TRG_COM_IRQHandler           (void)    {  uipIntTableID = Int_ID_TIM1_TRG_COM_IRQHandler           ; uipInterruptServiceEngine();  } 
void TIM1_CC_IRQHandler                (void)    {  uipIntTableID = Int_ID_TIM1_CC_IRQHandler                ; uipInterruptServiceEngine();  } 
void TIM2_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM2_IRQHandler                   ; uipInterruptServiceEngine();  } 
void TIM3_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM3_IRQHandler                   ; uipInterruptServiceEngine();  } 
void TIM4_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM4_IRQHandler                   ; uipInterruptServiceEngine();  } 
void I2C1_EV_IRQHandler                (void)    {  uipIntTableID = Int_ID_I2C1_EV_IRQHandler                ; uipInterruptServiceEngine();  } 
void I2C1_ER_IRQHandler                (void)    {  uipIntTableID = Int_ID_I2C1_ER_IRQHandler                ; uipInterruptServiceEngine();  } 
void I2C2_EV_IRQHandler                (void)    {  uipIntTableID = Int_ID_I2C2_EV_IRQHandler                ; uipInterruptServiceEngine();  } 
void I2C2_ER_IRQHandler                (void)    {  uipIntTableID = Int_ID_I2C2_ER_IRQHandler                ; uipInterruptServiceEngine();  } 
void SPI1_IRQHandler                   (void)    {  uipIntTableID = Int_ID_SPI1_IRQHandler                   ; uipInterruptServiceEngine();  }
void SPI2_IRQHandler                   (void)    {  uipIntTableID = Int_ID_SPI2_IRQHandler                   ; uipInterruptServiceEngine();  }
void USART1_IRQHandler                 (void)    {  uipIntTableID = Int_ID_USART1_IRQHandler                 ; uipInterruptServiceEngine();  }
void USART2_IRQHandler                 (void)    {  uipIntTableID = Int_ID_USART2_IRQHandler                 ; uipInterruptServiceEngine();  }
void USART3_IRQHandler                 (void)    {  uipIntTableID = Int_ID_USART3_IRQHandler                 ; uipInterruptServiceEngine();  }
void EXTI15_10_IRQHandler              (void)    {  uipIntTableID = Int_ID_EXTI15_10_IRQHandler              ; uipInterruptServiceEngine();  }
void RTCAlarm_IRQHandler               (void)    {  uipIntTableID = Int_ID_RTCAlarm_IRQHandler               ; uipInterruptServiceEngine();  }
void USBWakeUp_IRQHandler              (void)    {  uipIntTableID = Int_ID_USBWakeUp_IRQHandler              ; uipInterruptServiceEngine();  }
void TIM8_BRK_IRQHandler               (void)    {  uipIntTableID = Int_ID_TIM8_BRK_IRQHandler               ; uipInterruptServiceEngine();  }
void TIM8_UP_IRQHandler                (void)    {  uipIntTableID = Int_ID_TIM8_UP_IRQHandler                ; uipInterruptServiceEngine();  }
void TIM8_TRG_COM_IRQHandler           (void)    {  uipIntTableID = Int_ID_TIM8_TRG_COM_IRQHandler           ; uipInterruptServiceEngine();  }
void TIM8_CC_IRQHandler                (void)    {  uipIntTableID = Int_ID_TIM8_CC_IRQHandler                ; uipInterruptServiceEngine();  }
void ADC3_IRQHandler                   (void)    {  uipIntTableID = Int_ID_ADC3_IRQHandler                   ; uipInterruptServiceEngine();  }
void FSMC_IRQHandler                   (void)    {  uipIntTableID = Int_ID_FSMC_IRQHandler                   ; uipInterruptServiceEngine();  }
void SDIO_IRQHandler                   (void)    {  uipIntTableID = Int_ID_SDIO_IRQHandler                   ; uipInterruptServiceEngine();  }
void TIM5_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM5_IRQHandler                   ; uipInterruptServiceEngine();  }
void SPI3_IRQHandler                   (void)    {  uipIntTableID = Int_ID_SPI3_IRQHandler                   ; uipInterruptServiceEngine();  }
void UART4_IRQHandler                  (void)    {  uipIntTableID = Int_ID_UART4_IRQHandler                  ; uipInterruptServiceEngine();  }
void UART5_IRQHandler                  (void)    {  uipIntTableID = Int_ID_UART5_IRQHandler                  ; uipInterruptServiceEngine();  }
void TIM6_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM6_IRQHandler                   ; uipInterruptServiceEngine();  }
void TIM7_IRQHandler                   (void)    {  uipIntTableID = Int_ID_TIM7_IRQHandler                   ; uipInterruptServiceEngine();  }
void DMA2_Channel1_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA2_Channel1_IRQHandler          ; uipInterruptServiceEngine();  }
void DMA2_Channel2_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA2_Channel2_IRQHandler          ; uipInterruptServiceEngine();  }
void DMA2_Channel3_IRQHandler          (void)    {  uipIntTableID = Int_ID_DMA2_Channel3_IRQHandler          ; uipInterruptServiceEngine();  }
void DMA2_Channel4_5_IRQHandler        (void)    {  uipIntTableID = Int_ID_DMA2_Channel4_5_IRQHandler        ; uipInterruptServiceEngine();  }
                                                                                             
/****************************************************************************/
/**
*
* This function is a stub Handler that is the default Handler that gets called
* if the application has not setup a Handler for a specific  interrupt. The
* function interface has to match the interface specified for a Handler even
* though none of the arguments are used.
*
* @param	Data is unused by this function.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
static VOID Chip_UIP_InterruptNullHandler(VOID *Data, VOID *Info)
{
	(VOID)Data;
DieLoop: goto DieLoop;
}

/****************************************************************************/
/**
*
* Initialize interrupt handling for the Processor. The interrupt vector table
* is setup with the stub Handler for all interrupts.
*
* @param	None.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
VOID Chip_UIP_InterruptInit(VOID)
{
	unsigned long index;

	/*
	 * Initialize the vector table. Register the stub Handler for each
	 * interrupt.
	 */
	for(index = 0; index < CHIP_UIP_INTERRUPT_MAX_NUM; index++) {
		if (UIP_Exc_VectorTable[index].Handler == uip_NULL) {
			Chip_UIP_InterruptRegisterHandler(index,
						     Chip_UIP_InterruptNullHandler,
						     uip_NULL,
						     uip_NULL);
		}
	}
}

/*****************************************************************************/
/**
*
* Makes the connection between the Id of the interrupt source and the
* associated Handler that is to run when the interrupt is recognized. The
* argument provided in this call as the Data is used as the argument
* for the Handler when it is called.
*
* @param	interrupt_id contains the ID of the interrupt source and should
*		be in the range of 0 to CHIP_EXCEPTION_ID_LAST.

* @param	Handler to the Handler for that interrupt.
* @param	Data is a reference to Data that will be passed to the
*		Handler when it gets called.
*
* @return	None.
*
* @note		None.
*
****************************************************************************/
VOID Chip_UIP_InterruptRegisterHandler(UIP_UINT32 interrupt_id,
				    Chip_UIP_InterruptHandler Handler,
				    VOID *Data,
				    Chip_UIP_InterruptCallback Callback)
{
    UIP_Exc_VectorTable[interrupt_id].Handler = Handler;
    UIP_Exc_VectorTable[interrupt_id].Data = Data;
    UIP_Exc_VectorTable[interrupt_id].IntControl.uipIntCallBack = Callback;
}

/*****************************************************************************/
/**
*
* Removes the Handler for a specific interrupt Id. The stub Handler is then
* registered for this interrupt Id.
*
* @param	interrupt_id contains the ID of the interrupt source and should
*		be in the range of 0 to CHIP_EXCEPTION_ID_LAST.

* @return	None.
*
* @note		None.
*
****************************************************************************/
VOID Chip_UIP_InterruptRemoveHandler(UIP_UINT32 interrupt_id)
{
    Chip_UIP_InterruptRegisterHandler(interrupt_id,
				       Chip_UIP_InterruptNullHandler,
				       uip_NULL,
				       uip_NULL);
}

/*
*********************************************************************************************************
*
* Description : Handle ARM IRQ and FIQ.
*
*********************************************************************************************************
*/
UIP_UCHAR InterruptHandler(VOID)
{
    UIP_UCHAR                    value = 0;
    UIP_UCHAR                    i;
    UIP_UINT32                   chip_interrupt_id;
    UIP_Exc_VectorTableEntry     *interrupt_vector;
    Chip_UIP_InterruptHandler    handler;
    uipIntCallBackFunction       callback;
    VOID                         *data;

    /* 读取中断ID号 */
    chip_interrupt_id = uipIntTableID;
    
    for(i = 0; i < AppIntNumber; i++) {        
        interrupt_vector = &UIP_Exc_VectorTable[i];        
        if (chip_interrupt_id == interrupt_vector->IntControl.uipIntId) {
            handler = interrupt_vector -> Handler;
            data = interrupt_vector -> Data;
            if(handler != INT_OUTCOME_NULL) {
                (*handler)(data, interrupt_vector -> IntControl.uipInfo);
                /* 执行中断处理程序块中定义的回调函数 */
                callback = interrupt_vector -> IntControl.uipIntCallBack;
				if(callback != INT_OUTCOME_NULL) {
                    value = (*callback)(&(interrupt_vector -> IntControl));
			    }
            }

            /* 清中断 */
            break;
       }
    }
    return value;
}

VOID uipInterruptHandlingCallback(VOID)
{
    UIP_UCHAR    value;
    
    value = InterruptHandler();
    
    if (value == uip_RETURN_FROM_LOW_POWER_MODE) {
        uipLowPowerMode = 0;
    }
} 

/*
************************************************************************************************************************
*
* Description: System Tick interrupt handler.
*
************************************************************************************************************************
*/
VOID  Chip_UIP_Kernel_Tick_ISR_Handler (VOID  *arg, VOID *info)
{    
    uipSystemCounterHandler();
}

UIP_UINT32 Chip_UIP_Kernel_Tick_ISR_Handler_Callback(uipIntPtr intControl)
{
    return 0;
}

/**********************************************************************/
/*                 End of File : chip_uip_interrupt.c                 */
/**********************************************************************/
