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

📄 mt6188a1_drv.c

📁 gemini0816 fm drv new
💻 C
📖 第 1 页 / 共 5 页
字号:
#else
   	VCO_LSB += 16927;    	// rounding
   	VCO_LSB /= 33854;	// 384/13000000
   	
   	pf_LSB = 3448;		// 456*64*4/(13000/384)
//   	pf_LSB += 66;		//rounding
//   	pf_LSB /= 132;		//64*384*4/13000000
#endif

//save_irq_mask=SaveAndSetIRQMask();        //Set IRQ to increase process speed   

	MT6188_WriteByte(CW(24, 0), 0x00);	//Stop real-time calibration

   	MT6188_WriteByte(CW(6, 1), MT6188_ReadCache(CW(6, 1)) & 0xFE);	//Reset to default without calibration   
	
   }	
   	
   	MT6188_ReadByte(CW(7, 0), &TmpReg);
   	TmpReg &= 0x1F;
   	if(CurFreq <= 84000)
   		MT6188_WriteByte(CW(7, 0), TmpReg|0xE0);  	// CW7_0  [7:5]  7
   	else if(CurFreq > 84000 && CurFreq <= 92000)
   		MT6188_WriteByte(CW(7, 0), TmpReg|0x60);  	// CW7_0  [7:5]  3
   	else if(CurFreq > 92000 && CurFreq <=100000)
   		MT6188_WriteByte(CW(7, 0), TmpReg|0x20);  	// CW7_0  [7:5]  1	
 	else if(CurFreq > 100000)
 		MT6188_WriteByte(CW(7, 0), TmpReg|0x00);  	// CW7_0  [7:5]  0
   	

   	MT6188_WriteByte(CW(5, 1), (MT6188_ReadCache(CW(5, 1)) & 0xFB) | 0x04);	//CW5_1		[2:2]	1	
   	
   	MT6188_WriteByte(CW(7, 1), MT6188_ReadCache(CW(7, 1)) & 0xFC);		//CW7_1		[1:0]	0	

  	
   	MT6188_WriteByte(CW(5, 1), (MT6188_ReadCache(CW(5, 1)) & 0x7F) | 0x80);	//CW5_1		[7:7]	1
   	
   	MT6188_WriteByte(CW(8, 0), (MT6188_ReadCache(CW(8, 0)) & 0xF7) | 0x08);	//CW8_0		[3:3]	1	

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

#if defined   REF_CLK_32K
	CurFreq += 262144;	// rounding
	CurFreq >>= 19;		// 1/16*32768
   	CurFreqLSB += 16384;    // rounding
   	CurFreqLSB /= 32768;	// 1/32768
   	
#else
	CurFreq += 270834;	// rounding
	CurFreq /= 541667; 	// 24/13000000
   	CurFreqLSB += 16927;    // rounding
   	CurFreqLSB /= 33854;	// 384/13000000
   	
#endif
   	
   	MT6188_WriteByte(CW(12, 1), (MT6188_ReadCache(CW(12, 1)) & 0xFC) | 0x03);  	// CW12_1  [1:0]  0x03	turn-on digital clock

   	MT6188_WriteByte(CW(100, 1), (MT6188_ReadCache(CW(100, 1)) & 0xC0) | 0x10);  	// CW100_1 [5:0]  0x10	Set DAC at half range
   	
   	MT6188_WriteByte(CW(100, 0), MT6188_ReadCache(CW(100, 0)) & 0xF8);  		// CW100_0 [2:0]  0	Set DAC at half range
 
   	MT6188_ReadByte(CW(4, 0), &TmpReg);
   	TmpReg &= 0x7F;
   	if (HiLoInj == LO_INJECTION) 
   	{		
   		MT6188_WriteByte(CW(4, 0), TmpReg);  	// CW4_0    [7:7] 0:Lside
   	}
   	else
   	{
   		MT6188_WriteByte(CW(4, 0), TmpReg|0x80);  // CW4_0  [7:7] 1:Hside
   	}
   	

   	MT6188_WriteByte(CW(9, 1), MT6188_ReadCache(CW(9, 1)) & 0xF9);  		// CW9_1    [2:1]  0x00	turn-off AFC loop
   	
   	MT6188_WriteByte(CW(2, 1), MT6188_ReadCache(CW(2, 1)) & 0xC0);  		// CW2_1  [5:0]  0x00	Fix VCO divider value for calibration
   	
   	MT6188_WriteByte(CW(2, 0), 0x04);  		// CW2_0  [7:0]  0x04	Fix original calibration speed
   	
   	MT6188_WriteByte(CW(18, 0), (MT6188_ReadCache(CW(18, 0)) & 0x7F) | 0x80);  	// CW18_0  [7:7] 0x80	Fix original calibration speed
   	
   	MT6188_WriteByte(CW(3, 0), (MT6188_ReadCache(CW(3, 0)) & 0xEF) | 0x10);  	// CW3_0   [4:4] 0x10	Disconnect RFPLL
   	
   	MT6188_WriteByte(CW(3, 0), (MT6188_ReadCache(CW(3, 0)) & 0xF8) | 0x05);  	// CW3_0   [2:0] 0x05	Turn-on reference clock path
   	
   	MT6188_WriteByte(CW(7, 1), (MT6188_ReadCache(CW(7, 1)) & 0xFC) | 0x03);  	// CW7_1   [1:0] 0x03  Calibration standby

   	MT6188_WriteByte(CW(6, 0), MT6188_ReadCache(CW(6, 0)) & 0xFC);  		// CW6_0   [1:0] 0x00  select calibration window
   	
   	MT6188_WriteByte(CW(6, 1), 0x00);  		// CW6_1   [7:0] 0x00  select calibratio MSB of VCO

	MT6188_WriteByte(CW(25, 0), (uint8)(CurFreq&0xFF));
   	MT6188_WriteByte(CW(25, 1), (uint8)(CurFreq>>8));  	// CW25   Set calibration target frequency

 
   	MT6188_WriteByte(CW(1, 0), 0x00);  		// CW1_0   [7:0]  clear interrupt flag
   	
   	MT6188_WriteByte(CW(6, 1), (MT6188_ReadCache(CW(6, 1)) & 0xFE) | 0x01);  	// CW6_1   [0:0]  0x01	start calibration

#ifdef MT6188_timing_cal
#ifdef MT6188_DEBUG_DUMP_LOG
   duration_t = video_get_duration_ms(start_t);
   kal_sprintf((void*)_dbg_str, "  Set_freq1: %d ms.\n\0", duration_t);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif   
#endif   

   	
   	/// Make sure that the counting is done
   	do {
   		
   	   	if ((WaitingCounter >> 8) == 1) {
   	      		return false;
   	   }
   	   	if ((++WaitingCounter & 0x00FF) != 0) {
   	      		MT6188_ReadByte(CW(1, 0), &TmpReg);
   	   }
   	} while ((TmpReg & 0x01) == 0);
   		
   	MT6188_WriteByte(CW(1, 0), 0x00);    		// Reset CW1_0	Clear interrupt flag

#ifdef MT6188_timing_cal
#ifdef MT6188_DEBUG_DUMP_LOG
   duration_t = video_get_duration_ms(start_t);
   kal_sprintf((void*)_dbg_str, "  Set_freq2: %d ms.\n\0", duration_t);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif   
#endif   

 
 	MT6188_ReadByte(CW(96, 0), &TmpReg);
   	if(TmpReg <= 63)
   		MT6188_WriteByte(CW(96, 0), TmpReg+1);	// 
   		

   	MT6188_WriteByte(CW(5, 1), MT6188_ReadCache(CW(5, 1)) & 0xFB);  		// CW5_1  [2:2]  0x00	fit LSB of VCO
	
	MT6188_WriteByte(CW(1, 0), 0x00);    		// Reset CW1_0	Clear interrupt flag 	
	
   	MT6188_WriteByte(CW(6, 0), (MT6188_ReadCache(CW(6, 0)) & 0xFC) | 0x01);  	// CW6_0  [1:0]  0x01	Select calibration window for LSB
   	
   	MT6188_WriteByte(CW(6, 1), 0x30);  		// CW6_1  [7:0]  0x30(32)  select calibration LSB1 of VCO
   	
   	MT6188_WriteByte(CW(25, 0), (uint8)(CurFreqLSB&0xFF));
   	MT6188_WriteByte(CW(25, 1), (uint8)(CurFreqLSB>>8));  	// CW25 [11:0]   Set calibration target frequency for VCO LSB


   	MT6188_WriteByte(CW(6, 1), (MT6188_ReadCache(CW(6, 1)) & 0xFE) | 0x01);  	// CW6_1  [0:0]  0x01	start calibration

#ifdef MT6188_timing_cal
#ifdef MT6188_DEBUG_DUMP_LOG
   duration_t = video_get_duration_ms(start_t);
   kal_sprintf((void*)_dbg_str, "  Set_freq3: %d ms.\n\0", duration_t);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif   
#endif
   	  	
   	/// Make sure that the counting is done
   	do {
   	   	if ((WaitingCounter >> 12) == 1) {
   	      		return false;
   	   }
   	   	if ((++WaitingCounter & 0x0FFF) != 0) {
   	      		MT6188_ReadByte(CW(1, 0), &TmpReg);
   	   }
   	} while ((TmpReg & 0x01) == 0);
   		
   	MT6188_WriteByte(CW(1, 0), 0x00);    		// Reset CW1_0

    if (Chip_ID == 5)
        MT6188_WriteByte(CW(6, 1),  (MT6188_ReadCache(CW(6, 1)) & 0x0F) | 0x10);  	// CW6_1  [7:4]  0x01

   	MT6188_WriteByte(CW(7, 1), MT6188_ReadCache(CW(7, 1)) & 0xFC);  		// CW7_1  [1:0]  0	reset to default without cali
   	
   	MT6188_WriteByte(CW(12, 1), MT6188_ReadCache(CW(12, 1)) & 0xFC);  		// CW12_1 [1:0]  0	reset to default without cali
   	
   	MT6188_WriteByte(CW(5, 1), (MT6188_ReadCache(CW(5, 1)) & 0xFB) | 0x04);  	// CW5_1  [2:2]  0x04  	reset to default without cali
   	
   	MT6188_WriteByte(CW(8, 0), (MT6188_ReadCache(CW(8, 0)) & 0xF7) | 0x08);  	// CW8_0  [3:3]  0x08  	reset to default without cali

    MT6188_WriteByte(CW(5, 1), MT6188_ReadCache(CW(5, 1)) & 0x7F);	//CW5_1		[7:7]	0

#ifdef MT6188_timing_cal
#ifdef MT6188_DEBUG_DUMP_LOG
   duration_t = video_get_duration_ms(start_t);
   kal_sprintf((void*)_dbg_str, "  Set_freq4: %d ms.\n\0", duration_t);
   FS_Write(_file_handle, _dbg_str, strlen((void*)_dbg_str), &_data_written);
#endif   
#endif   

   
   // Enable (1-bit SAR)
   {

   	MT6188_WriteByte(CW(6, 1), MT6188_ReadCache(CW(6, 1)) & 0x0F);	//CW6_1	[7:4]	0   
	
   	MT6188_WriteByte(CW(7, 1), MT6188_ReadCache(CW(7, 1)) & 0xFC);	//CW7_1 [1:0]	0
   	
   	MT6188_WriteByte(CW(5, 1), MT6188_ReadCache(CW(5, 1)) & 0xFB);	//CW5_1	[2:2]	0

   	MT6188_WriteByte(CW(18, 0), MT6188_ReadCache(CW(18, 0)) & 0x7F);  	// CW18_0  [7:7] 0x00	Fix original calibration speed
   	   	
   	MT6188_WriteByte(CW(24, 1), (MT6188_ReadCache(CW(24, 1)) & 0xF8) | 0x05);	//CW24_1	[2:0]	3
   	
   	MT6188_WriteByte(CW(25, 0), (uint8)(VCO_LSB&0xFF));
   	MT6188_WriteByte(CW(25, 1), (uint8)(VCO_LSB>>8));  	// CW25 [11:0]   Set calibration target frequency for VCO LSB


   	MT6188_WriteByte(CW(26, 0), (uint8)(pf_LSB&0xFF));
   	MT6188_WriteByte(CW(26, 1), (uint8)(pf_LSB>>8));  	// CW26 [11:0]   Set calibration target frequency for pf
	
   	
   	MT6188_WriteByte(CW(10, 0), (MT6188_ReadCache(CW(10, 0)) & 0xFC) | 0x03);	//CW10_0	[1:0]	3
   	

	MT6188_WriteByte(CW(6, 1), 0);	//CW6_1	[0:0]	0
   	MT6188_WriteByte(CW(6, 1), 1);	//CW6_1	[0:0]	1
   	

   	MT6188_WriteByte(CW(24, 0), MT6188_ReadCache(CW(24, 0)) & 0xF8);	//CW24_0	[2:0]	M=0
   	
   	MT6188_WriteByte(CW(24, 0), (MT6188_ReadCache(CW(24, 0)) & 0xEF) | 0x10);	//CW24_0	[4:4]	1
   	
   	MT6188_WriteByte(CW(24, 0), (MT6188_ReadCache(CW(24, 0)) & 0xDF) | 0x20);	//CW24_0	[5:5]	1

//RestoreIRQMask(save_irq_mask);        //Set IRQ to increase process speed       	   	
   }
  kal_sleep_task(1);// after set frequency need to wait 5ms
   
#if defined MT6188_DEBUG
   MT6188_DumpCtrlWord();
#endif
   return true;
}                       //Chip_ID=4,MT6188_ECO_V4
else if (Chip_ID == 3)  //Chip_ID=3,MT6188_V3
{
    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, "\nFMDrv_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
#else
   	VCO_LSB += 16927;    	// rounding
   	VCO_LSB /= 33854;	// 384/13000000
   	
   	pf_LSB = 3448;		// 456*64*4/(13000/384)
//   	pf_LSB += 66;		//rounding
//   	pf_LSB /= 132;		//64*384*4/13000000
#endif

//save_irq_mask=SaveAndSetIRQMask();        //Set IRQ to increase process speed    

	MT6188_WriteByte(CW(24, 0), 0x00);	//Stop re

⌨️ 快捷键说明

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