⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 si4702_rx_fm.c

📁 silabs si4700/02 driver firemware 参考程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	error_ind = OperationSi47XX_2w(WRITE,&(si4700_channel_seek_stop[0]), 1);
	if(error_ind)
		return I2C_ERROR;	

	//wait STC=0
	do
	{	
		error_ind = OperationSi47XX_2w(READ,&(si4700_reg_data[0]), 1);
		if(error_ind)
			return I2C_ERROR;	
		loop_counter++;
	}
	while(((si4700_reg_data[0]&0x40) != 0) && (loop_counter < 0xff));		
	
	if(loop_counter >= 0xff)
    return LOOP_EXP_ERROR;


	//you can read REG0A&0B for channel number or RSSI here
	error_ind = OperationSi47XX_2w(READ,&(si4700_reg_data[0]), 4);	
	if(error_ind)
		return I2C_ERROR;	
		
  freq_reg_data = ((Si47XX_reg_data[2] << 8) | Si47XX_reg_data[3])& 0x3ff;
  *pChannel_Freq = 8750 + freq_reg_data*(channel_space/10);
  
	return OK;

}


/**************************************

Si4702_FM_Seek()

channel_freq: 8750~10800
channel_space: 50,100,200

***************************************/

T_ERROR_OP Si4702_FM_Seek(T_SEEK_MODE seek_mode, 
													unsigned char channel_space, 
													unsigned short *pChannel_Freq, 
													unsigned char *SeekFail)
{
	unsigned char valid_channel;
	unsigned short loop_counter = 0;

	do
	{
		if(Si4702_FM_Seek_Start(seek_mode, channel_space, 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;

	return OK;
}

/**************************************

Si4702_FM_Seek_All()

***************************************/

T_ERROR_OP Si4702_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(Si4702_FM_Tune_Freq(8750, 100) != OK) return ERROR;

	while(*pReturn_Length < Max_Length)
	{
		if(Si4702_FM_Seek(SEEKUP_WRAP, 100, &Channel_Result, &SeekFail) != OK) return ERROR;

		if(SeekFail)
		{
			if(Channel_Result == 8750)
			{
				if(Si4702_FM_Tune_Freq(10800, 100) != OK) return ERROR;
				if(Si4702_FM_Seek(SEEKUP_WRAP, 100, &Channel_Result, &SeekFail) != OK) return ERROR;
				if(Channel_Result == 8750)
				{
					*pChannel_All_Array++ = Channel_Result;
					(*pReturn_Length)++;
				}
			}
			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;
}

/**************************************
Si4702_FM_RDS_ISR()

use standard mode
GPIO2 pull low at least 5ms
RDSR keep high at least 40ms

***************************************/

T_ERROR_OP Si4702_FM_RDS_ISR(void)
{
	unsigned char si4700_reg_data[32];	
	unsigned char error_ind = 0;

	//check whether RDSR=1

	error_ind = OperationSi47XX_2w(READ, &(si4700_reg_data[0]), 12);
	if(error_ind)
		return;	

	if((si4700_reg_data[0]&0x80) != 0)	
	{
		RDS_data_process(&(si4700_reg_data[4]));
	}
	
	return OK;

}

/*************************************************

Si4702_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 Si4702_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(Si4702_FM_Tune_Freq(10800, 100) != 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(Si4702_FM_Seek(SEEKUP_WRAP, 100, &last_channel_result, &SeekFail) != OK) return ERROR;
			
		if(SeekFail)
		{
			if(last_channel_result == 10800)
			{
				if(Si4702_FM_Tune_Freq(10790, 100) != OK) return ERROR;
				if(Si4702_FM_Seek(SEEKUP_WRAP, 100, &last_channel_result, &SeekFail) != OK) return ERROR;
				if(last_channel_result == 10800)
				{
					/*
					DELAY(1ms);
					if(Si4702_FM_Get_RSSI(&last_channel_rssi) != OK) return ERROR;
					*/
				}
				else
					last_channel_result = 10810;
			}
			else
			  last_channel_result = 10810;
		}
		else
		{
			/*
			DELAY(1ms);
			if(Si4702_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;
}

/***************************************************

Si4702_FM_Get_SigLvl_MTK()

for the case: if(valid_stop) then (get_signal_level)

****************************************************/

T_ERROR_OP Si4702_FM_Get_SigLvl_MTK(unsigned char *pRSSI)
{
	unsigned char Si47XX_reg_data[32];	
	unsigned char error_ind = 0;

	DELAY(1ms);
 	error_ind = OperationSi47XX_2w(READ, &(Si47XX_reg_data[0]), 2);
	if(error_ind)
		return I2C_ERROR;
		
	*pRSSI = Si47XX_reg_data[1];

	return OK;

}
/*************************************************

Si4702_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 Si4702_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(Si4702_FM_Tune_Freq(10800, 100) != 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(Si4702_FM_Seek(SEEKUP_WRAP, 100, &last_channel_result, &SeekFail) != OK) return ERROR;
			
		if(SeekFail)
		{
			if(last_channel_result == 10800)
			{
				if(Si4702_FM_Tune_Freq(10790, 100) != OK) return ERROR;
				if(Si4702_FM_Seek(SEEKUP_WRAP, 100, &last_channel_result, &SeekFail) != OK) return ERROR;
				if(last_channel_result == 10800)
				{
					DELAY(1ms);
					if(Si4702_FM_Get_RSSI(&last_channel_rssi) != OK) return ERROR;
				}
				else
					last_channel_result = 10810;
			}
			else
			  last_channel_result = 10810;
		}
		else
		{
			DELAY(1ms);
			if(Si4702_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 + -