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

📄 driv0299.c

📁 Zoran V966 DVD 解码 Soc芯片的源程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	sn=FieldGetVal(handle,SN);  
	to=FieldGetVal(handle,TO);  
	hy=FieldGetVal(handle,H);  
	errorrate=FieldGetVal(handle,RATE);
	RegTriggerOff(handle);
	
	/* Initial calculations	*/
	RegTriggerOn(handle);
	pParams->DerotStep = pParams->DerotPercent*(pParams->SymbolRate/1000L)/pParams->Mclk;	/*	saut de DerotStep/1000 * Fsymbol	*/     
	pParams->Ttiming = CalcTimingTimeConstant(pParams->SymbolRate);
	pParams->Tderot = 2 + CalcDerotTimeConstant(pParams->SymbolRate);
	pParams->Tdata = 2 + CalcDataTimeConstant(handle,errorrate,sn,to,hy,pParams->SymbolRate);
	RegTriggerOff(handle);
	
	FirstSubRange(pParams);

	/* Initialisations */
	FieldSetVal(handle,DEROTATORFREQUENCYMSB,0); 
	FieldSetVal(handle,DEROTATORFREQUENCYLSB,0);   
	RegSetRegisters(handle,R_CFRM,2); 		/*	Reset of the derotator frequency	*/
	RegSetField(handle,RTF,0);
	RegSetField(handle,CFD_ALGO,1);

	pParams->DerotFreq = 0;
	pParams->State = NOAGC1;
	
	RegTriggerOn(handle);
	pParams->Frequency = TunerSetFrequency(handle,pParams->Frequency);	/* Move the tuner */
	RegTriggerOff(handle);

	pResult->SignalType = pParams->State;
	
	return	pParams->State;
}

/*****************************************************
--FUNCTION	::	GetSearchResult
--ACTION	::	Get the result of the search
--PARAMS IN	::	pResult ==> Pointer to SEARCHRESULT structure
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
void GetSearchResult(DEMOD_HANDLE handle, SEARCHRESULT *pResult)
{
	DEMOD_SAT_DATA *sDemodData = (DEMOD_SAT_DATA*)handle;			

	pResult->SignalType		= sDemodData->Result.SignalType;
	pResult->Polarization	= sDemodData->ScanPolarization;
	pResult->PunctureRate	= sDemodData->Result.PunctureRate;
	pResult->Frequency		= sDemodData->Result.Frequency;
	pResult->SymbolRate		= sDemodData->Result.SymbolRate;
}

/*****************************************************
--FUNCTION	::	EndOfScan
--ACTION	::	Check the end of the scan
--PARAMS IN	::	Direction	->	Direction of the scan
--				Frequency	->	Current frequency
--				EndFrequency	->	Frequency to be reached
--PARAMS OUT::	NONE
--RETURN	::	TRUE if the end is reached, FALSE otherwise 
--***************************************************/
INT32 EndOfScan(SCANDIR Direction, long Frequency, long EndFrequency)
{
	if (Direction == SCANUP)
	{
		return Frequency >= EndFrequency;
	}
	else
	{
		return Frequency <= EndFrequency;
	}
}

/*****************************************************
--FUNCTION	::	SetPolarization
--ACTION	::	set the polarization
--PARAMS IN	::	Polarization	->	Polarization
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
void SetPolarization(DEMOD_HANDLE handle, POLARIZATION Polarization)
{
	if (Polarization == VERTICAL)
	{
		RegSetField(handle,LOCKOUTPUT,0);
		RegSetField(handle,DACMSB,4);
		RegSetField(handle,DACLSB,0xCE);
	}
	else
	{	
		RegSetField(handle,LOCKOUTPUT,1);
		RegSetField(handle,DACMSB,1);
		RegSetField(handle,DACLSB,0x40);
	}
}

/*****************************************************
--FUNCTION	::	GetPolarization
--ACTION	::	Get the polarization
--PARAMS IN	::	Polarization	->	Polarization
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
POLARIZATION GetPolarization(DEMOD_HANDLE handle)
{
	if (RegGetField(handle, LOCKOUTPUT))
	{
		return HORIZONTAL;
	}
	
	return VERTICAL;
}

/*****************************************************
--FUNCTION	::	NextPolarization
--ACTION	::	Compute the next polarization
--PARAMS IN	::	Polarization	->	Current polarization
--				
--PARAMS OUT::	NONE
--RETURN	::	Next polarization 
--***************************************************/
int NextPolarization(DEMOD_HANDLE handle, POLARIZATION Polarization) 
{
	if (Polarization == HORIZONTAL)
	{
		Polarization=VERTICAL;
		SetPolarization(handle,Polarization);
	}
	else
	{
		Polarization=NOPOLARIZATION;
	}
			
	return Polarization;
}

/*****************************************************
--FUNCTION	::	SetLnb
--ACTION	::	set the Lnb
--PARAMS IN	::	Lnb	-> true for LnbHigh, false for LnbLow	
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
void SetLnb(DEMOD_HANDLE handle, INT32 Lnb)
{
	RegSetField(handle,OP0VALUE,(INT)Lnb);

	if (Lnb)
	{
		RegSetOneRegister(handle, R_ACR, 0xe3);		// patch - not supposed to be here but will not work without
		RegSetOneRegister(handle, R_DISEQC, 0xe3);	// turn 22kHz on for High freq.
	}
	else
	{
		RegSetOneRegister(handle, R_ACR, 0xe0);		// patch - not supposed to be here but will not work without
		RegSetOneRegister(handle, R_DISEQC, 0xe0);	// turn 22kHz off for Low freq.
	}
}

/*****************************************************
--FUNCTION	::	SelectLnb
--ACTION	::	Select the local oscillator corresponding to the current frequency 
--PARAMS IN	::	CurrentLnb			->	Current value of the Lnb offset
--				ScanLnb				->	List of Lnb followed by the switch value
--				CurrentFrequency	->	Frequency to be scanned 
--PARAMS OUT::	CurrentLnb			->	New value of the Lnb offset
--RETURN	::	NONE
--***************************************************/
void SelectLnb(DEMOD_HANDLE handle, long *CurrentLnb,long *ScanLnb,long CurrentFrequency)
{
	if (ScanLnb[0] == 0)
	{
		//
		// Non Universal
		//
		*CurrentLnb = ScanLnb[2];
	}
	else
	{
		//
		// Universal
		//
		if ((CurrentFrequency > ScanLnb[2]) && (*CurrentLnb != ScanLnb[1]))
		{
			*CurrentLnb = ScanLnb[1];
			SetLnb(handle,1);
		}
		
		if ((CurrentFrequency < ScanLnb[2]) && (*CurrentLnb != ScanLnb[0]))
		{
			*CurrentLnb = ScanLnb[0];
			SetLnb(handle,0);
		}
	}
}

/*****************************************************
--FUNCTION	::	StartAutoFrequencyScan
--ACTION	::	Search all the carriers with the selected symbol rates and polarization 
--				in the bandwidth [StartScanFrequency,EndScanFrequency]
--				(symbol rates must be in increase order)
--PARAMS IN	::	
--				ScanLnb				->	LowLnb, HighLnb and switch value
--				pSymbolRate			->	List of symbol rates (Kbauds)
--				DerotStep			->	Step of the derotator during the carrier search
--				PolarizationMode	->	polarization test order
--PARAMS OUT::	NONE (Results are returned by the RegisterCarrier() function)
--RETURN	::	NONE
--***************************************************/
void StartAutoFrequencyScan(DEMOD_HANDLE handle, int DerotStep)
{
	int	index;			
	
	DEMOD_SAT_DATA *sDemodData = (DEMOD_SAT_DATA*)handle;

	sDemodData->Params.DerotStepSize = DerotStep;
	sDemodData->Params.CurrentLnb=0;				//	Current lnb used		
	sDemodData->Params.ScanDirection = (sDemodData->StartScanFrequency >= sDemodData->EndScanFrequency) ? SCANDOWN : SCANUP;
	InitParams(handle);									//	structure initialisation	
	
	for (index=0 ; index<MAX_NUMBER_OF_SYMBOL_RATES && sDemodData->Params.SymbolRates[index] ; index++)
	{
		sDemodData->Params.WidthArray[index]=CarrierWidth(sDemodData->Params.SymbolRates[index],sDemodData->Params.RollOff);  
		if(index==0 || sDemodData->Params.WidthArray[index]<sDemodData->Params.MinWidth)
			sDemodData->Params.MinWidth = sDemodData->Params.WidthArray[index];
	}
	
	sDemodData->ScanPolarization = HORIZONTAL;		//	Select the first polarization 
	SetPolarization(handle,HORIZONTAL);
	
	sDemodData->ScanCurrentFrequency = sDemodData->StartScanFrequency;
		
//	dbg_printf(("End of scan\n"));
}

/*****************************************************
--FUNCTION	::	ContinueAutoFrequencyScan
--ACTION	::	Search all the carriers with the selected symbol rates and polarization 
--				in the bandwidth [StartScanFrequency,EndScanFrequency]
--				(symbol rates must be in increase order)
--PARAMS IN	::	
--				ScanLnb				->	LowLnb, HighLnb and switch value
--				pSymbolRate			->	List of symbol rates (Kbauds)
--				DerotStep			->	Step of the derotator during the carrier search
--				PolarizationMode	->	polarization test order
--PARAMS OUT::	NONE (Results are returned by the RegisterCarrier() function)
--RETURN	::	NONE
--***************************************************/
void ContinueAutoFrequencyScan(DEMOD_HANDLE handle)
{
	int index;
	DEMOD_SAT_DATA *sDemodData = (DEMOD_SAT_DATA*)handle;
	UINT32 ulEndFreqInCurrentTry;

		// Never try to scan too much of the freq range at once, 
	ulEndFreqInCurrentTry = sDemodData->ScanCurrentFrequency + ((sDemodData->EndScanFrequency - sDemodData->StartScanFrequency) >> 5);
	
	while (sDemodData->ScanPolarization)		//	polarization loop
	{
		sDemodData->Result.Polarization = sDemodData->ScanPolarization;

		if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST | EXCEPTION_ABORT_FTA_SCAN)) 
		{
			tr_printf(("ContinueAutoFrequencyScan: Exception_catchAndRethrow [0]\n"));

			return;
		}
		
		while (!EndOfScan(sDemodData->Params.ScanDirection, sDemodData->ScanCurrentFrequency, sDemodData->EndScanFrequency))	//While not all the bandwidth is scanned
		{
			index = 0;
			sDemodData->Result.SignalType = NOAGC1; 
			
			if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST | EXCEPTION_ABORT_FTA_SCAN)) 
			{
				tr_printf(("ContinueAutoFrequencyScan: Exception_catchAndRethrow [1]\n"));

				return;
			}

			SelectLnb(handle,&sDemodData->Params.CurrentLnb,sDemodData->Params.lnb,sDemodData->ScanCurrentFrequency);

			while (sDemodData->Params.SymbolRates[index] && sDemodData->Result.SignalType!=RANGEOK)		//	While no channel is found and all symbol rates are not tested	  
			{
				if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST | EXCEPTION_ABORT_FTA_SCAN)) 
				{
					tr_printf(("ContinueAutoFrequencyScan: Exception_catchAndRethrow [2]\n"));

					return;
				}

				InitSearch(handle, LO_FILTER(sDemodData->ScanCurrentFrequency,sDemodData->Params.CurrentLnb),sDemodData->Params.SymbolRates[index],sDemodData->Params.MinWidth,sDemodData->Params.DerotStepSize,DRV_SEARCH);  
				AutoSearchAlgo(handle);	//	Search carrier 
				
				if (sDemodData->Result.SignalType != RANGEOK) 
					index++;
			}
			
			sDemodData->Result.SymbolRate = sDemodData->Params.SymbolRates[index];

			if (!sDemodData->Params.SymbolRates[index])
				index--;

			if (sDemodData->sLnb.low_freq == 0)
			{
				if (lnbGTfreq)
				{
					sDemodData->Result.Frequency = sDemodData->Params.CurrentLnb - sDemodData->Result.Frequency;
				}
				else
				{
				    sDemodData->Result.Frequency = sDemodData->Result.Frequency + sDemodData->Params.CurrentLnb;
				}
			}
			else
			{
				sDemodData->Result.Frequency += sDemodData->Params.CurrentLnb;
			}

			switch(sDemodData->Result.SignalType)
			{
				case RANGEOK:		//	A carrier has been founded
                	tr_printf(("A carrier has been founded %ld,%ld,%s\n",
                		        sDemodData->Result.Frequency,
								sDemodData->Result.SymbolRate,
								(sDemodData->Result.Polarization==1)? "HORIZONTAL" : "VERTICAL" ));

					sDemodData->ScanCurrentFrequency = sDemodData->Result.Frequency + sDemodData->Params.ScanDirection * (sDemodData->Params.WidthArray[index] + sDemodData->Params.MinWidth)/2000;	//	Jump after the founded carrier
					Ker_SendEvent(IE_CORE_FTA_DEMOD_LOCKED, NULL);
					return;  // Found a channel. return to enable table parsing.

				case NOAGC1:
					//dbg_printf(("Demod: No connection\n"));
					sDemodData->ScanCurrentFrequency += sDemodData->Params.ScanDirection * (sDemodData->Params.WidthArray[index] + sDemodData->Params.MinWidth)/2000;	/*	Jump after the founded carrier	*/
					break;

				case NODATA:
					//dbg_printf(("Demod: No data\n"));
					sDemodData->ScanCurrentFrequency += sDemodData->Params.ScanDirection * (sDemodData->Params.WidthArray[index] + sDemodData->Params.MinWidth)/2000;	/*	Jump after the founded carrier	*/
					break;

				default:																			/*	There is signal but no carrier	*/
					sDemodData->ScanCurrentFrequency = sDemodData->ScanCurrentFrequency + sDemodData->Params.ScanDirection * sDemodData->Params.MinWidth/2000;				/*	Jump of (Fs min size)/ 2	*/
					break;
			}
			if (sDemodData->ScanCurrentFrequency > ulEndFreqInCurrentTry)
			{
//				Ker_SendEvent(IE_CORE_FTA_SCAN_TIMEOUT, 0); // FIXME - what should we really send?
//				return;
			}
		}
		
		sDemodData->ScanCurrentFrequency = sDemodData->StartScanFrequency;
		sDemodData->ScanPolarization = NextPolarization(handle,sDemodData->ScanPolarization);				/*	Select the next polarization 	*/
	}
    
	bAutoScanStarted = FALSE;
	Ker_SendEvent(IE_CORE_FTA_DEMOD_RANGE_END, 0); // scanned all Freqencies, polarizations and given SymbolRates
}

/*****************************************************
--FUNCTION	::	DiseqcSend
--ACTION	::	Send bytes accross the diseqc interface
--PARAMS IN	::	Data	=> Data to send
--				NbData	=> Number of data to send 
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
void DiseqcSend(DEMOD_HANDLE handle, unsigned char *Data ,INT32 NbData)
{
	UINT8 i=0;
	
	if (RegGetField(handle,OP0VALUE))
	{
		/* Stop continuous tone (if needed) */
		RegSetField(handle,OP0VALUE,0);
	}
	
	Ker_SleepUs(1000UL * 15UL);
	
	while (i<NbData)
	{
		/* wait for FIFO not full */
		while (RegGetField(handle,FIFOFULL))
			;
		
		/* send byte to FIFO */
		RegSetField(handle,DISEQCFIFO,Data[i]);
		i++;
	}
	
	/* wait for FIFO empty */
	while(!RegGetField(handle,FIFOEMPTY))
		;

	Ker_SleepUs(2000UL);
}

/*****************************************************
--FUNCTION	::	CarrierGetError
--ACTION	::	Compute errors accordings to registers settings
--PARAMS IN	::	NONE
--PARAMS OUT::	NONE
--RETURN	::	Nb of errors if mode = ERRORCOUNT, Bit error rate x 10^7 otherwise 
--***************************************************/
INT32 CarrierGetError(DEMOD_HANDLE handle)
{
	long result = 0;
	
	result = RegGetErrorCount(handle);  
	
	if (RegGetField(handle,CF))	/*	Check for carrier	*/
	{
		if (!FieldGetVal(handle,ERRORMODE))   
		{
			/*	Error Rate	*/
			result *= 9766;
			result /= PowOf2(2 + 2*FieldGetVal(handle,NOE));	/*  theses two lines => result = result * 10^7	*/
			
			switch (FieldGetVal(handle,ERRORSOURCE))
			{
				case 0 :				/*	QPSK bit errors	*/
					result /= 8;
					switch(FieldGetVal(handle,CPR))
					{
						case	0:		/*	PR 2/3	*/
							result *= 2;
							result /= 3;
							break;
				
						case	1:		/*	PR 3/4	*/
							result *= 3;
							result /= 4;
							break;
				
						case	2:		/*	PR 5/6	*/
							result *= 5;
							result /= 6;
							break	;
				
						case	3:		/*	PR 7/8	*/
							result *= 7;
							result /= 8;
							break;
				
						case	4:		/*	PR 1/2	*/
							result *= 1;
							result /= 2;
							break;
				
						default	:
							result = 0;
							break;
				  	}
					break;
			
				case 1:		/*	Viterbi bit errors	*/
					result /= 8;
					break;
		
				case 2:		/*	Viterbi	byte errors	*/
					break;
		  
				case 3:		/*	Packet errors	*/
					result *= 204;
					break;	
			}
		}
	}
	
	return result;
}

#endif // SATELLITE_299

#endif // FTA_SUPPORT

⌨️ 快捷键说明

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