📄 radio_player.c
字号:
/**
refactored by liwei@fw.act
2007-02-08
*/
#include "includes.h"
#include "actions_reg_213x.h"
#include "atj213x.h"
#include "radio_player.h"
#include "irq_timer.h" //soft timer.
#include "device.h" //setupCorePll, changeCorePll, chipCheck
//#define FM_DBG
#ifdef FM_DBG
#define dbg(x...) printf("FM dbg : " x)
#else
#define dbg(...) do { } while (0)
#endif
static radio_info_t radio_info =
{
.status = PLAYER_STOPPED,
.current_freq = 87000,
// .search_step = 0, //not used
.stereo_status = 1, //mono mode
.band_mode = US, //band info
.cur_volume = 0X10,
.threshold = 0x5,
.intensity =0
};
static radio_info_t null_info; //just to fool the user
void fm_set_pa_enable(void);
void * radioOpen(void* nullp)
{
int ret;
int bandinfo;
dbg(" into radioOpen \n");
/* 系统频率初始为0级 */
// setupCorePll(2);
// sys_clk = 2;
#if 0
/* 构造定时器 */
timer.timerHandler = (void *)timer_handler;
timer.timerValue = 2*100; //定时器时间间隔定为2秒
timer.type = TIMER_CYCLE;
timeno = set_timer(&timer);
#endif
i2c_get_gpio();
fm_host_init();
bandinfo = 0; //default US mode
ret = fm_init(bandinfo);
#if 0
if(ret){
// changeCorePll(0,sys_clk);
// sys_clk = 0;
i2c_release_gpio();
printf("fm_dbg: fm_init falied\n");
return (void *)0;
}
#endif
// fm_stop_playing();
radio_info.band_mode = bandinfo;
i2c_release_gpio();
dbg("open succ\n");
return &null_info;
}
int radioCmd(void *handle,unsigned int cmd,unsigned int param)
{
int ret;
unsigned int * value_p;
player_status_t * intensity_ptr;
radio_info_t * fm_info_ptr;
dbg("into radioCmd\n\n");
// dbg("\n");
ret = 0; //always success
i2c_get_gpio();
switch (cmd) {
case GET_RADIO_STEREO_MODE:
*((unsigned int *) param) = radio_info.stereo_status;
break;
case SET_RADIO_BAND_MODE:
ret = fm_set_band_mode(param);
if (!ret)
radio_info.band_mode = ( (param == 0) ? 0 :1 ) ;
break;
case SET_RADIO_FREQ://should named IS_FREQ_VALID_STATION
#if 0
/********************************* 搜索电台时需要升高频率*******************************************/
pullup_flag = 1; //系统需要升频
changeCorePll(2, sys_clk);
sys_clk = 2;
/********************************************************************************************/
#endif
ret = is_freq_valid_station(param);
radio_info.current_freq = param;
fm_get_current_station_intensity(&(radio_info.intensity));
fm_get_stereo_mode(&(radio_info.stereo_status));
radio_info.status = FM_SEARCHING;
break;
case PLAY:
ret = fm_start_playing();
if(!ret)
radio_info.status = PLAYER_PLAYING;
break;
case STOP:
ret = fm_stop_playing();
if(!ret)
radio_info.status = PLAYER_STOPPED;
break;
case GET_RADIO_INFO:
*((radio_info_t*)param) = radio_info;
break;
#if 0
case SET_PLAYER_VOLUME:
ret = fm_set_volume(param);
if(!ret)
radio_info.cur_volume = param;
break;
#endif
case GET_PLAYER_STATUS:
*(player_status_t *)param = radio_info.status;
break;
case SET_RADIO_THRESHOLD: //should named set threshold
ret = fm_set_intensity_threshold(param);
if(!ret)
radio_info.threshold = param;
break;
case GET_RADIO_INTENSITY:
*(unsigned int*)param = radio_info.intensity;
break;
case SET_INTERNEL_PA_EN:
fm_set_pa_enable();
break;
default:
ret = -1;
break;
}
i2c_release_gpio();
dbg(" ret=%d \n");
return ret;
}
int radioClose(void *handle, void *param)
{
int ret;
dbg("into radioClose\n");
i2c_get_gpio();
fm_host_exit();
i2c_release_gpio();
#if 0
/* 系统频率改回为0级 */
changeCorePll(0,sys_clk);
del_timer(timeno);
#endif
return 0; //success
}
int is_earphone_inserted(void)
{
act_writel(act_readl(GPIO_AOUTEN) & ~(0x1 << 26), GPIO_AOUTEN);
act_writel(act_readl(GPIO_AINEN) | (0x1 << 26), GPIO_AINEN);
if (act_readl(GPIO_ADAT) & (0x1 << 26))
return -1; ///not
return 0; //yes, the earphone is inserted
}
void fm_set_pa_enable(void)
{
int val = act_readl(DAC_ANALOG) & (0x1 << 1);
if (val != 1)
{
act_writel(act_readl(DAC_ANALOG) |(0x1 << 1), DAC_ANALOG);
}
}
/*
****************************************************************************************************
*
* 以下模块是专供FM在96MHz附近搜台用的功能块
*
****************************************************************************************************
*/
void delay(void)
{
int i;
// delay must enough longer,
// herwise key peiding can not cleared stablely
for(i = 0; i < 20; i++);
}
void read_modify_write(int reg, int val)
{
volatile int * p = (volatile int *)reg;
int old_val = *p;
int new_val;
*p = val;
new_val = *p;
// printf("\n reg addr: %x reg_old: %x reg_new:%x \n", reg, old_val, new_val);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -