📄 0229.c
字号:
/* **************************************************************************************
* Copyright (c) 2004 ZORAN Corporation, All Rights Reserved
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
*
* File: $Workfile: .c $
*
* Description:
* ============
*
*
* Log:
* ====
* $Revision: $
* Last Modified by $Author: $ at $Modtime: $
**************************************************************************************** */
#include "Config.h" // Global Configuration - do not remove!
#ifdef FTA_SUPPORT
#ifdef SATELLITE_299
#include "Include\SysDefs.h"
#include "devices\demodulator\0299\def.h"
#include "devices\I2C\i2c.h"
#include "devices\demodulator\0299\tun0299.h"
#include "devices\demodulator\0299\reg0299.h"
#include "devices\demodulator\0299\driv0299.h"
#include "devices\demodulator\0299\0229.h"
#include "Kernel\Ker_API.h"
/////////////////////////////////////////////////////////////////////////////////////////////////
// Constants
#define UNIVERSAL_SWITCH 11600000UL
#define UNIVERSAL_HIGH 10600000UL
#define UNIVERSAL_LOW 9750000UL
#define LOW_KU_FREQ 10700000L
#define HIGH_KU_FREQ 12750000L
#define LOW_C_FREQ 3400000L
#define HIGH_C_FREQ 4200000L
#define LNB_C_FREQ 5150000L
#define SET22K_ON 0x3
#define SET22K_OFF 0x0
#define SATELLITE_FEC_22K_MASK 0x8000
/////////////////////////////////////////////////////////////////////////////////////////////////
// Internal Variable
static SDiSEqCMessage sLastDisEqC1_0 = {0};
BOOL bAutoScanStarted = FALSE;
/////////////////////////////////////////////////////////////////////////////////////////////////
// Internal Functions Declaration
static void d229_DisEqC10Send(DEMOD_HANDLE handle,SDiSEqCMessage* DisEqC);
/////////////////////////////////////////////////////////////////////////////////////////////////
// Public Services
void D299_Init(DEMOD_HANDLE handle)
{
DEMOD_SAT_DATA *sDemodData = (DEMOD_SAT_DATA*)handle;
sDemodData->sLnb.demodulator = DEMOD_TYPE_SATELLITE;
sDemodData->sLnb.low_freq = 9750000L;
sDemodData->sLnb.high_freq = 10600000L;
sDemodData->sLnb.switch_freq = 11600000L;
RegSetExtClk(handle, 4000000L); /* Set the frequency of the external quartz */
RegInit(handle); /* Initialize the STV0299 */
TunerSelect(handle, TNR_CUSTOM, TUNERADR); /* Initialize the tuner */
InitParams(handle); /* Initialize parameters for the driver */
}
#pragma argsused
void D299_Standby(long lDemodulator_id, INT32 iStandby)
{
// TODO: HAMAD - implement later
}
// //////////////////////////////////////////////////////////////////////////
// Function Name:
// D299_GetSignalData
//
// Input Parameters:
// pSignal - DEMOD_SIGNAL_ATTRIBUTES defined by OpenTV
// tuning_info - if it is not NULL, try to connect and get signal status
//
// Return Value:
// D299_GetSignalData is always considered valid, whether the demodulator
// is locked or not, and irrespective of whether the demodulator is being
// used for scanning (through the requests above) or is connected using the
// normal demodulator functions. A FAILURE response is expected only if the
// demodulator control driver does not provide the capability. A set request
// is always invalid and should result in an immediate FAILURE response.
//
// Description:
// Gets information on the quality of the signal being received by the
// tuner and demodulation hardware.
// //////////////////////////////////////////////////////////////////////////
INT32 D299_GetSignalData(DEMOD_HANDLE handle, DEMOD_SIGNAL_ATTRIBUTES *pSignal, DEMOD_DELIVERY_INFO* tuning_info)
{
char i;
int j;
UINT16 q;
// if there is request to get a specific signal status do it here
if (tuning_info != NULL)
{
unsigned long freq, sym;
// symbol_rate too small, no need to connect
if (tuning_info->ulSymbolRate < (200UL * 1024UL))
{
return 0;
}
switch (3 & (tuning_info->uiWEPolModFec >> 9))
{
case 0: // Horizontal linear
SetPolarization(handle,HORIZONTAL); /* Select Horizontal polarization */
break;
case 1: // Vertical linear
SetPolarization(handle,VERTICAL); /* Select Horizontal polarization */
break;
case 2: // Circular left
case 3: // Circular right
tr_printf(("Not support circular LNB\n"));
break;
}
freq = tuning_info->ulFrequency;
#ifdef LNB_SEPERATE
//22k is set in ts_tune
freq = ABS((long)(tuning_info->LnbSwitchFreq - freq));
#else
if (0 != tuning_info->ulLnbSwitchFreq)
{
freq = ABS((long)(tuning_info->ulLnbSwitchFreq - freq));
}
else
{
// UNIVERSAL
//
if (freq > UNIVERSAL_SWITCH)
{
freq -= UNIVERSAL_HIGH;
SetLnb(handle,1); /* Select high band */
}
else
{
freq -= UNIVERSAL_LOW;
SetLnb(handle,0); /* Select low band */
}
}
#endif
sym = tuning_info->ulSymbolRate;
InitSearch(handle,freq,sym, 20000000L, 6, DRV_SEARCH); /* Parameters for the search algorithm */
SimpleSearch(handle);
}
i = RegGetOneRegister(handle, R_AGC1I);
j = i+128;
//tr_printf(("Strength %d %x\n", i, j));
pSignal->signal_lock = RegGetField(handle,LK);
pSignal->signal_strength = j*2;
RegGetRegisters(handle, R_NIRH, 2);
q = MAKEWORD(FieldGetVal(handle,NOISEINDICATORMSB), FieldGetVal(handle,NOISEINDICATORLSB));
//tr_printf(("Quality %x\n", q));
if (q >= 0x3800)
{
pSignal->signal_quality = 255;
}
else if (q >= 0x3000)
{
pSignal->signal_quality = 180 + (q-0x3000)*60/0x800;
}
else if (q >= 0x2800)
{
pSignal->signal_quality = 120 + (q-0x2800)*60/0x800;
}
else if (q >= 0x2000)
{
pSignal->signal_quality = 60 + (q-0x2000)*60/0x800;
}
else if (q >= 0x1800)
{
pSignal->signal_quality = 0 + (q-0x1800)*60/0x800;
}
else
{
pSignal->signal_quality = 0;
}
pSignal->signal_quality = 255 - pSignal->signal_quality;
// Transform to percents
pSignal->signal_quality = (pSignal->signal_quality * 100) / 255;
pSignal->signal_strength = (pSignal->signal_strength * 100) / 255;
//tr_printf(("Strength %x, Quality %x\n", (unsigned char)pSignal->signal_strength, pSignal->signal_quality));
return 0;
}
// <<< [ZCH:Nick030902]
// /////////////////////////////////////////////////////////////////////////////
// Function Name:
// d229_DisEqC10Send
//
// Params In:
// handle - Satellite Data handle
// DisEqC - DisEqC command to be sent
//
// Params Out:
// none
//
// Return Value:
// none
//
// Description:
// This function set DisEqC 1.0 switch selection
// /////////////////////////////////////////////////////////////////////////////
static void d229_DisEqC10Send(DEMOD_HANDLE handle,SDiSEqCMessage* DisEqC)
{
UINT32 i;
UINT16 NbData;
UINT8 uDisEqCData[4];
INT16 SaveField1 = 0;
INT16 SaveField2 = 0;
UINT8 RepeatTime = 1;
UINT8 ToneBurst = 0;
if (DISEQC_OPT_RESTORE == (DisEqC->options & DISEQC_OPT_RESTORE))
{
//save original 22k tone status
SaveField1 = RegGetField(handle, UNMODULATEDBURST);
SaveField2 = RegGetField(handle, DISEQCMODE);
}
//switch to DisEqC mode
RegSetField(handle, UNMODULATEDBURST, 1);
RegSetField(handle, DISEQCMODE, 2);
//The max repeat time is 3 times
RepeatTime = DisEqC->repeats;
if (RepeatTime >= 4)
{
RepeatTime = 1;
}
DiseqcSend(handle,DisEqC->data,DisEqC->count);
//repeat messages
for (i=0; i<RepeatTime; i++)
{
//there should be 100 ms between the repeated messages
//but there are 20 ms in the start and end of DiseqcSend
Ker_SleepUs(6000UL);
DiseqcSend(handle,DisEqC->data,DisEqC->count);
}
//send toneburst
ToneBurst = DisEqC->toneburst;
if (ToneBurst > 1)
{
ToneBurst = 0;
}
if (0 == ToneBurst)
{
// send ToneBurst 0
RegSetField(handle, DISEQCMODE, 2);
RegSetField(handle, UNMODULATEDBURST, 0);
uDisEqCData[0] = 0x00;
NbData = 1;
DiseqcSend(handle,uDisEqCData,NbData);
}
else
{
// send ToneBurst 1
RegSetField(handle, DISEQCMODE, 2);
RegSetField(handle, UNMODULATEDBURST, 1);
uDisEqCData[0] = 0xFF;
NbData = 1;
DiseqcSend(handle,uDisEqCData,NbData);
}
// wait for 20 ms
Ker_SleepUs(20000UL);
if (DISEQC_OPT_RESTORE == (DisEqC->options & DISEQC_OPT_RESTORE))
{
//dbprintf(("Restore 22k\n"));
//restore 22k tone setting
RegSetField(handle, UNMODULATEDBURST, SaveField1);
RegSetField(handle, DISEQCMODE, SaveField2);
}
//tr_printf(("DisEqC1.0 data 0x%x Repeat %d, ToneBurst %d\n", DisEqC->data[3], RepeatTime, ToneBurst));
}
// /////////////////////////////////////////////////////////////////////////////
// Function Name:
// D299_Set22kOnOff
//
// Params In:
// handle - Satellite Data handle
// bOn - 22k on/off
//
// Params Out:
// none
//
// Return Value:
// none
//
// Description:
// This function open or close 22k continuous tone
// /////////////////////////////////////////////////////////////////////////////
void D299_Set22kOnOff(DEMOD_HANDLE handle, BOOL bOn)
{
SetLnb(handle,bOn);
}
// /////////////////////////////////////////////////////////////////////////////
// Function Name:
// D299_Get22kOnOff
//
// Params In:
// handle - Satellite Data handle
//
// Params Out:
// none
//
// Return Value:
// return the current 22k continuous tone status
// TRUE 22k on
// FALSE 22k off
//
// Description:
// This function return current continuous tone status.Used to detect current
// 22k status.
// /////////////////////////////////////////////////////////////////////////////
BOOL D299_Get22kOnOff(DEMOD_HANDLE handle)
{
INT32 FieldValue;
BOOL bOn;
FieldValue = RegGetField(handle,DISEQCMODE);
if (SET22K_ON == FieldValue)
{
bOn = TRUE;
}
else
{
bOn = FALSE;
}
tr_printf(("Get 22k On/Off %d\n",bOn));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -