📄 l0399.c
字号:
/* ----------------------------------------------------------------------------
File Name: l0399.c
Description:
stv0399 LNB driver (setup I/O passthrough to a stv0399 demod driver)
Copyright (C) 1999-2001 STMicroelectronics
History:
date: 20-August-2001
version: 3.2.0
author: GJP
comment: Initial version.
date: 07-April-2004
version:
author: SD
comment: Add support for SatCR.
Reference:
ST API Definition "LNB Driver API" DVD-API-06
---------------------------------------------------------------------------- */
/* Includes ---------------------------------------------------------------- */
/* C libs */
#include <string.h>
/* Standard includes */
#include "stlite.h"
#ifndef STTUNER_MINIDRIVER
#include "stevt.h"
#include "sdrv.h" /* utilities */
#include "sioctl.h" /* data structure typedefs for all the the sat ioctl functions */
#include "ioarch.h" /* I/O for this driver */
#include "ioreg.h" /* I/O register mapping */
#include "chip.h" /* I/O register mapping */
#endif
/* STAPI */
#include "stcommon.h" /* for ST_GetClocksPerSecond() */
#include "sttbx.h"
#include "sttuner.h"
/* local to stlnb */
#include "util.h" /* generic utility functions for stlnb */
#include "dbtypes.h" /* data types for databases */
#include "sysdbase.h" /* functions to accesss system data */
/* LLA */
#include "399_drv.h" /* driver */
#include "399_util.h" /* utility functions to support STV0399 LLA */
#include "l0399.h" /* header for this file */
#include "d0399.h" /* access */
/* private variables ------------------------------------------------------- */
#ifdef ST_OS21
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif
/* ---------- per instance of driver ---------- */
typedef struct
{ /* supplied by init() */
ST_DeviceName_t *DeviceName; /* unique name for opening under */
IOARCH_Handle_t IOHandle; /* instance access to I/O driver */
ST_Partition_t *MemoryPartition; /* which partition this data block belongs to */
/* supplied by open() */
STTUNER_Handle_t TopLevelHandle; /* access tuner, demod etc. using this */
/* generated */
void *InstanceChainPrev; /* previous data block in chain or NULL if not */
void *InstanceChainNext; /* next data block in chain or NULL if last */
FE_399_Handle_t FE_399_Handle; /* borrow demod handle to interface to LLA */
LNB_Config_t Config; /* LNB config for each instance */
BOOL DISECQ_ST_ENABLE;
} L0399_InstanceData_t;
#ifndef STTUNER_MINIDRIVER
static BOOL Installed = FALSE;
/* instance chain, the default boot value is invalid, to catch errors */
static L0399_InstanceData_t *InstanceChainTop = (L0399_InstanceData_t *)0x7fffffff;
#endif
#ifdef STTUNER_MINIDRIVER
/* instance chain, the default boot value is invalid, to catch errors */
static L0399_InstanceData_t *LNBInstance;
#endif
/************extern from open.c for SatCR loopthrough mode application ************/
#ifdef STTUNER_DRV_SAT_SCR
#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
extern U32 LnbDrvHandleOne;
#endif
#endif
/* functions --------------------------------------------------------------- */
#ifndef STTUNER_MINIDRIVER
/* API */
ST_ErrorCode_t lnb_l0399_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams);
ST_ErrorCode_t lnb_l0399_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams);
ST_ErrorCode_t lnb_l0399_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle);
ST_ErrorCode_t lnb_l0399_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams);
ST_ErrorCode_t lnb_l0399_GetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
ST_ErrorCode_t lnb_l0399_SetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
/* I/O API */
ST_ErrorCode_t lnb_l0399_ioaccess(LNB_Handle_t Handle, IOARCH_Handle_t IOHandle,
STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);
/* access device specific low-level functions */
ST_ErrorCode_t lnb_l0399_ioctl(LNB_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
#endif
#ifndef STTUNER_MINIDRIVER
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0399_Install()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_STV0399_Install(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c STTUNER_DRV_LNB_STV0399_Install()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == TRUE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver already installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s installing sat:lnb:STV0399...", identity));
#endif
/* mark ID in database */
Lnb->ID = STTUNER_LNB_STV0399;
/* map API */
Lnb->lnb_Init = lnb_l0399_Init;
Lnb->lnb_Term = lnb_l0399_Term;
Lnb->lnb_Open = lnb_l0399_Open;
Lnb->lnb_Close = lnb_l0399_Close;
Lnb->lnb_GetConfig = lnb_l0399_GetConfig;
Lnb->lnb_SetConfig = lnb_l0399_SetConfig;
Lnb->lnb_ioaccess = lnb_l0399_ioaccess;
Lnb->lnb_ioctl = lnb_l0399_ioctl;
#if defined(STTUNER_DRV_SAT_LNB21) || defined(STTUNER_DRV_SAT_LNBH21) /*Added for GNBvd40148-->Error
if sttuner compiled with LNBH21 option but use another one: This will only come when more than 1 lnb is
in use & atleast one of them is LNB21 or LNBH21*/
Lnb->lnb_overloadcheck = lnb_l0399_overloadcheck;
#if defined(STTUNER_DRV_SAT_LNBH21)
Lnb->lnb_setttxmode = lnb_l0399_setttxmode;
#endif
#endif
InstanceChainTop = NULL;
#ifdef ST_OS21
Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif
Installed = TRUE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0399_UnInstall()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_STV0399_UnInstall(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c STTUNER_DRV_LNB_STV0399_UnInstall()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
if(Lnb->ID != STTUNER_LNB_STV0399)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
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_L0399
STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
return(ST_ERROR_OPEN_HANDLE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s uninstalling sat:lnb:STV0399...", identity));
#endif
/* mark ID in database */
Lnb->ID = STTUNER_NO_DRIVER;
/* unmap API */
Lnb->lnb_Init = NULL;
Lnb->lnb_Term = NULL;
Lnb->lnb_Open = NULL;
Lnb->lnb_Close = NULL;
Lnb->lnb_GetConfig = NULL;
Lnb->lnb_SetConfig = NULL;
Lnb->lnb_ioaccess = NULL;
Lnb->lnb_ioctl = NULL;
#if defined(STTUNER_DRV_SAT_LNB21) || defined(STTUNER_DRV_SAT_LNBH21)
Lnb->lnb_overloadcheck = NULL;
#if defined(STTUNER_DRV_SAT_LNBH21)
Lnb->lnb_setttxmode = NULL;
#endif
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("<"));
#endif
#ifdef ST_OS21
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print((">"));
#endif
InstanceChainTop = (L0399_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("ok\n"));
#endif
return(Error);
}
#endif
/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ API /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Name: lnb_l0399_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0399_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c lnb_l0399_Init()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0399_InstanceData_t *InstanceNew, *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check partition ---------- */
Error = STTUNER_Util_CheckPtrNull(InitParams->MemoryPartition);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( L0399_InstanceData_t ));
if (InstanceNew == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
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->IOHandle = InitParams->IOHandle;
InstanceNew->MemoryPartition = InitParams->MemoryPartition;
InstanceNew->TopLevelHandle = STTUNER_MAX_HANDLES; /* mark as not used */
InstanceNew->InstanceChainNext = NULL; /* always last in the chain */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( L0399_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
LNBInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( L0399_InstanceData_t ));
LNBInstance->MemoryPartition = InitParams->MemoryPartition;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0399_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0399_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c lnb_l0399_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0399_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -