?? si47xx_rx_fm.c
字號:
error_ind = OperationSi47XX_2w(WRITE, &(Si47XX_fm_tune_status[0]), 2);
if(error_ind)
return I2C_ERROR;
//wait CTS = 1
do
{
error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 1);
if(error_ind)
return I2C_ERROR;
loop_counter++;
}
while(((Si47XX_reg_data[0]) != 0x80) && (loop_counter < 0xff)); //loop_counter limit should guarantee at least 300us
if(loop_counter >= 0xff)
return LOOP_EXP_ERROR;
//read tune status: you should read out: {0x80,0x01,0x27,0xF6,0x2D,0x33,0x00,0x00} //Freq=0x27F6=10230KHz, RSSI=0x2D=45dBuV, SNR=0x33=51dB
error_ind = OperationSi47XX_2w(READ, &Si47XX_reg_data[0], 8);
if(error_ind)
return I2C_ERROR;
if(((Si47XX_reg_data[1]&0x80) != 0))
*SeekFail = 1;
else
*SeekFail = 0;
if(((Si47XX_reg_data[1]&0x01) != 0))
*valid_channel = 1;
else
*valid_channel = 0;
*pChannel_Freq = ((Si47XX_reg_data[2] << 8) | Si47XX_reg_data[3]);
return OK;
}
/**************************************
Si47XX_Set_FM_Frequency()
***************************************/
T_ERROR_OP Si47XX_Set_FM_Frequency(unsigned short channel_freq)
{
if(Si47XX_FM_Tune_Freq(channel_freq) != OK) return ERROR;
if(Si47XX_Wait_STC() != OK) return ERROR;
return OK;
}
/*********************************************
Si47XX_FM_Seek()
SeekFail:"no any station" or not when in WRAP mode
*********************************************/
T_ERROR_OP Si47XX_FM_Seek(T_SEEK_MODE seek_mode, unsigned short *pChannel_Freq, unsigned char *SeekFail)
{
unsigned char valid_channel;
unsigned short loop_counter = 0;
do
{
if(Si47XX_FM_Seek_Start(seek_mode) != OK) return ERROR;
if(Si47XX_Wait_STC() != OK) return ERROR;
//read seek result:
if(Si47XX_FM_Tune_Status(pChannel_Freq, SeekFail, &valid_channel) != OK) return ERROR;
loop_counter++;
}
while((valid_channel == 0) && (loop_counter < 0xff) && (*SeekFail == 0));
if(loop_counter >= 0xff)
return LOOP_EXP_ERROR;
if((seek_mode == SEEKDOWN_WRAP) || (seek_mode == SEEKUP_WRAP))
if((valid_channel == 1) && (*SeekFail == 1))
*SeekFail = 0;
return OK;
}
/**************************************
Si47XX_FM_Seek_All()
***************************************/
T_ERROR_OP Si47XX_FM_Seek_All(unsigned short *pChannel_All_Array, unsigned char Max_Length, unsigned char *pReturn_Length)
{
unsigned char SeekFail;
unsigned short Channel_Result, Last_Channel = 8750;
*pReturn_Length = 0;
if(Si47XX_Set_FM_Frequency(8750) != OK) return ERROR;
while(*pReturn_Length < Max_Length)
{
if(Si47XX_FM_Seek(SEEKUP_WRAP, &Channel_Result, &SeekFail) != OK) return ERROR;
if(SeekFail)
return OK;
if((Channel_Result) <= Last_Channel)
{
if((Channel_Result) == 8750)
{
*pChannel_All_Array++ = Channel_Result;
(*pReturn_Length)++;
}
return OK;
}
else
{
*pChannel_All_Array++ = Last_Channel = Channel_Result;
(*pReturn_Length)++;
}
}
return OK;
}
/**************************************
Si47XX_FM_Get_RSSI()
***************************************/
T_ERROR_OP Si47XX_FM_Get_RSSI(unsigned char *pRSSI)
{
unsigned short loop_counter = 0;
unsigned char Si47XX_reg_data[32];
unsigned char error_ind = 0;
unsigned char Si47XX_rsq_status[] = {0x23,0x00};
//send CMD
error_ind = OperationSi47XX_2w(WRITE, &(Si47XX_rsq_status[0]), 2);
if(error_ind)
return I2C_ERROR;
//wait CTS = 1
do
{
error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 1);
if(error_ind)
return I2C_ERROR;
loop_counter++;
}
while(((Si47XX_reg_data[0]&0x80) == 0) && (loop_counter < 0xff)); //loop_counter limit should guarantee at least 300us
if(loop_counter >= 0xff)
return LOOP_EXP_ERROR;
error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 8);
if(error_ind)
return I2C_ERROR;
*pRSSI = Si47XX_reg_data[4];
return OK;
}
/*************************************************
Si47XX_FM_Valid_Stop_MTK()
only used for MTK search all...
channel_number must from 87.5,87.6,87.7... to 108
if it's valid station, *Valid_Stop = 1, or *Valid_Stop = 0
note: for MTK channel: 875, 876...
*************************************************/
T_ERROR_OP Si47XX_FM_Valid_Stop_MTK(unsigned short channel_number, unsigned char *Valid_Stop)
{
unsigned char SeekFail;
static unsigned short last_channel_result = 0;
/*
static unsigned char last_channel_rssi;
*/
channel_number * = 10;
if(channel_number == 8750)
{
if(Si47XX_Set_FM_Frequency(10800) != OK) return ERROR;
last_channel_result = 0;
}
if(last_channel_result > channel_number)
*Valid_Stop = 0;
else if(last_channel_result == channel_number)
*Valid_Stop = 1;
else //if(last_channel_result < channel_number)
{
if(Si47XX_FM_Seek(SEEKUP_WRAP, &last_channel_result, &SeekFail) != OK) return ERROR;
if(SeekFail)
last_channel_result = 10810;
else
{
/*
DELAY(1ms);
if(Si47XX_FM_Get_RSSI(&last_channel_rssi) != OK) return ERROR;
*/
}
if(last_channel_result > channel_number)
*Valid_Stop = 0;
else if(last_channel_result == channel_number)
*Valid_Stop = 1;
else //if(last_channel_result < channel_number)
{
*Valid_Stop = 0;
last_channel_result = 10810;
}
}
return OK;
}
/**************************************
Si47XX_FM_Get_SigLvl_MTK()
for the case: if(valid_stop) then (get_signal_level)
***************************************/
T_ERROR_OP Si47XX_FM_Get_SigLvl_MTK(unsigned char *pRSSI)
{
unsigned short loop_counter = 0;
unsigned char Si47XX_reg_data[32];
unsigned char error_ind = 0;
unsigned char Si47XX_rsq_status[] = {0x23,0x00};
DELAY(1ms);
//send CMD
error_ind = OperationSi47XX_2w(WRITE, &(Si47XX_rsq_status[0]), 2);
if(error_ind)
return I2C_ERROR;
//wait CTS = 1
do
{
error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 1);
if(error_ind)
return I2C_ERROR;
loop_counter++;
}
while(((Si47XX_reg_data[0]&0x80) == 0) && (loop_counter < 0xff)); //loop_counter limit should guarantee at least 300us
if(loop_counter >= 0xff)
return LOOP_EXP_ERROR;
error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 8);
if(error_ind)
return I2C_ERROR;
*pRSSI = Si47XX_reg_data[4];
return OK;
}
/*************************************************
Si47XX_FM_Seek_MTK()
only used for MTK search all...
channel_number must from 87.5,87.6,87.7... to 108
if it's invalid station, *Return_RSSI = 0
note: for MTK channel: 875, 876...
*************************************************/
T_ERROR_OP Si47XX_FM_Seek_MTK(unsigned short channel_number, unsigned char *Return_RSSI)
{
unsigned char SeekFail;
static unsigned short last_channel_result = 0;
static unsigned char last_channel_rssi;
if(channel_number == 8750)
{
if(Si47XX_Set_FM_Frequency(10800) != OK) return ERROR;
last_channel_result = 0;
}
if(last_channel_result > channel_number)
*Return_RSSI = 0;
else if(last_channel_result == channel_number)
*Return_RSSI = last_channel_rssi;
else //if(last_channel_result < channel_number)
{
if(Si47XX_FM_Seek(SEEKUP_WRAP, &last_channel_result, &SeekFail) != OK) return ERROR;
if(SeekFail)
last_channel_result = 10810;
else
{
DELAY(1ms);
if(Si47XX_FM_Get_RSSI(&last_channel_rssi) != OK) return ERROR;
}
if(last_channel_result > channel_number)
*Return_RSSI = 0;
else if(last_channel_result == channel_number)
*Return_RSSI = last_channel_rssi;
else //if(last_channel_result < channel_number)
{
*Return_RSSI = 0;
last_channel_result = 10810;
}
}
return OK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -