?? tuning.c
字號:
/********************* SGS-THOMSON MICROELECTRONICS ************************
FILENAME : TUNING.C
VERSION : V1.0
DATE : JAN 1999
AUTHOR(s) : ASHISH RUDOLA / DEEPAK DOSHI
PROCESSOR : ST92195
DESCRIPTION : This module includes functions which perform channel tuning.
MODIFICATIONS:
-
*****************************************************************************/
#include "st92196.h"
#include "tuning.h"
#include "macro.h"
#include "autosrch.h"
#include "channel.h"
#include "eeprom.h"
#include "i2c_bus.h"
#include "io.h"
#include "label.h"
#include "power.h"
#include "register.h"
#include "source.h"
#include "timer.h"
#include "utility.h"
#include "video.h"
#include "audio.h"
#include "tv_glob.h"
unsigned char system;
/* Save the current tuning state */
unsigned char tuning_state;
/*****************************************************************************
INPUTS : none
OUTPUTS : TUNING_REQUEST - Disable any possible tuning request
DESCRIPTION: This function initializes tuning to prevent false tuning.
*****************************************************************************/
void init_tuning(void)
{
/* Reset tuning flags to prevent non wanted tuning on start-up */
tuning_flags = tuning_flags & ~TUNING_REQUEST;
}
/*****************************************************************************
INPUTS : none
OUTPUTS : tuning_state - Point the first tuning process to start with
TUNING_REQUEST - Request a tuning
DESCRIPTION: This function initializes the tuning to its nominal state. It
should be called before any other function of this module is
used.
*****************************************************************************/
void start_tuning(void)
{
/* Prepare that should be the first process to start with */
tuning_state = SETUP_TUNING;
/* initiate a tuning procedure, set tuning flags */
tuning_flags = tuning_flags | TUNING_REQUEST;
/* Check if this channel is stored in the channel list (EEPROM) */
/* i = read_channel_info(SETTINGS);*/
init_channel();
}
/*****************************************************************************
INPUTS : TUNING_REQUEST - Set if a tuning has been requested
tuning_state - Current state to work with
channel - New channel to tune
OUTPUTS : TUNING_REQUEST - Reset after tuning completion
tuning_state - Next state to handle
video_status - Current video status
TUNING_AV_TIMER - General purpose timer for the tuning
REFRESH_DISPLAY - Refresh autosearch bargraph display
STANDARD_SELECTION - Enable automatic color recognition
ENABLE_AFC - Enable AFC if it has to be done (EEPRM info)
ST9 Voltage Synthesis registers
see mute_audio_video
see set_external_source_input
see set_internal_source_input
see read_channel_info
see read_label
see set_system
see set_band
DESCRIPTION: This function updates tuning states.
*****************************************************************************/
void update_tuning(void)
{
unsigned char i ;
unsigned int j ;
/* Check if a tuning has been requested */
if (!(tv_flags & ON_STATE))
return;
/* Check if a tuning has been requested */
if (tuning_flags & TUNING_REQUEST)
{
switch (tuning_state)
{
case SETUP_TUNING:
/*mute audio and blank the screen */
mute_audio_video();
/* Make sure automatic color recognition is active */
write_video_ram_data(STANDARD_SELECTION, 0x18);
/* Disable AFC while tuning (not restored if video channel) */
tuning_flags = tuning_flags & ~ENABLE_AFC;
/* Select internal video source */
/* set_internal_source_input(); *//* source.c */
source = TUNER;
get_source_input();
tuning_state = SETUP_VS;
/* Set blanking and muting time */
fast_timers[TUNING_AV_TIMER] = 500/MS_PER_INTERRUPT;
break;
case SETUP_VS:
i = read_channel_info(VS_MSB);
/* Setup AFC according to new channel settings */
j = i ;
i = i &~0xC0;
i = i | 0x80 ;
spp (VS_PG);
asm ("ld R254,%0" : : "r"(i));
i = read_channel_info(VS_LSB);
spp (VS_PG);
asm ("ld R255,%0" : : "r"(i));
j = j &~ 0x3f ;
j >>= 6 ;
set_band(j) ;
#ifdef FINE_TUNE_STATUS
j = EEPROM_START_FINE_TUNE_STATUS + (channel-1);
i = read_eeprom(j);
fine_tune = i &~ 0xC0;
if(fine_tune == 0x1F)
tuning_flags = tuning_flags | ENABLE_AFC;
else
tuning_flags = tuning_flags &~ENABLE_AFC;
#else
fine_tune = 31;
tuning_flags = tuning_flags | ENABLE_AFC;
#endif
tuning_state = SETUP_CHANNEL;
break;
case SETUP_CHANNEL:
if (fast_timers[TUNING_AV_TIMER] != 0)
return;
/* unmute_audio_video();*/
/* Get possible associated label */
read_label(); /* label.c */
set_color_standard();
set_audio_standard();
tuning_state = STOP_TUNING;
/* Enable status display and refresh the current display */
display_request_flags |= (STATUS_DISPLAY | REFRESH_DISPLAY );
fast_timers[TUNING_AV_TIMER] = 50/MS_PER_INTERRUPT;//feman add
break;
case STOP_TUNING:
/* Before doing anything else, wait AGC to stabilize */
if (fast_timers[TUNING_AV_TIMER] != 0) //feman debug
return;
unmute_audio_video();
user_flags = user_flags & ~FORCED_NICAM_FLAG;
tv_flags = tv_flags &~ INITIAL_SETUP ;
write_eeprom(EEPROM_LAST_CHANNEL,channel);
tuning_flags = tuning_flags & ~TUNING_REQUEST;
break;
}
}
}
/*****************************************************************************
INPUTS : ENABLE_AFC - Do not track IF if AFC not enabled
video_status - Check identification bit
OUTPUTS : ST9 Voltage Synthesis registers
see read_AFC
DESCRIPTION: AFC level can be modified by the temperature, so this function
updates VS so as to keep AFC at the nominal value.
*****************************************************************************/
void monitor_AFC(void)
{
unsigned char i; /* Temporary storage */
if (tuning_flags & ENABLE_AFC)
{
/* Make sure a channel is present before updating VS */
read_video_new();
i = read_data[0] & 0x08;
if(i == 0x08)
{
i = read_data[2] & 0x07;
/* if(i == 2 || i == 3)*/
if(i == 2 )
increment_VS ( SLOW_STEP) ;
if(i == 3 )
increment_VS ( MEDIUM_STEP) ;
if(i == 4 )
decrement_VS ( SLOW_STEP) ;
if(i == 5 )
decrement_VS ( MEDIUM_STEP) ;
}
}
}
/*****************************************************************************
INPUTS : Band to tune
OUTPUTS : ST9 IO registers
DESCRIPTION: This function sets IO pins according to the band selected. Make
sure a band has been defined (UHF as default in case of).
*****************************************************************************/
void set_band(unsigned char selected_band)
{
P3DR = P3DR & ~BAND_MASK;
switch(selected_band)
{
case VHF_L:
P3DR = P3DR | BAND_VL;/* VHF_L Selected*/
break;
case VHF_H:
P3DR = P3DR | BAND_VH; /* VHF_H Selected*/
break;
case UHF:
P3DR = P3DR | BAND_U; /* UHF SELECTED */
break;
default :
P3DR = P3DR | BAND_VL;
break;
}
}
/*****************************************************************************
INPUTS : System to select
OUTPUTS : ST9 IO registers
IF_STANDARD - Set modulation mode (positive/negative)
DESCRIPTION: This function selects system to use. Make sure a system has been
defined (system C as default in case of).
*****************************************************************************/
void set_video_audio_system(unsigned char audio_standard)
{
unsigned char j;
if ((AUDIO_system == SYSTEM_BG) || (AUDIO_system == SYSTEM_DK)||(AUDIO_system == SYSTEM_I))
{
write_video_ram_data(SAW_FILTER_SWITCH, 0x10);
j = misc1 & 0x02;
if( j == 0) ;/* QSS */
// P4DR = P4DR &~ SAW_SW1;
else ;
// P4DR = P4DR | SAW_SW1;
// P4DR = P4DR &~ SAW_SW2;
}
else
{
write_video_ram_data(SAW_FILTER_SWITCH, 0x00);
j = misc1 & 0x02;
if( j == 0) ;/* QSS */
// P4DR = P4DR | SAW_SW1;
else ;
// P4DR = P4DR & ~SAW_SW1;
// P4DR = P4DR | SAW_SW2;
}
}
/*************************************************************************
This function is used to select varoius COLOR Standard
*************************************************************************/
void set_color_standard(void)
{
unsigned char j;
j = read_channel_info(SETTINGS);
system = get_value(j,SYSTEM_MASK);
if (system == SYSTEM_SECAM)
{
write_video_ram_data(STANDARD_SELECTION, 0x10);
}
if (system == SYSTEM_PAL)
{
write_video_ram_data(STANDARD_SELECTION, 0x00);
}
if (system == SYSTEM_NTSC_1)
{
write_video_ram_data(STANDARD_SELECTION, 0x08);
}
if (system == SYSTEM_NTSC_2)
{
write_video_ram_data(STANDARD_SELECTION, 0x0A);
if (system == SYSTEM_AUTO)
{
write_video_ram_data(STANDARD_SELECTION, 0x18);
}
}
/*************************************************************************
This function is used to select varoius SOUND Standard
*************************************************************************/
void set_audio_standard(void)
{
unsigned char j;
j = read_channel_info(SETTINGS);
AUDIO_system = get_value(j,AUDIO_SYSTEM_MASK);
if (AUDIO_system == SYSTEM_BG)
{
write_video_ram_data(SOUND_STANDARD, 0x04);
}
if (AUDIO_system == SYSTEM_DK)
{
write_video_ram_data(SOUND_STANDARD, 0x00);
}
if (AUDIO_system == SYSTEM_I)
{
write_video_ram_data(SOUND_STANDARD, 0x02);
}
if (AUDIO_system == SYSTEM_MN)
{
write_video_ram_data(SOUND_STANDARD, 0x06);
}
if (!(tuning_flags & AUTOSEARCH_REQUEST))
set_video_audio_system(AUDIO_system) ;
}
/******************************************************************************
******************************************************************************/
void store_program_info(unsigned char channel)
{
unsigned char i,k;
unsigned int j;
k = P3DR & BAND_MASK; //FEMAN P4DR -> P3DR
if(k == BAND_VL)
k = VHF_L;
else
if( k == BAND_VH)
k = VHF_H;
else
k = UHF;
k <<= 6;
k = k & 0xC0;
spp(VS_PG);
asm ("ld %0,R254" : "=r"(i));
i= i &~ 0xC0;
i = i | k;
j = EEPROM_START_CHANNEL_MEMORY + ((channel-1) * 3);
write_eeprom(j,i);
spp (VS_PG);
asm ("ld %0,R255" : "=r"(i));
j++;
write_eeprom(j, i);
#ifdef FINE_TUNE_STATUS
j = EEPROM_START_FINE_TUNE_STATUS + (channel-1);
i = fine_tune &~ 0xC0;
write_eeprom(j, i);
#endif
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -