📄 d0362.c
字号:
/*** TO initialize the Standby Flag for StandByMode ****/
InstanceNew->StandBy_Flag = 0 ;
/* Allocate memory for register mapping */
Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail setup new register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( D0362_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0362_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
const char *identity = "STTUNER d0362.c demod_d0362_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0362_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
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(TermParams);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail TermParams not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
/* reap next matching DeviceName */
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("<-- ]\n"));
#endif
/* found so now xlink prev and next(if applicable) and deallocate memory */
InstancePrev = Instance->InstanceChainPrev;
InstanceNext = Instance->InstanceChainNext;
/* if instance to delete is first in chain */
if (Instance->InstanceChainPrev == NULL)
{
InstanceChainTop = InstanceNext; /* which would be NULL if last block to be term'd */
if ( InstanceNext != NULL)
{
InstanceNext->InstanceChainPrev = NULL; /* now top of chain, no previous instance */
}
}
else
{ /* safe to set value for prev instaance (because there IS one) */
InstancePrev->InstanceChainNext = InstanceNext;
}
/* if there is a next block in the chain */
if (InstanceNext != NULL)
{
InstanceNext->InstanceChainPrev = InstancePrev;
}
/* Added for removing memory related problem in API test
memory for register mapping */
Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail deallocate register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
memory_deallocate(Instance->MemoryPartition, Instance);
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s terminated ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
else if(Instance->InstanceChainNext == NULL)
{ /* error we should have found a matching name before the end of the list */
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("\n%s fail no free handle before end of list\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
else
{
Instance = Instance->InstanceChainNext; /* next block */
}
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0362_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
const char *identity = "STTUNER d0362.c demod_d0362_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0362_InstanceData_t *Instance;
U8 ChipID = 0;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
/* find handle from name */
Instance = InstanceChainTop;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s looking (%s)", identity, Instance->DeviceName));
#endif
while(strcmp((char *)Instance->DeviceName, (char *)DeviceName) != 0)
{
/* error, should have found matching DeviceName before end of list */
if(Instance->InstanceChainNext == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("\n%s fail no block named '%s' before end of list\n", identity, DeviceName));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
Instance = Instance->InstanceChainNext; /* next block */
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif
/* check handle IS actually free */
if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail driver instance already open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
/* else now got pointer to free (and valid) data block */
ChipID = STTUNER_IOREG_GetRegister( &(Instance->DeviceMap), Instance->IOHandle, R0362_ID);
if ( (ChipID & 0x40) != 0x40)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail device not found (0x%02x)\n", identity, ChipID));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_UNKNOWN_DEVICE);
}
else
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s device found, release/revision=%u\n", identity, ChipID & 0x40));
#endif
}
/* reset all chip registers */
Error = STTUNER_IOREG_Reset(&(Instance->DeviceMap), Instance->IOHandle,STV0362_DefVal,STV0362_Address);
/* Set serial/parallel data mode */
if (Instance->TSOutputMode == STTUNER_TS_MODE_SERIAL)
{
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_OUTRS_SP, 1);
}
else
{
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_OUTRS_SP, 0);
}
/*set data clock polarity inversion mode (rising/falling)*/
switch(Instance->ClockPolarity)
{
case STTUNER_DATA_CLOCK_POLARITY_RISING:
STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_CLK_POL, 1);
break;
case STTUNER_DATA_CLOCK_POLARITY_FALLING:
STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_CLK_POL, 0);
break;
case STTUNER_DATA_CLOCK_POLARITY_DEFAULT:
STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_CLK_POL, 0);
break;
default:
break;
}
/* Set capabilties */
Capability->FECAvail = STTUNER_FEC_ALL; /* direct mapping to STTUNER_FECRate_t */
Capability->ModulationAvail = STTUNER_MOD_ALL; /* direct mapping to STTUNER_Modulation_t */
Capability->AGCControl = FALSE;
Capability->SymbolMin = 1000000; /* 1 MegaSymbols/sec */
Capability->SymbolMax = 50000000; /* 50 MegaSymbols/sec */
Capability->BerMax = MAX_BER;
Capability->SignalQualityMax = MAX_SIGNAL_QUALITY;
Capability->AgcMax = MAX_AGC;
/* finally (as nor more errors to check for, allocate handle */
Instance->TopLevelHandle = OpenParams->TopLevelHandle;
Instance->UnlockCounter = 2; /* unlock counter made 0 initially*/
*Handle = (U32)Instance;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0362_Close()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_Close(DEMOD_Handle_t Handle, DEMOD_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
const char *identity = "STTUNER d0362.c demod_d0362_Close()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0362_InstanceData_t *Instance;
/* private driver instance data */
Instance = d0362_GetInstFromHandle(Handle);
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
if(Instance->TopLevelHandle == STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s fail driver instance not open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
/* indicate instance is closed */
Instance->TopLevelHandle = STTUNER_MAX_HANDLES;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
STTBX_Print(("%s closed\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0362_GetTunerInfo()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_GetTunerInfo(DEMOD_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
const char *identity = "STTUNER d0362.c demod_d0362_GetTunerInfo()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
ST_ErrorCode_t TunerError ;
D0362_InstanceData_t *Instance;
STTUNER_InstanceDbase_t *Inst;
U8 Data;
U32 CurFrequency, CurSignalQuality, CurBitErrorRate;
STTUNER_Modulation_t CurModulation;
STTUNER_Mode_t CurMode;
STTUNER_FECRate_t CurFECRates;
STTUNER_Guard_t CurGuard;
STTUNER_Spectrum_t CurSpectrum;
STTUNER_Hierarchy_t CurHierMode;
S32 CurEchoPos;
S32 offset=0;
U32 CrlRegVal;
S32 offset_type=0;
U8 crl_freq1[3];
/* private driver instance data */
Instance = d0362_GetInstFromHandle(Handle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -