📄 d0372.c
字号:
/* 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_D0372
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_D0372
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_D0372
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
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_D0372
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_D0372
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
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_D0372
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_D0372
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0372_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0372_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c demod_d0372_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0372_InstanceData_t *Instance;
U8 ChipID = 0;
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 that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
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_D0372
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_D0372
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_D0372
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
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_D0372
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, R0372_ID);
if ( (ChipID & 0x10) != 0x10)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s fail device not found (0x%02x)\n", identity, ChipID));
#endif
/* Term LLA */
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s FE_372_Term()\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_UNKNOWN_DEVICE);
}
else
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s device found, release/revision=%u\n", identity, ChipID & 0x10));
#endif
}
/* reset all chip registers */
Error = STTUNER_IOREG_Reset(&(Instance->DeviceMap), Instance->IOHandle,STV0372_DefVal,STV0372_Address);
/* Set serial/parallel data mode */
if (Instance->TSOutputMode == STTUNER_TS_MODE_SERIAL)
{
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_SERIES, 0x01);
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_SWAP, 0x01);
}
else
{
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_SERIES, 0x00);
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_SWAP, 0x00);
}
/*set data clock polarity inversion mode (rising/falling)*/
switch(Instance->ClockPolarity)
{
case STTUNER_DATA_CLOCK_INVERTED:
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_POLARITY, 0x01);
break;
case STTUNER_DATA_CLOCK_NONINVERTED:
Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0372_POLARITY, 0x00);
break;
case STTUNER_DATA_CLOCK_POLARITY_DEFAULT:
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;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s no EVALMAX tuner driver, F0360_IAGC=0\n", identity));
#endif
/* finally (as nor more errors to check for, allocate handle */
Instance->TopLevelHandle = OpenParams->TopLevelHandle;
*Handle = (U32)Instance;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0372_Close()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0372_Close(DEMOD_Handle_t Handle, DEMOD_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c demod_d0372_Close()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0372_InstanceData_t *Instance;
/* private driver instance data */
Instance = d0372_GetInstFromHandle(Handle);
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
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_D0372
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_D0372
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_D0372
STTBX_Print(("%s closed\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0372_GetTunerInfo()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0372_GetTunerInfo(DEMOD_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0372
const char *identity = "STTUNER d0372.c demod_d0372_GetTunerInfo()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0372_InstanceData_t *Instance;
STTUNER_Modulation_t CurModulation;
STTUNER_FECRate_t CurFECRates;
STTUNER_Spectrum_t CurSpectrum;
U32 CurFrequency,CurBitErrorRate;
S32 CurSignalQuality;
/* private driver instance data */
Instance = d0372_GetInstFromHandle(Handle);
CurModulation = STTUNER_MOD_8VSB;
CurFECRates = STTUNER_FEC_2_3;
CurFrequency = TunerInfo_p->Frequency;
/* Read noise estimations for C/N and BER */
CurSignalQuality = FE_372_GetCarrierToNoiseRatio(&(Instance->DeviceMap), Instance->IOHandle);
CurBitErrorRate=FE_372_GetBitErrorRate(&(Instance->DeviceMap), Instance->IOHandle);
#ifndef ST_OSLINUX
task_lock();
#endif
CurSignalQuality = (CurSignalQuality * 10)/36; /*signal qaulity in % calculated considering 36dB as 100% signal-quality,. x*100/36 *10 as value should be devided by 10 */
/*If it reaches maximum value then force it to max value*/
if ( CurSignalQuality > MAX_SIGNAL_QUALITY)
{
CurSignalQuality = MAX_SIGNAL_QUALITY;
}
TunerInfo_p->FrequencyFound = CurFrequency;
TunerInfo_p->SignalQuality = CurSignalQuality;
TunerInfo_p->BitErrorRate = CurBitErrorRate;
TunerInfo_p->ScanInfo.Modulation = CurModulation;
TunerInfo_p->ScanInfo.FECRates = CurFECRates;
TunerInfo_p->ScanInfo.Spectrum = CurSpectrum;
/*Inst[Instance->TopLevelHandle].TunerInfoError = TunerError;)*/
Error = Instance->DeviceMap.Error;
#ifndef ST_OSLINUX
task_unlock();
#endif
return(Error);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -