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

📄 cu1216.c

📁 Cu1216 解调器驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	pSignal->signal_strength = 255-(UINT8)((RegGetField0297(handle,AGC2SD_HI)<<6) + (RegGetField0297(handle,AGC2SD_LO)>>2));
		
	if(0 == RegGetField0297(handle,BERT_ON))
	{
		signal_quality = (UINT16)((RegGetField0297(handle,ERRCOUNT_HI)<<8)+(RegGetField0297(handle,ERRCOUNT_LO)));
		RegSetField0297(handle,ERRCOUNT_LO, 0);
		RegSetField0297(handle,ERRCOUNT_HI, 0);		
		RegSetField0297(handle,BERT_ON, 1);
	}

	while(i<16)
	{
		if((signal_quality<<i) & 0x8000)
			break;
		i++;
	}

	pSignal->signal_quality = (16-i)*255/16;	
	#endif
	
	return 0;
}
int Cu1216_GetSignalData1(DEMOD_HANDLE handle, unsigned long *Ber)
{	
	
	
	//d_prinft( "[SIGNAL] BER \n");

	
	tmbsl10023GetBER ((tmUnitSelect_t)0,Ber);
	//d_prinft( "[SIGNAL] BER = %d \n", *Ber);
	
	
	return 0;

}
int Cu1216_GetSignalData2(DEMOD_HANDLE handle, unsigned char *Lvl)
{	
	
	
	//d_prinft( "[SIGNAL] Lvl \n");

	
	tmbsl10023GetLVL((tmUnitSelect_t)0,Lvl);
	//d_prinft( "[SIGNAL] Lvl = %d \n", *Lvl);
	
	
	return 0;

}
// //////////////////////////////////////////////////////////////////////////
// Function Name: Cu1216_AbortScan
// 
// Input Parameters:
//   handle the demod handle, not used for Dcf872x
//
// Return Value:
//  none
//
// Description: 
// 
// this function is used to quit from the scanning process
// //////////////////////////////////////////////////////////////////////////
void Cu1216_AbortScan( DEMOD_HANDLE handle )
{
	g_isScanning = DTV_FALSE; 
	gScanProgress = 0;	
}


// //////////////////////////////////////////////////////////////////////////
// Function Name: 
//   Cu1216_ScanRequest
//
// Input Parameters:
//   pRequest - Pointer to o_demodulator_scan_request defined in OpenTV
//
// Return Value:
//  If the scanning operation is still in progress or an error was encountered, the
//  demodulator control driver should return FAILURE for a get request. Similarly,
//  the demodulator control driver should return FAILURE for a set operation if a
//  scanning operation is in progress or a located signal source has not been
//  unlocked.
//
// Description: 
//  Initiates a scanning operation for the demodulator identified by the 
//  last successful Dcf8710_SetScanMode (per demodulator).
//  When the demodulator locates a signal or encounters an error, a callback 
//  called with NOTIFY_CU1216_LOCKED.
// //////////////////////////////////////////////////////////////////////////

static void Cu1216_SetScanParam( UINT32 freq, UINT32 symRate, UINT32 modulation )
{
	dbprintf(("Setting scan param: Freq = %dkHz, symbol_rate = %dkHz, modulation = %d\n", 
		freq, symRate, modulation));	

    	gRequest.descriptor.delivery.cable.frequency = freq;//convert_decimal_to_BCD(freq/10);
	gRequest.descriptor.delivery.cable.symbol_rate = symRate;//convert_decimal_to_BCD(symRate/10);
	gRequest.descriptor.delivery.cable.modulation = modulation;
	gRequest.descriptor.demodulator_flags = 0;
}

static UINT32 GetScanParameters(UINT32 chanTable, UINT32 *tvStartFreq, UINT32 *dataStartFreq)
{
	UINT32	step = 8000;
	
	switch(chanTable)
	{
	#if 0 //old
		case CHANTABLE_CHINA:
		default:
			*tvStartFreq = 163000;
			*dataStartFreq = 554000;
			break;
	#else //maj.modified
	       case CHANTABLE_CHINA:
		default:
			*tvStartFreq = 115000;
			*dataStartFreq = 474000;
			break;
	
	#endif
	}

	return step;
}

extern   UINT32 frequency;  //maj.added
extern   UINT32 symbolRate;//maj.added

int Cu1216_ScanRequest(DEMOD_HANDLE handle, 
							o_demodulator_scan_request *pRequest ,
							unsigned long *ulScanSymbolRates)
{
	#define	CABLE_END_FREQ	858000

	SIGNAL	Signal;
	INT32	step;
	UINT32	retrieved_events;
	INT32 	tvStartFreq;
	INT32 	dataStartFreq;
	INT32	i;
	
	tmhalFEManagerStatus_t eStatus;
	tmErrorCode_t eErrorCode;

	g_isScanning = TRUE;
	
	step = GetScanParameters(handle, &tvStartFreq, &dataStartFreq);
	dataStartFreq += step;

	/* TCL DTV 	sunyj
	*	Author			Date					Reason
	*---------------------------------------------------------
	*    Sunyoujiang		04/07/21			QAMSIZE, SYMBOL RATE SHOULD TAKE FROM UI INPUT
	*    										Here, we set qamsize to 64 temperly.
	*    Sunyoujiang		04/07/21			we set qamsize in ui osd,so we should set Signal.QAMSize 
	*										with actual value
	----------------------------------------------------------*/
	Signal.QAMSize   = pRequest->descriptor.delivery.cable.modulation ;

	if(0 == ulScanSymbolRates[0])
	{
		ulScanSymbolRates[0] = 6875000;
		ulScanSymbolRates[1] = 0;
	}

	Signal.Frequency = tvStartFreq;

	while(Signal.Frequency < CABLE_END_FREQ)
	{
		i = 0;
		if( (Signal.Frequency < dataStartFreq) && (Signal.Frequency >= dataStartFreq-step) )
			Signal.Frequency = dataStartFreq - step;

		gScanProgress = (Signal.Frequency-tvStartFreq)*100/(CABLE_END_FREQ-tvStartFreq);
		while(0 != ulScanSymbolRates[i])
		{
			Signal.SymbolRate = ulScanSymbolRates[i];   // in Baud/s
	
			if(DTV_FALSE == g_isScanning)			//before time-consuming function, check if scan aborted
					return DTV_TRUE;

			dbprintf(("tmbsl10023Manager: Frequency=%d MHz, SymbolRate=%dKSymb\n", Signal.Frequency/1000, Signal.SymbolRate/1000));
                     #if 0 //maj.added
			frequency  = Signal.Frequency/1000;  //maj.added for ew display
			symbolRate = Signal.SymbolRate/1000;   //maj.added
			#endif

			eErrorCode = tmbsl10023SetRF ((tmUnitSelect_t)0, Signal.Frequency*1000);
    			DISPLAY_ERR (eErrorCode, "tmbsl10023SetRF");
    			eErrorCode = tmbsl10023SetSR ((tmUnitSelect_t)0, Signal.SymbolRate); 
    			DISPLAY_ERR (eErrorCode, "tmbsl10023SetSR");
    			eErrorCode = tmbsl10023SetSI ((tmUnitSelect_t)0, tmhalFESpectrumNormal); 
    			DISPLAY_ERR (eErrorCode, "tmbsl10023SetSI");
    			eErrorCode = tmbsl10023SetMod ((tmUnitSelect_t)0, tmhalFEModulationAuto); 
    			DISPLAY_ERR (eErrorCode, "tmbsl10023SetMod");
    
    			// perform algo
    			do {
        			eErrorCode = tmbsl10023Manager((tmUnitSelect_t)0, &eStatus);
        			DISPLAY_ERR (eErrorCode, "tmbsl10023Manager");
    			} while (tmhalFEManagerStatusNotCompleted == eStatus);

    			//---------------
    			// DISPLAY RESULT
    			//---------------
    			if (tmhalFEManagerStatusCarrierOk == eStatus)
			{
        			dbprintf(("\n Carrier detected...\n"));
	 		
				Cu1216_SetScanParam(Signal.Frequency, Signal.SymbolRate, Signal.QAMSize);

				if (pDemodCallback)
				{
                    			dbprintf(("sendsendsendsendsend lock event to scan task!!!!!!!!11\n"));
					pDemodCallback (Cu1216_GetType(handle),NOTIFY_DEMOD_LOCKED);
				}
                		else
                		{
                    			dbprintf(("the pDemodCallback!!!!!!!!!!!!!!!!\n"));
                		}

				//
				// Wait for UNLOCK event
				//
				if(DTV_FALSE == g_isScanning)			//before time-consuming function, check if scan aborted
					return DTV_TRUE;
				//dbprintf((""));
				OS_Retrieve_Events(&DemodEvents,DEMOD_UNLOCKED_EVENT,
									OS_OR_CONSUME,&retrieved_events,OS_SUSPEND);
				
				if (pDemodCallback)
				{
					pDemodCallback (Cu1216_GetType(handle),NOTIFY_DEMOD_UNLOCKED);
				}
			}			
			i ++;
			
		}
		Signal.Frequency += step; //In kHz			
	}
	
	gScanProgress = 0;
	dbprintf(("Cu1216_ScanRequest()\n"));
	return 0;
}

// //////////////////////////////////////////////////////////////////////////
// Function Name: 
//  Cu1216_GetScanRequest
//
// Input Parameters:
//  pRequest : 
//
// Return Value:
//   0 on fail 1 on success.
//
// Description: 
// Retrieves connection information for this demodulator when a signal is
// successfully locked.
// //////////////////////////////////////////////////////////////////////////
int Cu1216_GetScanRequest(DEMOD_HANDLE handle, o_demodulator_scan_request *pRequest )
{
	DEMOD_CABLE_DATA *sDemodData = (DEMOD_CABLE_DATA*)handle;

	dbprintf(("Cu1216_GetScanRequest():type=0x200 type=0(digital)\n"));

	pRequest->direction                    = 0x0;
	pRequest->hop_frequency                = 0x0;
	pRequest->descriptor.type              = CABLE_DEMOD | sDemodData->Cu1216_Index;
	pRequest->descriptor.demodulator_flags = 0x0; // Digital

	pRequest->descriptor.delivery.cable.frequency = gRequest.descriptor.delivery.cable.frequency;
	pRequest->descriptor.delivery.cable.symbol_rate = gRequest.descriptor.delivery.cable.symbol_rate;
	pRequest->descriptor.delivery.cable.modulation = gRequest.descriptor.delivery.cable.modulation;

	return 1;
}

// //////////////////////////////////////////////////////////////////////////
// Function Name: 
//  Cu1216_GetScanProgress
//
// Input Parameters:
//  demodulator - demodulator ID
//
// Return Value:
//   Number between 0 to 100 which represent the location of the current 
//   demodulator frequency in the demodulator frequency range  
//
// Description: 
//  This function return the percentage of the current frequency in the totlal 
//  possible frequency range of the specify demodulator. It may use for
//  display a progress bar while the auto scanning is active
// //////////////////////////////////////////////////////////////////////////
int Cu1216_GetScanProgress(DEMOD_HANDLE handle, unsigned long demodulator)
{
	dbprintf(("Cu1216_GetScanProgress():%d\n",gScanProgress));
	return gScanProgress;
}



// //////////////////////////////////////////////////////////////////////////
// Function Name: 
//   Cu1216_GetType
//
// Input Parameters:
//   o_demodulator_type - Define in OpenTV specification includes two fields:
//      index - Specifies a value between zero and (number_of_demodulators-1),
//              where the number_of_demodulators value is obtained from the
//              Dcf8710_Query.
//      demodulator - Is a returned value that identifies the type of demodulator
//                    device using the following OpenTV-defined types:
//                    SATELLITE_DEMOD  0x0100 to 0x01ff
//                    CABLE_DEMOD      0x0200 to 0x02ff
//                    TERESTRIAL_DEMOD 0x0300 to 0x03ff
//
// Return Value:
//  The demodulator control driver should return FAILURE if the provided index is
//  invalid.
//
// Description: 
//   This function retrieves the type of specific demodulator 
// //////////////////////////////////////////////////////////////////////////
int Cu1216_GetType(DEMOD_HANDLE handle)
{
	DEMOD_CABLE_DATA *sDemodData = (DEMOD_CABLE_DATA*)handle;

//	dbprintf(("Cu1216_GetType():0x%x\n",CABLE_DEMOD + sDemodData->Cu1216_Index));
	return CABLE_DEMOD + sDemodData->Cu1216_Index;
}

DTV_BOOL Cu1216_CheckI2cPin( I2C_PORT iPinType )
{
	UINT8 tmp;

	if(   I2C_Write(iPinType.sClockGpio,iPinType.sDataGpio,DEMOD_I2C_ADDRESSS,&tmp,1) ==1 &&
		I2C_Read(iPinType.sClockGpio,iPinType.sDataGpio,DEMOD_I2C_ADDRESSS,&tmp,1) ==1)
	{
		return DTV_TRUE;
	}

	return DTV_FALSE;
}

void Cu1216_IdleDemod( DEMOD_HANDLE handle )
{
	DEMOD_CABLE_DATA *sDemodData = (DEMOD_CABLE_DATA*)handle;
	unsigned char  buff[2] = {0x84,0x10};

#if 0
	I2C_Write( sDemodData->iPinType.sClockGpio, sDemodData->iPinType.sDataGpio, 
				CABLE_I2C_ADDR, buff, 2);
#else
#endif

}

void Cu1216_UnIdleDemod( DEMOD_HANDLE handle )
{
	DEMOD_CABLE_DATA *sDemodData = (DEMOD_CABLE_DATA*)handle;
	unsigned char buff[2] = {0x84,0x2a}; // just a guess
#if 0
	I2C_Write( sDemodData->iPinType.sClockGpio, sDemodData->iPinType.sDataGpio, CABLE_I2C_ADDR, buff, 2);
#else
#endif

}
 

⌨️ 快捷键说明

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