📄 d0899.c
字号:
Demod->demod_SetDiSEqCBurstOFF = demod_stb0899_DiSEqCBurstOFF;
Demod->demod_ioaccess = demod_stb0899_ioaccess;
Demod->demod_ioctl = demod_stb0899_ioctl;
Demod->demod_tonedetection = demod_stb0899_Tonedetection;
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_SATDRV_STB0899
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STB0899_UnInstall()
Description:
install a satellite device driver into the demod database.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STB0899_UnInstall(STTUNER_demod_dbase_t *Demod)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
if(Demod->ID != STTUNER_DEMOD_STB0899)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
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_SATDRV_STB0899
STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
return(ST_ERROR_OPEN_HANDLE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("%s uninstalling sat:demod:STB0899...", 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_GetSignalQuality = NULL;
Demod->demod_GetModulation = NULL;
Demod->demod_SetModulation = NULL;
Demod->demod_GetAGC = NULL;
Demod->demod_GetFECRates = NULL;
Demod->demod_GetIQMode = NULL; /*added for GNBvd26107->I2C failure due to direct access to demod device at API level*/
Demod->demod_IsLocked = NULL;
Demod->demod_SetFECRates = NULL;
Demod->demod_Tracking = NULL;
Demod->demod_ScanFrequency = NULL;
Demod->demod_DiSEqC = NULL;
Demod->demod_GetConfigDiSEqC = NULL;
Demod->demod_SetDiSEqCBurstOFF= NULL;
#ifdef STTUNER_DRV_SAT_STB0899
Demod->demod_GetModeCode = NULL;
#endif
Demod->demod_ioaccess = NULL;
Demod->demod_ioctl = NULL;
Demod->demod_tonedetection = NULL;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("<"));
#endif
#if defined(ST_OS21) || defined(ST_OSLINUX)
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print((">"));
#endif
InstanceChainTop = (STB0899_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_stb0899_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_stb0899_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
const char *identity = "STTUNER d_0899.c demod_stb0899_Init()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
STB0899_InstanceData_t *InstanceNew, *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
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_SATDRV_STB0899
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_SATDRV_STB0899
STTBX_Print(("%s fail DeviceName not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( STB0899_InstanceData_t ));
if (InstanceNew == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
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->DeviceMap.Timeout = IOREG_DEFAULT_TIMEOUT;
InstanceNew->DeviceMap.Registers = STB0899_NBREGS;
InstanceNew->DeviceMap.Fields = STB0899_NBFIELDS;
InstanceNew->DeviceMap.Mode = IOREG_MODE_SUBADR_16_POINTED; /* NEW as of 3.4.0: i/o addressing mode to use */
InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
InstanceNew->DeviceMap.DefVal = (U32 *)&STB0899DefVal[0];
InstanceNew->ExternalClock = InitParams->ExternalClock;
InstanceNew->TSOutputMode = InitParams->TSOutputMode;
/*InstanceNew->SerialDataMode = InitParams->SerialDataMode;*/
InstanceNew->SerialClockSource = InitParams->SerialClockSource;
InstanceNew->FE_STB0899_Modulation = FE_899_MOD_QPSK; /* default to QPSK modulation */
InstanceNew->FECMode = InitParams->FECMode;
InstanceNew->FECType = STTUNER_FEC_MODE_DVBS2;
InstanceNew->ClockPolarity = InitParams->ClockPolarity;
InstanceNew->DataClockAtParityBytes = InitParams->DataClockAtParityBytes;
InstanceNew->TSDataOutputControl = InitParams->TSDataOutputControl;
InstanceNew->BlockSyncMode = InitParams->BlockSyncMode;
InstanceNew->DataFIFOMode = InitParams->DataFIFOMode;
InstanceNew->OutputFIFOConfig = InitParams->OutputFIFOConfig;
InstanceNew->DiSEqC_RxFreq = 0;
/********Added for DiSEqC***************************/
InstanceNew->DiSEqCConfig.Command=STTUNER_DiSEqC_COMMAND;
InstanceNew->DiSEqCConfig.ToneState=STTUNER_DiSEqC_TONE_CONTINUOUS_OFF;
/**************************************************/
InstanceNew->SET_TRACKING_PARAMS = FALSE;
/* reserve memory for register mapping */
Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("%s fail setup new register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( D0399_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_stb0899_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_stb0899_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
const char *identity = "STTUNER d0399.c demod_d0399_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
STB0899_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
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_SATDRV_STB0899
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_SATDRV_STB0899
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_SATDRV_STB0899
STTBX_Print(("%s reap next matching DeviceName[", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
STTBX_Print(("<-- ]\n"));
#endif
Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
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_SATDRV_STB0899
STTBX_Print(("%s freed block at 0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_STB0899
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_SATDRV_STB0899
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_SATDRV_STB0899
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -