📄 fm_drv.c
字号:
if (flag) {
temp = Read_Buffer[0] & 0x80; //judge if any station has been found
if (temp)
goto exit;
flag = 0;
}
}
exit:
return (flag);
}
/********************************************************************************************
Function is to test FM station.
Input parameter: no
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
Teststation(void)
{
char flag = 0;
static int c;
for (c = 2; c > 0; c--) {
flag = WRITE_ONEFRAME();
if (flag) {
flag = READ_Status();
if (flag) {
DISASSEMBLE_RB();
Searchtemp_LEV = RSET_LEV;
goto exit;
}
}
}
exit:
return (flag);
}
/********************************************************************************************
Function is to set frequency.
Input parameter:
freq(wanted frequency)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_Setfrequency(unsigned long freq)
{
char flag, FM_result, FMadclevel1, FMadclevel2;
unsigned long temp;
int i;
// WSET_MUTE=1;
WSET_MUTE = 0;
WSET_HLSI = 1;
CALCULATE_Pll(freq);
ASSEMBLE_WB();
temp = WSET_PLLHB;
if (WSET_PLLLB > 0xc8) {
temp = temp + 1;
}
Write_Buffer[0] = (temp | 0x80);
Write_Buffer[1] = ((WSET_PLLLB + 0x37) & 0xff);
FM_result = Teststation();
if (FM_result == 0)
goto FM_HLSI1;
FMadclevel1 = Searchtemp_LEV;
temp = WSET_PLLHB;
if (WSET_PLLLB < 0x37) {
temp = temp - 1;
}
Write_Buffer[0] = (temp | 0x80);
Write_Buffer[1] = ((WSET_PLLLB + 0xff - 0x37) & 0xff);
FM_result = Teststation();
if (FM_result == 0)
goto FM_HLSI1;
FMadclevel2 = Searchtemp_LEV;
if (FMadclevel1 < FMadclevel2)
goto FM_HLSI1;
WSET_HLSI = 0x00;
CALCULATE_Pll(freq);
FM_HLSI1:
WSET_MUTE = 0x00;
ASSEMBLE_WB();
for (i = 0; i < 3; i++) {
flag = WRITE_ONEFRAME();
if (flag != 0)
break;
}
return (flag);
}
/********************************************************************************************
Function is FM set frequency.
Input parameter:
freq(want frequency)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_SETFREQ_Drv(unsigned long freq)
{
char flag;
FREQ_RF = freq;
flag = FM_Setfrequency(FREQ_RF);
return (flag);
}
#if 0
/********************************************************************************************
Function is to get status of FM.
Input parameter:
buffer(an array for memory the output data)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
void
FM_GETSTATUS_Drv(unsigned long * buffer)
{
char flag, status, temp;
int i;
for (i = 0; i < 3; i++) {
flag = READ_Status();
if (flag != 0)
break;
}
if (flag) {
DISASSEMBLE_RB();
} else { //err?
//FM_Result=1;
RSET_STEREO = 1;
}
temp = RSET_STEREO;
temp = temp & 0x01;
if (temp == 1)
status = 0;
else
status = 1;
buffer[0] = status;
buffer[1] = (unsigned long) FREQ_RF;
return;
}
#endif
/********************************************************************************************
Function is to set FM mute.
Input parameter:
mute(direct on or off radio)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_SETMUTE_Drv(char mute)
{
char flag = 0;
char m;
unsigned long temp;
Write_Buffer[0] = Write_Buffer[0] & 0x7f; //not mute
WSET_MUTE = mute;
if (WSET_MUTE)
Write_Buffer[0] = Write_Buffer[0] | 0x80; //mute
for (m = 2; m > 0; m--) {
flag = WRITE_ONEFRAME();
if (flag) {
if (mute == 0) {
temp = Read_reg((unsigned long *) (DAC_ANALOG));
temp = temp | 0x400;
Write_reg((unsigned long *) (DAC_ANALOG), temp);
goto exit;
}
temp = Read_reg((unsigned long *) (DAC_ANALOG));
temp = temp & 0xfffffbff;
Write_reg((unsigned long *) (DAC_ANALOG), temp);
goto exit;
}
}
exit:
return flag;
}
#if 0
/********************************************************************************************
Function is to drive stereo of FM.
Input parameter:
stereo(direct on or off standby mode)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_STEREO_Drv(char stereo)
{
char flag = 0;
char c;
Write_Buffer[2] = Write_Buffer[2] & 0xf7; //mono
WSET_MS = stereo;
if (WSET_MS)
Write_Buffer[2] = Write_Buffer[2] | 0x08; //stereo
for (c = 2; c > 0; c--) {
flag = WRITE_ONEFRAME();
if (flag)
goto exit;
}
exit:
return flag;
}
#endif
#if 0
/********************************************************************************************
Function is to set volume of FM.
Input parameter:
volume(set volume level)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_VOLUMESET_Drv(char volume)
{
char flag = 0;
VOLUMELEV = volume;
//flag=PA_Setvolume(VOLUMELEV);
return flag;
}
#endif
/********************************************************************************************
Function is to check FM station.
Input parameter: no
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
CHECK_Station(void)
{
char flag, temp;
int c;
temp = SOFT_LEV; //SOFT_LEV defined by ourself. range:1-16
c = 3;
loop1:
c = c - 1;
if (c == 0)
goto FMerrstop;
flag = WRITE_ONEFRAME();
if (flag == 0)
goto loop1;
flag = READ_Status(); //judge if any station has been found
if (flag == 0)
goto loop1;
DISASSEMBLE_RB();
searchtemp_if = RSET_IFCOUNTER;
searchtemp_stereo = RSET_STEREO;
Searchtemp_LEV = RSET_LEV;
if (Searchtemp_LEV < temp)
goto FMerrstop;
if (searchtemp_if >= IFhighlimit)
goto FMerrstop;
if (searchtemp_if <= IFlowlimit)
goto FMerrstop;
#ifndef DINGXIN_FMmodule
if (searchtemp_stereo == 0)
goto FMerrstop;
#endif
tempresult_LEV = Searchtemp_LEV;
flag = 1;
goto exit;
FMerrstop:
flag = 0;
exit:
return (flag);
}
/********************************************************************************************
Function is to search FM station.
Input parameter:
freq(wanted frequency) softsud(search direction)
Output parameter:
flag(1:success 0:failure)
********************************************************************************************/
char
FM_SEARCH_Drv(unsigned long freq, char softsud)
{
char flag = 0;
char temp, temp1, temp2;
FREQ_RF = freq;
SOFT_SUD = softsud;
WSET_MUTE = 0;
//printk("flag is %x\n", flag);
CALCULATE_Pll(freq);
ASSEMBLE_WB();
flag = CHECK_Station(); //test if any station
//printk("flag is %x\n", flag);
if (flag == 0)
goto exit;
//printk("flag is %x\n", flag);
temp1 = tempresult_LEV; //level1
if (WSET_HLSI == 0)
WSET_HLSI = 1; //opposition HLSI, test
else
WSET_HLSI = 0;
CALCULATE_Pll(freq);
ASSEMBLE_WB();
flag = CHECK_Station();
//printk("flag is %x\n", flag);
//if(flag==0) goto exit;
if (flag == 0)
return 1;
//printk("flag is %x\n", flag);
temp2 = tempresult_LEV; //level2
if (temp2 >= temp1)
goto FMsearchloop2;
else {
temp = temp1;
temp1 = temp2;
temp2 = temp;
goto FMsearchloop3;
}
//printk("flag is %x\n", flag);
FMsearchloop2:
tempresult_LEV = temp1;
if (WSET_HLSI == 0)
WSET_HLSI = 1; //get back the original HLSI
else
WSET_HLSI = 0;
FMsearchloop3:
temp = temp2 - temp1;
if (temp > LEVdiffrence)
goto exit;
//printk("flag is %x\n", flag);
//FM_SETMUTE_Drv(0x01);
// FM_SETMUTE_Drv(0x00);
FM_MUTE(0x0);
flag = 1;
//printk("flag is %x\n", flag);
goto exit;
exit:
return flag;
}
/********************************************************************************************
Function is to find the RSSI of station.
Input parameter: no
Output parameter:
rssi(the value of RSSI)
********************************************************************************************/
char
RSSI_FUC(void)
{
char rssi;
DISASSEMBLE_RB();
rssi = RSET_LEV;
return rssi;
}
/**
band info set : 0: US mode; 1: jpan mode
*/
char BAND_SET(char band)
{
char flag;
if(band==0)
{
Write_Buffer[3]=Write_Buffer[3]&0xdf; //US FM band
}
else
{
Write_Buffer[3]=Write_Buffer[3]|0x20; //JAP FM band
}
flag=WRITE_ONEFRAME();
return(flag);
}
/********************************************************************************************
Function is to test the track of station.
Input parameter: no
Output parameter:
track(1:mono 0:Stereo)
********************************************************************************************/
char TRACK_FUC(void)
{
char track = 0,flag;
flag=READ_ONEFRAME();
if(flag==1)
{
DISASSEMBLE_RB();
track=RSET_STEREO;
// track = 0;
}
return(track);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -