radio_mv114_kst.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:31k
- /* note: this program is for self tuned radio MV114, MV014, MV011 */
- /* PLL IC: LC72131, TUNER IC: LA1844 */
- /* state=FM AM mode */
- #include "regmap.h"
- #include "global.h"
- #include "func.h"
- #include "radio_mv114_kst.h"
- #include "radio_rds.h"
- #include "ircode.h"
- #include "osd.h"
- #include "dsp3_if.h"
- #include "set.h"
- #include "audctrl.h"
- #include "util.h"
- extern UINT16 check_sum(BYTE *data,BYTE len);
- #define NEW_AUTO_SEARCH_ALL
- #define TUNER_DBG
- /*
- #ifdef SUPPORT_TUNER_DBG
- #define TUNER_DBG
- #endif
- */
- /*
- #ifndef DVDRELEASE
- #define TUNER_DBG
- #endif
- #ifndef TUNER_DBG
- #undef printf
- #undef print_block
- #define printf(f, a...) do {} while (0)
- #define print_block(x,y) do {} while (0)
- #endif
- */
- #ifndef SUPPORT_OSD
- #undef PrintOsdMsg(x,y,z,w)
- #define PrintOsdMsg(x,y,z,w)
- #endif
- /*
- * declare extern function
- */
- extern void init_ir_num(void);
- extern void polling_vfdr(void);
- /*from lc72131.c*/
- extern void tuner_mute( BYTE );
- extern void set_band(BYTE);
- extern void set_mono_stereo(BYTE);
- extern void set_station(BYTE i);
- extern BYTE is_station();
- extern void init_tuner();
- extern BYTE test_tuner();
- extern void set_freq(UINT16 freq);
- extern BYTE is_stereo(void);
- BYTE search_station=0;
- static BYTE search_dir=0;
- BYTE write2mem=0;
- extern int rep_ir_times;
- #include ".\Customers\Sunplus\vfd_gbmsample_l.h"
- #include "vfdfunc.h"
- extern void vfd_set_str();
- /*/////////////////////////
- Creator: xyy 2004-3-12
- Function:Auto search all station and save the station to e2prom
- //////////////////////////*/
- #ifndef NEW_AUTO_SEARCH_ALL
- void auto_search_all()
- {
- int i=0;
- search_dir = 1;
- if(tuner.bandswitch)//am
- {
- tuner.ambak=AM_FREQ_MIN+0x30;
- while(1)
- {
- if(tuner.ambak == AM_FREQ_MIN)
- {
- i = 0;
- search_station = 0;
- save_tuner_E2PROM();
- tuner.am_ch = 1;
- set_station(tuner.am_ch);
- break;
- }
- Amautosearch(AUTOSEARCHUP);
-
- if(search_station==1)
- {
- tuner.amfreq[i] = tuner.ambak;
- i++;
- //save station
- search_station = 0;
- search_dir = 1;
- }
- }
- }
- else //fm*/
- {
- tuner.fmbak=FM_FREQ_MIN+1;
- while(1)
- {
- if(tuner.fmbak == FM_FREQ_MIN)
- {
- i = 0;
- search_station = 0;
- save_tuner_E2PROM();
- tuner.fm_ch = 1;
- set_station(tuner.fm_ch);
- break;
- }
- Fmautosearch(AUTOSEARCHUP);
-
- if(search_station==1)
- {
- tuner.fmfreq[i] = tuner.fmbak;
- i++;
- //save station
- search_station = 0;
- search_dir = 1;
- }
- }
- }
- }
- #endif//NEW_AUTO_SEARCH_ALL
- #ifdef NEW_AUTO_SEARCH_ALL
- void auto_search_all_am()
- {
- BYTE ch;
- if(tuner.bandswitch == 0)
- {
- tuner.bandswitch=(!tuner.bandswitch);
- set_band(tuner.bandswitch);
- }
- //now is am
- tuner.ambak = AM_FREQ_MIN;
- tuner.am_ch = 0;
- for(ch = 0;ch < MAX_MEM_BAND;ch++)
- {
-
- while(1)
- {
- tuner.ambak = (tuner.ambak + 0x30); // 3*3k step
- if(tuner.ambak>AM_FREQ_MAX) //am max
- {
- break;
- }
-
- tuner.amfreq[tuner.am_ch] = tuner.ambak;
- disfreq();
-
- if(is_station())
- {
- break;
- }
- }
- if(tuner.ambak>AM_FREQ_MAX) //am max
- {
- break;
- }
- if(tuner.am_ch < (MAX_MEM_BAND-1))
- tuner.am_ch++;
- else
- tuner.am_ch = 0;
- }
- }
- void auto_search_all_fm()
- {
- BYTE ch;
- if(tuner.bandswitch == 1)
- {
- tuner.bandswitch=(!tuner.bandswitch);
- set_band(tuner.bandswitch);
- }
- //now is fm
- tuner.fmbak = FM_FREQ_MIN;
- tuner.fm_ch = 0;
- tuner.bandswitch = 0;//fm
- for(ch = 0;ch < MAX_MEM_BAND;ch++)
- {
-
- while(1)
- {
- tuner.fmbak=(tuner.fmbak+1); // 100K STEP, ref clock: 25k
- if(tuner.fmbak>FM_FREQ_MAX) //fm max 107.8MHZ
- {
- break;
- }
- tuner.fmfreq[tuner.fm_ch] =tuner.fmbak ;
- disfreq();
- if(is_station())
- break;
- }
- if(tuner.fmbak >FM_FREQ_MAX) //fm max 107.8MHZ
- {
- break;
- }
-
- if(tuner.fm_ch < (MAX_MEM_BAND-1))
- tuner.fm_ch++;
- else
- tuner.fm_ch = 0;
- }
- }
- #endif//NEW_AUTO_SEARCH_ALL
- /*
- char *capitalise(char *p)
- mode==0
- ----translate lowercase into capital
- mode==1
- ----translate capital into lowercase
- len ??????
- */
- void capitalize(char *p,BYTE mode,BYTE len)
- {
- while(len)
- {
- if(*p>='a'&&*p<='z')
- {
- if(mode)
- *p+=0x20;
- else
- *p-=0x20;
- }
- p++;
- len--;
- }
- }
- void str_filter(char *p,BYTE len)
- {
- //capitalize(p,len);
- while(len)
- {
- if(*p>='A'&&*p<='Z')
- {
- }
- else if((*p == '-')||(*p == ':'))
- {
- }
- else if(*p>='0'&&*p<='9')
- {
- }
- else
- {
- *p = ' ';
- }
- p++;
- len--;
- }
-
- }
- #ifdef XINGQIU_DVD_RECEIVER//xyy 2004-5-24 9:06
- void tuner_key(BYTE key)
- {
- static BYTE enter_flag=0;
- //return;
- switch(key)
- {
-
- /* case IRC_0:
- case IRC_1:
- printf("======== hello hello =======n");
- tuner_oper_mode = RECALL_OR_STORE;
- break;*/
- case IRC_MUTE:
- {
- int id;
- //rds_decoder_init();
- //return;
- //printf("size of :%dn",sizeof(tuner));
- user_mute=!user_mute;
- tuner_mute(user_mute);
-
- if(user_mute)
- {
- id=STR_OS_MUTE;
- OSD1000ISP_STATUS(OSDISP_MUTE, OSDIR_MUTE);
- PrintOsdMsg(id,REGION1,0,0);
- }
- else
- {
- // id=STR_OS_SPACE;
- OSD1000ISP_STATUS(OSDISP_CLEAR, OSDIR_GLOBAL);
- OSD_OnOffRegion(OSD_OFF,1);//xyy 2003-10-13 17:15
- }
- break;
- }
-
- case IRC_GOTO:
- tuner_oper_mode = AUTO_SEARCH;
- timeout_vfd = 0;
- if(tuner.bandswitch == 1)
- {
- auto_search_all_am();
- tuner.am_ch = 0;
- set_station(tuner.am_ch);
- }
- else
- {
- auto_search_all_fm();
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch);
- }
- save_tuner_E2PROM();
- tuner_oper_mode = NORMAL_TUNE;
- disfreq();
- break;
-
- case IRC_SETUP:
- search_station = 1;
- tuner_oper_mode = RECALL_OR_STORE;
- timeout_vfd = 6000;
- break;
-
- case IRC_AUD_LANGUAGE:
- if(!tuner.bandswitch)
- {
- tuner_st_mono();
- timeout_vfd = 4000;
- }
- break;
- case IRC_CLEAR:
- printf("====== clear ======n");
- break;
-
- case IRC_TITLEMENU:
- tuner_oper_mode = FREQ_DIRECT_CALL;
- timeout_vfd = 6000;
- erase_vfd_mem();
- if(tuner.bandswitch)
- {
- station_input_index = 1;
- psprintf(linebuf,"%02d 0000",tuner.am_ch);
- }
- else
- {
- psprintf(linebuf,"%02d 00000",tuner.fm_ch);
- vfd_set_dot(0x49);
- }
- vfd_set_str(0,0,0,linebuf);
- break;
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 13:54
- case IRC_SELECT:
- if(enter_flag == 0)
- {
- erase_vfd_mem();
- if(psReadyFlag == 0x0f)
- {
- rds_func_flag = PS_FUNC;
- psprintf(RegionValStr[REGION1],"PS : %s",programServiceBuf);
- PrintOsdMsg(0, REGION1, 0, 1);
- }
- else
- {
- //vfd_set_str(0,0,0," NO PS ");
- psprintf(RegionValStr[REGION1],"NO PS");
- PrintOsdMsg(0, REGION1, 0, 1);
- rds_func_flag = 0;
- }
- enter_flag++;
- }
- else if(enter_flag == 1)
- {
- erase_vfd_mem();
- if(ptyReadyFlag == 0xff)
- {
- rds_func_flag = PTY_FUNC;
- //printf( "PTY %s",programTypeBuf);
- //PrintOsdMsg(, y, z, w)
- psprintf(RegionValStr[REGION1],"PYP : %s",programTypeBuf);
- PrintOsdMsg(0, REGION1, 0, 1);
- }
- else
- {
- //vfd_set_str(0,0,0," NO PTY ");
- psprintf(RegionValStr[REGION1],"NO PYP");
- PrintOsdMsg(0, REGION1, 0, 1);
- rds_func_flag = 0;
- }
- enter_flag++;
- }
- else if(enter_flag == 2)
- {
- erase_vfd_mem();
- if((txtBreadyFlag == 0xffff)||(txtAreadyFlag == 0xffff))
- {
- rds_func_flag = RT_FUNC;
- //printf("%sn",radioTextBufA[0]);
- capitalize(radioTextBufA[radio_text_type], 0, 64);
- str_filter(radioTextBufA[radio_text_type], 64);
- //printf("%sn",radioTextBufA[0]);
- psprintf(RegionValStr[REGION1],"RT : %s",radioTextBufA[radio_text_type]);
- PrintOsdMsg(0, REGION1, 0, 1);
- }
- else
- {
- //vfd_set_str(0,0,0," NO RT ");
- psprintf(RegionValStr[REGION1],"NO RT");
- PrintOsdMsg(0, REGION1, 0, 1);
-
- rds_func_flag = 0;
- }
- enter_flag++;
- }
- else if(enter_flag == 3)
- {
- erase_vfd_mem();
- if(ctReadyFlag == 0xff)
- {
- rds_func_flag = CT_FUNC;
- //printf("CT %sn",clocktimeBuf);
- psprintf(RegionValStr[REGION1],"%s",clocktimeBuf);
- PrintOsdMsg(0, REGION1, 0, 1);
-
- }
- else
- {
- //vfd_set_str(0,0,0," NO CT ");
- psprintf(RegionValStr[REGION1],"NO CT");
- PrintOsdMsg(0, REGION1, 0, 1);
-
- rds_func_flag = 0;
- }
- enter_flag++;
- }
- else if(enter_flag == 4)
- {
-
- erase_vfd_mem();
- if(ptynReadyFlag == 0x0f)
- {
- rds_func_flag = PTYN_FUNC;
- capitalize(programTypeNameBuf, 0, 9);
- str_filter(programTypeNameBuf,9);
- psprintf(RegionValStr[REGION1],"PTYN:%s",programTypeNameBuf);
- PrintOsdMsg(0, REGION1, 0, 1);
- }
- else
- {
- //vfd_set_str(0,0,0," NO PTYN ");
- rds_func_flag = 0;
- psprintf(RegionValStr[REGION1],"NO PTYN");
- PrintOsdMsg(0, REGION1, 0, 1);
- }
- enter_flag = 0;
- }
- rdsinfo_dispindex = 0;
- timeout_vfd = 2000;
-
- break;
- #endif
- case IRC_FORWARD:/* auto search up */
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
- tuner_oper_mode = NORMAL_TUNE;
- tuner.Istuning[tuner.bandswitch]=1;
- timeout_vfd = 0;
- // to avoid the noise when enter auto search mode
- tuner_mute_flag = 0;
- search_dir=1;
- break;
- case IRC_BACKWARD: /* auto search down */
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
- // to avoid the noise when enter auto search mode
- tuner_oper_mode = NORMAL_TUNE;
- timeout_vfd = 0;
- tuner_mute_flag = 0;
- search_dir=2;
- break;
- case IRC_LEFT:
- search_dir = 0;
- search(SEARCHDEC);
- break;
- case IRC_RIGHT:
- search_dir = 0;
- search(SEARCHADD);
- break;
- case IRC_PREV:
- //printf("leftn");
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
-
- if(tuner.bandswitch)//am
- {
- if(tuner.am_ch>1)
- tuner.am_ch--;
- else
- tuner.am_ch = 1;
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch>=1)
- tuner.fm_ch--;
- else
- // tuner.fm_ch = 1;
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- break;
- case IRC_NEXT:
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
-
- if(tuner.bandswitch) //am
- {
- if(tuner.am_ch<MAX_MEM_BAND)
- tuner.am_ch++;
- else
- tuner.am_ch = MAX_MEM_BAND;
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch<MAX_MEM_BAND)
- tuner.fm_ch++;
- else
- tuner.fm_ch = MAX_MEM_BAND;
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- break;
- case IRC_RCVR_BAND: /* serach- */
- {
- search_dir=0;
- tuner.bandswitch=(!tuner.bandswitch);
- //printf("bandn");
- set_band(tuner.bandswitch);
- write2mem=1;
- break;
- }
- #ifdef SUPPORT_APOGEE_AMP
- case IRC_VOLUME_UP:
- // ircmd_volume_up();
- // set_volume(1);
- break ;
- case IRC_VOLUME_DN:
- // ircmd_volume_down();
- // set_volume(0);
- break ;
- #endif
- default:
- break;
- }
- }
- #elif defined(ORITRON_DVD_RECEIVER)
- void tuner_key(BYTE key)
- {
- static BYTE enter_flag=0;
- static BYTE stereo = 1;
- //return;
- switch(key)
- {
-
- case IRC_MUTE:
- {
- int id;
- //rds_decoder_init();
- //return;
- //printf("size of :%dn",sizeof(tuner));
- user_mute=!user_mute;
- tuner_mute(user_mute);
-
- if(user_mute)
- {
- id=STR_OS_MUTE;
- PrintOsdMsg(id,REGION1,0,0);
- }
- else
- // id=STR_OS_SPACE;
- OSD_OnOffRegion(OSD_OFF,1);//xyy 2003-10-13 17:15
- break;
- }
- /* //xyy mask 2004-11-9
- case IRC_GOTO:
- tuner_oper_mode = AUTO_SEARCH;
- timeout_vfd = 0;
- if(tuner.bandswitch == 1)
- {
- auto_search_all_am();
- tuner.am_ch = 0;
- set_station(tuner.am_ch);
- }
- else
- {
- auto_search_all_fm();
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch);
- }
- save_tuner_E2PROM();
- tuner_oper_mode = NORMAL_TUNE;
- disfreq();
- break;
-
- case IRC_SETUP:
- search_station = 1;
- tuner_oper_mode = RECALL_OR_STORE;
- timeout_vfd = 6000;
- break;
- */
- case IRC_RCVR_EQ:
-
- stereo = !stereo;
- if(!tuner.bandswitch)
- {
- set_mono_stereo(stereo);
- timeout_vfd = 4000;
- }
- break;
-
- case IRC_FORWARD:/* auto search up */
- case IRC_VFD_RIGHT:
- tuner_oper_mode = NORMAL_TUNE;
- tuner.Istuning[tuner.bandswitch]=1;
- timeout_vfd = 0;
- // to avoid the noise when enter auto search mode
- tuner_mute_flag = 0;
- search_dir=1;
- break;
- case IRC_BACKWARD: /* auto search down */
- case IRC_VFD_LEFT:
- // to avoid the noise when enter auto search mode
- tuner_oper_mode = NORMAL_TUNE;
- timeout_vfd = 0;
- tuner_mute_flag = 0;
- search_dir=2;
- break;
- case IRC_LEFT:
- search_dir = 0;
- search(SEARCHDEC);
- break;
- case IRC_RIGHT:
- search_dir = 0;
- search(SEARCHADD);
- break;
- case IRC_PREV:
- //printf("leftn");
- if(tuner.bandswitch)//am
- {
- if(tuner.am_ch>1)
- tuner.am_ch--;
- else
- tuner.am_ch = 1;
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch>=1)
- tuner.fm_ch--;
- else
- // tuner.fm_ch = 1;
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- break;
- case IRC_NEXT:
-
- if(tuner.bandswitch) //am
- {
- if(tuner.am_ch<MAX_MEM_BAND)
- tuner.am_ch++;
- else
- tuner.am_ch = MAX_MEM_BAND;
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch<MAX_MEM_BAND)
- tuner.fm_ch++;
- else
- tuner.fm_ch = MAX_MEM_BAND;
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- break;
- case IRC_P_SCAN: /* serach- */
- {
- search_dir=0;
- tuner.bandswitch=(!tuner.bandswitch);
- //printf("bandn");
- set_band(tuner.bandswitch);
- write2mem=1;
- disfreq();
- break;
- }
- default:
- break;
- }
- }
- #else
- void tuner_key(BYTE key)
- {
- static BYTE enter_flag=0;
- //return;
- switch(key)
- {
- case IRC_MUTE:
- {
- int id;
- //rds_decoder_init();
- //return;
- //printf("size of :%dn",sizeof(tuner));
- user_mute=!user_mute;
- tuner_mute(user_mute);
-
- if(user_mute)
- {
- id=STR_OS_MUTE;
- OSD1000ISP_STATUS(OSDISP_MUTE, OSDIR_MUTE);
- PrintOsdMsg(id,REGION1,0,0);
- }
- else
- {
- // id=STR_OS_SPACE;
- OSD1000ISP_STATUS(OSDISP_CLEAR, OSDIR_GLOBAL);
- OSD_OnOffRegion(OSD_OFF,1);//xyy 2003-10-13 17:15
- }
- break;
- }
- #ifdef SUPPORT_RDS_FUNCTION
- case IRC_SELECT:
-
- if(rds_func_flag >= 4)
- {
- rds_func_flag = 0;
- }
- else
- {
- rds_func_flag++;
- }
- disp_rds_func(rds_func_flag);
- break;
- #endif /*SUPPORT_RDS_FUNCTION*/
- case IRC_UP:/* auto search up */
-
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
- {
- tuner.Istuning[tuner.bandswitch]=1;
- if(search_dir&&(rep_ir_times<INC_SPEED_TIMES))
- {
- search_dir=0;
- //tuner_mute( 0 ); // demute when auto search
- tuner_mute_flag = 1; // auto demute after 500ms
- }else
- {
- if(rep_ir_times<INC_SPEED_TIMES)
- {
- #ifdef TUNER_DBG
- //printf("addn");
- #endif
-
- search(SEARCHADD);
- }else
- {
- // to avoid the noise when enter auto search mode
- tuner_mute_flag = 0;
- search_dir=1;
- }
- }
- break;
- }
- case IRC_DOWN: /* auto search down */
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
- {
- tuner.Istuning[tuner.bandswitch]=1;
- if(search_dir&&(rep_ir_times<INC_SPEED_TIMES))
- {
- search_dir=0;
- //tuner_mute( 0 ); //demute when auto search
- tuner_mute_flag = 1; // auto demute after 500ms
- }else
- {
- if(rep_ir_times<INC_SPEED_TIMES)
- {
- #ifdef TUNER_DBG
- //printf("decn");
- #endif
-
- search(SEARCHDEC);
- }else
- {
- // to avoid the noise when enter auto search mode
- tuner_mute_flag = 0;
- search_dir=2;
- }
- }
- break;
- }
- case IRC_LEFT:
- //printf("leftn");
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
-
- if(tuner.bandswitch)//am
- {
- if(tuner.am_ch>0)
- tuner.am_ch--;
- else
- tuner.am_ch = 0;
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch>0)
- tuner.fm_ch--;
- else
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- disfreq();
- break;
- case IRC_RIGHT:
- #ifdef SUPPORT_RDS_FUNCTION//xyy 2003-12-4 16:18
- rds_clear_var();
- #endif
-
- if(tuner.bandswitch) //am
- {
- if(tuner.am_ch<(MAX_MEM_BAND-1))
- tuner.am_ch++;
- else
- tuner.am_ch = (MAX_MEM_BAND-1);
- set_station(tuner.am_ch);
-
- }
- else //fm
- {
- if(tuner.fm_ch<(MAX_MEM_BAND-1))
- tuner.fm_ch++;
- else
- tuner.fm_ch = (MAX_MEM_BAND-1);
- set_station(tuner.fm_ch);
- }
- write2mem =1;
- disfreq();
- break;
- case IRC_FORMAT:
- tuner_st_mono();
- break;
-
- case IRC_ZOOM: /* serach- */
- {
- search_dir=0;
- tuner.bandswitch=(!tuner.bandswitch);
- //printf("bandn");
- set_band(tuner.bandswitch);
- write2mem=1;
- break;
- }
- case IRC_PROGRAM:
- #ifndef NEW_AUTO_SEARCH_ALL
- auto_search_all();
- #else
- auto_search_all_am();
- auto_search_all_fm();
- tuner.fm_ch = 0;
- set_station(tuner.fm_ch); //goto the 1st station
- #endif //NEW_AUTO_SEARCH_ALL
- break;
- #ifdef SUPPORT_APOGEE_AMP
- case IRC_VOLUME_UP:
- // ircmd_volume_up();
- // set_volume(1);
- break ;
- case IRC_VOLUME_DN:
- // ircmd_volume_down();
- // set_volume(0);
- break ;
- #endif
- default:
- break;
- }
- }
- #endif
- #include "sysmain2_inc.h"
- #include "kernel.h"
- #include "tvif.h"
- //#include "radio_rds.h"//xyy 2003-12-1 13:28
- void tuner_main(void)
- {
- osd_init();//xyy 2003-9-23 16:36
- #ifdef NEW_AUTO_SEARCH_ALL
- //change_system_clock(19);
- #endif
- #ifdef TUNER_DISABLE_VIDEO//xyy 2004-11-9
- /// disable_video();
- tv_dacoff(0x3f);
- #endif
-
- load_tuner_E2PROM();//marked by xyy 2003-9-23 9:01
- tunerflag = 0;
- station_input_index = 0;
- tuner_oper_mode = NORMAL_TUNE;
-
- init_tuner();
-
- if(test_tuner())
- {
- psprintf(RegionValStr[2],"TUNER NOT READY");
- PrintOsdMsg(STR_OS_SPACE,0x2,0,1);
- #ifdef XINGQIU_RECEIVER_PANNEL //xyy 2004-8-5
- vfd_set_str(0,0,0,"NOT READY");
- #endif
- while (system_state != SYSTEM_OPEN)
- {
- polling();
- }
- }
- erase_vfd_mem();
-
- while (system_state != SYSTEM_OPEN)
- {
- #ifdef SUPPORT_RDS_FUNCTION //xyy
-
- rds_collect_data();
- disp_rds(rds_func_flag);
- #endif
- disfreq();
- polling();//i=keyscan()
- #if 0
- if(RDS_PS_RDY())
- {
- //printf("ps:%sn",rds_get_ps());
- psprintf(RegionValStr[REGION1],"PS : %s",rds_get_ps());
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_PS_CLR_RDY();
- }
- #endif
- #ifdef SUPPORT_STEREO_DETECT
- if(is_stereo())
- {
- printf("stereon");
- }
- else
- {
- printf("monon");
- }
- #endif //SUPPORT_STEREO_DETECT
- if(search_dir)
- {
- tuner_auto_search();
- }
-
- if(write2mem)
- {
- write2mem=0;
- tuner.memory_status=MEM_MODE;
- save_tuner_E2PROM();//xyy 2003-9-23 9:02
- //printf("writen");
- }
- }
-
- }
- void tuner_auto_search( void )
- {
- if( search_dir == 1 ) //auto search up
- {
- if( tuner.bandswitch )//am
- {//am auto search up
- //Amautosearchup();
- Amautosearch( AUTOSEARCHUP );
- }else
- { // fm auto search up
- //Fmautosearchup();
- Fmautosearch( AUTOSEARCHUP );
- }
- }else // search_dir == 2, auto search down
- {
- if( tuner.bandswitch )//am
- { //am auto search down
- //Amautosearchdown();
- Amautosearch( AUTOSEARCHDOWN );
- }else
- {// fm auto search down
- //Fmautosearchdown();
- Fmautosearch( AUTOSEARCHDOWN );
- }
- }
-
- }
- void d_ms(BYTE ms)
- {
- delay_1ms(ms);
- }
- void disfreq(void)
- {
- #if !defined(TUNER_DISABLE_VIDEO)//xyy 2004-11-9
- if(tuner.bandswitch)
- {
- psprintf(RegionValStr[2],"AM CH:%d %03d KHZ",tuner.am_ch+1,(tuner.ambak>>4)*3-450); //ITEM number
- }
- else
- {
- //int x=tuner.fmbak*5-1070;
- int x = tuner.fmfreq[tuner.fm_ch]*5-1070;
- psprintf(RegionValStr[2],"FM CH:%d %d.%02d MHZ",tuner.fm_ch+1,x/100,x%100); //ITEM number
- }
- PrintOsdMsg(STR_OS_SPACE,0x2,0,1);
- #endif
- vfd_set_power_state(0);
- }
- void search(BYTE search_status)
- {
- tuner_mute(1);
-
- if(tuner.bandswitch)
- {
- if(search_status==SEARCHADD)
- {
- tuner.ambak=(tuner.ambak+0x30);
- if(tuner.ambak>AM_FREQ_MAX) tuner.ambak=AM_FREQ_MIN;
- }
- else if(search_status==SEARCHDEC)
- {
- tuner.ambak=(tuner.ambak-0x30);
- if(tuner.ambak<AM_FREQ_MIN) tuner.ambak=AM_FREQ_MAX;
- }
- tuner.amfreq[tuner.am_ch] = tuner.ambak;
- set_freq(tuner.ambak);
- }
- else
- {
- if(search_status==SEARCHADD)
- {
- tuner.fmbak=(tuner.fmbak+1);
- if(tuner.fmbak>FM_FREQ_MAX) tuner.fmbak=FM_FREQ_MIN;
- }
- else if(search_status==SEARCHDEC)
- {
- tuner.fmbak=(tuner.fmbak-1);
- if(tuner.fmbak<FM_FREQ_MIN) tuner.fmbak=FM_FREQ_MAX;
- }
- tuner.fmfreq[tuner.fm_ch] = tuner.fmbak;
- set_freq(tuner.fmbak);
- }
- disfreq();
- tuner_mute_flag = 1; // auto demute after 500ms
- output_vfd_msg();
- write2mem = 1;
- }
- void output_vfd_msg(void)
- {
- int i;
-
- polling();
-
- #ifdef NEW_AUTO_SEARCH_ALL
- for(i=0;i<4;i++)
- #endif
- {
- polling_vfdr();
- //polling_vfd();
- }
- }
- void Fmautosearch( BYTE autosearch_status )
- {
-
- #ifndef TUNER_DISABLE_VIDEO///xyy 2004-11-9
- #ifdef NEW_AUTO_SEARCH_ALL
- psprintf(RegionValStr[1],"AUTO SCAN");
- PrintOsdMsg(STR_OS_SPACE,0x1,1,1);
- #endif
- #endif
- if(!tuner.bandswitch)
- {
- while(1)
- {
- if( autosearch_status == AUTOSEARCHUP )
- {
- if(search_dir!=1) //up
- return;
-
- tuner.fmbak=(tuner.fmbak+1); // 100K STEP, ref clock: 25k
-
- if(tuner.fmbak>FM_FREQ_MAX) //fm max 107.8MHZ
- {
- tuner.fmbak=FM_FREQ_MIN;//87.8Mhz,ref= 25khz
- tuner_mute_flag=1; // auto demute after 500 ms
-
- break;
- }
- }else if( autosearch_status == AUTOSEARCHDOWN )
- {
- if(search_dir!=2) //down
- return;
-
- tuner.fmbak=(tuner.fmbak-1); //gap = 2. 100K STEP
-
-
- if(tuner.fmbak<FM_FREQ_MIN)//fm min
- {
- tuner.fmbak=FM_FREQ_MAX;
- tuner_mute_flag = 1;
- break;
- }
-
- }
- tuner.fmfreq[tuner.fm_ch] = tuner.fmbak;
- disfreq();
- output_vfd_msg();
- if(is_station())
- {
- write2mem = 1;
- search_station = 1;//xyy 2004-3-12
- #if defined(SUPPORT_STATION_INPUT)//xyy 2004-5-26
- tuner_oper_mode = RECALL_OR_STORE;
- timeout_vfd = 10000;
- #endif
- break;
- }
- }
-
- disfreq();
- }
- search_dir=0;
- }
- void Amautosearch( BYTE autosearch_status )
- {
- #ifndef TUNER_DISABLE_VIDEO//xyy 2004-11-9
- #ifdef NEW_AUTO_SEARCH_ALL
- psprintf(RegionValStr[1],"AUTO SCAN");
- PrintOsdMsg(STR_OS_SPACE,0x1,1,1);
- #endif
- #endif
- if(tuner.bandswitch)//am
- {
- while(1)
- {
- output_vfd_msg();
-
- if( autosearch_status == AUTOSEARCHUP )
- {
- if(search_dir!=1) //up
- return;
-
- tuner.ambak = (tuner.ambak + 0x30); // 3*3k step
-
- if(tuner.ambak>AM_FREQ_MAX) //am max
- {
- tuner.ambak=AM_FREQ_MIN;
- tuner_mute_flag=1; // auto demute after 500 ms
-
- break;
- }
- }else if( autosearch_status == AUTOSEARCHDOWN )
- {
- if(search_dir!=2) //down
- return;
-
- tuner.ambak=(tuner.ambak-0x30); //gap = 3; 3*3K step
-
- if(tuner.ambak<AM_FREQ_MIN)//Am min
- {
- tuner.ambak=AM_FREQ_MAX;
- tuner_mute_flag=1; // auto demute after 500 ms
-
- break;
- }
- }
- tuner.amfreq[tuner.am_ch] = tuner.ambak;
- disfreq();
-
- if(is_station())
- {
- write2mem = 1;
- search_station = 1;
- #if defined(SUPPORT_STATION_INPUT)//xyy 2004-8-5
- tuner_oper_mode = RECALL_OR_STORE;
- timeout_vfd = 10000;
- #endif
- break;
- }
- }
- disfreq();
- }
- search_dir=0;
- }
-
-
-
- void save_tuner_E2PROM(void)
- {
- int test;
- BYTE *p;
-
-
- #ifdef TUNER_DBG
- //printf("!!!run save_tuner_setup ,size:%dn",sizeof(t_tuner));
- #endif
-
- p=(BYTE *)&tuner;
- tuner.checksum = check_sum(p, (sizeof(tuner)-2));
- test=WriteToI2c(0xa0, TUNER_START,p, sizeof(t_tuner));
-
- #ifdef TUNER_DBG
- printf("save checksum %xn",tuner.checksum);
- #endif
- }
- void load_tuner_E2PROM(void)
- {
- int iRts;
- BYTE *p;
-
- //printf("load tuner e2promn");
- p=(BYTE *)&tuner;
- iRts = ReadFromI2c(0xa0, TUNER_START,p, sizeof(t_tuner));
- if(iRts<0)
- {
- init_tuner_var();
- return;
- }
- if(tuner.checksum != check_sum(p, (sizeof(t_tuner)-2)))
- {
- #ifdef TUNER_DBG
- //printf("checksum err! load defaultn");
- #endif
- init_tuner_var();
- save_tuner_E2PROM();
- }
-
- }
- /*****************
- Changed by xyy 2004-5-26
- ******************/
- #if defined(SUPPORT_STATION_INPUT)//xyy 2004-8-5
- void init_tuner_var(void)
- {
- int i;
- printf("init varn");
- for(i=0;i<MAX_MEM_BAND;i++)
- {
- tuner.fmfreq[i]=0x7de;
- tuner.amfreq[i]=0x1470;
- }
- //tuner.memory_band_id[0]=1;
- //tuner.memory_band_id[1]=1;
- tuner.memory_status=NO_MEM_MODE;
- tuner.bandswitch=0; //0:fm, 1:am
- tuner.Istuning[0]=1;
- tuner.Istuning[1]=1;
- tuner.ambak=0x1440;
- tuner.fmbak=0x7b2;
- // tuner.in2_data1=0x00;
- //p = (BYTE *)&tuner;
- //tuner.checksum = check_sum(p,sizeof(tuner));
-
- #ifdef TUNER_DBG
- //report_tuner_info();
- #endif
- }
- #else
- void init_tuner_var(void)
- {
- const UINT16 fmfreq[MAX_MEM_BAND]={0x7de,0x802,0x86c,0x87e,0x91e,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922,0x922};// 90.0 91.8 97.1 98.0 106.0 106.2
- const UINT16 amfreq[MAX_MEM_BAND]={0x1470,0x15f0,0x1e30,0x26a0,0x2ac0,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20,0x2b20};//531 603 999 1404 1602 1620
- int i;
- //BYTE *p;
- printf("init varn");
- for(i=0;i<MAX_MEM_BAND;i++)
- {
- tuner.fmfreq[i]=fmfreq[i];
- tuner.amfreq[i]=amfreq[i];
- }
-
- //tuner.memory_band_id[0]=1;
- //tuner.memory_band_id[1]=1;
- tuner.memory_status=NO_MEM_MODE;
- tuner.bandswitch=0; //0:fm, 1:am
- tuner.Istuning[0]=1;
- tuner.Istuning[1]=1;
- tuner.ambak=0x1440;
- tuner.fmbak=0x7b2;
- // tuner.in2_data1=0x00;
- //p = (BYTE *)&tuner;
- //tuner.checksum = check_sum(p,sizeof(tuner));
-
- #ifdef TUNER_DBG
- //report_tuner_info();
- #endif
- }
- #endif
- #if defined(SUPPORT_STATION_INPUT)
- /**********************
- Changed by xyy 2004-5-24
- **********************/
- void tuner_func_input(void) //xyy 2003-11-3 11:20
- {
- // if(tuner.memory_status==MEM_MODE)
- if(tuner_oper_mode == RECALL_OR_STORE)
- {
- vfd_set_stationNm();
- }
- #if defined(SUPPORT_FREQ_DIRECT_CALL)
- else if(tuner_oper_mode == FREQ_DIRECT_CALL)//xyy 2004-7-28
- {
- if(tuner.bandswitch)
- vfd_set_amFreq_input();
- else
- vfd_set_fmFreq_input();
- }
- #endif
- }
- #endif
- void tuner_st_mono(void)
- {
- if(tuner.st_mono == 1)
- {
- tuner.st_mono = 0;
- psprintf(RegionValStr[1],"MONO");
- }
- else
- {
- tuner.st_mono = 1;
- psprintf(RegionValStr[1],"ST");
- }
- PrintOsdMsg(STR_OS_SPACE,0x1,1,1);
- set_mono_stereo(tuner.st_mono);
- write2mem=1;
- }
- #ifdef SUPPORT_RDS_FUNCTION
- disp_rds_func(BYTE enter_flag)
- {
- printf("flag %dn",enter_flag);
- if(enter_flag == 0)
- {
- psprintf(RegionValStr[REGION1],"PS :");
- PrintOsdMsg(0, REGION1, 1, 1);
- }
-
- else if(enter_flag == 1)
- {
- psprintf(RegionValStr[REGION1],"PTY :");
- PrintOsdMsg(0, REGION1, 1, 1);
- }
-
- else if(enter_flag == 2)
- {
- psprintf(RegionValStr[REGION1],"RT :");
- PrintOsdMsg(0, REGION1, 1, 1);
- }
- else if(enter_flag == 3)
- {
- psprintf(RegionValStr[REGION1],"CT :");
- PrintOsdMsg(0, REGION1, 1, 1);
- }
- else if(enter_flag == 4)
- {
- psprintf(RegionValStr[REGION1],"PTYN :");
- PrintOsdMsg(0, REGION1, 1, 1);
- }
- }
- void disp_rds(BYTE enter_flag)
- {
- char rds_disp_buf[65];
-
- if(enter_flag == 0)
- {
- if(RDS_PS_RDY())
- {
- psprintf(RegionValStr[REGION1],"PS : %s",rds_get_ps());
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_PS_CLR_RDY();
- }
- }
-
- else if(enter_flag == 1)
- {
- if(RDS_PTY_RDY())
- {
- psprintf(RegionValStr[REGION1],"PTY : %s",rds_get_pty());
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_PTY_CLR_RDY();
- }
- }
-
- else if(enter_flag == 2)
- {
- if(RDS_RTA_RDY()||RDS_RTB_RDY())
- {
- memcpy(rds_disp_buf,rds_get_rt(RDS_RT_TYPE()),64);
- capitalize(rds_disp_buf, 0, 64);
- str_filter(rds_disp_buf, 64);
- psprintf(RegionValStr[REGION1],"RT : %s",rds_disp_buf);
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_RTA_CLR_RDY();
- RDS_RTB_CLR_RDY();
- }
- }
- else if(enter_flag == 3)
- {
- if(RDS_CT_RDY())
- {
- psprintf(RegionValStr[REGION1],"%s",rds_get_ct());
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_CT_CLR_RDY();
- }
- }
- else if(enter_flag == 4)
- {
- if(RDS_PTYN_RDY())
- {
- psprintf(RegionValStr[REGION1],"PTYN:%s",rds_get_ptyn());
- PrintOsdMsg(0, REGION1, 1, 1);
- RDS_PTYN_CLR_RDY();
- }
- }
-
- }
- #endif /*rds func*/