/*********************************************************************************************************************
* TC264 Opensourec Library TC264 Դ⣩һڹٷ SDK ӿڵĵԴ
* Copyright (c) 2022 SEEKFREE ɿƼ
*
* ļ TC264 Դһ
*
* TC264 Դ 
* Ըᷢ GPLGNU General Public License GNUͨù֤
*  GPL ĵ3棨 GPL3.0ѡģκκİ汾·/޸
*
* Դķϣܷãδκεı֤
* ûԻʺض;ı֤
* ϸμ GPL
*
* ӦյԴͬʱյһ GPL ĸ
* ûУ<https://www.gnu.org/licenses/>
*
* ע
* Դʹ GPL3.0 Դ֤Э Ϊİ汾
* Ӣİ libraries/doc ļµ GPL3_permission_statement.txt ļ
* ֤ libraries ļ ļµ LICENSE ļ
* ӭλʹò ޸ʱ뱣ɿƼİȨ
*
* ļ          isr
* ˾          ɶɿƼ޹˾
* 汾Ϣ          鿴 libraries/doc ļ version ļ 汾˵
*           ADS v1.9.4
* ƽ̨          TC264D
*           https://seekfree.taobao.com/
*
* ޸ļ¼
*                               ע
* 2022-09-15       pudding            first version
********************************************************************************************************************/

#include "isr_config.h"
#include "isr.h"
#include "ALL_Variables.h"

// TCϵĬǲ֧жǶ׵ģϣ֧жǶҪжʹ interrupt_global_enable(0); жǶ
// 򵥵˵ʵϽжϺTCϵеӲԶ interrupt_global_disable(); ܾӦκεжϣҪԼֶ interrupt_global_enable(0); жϵӦ

// **************************** PITжϺ ****************************
IFX_INTERRUPT(cc60_pit_ch0_isr, 0, CCU6_0_CH0_ISR_PRIORITY)
{
    interrupt_global_enable(0);                     // жǶ
    pit_clear_flag(CCU60_CH0);

    static int Count_X=0;
    static int Count_Y=0;
    static int Count_Z=0;

    if(MotorX_Flag==1)
    {
        Count_X++;
        gpio_toggle_level(PWM_X_Left);
        gpio_toggle_level(PWM_X_Right);
        if(Count_X>=(Step_X*2))//һؼ½صó벽ֵϵ
        {
            Count_X=0;
            Step_X_absolute+=Step_OnceX_relative;//xľ
            MotorX_Flag=0;
        }
    }
    if(MotorY_Flag==1)
    {
        Count_Y++;
        gpio_toggle_level(PWM_Y);
        if(Count_Y>=(Step_Y*2))//һؼ½صó벽ֵϵ
        {
            Step_Y_absolute+=Step_OnceY_relative;//Yľ
            Count_Y=0;
            MotorY_Flag=0;
        }
    }
    if(MotorZ_Flag==1)
    {
        Count_Z++;
        gpio_toggle_level(PWM_Z);
        if(Count_Z>=(Step_Z*2))//һؼ½صó벽ֵϵ
        {
            Step_Z_absolute+=Step_OnceZ_relative;//Yľ
            Count_Z=0;
            MotorZ_Flag=0;
        }
    }



}


IFX_INTERRUPT(cc60_pit_ch1_isr, 0, CCU6_0_CH1_ISR_PRIORITY)
{
    static int Key_Scan_Count=0;

    interrupt_global_enable(0);                     // жǶ
    pit_clear_flag(CCU60_CH1);

    Key_Scan_Count++;
    if(Key_Scan_Count>=20)
    {
        Key_Scan_Count=0;
        Key_Scan();
    }


}

IFX_INTERRUPT(cc61_pit_ch0_isr, 0, CCU6_1_CH0_ISR_PRIORITY)
{
    interrupt_global_enable(0);                     // жǶ
    pit_clear_flag(CCU61_CH0);







}

IFX_INTERRUPT(cc61_pit_ch1_isr, 0, CCU6_1_CH1_ISR_PRIORITY)
{
    interrupt_global_enable(0);                     // жǶ
    pit_clear_flag(CCU61_CH1);




}
// **************************** PITжϺ ****************************


// **************************** ⲿжϺ ****************************
IFX_INTERRUPT(exti_ch0_ch4_isr, 0, EXTI_CH0_CH4_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    if(exti_flag_get(ERU_CH0_REQ0_P15_4))           // ͨ0ж
    {
        exti_flag_clear(ERU_CH0_REQ0_P15_4);

    }

    if(exti_flag_get(ERU_CH4_REQ13_P15_5))          // ͨ4ж
    {
        exti_flag_clear(ERU_CH4_REQ13_P15_5);




    }
}

IFX_INTERRUPT(exti_ch1_ch5_isr, 0, EXTI_CH1_CH5_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ

    if(exti_flag_get(ERU_CH1_REQ10_P14_3))          // ͨ1ж
    {
        exti_flag_clear(ERU_CH1_REQ10_P14_3);

        tof_module_exti_handler();                  // ToF ģ INT ж

    }

    if(exti_flag_get(ERU_CH5_REQ1_P15_8))           // ͨ5ж
    {
        exti_flag_clear(ERU_CH5_REQ1_P15_8);

        wireless_module_spi_handler();              // SPI WIFI жϻص

    }
}

// ͷpclkĬռ 2ͨڴDMAﲻٶжϺ
// IFX_INTERRUPT(exti_ch2_ch6_isr, 0, EXTI_CH2_CH6_INT_PRIO)
// {
//  interrupt_global_enable(0);                     // жǶ
//  if(exti_flag_get(ERU_CH2_REQ7_P00_4))           // ͨ2ж
//  {
//      exti_flag_clear(ERU_CH2_REQ7_P00_4);
//  }
//  if(exti_flag_get(ERU_CH6_REQ9_P20_0))           // ͨ6ж
//  {
//      exti_flag_clear(ERU_CH6_REQ9_P20_0);
//  }
// }

IFX_INTERRUPT(exti_ch3_ch7_isr, 0, EXTI_CH3_CH7_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    if(exti_flag_get(ERU_CH3_REQ6_P02_0))           // ͨ3ж
    {
        exti_flag_clear(ERU_CH3_REQ6_P02_0);
        camera_vsync_handler();                     // ͷɼͳһص
    }
    if(exti_flag_get(ERU_CH7_REQ16_P15_1))          // ͨ7ж
    {
        exti_flag_clear(ERU_CH7_REQ16_P15_1);




    }
}
// **************************** ⲿжϺ ****************************


// **************************** DMAжϺ ****************************
IFX_INTERRUPT(dma_ch5_isr, 0, DMA_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    camera_dma_handler();                           // ͷɼͳһص
}
// **************************** DMAжϺ ****************************


// **************************** жϺ ****************************
IFX_INTERRUPT(uart0_tx_isr, 0, UART0_TX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrTransmit(&uart0_handle);


}
IFX_INTERRUPT(uart0_rx_isr, 0, UART0_RX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrReceive(&uart0_handle);

#if DEBUG_UART_USE_INTERRUPT                        //  debug ж
        debug_interrupr_handler();                  //  debug ڽմ ݻᱻ debug λȡ
#endif                                              // ޸ DEBUG_UART_INDEX δҪŵӦĴжȥ

}
IFX_INTERRUPT(uart0_er_isr, 0, UART0_ER_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrError(&uart0_handle);



}

// 1Ĭӵͷô
IFX_INTERRUPT(uart1_tx_isr, 0, UART1_TX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrTransmit(&uart1_handle);




}
IFX_INTERRUPT(uart1_rx_isr, 0, UART1_RX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrReceive(&uart1_handle);
    camera_uart_handler();                          // ͷͳһص
}
IFX_INTERRUPT(uart1_er_isr, 0, UART1_ER_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrError(&uart1_handle);




}


// 2Ĭӵתģ
IFX_INTERRUPT(uart2_tx_isr, 0, UART2_TX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrTransmit(&uart2_handle);





}
IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrReceive(&uart2_handle);
    wireless_module_uart_handler();                 // ģͳһص

}
IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrError(&uart2_handle);

}



IFX_INTERRUPT(uart3_tx_isr, 0, UART3_TX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrTransmit(&uart3_handle);




}
IFX_INTERRUPT(uart3_rx_isr, 0, UART3_RX_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrReceive(&uart3_handle);

    uart3_receive_Mode0();
    uart3_Analysis();
    gps_uart_callback();


}
IFX_INTERRUPT(uart3_er_isr, 0, UART3_ER_INT_PRIO)
{
    interrupt_global_enable(0);                     // жǶ
    IfxAsclin_Asc_isrError(&uart3_handle);





}
// **************************** жϺ ****************************
