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

📄 mt6188a1_drv.c

📁 gemini0816 fm drv new
💻 C
📖 第 1 页 / 共 5 页
字号:
      				mono_flag = 1;
			}
			else
			{
				switch (item_idx)
				{
					case Sblend_ON:
						MT6188_ReadByte(CW(14, 0), &TmpReg1);
      					TmpReg1&=0x2F;
      					MT6188_WriteByte(CW(14, 0),TmpReg1|0xD0);
      					mono_flag = 3;
					break;
					case Sblend_OFF:
						MT6188_ReadByte(CW(14, 0), &TmpReg1);
      					TmpReg1&=0x2F;
      					MT6188_WriteByte(CW(14, 0),TmpReg1|0x90);
      					mono_flag = 4;
					break;
				}
			}
		break;
		case RSSI_threshold:
			if (item_value == 1)
		        	RSSI_offset = 1;
		    	else if (item_value == 2)
		        	RSSI_offset = 2;
		    	else if (item_value == 3)
		        	RSSI_offset = 3;
		    	else if (item_value == 4)
		        	RSSI_offset = 4;
		    	else if (item_value == 5)
		        	RSSI_offset = 5;
		    	else if (item_value == 6)
		        	RSSI_offset = 6;
		    	else
		    		RSSI_offset = 0;//FM_RADIO_INPUT_LEVEL_THRESHOLD;
		break;
		case IF_count_delta:
			if(item_value == 10)
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 20;
#else
				PRESET_IF_DELTA = 19;
#endif
			}
			else if(item_value == 15)
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 30;
#else
				PRESET_IF_DELTA = 28;
#endif
			}
			else if(item_value == 20)
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 39;
#else
				PRESET_IF_DELTA = 38;
#endif
			}
			else if(item_value == 25)
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 52;
#else
				PRESET_IF_DELTA = 50;
#endif
			}
			else if(item_value == 30)
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 60;
#else
				PRESET_IF_DELTA = 58;
#endif
			}
			else
			{
#if !defined( MT6205B ) && !defined( MT6208 )
				PRESET_IF_DELTA = 52;
#else
				PRESET_IF_DELTA = 50;
#endif
			}
		break;
		
	}
	SerialCommRelease();
}

/***********************************************************************
*  Get RSSI Value (internal)
*
*  parameter-->
***********************************************************************/
static uint16 MT6188_GetCurRSSI(void)
{
   uint8 TmpReg;

   MT6188_ReadByte(CW(4, 1), &TmpReg);
   return (TmpReg & 0x1F);
}

/***********************************************************************
*  FM flag clear (internal)
*
*  parameter-->ReadClear: 0: read flag
*                         1: set flag to 0
***********************************************************************/
static uint8 MT6188_ReadIntFlags(bool ReadClear)
{
   uint8 TmpReg;
   MT6188_ReadByte(CW(1, 0), &TmpReg);
   if (ReadClear)
      MT6188_WriteByte(CW(1, 0), 0x00);
   return TmpReg;
}

/***********************************************************************
*  Get IF count (internal)
*
*  parameter-->early_check: 0: don't check IF_count variation
*                           1: check IF_count variation
*             Timing window for 32K clock: 64/32768 = 0.00195 second        
*             Timing window for 26M clock: 49152/26000000 = 0.00189 second  
***********************************************************************/
static int32 MT6188_GetCurIFCnt(uint8 count, uint8 early_check)
{
   uint32 CurIF = 0;
   uint32 WaitingCounter = 0;
   uint32 if_cnt;
   uint8  TmpReg;
   int32  i = (int32)count;
   int32  rssi_consecutive_fail = 0;
   int32  if_consecutive_fail = 0;


//	_valid_rssi = 0;
#ifdef MT6188_DEBUG_DUMP_LOG
   kal_sprintf((void*)_dbg_str, "   MT6188_GetCurIFCnt(%d, %d);\n   \0", count, early_check);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif
   
	MT6188_WriteByte(CW(24, 0), 0x00);	//Stop real-time calibration; disable 1-bit SAR

   	MT6188_WriteByte(CW(5, 1), (MT6188_ReadCache(CW(5, 1)) & 0xFB) | 0x04);	//CW5_1	[2:2]	0
   
   while (--i >= 0) 
    {
        if (Chip_ID == 5)
            MT6188_WriteByte(CW(21, 0), (MT6188_ReadCache(CW(21, 0)) & 0x7F) | 0x80);//enable IF counter
   	
	    MT6188_WriteByte(CW(6, 1), 0x14);
	    MT6188_WriteByte(CW(1, 0), 0x00);	//clear flag
	
      	MT6188_WriteByte(CW(7, 1), MT6188_ReadCache(CW(7, 1)) & 0xFC);
      	
      	MT6188_WriteByte(CW(6, 0), 0x01);
      	
      	MT6188_WriteByte(CW(1, 0), 0x00);
      	
      	MT6188_WriteByte(CW(1, 1), (MT6188_ReadCache(CW(1, 1)) & 0xF7) | 0x08);	//Enable IF counter interrupt
      	
      	MT6188_WriteByte(CW(20, 0), 0x00);	//clear IF counter
	    MT6188_WriteByte(CW(20, 1), 0x00);
      	

     	MT6188_WriteByte(CW(6, 1), (MT6188_ReadCache(CW(6, 1)) & 0xFE) | 0x01);	//Enable time window
     	
     	/// Make sure that the counting is done
      	do {
         	if (++WaitingCounter == 4096) {
            		ASSERT(0);
            		return 0;
         	}
         	MT6188_ReadByte(CW(1, 0), &TmpReg);
      	} while ((TmpReg & 0x08) == 0);
      	
      	MT6188_ReadByte(CW(20, 1), &TmpReg);
      	if_cnt = (TmpReg & 0x03);
      	if_cnt <<= 8;
      
      	MT6188_ReadByte(CW(20, 0), &TmpReg);
      	if_cnt += TmpReg;
      	     	
      	CurIF += if_cnt;
      	     	

     	MT6188_WriteByte(CW(6, 1), MT6188_ReadCache(CW(6, 1)) & 0xFE);	//Disable time window
     	
	    MT6188_WriteByte(CW(1, 0), 0x00);	//clear flag
     	      	
      	
#ifdef MT6188_DEBUG_DUMP_LOG
      kal_sprintf((void*)_dbg_str, "%d,\0", if_cnt);
      FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif


      if (early_check) 
      {
        
         if (if_cnt > (PRESET_IF_CNT + 120) ||
             if_cnt < (PRESET_IF_CNT - 120)) 
        {
            if (++if_consecutive_fail == 1) 
            {
               CurIF /= (count-i);
           
#ifdef MT6188_DEBUG_DUMP_LOG
               kal_sprintf((void*)_dbg_str, "\n   IF Early Check Fail!\n\0");
               FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif
               return -CurIF;
            }
         } 
         else 
         {
            if_consecutive_fail = 0;
         }
      }


    }
    
    CurIF = (CurIF/count);
    if (Chip_ID == 5)
        MT6188_WriteByte(CW(21, 0), 0x00);//0x01//disable IF counter
        																	//disable auto AGC joetsou
    
#ifdef MT6188_DEBUG_DUMP_LOG
   kal_sprintf((void*)_dbg_str, "\n   IF count returned: %d\n\0", CurIF);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif

   return CurIF;
}

/// Timing window for 32K clock: 64/32768 = 0.00195 second
/// Timing window for 26M clock: 49152/26000000 = 0.00189 second
static uint16 MT6188_GetCurIF(void)
{
   uint32 CurIF = MT6188_GetCurIFCnt(IF_MEASURE_COUNT,0);
   CurIF *= IF_CONVERT_FACTOR;
   CurIF += 500;
   CurIF /= 1000;
   return (uint16) CurIF;
}

/***********************************************************************
*  Set radio frequency (internal)
*
*  parameter-->CurFreq:set frequency
*              HiLoInj:set frequency is forward or backward
***********************************************************************/
static bool MT6188_SetFreq(int32 CurFreq, uint8 HiLoInj)
{
if (Chip_ID == 4 || Chip_ID ==5)       //MT6188_ECO_V4/MT6188D
{
	uint16 Divider, N2, Ns, Target;
	int32 CurFreqLSB,VCO_LSB=0,pf_LSB=0;
   	uint8  TmpReg;
   	uint16 WaitingCounter = 0,freq = 0,CurFreq_PLUS = 0;
uint32 save_irq_mask;

#ifdef MT6188_DEBUG_DUMP_LOG
   uint32 start_t, duration_t;
   kal_sprintf((void*)_dbg_str, "\nMT6188_SetFreq(%d, %d);\n\0", CurFreq, HiLoInj);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
   start_t = video_get_current_time();
#endif   
   
   	
   	_current_frequency = CurFreq/FM_TUNER_GRID;
	freq = CurFreq;

   	VCO_LSB = CurFreq;
   // Disable PLL calibration	
   {	   	
  
   	/// DividerNumber = (CurFreq +- PresetIF) * 4 / RefClock 
   	if (HiLoInj == LO_INJECTION) 
   	{
     	 	VCO_LSB -= PRESET_IF;
   	} 
   	else 
   	{
      		VCO_LSB += PRESET_IF;
   	}
   		VCO_LSB *= 4000;

#if defined   REF_CLK_32K
   	VCO_LSB += 16384;    	// rounding
   	VCO_LSB /= 32768;		// 1/32768
   	
   	pf_LSB = 3562;		//456*64*4/32.768
//   	pf_LSB += 64;		//rounding
//   	pf_LSB /= 128;		//64*4/32768

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -