⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvisr.c

📁 mstar 776 开发的车载dvd
💻 C
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 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.
//
// Description: Interrupt Service Routines
//
////////////////////////////////////////////////////////////////////////////////

#define _DRV_ISR_C_

#include <stdio.h>
#include <string.h>
#include <intrins.h>

#include "datatype.h"
#include "board.h"
#include "sysinfo.h"
#include "mreg51.h"
#include "hwreg.h"
#include "Analog_Reg.h"

#include "sramvar.h"
#include "msGPIO.h"
#include "drvvop.h"
#include "drvddc2bi.h"
#include "drvGlobal.h"
#include "drvScaler.h"
#include "drvuart.h"
#include "msIR.h"
#include "drvtimer.h"
#include "drvISR.h"
#include "Drvsys.h"

extern U32 gIRTimeOutCount;

#define INT_USING0 // compiler will handle this, cannot use "using 0"
#define INT_USING1 using 1
#define INT_USING2 using 2
#define INT_USING3 using 3

#define INT_SERVICE_USING( irq, register_bank ) \
    static void CONCAT( irq, _ISR ) ( void ) interrupt CONCAT( INT_, irq ) CONCAT( INT_USING, register_bank )

#define INT_SERVICE( irq ) INT_SERVICE_USING( irq, INT_REGBANK( irq ) )

extern	U16 gTP_X,gTP_Y;
extern U8 g_U8TP_PollingCounter;

// IE0 is auto-cleared by R8051XC (Design Spec Page.38)
INT_SERVICE( EX0 )
{
    U8 data u8IntStatus;
//    BYTE MAD_Mailbox_180;

    u8IntStatus = XBYTE[EX0_INT_FINAL_STATUS_0];
    if ( u8IntStatus )
    {
        XBYTE[EX0_INT_CLEAR_0] = u8IntStatus;
        XBYTE[EX0_INT_CLEAR_0] = 0;
    }

    u8IntStatus = XBYTE[EX0_INT_FINAL_STATUS_1];
    if ( u8IntStatus )
    {
        XBYTE[EX0_INT_CLEAR_1] = u8IntStatus;
        XBYTE[EX0_INT_CLEAR_1] = 0;
    }

    u8IntStatus = XBYTE[EX0_INT_FINAL_STATUS_2];
    if ( u8IntStatus )
    {
        XBYTE[EX0_INT_CLEAR_2] = u8IntStatus;
        XBYTE[EX0_INT_CLEAR_2] = 0;
    }

    u8IntStatus = XBYTE[EX0_INT_FINAL_STATUS_3];
    if ( u8IntStatus )
    {
        XBYTE[EX0_INT_CLEAR_3] = u8IntStatus;
        XBYTE[EX0_INT_CLEAR_3] = 0;

        if ( u8IntStatus & BIT2 )   // 26: INT
        {
            // TODO: Add handler.
            #if( POWER_KEY_PAD_BY_INTERRUPT )
            u8PwrKeypadIntFlag = TRUE;
            #endif
        }

        if ( u8IntStatus & BIT3 )   // 27: IR
        {
            #if (IR_MODE_SEL == IR_TYPE_SWDECODE_MODE)
            MDrv_IR_SW_Isr();
//add by Jason071031 for RC5
            #elif (IR_MODE_SEL == IR_TYPE_RC5_MODE)
             MDrv_IR_SW_Isr();
//end by Jason071031
            #elif (IR_MODE_SEL == IR_TYPE_FULLDECODE_MODE)
            gIRTimeOutCount = MDrv_Timer_GetTime0();
            #endif
        }
        /*if ( u8IntStatus & 0x20 )   //DSP2IP (MAD) interrupt
        {
            // MDrv_AuProcessSetMute( AUDIO_PATH_0, 1 );        // AUDIO MUTE

            MAD_Mailbox_180 = XBYTE[0x2D40];
            //printf("IO_180=%d \r\n", MAD_Mailbox_180);
            if ( MAD_Mailbox_180 == 0x1 )
            {
                //printf("MAD Interrupt - Stop \r\n");
                XBYTE[0x2D36] |= 0x08;                  // for weak signal protect flag on
                XBYTE[0x2D22] = 0x90;                   // equal nop
                XBYTE[0x2D22] = 0x90;                   // equal nop
                XBYTE[0x2DEC] = 0x00;
            }
            if ( MAD_Mailbox_180 == 0x2)
            {
                 //printf("MAD Interrupt - Play \r\n");
                 XBYTE[0x2DEC] = 0x01;
                 XBYTE[0x2D36] &= ~0x08;                // for weak signal protect flag off
            }

            //XBYTE[0x2D22] = 0x10;
            //XBYTE[0x2D22] = 0x10;
            //XBYTE[0x2D22] = 0x10;
            //XBYTE[0x2D22] = 0x00;
            XBYTE[0x2D22] = 0x90;
            XBYTE[0x2D22] = 0x90;
            XBYTE[0x2D22] = 0x90;

#if (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_BTSC)
            XBYTE[0x2D22] = 0x82;
#elif (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_A2)
            XBYTE[0x2D22] = 0x80;
#endif
        }*/
#if 1
        if ( u8IntStatus & BIT7 )   // 31: SAR for Touch Panel
        {
        #if 1//(testboard==1)
		gTP_Y=(MDrv_ReadByte(0x190B)<<8)|MDrv_ReadByte(0x190A);
		gTP_X=(MDrv_ReadByte(0x190D)<<8)|MDrv_ReadByte(0x190C);
        #else
		gTP_X=(MDrv_ReadByte(0x190B)<<8)|MDrv_ReadByte(0x190A);
		gTP_Y=(MDrv_ReadByte(0x190D)<<8)|MDrv_ReadByte(0x190C);
        #endif
        }
#endif
    }
}

// IE1 is auto-cleared by R8051XC (Design Spec Page.38)
INT_SERVICE( EX1 )
{
    U8 data u8IntStatus;

    // not used yet
    //u8IntStatus = XBYTE[EX1_INT_FINAL_STATUS_0];

    u8IntStatus = XBYTE[EX1_INT_FINAL_STATUS_1];
    if ( u8IntStatus )
    {
        if ( u8IntStatus & BIT2 )   // 10: DISP
        {
            MDrv_Scaler_Isr();
        }

    #if ENABLE_HKMCU_CODE_ECC
        if ( u8IntStatus & BIT7 )   // 15: ECC_DERR
        {
            puts("\nECC_DERR!");
            while (1);
        }
    #endif
    }

    u8IntStatus = XBYTE[EX1_INT_FINAL_STATUS_2];
    if ( u8IntStatus )
    {
    #if 0// kill demux (!BOOTLOADER_SYSTEM)
        if ( u8IntStatus & BIT0 )   // 16: TSP2HK
        {
            MDrv_Secisr_Isr();
        }
    #endif

    #ifdef MDrv_VOP_Isr
        if ( u8IntStatus & BIT3 )   // 19: DC
        {
            MDrv_VOP_Isr();
        }
    #endif

        if ( u8IntStatus & BIT7 )   // 23: RTC
        {
            // MDrv_Power_RTCCallback();
        }
    }

    u8IntStatus = XBYTE[EX1_INT_FINAL_STATUS_3];
    if ( u8IntStatus )
    {
    #if ENABLE_DDCCI
        if ( u8IntStatus & BIT2 )   // 26: D2B
        {
#if 0
            MDrv_DDC2BI_Int();
#else
            MDrv_DDC2BI_FF_Int();
#endif
//            MDrv_DDC2BI_IIC();
        }
    #endif
    /*#if (!BOOTLOADER_SYSTEM && ENABLE_CEC)
        if ( u8IntStatus & BIT7 )   // 31: ADCDVI2RIU
        {
            MDrv_CecChkBuf();     // save the buffer for receiving a CEC message.
        }
    #endif*/	// kevin 071206_1
    }
}

INT_SERVICE( EX3 )
{
#ifndef USE_TIMER0_FOR_SYSTEM_TIME
    gSystemTimeCount++;
#endif
}

// dummy isr for stability, don't remove
INT_SERVICE( EX2 ) {}

INT_SERVICE( EX4 ) {}
INT_SERVICE( EX5 ) {}
INT_SERVICE( EX6 ) {}
INT_SERVICE( EX7 ) {}
INT_SERVICE( EX8 ) {}
INT_SERVICE( EX9 ) {}
INT_SERVICE( EX10 ) {}
INT_SERVICE( EX11 ) {}
INT_SERVICE( EX12 ) {}


/******************************************************************************/
/******************************************************************************/
INT_SERVICE( TIMER0 )
{
    TL0 = ISR_TIMER0_COUNTER % 256;
    TH0 = ISR_TIMER0_COUNTER / 256;

    gTimerCount0++;
    gu8100msTH++;

#ifdef USE_TIMER0_FOR_SYSTEM_TIME      // try to use PIU Timer1 for system time count
    gu16SystemTimePeriodTH++;

    /* monitor gSystemTimeCount */
    // Use a threshold to check the system time period. If the threshold
    // is greater or equal than the system time period. Increase the system
    // time counter.
    if (gu16SystemTimePeriodTH >= USER_TIMER_PERIOD)
    {
        gSystemTimeCount++;
        gu16SystemTimePeriodTH = 0;
    }
#endif

    // Use a threshold to check the 100 ms. If the threshold
    // is greater or equal than the 100 ms. Increase the 100 ms
    // counter.
    if (gu8100msTH >= 100)
    {
        g100msTimeCount++;
        gu8100msTH = 0;
    }

#if 1// kevin 071224 //(!BOOTLOADER_SYSTEM)
    //if ( IsAnalogSourceInUse() )
    {
        // mode detect counter
        if (g_ucModeDetectPollingCounter)
            g_ucModeDetectPollingCounter--;

        if (g_VdInfo.ucVideoPollingCounter)
            g_VdInfo.ucVideoPollingCounter--;
    }

        if (g_U8TP_PollingCounter)
            g_U8TP_PollingCounter--;

    //--------------------------------
    //down time counter:
    if ( gTimerDownCount0 > 0 )
        gTimerDownCount0--;

    if ( gTimerDownCount1 > 0 )
        gTimerDownCount1--;
#endif  // #if (!BOOTLOADER_SYSTEM)

#if (IR_MODE_SEL == IR_TYPE_SWDECODE_MODE)
    if(g_ucIrRepeatTimer > 0)//hjkoh 070403 - IR Timeout
        g_ucIrRepeatTimer--;
#endif
    //-------------------------------

    #if (ENABLE_MSTV_UART_DEBUG )
    if (g_Uart0CheckTick)
    {
        --g_Uart0CheckTick;
        if ( g_Uart0CheckTick == 0 )
        {
            g_bUart0Detected = FALSE;//hjkoh 070320
            g_UartCommand.Index = 0;
        }
    }
    #endif
    #if (ENABLE_UART1_INTERRUPT == ENABLE)
    if (g_Uart1CheckTick)
    {
        --g_Uart1CheckTick;
        if ( g_Uart1CheckTick == 0 )
        {
            //g_bUart1Detected = FALSE;//hjkoh 070320
            g_Uart1Command.BuffIndex = 0;
            g_Uart1Command.CommandCRC =0 ;
        }
    }
    #endif
}

INT_SERVICE( TIMER1 ) {}    // dummy isr for stability, don't remove

// use register bank 0 because TT_AcqExecuteProcessing calls a lot of functions
INT_SERVICE_USING( TIMER2, 0 )
{
#ifdef USE_TIMER0_FOR_SYSTEM_TIME      // try to use PIU Timer1 for system time count
    // Standby Mode Timer function
    if ( (XBYTE[PM_OFF_FLAG] & PM_MODE_MASK) == PM_MODE_OFF )
    {
        g10msTimeCount++;
        if ( g10msTimeCount >= 100 )
        {
            g10msTimeCount = 0;
            gSystemTimeCount++;
        }
    }
    else
#endif
    {
    }

    TF2 = 0; // clear timer2 overflow flag
}

#if !ROBUST_TEST_ENABLE
INT_SERVICE( SERIAL0 )
{
    if (!_testbit_(TI)) // check transmit interrupt
    {
    #if (ENABLE_MSTV_UART_DEBUG)
        RI = 0; // clear recieve interrupt

        g_Uart0CheckTick = 50;// time-out control ms

        g_UartCommand.Buffer[g_UartCommand.Index] = SBUF0; // recieve byte

        // check command buffer index
        if (UART_EXT)
        {
            if (g_UartCommand.Index == 0) // check 1st data
                g_UartCommand.Index++; // for get UART_CMD_EXT_LENGTH
            else
            {
                if (g_UartCommand.Index < UART_CMD_EXT_LENGTH) // still read command
                    g_UartCommand.Index++; // next index of command buffer
                if (g_UartCommand.Index >= UART_CMD_EXT_LENGTH) // read command ok
                {
                    g_bUart0Detected = TRUE; // command  buffer recieve ok
                    g_UartCommand.Index = 0; // reset index of command buffer
                    g_Uart0CheckTick = 0;
                }
            }
        }
        else
        {
            if (g_UartCommand.Index < UART_CMD_LENGTH) // still read command
                g_UartCommand.Index++; // next index of command buffer
            if (g_UartCommand.Index >= UART_CMD_LENGTH) // read command ok
            {
                g_bUart0Detected = TRUE; // command  buffer recieve ok
                g_UartCommand.Index = 0; // reset index of command buffer
                g_Uart0CheckTick = 0;
            }
        }
    #else
        RI = 0;
    #endif
    }
}
#else
U8 RobustBuf[8], RobustIndex;
INT_SERVICE( SERIAL0 )
{
    if (_testbit_(RI))
    {
        if (RobustIndex < sizeof(RobustBuf))
            RobustBuf[RobustIndex++] = SBUF;
    }
}
#endif

//---------------------------------------------------------------------------
//Saturn 2: Uart1 interrupt service routine
//
//---------------------------------------------------------------------------
INT_SERVICE( SERIAL1 )
{
    if ( S1CON & BIT0 )  //com1 rx
  	{
        S1CON &= ~BIT0; // clear RI

        g_Uart1CheckTick = 50;// time-out control ms

        g_Uart1Command.Buffer[g_Uart1Command.CommandIndex][g_Uart1Command.BuffIndex] = SBUF1; // recieve byte

        // check command buffer index
        if (UART1_EXT_CMD_ID == UART1_EXT_ID)
        {
            if (g_Uart1Command.BuffIndex == 0) // check 1st data
            {
                g_Uart1Command.CommandCRC+= g_Uart1Command.Buffer[g_Uart1Command.CommandIndex][g_Uart1Command.BuffIndex];
                g_Uart1Command.BuffIndex++; // for get UART_CMD_EXT_LENGTH
            }
            else
            {
                if (g_Uart1Command.BuffIndex < (UART1_EXT_CMD_LENGTH+1)) // still read command
                {
                    g_Uart1Command.CommandCRC+= g_Uart1Command.Buffer[g_Uart1Command.CommandIndex][g_Uart1Command.BuffIndex];
                    g_Uart1Command.BuffIndex++; // next index of command buffer
                }
                else if(g_Uart1Command.BuffIndex == (UART1_EXT_CMD_LENGTH+1))
                    g_Uart1Command.BuffIndex++; // next index of command buffer
                if (g_Uart1Command.BuffIndex >= (UART1_EXT_CMD_LENGTH+2)) // read command ok
                {
                    //g_bUart1Detected = TRUE; // command  buffer recieve ok
                    g_Uart1Command.BuffIndex = 0; // reset index of command buffer
                    g_Uart1CheckTick = 0;
                    if(g_Uart1Command.CommandCRC==g_Uart1Command.Buffer[g_Uart1Command.CommandIndex][UART1_EXT_CMD_LENGTH+1])
                    {
                        putcharUART1(0x55);
                        g_Uart1Command.CommandIndex++;
                        if(g_Uart1Command.CommandIndex>19)
                            g_Uart1Command.CommandIndex=0;
                        if(g_Uart1Command.CommandIndex==g_u8Uart1CommandIndex)
                        {
                            g_Uart1Command.CommandIndex++;
                            if(g_Uart1Command.CommandIndex>19)
                                g_Uart1Command.CommandIndex=0;
                        }
                    }
                    g_Uart1Command.CommandCRC =0 ;
                }
            }
        }
        else if(UART1_EXT_CMD_ID == 0x55&&g_bUart1WaitAck == TRUE)
        {
            g_bUart1Ack = TRUE;
            g_bUart1WaitAck = FALSE;
        }
    }
    else
    {
        S1CON &= ~BIT1; // clear TI
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -