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

📄 msapi_drvinit.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.
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
// @file msAPI_DrvInit.h
// @brief Driver initialization
//
////////////////////////////////////////////////////////////////////////////////

#define _MSAPI_DRVINIT_C_

/******************************************************************************/
/*                            Header Files                                    */
/* ****************************************************************************/

#include "DataType.h"
#include "board.h"
#include "drvcpu.h"
#include "drvmiu.h"
#include "drvtimer.h"
#include "drvsys.h"
#include "drvge.h"
#include "drvgop.h"
#include "drvvop.h"
#include "drvflash.h"
#include "drvuart.h"
#include "drviic.h"
#include "drvsys.h"
#include "drvadc.h"
#include "drvScaler.h"

#include "Msapi_DrvInit.h"
#include "msapi_miu.h"
#include "msAPI_Timer.h"
#include "msAPI_Video.h"
#include "msAPI_GOP.h"
#include "msAPI_Scaler.h"
#include "msAPI_Global.h"
#include "msAPI_VD.h"
#include "Panel.h"
#include "drvpower.h"
#include "mreg51.h"
#include "hwreg.h"
#include "sramvar.h"

#include <stdio.h>
#include "msAPI_ACE.h"
#include "msAPI_DLC.h"
#include "msIR.h"
#include "msGPIO.h"
#include "msKeypad.h"
#include "drvddc2bi.h"
#include "drvSAR.h"
#include "DrvHDMI.h"

#define DRVINIT_DBG(x)   //x


/***************************************************************************************/
/// Initial system and all drivers
/***************************************************************************************/
/*void MDrv_Write2ByteB( U16 u16Reg, U16 u16Value)
{
	u16Reg=(u16Reg&0xFF00)|((u16Reg&0x00FF)*2);
	MDrv_WriteByte(u16Reg,u16Value);
	MDrv_WriteByte(u16Reg+1,u16Value>>8);
}*/

void msAPI_ChipInit(void)
{
#if ( WATCH_DOG == ENABLE )
    MDrv_Sys_SetWatchDogTimer( 15 );
#endif

    MDrv_Sys_Devices_Init();

    if( MDrv_ReadByte(PM_OFF_FLAG) == 0x00 )
    {
        msAPI_Timer_SetSystemTime (630720000);
        g_u8WakeUpOnOffFlag = 0;
        g_u8WakeUpTime[0] = 0;
        g_u8WakeUpTime[1] = 0;
        g_u32WakeupSystemTime = 0xFFFFFFFF;
    }

#if (IR_MODE_SEL == IR_TYPE_SWDECODE_MODE)
    MDrv_Sys_SetInterrupt( EX0, ENABLE );
    MDrv_Sys_SetInterrupt( EX1, ENABLE );
    MDrv_Sys_SetInterrupt( GLOBAL, ENABLE );
#endif

    msIR_Initialize(MST_XTAL_CLOCK_MHZ);

#if (IR_MODE_SEL == IR_TYPE_SWDECODE_MODE)
    MDrv_Sys_SetInterrupt( EX0_IR, ENABLE );
#endif

    DRVINIT_DBG(printf("msAPI_ChipInit done....\r\n"));
}

/*BOOLEAN msAPI_Power_Is1STBootUp()
{
    return MDrv_Power_Is1STBootUp();
}

BOOLEAN msAPI_Power_IsPowerDown()
{
    return MDrv_Power_IsPowerDown();
}*/

void msAPI_Power_PowerDown_EXEC()
{
    MDrv_Power_ExecutePowerDown();
    MDrv_Power_Standby();
}

/*void msAPI_PowerON_EXEC()
{
    MDrv_Power_SetMode(PM_MODE_ON);
}*/

#if 0
static void Factory_MemoryCheck( void )
{
    if( MDrv_Flash_GetFactoryTestSetting() != 0x00 )
        return;

    if( u8FactoryTest == 0x00 )
        return;

    MDrv_Timer_Init0();
    MDrv_Sys_SetInterrupt( TIMER0, ENABLE );
    MDrv_Sys_SetInterrupt( GLOBAL, ENABLE );

    msGPIO_Init();

    //msAPI_Scaler_Init();
    MDrv_Scaler_Init();

    MDrv_Scaler_SetFreeRunWindow();
    MDrv_Scaler_SetFreeRunTiming();

    MDrv_Scaler_SetFreeRunColor(FREE_RUN_COLOR_RED);

    while( 1 );
}
#endif

/******************************************************************************/
/// Initial system and all drivers
/******************************************************************************/
void msAPI_DrvInit(void)
{
//    U8 test[16];
//    U8 i;
//    MDrv_Sys_Devices_Init();
    DRVINIT_DBG(puts("\r\nInit Sys, Drv Start....."));// kevin test

#if ENABLE_DDCCI
	msAPI_SI2C_Init();
#endif

    /* scaler intialization */ // seven 070821
#if 1// kevin 071224 //(!BOOTLOADER_SYSTEM)
    msAPI_Scaler_Init();
#else
    MDrv_Scaler_InitToFreeRun();
#endif

	// seven 070821
    MDrv_Change_CPU_Speed(MCU_CLOCK_SEL);
    MDrv_Change_SPI_Speed(SPI_CLOCK_SEL);// kevin JJ
    MDrv_Change_VD_Speed(VDMCU_CLOCK_SEL);

    MDrv_Write2Byte(BK_19_00_L,0x7F00);  //{8'h19,7'h00} div_sample clock period.
	MDrv_Write2Byte(BK_19_01_L,0x0008);  // scan_times[7:0]
	MDrv_Write2Byte(BK_19_02_L,0x0008);  // counter_times[7:0].

#if (SCALER_TYPE <= MOSES_U03)
	MDrv_Write2Byte(BK_19_03_L,0x0010);  // boundary code
#else
	MDrv_Write2Byte(BK_19_03_L,0x0000);
#endif

	MDrv_Write2Byte(BK_19_04_L,0x0010);  // error code.

#if (SCALER_TYPE <= MOSES_U03)
	MDrv_Write2Byte(BK_19_00_L,0xFF00);  //{8'h19,7'h00} div_sample clock period.
#else
	MDrv_Write2Byte(BK_19_00_L,0xFF03);  //{8'h19,7'h00} div_sample clock period.
#endif

    MDrv_Power_ExecutePowerUp();

#if 1
    if (CHIP_HAS_DMA_CRC16)
    {
        // default use CRC16 f = X16 + X15 + X2 + X0
        MDrv_DMA_SetCrcPolynomial(0x8005);
        MDrv_DMA_SetCrcInitial(0);
        MDrv_DMA_EnableCrc(1);
        DRVINIT_DBG(printf("Init CRC16"));
    }

    if (MDrv_Sys_IsCodeInSPI())
    {
        if (CHIP_HAS_DMA_CRC16)
            MDrv_DMA_ClearCrc();

        MDrv_MIU_Copy(0L,CODE_MAP_BASE_ADR,CODE_MAP_LEN, MIU_FLASH2SDRAM);
        //DRVINIT_DBG(printf("\r\nCopy Bank0 code from FLASH to SDRAM!\r\n"));
        printf("\r\nCopy Bank0 code from FLASH to SDRAM!\r\n");

        if (CHIP_HAS_DMA_CRC16)
            printf("CODE CRC16: %04x\n", MDrv_DMA_GetCrcResult());

        MDrv_Sys_ClearWatchDog();

        MDrv_Sys_Set_ECC_DMA(DISABLE);

        MDrv_Sys_RunCodeInMIU(CODE_MAP_BASE_ADR / SYSTEM_BANK_SIZE, CODE_MAP_LEN/SYSTEM_BANK_SIZE, ENABLE_HKMCU_ICACHE_BYPASS);
//        MDrv_Sys_RunCodeInMIU(CODE_MAP_BASE_ADR / SYSTEM_BANK_SIZE, SYSTEM_BANK_NUM, ENABLE_HKMCU_ICACHE_BYPASS);

        //DRVINIT_DBG(printf("\r\n Copy OK and Start run code in SDRAM!\r\n"));
        printf("\r\nStart run code in SDRAM!\r\n");

        MDrv_MIU_Protect(0,MCU_WRITE_ID, (CODE_MAP_BASE_ADR),(CODE_MAP_BASE_ADR+CODE_MAP_LEN-1),ENABLE);
    }
#endif

#if 0
    #if POWER_DOWN_SEQ
    if(MDrv_Power_IsPowerDown())
    {
        MDrv_Power_ExecutePowerDown();
        MDrv_Power_Standby();
    }

    MDrv_Power_SetMode(PM_MODE_ON);
    #endif

    #if (!BOOTLOADER_SYSTEM)
    Factory_MemoryCheck();
    #endif
#endif

    MDrv_SerFlash_Init();
    DRVINIT_DBG(printf("flash init done.....\r\n"));


// 070821 seven
//    MDrv_Change_CPU_Speed(MCU_CLOCK_SEL);
//    MDrv_Change_SPI_Speed(SPI_CLOCK_SEL);// kevin JJ
// end

    /* init timer0 and its interrupt */
    MDrv_Timer_Init0();
    MDrv_Sys_SetInterrupt( TIMER0, ENABLE );

    /* enable external interrupt */
    MDrv_Sys_SetInterrupt( EX0, ENABLE );
    MDrv_Sys_SetInterrupt( EX1, ENABLE );
    MDrv_Sys_SetInterrupt( EX3, ENABLE );
    MDrv_Sys_SetInterrupt( GLOBAL, ENABLE );

    DRVINIT_DBG(printf("\r\n *** Init INT done ***"));   // kevin test

    /* init MIU */
    msAPI_MIU_Init();

    /* init IR */
    msIR_Initialize(MST_XTAL_CLOCK_MHZ);

//add by Jason071031 for RC5
#if (IR_MODE_SEL == IR_TYPE_RC5_MODE)
    MDrv_Sys_SetInterrupt( EX0_IR, ENABLE );
    MDrv_Sys_SetInterrupt( EX0_EDGE_TRIGGER, DISABLE );
#endif
//end by Jason071031

#if (IR_MODE_SEL == IR_TYPE_SWDECODE_MODE || IR_MODE_SEL == IR_TYPE_FULLDECODE_MODE)
    MDrv_Sys_SetInterrupt( EX0_IR, ENABLE );
#endif

#if( POWER_KEY_PAD_BY_INTERRUPT )
    MDrv_Sys_SetInterrupt(EX0_INT_IN, ENABLE);
#endif

    drvInitialSAR();

    /* init KeyPad */
   msKeypad_Init();

    /* init Graphics Engine */
    MDrv_GE_Init( 400, 200, CC_USE_123433);   // frame size = full screen

    DRVINIT_DBG(printf("\r\n *** Init GE done ***"));   // kevin test

    MDrv_GOP_Init();            // Must be called after MDrv_GE_Init()

    DRVINIT_DBG(printf("\r\n *** Init GOP done ***"));   // kevin test

    /* Init IIC */
    //MDrv_IIC_Init();

    /* Init GPIO */
   msGPIO_Init();

    #if ( MS_BOARD_TYPE_SEL == BD_MST7702_DEMO_B02A)
    //GPIOWrite(1, 1);// Dyson asked 071101_3
    PANEL_POWER_ON;
    #endif

    /* video decoder initalization */

#if 1// kevin 071224 //(!BOOTLOADER_SYSTEM)
    #if 0
    msAPI_VD_BIN_Select(VD_BIN_SEL_NTSC);
	#else
    msAPI_VD_BIN_Select(VD_BIN_SEL_AUTO);
    #endif
    msAPI_VD_Init();
#endif
    DRVINIT_DBG(printf("\r\n *** Init VD done ***"));   // kevin test
    DRVINIT_DBG(puts("\r\nInit Sys, Drv done....."));// kevin test

#if (HDMI_CHIP_SEL != HDMI_CHIP_NONE)
    devHDMIInitialize();
    DRVINIT_DBG(printf("\r\n *** Init HDMI ***"));   // kevin test
#endif

    MDrv_UART_Init();
}

BOOLEAN msAPI_Power_IsWakeUpByOnTimer(void)
{
    return (BOOLEAN)MDrv_Power_IsWakeUpByOnTimer();
}

void msAPI_Sys_UartControl(BOOLEAN bEnable)
{
    MDrv_Sys_UartControl(bEnable);
}
#undef _MSAPI_DRVINIT_C_

⌨️ 快捷键说明

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