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

📄 power.c

📁 车载 液晶显示器的主控程序(主要使用芯片为 MYSON MTV512 单片机、RealTek 2323 Scare 芯片、TVP5147(视频解码)。配Sharp 8寸液晶显示器 )。
💻 C
字号:
//----------------------------------------------------------------------------------------------------
// ID Code      : Power.c No.0001
// Update Note  : 
//
//----------------------------------------------------------------------------------------------------

#define __POWER__

#include "..\Header\Include.h"


//--------------------------------------------------
// Description  : Check if the power status changed
// Input Value  : None
// Output Value : Return _TRUE if power status is changed, _FALSE if not
//--------------------------------------------------
bit CPowerHandler(void)
{
    	if(GET_POWERSWITCH())		//if power status changed. note by zhang_dc
    	{
        	CPowerControl();
        	CLR_POWERSWITCH();

        	return _TRUE;
    	}

    	return _FALSE;
}

//--------------------------------------------------
// Description  : Execute power up/down process
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerControl(void)
{
	//20050810, update: power switch cause power up under sleep mode, by request
	if (ucCurrState == _SLEEP_STATE) {
		CLR_POWERSTATUS();
	}

    	if(GET_POWERSTATUS())       // Power Down Process
    	{
			//x.hu, mute audio
			#if (_CUSTOM_TYPE == _CUSTOM_NONE)
			#if (_AUDIO_DEVICE != _AUDIO_NONE)
			CAudioSelChannel(_AUDIO_CHANNEL_NC);
			#endif
			#endif
			
			#if (_CUSTOM_TYPE == _CUSTOM_HAOZHEN)
			#if (_AUDIO_DEVICE != _AUDIO_NONE || _FM_MODULATION == _ENABLE)
			CAudioSelChannel(_AUDIO_CHANNEL_NC);
			#endif
			LED_Message_HaoZhen(LED_MSG_GREEN);
			CTimerDelayXms(50);
			LED_Message_HaoZhen(LED_MSG_BLACK);
			#endif
			
        	CLR_POWERSTATUS();
		COsdFxDisableOsd();//  XYW
        	CPowerPanelOff();
        	CPowerADCAPLLOff();
        	CPowerLVDSOff();
        	CPowerDPLLOff();
        	CPowerTMDSOff();
        	CScalerSetByte(_HOST_CTRL_01, 0x02);			//Enable power saving mode. note by zhang_dc
        	//CEepromSaveSystemData();					//Save power status.  Disabled by zhang_dc


		CTimerCancelTimerEvent(CModeNoSignalEvent);
		CTimerCancelTimerEvent(CModeNoCableEvent);
		CTimerCancelTimerEvent(CModeNoSupportEvent);
		CTimerCancelTimerEvent(CModePowerSavingEvent);
		CTimerCancelTimerEvent(COsdDispOsdTimerEvent);	//x.hu, add for event cancel

        	CEepromSavePowerStatus();					//Add by zhang_dc for saving power status.
			#if (_VIDEO_SUPPORT == _ON)
        	//cut off video
        	CVideoDataEnable(_OFF);						//Add by zhang_dc
        	CVideoPowerState(_VIDEO_POWER_SAVING);	//Add by zhang_dc
			#endif
			LED_Message(LED_MSG_BLACK);				// evan 050512

			//x.hu, mute audio
			#if (_CUSTOM_TYPE == _CUSTOM_NONE)
			#if (_AUDIO_DEVICE != _AUDIO_NONE)
			CAudioSelChannel(_AUDIO_CHANNEL_NC);
			#endif
			#endif
			
			#if (_CUSTOM_TYPE == _CUSTOM_HAOZHEN)
			#if (_AUDIO_DEVICE != _AUDIO_NONE || _FM_MODULATION == _ENABLE)
			CAudioSelChannel(_AUDIO_CHANNEL_NC);
			#endif
			LED_Message_HaoZhen(LED_MSG_GREEN);
			CTimerDelayXms(50);
			LED_Message_HaoZhen(LED_MSG_BLACK);
			#endif

			//COsdDispState(_MENU_NONE);
			ucOsdState = _MENU_NONE;
			
    	}
    	else                        // Power Up Process
    	{
    		LED_Message(LED_MSG_GREEN);				// evan 050512
        	CModeResetMode();
        	SET_POWERSTATUS();
        	CScalerInitial();
        	//CEepromSaveSystemData();					//disabled by zhang_dc
        	CEepromSavePowerStatus();					//Add by zhang_dc for saving power status.

			CEepromLoadSystemData();					//Add by zhang_dc for fixing color error.
			CInitialUserTimer();							//Add by zhang_dc for clear User Timer 
		
			//x.hu, request to set scaler in CVideoExist()
			SET_VIDEO_TABLE_SET_SCALER();
    }
}

//--------------------------------------------------
// Description  : Set panel on process
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerPanelOn(void)
{
	#if (_CUSTOM_TYPE == _CUSTOM_HAOZHEN)
if (!GET_VIDEO_PN_ACTION()) {
	/*
    CPowerDisplayPortOn();

    if(GET_PANELPOWERSTATUS() == _OFF)
    {
        CTimerDelayXms(10);
        CPowerPanelPowerOn();
        CTimerDelayXms(40);
        CScalerEnableDisplayOutput();
        CTimerDelayXms(80);
    }

    CPowerLightPowerOn();
    CMiscClearStatusRegister();
	*/
	//version 200D
	if(GET_PANELPOWERSTATUS() == _OFF)
    {
        CPowerPanelPowerOn();
        //CTimerDelayXms(40);
        CTimerDelayXms(10);	// 104 timing 
        CPowerDisplayPortOn();
        CScalerEnableDisplayOutput();
        CTimerDelayXms(80);
    }

    CPowerLightPowerOn();
    CMiscClearStatusRegister();

	//x.hu, for led
	LED_Message(LED_MSG_GREEN);
}
#else
      
	//version 200D
	if(GET_PANELPOWERSTATUS() == _OFF)
    {
         CPowerDisplayPortOn();
         //CPowerPanelPowerOn();
        //CTimerDelayXms(40);
        CTimerDelayXms(10);	// 104 timing 
         CPowerPanelPowerOn();
        //CPowerDisplayPortOn();
        CScalerEnableDisplayOutput();
        CTimerDelayXms(50);//CTimerDelayXms(80);xyw
    }

   CPowerLightPowerOn();
    CMiscClearStatusRegister();

	//x.hu, for led
	LED_Message(LED_MSG_GREEN);
#endif
}

//--------------------------------------------------
// Description  : Set panel off process
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerPanelOff(void)
{
	#if (_CUSTOM_TYPE == _CUSTOM_HAOZHEN)

	// x.hu, 20050804, add, detect whether the video is changed btween PAL and NTSC
	//CPowerLightPowerOff();
	if (!GET_VIDEO_PN_ACTION())
	{
	// x.hu, 20050804, add, for Power timing
	CAdjustBackgroundColor(0x00, 0x00, 0x00);
    CScalerSetBit(_VDISP_CTRL_28, ~(_BIT5 | _BIT3 | _BIT1 | _BIT0), (_BIT5 | _BIT1 | _BIT0));
    //CTimerDelayXms(60);
	// add end
	CPowerLightPowerOff();

    CTimerDelayXms(120);
    CScalerDisableDisplayOutput(); 
    CPowerDisplayPortOff();
    CTimerDelayXms(20); 
    CPowerPanelPowerOff();
	
    // The delay below is to prevent from short period between panel OFF and next ON
    CTimerDelayXms(250);
    CTimerDelayXms(250);
	}
	#else
	// x.hu, 20050804, add, for Power timing
	CAdjustBackgroundColor(0x00, 0x00, 0x00);
    CScalerSetBit(_VDISP_CTRL_28, ~(_BIT5 | _BIT3 | _BIT1 | _BIT0), (_BIT5 | _BIT1 | _BIT0));
    //CTimerDelayXms(60);
	// add end
	CPowerLightPowerOff();

   CTimerDelayXms(120); //CTimerDelayXms(120);//xyw
    CScalerDisableDisplayOutput(); 
    CPowerDisplayPortOff();
    CTimerDelayXms(20); 
    CPowerPanelPowerOff();
	
    // The delay below is to prevent from short period between panel OFF and next ON
   CTimerDelayXms(250); //CTimerDelayXms(250);//////////////////////xyw
    CTimerDelayXms(250);/////////////////////xyw
     
	#endif
}

//--------------------------------------------------
// Description  : Set panel power on
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerPanelPowerOn(void)
{
    PANELPOWER_UP();
#if(_POWER12VUSE == _ON)				// evan 050512
	CTimerDelayXms(6);
	PANELPOWER_UP12V();
#endif
    SET_PANELPOWERSTATUS();
}

//--------------------------------------------------
// Description  : Set panel power off
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerPanelPowerOff(void)
{
    PANELPOWER_DOWN();
#if(_POWER12VUSE == _ON)				// evan 050512
	CTimerDelayXms(6);
	PANELPOWER_DOWN12V();
#endif	
    CLR_PANELPOWERSTATUS();
}

//--------------------------------------------------
// Description  : Set backlight power on
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerLightPowerOn(void)
{
	//x.hu, when we show source hint while no signal, the invertor's PWM have not be set yet,
	// this may cause invertor working error.
	
	#if 1//(_PCB_TYPE == _PCB_RIGHTECH_A)
	LIGHT_ENABLE();
	#endif
	
	//x.hu, add for test
   	CAdjustBacklight();//xyw

	// add end
    LIGHTPOWER_UP();
    SET_LIGHTPOWERSTATUS();
}

//--------------------------------------------------
// Description  : Set backlight power off
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerLightPowerOff(void)
{
	//x.hu, add for test
	#if 1//(_PCB_TYPE == _PCB_RIGHTECH_A)
	LIGHT_DISABLE();
	//LIGHT_ENABLE();
	#endif
	
    LIGHTPOWER_DOWN();
    CLR_LIGHTPOWERSTATUS();
}

//--------------------------------------------------
// Description  : Power on display port
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerDisplayPortOn(void)
{
    switch(Panel.PanelStyle)
    {
        case _PANEL_TTL:
            CPowerTCONOn();	//x.hu, when signal in at no signal state, TTL needs to initial.
            break;

        case _PANEL_LVDS:
            CPowerLVDSOn();
            break;

        case _PANEL_RSDS:
			CPowerRSDSOn();
            break;
			
	 case _PANEL_TCON:		//add by cooriee 050521 for TCON
            CPowerTCONOn();
            break;
    }
}

//--------------------------------------------------
// Description  : Power off display port
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerDisplayPortOff(void)
{
    switch(Panel.PanelStyle)
    {
        case _PANEL_TTL:
            CPowerTCONOff();	//x.hu, 20080809, for timing
            break;

        case _PANEL_LVDS:
            CPowerLVDSOff();
            break;

        case _PANEL_RSDS:
			CPowerRSDSOff();
            break;
			
	 case _PANEL_TCON:		//add by cooriee 050521 for TCON
            CPowerTCONOff();
            break;
    }
}

//--------------------------------------------------
// Description  : Power on LVDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerLVDSOn(void)
{
    if((bit)(Panel.PanelConfig & _BIT3))
    {
        CScalerSetByte(_TCON_ADDR_PORT_8B, _LVDS_CTRL0_78);
        CScalerSetByte(_TCON_DATA_PORT_8C, 0xf0);
    }
    else
    {
        //LVDS from even port, if from odd port, the below value should be 0xa0
        CScalerSetByte(_TCON_ADDR_PORT_8B, _LVDS_CTRL0_78);

		#if (_PANEL_TYPE == _PANEL_TD141TGCB1 || _PANEL_TYPE == _PANEL_CLAA154WA01)
		//OPEN Odd port, x.hu
        CScalerSetByte(_TCON_DATA_PORT_8C, 0xd0);
		#else
        CScalerSetByte(_TCON_DATA_PORT_8C, 0xf0);				// evan 050512
        #endif
    }
}

//--------------------------------------------------
// Description  : Power off LVDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerLVDSOff(void)
{
    CScalerSetByte(_TCON_ADDR_PORT_8B, _LVDS_CTRL0_78);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0x00);
}

//--------------------------------------------------
// Description  : Power on RSDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerRSDSOn(void)
{
    CPowerLVDSOn();
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0xc3);
    CTimerDelayXms(40);
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0x83);
}

//--------------------------------------------------
// Description  : Power off RSDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerRSDSOff(void)
{
    CPowerLVDSOff();
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0x43);
}

/**********************TCON**********************************/
//add by cooriee 050521 for TCON
//--------------------------------------------------
// Description  : Power on TCON
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerTCONOn(void)
{
    CPowerLVDSOn();
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0xc0);
    CTimerDelayXms(40);
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0x80);
}

//--------------------------------------------------
// Description  : Power off RSDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerTCONOff(void)
{
    CPowerLVDSOff();
    CScalerSetByte(_TCON_ADDR_PORT_8B, 0x00);
    CScalerSetByte(_TCON_DATA_PORT_8C, 0x40);
}
/**********************TCON**********************************/

//--------------------------------------------------
// Description  : Power on ADC and APLL
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerADCAPLLOn(void)
{
    CScalerSetBit(_PLL1_N_A2, ~_BIT7, 0x00);                                                // Power up PLL1
    CScalerSetBit(_PLL2_WD_A8, ~_BIT0, 0x00);                                               // Power up PLL2
    CScalerSetBit(_ADC_POWER_CTRL_E8, ~(_BIT2 | _BIT1 | _BIT0), (_BIT2 | _BIT1 | _BIT0));   // Power up ADC
}

//--------------------------------------------------
// Description  : Power off ADC and APLL
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerADCAPLLOff(void)
{
    CScalerSetBit(_PLL1_N_A2, ~_BIT7, _BIT7);                                               // Power down PLL1
    CScalerSetBit(_PLL2_WD_A8, ~_BIT0, _BIT0);                                              // Power down PLL2
    CScalerSetBit(_ADC_POWER_CTRL_E8, ~(_BIT2 | _BIT1 | _BIT0), 0x00);                      // Power down ADC
}

#if(_TMDS_SUPPORT == _ON)
//--------------------------------------------------
// Description  : Power on TMDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerTMDSOn(void)
{
    CScalerSetBit(_DEVICE_KEY_BIST_PATTERN_D7, ~_BIT7, _BIT7);
    CScalerSetBit(_SYNC_CTRL_49, ~(_BIT1 | _BIT0), 0x00);
}
#endif

//--------------------------------------------------
// Description  : Power off TMDS
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerTMDSOff(void)
{
    CScalerSetBit(_Z0_CALIBRATION_CTRL_C7, ~_BIT6, 0x00);
    CScalerSetBit(_TMDS_OUTPUT_CTRL_C1, ~_BIT7, 0x00);
    CScalerSetBit(_DEVICE_KEY_BIST_PATTERN_D7, ~_BIT7, 0x00);
}

//--------------------------------------------------
// Description  : Power off ADC and APLL
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CPowerDPLLOff(void)
{
    CScalerSetBit(_DPLL_N_AF, ~_BIT7, _BIT7);                                               // Power down DPLL
}

⌨️ 快捷键说明

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