📄 driv0297.c
字号:
/*
//
//==============================================================================
//
// =================================================
// ||| |||
// ||| STV 0297 evaluation software |||
// ||| Version 5.02 dated November 1999 |||
// ||| Authors : Thierry ABRAHAM |||
// ||| : Mariano BONA |||
// ||| SGS-THOMSON Video application Lab. |||
// ||| |||
// =================================================
//
//
// Purpose of the driver
// =====================
// =====================
//
//==============================================================================
//
*/
#include "appldef.h"
/*
#include "def.h"
*/
#define SOURCE DRIV0297
/**/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "reg0297.h"
#include "tun0297.h"
#include "driv0297.h"
/**/
#if (LANGUAGE == CPP)
#define ROUTINE TDriv0297::
#define TUNER_ pTuner->
#define REG_ pReg->
#else
#define ROUTINE
#define TUNER_
#define REG_
#endif
/**/
#if (HOST > 1000)
/* debug facilities */
#include "System.h"
#include "ReportP.h"
#elif (HOST == ST20_SWC)
#include "System.h"
#endif
/**/
#define QAM16 0
#define QAM32 1
#define QAM64 4
#define QAM128 2
#define QAM256 3
FLAG Driv0297DataLocked ;
FLAG Driv0297DataLost ;
/*
#define MILLI_DELAY(__ms__) task_delay ( __ms__ * ST20_CLOCKS_PER_SEC_LOW / 1000 )
*/
#define SystemWaitFor( __ms__) MILLI_DELAY( __ms__ )
/*
//
//==============================================================================
//==============================================================================
//
*/
#if (LANGUAGE == CPP )
/* constructor of the driver */
ROUTINE TDriv0297 ( TI2c *_pI2c,
TReg *_pReg,
TTuner *_pTuner,
TTools *_pTools )
{
pI2c = _pI2c ;
pReg = _pReg ;
pTools = _pTools ;
pTuner = _pTuner ;
/**/
}
#endif
/*
//
*/
void ROUTINE Driv0297Init(void)
{
/*
void ROUTINE _RegInit(void);
*/
int Index ;
_RegInit ();
/* RESET */
RegSTV0297reset() ;
RegReset() ;
/**/
Driv0297DataLost = NO ;
Driv0297DataLocked = NO ;
/**/
return ;
}
/*
//
*/
int ROUTINE Driv0297CarrierSearch(int _QAMSize, unsigned long _SymbolRate, int _SweepRate, int _CarrierOffset, FLAG _SpectrumInversion)
{
int QAMSize ;
int SweepRate ;
int CarrierOffset ;
int TrackingLock ;
unsigned long SymbolRate ;
FLAG SpectrumInversion ;
int DataSearchTime ;
int int_tmp ;
int i ;
int initial_u, blind_u, u_threshold ;
FLAG EndOfSearch ;
/**/
#define TIME_OUT 500
/**/
#if(HOST > 1000)
SystemStartTimer(0) ;
SystemStartTimer(1) ;
ReportStartMessage();
#endif
/**/
/* Driv0297Init() ;*/
#if(HOST > 1000)
SystemStopTimer(1) ;
ReportInsertMessage(10,SystemGetTimerValue(1),0) ;
SystemStartTimer(1);
#endif
/**/
RegTriggerOn() ;
/**/
/*do_report ( severity_info, "OH MY GOODNESS iSweepRate is %d\n", _SweepRate );*/
QAMSize = _QAMSize ;
SymbolRate = _SymbolRate ;
SweepRate = _SweepRate ;
CarrierOffset = _CarrierOffset ;
SpectrumInversion = _SpectrumInversion ;
/*RegSetField(RESET_DI,1) ;
RegSetField(RESET_RS,1) ;
RegSetField(RESET_EQL,1) ;
task_delay( CLOCKS_PER_SEC_LOW );*/
/*
// Wide Band AGC freeze
*/
RegSetField(WAGC_EN,0x00) ;
/*
// PMF AGC unlock forcing is enabled
*/
RegSetField(PMFA_F_UNLOCK,0x01) ;
/*
// Wide Band AGC unlock force
*/
RegSetField(WAGC_ACQ,0x00) ;
/*
// PMF AGC unlock forcing is disabled
*/
RegSetField(PMFA_F_UNLOCK,0x00) ;
/*
// phase clear
*/
RegSetField(PHASE_CLR,0x01) ;
/*
// integral path enabled only after the WBAGC lock
*/
RegSetField(ERR_EN,0x00) ;
/*
// direct path immediatly enabled
*/
RegSetField(PHASE_EN,0x01) ;
/*
// Sweep disable
*/
RegSetField(SWEEP_EN,0) ;
/*
// deinterleaver&descrambler reset
*/
RegSetField(RESET_DI,1) ;
RegSetField(RESET_DI,0) ;
/*
// Reed-Salomon clear
*/
RegSetField(RESET_RS,1) ;
RegSetField(RESET_RS,0) ;
/*
//Equalizer values capture
*/
u_threshold = RegGetField(U_THRESHOLD) ;
initial_u = RegGetField(INITIAL_U) ;
blind_u = RegGetField(BLIND_U) ;
/*
//Equalizer clear
*/
RegSetField(RESET_EQL,1) ;
RegSetField(RESET_EQL,0) ;
/*
//Equalizer values reload
*/
RegSetField(U_THRESHOLD,u_threshold) ;
RegSetField(INITIAL_U,initial_u) ;
RegSetField(BLIND_U,blind_u) ;
/*
// Roll setting
*/
RegSetField(ROLL_LO, 0xFF) ;
RegSetField(ROLL_HI, 0x04) ;
/*
// source selection : internal A/D
*/
RegSetField(SOURCESEL,0) ;
/*
// Algorithm selection : STL 0
*/
RegSetField(ALGOSEL,0) ;
/*
// timing integral gain
*/
RegSetField(INTEGRAL_GAIN_LO, 0x08) ;
RegSetField(INTEGRAL_GAIN_HI, 0x00) ;
/*
// timing direct gain
*/
RegSetField(DIRECT_GAIN_LO, 0x08) ;
RegSetField(DIRECT_GAIN_HI, 0x00) ;
/*
// derotator selection : off
*/
RegSetField(IN_DEMOD_EN, 0x00) ; /* VICKY - 100100 - disabled init demo */
/*
// Frequency Offset Clear
*/
RegSetField(IPHASE_0,0x00) ;
RegSetField(IPHASE_1,0x00) ;
RegSetField(IPHASE_2,0x00) ;
RegSetField(IPHASE_3,0x00) ;
/*
// Parameters setting
*/
RegSetQAMSize(QAMSize) ;
RegSetSymbolRate(SymbolRate) ;
RegSetFrequencyOffset(CarrierOffset) ;
RegSetSweepRate(SweepRate) ;
RegSetField(SPEC_INV,SpectrumInversion) ;
if( QAMSize == 256 ) /*lehu 190100*/
{
RegSetField( U_THRESHOLD, 0x09 );
RegSetField( INITIAL_U, 0x06 );
RegSetField( BLIND_U, 0x09 );
}
else
{
RegSetField( U_THRESHOLD, 0x08 );
RegSetField( INITIAL_U, 0x05 );
RegSetField( BLIND_U, 0x08 );
}
/*
// phase clear release
*/
RegSetField(PHASE_CLR,0x00) ;
/*
// Sweep enable
*/
RegSetField(SWEEP_EN,1) ;
/*
// Wide Band AGC clear
*/
RegSetField(WAGC_CLR,0x01) ;
/*
// Wide Band AGC enable
*/
RegSetField(WAGC_EN,0x1) ;
/*
// Wait for 1 ms (enough for WBAGC lock)
*/
SystemWaitFor(1) ;
/**/
#if(HOST > 1000)
SystemStopTimer(1) ;
ReportInsertMessage(20,SystemGetTimerValue(1),0) ;
SystemStartTimer(1);
#endif
/*
// waiting for a tracking indication or a time-out
*/
DataSearchTime = 0 ;
EndOfSearch = NO ;
while (EndOfSearch == NO)
{
TrackingLock = RegGetField(SYNCSTATE) ;
if(TrackingLock == 1)
{
EndOfSearch = YES ;
for (i = 0 ; i < 3 ; i++)
{
SystemWaitFor(1) ;
DataSearchTime += 1 ;
TrackingLock = RegGetField(SYNCSTATE) ;
if(TrackingLock == 0) EndOfSearch = NO ;
}
}
SystemWaitFor(1) ;
DataSearchTime +=1 ;
if(DataSearchTime > TIME_OUT)
EndOfSearch = YES ;
}
/**/
RegTriggerOff() ;
/**/
if(DataSearchTime <= TIME_OUT)
int_tmp = DataSearchTime ;
else
int_tmp = -1 ;
/**/
#if(HOST > 1000)
if(int_tmp > 0)
{
ReportInsertMessage(100,int_tmp,0) ;
ReportInsertMessage(1000,0,0) ;
}
else
{
ReportInsertMessage(200,TIME_OUT,0) ;
ReportInsertMessage(900,0,0) ;
}
ReportEndMessage() ;
#endif
/**/
return (int_tmp);
}
/*
int Driv0297AutoScan ()
*/
int ROUTINE Driv0297AutoScan(long _StartingFrequency,
long _EndingFrequency ,
long *_pSymbolRateList )
{
long StartingFrequency ,
EndingFrequency ,
*pSymbolRateList ;
long SymbolRate ,
SymbolRateMin ;
int SearchTime ;
int iSymbolRate ;
int iQAM ;
int QAMSize[4] = {QAM16, QAM64, QAM128, QAM256} ;
long CurrentFrequency ,
QAMFrequency ,
QAMOld ,
FrequencyStep ;
FLAG ScanEnd ,
SymbolRateEnd ;
int SweepRate ;
int CarrierOffset ;
FLAG SpectrumInversion ;
double double_tmp ;
/**/
StartingFrequency = _StartingFrequency ; /* in KHz */
EndingFrequency = _EndingFrequency ; /* in KHz */
pSymbolRateList = _pSymbolRateList ; /* in KBaud */
/**/
if((StartingFrequency <= 0)||(EndingFrequency<=0))
/* bad parameters */
return -1;
/**/
pSymbolRateList = _pSymbolRateList ;
SymbolRateMin = 100000L ;
for (iSymbolRate = 0 ; iSymbolRate < 8 ; iSymbolRate++)
{
SymbolRate = pSymbolRateList[iSymbolRate] ;
if((SymbolRate >= 1000L)&&(SymbolRate < SymbolRateMin))
SymbolRateMin = SymbolRate ;
}
/**/
CurrentFrequency = StartingFrequency ;
/**/
if(StartingFrequency <= EndingFrequency)
FrequencyStep = 10000 ; /* 10 MHz */
else
FrequencyStep = -10000 ; /* 10 MHz */
/**/
QAMOld = StartingFrequency - FrequencyStep ;
ScanEnd = NO ;
/**/
while (ScanEnd == NO)
{
pSymbolRateList = _pSymbolRateList ;
CurrentFrequency += FrequencyStep ;
_TunerSetFrequency(CurrentFrequency) ;
SymbolRateEnd = NO ;
/**/
for(iSymbolRate = 0 ; (iSymbolRate < 8)&&(SymbolRateEnd == NO); iSymbolRate++)
{
SymbolRate = pSymbolRateList[iSymbolRate] ;
if(SymbolRate >= 1000L)
{
double_tmp = 6000000.0 ; /* 6 MHz/Sec */
double_tmp /= SymbolRate ;
SweepRate = (int) double_tmp ; /* SweepRate = 1000.0 * (UserSweepRate/Fs) */
QAMFrequency = -1000 ;
for (iQAM = 0 ; (iQAM < 4)&&(QAMFrequency < 0 ) ; iQAM++)
{
SpectrumInversion = NO ;
SearchTime = Driv0297CarrierSearch(QAMSize[iQAM],SymbolRate,SweepRate,CarrierOffset,SpectrumInversion) ;
if(SearchTime > 0)
{
QAMFrequency = CurrentFrequency + RegGetFrequencyOffset() ;
if(FrequencyStep >= 0)
CurrentFrequency = QAMFrequency +
((SymbolRate/2000)+(SymbolRateMin/2000)) ;
else
CurrentFrequency = QAMFrequency -
((SymbolRate/2000)+(SymbolRateMin/2000)) ;
QAMOld = QAMFrequency ;
}
else
{
SpectrumInversion = YES ;
SearchTime = Driv0297CarrierSearch(QAMSize[iQAM], SymbolRate, SweepRate, CarrierOffset, SpectrumInversion) ;
if(SearchTime > 0)
{
QAMFrequency = CurrentFrequency + RegGetFrequencyOffset() ;
if(FrequencyStep >= 0)
CurrentFrequency = QAMFrequency +
((SymbolRate/2000)+(SymbolRateMin/2000)) ;
else
CurrentFrequency = QAMFrequency -
((SymbolRate/2000)+(SymbolRateMin/2000)) ;
QAMOld = QAMFrequency ;
}
}
} /* end of the constellation QAM size loop */
if(QAMFrequency > 0) SymbolRateEnd = YES ;
}
} /*end of the symbol rate loop */
/**/
if (((CurrentFrequency > EndingFrequency)&&(FrequencyStep > 0))
||((CurrentFrequency < EndingFrequency)&&(FrequencyStep < 0))
|| (FrequencyStep == 0))
ScanEnd = YES ;
} /* end of the frequency loop */
/**/
return 0 ;
}
/*
//
*/
/********** Driv297ReloadLoops ******************/
/* Function : reload of the loop values. */
/* If Data locks, the result is YES. */
/* If after 100 ms, Data are not locked, the */
/* routine exits with the value NO */
/* input parameter : none */
/* output parameter : FLAG */
/************************************************/
FLAG Driv0297ReloadLoops(void)
{
FLAG DataLock ;
/**/
DataLock = NO ;
/**/
return(DataLock);
}
/*
//
*/
/********** Driv297MOnitoring *******************/
/* Function : monitoring of the loop values. */
/* If the input signal vanishes, the software */
/* detect this event and try to feed the loops */
/* with the last loop values */
/* input parameter : none */
/* output parameter : none */
/************************************************/
void Driv0297Monitoring(void)
{
int WBAgcGain ;
/**/
WBAgcGain = (RegGetField(AGC2SD_HI)<<8) + RegGetField(AGC2SD_LO);
if((WBAgcGain == 1023)&&
(Driv0297DataLocked == YES)&&
(Driv0297DataLost == NO))
{
/* the signal has vanished */
Driv0297DataLost = YES ;
Driv0297DataLocked = NO ;
}
else if((WBAgcGain != 1023)&&(Driv0297DataLost == YES))
{
/* the signal is here */
Driv0297DataLocked = Driv0297ReloadLoops() ;
if(Driv0297DataLocked == YES)
Driv0297DataLost = NO ;
}
/**/
return;
}
/*
//
//==============================================================================
//
// END of the source code .
//
//==============================================================================
//
// TTT H H EEE
// T HHH EE
// T H H EEE
//
//
// EEEEEEEEEEEE NNNNNNNN NNNN DDDDDDDDDDDDDD
// EEEEEEEEEEEE NNNNNNNN NNNN DDDDDDDDDDDDDDDD
// EEEE NNNN NNNN NNNN DDDD DDDD
// EEEE NNNN NNNN NNNN DDDD DDDD
// EEEEEEEE NNNN NNNN NNNN DDDD DDDD
// EEEEEEEE NNNN NNNN NNNN DDDD DDDD
// EEEE NNNN NNNN NNNN DDDD DDDD
// EEEE NNNN NNNNNNNN DDDD DDDD
// EEEEEEEEEEEE NNNN NNNNNNN DDDDDDDDDDDDDDD
// EEEEEEEEEEEE NNNN NNNNNN DDDDDDDDDDDDDD
//
//
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -