📄 d0361_drv.c
字号:
/* standard ansi includes */
/*#include "math.h"*/
#ifdef ST_OSLINUX
#include "stos.h"
#else
#include <stdlib.h>
#endif
/*#include "chip.h"*/
#include "ioreg.h"
#ifdef HOST_PC
#include "I2C.h"
#else
#include "sti2c.h"
#endif
#ifdef HOST_PC
/* generic includes */
#include <utility.h>
#include <ansi_c.h>
#include "gen_macros.h"
#include "gen_types.h"
#include "gen_csts.h"
#include "system.h"
#include "360_util.h"
#endif
#include "361_map.h"
#include "361_echo.h"
#include "361_drv.h"
#ifdef HOST_PC
/* 360 includes */
#include "360_GUI.h"
#include "ApplMain.h"
#include "DRIVMAIN.h"
#include "Tun0360.h"
FILE *fp;
#else
#ifndef ST_OSLINUX
#include "stlite.h" /* Standard includes */
#endif
#include "stddefs.h"
/* STAPI */
#include "sttuner.h"
#include "sti2c.h"
#include "stcommon.h"
#ifndef ST_OSLINUX
#include "sttbx.h"
#endif
#include "stevt.h"
/* local to sttuner */
#include "util.h" /* generic utility functions for sttuner */
#include "dbtypes.h" /* data types for databases */
#include "sysdbase.h" /* functions to accesss system data */
#include "ioarch.h" /* I/O for this driver */
#include "ioreg.h" /* I/O for this driver */
#include "d0361.h" /* top level header for this driver */
#include "tuntdrv.h"
/* Current LLA revision */
static ST_Revision_t Revision361 = " STV0361-LLA_REL_3.0(GUI) ";
#define M6_F_GAIN_SRC_HI 0xE/*0x8*/
#define M6_F_GAIN_SRC_LO 0x10/*0x20*/
#define M6_F_TRL_NOMRATE0 0x0
#define M6_F_TRL_NOMRATE8_1 0x00/*0x01*/
#define M6_F_TRL_NOMRATE16_9 0x41
#define M7_F_GAIN_SRC_HI 0xA
#define M7_F_GAIN_SRC_LO 0xF0/*0x7B*/
#define M7_F_TRL_NOMRATE0 0x1/*0x0*/
#define M7_F_TRL_NOMRATE8_1 0xD5/*0xD7*/
#define M7_F_TRL_NOMRATE16_9 0x4B/*0x4D*/
#define M8_F_GAIN_SRC_HI 0xD /*0xA*/
#define M8_F_GAIN_SRC_LO 0xAC /*0xB4*/ /*27MHz*/
#define M8_F_TRL_NOMRATE0 0x00
#define M8_F_TRL_NOMRATE8_1 0xAC
#define M8_F_TRL_NOMRATE16_9 0x56
#if defined (ST_OS21) || defined (ST_OSLINUX)
#define UTIL_Delay(micro_sec) task_delay((signed int)(((micro_sec) + 999) / 1000) * ST_GetClocksPerSecond() / 1000)
#define Delay(x) task_delay((signed int)(ST_GetClocksPerSecond()*x));
#else
#define UTIL_Delay(micro_sec) task_delay((unsigned int)(((micro_sec) + 999) / 1000) * ST_GetClocksPerSecond() / 1000)
#define Delay(x) task_delay((unsigned int)(ST_GetClocksPerSecond()*x));
#endif
#define SystemWaitFor(x) UTIL_Delay((x*1000))
TUNTDRV_InstanceData_t *TUNTDRV_GetInstFromHandle(TUNER_Handle_t Handle);
#endif
#define DELTA 666
/* dcdc #define CPQ_LIMIT 23*/
#define CPQ_LIMIT 23
/***********************************************************
**FUNCTION :: Drv0361_GetLLARevision
**ACTION :: Returns the 361 LLA driver revision
**RETURN :: Revision361
***********************************************************/
ST_Revision_t Drv0361_GetLLARevision(void)
{
return (Revision361);
}
/*****************************************************
**FUNCTION :: FE_361_PowOf2
**ACTION :: Compute 2^n (where n is an integer)
**PARAMS IN :: number -> n
**PARAMS OUT:: NONE
**RETURN :: 2^n
*****************************************************/
int FE_361_PowOf2(int number)
{
int i;
int result=1;
for(i=0;i<number;i++)
result*=2;
return result;
}
/*********************************************************
--FUNCTION :: SpeedInit_361
--ACTION :: calculate I2C speed (for SystemWait ...)
--PARAMS IN :: Handle to the Chip
--PARAMS OUT:: NONE
--RETURN :: #ms for an I2C reading access ..
--********************************************************/
int SpeedInit_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle)
{
#ifdef HOST_PC
unsigned int i;
int tempo;
tempo= clock();
for (i=0;i<16;i++) STTUNER_IOREG_GetField(DeviceMap,IOHandle,PPM_CPC);
tempo=clock()-tempo;
tempo=(tempo*1000)/CLOCKS_PER_SEC;
tempo=(tempo+4)>>4; /* 4 not 8 to avoid too rough rounding */
return tempo;
#else
unsigned int i,tempo;
#ifdef ST_OS21
osclock_t time1,time2,time_diff;
#else
clock_t time1,time2,time_diff;
#endif
time1 = time_now();
for (i=0;i<16;i++) STTUNER_IOREG_GetField(DeviceMap,IOHandle,PPM_CPC); time2 = time_now();
time_diff = time_minus(time2,time1);
tempo = (time_diff * 1000 ) / ST_GetClocksPerSecond() + 4; /* Duration in milliseconds, + 4 for rounded value */
tempo = tempo << 4;
return tempo;
#endif
}
/*********************************************************
--FUNCTION :: CheckEPQ_361
--ACTION :: calculate I2C speed (for SystemWait ...)
--PARAMS IN :: Handle to the Chip
--PARAMS OUT:: NONE
--RETURN ::
--********************************************************/
void CheckEPQ_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle,FE_361_OFDMEchoParams_t *Echo)
{
unsigned short int epq=0,mode,epq_limit,data;
unsigned short int epq_avg , i;
U8 epq_auto= 0;
/********* To check the status of auto epq**********/
epq_auto=STTUNER_IOREG_GetField(DeviceMap,IOHandle,AUTO_LE_EN);
if(epq_auto==1)
{
return;
}
/****** Here according to FFT Mode and Modualtion different EPQ values has been set****/
mode=STTUNER_IOREG_GetField(DeviceMap,IOHandle,SYR_MODE);
data=STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_CONST);
for(i=0;i<4;i++)
{
epq+=Get_EPQ_361(DeviceMap,IOHandle,0);
/* SystemWaitFor(DELTA);*/
if(mode == 0)
{
SystemWaitFor(25); /* wait for 25 msec for 2k mode to get the epq over a range of time so that the
average is better*/
}
else
{
SystemWaitFor(100);/* wait for 100 msec for 8k mode to get the epq over a range of time so that the
average is better*/
}
}
epq_avg=epq/4;
/*epq_limit=(6<<(2*mode));*/
if(mode==0)
{
switch(data)
{
case 0 : /* QPSK */
epq_limit=9;
break;
case 1 : /* 16 QAM */
epq_limit=7;
break;
case 2 : /* 64 QAM */
epq_limit=6;
break;
default :
epq_limit=6;
break;
}/* end of switch */
}
else
{
switch(data)
{
case 0 : /* QPSK */
epq_limit=35;
break;
case 1 : /* 16 QAM */
epq_limit=28;
break;
case 2 : /* 64 QAM */
epq_limit=24;
break;
default :
epq_limit=24;
break;
}/* end of switch */
}
if ( epq_avg > epq_limit )
{
Ack_long_scan_361(DeviceMap,IOHandle);
}
return;
}
/*****************************************************
--FUNCTION :: FE_361_TunerSet
--ACTION :: Search for a valid transponder
--PARAMS IN :: Handle ==> Front End Handle
pSearch ==> Search parameters
pResult ==> Result of the search
--PARAMS OUT:: NONE
--RETURN :: Error (if any)
--***************************************************/
FE_361_Error_t FE_361_TunerSet(TUNER_Handle_t Handle, FE_361_InternalParams_t* pParams)
{
FE_361_Error_t error = FE_361_NO_ERROR;
U32 Frequency;
int returned_freq;
#ifndef HOST_PC
TUNTDRV_InstanceData_t *Instance;
#endif
STTUNER_TunerType_t Tuner;
/*U32 Freq; */
Frequency=pParams->Frequency;
Tuner= pParams->Tuner;
#ifndef HOST_PC
Instance = TUNTDRV_GetInstFromHandle(Handle);
Instance->ChannelBW=pParams->ChannelBW;
#endif
returned_freq=Frequency ;
if (Tuner==STTUNER_TUNER_TDLB7)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDLB7,0xC0);
if ((Frequency<470000) || (Frequency>862000)) error = FE_361_BAD_PARAMETER;
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_DTT7572)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_DTT7572,0xC0);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else
{
tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
}
else if (Tuner==STTUNER_TUNER_EAL2780)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_EAL2780,0xC0);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_DTT7578)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_DTT7578,0xC0);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_DTT7592)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_DTT7592,0xC0);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_ENG47402G1)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_ENG47402G1,0xC0);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_TDA6650)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDA6650,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_TDM1316)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDM1316,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_TDEB2)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDEB2,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
else if (Tuner==STTUNER_TUNER_TDED4)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDED4,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/***********New tuner added ED5058**************/
else if (Tuner==STTUNER_TUNER_ED5058)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_ED5058,0xC2);
if ((Frequency<430000) || (Frequency>858000)) /* PARAMETRES A REGLER*/
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/************New tuner MIVAR*****************/
else if (Tuner==STTUNER_TUNER_MIVAR)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_MIVAR,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/************New tuner DTT7102*****************/
else if (Tuner==STTUNER_TUNER_DTT7102)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_DTT7102,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/************New tuner TECC2849PG*****************/
else if (Tuner==STTUNER_TUNER_TECC2849PG)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TECC2849PG,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/************New tuner TDCC2345*****************/
else if (Tuner==STTUNER_TUNER_TDCC2345)
{
tuner_tuntdrv_Select(Handle,STTUNER_TUNER_TDCC2345,0xC2);
if ((Frequency<51000) || (Frequency>896000))
{
error = FE_361_BAD_PARAMETER;
}
else tuner_tuntdrv_SetFrequency(Handle,(int)Frequency,(U32*)&returned_freq);
}
/* *Freq=returned_freq; */
(pParams->Frequency)=returned_freq;
return error;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -