📄 d0370qam.c
字号:
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( D0370QAM_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0370QAM_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0370QAM_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
const char *identity = "STTUNER d0370QAM.c demod_d0370QAM_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
D0370QAM_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("]\n"));
#endif
Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s fail close register database\n", identity));
#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;
}
memory_deallocate(Instance->MemoryPartition, Instance);
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0370QAM_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0370QAM_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
const char *identity = "STTUNER d0370QAM.c demod_d0370QAM_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
U8 Version;
D0370QAM_InstanceData_t *Instance;
STTUNER_InstanceDbase_t *Inst;
STTUNER_tuner_instance_t *TunerInstance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
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_CABDRV_D0370QAM
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
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_CABDRV_D0370QAM
STTBX_Print(("%s fail driver instance already open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
/* now got pointer to free (and valid) data block */
Inst = STTUNER_GetDrvInst(); /* pointer to instance database */
/*Assign the default register array according to the tuner type*/
TunerInstance = &Inst[OpenParams->TopLevelHandle].Cable.Tuner; /* pointer to tuner for this instance */
switch(TunerInstance->Driver->ID)
{
case STTUNER_TUNER_TD1336:
Instance->DeviceMap.DefVal= (U32*)&STB0370_DefVal_256QAM_TD1336[0];
break;
case STTUNER_TUNER_DCT7050:
Instance->DeviceMap.DefVal= (U32*)&STB0370_DefVal_256QAM_DCT7050[0];
break;
case STTUNER_TUNER_DTT7600:
Instance->DeviceMap.DefVal= (U32*)&STB0370_DefVal_256QAM_DTT7600[0];
break;
default:
/*Do nothing. In this case default value is STB0370_DefVal_256QAM_TD1336, as set in Init()*/
break;
}
/*
--- wake up chip if in standby, Reset
*/
/* soft reset of the whole chip */
Error = STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle, R0370QAM_CTRL_0, 1);/* check the what will be the actual register ??*/
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s fail SOFT_RESET\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
Error = STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle, R0370QAM_CTRL_0, 0); /* check the what will be the actual register ??*/
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s fail SOFT_RESET\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/*
--- Get chip ID
*/
Version = Reg0370QAM_GetSTB0370QAMId(&Instance->DeviceMap, Instance->IOHandle);
if ((Version & STB0370QAM_DEVICE_VERSION) != STB0370QAM_DEVICE_VERSION)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s fail device not found (0x%02x)\n", identity, Version));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_UNKNOWN_DEVICE);
}
else
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s device found, release/revision=%u\n", identity, Version));
#endif
}
/* reset all chip registers */
Error = STTUNER_IOREG_Reset(&Instance->DeviceMap, Instance->IOHandle,Instance->DeviceMap.DefVal,STB0370_Address_256QAM_TD1336);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
STTBX_Print(("%s fail reset device\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* Set capabilties */
Capability->FECAvail = 0;
Capability->ModulationAvail = STTUNER_MOD_QAM |
STTUNER_MOD_16QAM |
STTUNER_MOD_32QAM |
STTUNER_MOD_64QAM |
STTUNER_MOD_128QAM |
STTUNER_MOD_256QAM; /* direct mapping to STTUNER_Modulation_t */
Capability->J83Avail = STTUNER_J83_B;
Capability->AGCControl = FALSE;
Capability->SymbolMin = STB0370QAM_SYMBOLMIN; /* 1 MegaSymbols/sec (e.g) */
Capability->SymbolMax = STB0370QAM_SYMBOLMAX; /* 11 MegaSymbols/sec (e.g) */
Capability->BerMax = 0;
Capability->SignalQualityMax = STB0370QAM_MAX_SIGNAL_QUALITY;
Capability->AgcMax = STB0370QAM_MAX_AGC;
/* Setup stateblock */
Instance->StateBlock.ScanMode = DEF0370QAM_CHANNEL;
Instance->StateBlock.lastAGC2Coef = 1;
Instance->StateBlock.Ber[0] = 0;
Instance->StateBlock.Ber[1] = 50; /* Default Ratio for BER */
Instance->StateBlock.Ber[2] = 0;
Instance->StateBlock.CNdB = 0;
Instance->StateBlock.SignalQuality = 0;
/*Check the Output formatting accordingly*/
/* TS output mode */
switch (Instance->TSOutputMode)
{
case STTUNER_TS_MODE_SERIAL:
STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F0370QAM_OUT_FORMAT,0x01);
break;
case STTUNER_TS_MODE_DVBCI:
STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F0370QAM_OUT_FORMAT,0x02);
break;
case STTUNER_TS_MODE_PARALLEL:
case STTUNER_TS_MODE_DEFAULT:
STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F0370QAM_OUT_FORMAT,0x00);
default:
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -