📄 avsys.c
字号:
// Step 2: Detect earphone input, and do the correspond control -- LLY.278a
#ifdef SUPPORT_EARPHONE
_Earphone_Control();
#endif // #ifdef SUPPORT_EAR_PHONE
// Step 3: Display necessary in PANEL -- LLY.278a
#ifndef NO_PANEL
PANEL_StringTrigger();
#endif // #ifndef NO_PANEL
#ifndef NO_TUNER
// **** Notice: Collect the thing which will be done only for tuner mode
// [1] Nothing need to do while non-tuner mode
if(__bAUXChannel != AUX_CHANNEL_TUNER)
return;
// [2] Continue to do auto-scan action if unlock receivable station
if(__bTunerMode & TUNER_MODE_AUTO_SCAN)
{
// LLY2.78b, add search scan procedure
if( (__bTunerMode&TUNER_MODE_SEARCH_SCAN) == TUNER_MODE_SEARCH_SCAN )
{
__bTemp=_TUNER_QuerySearchScan();
if(__bTemp==SEARCH_SCAN_STOP) // cancel search scan mode
{
_TUNER_AutoScan(DISABLE_AUTO_SCAN);
return;
}
else if(__bTemp==SEARCH_SCAN_POSTPOND) // postpond the search scan mode
{
return;
}
}
__bTemp=__bTunerMode & 0x0F; // first, get up/down tuning info.
__bTemp |= AUTO_SCAN; // then, merge "AUTO_SCAN" info.
if( _TUNER_TuningFreq(__bTemp)==STATION_LOCK )
{
// LLY2.78b, do correspond action while search scan mode
if( (__bTunerMode&TUNER_MODE_SEARCH_SCAN) == TUNER_MODE_SEARCH_SCAN )
{
//Increase the memory index by 1 for saving action
__bProgramCurrentIndex++;
// Save the receivable station info. into memory array
_TUNER_MemoryAction(MEMORY_SAVE);
// Keep the system time for next search scan reference
__dwPreGetTime=UTL_GetSysTimer();
}
else
{
// clear auto-scan mode
_TUNER_AutoScan(DISABLE_AUTO_SCAN);
}
}
}
#endif // #ifndef NO_TUNER
#endif // #ifdef SUPPORT_AV_SYSTEM
}
// ********************************************************************************
// Function : AVSYS_TunerDataAccess
// Description : Read-back/ Store the tuner relative info. to/ from serial-EPROM
// Arguments : bAction, specify the R/W action
// DATA_READ, read-back the serial-EPROM data
// DATA_WRITE, store the data into serial-EPROM
// DATA_DEFAULT, write the default value into serial-EPROM
// Return : None
// Side Effect : __StationInfo, __MemStation
// ********************************************************************************
void AVSYS_TunerDataAccess(BYTE bAction)
{
#ifndef NO_TUNER
//Kevin2.81-2, allocate tuner buffer here
if( (bAction==DATA_DEFAULT|DATA_WRITE) || (bAction&DATA_READ) )
{
// [1.2] Partition __cBuffer for necessary array
// Allocate the space for __StationInfo from __cBuffer start point
__StationInfo=(PSTATION_INFO)(__cBuffer);
// Allocate the space for __MemStation from (__cBuffer+PSTATION_INFO_LENGTH)
__MemStation=(PMEMORY_STATION)(__cBuffer + STATION_INFO_LENGTH);
// Output warning message if tuner mode need > cBuffer size memory
if( (STATION_INFO_LENGTH+MEMORY_STATION_LENGTH) > LENGTH_SHAREBUFFER )
{
#ifdef _DEBUG_INFO
OSD_Output(MSG_VERSION, TUNER_BUFFER_OVERFLOW, 0x3);
#endif // #ifdef _DEBUG_INFO
return;
}
}
// Initial default value for new Serial-EPROM
if(bAction & DATA_DEFAULT)
{
// default FM/AM station info.
__StationInfo->bBand=TUNER_DEFAULT_BAND;
__StationInfo->wFreq[BAND_FM]=TUNER_DEFAULT_FM_FREQ;
__StationInfo->wFreq[BAND_AM]=TUNER_DEFAULT_AM_FREQ;
// default memory station info.
for(__bTemp=0; __bTemp<MAX_FM_STATION_NO; __bTemp++)
__MemStation->wFM[__bTemp]=TUNER_DEFAULT_FM_FREQ;
for(__bTemp=0; __bTemp<MAX_AM_STATION_NO; __bTemp++)
__MemStation->wAM[__bTemp]=TUNER_DEFAULT_AM_FREQ;
}
//Kevin2.81-2, add a define & modify
//DATA_DEFAULT|DATA_WRITE : WRITE_ALL_INITIAL
//DATA_WRITE: WRITE_NOT_INITIAL
//DATA_READ: READ_FROM_EPPROM
#ifdef TUNER_VALUE_SAVE_IN_SERIAL_EPROM
// LLY.278-1, it's unnecessary for "SYSTEM_8051" because HAL module will handle it
//#ifdef SYSTEM_8051
if(bAction & DATA_WRITE)
{
HAL_EEPROM_PWrite(AVSYS_ADDR_STATION_INFO, (BYTE *)__StationInfo, EPROM_STATION_INFO_BYTE);
HAL_EEPROM_PWrite(AVSYS_ADDR_MEMORY_STATION, (BYTE *)__MemStation, EPROM_MEMORY_STATION_BYTE);
}
else if(bAction & DATA_READ)
{
HAL_EEPROM_PRead(AVSYS_ADDR_STATION_INFO, EPROM_STATION_INFO_BYTE, (BYTE *)__StationInfo);
HAL_EEPROM_PRead(AVSYS_ADDR_MEMORY_STATION, EPROM_MEMORY_STATION_BYTE, (BYTE *)__MemStation);
//Kevin2.79 add EEPROM read protection for __StationInfo & __MemStation
if(__StationInfo->bBand != BAND_FM && __StationInfo->bBand != BAND_AM) // Value protection, KCHong, 278b-Mustek
__StationInfo->bBand=TUNER_DEFAULT_BAND;
if(__StationInfo->wFreq[BAND_FM] > MAX_FM_FREQ || __StationInfo->wFreq[BAND_FM] < MIN_FM_FREQ)
__StationInfo->wFreq[BAND_FM]=TUNER_DEFAULT_FM_FREQ;
if(__StationInfo->wFreq[BAND_AM] > MAX_AM_FREQ || __StationInfo->wFreq[BAND_AM] < MIN_AM_FREQ)
__StationInfo->wFreq[BAND_AM]=TUNER_DEFAULT_AM_FREQ;
for(__bTemp=0; __bTemp<MAX_FM_STATION_NO; __bTemp++)
{
if(__MemStation->wFM[__bTemp] > MAX_FM_FREQ || __MemStation->wFM[__bTemp] < MIN_FM_FREQ)
{
__MemStation->wFM[__bTemp]=TUNER_DEFAULT_FM_FREQ;
}
}
for(__bTemp=0; __bTemp<MAX_AM_STATION_NO; __bTemp++)
{
if(__MemStation->wAM[__bTemp] > MAX_AM_FREQ || __MemStation->wAM[__bTemp] < MIN_AM_FREQ)
{
__MemStation->wAM[__bTemp]=TUNER_DEFAULT_AM_FREQ;
}
}
}
//#endif // #ifdef SYSTEM_8051
#else
if( bAction&DATA_READ )
{
// default FM/AM station info.
__StationInfo->bBand=TUNER_DEFAULT_BAND;
__StationInfo->wFreq[BAND_FM]=TUNER_DEFAULT_FM_FREQ;
__StationInfo->wFreq[BAND_AM]=TUNER_DEFAULT_AM_FREQ;
// default memory station info.
for(__bTemp=0; __bTemp<MAX_FM_STATION_NO; __bTemp++)
__MemStation->wFM[__bTemp]=TUNER_DEFAULT_FM_FREQ;
for(__bTemp=0; __bTemp<MAX_AM_STATION_NO; __bTemp++)
__MemStation->wAM[__bTemp]=TUNER_DEFAULT_AM_FREQ;
}
#endif
#endif // #ifndef NO_TUNER
}
// LLY2.78b, re-adjust the procedure to include panel output and IC programming
// **************************************************************************************
// Function : _TUNER_MemoryAction
// Description : [1] Get/ Save the desired station info. from/into memory array
// [2] Light the correspond panel output
// [3] Programming the correspond station info. to TUNER IC
// Argument : bAction, the save or get action
// MEMORY_SAVE, Save current station info. into desired memory index
// MEMORY_GET, Get desired memory index info. to current station
// Return : None
// Global : __bProgramCurrentIndex, the desired memory index
// Side Effect : __bProgramCurrentIndex value will be modified while it's overflow/ underflow
// **************************************************************************************
void _TUNER_MemoryAction(BYTE bAction)
{
#ifndef NO_TUNER
// [1] Check input index if overflow or underflow
if(__bProgramCurrentIndex==0) // underflow
{
__bProgramCurrentIndex=1; // reset as 1st index
}
else // overflow
{
if(__StationInfo->bBand==BAND_FM)
{
if(__bProgramCurrentIndex > MAX_FM_STATION_NO)
__bProgramCurrentIndex=MAX_FM_STATION_NO;
}
else
{
if(__bProgramCurrentIndex > MAX_AM_STATION_NO)
__bProgramCurrentIndex=MAX_AM_STATION_NO;
}
}
// [2] Decrease bIdx by 1, because the array index is from '0'
__bProgramCurrentIndex--;
// [3] Save or Get the correspond memory info.
if(bAction==MEMORY_SAVE) // save info. to memory array
{
// LLY.278-1, save the memory station info. into serial-EPROM while action done
// To avoid the info. lost while user press H/W power on directly
// Becasue, only band switch or IR power down will save all info. into serial-EPROM
if(__StationInfo->bBand==BAND_FM)
{
__MemStation->wFM[__bProgramCurrentIndex]=__StationInfo->wFreq[BAND_FM];
// LLY2.78b, for compiler warning in Emulator
//HAL_EEPROM_PWrite((AVSYS_ADDR_MEMORY_STATION+__bProgramCurrentIndex*STATION_BYTE_NO), &__StationInfo->wFreq[BAND_FM], STATION_BYTE_NO);
HAL_EEPROM_PWrite((BYTE)(AVSYS_ADDR_MEMORY_STATION+__bProgramCurrentIndex*STATION_BYTE_NO),
(BYTE *)(&__StationInfo->wFreq[BAND_FM]), STATION_BYTE_NO);
}
else
{
__MemStation->wAM[__bProgramCurrentIndex]=__StationInfo->wFreq[BAND_AM];
// LLY2.78b, for compiler warning in Emulator
//HAL_EEPROM_PWrite((AVSYS_ADDR_MEMORY_STATION+(MAX_FM_STATION_NO+__bProgramCurrentIndex)*STATION_BYTE_NO), &__StationInfo->wFreq[BAND_AM], STATION_BYTE_NO);
HAL_EEPROM_PWrite((BYTE)(AVSYS_ADDR_MEMORY_STATION+(MAX_FM_STATION_NO+__bProgramCurrentIndex)*STATION_BYTE_NO),
(BYTE *)(&__StationInfo->wFreq[BAND_AM]), STATION_BYTE_NO);
}
}
else // get info. from memory array
{
if(__StationInfo->bBand==BAND_FM)
{
__StationInfo->wFreq[BAND_FM]=__MemStation->wFM[__bProgramCurrentIndex];
}
else
{
__StationInfo->wFreq[BAND_AM]=__MemStation->wAM[__bProgramCurrentIndex];
}
}
// [4] Increase __bProgramCurrentIndex by 1, because it means the real index, from "1"
__bProgramCurrentIndex++;
// [5] Light the correspond info. on PANEL & program tuner IC if necessary -- LLY2.78b
if(bAction == MEMORY_SAVE)
{
// clear "memory" LED
PANEL_Output(MSG_MEMORY, CLEAR_MSG);
// light desired memory index
PANEL_Output(MSG_MEMORY, __bProgramCurrentIndex);
}
else //MEMORY_GET
{
// Light the memory info of desired index
PANEL_Output(MSG_MEMORY, __bProgramCurrentIndex);
// Program Tuner IC by desired station info.
CHIPS_ProgramTuner((BYTE)(SET_BAND|__StationInfo->bBand));
}
#endif // #ifndef NO_TUNER
}
// *************************************************************************
// Function : _TUNER_TuningFreq
// Description : Up/ Dwon tuning the frequency by one gap,
// and program the tuner IC by this value
// Arguments : bAction, specify the desired tuning action
// [3:0], up/ down tuning info.
// UP_TUNING, increase the frequency
// DOWN_TUNING, decrease the frequency
// [7:4], auto/ manual scan info
// AUTO_SCAN, auto scan the receivable station
// MANUAL_SCAN, scan the station by manual adjustment
// Return : Same as CHIPS_ProgramTuner() return value
// STATION_LOCK, lock at receivable station
// STATION_UNLOCK, unlock at receivable station
// Side Effect :
// *************************************************************************
BYTE _TUNER_TuningFreq(BYTE bAction)
{
#ifndef NO_TUNER
// [1] Calculate the desired frequency by up/ down tuning
if(bAction & UP_TUNING) // up tuning
{
// LLY2.78b, re-adjust the next frequency calculation procedure
// Step 1: check if current frequency stay at maximum
// Step 2: check if current frequency is valid (gap boundary)
// Step 3: increase the frequency to match valid frequency
// Step 4: check if overflow
if(__StationInfo->bBand==BAND_FM)
{
// [1.1] If current frequency stay at maximum value
if(__StationInfo->wFreq[BAND_FM] == MAX_FM_FREQ)
{
// reset to minimum frequency
__StationInfo->wFreq[BAND_FM] = MIN_FM_FREQ;
}
else // must increase frequency for others
{
// [1.2] check if current frequency is valid (gap boundary)
__bTemp=(BYTE)(__StationInfo->wFreq[BAND_FM]%FM_GAP_PER_TUNING);
// [1.3] Increase frequency to match FM mode valid frequency
if(__bTemp) // not gap boundary
{
__StationInfo->wFreq[BAND_FM] += (FM_GAP_PER_TUNING-__bTemp);
}
else
{
__StationInfo->wFreq[BAND_FM] += FM_GAP_PER_TUNING;
}
// [1.4] Check if the frequency is overflow
if(__StationInfo->wFreq[BAND_FM] > MAX_FM_FREQ)
{
// stay at maximum frequency
__StationInfo->wFreq[BAND_FM] = MAX_FM_FREQ;
}
}
}
else // AM mode
{
// [1.1] If current frequency stay at maximum value
if(__StationInfo->wFreq[BAND_AM] == MAX_AM_FREQ)
{
// reset to minimum frequency
__StationInfo->wFreq[BAND_AM] = MIN_AM_FREQ;
}
else // must increase frequency for others
{
// [1.2] Check if current frequency is valid (gap boundary)
__bTemp=(BYTE)(__StationInfo->wFreq[BAND_AM]%AM_GAP_PER_TUNING);
// [1.3] Increase frequency to match AM mode valid frequency
if(__bTemp) // not gap boundary
{
__StationInfo->wFreq[BAND_AM] += (AM_GAP_PER_TUNING-__bTemp);
}
else
{
__StationInfo->wFreq[BAND_AM] += AM_GAP_PER_TUNING;
}
// [1.4] Check if the frequency is overflow
if(__StationInfo->wFreq[BAND_AM] > MAX_AM_FREQ)
{
// stay at maximum frequency
__StationInfo->wFreq[BAND_AM] = MAX_AM_FREQ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -