//<MStar Software>
//******************************************************************************
// MStar Software
// Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
// All software, firmware and related documentation herein ("MStar Software") are
// intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
// law, including, but not limited to, copyright law and international treaties.
// Any use, modification, reproduction, retransmission, or republication of all
// or part of MStar Software is expressly prohibited, unless prior written
// permission has been granted by MStar.
//
// By accessing, browsing and/or using MStar Software, you acknowledge that you
// have read, understood, and agree, to be bound by below terms ("Terms") and to
// comply with all applicable laws and regulations:
//
// 1. MStar shall retain any and all right, ownership and interest to MStar
//    Software and any modification/derivatives thereof.
//    No right, ownership, or interest to MStar Software and any
//    modification/derivatives thereof is transferred to you under Terms.
//
// 2. You understand that MStar Software might include, incorporate or be
//    supplied together with third party`s software and the use of MStar
//    Software may require additional licenses from third parties.
//    Therefore, you hereby agree it is your sole responsibility to separately
//    obtain any and all third party right and license necessary for your use of
//    such third party`s software.
//
// 3. MStar Software and any modification/derivatives thereof shall be deemed as
//    MStar`s confidential information and you agree to keep MStar`s
//    confidential information in strictest confidence and not disclose to any
//    third party.
//
// 4. MStar Software is provided on an "AS IS" basis without warranties of any
//    kind. Any warranties are hereby expressly disclaimed by MStar, including
//    without limitation, any warranties of merchantability, non-infringement of
//    intellectual property rights, fitness for a particular purpose, error free
//    and in conformity with any international standard.  You agree to waive any
//    claim against MStar for any loss, damage, cost or expense that you may
//    incur related to your use of MStar Software.
//    In no event shall MStar be liable for any direct, indirect, incidental or
//    consequential damages, including without limitation, lost of profit or
//    revenues, lost or damage of data, and unauthorized system use.
//    You agree that this Section 4 shall still apply without being affected
//    even if MStar Software has been modified by MStar in accordance with your
//    request or instruction for your use, except otherwise agreed by both
//    parties in writing.
//
// 5. If requested, MStar may from time to time provide technical supports or
//    services in relation with MStar Software to you for your use of
//    MStar Software in conjunction with your or your customer`s product
//    ("Services").
//    You understand and agree that, except otherwise agreed by both parties in
//    writing, Services are provided on an "AS IS" basis and the warranty
//    disclaimer set forth in Section 4 above shall apply.
//
// 6. Nothing contained herein shall be construed as by implication, estoppels
//    or otherwise:
//    (a) conferring any license or right to use MStar name, trademark, service
//        mark, symbol or any other identification;
//    (b) obligating MStar or any of its affiliates to furnish any person,
//        including without limitation, you and your customers, any assistance
//        of any kind whatsoever, or any information; or
//    (c) conferring any license or right under any intellectual property right.
//
// 7. These terms shall be governed by and construed in accordance with the laws
//    of Taiwan, R.O.C., excluding its conflict of law rules.
//    Any and all dispute arising out hereof or related hereto shall be finally
//    settled by arbitration referred to the Chinese Arbitration Association,
//    Taipei in accordance with the ROC Arbitration Law and the Arbitration
//    Rules of the Association by three (3) arbitrators appointed in accordance
//    with the said Rules.
//    The place of arbitration shall be in Taipei, Taiwan and the language shall
//    be English.
//    The arbitration award shall be final and binding to both parties.
//
//******************************************************************************
//<MStar Software>
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2009 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// ("MStar Confidential Information") by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
/// file    Mdrv_sc_isr.c
/// @brief  Driver Interface
/// @author MStar Semiconductor Inc.
///////////////////////////////////////////////////////////////////////////////////////////////////
#define _MHAL_XC_ISR_C_

//-------------------------------------------------------------------------------------------------
//  Include Files
//-------------------------------------------------------------------------------------------------
// Common Definition
#ifdef MSOS_TYPE_LINUX_KERNEL
#include <linux/sched.h>  // for task_normal
#endif
#include "MsCommon.h"
#include "MsOS.h"
#include "mhal_xc_chip_config.h"

// Internal Definition
#include "utopia.h"
#include "utopia_dapi.h"
#include "drvXC_IOPort.h"
#include "xc_hwreg_utility2.h"
#include "hwreg_sc.h"
#include "apiXC.h"
#include "apiXC_Adc.h"
#include "apiXC_Auto.h"
#include "apiXC_ModeParse.h"
#include "drvXC_HDMI_if.h"
#include "drv_sc_display.h"
#include "apiXC_PCMonitor.h"
#include "mvideo_context.h"
#include "drv_sc_ip.h"
#if (LD_ENABLE==1)
#include "mdrv_ld.h"
#include "mdrv_ldalgo.h"
#endif
#include "mdrv_sc_3d.h"
#include "xc_Analog_Reg.h"
#include "mhal_sc.h"
#include "drv_sc_menuload.h"
#include "drvXC_ADC_Internal.h"
#if FRC_INSIDE
#include "mdrv_frc.h"
#include "mhal_frc.h"
#endif
#include "drv_sc_isr.h"
#include "XC_private.h"
//-------------------------------------------------------------------------------------------------
//  Driver Compiler Options
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//  Local Defines
//-------------------------------------------------------------------------------------------------
#define SC_ISR_DBG(x)       //x
#define IRQ_L             (16)//Original ISR 0~15
#define IRQ_H             (32)//Original ISR 16~31
#define EXT_IRQ_L         (48)//Extend ISR 32~47
#define EXT_IRQ_H         (64)//Extend ISR 48~63
//-------------------------------------------------------------------------------------------------
//  Local Structurs
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//  Global Variables
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//  Local Variables
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//  Debug Functions
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//  Local Functions
//-------------------------------------------------------------------------------------------------
#if IRQ_CLEAN_INKERNEL
static MS_U64 _MHal_XC_GetDummyDispIRQ(void *pInstance)
{
    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);

    MS_U32 u32DummyReg = (MS_U32)SC_R2BYTE(psXCInstPri->u32DeviceID, CFD_PLUS_INTERRUPT_DUMMY_REGISTER);
    MS_U8 u8DummyMappingTable[IRQ_INT_DISP_NUM] = DUMMY_MAPPING_TABLE_ARRAY;
    MS_U64 u64IRQNum = 0; //CID:328701, Bad bit shift operation for u64IRQNum @Crixus 20180517
    MS_U64 u64DummyDispIRQ = 0;

    for (u64IRQNum = 0; u64IRQNum < IRQ_INT_DISP_NUM; u64IRQNum++)
    {
        MS_U8 u8DummyMappingBit = u8DummyMappingTable[u64IRQNum];
        if (u8DummyMappingBit < IRQ_INT_DISP_DUMMY_NUM)
        {
            if(u32DummyReg & (BIT(u8DummyMappingBit)))
            {
                u64DummyDispIRQ |= BIT_64(u64IRQNum);
            }
        }
    }

    return u64DummyDispIRQ;
}
#endif

//-------------------------------------------------------------------------------------------------
//  Global Functions
//-------------------------------------------------------------------------------------------------


/******************************************************************************/
/*                           Local Variables                                    */
/******************************************************************************/

/******************************************************************************/
/*               P r i v a t e    F u n c t i o n s                             */
/******************************************************************************/
//-------------------------------------------------------------------------------------------------

MS_U64 MHal_XC_GetInterrupt(void *pInstance)
{
    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
    MS_U64 u64Reg = (MS_U64)SC_EXT_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_STATUS_L);
#if IRQ_CLEAN_INKERNEL
    XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;

    UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));

    MS_U8 u8CFDVersion = pXCResourcePrivate->stdrvXC_Display._u8CFDVersion;

    if (u8CFDVersion == CFD_PLUS_VERSION)
    {
        MS_U64 u64DummyReg = _MHal_XC_GetDummyDispIRQ(pInstance);

        return u64DummyReg;
    }
    else
    {
        MS_U64 u64DummyReg = (MS_U64)SC_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_DUMMY_REGISTER);
#if (IRQ_EXPAND == 1) && (SUPPORT_SCALER_EXT_REG == 1)
        u64Reg = (u64Reg | ((MS_U64)SC_EXT_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_EXT_STATUS_L) << 32));
        u64DummyReg = (u64DummyReg | ((MS_U64)SC_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_EXT_DUMMY_REGISTER_L) << 32));
#endif
#if (IRQ_REFINE == 1)
        return (u64Reg | u64DummyReg);
#else
        return u64Reg|(u64DummyReg&(SUPPORTED_KERNEL_INT >> (SC_INT_START - IRQ_INT_START)));
#endif
    }
#else
    return u64Reg;
#endif
}

#if (IRQ_REFINE == 1)
static void _MHal_XC_ClearInterruptInKernel(void *pInstance, SC_INT_SRC u8IntSrc)
{
    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);

    MS_U8 u8IntRemap = MDrv_XC_GetIntSrc(u8IntSrc);

    if(u8IntRemap != IRQ_INT_NOT_DEFINED)
    {
#if IRQ_CLEAN_INKERNEL
        if(u8IntRemap < IRQ_L)
        {
            SC_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_DUMMY_REGISTER, 0, BIT(u8IntRemap));
        }
        else if(u8IntRemap >= IRQ_L && u8IntRemap < IRQ_H)
        {
            SC_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_DUMMY_REGISTER_H, 0, BIT(u8IntRemap-IRQ_L));
        }
#if (IRQ_EXPAND == 1) && (SUPPORT_SCALER_EXT_REG == 1)
        else if(u8IntRemap >= IRQ_H && u8IntRemap < EXT_IRQ_L)
        {
            SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_DUMMY_REGISTER_L, 0, BIT(u8IntRemap-IRQ_H));
        }
        else if(u8IntRemap >= EXT_IRQ_L && u8IntRemap < EXT_IRQ_H)
        {
            SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_DUMMY_REGISTER_H, 0, BIT(u8IntRemap-EXT_IRQ_L));
        }
#endif
#else
#if defined(UFO_XC_HDR) && defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION >= 2)
        if(u8IntRemap < 16)
        {
            if((u8IntRemap != IRQ_INT_F2_IPVS_SB))
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L , BIT(u8IntRemap),BIT(u8IntRemap));
            }
        }
        else
        {
            //IRQ_INT_PWM_RP_R_INT and IRQ_INT_PWM_FP_R_INT  will be cleaned in kernel
            if((u8IntRemap != IRQ_INT_PWM_RP_R_INT) && (u8IntRemap != IRQ_INT_PWM_FP_R_INT))
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , BIT(u8IntRemap-IRQ_L), BIT(u8IntRemap-IRQ_L));
            }
        }
#else
        if(u8IntRemap < 16)
        {
            SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L, BIT(u8IntRemap), BIT(u8IntRemap));
        }
        else
        {
            SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , BIT(u8IntRemap-IRQ_L) ,BIT(u8IntRemap-IRQ_L));
        }
#endif
#endif
    }
}

#else
static void _MHal_XC_ClearInterruptWithKernel(void *pInstance, SC_INT_SRC u8IntSrc)
{
    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);

    MS_U8 u8IntRemap = MDrv_XC_GetIntSrc(u8IntSrc);

    if(u8IntRemap != IRQ_INT_NOT_DEFINED)
    {
        if(u8IntRemap < 16)
        {
#if IRQ_CLEAN_INKERNEL
            MS_U32 u32DummyReg = SC_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_DUMMY_REGISTER);

            if(SUPPORTED_KERNEL_INT&(1ULL << u8IntSrc))
            {
                if( u32DummyReg&(1ULL << u8IntRemap))
                {
                    SC_W2BYTEMSK(psXCInstPri->u32DeviceID,INTERRUPT_DUMMY_REGISTER,0, (1ULL << (u8IntRemap)));
                }
                else
                {
                    SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L , BIT(u8IntRemap),BIT(u8IntRemap));
                    SC_W2BYTEMSK(psXCInstPri->u32DeviceID,INTERRUPT_DUMMY_REGISTER, (1ULL << u8IntRemap), (1ULL << u8IntRemap));
                }
            }
            else
#endif
            {
#if defined(UFO_XC_HDR) && defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION >= 2)
                if((u8IntRemap != IRQ_INT_F2_IPVS_SB))
                {
                    SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L , BIT(u8IntRemap),BIT(u8IntRemap));
                }
#else
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L , BIT(u8IntRemap),BIT(u8IntRemap));
#endif
            }
        }
        else
        {
#if IRQ_CLEAN_INKERNEL
            //IRQ_INT_PWM_RP_R_INT and IRQ_INT_PWM_FP_R_INT is dummy will be cleaned in kernel
            MS_U32 u32DummyReg = SC_R4BYTE(psXCInstPri->u32DeviceID, INTERRUPT_DUMMY_REGISTER);

            if(SUPPORTED_KERNEL_INT&(1ULL << u8IntSrc))
            {
                if( u32DummyReg&(1ULL << u8IntRemap))
                {
                    SC_W2BYTEMSK(psXCInstPri->u32DeviceID,INTERRUPT_DUMMY_REGISTER_H,0, (1ULL << (u8IntRemap-16)));
                }
                else
                {
                    SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , BIT(u8IntRemap-16) ,BIT(u8IntRemap-16));
                    SC_W2BYTEMSK(psXCInstPri->u32DeviceID,INTERRUPT_DUMMY_REGISTER_H, (1ULL << (u8IntRemap-16)), (1ULL << (u8IntRemap-16)));
                }
            }
            else
#endif
            {
#if defined(UFO_XC_HDR) && defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION >= 2)
                //IRQ_INT_PWM_RP_R_INT and IRQ_INT_PWM_FP_R_INT  will be cleaned in kernel
                if((u8IntRemap != IRQ_INT_PWM_RP_R_INT) && (u8IntRemap != IRQ_INT_PWM_FP_R_INT))
                {
                    SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , BIT(u8IntRemap-16) ,BIT(u8IntRemap-16));
                }
#else
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , BIT(u8IntRemap-16) ,BIT(u8IntRemap-16));
#endif
            }
        }
    }
}
#endif

void MHal_XC_ClearInterrupt(void *pInstance, SC_INT_SRC u8IntSrc)
{
#if IRQ_CLEAN_INKERNEL
    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
    XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;

    UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));

    MS_U8 u8CFDVersion = pXCResourcePrivate->stdrvXC_Display._u8CFDVersion;

    if (u8CFDVersion == CFD_PLUS_VERSION)
    {
        MS_U8 u8IntRemap = MDrv_XC_GetIntSrc(u8IntSrc);
        MS_U32 u32DummyReg = SC_R2BYTE(psXCInstPri->u32DeviceID, CFD_PLUS_INTERRUPT_DUMMY_REGISTER);
        MS_U8 u8DummyMappingTable[IRQ_INT_DISP_NUM] = DUMMY_MAPPING_TABLE_ARRAY;
        MS_U8 u8DummyMappingBit = 0xFF;

        if(u8IntRemap != IRQ_INT_NOT_DEFINED)
        {
            u8DummyMappingBit = u8DummyMappingTable[u8IntRemap];
        }

        if (u8DummyMappingBit < IRQ_INT_DISP_DUMMY_NUM)
        {
            if (u32DummyReg & BIT(u8DummyMappingBit))
            {
                SC_W2BYTEMSK(psXCInstPri->u32DeviceID, CFD_PLUS_INTERRUPT_DUMMY_REGISTER, 0, BIT(u8DummyMappingBit));
            }
            else
            {
                SC_W2BYTEMSK(psXCInstPri->u32DeviceID, CFD_PLUS_INTERRUPT_DUMMY_REGISTER, BIT(u8DummyMappingBit), BIT(u8DummyMappingBit));
            }
        }
        else
        {
            printf("IRQ Reg BIT(%d) mapping to BIT(%d) fail!!!\n", u8IntRemap, u8DummyMappingBit);
        }
    }
    else
#endif
    {
#if (IRQ_REFINE == 1)
        _MHal_XC_ClearInterruptInKernel(pInstance, u8IntSrc);
#else
        _MHal_XC_ClearInterruptWithKernel(pInstance, u8IntSrc);
#endif
    }
}

void MHal_XC_SetInterrupt(void *pInstance, SC_INT_SRC u8IntSrc, MS_BOOL bEnable)
{
#if (!ENABLE_REGISTER_SPREAD)
    MS_U8 u8Bank;
#endif
    MS_U8 u8IntRemap = MDrv_XC_GetIntSrc(u8IntSrc);

#if (!ENABLE_REGISTER_SPREAD)
    u8Bank = MDrv_ReadByte(BK_SELECT_00);
#endif

    XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
    UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);

    if(u8IntRemap != IRQ_INT_NOT_DEFINED)
    {
        if(bEnable)
        {
            if(u8IntRemap < IRQ_L)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L ,BIT(u8IntRemap),BIT(u8IntRemap));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_MASK_L , 0 ,BIT(u8IntRemap));
            }
            else if(u8IntRemap >= IRQ_L && u8IntRemap < IRQ_H)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H ,BIT(u8IntRemap-IRQ_L),BIT(u8IntRemap-IRQ_L));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_MASK_H , 0 ,BIT(u8IntRemap-IRQ_L));
            }
#if (IRQ_EXPAND == 1) && (SUPPORT_SCALER_EXT_REG == 1)
            else if(u8IntRemap >= IRQ_H && u8IntRemap < EXT_IRQ_L)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_CLEAR_L ,BIT(u8IntRemap-IRQ_H),BIT(u8IntRemap-IRQ_H));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_MASK_L , 0 ,BIT(u8IntRemap-IRQ_H));
            }
            else if(u8IntRemap >= EXT_IRQ_L && u8IntRemap < EXT_IRQ_H)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_CLEAR_H ,BIT(u8IntRemap-EXT_IRQ_L),BIT(u8IntRemap-EXT_IRQ_L));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_MASK_H , 0 ,BIT(u8IntRemap-EXT_IRQ_L));
            }
#endif
        }
        else
        {
            if(u8IntRemap < IRQ_L)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_MASK_L , BIT(u8IntRemap),BIT(u8IntRemap));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_L , 0,BIT(u8IntRemap));
            }
            else if(u8IntRemap >= IRQ_L && u8IntRemap < IRQ_H)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_MASK_H ,BIT(u8IntRemap-IRQ_L),BIT(u8IntRemap-IRQ_L));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_CLEAR_H , 0 ,BIT(u8IntRemap-IRQ_L));
            }
#if (IRQ_EXPAND == 1) && (SUPPORT_SCALER_EXT_REG == 1)
            else if(u8IntRemap >= IRQ_H && u8IntRemap < EXT_IRQ_L)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_MASK_L , BIT(u8IntRemap-IRQ_H),BIT(u8IntRemap-IRQ_H));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_CLEAR_L , 0,BIT(u8IntRemap-IRQ_H));
            }
            else if(u8IntRemap >= EXT_IRQ_L && u8IntRemap < EXT_IRQ_H)
            {
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_MASK_H ,BIT(u8IntRemap-EXT_IRQ_L),BIT(u8IntRemap-EXT_IRQ_L));
                SC_EXT_W2BYTEMSK(psXCInstPri->u32DeviceID, INTERRUPT_EXT_CLEAR_H , 0 ,BIT(u8IntRemap-EXT_IRQ_L));
            }
#endif
        }
    }
#if (!ENABLE_REGISTER_SPREAD)
    MDrv_WriteByte(BK_SELECT_00, u8Bank);
#endif
}

#undef _MHAL_XC_ISR_C_

