/*----------------------------------------------------------------------------*/
void fm_radio(void)
{
//    printf("enter fm\n");
    //P05_source_select(P05_SEL_OSC1);
    amux_dsp_eq();

    sys_clk_div(2);//SYSTEM_CLK_DIV2();
    init_fm_rev();

    PT2313_Config(RADIO_CHAN,CHAN_ADJ);

    input_number_en = 1;
    vol_change_en=1;
    main_menu = MENU_FM_MAIN;
    key_table_sel(1);
    flush_all_msg();
    enter_fm_rev();
    disp_port(MENU_FM_MAIN);
    sys_clk_div(4);//SYSTEM_CLK_DIV4();
    set_max_vol(MAX_ANOLOG_VOL,MAX_DIGITAL_VOL);///设置最大音量
    dac_out_select(DAC_AMUX1, 0);
    encode_channel = REC_FM; 
#if ECHO_ENABLE
    encode_channel = REC_MIC ;
#endif 
    encode_vol = REC_AMUX_GAIN;
    fm_rev();
    main_vol_set(0, CHANGE_VOL_NO_MEM);
    amp_mute(1);
    alm_on_flag =0;

    fm_rev_powerdown();
    //P05_source_select(P05_SEL_IO);
    break_encode();

}
void fm_radio(void)
{
#if defined(FM_LINE_IN_SHARE_SAME_CHANNEL)||defined(FM_LINE_IN_ONLY_ONE_MODE_EXIST)
#ifdef USE_LINE_IN_DETECT_FUNC
   if(aux_online){
   	
	Set_Curr_Func(SYS_AUX);
	return;
   }
#endif
#endif

#ifdef NOT_MOUNT_FM_DEV		
       if(get_fm_id() ==0xFFFF){	//NO FM 
		Set_Curr_Func(SYS_IDLE);
		return;
	}
#endif

//     xd_u8 vol_tmp=0;
    PT1 = 1;										//timer1 interrupt 低优先级
    IR_KEY_Detect =0;
#if 1//defined(FM_PLAY_KEY_PAUSE)    
            play_status = MUSIC_PLAY;
#endif

#ifndef DISABLE_P05_OSC_OUTPUT
    fm_osc_output_select(TRUE);
#endif

#if defined(VOL_TUNE_VOL_DEFAULT_TUNE_FREQ_POP)
	radio_freq_tune_pop=0;
#endif

#if defined(K202_WEISI_KL202_V001000000000)
    set_led_enable_bit(1);
#endif	
    set_play_flash(LED_FLASH_ON);
#ifdef USE_AMP_MODE_SELECT
	D_CLASS_AMP_GPIO_INIT(); 
	D_CLASS_AMP_LOW();
#endif
    Mute_Ext_PA(MUTE);
    my_main_vol(0);
#if SDMMC_CMD_MODE
	sd_chk_ctl(SET_SD_L_CHK);
#endif
    flush_low_msg();
    sysclock_div2(1);

    init_fm_rev();

#ifdef RADIO_AM_WM_ENABLE
	FMAM_Mode_Switch_Profile(work_mode);
#else
    	enter_fm_rev();  
#endif
    set_fre(frequency,1);

#ifdef DISP_CH_NUM_IN_RADIO_AT_FISRT
    Disp_Con(DISP_CH_NO);
#else
    Disp_Con(DISP_FREQ);
#endif


//    delay_10ms(1);
	
//vol_tmp = my_music_vol;
//    if(vol_tmp>12)my_music_vol = 12;//dac_channel_sel()会用music_vol 打开声音通道

#ifdef SUPPORT_PT2313

    my_main_vol(0);	
    delay_10ms(10);
	
#ifdef FM_PATH_SHARE_SAME_MP3_PT_CHAN

#ifdef EXCHANGE_LINE_IN_CHANNEL
    aux_channel_crosstalk_improve(DAC_AMUX1);//4  P26,P27 FM_IN
#else
    aux_channel_crosstalk_improve(DAC_AMUX0);//4P24,P25 FM_IN	
#endif

    delay_10ms(20);
	
    PT2313_Config(MP3_CHAN,CHAN_ADJ);
#else
    PT2313_Config(FM_CHAN,CHAN_ADJ);
#endif	

#else//  SUPPORT_PT2313

#ifdef FM_BY_PASS
 //   Mute_Ext_PA(UNMUTE); 
    //my_main_vol(my_music_vol);	
    	aux_channel_crosstalk_improve(DAC_AMUX0);//4P24,P25 FM_IN	  
	//dac_out_select(DAC_DECODE);	//4  
	//aux_ch_reg=DAC_AMUX0;

    	main_vol(0);  
   // dac_highz_output_enable();

#else

#ifdef FM_LINE_IN_SHARE_SAME_CHANNEL

#ifdef EXCHANGE_LINE_IN_CHANNEL
    aux_channel_crosstalk_improve(DAC_AMUX0);//4P24,P25 FM_IN	  
#else
    aux_channel_crosstalk_improve(DAC_AMUX1);//4P26,P27 FM_IN
#endif

#else

#ifdef EXCHANGE_LINE_IN_CHANNEL
    aux_channel_crosstalk_improve(DAC_AMUX1);//4P26,P27 FM_IN
#else
    aux_channel_crosstalk_improve(DAC_AMUX0);//4P24,P25 FM_IN	  
#endif

#endif

#endif	// END OF FM_BY_PASS

#endif	// END OF SUPPORT_PT2313

//    my_music_vol =vol_tmp;
	
    my_main_vol(my_music_vol);	
    set_fre(frequency,1);
#ifdef FM_BY_PASS
    my_main_vol(my_music_vol);	// add here for FM volume setting confirm, after setting the freq ,vol may turn on ....
#endif

    set_max_vol(MAX_ANALOG_VOL, MAX_DIGITAL_VOL);			//设置FM模式的音量上限

    dac_out_select(aux_ch_reg);

    delay_10ms(20);	
    Mute_Ext_PA(UNMUTE);
    fm_rev();
    Mute_Ext_PA(MUTE);
    sys_clock_pll();

    main_vol_set(0, CHANGE_VOL_NO_MEM);
	
    fm_rev_powerdown();

#if defined(VOL_TUNE_VOL_DEFAULT_TUNE_FREQ_POP)
	radio_freq_tune_pop=0;
#endif
	
#if SDMMC_CMD_MODE
	sd_chk_ctl(SET_SD_H_CHK);
#endif

#ifndef DISABLE_P05_OSC_OUTPUT
    fm_osc_output_select(FALSE);
#endif

#if defined(USE_SPECTRUM_PARTTERN)		  
    set_lcd_flash_lock(UNLOCK);	
#endif

#ifdef USE_AMP_MODE_SELECT
	D_CLASS_AMP_HIGH();
#endif
	
}