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

📄 power.c

📁 以ST公司CPU为核心的彩色电视机的完整源程序。
💻 C
字号:
/********************* SGS-THOMSON MICROELECTRONICS ************************
FILENAME     : POWER.C
VERSION      : V1.0
DATE         : JAN 1999
AUTHOR(s)    : ASHISH RUDOLA/ DEEPAK DOSHI
PROCESSOR    : ST92195
DESCRIPTION  : This module contains functions which implement the power
               management. It is responsible for the transition from the
               power OFF to power ON state and vice versa.
MODIFICATIONS:
   -
*****************************************************************************/

#include "power.h"
#include "macro.h"
#include "audio.h"
#include "display.h"
#include "i2c_bus.h"
#include "io.h"
#include "st92196.h"
#include "menuctrl.h"
#include "register.h"
#include "reset.h"
#include "sleep.h"
#include "source.h"
#include "timer.h"
#include "tuning.h"
#include "utility.h"
#include "video.h"
#include "autosrch.h"
#include "eeprom.h"
#include "channel.h"
#include "service.h"
#include "tv_glob.h"


/* Save the current power state */
unsigned char power_state;

/*****************************************************************************
INPUTS     : none
OUTPUTS    : ENABLE_POWER - Make sure TV is OFF
             ON_STATE - Set the TV to nominal OFF state
DESCRIPTION: This function initializes the power management to OFF state.
*****************************************************************************/
void init_power(void)
{
    /* Launch power off procedure */
    tv_flags = tv_flags & ~ENABLE_POWER;   /* register.h */
	tv_flags = tv_flags | ON_STATE;		   /* register.h */
}

/*****************************************************************************
INPUTS     : ON_STATE - Set if TV set is on, cleared otherwise.
             ENABLE_POWER - Set if a power-on procedure is requested
             power_state - Power state to process
OUTPUTS    : ST9 I/O registers
             ON_STATE - Set if TV set is on, cleared otherwise.
             power_state - Next step state to process
             see specific functions called by this function.
DESCRIPTION: This function updates the state of the power management.
*****************************************************************************/
void update_power(void)
{
	unsigned char i;
	unsigned char errnum;
	/* Check the current state */
	if (tv_flags & ON_STATE)   /* on --> off */
	{
		/* Wait for a power OFF command */
		if (tv_flags & ENABLE_POWER)
			return;

		/* Mute audio and blank the screen */
		mute_audio();

		/* Turn-off speakers */
	   	P4DR = P4DR | SPMUTE;
		
		/* Turn on LED */
/*		P2DR = P2DR | LED; */
/*		P2DR = P2DR &~ LED; */ /* feman remove */

		/* Disable menu and sleep timer */
		reset_sleep_timer();			   		/* sleep.c    */

		write_eeprom(EEPROM_LAST_CHANNEL,channel);

        P4DR = P4DR &~POWER;	/* POWER OFF */

		i = read_eeprom(EEPROM_POWER_STATUS);
		i = i & 0xFE;
		i = i | POWER_STANDBY;
		write_eeprom(EEPROM_POWER_STATUS, i);
		

		/* Set OFF state active */
		tv_flags = tv_flags & ~ON_STATE;

		/* Set that should be the next state */
		power_state = ON1;

	}
	else   /* off --> on */
	{
		switch (power_state)
		{
			case ON1:
				/* Wait here for a power ON command */
				if (!(tv_flags & ENABLE_POWER))
					return;

				/* Enable power supply */
		        P4DR = P4DR | POWER;    

		i = read_eeprom(EEPROM_POWER_STATUS);
		i = i & 0xFE;
		i = i | POWER_COMPLETE_OFF;
		write_eeprom(EEPROM_POWER_STATUS, i);
		

				/* Turn off LED */
			/*	P2DR = P2DR | LED; */ /* feman remove */ 

				/* Wait for power to stabilize */
				fast_timers[POWER_TIMER] = 100/MS_PER_INTERRUPT;/*Earlier 500ms */

				/* Set next state */
				power_state = ON2;
				break;					

			case ON2:
				/* Wait here till the end of the timer */
				if (fast_timers[POWER_TIMER] != 0)
					return;
				
				/* Mute audio and blank the screen (released by tuning) */
				mute_audio();

				/* Update video processor */
		        init_video();	 /* video.c */
#ifdef _emulate_
//9306
I2cCheck();
I2cSendByte(0x8c,STARTTRUE,STOPFALSE);
I2cSendByte(0x00,STARTFALSE,STOPFALSE);
I2cSendByte(0x8d,STARTFALSE,STOPTRUE);

I2cCheck();
I2cSendByte(0x8c,STARTTRUE,STOPFALSE);
I2cSendByte(0x80,STARTFALSE,STOPFALSE);
I2cSendByte(0x81,STARTFALSE,STOPTRUE);

I2cCheck();
I2cSendByte(0x8c,STARTTRUE,STOPFALSE);
I2cSendByte(0xA0,STARTFALSE,STOPFALSE);
I2cSendByte(0x51,STARTFALSE,STOPTRUE);
//7439
I2cCheck();
I2cSendByte(0x88,STARTTRUE,STOPFALSE);
I2cSendByte(0x00,STARTFALSE,STOPFALSE);
I2cSendByte(0x03,STARTFALSE,STOPTRUE);

I2cCheck();
I2cSendByte(0x88,STARTTRUE,STOPFALSE);
I2cSendByte(0x02,STARTFALSE,STOPFALSE);
I2cSendByte(0x05,STARTFALSE,STOPTRUE);

I2cCheck();
I2cSendByte(0x88,STARTTRUE,STOPFALSE);
I2cSendByte(0x06,STARTFALSE,STOPFALSE);
I2cSendByte(0x20,STARTFALSE,STOPTRUE);

I2cCheck();
I2cSendByte(0x88,STARTTRUE,STOPFALSE);
I2cSendByte(0x07,STARTFALSE,STOPFALSE);
I2cSendByte(0x20,STARTFALSE,STOPTRUE);


#endif 	
     			/* Update volume */
 				init_audio(); 
				
				/* Power-on procedure takes 1 second */
				fast_timers[POWER_TIMER] = 500/MS_PER_INTERRUPT;
				
				/* Set next state */
				power_state = ON3;
				break;					

			case ON3:
				/* Wait here till the end of the timer */
				if (fast_timers[POWER_TIMER] != 0)
					return;
		

				/* Set ON state active */
				tv_flags = tv_flags | ON_STATE;

				/* Initialize default audio and video source */
				init_source();	 /* source.c */

				/* Display status lines */
				display_request_flags = display_request_flags | STATUS_DISPLAY ;
				slow_timers[STATUS_TIMER] = STATUS_TIME_OUT;  

				/* Turn-on speakers (at the end so as to avoid audio "POP") */
                P4DR = P4DR & ~SPMUTE;
                
                errnum = 0x03;
				do
				{
					read_video_new();
					i = read_data[01] & 0xC0;
					errnum--;
				}while(i != 0xC0 && errnum != 0x00 );

#ifdef LANGUAGE_OPTION
				language = read_eeprom(EEPROM_LANGUAGE); 
#else
				language = DEFAULT_LANGUAGE;
#endif
				channel = read_eeprom(EEPROM_LAST_CHANNEL);
				/* Start tuning current channel */
                               start_tuning();         /* tuning.c */
                              
 				break;					
		}
	}
}

/*****************************************************************************
INPUTS     : none
OUTPUTS    : ST9 I/O registers
             VOLUME - Decrease volume before muting
             MUTE - Mute audio
             see write_video
DESCRIPTION: This function mute audio and blank the screen.
*****************************************************************************/
void mute_audio(void)
{
  	write_video_ram_data(MAIN_AUDIO_OUT, 0x02);	  
#ifdef NICAM
					read_status = read_nicam(0x0E);
					read_status = read_status | 0x80;
					write_nicam(0x0E, read_status);
					read_status = read_status & 0x0f;
					if (read_status == 0) /* Manual Mode */
						write_nicam(0x08, 0x00);
#endif

}

/*****************************************************************************
INPUTS     : none
OUTPUTS    : ST9 I/O registers
             VOLUME - Increase volume
             see write_video
             see update_user_mute
DESCRIPTION: This function unmute audio and unblank the screen.
*****************************************************************************/
void unmute_audio(void)
{
	unsigned char i;//,j;						/* Temporary storage */

	update_user_mute();
	read_video_new();
	i = read_data[0] & 0x0C;
	if(i == 0x0C)
	{
		for (i=0; i<=video[VOLUME]; i++)

		{
			write_video_ram_data(VOLUME, ((0x3F-volume)*2));
			microsecond_delay(150);
			microsecond_delay(150);
		}

 			#ifdef NICAM
	  			stereo_std = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
			#ifdef FM_WIDE
				stereo_std = stereo_std & 0x0f;
			#else
				stereo_std = stereo_std & 0x07;
			#endif
				write_stereo_standard();
/*				read_status = read_nicam(0x0E);
				read_status = read_status & ~0x80;
				write_nicam(0x0E, read_status);
*/
			#endif
	}		
}

/*****************************************************************************
INPUTS     : none
OUTPUTS    : ST9 I/O registers
             VOLUME - Decrease volume before muting
             MUTE - Mute audio
             see write_video
DESCRIPTION: This function mute audio and blank the screen.
*****************************************************************************/
void mute_audio_video(void)
{
/*	write_video_ram_data(MAIN_AUDIO_OUT, 0x02);*/
//	video[0x09] = video[0x09] & ~(0x40);
	video[0x09] = video[0x09] | 0x40;
	write_video(0x09,video[0x09]);
	mute_audio();
/*
#ifdef NICAM
					read_status = read_nicam(0x0E);
					read_status = read_status | 0x80;
					write_nicam(0x0E, read_status);
					read_status = read_status & 0x0f;
					if (read_status == 0) 
						write_nicam(0x08, 0x00);
#endif
*/
	/* Turn-off speakers */
   	P4DR = P4DR | SPMUTE;

}
/*****************************************************************************
INPUTS     : none
OUTPUTS    : ST9 I/O registers
             VOLUME - Increase volume
             see write_video
             see update_user_mute
DESCRIPTION: This function unmute audio and unblank the screen.
*****************************************************************************/
void unmute_audio_video(void)
{

	write_video_ram_data(MUTE_CVBS, 0x00);

	video[0x09] = video[0x09] & ~(0x40);
	write_video(0x09,video[0x09]);
    write_video_ram_data(BLUE_SCREEN, 0x00);

	millisecond_delay(255);
	millisecond_delay(150);

	unmute_audio();

  	P4DR = P4DR & ~SPMUTE;

}

⌨️ 快捷键说明

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