📄 qpsk0299.c
字号:
/*
* VICKY - more calculation oriented registers, which is also confuses
* sometimes, if we dont have the following summary.
* ========================================================================
* Register Sign ID ADDR Size Unit
* ========================================================================
* Derotator Freq +/- CFRx 0x22-0x23 16 Fmclk(KHz) / ( 2 ^ 16 )
* Symbol Freq +/- SFRx 0x1F-0x21 20 Fmclk(Hz) / ( 2 ^ 20 )
* Timing Freq +/- RTF 0x1A 8 Fs / ( 2 ^ 19 )
* ========================================================================
*/
/*
* vicky.c ver 0.9
*
* (c) Copyright SGS-Thomson Microelectronics Limited 1996.
*
* Source file name : qpsk0299.c
* Authors Christina LIM (christina.lim@st.com)
* T.H.Thillai Rajan (tht.rajan@st.com)
*
* Original Work: Jean Yves COUET & Manish Pradan
*
* Thanks to: (for giving support)
* Michel GUILLIEN
*
* =======================
* IMPROVEMENTS THOUGHT OF
* =======================
*
* =====================
* MODIFICATION HISTORY:
* =====================
*
* Date Initials Modification
* ---- -------- ------------
* 26.04.00 LP register_command() adapted to STAPI testtool
* 03.02.00 THT Adopted for 299
* 01.08.97 THT Modified to fix the problem of loosing lock in MCPC
* and adapted for SCPC
* xx.07.97 JYC/MP Created this driver based on weixing software
*/
/*{{{ Includes */
#include "st_tuner.h"
/*}}}*/
#define TUNER_SOFTWARE_UPDATE_ID "0.9Beta"
#ifndef TESTTOOL_PRESENT
#define TESTTOOL_PRESENT
#endif
#undef CENTER_TUNER_AT_STARTUP
/* Philips ZIF tuner used with 5518-based application */
#ifdef USE_PHILIPS_ZIF
#define I2C_BUS_ID BACK_I2C
#else
#define I2C_BUS_ID FRONT_I2C
#endif
#define TUNER_DEV 0xC2 /* I2C slave address for PHILIPS NIM TUNER */
#define LINKIC_DEV I2C_SLAVE_ADDR_FOR_STV0299
#define I2C_COMMAND_LEN 6
#define POL_SELECTION_THROUGH_STV0299_OP_PINS
#define LNB_SELECTION_THROUGH_STV0299_OP_PINS
#ifdef SYSCLOCK_IS_27MHZ
#define MASTER_CLOCK_VALUE 54000.0
#define R_VALUE_FOR_22KHz 38 /* VCO/(256*R)=22KHz; R=216/(256*22)=38 */
#else
#define MASTER_CLOCK_VALUE 56000.0
#define R_VALUE_FOR_22KHz 39 /* VCO/(256*R)=22KHz; R=224/(256*22)=39 */
#endif
/* 2^9 */
#define CONSTANT_2_POWER_19 ( 1024 * 512 )
#define CONSTANT_2_POWER_16 ( 1024 * 64 )
#define CONSTANT_2_POWER_3 ( 8 )
#ifdef PRINT_TUNER_STATE_CHANGE
#define TUNER_TUNER_STATE(__command__) __command__
#else
#define TUNER_TUNER_STATE(__command__)
#endif
#ifdef PRINT_I2C_ERROR
#define TUNER_I2C_ERROR(__command__) __command__
#else
#define TUNER_I2C_ERROR(__command__)
#endif
#ifdef PRINT_INIT
#define TUNER_INIT(__command__) __command__
#define INSTALL_INIT(__command__) __command__
#else
#define TUNER_INIT(__command__)
#define INSTALL_INIT(__command__)
#endif
#ifdef PRINT_PERIODIC
#define INSTALL_PERIODIC(__command__) __command__
#define TUNER_PERIODIC(__command__) __command__
#else
#define INSTALL_PERIODIC(__command__)
#define TUNER_PERIODIC(__command__)
#endif
#ifdef PRINT_DEBUG
#define TUNER_DEBUG(__command__) __command__
#else
#define TUNER_DEBUG(__command__)
#endif
#ifdef PRINT_TUNER_STATE_MC
#define TUNER_TUNER(__command__) __command__
#else
#define TUNER_TUNER(__command__)
#endif
#ifdef PRINT_TUNER_CRITICAL
#define TUNER_TUNER_CRITICAL(__command__) __command__
#else
#define TUNER_TUNER_CRITICAL(__command__)
#endif
/* MILLI_DELAY */
#define MILLI_DELAY(__ms__) task_delay ( __ms__ * ST_GetClocksPerSecond() / 1000 );
#define PERIODIC_SLEEP_PERIOD_DURATION 200 /* 100 msec */
/* LNB tone state added by LP on 29/08/00 */
typedef enum
{
STTUNER_LNB_TONE_DEFAULT, /* Default (current) LNB state */
STTUNER_LNB_TONE_OFF, /* LNB disabled */
STTUNER_LNB_TONE_22KHZ /* LNB set to 22kHz */
} LNBToneState_t;
enum
{
TUNER_IDLE,
TUNER_SETUP_PARAMS,
TUNER_SIGNAL_DETECTION,
TUNER_TIMING_DETECTION,
TUNER_CARRIER_DETECTION,
TUNER_MONITOR_TUNING
};
enum
{
LNB_LOW_FREQ_INDEX,
LNB_HIGH_FREQ_INDEX
};
#define DEROTATOR_STEP 6
/*
* PIO0.2 is dedicated for H/V selection and will be configured as
* Output, Push-Pull
*/
#ifndef POL_SELECTION_THROUGH_STV0299_OP_PINS
#define POLARIZATION_CONTROL_PIO_BASE_ADDR PIO_0_BASE_ADDRESS
#define POLARIZATION_BIT 0x04
#endif
#ifdef LNB_SELECTION_THROUGH_STV0299_OP_PINS
#define LNB1_SELECTION 1
#define LNB2_SELECTION 1
#define DONT_SELECT_ANY_LNB 0
#else
#define LNB_SELECTION_PIO_BASE_ADDR PIO_2_BASE_ADDRESS
/*
* 2.2 2.0
* =======
* 0 0 invalid
* 0 1 LNB2
* 1 0 LNB1
* 1 1 invalid
*/
#define LNB_SELECTION_MASK 0x05
#define LNB1_SELECTION 0x04
#define LNB2_SELECTION 0x01
#define DONT_SELECT_ANY_LNB 0x00 /* 0x05 too ???? */
#endif
#define TUNER_STATUS_PLL_LOCKED_FLAG 0x40 /* BIT6 of STATUS reg */
/*
* channels more than 5Mbauds will have the max lnb offset of 7MHz else 4MHz
*/
#define KHz
#define SCPC_SYMBOL_RATE_THRESHOLD 5000
#define MAX_MCPC_OFFSET 5000 KHz /* half of the gap between MCPC transponders */
#define MAX_SCPC_OFFSET 4000 KHz /* half of the gap between SCPC transponders */
#define MAX_OFFSET 4000 KHz /* half of the gap between MCPC transponders */
#define MAX_LNB_DRIFT_NEGATIVE ( int ) ( -1 * MAX_OFFSET / TUNER_STEP ) /* -5MHz/125KHz */
#define MAX_LNB_DRIFT_POSITIVE ( int ) ( MAX_OFFSET / TUNER_STEP ) /* 5MHz/125KHz */
#define MCPC_TMG_MAX_DRIFT_NEGATIVE -80
#define MCPC_TMG_MAX_DRIFT_POSITIVE 80
#define SCPC_TMG_MAX_DRIFT_NEGATIVE -120 /* considering for Fs=4.4 MHz */
#define SCPC_TMG_MAX_DRIFT_POSITIVE 120
/*
* MACROS
*/
#ifdef LNB_SELECTION_THROUGH_STV0299_OP_PINS
/*
* LNB_SELECTION
*/
#define SELECT_LNB(__new_lnb_selection__) \
{ \
if ( __new_lnb_selection__ == DONT_SELECT_ANY_LNB ) \
{ \
RegSetField ( OP1VALUE, 0 ); \
} \
else \
{ \
RegSetField ( OP1VALUE, 1 ); \
} \
}
#endif
/*
* force iCurTunerTaskState which will not verify what is the current state.
* this will be invoked only if the new_tune_req is received
*/
#define FORCE_TUNER_STATE(__new_state__) \
{ \
semaphore_wait ( psemTunerStateWriteAccess ); \
iCurTunerTaskState = __new_state__; \
semaphore_signal ( psemTunerStateWriteAccess ); \
TUNER_TUNER_STATE( do_report ( severity_info, "TUNER_STATE changed -> %d\n", __new_state__ ) ); \
}
/*
* update iCurTunerTaskState if the current state has not changed,
* this will be invoked only by the tuner_process.
*/
#define UPDATE_TUNER_STATE(__old_state__, __new_state__) \
{ \
semaphore_wait ( psemTunerStateWriteAccess ); \
if ( iCurTunerTaskState == __old_state__ ) \
{ \
iSavedTunerTaskState = __new_state__; \
iCurTunerTaskState = __new_state__; \
} \
semaphore_signal ( psemTunerStateWriteAccess ); \
}
/* 13/12/00 - LP comment - New boolean flag added to synchro the database building
* start and
* the tuner lock
*/
boolean StillLocked = false;
/* VARIABLES */
int iCurTunerTaskState = TUNER_IDLE,
iSavedTunerTaskState = TUNER_IDLE;
#ifdef ENABLE_STAPI_ENVIRONMENT
STI2C_Handle_t I2CDemodHandle;
STI2C_Handle_t I2CTunerHandle;
#else
extern i2c_handle_t i2c_ssc0;
#endif
/* LP 260600 */
extern semaphore_t semSTv0299RegAccess;
/*
* the tuner_state_write_access_sem should be locked before writing the
* new state of tuner
*/
semaphore_t *psemTunerStateWriteAccess = NULL;
semaphore_t *psemTunerIdleStateEntered = NULL;
semaphore_t *psemTunerIdleStateReleased = NULL;
semaphore_t *psemLinkIcAccess = NULL;
static int i2c_errors = 0; /* count of retry problems on bus */
static int iTunerOffset = 0;
static signed int iDerotatorSignValue = 1;
static signed char cCurLnbSource = LNB1;
static int iInitialTunedFreq = 0;
static int iCurTunedFreq = 0;
static int iTunerStepSize = 1;
static BOOLEAN bImageTried = FALSE;
static task_t *ptidTunerTask;
/*
* VICKY - 28.08.97
* keep the local copy of all the carriers LNB offset. It is supposed to
* be in NVM.
*/
static SHORT asLnbOffset [ 2 ];
static signed char acLnbOffset [ MAX_NO_OF_TRANSPONDERS ];
signed short int asSymbolRateOffset [ MAX_NO_OF_TRANSPONDERS ];
int iCurFsRegOffset = 0;
static signed char cMaxTimingDriftNegative;
static signed char cMaxTimingDriftPositive;
static int iMaxLnbDrift = MAX_MCPC_OFFSET;
static POLARIZATION iCurPolarization;
static BOOLEAN bSpectrumInverted = FALSE; /* invert I&Q by software */
int iRequestedSymbolRate = DEFAULT_SYMBOL_RATE;
int iRequestedLnbFreq = DEFAULT_LNB_FREQ;
BYTE ucRequestedPolarisation = DEFAULT_POLARIZATION;
int iRequestedTransponderFreq = DEFAULT_TRANSPONDER_FREQ;
extern signed char cTransponderIndex2bRetrieved;
extern BOX_INFO_STRUCT *pstBoxInfo;
/* from DRIV0299.C */
extern SEARCHRESULT Result;
extern SEARCHPARAMS Params;
SIGNALTYPE DEMOD_TunerCentering ( SEARCHPARAMS *pParams );
SIGNALTYPE DEMOD_SearchData ( SEARCHPARAMS *pParams );
BOOLEAN DEMOD_SearchFalseLock ( SEARCHPARAMS *pParams );
long DEMOD_CenterTimingLoop ( SEARCHPARAMS *pParams );
boolean FE_StillLocked( void )
{
return StillLocked;
}
/*{{{ TUNER_PrintStatistics ()*/
void TUNER_PrintStatistics ( void )
{
int iLocDerotFreq;
do_report ( severity_info, "\n" );
do_report ( severity_info, "Status => [%02X]\n",
RegGetOneRegister ( R_VSTATUS ) );
RegGetRegisters ( R_CFRM, 2 );
iLocDerotFreq = ( signed short int ) MAKEWORD ( FieldGetVal ( DEROTATORFREQUENCYMSB ), FieldGetVal ( DEROTATORFREQUENCYLSB ) );
/* convert frequency drift into tuner steps */
iLocDerotFreq = Params . Frequency + ( iDerotatorSignValue * iLocDerotFreq * ( Params . Mclk ) / 1000 );
do_report ( severity_info, "LO freq = Base[%d] Cur[%d] var[%d]\n",
Params . BaseFreq,
iLocDerotFreq,
Params . Frequency );
do_report ( severity_info, "Act freq = Base[%d] Cur[%d] var[%d]\n",
iRequestedLnbFreq - Params . BaseFreq,
iRequestedLnbFreq - iLocDerotFreq,
iRequestedLnbFreq - Params . Frequency );
do_report ( severity_info, "Polarisation => %s\n", iCurPolarization == HORIZONTAL ? "HORIZ" : "VERT" );
do_report ( severity_info, "Current Lnb Offset TO[%d] LNB1=[%d] LNB2=[%d]\n",
iTunerOffset,
asLnbOffset [ 0 ],
asLnbOffset [ 1 ] );
do_report ( severity_info, "Current IQ : %s\n",
FieldGetVal ( IQ ) ? "INVERTED" : "NORMAL" );
do_report ( severity_info, "MasterClock => %ld VCO=> %ld\n",
RegGetMasterFreq (),
RegGetVCOFreq () );
do_report ( severity_info, "SymbolRate => %d Cur[%d]\n",
Params . SymbolRate,
RegGetSymbolRate () );
do_report ( severity_info, "TLIR=> %d RTF=> %d\n",
RegGetField ( TLIR ),
RegGetField ( RTF ) );
do_report ( severity_info, "CLDI=> %d CLDT=> %d CFRM=> %d\n",
RegGetField ( CLDI ),
RegGetField ( CLDT ),
( short int ) MAKEWORD ( FieldGetVal ( DEROTATORFREQUENCYMSB ), FieldGetVal ( DEROTATORFREQUENCYLSB ) ) );
do_report ( severity_info, "\n" );
}
/*}}}*/
#ifdef TESTTOOL_PRESENT
/*{{{ TESTTOOLPrintTunerStatistics ()*/
static boolean TESTTOOLTunerStatistics ( parse_t *pars_p, char *result_sym_p )
{
void TUNER_PrintStatistics ( void );
TUNER_PrintStatistics ();
return FALSE;
}
/*}}}*/
/*{{{ FE_PrintAllRegs ()*/
static boolean FE_PrintAllRegs ( parse_t *pars_p, char *result_sym_p )
{
void QPSK0299_PrintAllReg ( void );
void PrintTunerInfo ( void );
PrintTunerInfo ();
QPSK0299_PrintAllReg ();
return FALSE;
}
/*}}}*/
/*{{{ FE_ReadReg ()*/
static boolean FE_ReadReg ( parse_t *pars_p, char *result_sym_p )
{
unsigned char ucData;
unsigned char ucRegAddr;
int iActualLength;
long lInputVal;
cget_integer ( pars_p, true, &lInputVal );
ucRegAddr = ( unsigned char ) lInputVal;
#ifndef ENABLE_STAPI_ENVIRONMENT
if ( i2c_write ( i2c_ssc0,
( unsigned char ) I2C_SLAVE_ADDR_FOR_STV0299,
&ucRegAddr,
1,
&iActualLength ) )
{
do_report ( severity_info, "READ=> Failed to write STv0299 reg[%02X]\n",
ucRegAddr );
return FALSE;
}
if ( i2c_read ( i2c_ssc0,
( unsigned char ) I2C_SLAVE_ADDR_FOR_STV0299,
&ucData,
1,
&iActualLength ) )
{
do_report ( severity_info, "READ=> Failed to read STv0299 reg[%02X]\n",
ucRegAddr );
return FALSE;
}
do_report ( severity_info, "READ=> Reg[%02X] Data[%02X]\n",
ucRegAddr,
ucData );
#endif /* ENABLE_STAPI_ENVIRONMENT */
return FALSE;
}
/*}}}*/
/*{{{ FE_WriteReg ()*/
static boolean FE_WriteReg ( parse_t *pars_p, char *result_sym_p )
{
unsigned char aucData [ 2 ];
int iActualLength;
long lInputVal;
cget_integer ( pars_p, true, &lInputVal );
aucData [ 0 ] = ( unsigned char ) lInputVal;
cget_integer ( pars_p, true, &lInputVal );
aucData [ 1 ] = ( unsigned char ) lInputVal;
#ifndef ENABLE_STAPI_ENVIRONMENT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -