?? stv199_i.c
字號(hào):
/*****************************************************************************File Name : stv199_i.cDescription : STV0199A LINKIC Device implementation of the DEMOD API.Copyright (C) 1999 STMicroelectronicsRevision History : 02/02/00 Added support for FEC mode, serial clock control, serial data mode and TS output mode.Reference :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************/#define DEMOD_PROTOTYPE static /* Local pre-include defs *//* Includes --------------------------------------------------------------- */#include <string.h> /* C libs */ #include <stdio.h>#include "stlite.h" /* Standard includes */#include "stddefs.h"#include "sttuner.h" /* STAPI Error codes, etc */#include "stcommon.h"#include "demod.h" /* DEMOD Device API */#include "tnr.h" /* TNR Device API */#include "stv199.h" /* Low-level device access */#include "sttbx.h"/* Private types/constants ------------------------------------------------ */#define ANALOG_CARRIER_DETECT_SYMBOL_RATE 5000000#define ANALOG_CARRIER_DETECT_AGC2_VALUE 25#define BANDWIDTH 36000L/* Sub range params -- see SubRangeSetting() for more details */typedef struct{ S16 SubRangeInit; S16 SubRangeLimit; U16 SubRangeSize; S8 SubRangeIndex;} DEMOD_SubRangeParams_t;/* Derotator params */typedef struct{ S16 DerotatorStart; S16 DerotatorValue; S16 DerotatorFrequency; U16 DerotatorLimit; U8 DerotatorStep;} DEMOD_DerotatorParams_t;/* Timing loop parameters -- for tracking timing loop frequency */typedef struct{ U16 NumberSamples; U16 TimingLimit; S16 TimingLoopFrequency; U16 TimingLoopStep; U16 TimingLoopWait; BOOL TimingLoopOk;} DEMOD_TimingLoopParams_t;/* QPSK params -- timer values and frequency lock index */typedef struct{ S16 FLIndex; U32 QPSKFrequency; U16 QPSKWaitValue; U16 DataWaitValue;} DEMOD_QPSKParams_t;/* Scan params -- contains scan settings and all above params */typedef struct{ U32 InitialFrequency; U32 ScannedFrequency; U32 CurrentFrequency; U32 MaxLNBOffset; U32 TunerStep; S32 IQSense; DEMOD_SubRangeParams_t SubRangeParams; DEMOD_DerotatorParams_t DerotatorParams; DEMOD_TimingLoopParams_t TimingLoopParams; DEMOD_QPSKParams_t QPSKParams;} DEMOD_ScanParams_t;/* DEMOD control block */typedef struct{ DEMOD_MapTable_t *MapTable_p; /* Maptable */ ST_Partition_t *MemoryPartition; TNR_Handle_t TunerHandle; /* TNR device access */ STV0199A_Device_t STV0199ADevice; /* 199 device access */} DEMOD_ControlBlock_t;/* Private variables ------------------------------------------------------ */extern DEMOD_MapTable_t __STV0199MapTable;/* Private macros --------------------------------------------------------- *//* This macro is a convenient way of obtaining the underlying hardware * structure from the DEMOD API -- it saves us having to typecast * too much! */#define STV0199A_HANDLE(x) ((STV0199A_Device_t *) \ (&(((DEMOD_ControlBlock_t *)x)->STV0199ADevice)))#define TNR_HANDLE(x) (((DEMOD_ControlBlock_t *)x)->TunerHandle)/* Private function prototypes -------------------------------------------- */static DEMOD_ErrorCode_t InitializeSearchTimers(DEMOD_ControlBlock_t *Demod_p, DEMOD_ScanParams_t *ScanParams_p);static DEMOD_ErrorCode_t FastSearch(DEMOD_ControlBlock_t *Demod_p, U32 Frequency, U32 *NewFrequency_p, BOOL *AGCLevelGood_p);static DEMOD_ErrorCode_t Scan(DEMOD_ControlBlock_t *Demod_p, U32 Frequency, DEMOD_ScanParams_t *ScanParams_p, BOOL *ScanOk_p);static DEMOD_ErrorCode_t SearchQPSK(DEMOD_ControlBlock_t *Demod_p, DEMOD_ScanParams_t *ScanParams_p, BOOL *QPSKOk_p);static DEMOD_ErrorCode_t SetTunerFrequency(DEMOD_ControlBlock_t *Demod_p, U32 Frequency, U32 *NewFrequency_p);static DEMOD_ErrorCode_t IsAGC1Good(DEMOD_ControlBlock_t *Demod_p, BOOL *AGC1GoodLevel_p);static DEMOD_ErrorCode_t IsAGC2Good(DEMOD_ControlBlock_t *Demod_p, U16 NumberSamples, S16 *AGC2Value_p, BOOL *AGC2Good_p);static DEMOD_ErrorCode_t CheckTimingLoop(DEMOD_ControlBlock_t *Demod_p, DEMOD_TimingLoopParams_t *Params_p);static DEMOD_ErrorCode_t CentreTimingLoop(DEMOD_ControlBlock_t *Demod_p, S16 TimingLoopFrequency);static DEMOD_ErrorCode_t CheckQPSK(DEMOD_ControlBlock_t *Demod_p, U16 QPSKWaitValue, BOOL *SignalFound);static DEMOD_ErrorCode_t NewRange(DEMOD_ControlBlock_t *Demod_p, DEMOD_ScanParams_t *ScanParams_p, BOOL *RangeOk_p);static DEMOD_ErrorCode_t SearchData(DEMOD_ControlBlock_t *Demod_p, U32 Frequency, U16 Delay, BOOL *DataFound);static DEMOD_ErrorCode_t Optimization(DEMOD_ControlBlock_t *Demod_p, U32 Frequency, U16 Delay, S32 IQSense, U32 TunerStep, BOOL *SignalFound, U32 *NewFrequency_p);static DEMOD_ErrorCode_t NextQPSKLock(DEMOD_ControlBlock_t *Demod_p, DEMOD_ScanParams_t *ScanParams_p, BOOL *LockFound_p);static DEMOD_ErrorCode_t LargeTunerStep(DEMOD_ControlBlock_t *Demod_p, U32 NewFrequency, DEMOD_ScanParams_t *ScanParams_p);static DEMOD_ErrorCode_t VerifyTimingLoop(DEMOD_ControlBlock_t *Demod_p, S16 TimingLoopFrequency, U16 TimingLoopWait, BOOL *TimingLoopOk_p);static void DEMOD_Delay(U32 n);#ifdef STTUNER_DEBUGstatic void DumpScanParams(DEMOD_ScanParams_t *ScanParams_p);#endif/* API routines ----------------------------------------------------------- *//*****************************************************************************Name: DEMOD_Init()Description: Initializes the DEMOD device.Parameters: InitParams_p, pointer to init params to for guiding the initialization process for this device.Return Value: DEMOD_NO_ERROR, the operation completed without error. STI2C_xxx, there was a problem accessing the device. DEMOD_ERROR_BAD_PARAMETER, one or more params were invalid.See Also: Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_Init(DEMOD_InitParams_t *InitParams_p, DEMOD_Handle_t *Handle_p, DEMOD_Capability_t *Capability_p){ DEMOD_ErrorCode_t Error = DEMOD_NO_ERROR; DEMOD_ControlBlock_t *Demod_p; /* Allocate control block memory */ Demod_p = memory_allocate(InitParams_p->MemoryPartition, sizeof(DEMOD_ControlBlock_t)); /* Ensure allocation succeeded */ if (Demod_p == NULL) return ST_ERROR_NO_MEMORY; /* Store away internal handles */ Demod_p->TunerHandle = InitParams_p->TunerHandle; Demod_p->MapTable_p = &__STV0199MapTable; Demod_p->MemoryPartition = InitParams_p->MemoryPartition; /* Set capabilties */ Capability_p->FECAvail = DEMOD_FEC_ALL; Capability_p->ModulationAvail = DEMOD_MOD_ALL; Capability_p->AGCControl = FALSE; Capability_p->SymbolMin = 0; /* !!TBD!! */ Capability_p->SymbolMax = ((U32)-1); /* !!TBD!! */ /* Hardware specific bindings */ STV0199A_HANDLE(Demod_p)->Handle_p = InitParams_p->DeviceAccess_p; STV0199A_HANDLE(Demod_p)->ExternalClock = InitParams_p->ExternalClock; /* Initialize the hardware registers */ Error = STV0199A_ResetRegisters(STV0199A_HANDLE(Demod_p)); /* Check DEMOD initialization options */ /* TS output mode */ switch (InitParams_p->TSOutputMode) { case DEMOD_TS_SERIAL: STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_TS_OUTPUT_MODE, 1); break; default: case DEMOD_TS_PARALLEL: case DEMOD_TS_DEFAULT: STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_TS_OUTPUT_MODE, 0); break; } /* Set FEC mode */ switch (InitParams_p->FECMode) { case DEMOD_FEC_MODE_DIRECTV: Error = DEMOD_ERROR_FEATURE_NOT_SUPPORTED; return Error; default: case DEMOD_FEC_MODE_DEFAULT: case DEMOD_FEC_MODE_DVB: break; } /* Only set serial configuration if serial mode output */ if (InitParams_p->TSOutputMode == DEMOD_TS_SERIAL) { /* Set serial clock source */ switch(InitParams_p->SerialClockSource) { case DEMOD_SCLK_VCODIV6: Error = DEMOD_ERROR_FEATURE_NOT_SUPPORTED; return Error; default: case DEMOD_SCLK_DEFAULT: case DEMOD_SCLK_MASTER: break; } /* Set serial data mode */ if ((InitParams_p->SerialDataMode /* Rising edge */ & DEMOD_SDAT_VALID_RISING) != 0) STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_OUTPUT_CLOCK_CFG, 1); else STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_OUTPUT_CLOCK_CFG, 0); if ((InitParams_p->SerialDataMode /* Parity enable */ & DEMOD_SDAT_PARITY_ENABLE) != 0) STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_OUTPUT_CLOCK_PLR, 1); else STV0199A_SetProperty(STV0199A_HANDLE(Demod_p), STV0199A_OUTPUT_CLOCK_PLR, 0); } /* Set caller's handle */ *Handle_p = Demod_p; /* Ensure device communications is working */ if (Error != ST_NO_ERROR) { /* Deallocate control block */ memory_deallocate(InitParams_p->MemoryPartition, Demod_p); } return Error;} /* DEMOD_Init() *//*****************************************************************************Name: DEMOD_Term()Description: Performs any necessary operations that are required to cleanup after the DEMOD device.Parameters: Demod_p, pointer to the DEMOD device.Return Value: DEMOD_NO_ERROR, the operation completed without error. Other error codes TBD.See Also: Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_Term(DEMOD_Handle_t Handle){ memory_deallocate(((DEMOD_ControlBlock_t *)Handle)->MemoryPartition, Handle); return ST_NO_ERROR;} /* DEMOD_Term() *//*****************************************************************************Name: DEMOD_IsAnalogCarrier()Description: This routine checks for an analog carrier on the current frequency by setting the symbol rate to 5M (never a digital signal).Parameters: Demod_p, pointer to the DEMOD device. IsAnalog_p, pointer to area to store result: TRUE - is analog FALSE - is not analogReturn Value: DEMOD_NO_ERROR, the operation completed without error. STI2C_xxx, there was a problem accessing the device.See Also: Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_IsAnalogCarrier(DEMOD_Handle_t Handle, BOOL *IsAnalog_p){ DEMOD_ErrorCode_t Error = DEMOD_NO_ERROR; U8 i; U16 Agc2 = 0; /* Assume no analog carrier */ *IsAnalog_p = FALSE; /* Set the symbol rate to analog carrier rate */ Error = STV0199A_SetSymbolRate(STV0199A_HANDLE(Handle), ANALOG_CARRIER_DETECT_SYMBOL_RATE);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -