d0372.c
来自「st7710的tuner标准驱动」· C语言 代码 · 共 1,585 行 · 第 1/4 页
C
1,585 行
/* Private types/constants ------------------------------------------------ */
/* Device capabilities */
#define MAX_AGC 4095
#define MAX_SIGNAL_QUALITY 100
#define MAX_BER 200000
#define STCHIP_HANDLE(x) ((STCHIP_InstanceData_t *)x)
/* private variables ------------------------------------------------------- */
#if defined (ST_OS21) || defined(ST_OSLINUX)
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif
static BOOL Installed = FALSE;
/* instance chain, the default boot value is invalid, to catch errors */
static D0372_InstanceData_t *InstanceChainTop = (D0372_InstanceData_t *)0x7fffffff;
/* functions --------------------------------------------------------------- */
/* API */
ST_ErrorCode_t demod_d0372_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams);
ST_ErrorCode_t demod_d0372_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams);
ST_ErrorCode_t demod_d0372_Open (ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle);
ST_ErrorCode_t demod_d0372_Close(DEMOD_Handle_t Handle, DEMOD_CloseParams_t *CloseParams);
ST_ErrorCode_t demod_d0372_GetTunerInfo (DEMOD_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p);
ST_ErrorCode_t demod_d0372_GetSignalQuality(DEMOD_Handle_t Handle, U32 *SignalQuality_p, U32 *Ber);
ST_ErrorCode_t demod_d0372_GetModulation (DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation);
ST_ErrorCode_t demod_d0372_GetAGC (DEMOD_Handle_t Handle, S16 *Agc);
ST_ErrorCode_t demod_d0372_GetFECRates (DEMOD_Handle_t Handle, STTUNER_FECRate_t *FECRates);
ST_ErrorCode_t demod_d0372_IsLocked (DEMOD_Handle_t Handle, BOOL *IsLocked);
ST_ErrorCode_t demod_d0372_ScanFrequency (DEMOD_Handle_t Handle,
U32 InitialFrequency,
U32 SymbolRate,
U32 MaxOffset,
U32 TunerStep,
U8 DerotatorStep,
BOOL *ScanSuccess,
U32 *NewFrequency,
U32 Mode,
U32 Guard,
U32 Force,
U32 Hierarchy,
U32 Spectrum,
U32 FreqOff,
U32 ChannelBW,
S32 EchoPos);
ST_ErrorCode_t demod_d0372_ioctl (DEMOD_Handle_t Handle, U32 Function, void *InParams, void *OutParams,
STTUNER_Da_Status_t *Status);
/* I/O API */
ST_ErrorCode_t demod_d0372_ioaccess(DEMOD_Handle_t Handle, IOARCH_Handle_t IOHandle,
STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);
/* local functions --------------------------------------------------------- */
D0372_InstanceData_t *d0372_GetInstFromHandle(DEMOD_Handle_t Handle);
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STV0372_Install()
Description:
install a terrestrial device driver(8VSB) into the demod database.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0372_Install(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c STTUNER_DRV_DEMOD_STV0372_Install()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == TRUE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail driver already installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s installing ter:demod:STV0372...", identity));
#endif
/* mark ID in database */
Demod->ID = STTUNER_DEMOD_STV0372;
/* map API */
Demod->demod_Init = demod_d0372_Init;
Demod->demod_Term = demod_d0372_Term;
Demod->demod_Open = demod_d0372_Open;
Demod->demod_Close = demod_d0372_Close;
Demod->demod_IsAnalogCarrier = NULL;
Demod->demod_GetTunerInfo = demod_d0372_GetTunerInfo;
Demod->demod_GetSignalQuality = demod_d0372_GetSignalQuality;
Demod->demod_GetModulation = demod_d0372_GetModulation;
Demod->demod_GetAGC = demod_d0372_GetAGC;
#ifdef STTUNER_BASIC
Demod->demod_GetMode = NULL;
Demod->demod_GetGuard = NULL;
#endif
Demod->demod_GetFECRates = demod_d0372_GetFECRates;
Demod->demod_IsLocked = demod_d0372_IsLocked ;
Demod->demod_SetFECRates = NULL;
Demod->demod_Tracking = NULL;
Demod->demod_ScanFrequency = demod_d0372_ScanFrequency;
Demod->demod_ioaccess = demod_d0372_ioaccess;
Demod->demod_ioctl = demod_d0372_ioctl;
Demod->demod_GetRFLevel = NULL;
InstanceChainTop = NULL;
#if defined (ST_OS21) || defined(ST_OSLINUX)
Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif
Installed = TRUE;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STV0372_UnInstall()
Description:
uninstall a terrestrial device driver(8VSB) into the demod database.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0372_UnInstall(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c STTUNER_DRV_DEMOD_STV0372_UnInstall()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
if(Demod->ID != STTUNER_DEMOD_STV0372)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail incorrect driver type\n", identity));
#endif
return(STTUNER_ERROR_ID);
}
/* has all memory been freed, by Term() */
if(InstanceChainTop != NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
return(ST_ERROR_OPEN_HANDLE);
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s uninstalling ter:demod:STV0372...", identity));
#endif
/* mark ID in database */
Demod->ID = STTUNER_NO_DRIVER;
/* unmap API */
Demod->demod_Init = NULL;
Demod->demod_Term = NULL;
Demod->demod_Open = NULL;
Demod->demod_Close = NULL;
Demod->demod_IsAnalogCarrier = NULL;
Demod->demod_GetTunerInfo = NULL;
Demod->demod_GetSignalQuality = NULL;
Demod->demod_GetModulation = NULL;
Demod->demod_GetAGC = NULL;
#ifdef STTUNER_BASIC
Demod->demod_GetMode = NULL;
#endif
Demod->demod_GetFECRates = NULL;
#ifdef STTUNER_BASIC
Demod->demod_GetGuard = NULL;
#endif
Demod->demod_IsLocked = NULL;
Demod->demod_SetFECRates = NULL;
Demod->demod_Tracking = NULL;
Demod->demod_ScanFrequency = NULL;
Demod->demod_ioaccess = NULL;
Demod->demod_ioctl = NULL;
Demod->demod_GetRFLevel = NULL;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("<"));
#endif
#if defined (ST_OS21) || defined (ST_OSLINUX)
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print((">"));
#endif
InstanceChainTop = (D0372_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ API /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Name: demod_d0372_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0372_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c demod_d0372_Init()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0372_InstanceData_t *InstanceNew, *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check params ---------- */
Error = STTUNER_Util_CheckPtrNull(InitParams->MemoryPartition);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
Error = STTUNER_Util_CheckPtrNull(DeviceName);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail DeviceName not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( D0372_InstanceData_t ));
if (InstanceNew == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail memory allocation InstanceNew\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_NO_MEMORY);
}
/* slot into chain */
if (InstanceChainTop == NULL)
{
InstanceNew->InstanceChainPrev = NULL; /* no previous instance */
InstanceChainTop = InstanceNew;
}
else /* tag onto last data block in chain */
{
Instance = InstanceChainTop;
while(Instance->InstanceChainNext != NULL)
{
Instance = Instance->InstanceChainNext; /* next block */
}
Instance->InstanceChainNext = (void *)InstanceNew;
InstanceNew->InstanceChainPrev = (void *)Instance;
}
InstanceNew->DeviceName = DeviceName;
InstanceNew->TopLevelHandle = STTUNER_MAX_HANDLES;
InstanceNew->IOHandle = InitParams->IOHandle;
InstanceNew->MemoryPartition = InitParams->MemoryPartition;
InstanceNew->InstanceChainNext = NULL; /* always last in the chain */
InstanceNew->ExternalClock = InitParams->ExternalClock;
InstanceNew->TSOutputMode = InitParams->TSOutputMode;
InstanceNew->SerialDataMode = InitParams->SerialDataMode;
InstanceNew->SerialClockSource = InitParams->SerialClockSource;
InstanceNew->FECMode = InitParams->FECMode;
InstanceNew->ClockPolarity = InitParams->ClockPolarity;
InstanceNew->DeviceMap.Timeout = IOREG_DEFAULT_TIMEOUT;
InstanceNew->DeviceMap.Registers = STV0372_NBREGS;
InstanceNew->DeviceMap.Fields = STV0372_NBFIELDS;
InstanceNew->DeviceMap.Mode = IOREG_MODE_SUBADR_16; /* i/o addressing mode to use */
InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
InstanceNew->DeviceMap.DefVal= (U32 *)&STV0372_DefVal[0];
/* Allocate memory for register mapping */
Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail setup new register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* install a mapping */
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( D0372_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0372_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0372_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c demod_d0372_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0372_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?