📄 l0299.c
字号:
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail allocate register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* install a register map */
Error = L0299_Reg_Install(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail install a register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( L0299_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
LNBInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( L0299_InstanceData_t ));
LNBInstance->MemoryPartition = InitParams->MemoryPartition;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0299_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0299_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
const char *identity = "STTUNER l0299.c lnb_l0299_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0299_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
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_L0299
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_L0299
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_L0299
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("]\n"));
#endif
Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
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_L0299
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
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_L0299
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_L0299
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
memory_deallocate(LNBInstance->MemoryPartition, LNBInstance);
Error = ST_NO_ERROR;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0299_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0299_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
const char *identity = "STTUNER l0299.c lnb_l0299_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0299_InstanceData_t *Instance;
STTUNER_demod_instance_t *DemodInstance;
STTUNER_InstanceDbase_t *Inst;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
Inst = STTUNER_GetDrvInst();
/* 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_SATDRV_L0299
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_SATDRV_L0299
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_SATDRV_L0299
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_SATDRV_L0299
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif
if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
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 */
/* this LNB driver is only for use with an STV0299 demod */
Inst = STTUNER_GetDrvInst(); /* pointer to instance database */
/* pointer to **OPENED** demod for this instance */
DemodInstance = &Inst[OpenParams->TopLevelHandle].Sat.Demod;
if(DemodInstance->Driver->ID != STTUNER_DEMOD_STV0299)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail STV0299 required\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_ID);
}
else
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s STV0299 demod found\n", identity));
#endif
}
/* Set LNB capabilties */
Capability->ShortCircuitDetect = TRUE; /* lie (rewrite to get pwr status using stv0299 i/o pin etc.) */
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
#ifdef STTUNER_LNB_POWER_OFF_BY_DEFAULT
Instance->Config.Status = LNB_STATUS_OFF;
Instance->Config.Polarization = STTUNER_LNB_OFF;
#else
Instance->Config.Status = LNB_STATUS_ON;
Instance->Config.Polarization = STTUNER_PLR_HORIZONTAL; /*set default pol->Horizontal*/
#endif
Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
if((Inst[OpenParams->TopLevelHandle].Sat.Tuner.Driver->ID)==STTUNER_TUNER_DSF8910)
{
Instance->Config.LNBPowerControl = STTUNER_LNB_POWER_DemodDACPin;
Instance->Config.ToneSourceControl = STTUNER_22KHz_TONE_DemodDiseqcPin;
L0299_SetTone_Demod(&Instance->DeviceMap, Instance->IOHandle, 0); /*LNB Tone OFF*/
L0299_Set_DACPower(&Instance->DeviceMap, Instance->IOHandle, Instance->Config.Status);/*set LNB power 18V*/
}
else
{
Instance->Config.ToneSourceControl = STTUNER_22KHz_TONE_DemodOP0Pin;
Instance->Config.LNBPowerControl = STTUNER_LNB_POWER_LNBPDefault;
L0299_SetLnb(&Instance->DeviceMap, Instance->IOHandle, 0);/* LNB tone off */
L0299_SetPower(&Instance->DeviceMap, Instance->IOHandle, Instance->Config.Status);/*LNB power on*/
}
/* wait 500uS (0.5mS) then get power status */
L0299_Delay_uS(500);
Error = L0299_GetPower(&Instance->DeviceMap, Instance->IOHandle, &Instance->Config.Status);
/* Check to ensure there is no problem with the LNB circuit */
if (Error == ST_NO_ERROR) /* last i/o (above) operation was good */
{
if (Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail SAT_LNB_SHORT_CIRCUIT\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_HWFAIL);
}
}
else
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s fail Error=%u\n", identity, Error)); /* L0299_GetPower failed */
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
Instance->TopLevelHandle = OpenParams->TopLevelHandle; /* mark as valid */
*Handle = (U32)Instance;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
/* Set latest configuration */
LNBInstance->Config.Status = LNB_STATUS_ON;
LNBInstance->Config.ToneState = STTUNER_LNB_TONE_OFF;
LNBInstance->Config.Polarization = STTUNER_PLR_HORIZONTAL;/* set default pol->Horizontal*/
LNBInstance->Config.ToneSourceControl = STTUNER_22KHz_TONE_DemodOP0Pin;
LNBInstance->Config.LNBPowerControl = STTUNER_LNB_POWER_LNBPDefault;
L0299_SetLnb(0);/* LNB tone off */
L0299_SetPower(LNBInstance->Config.Status);/*LNB power on*/
L0299_SetPolarization(STTUNER_PLR_HORIZONTAL);
*Handle = (U32)LNBInstance;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0299_Close()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0299_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
const char *identity = "STTUNER l0299.c lnb_l0299_Close()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0299_InstanceData_t *Instance;
Instance = (L0299_InstanceData_t *)Handle;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0299
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_SATDRV_L0299
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_SATDRV_L0299
STTBX_Print(("%s fail driver instance not open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
Instance->TopLevelHandle = STTUNER_MAX_HANDLES;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -