📄 lstem.c
字号:
/* ----------------------------------------------------------------------------
File Name: lstem.c
Description:
STEM LNB driver (should setup I/O passthrough to a stv0299 demod driver)
Copyright (C) 1999-2001 STMicroelectronics
History:
date: 19-March-2002
version:
author: SJD
comment:
date: 10-April-2002
version:
author: GJP
comment: polarity selection corrected.
Reference:
ST API Definition "LNB Driver API" DVD-API-06
---------------------------------------------------------------------------- */
/* Includes ---------------------------------------------------------------- */
/* C libs */
#include <string.h>
/* Standard includes */
#include "stlite.h"
/* STAPI */
#include "stcommon.h" /* for ST_GetClocksPerSecond() */
#include "sttbx.h"
#include "stevt.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 */
#include "ioarch.h" /* I/O for this driver */
#include "ioreg.h" /* I/O register mapping */
#include "sdrv.h" /* utilities */
#include "lstem.h" /* header for this file */
#include "sioctl.h" /* data structure typedefs for all the the sat ioctl functions */
/* Global variable to keep track of current running task */
extern task_t *TunerTask1, *TunerTask2;
/* Global variable which sets to 2 when both task are running and helps
to differentiate when single tuner is running and when dual tuner is running */
extern U8 ucDualTunerFlag;
/* Added by for Debug 22 July 2k2 */
#ifdef USE_TRACE_BUFFER_FOR_DEBUG
#define DMP
extern void DUMP_DATA(char *info) ;
extern char Trace_PrintBuffer[40]; /* global variable to be seen by modules */
#endif
/* macros ------------------------------------------------------------------ */
/* Delay calling task for a period of microseconds */
#ifdef ST_OS21
#define LSTEM_Delay_uS(micro_sec) task_delay((signed int) \
(((micro_sec) + 999) / 1000) * \
ST_GetClocksPerSecond() / 1000)
#else
#define LSTEM_Delay_uS(micro_sec) task_delay((unsigned int) \
(((micro_sec) + 999) / 1000) * \
ST_GetClocksPerSecond() / 1000)
#endif
/* 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
static BOOL Installed = FALSE;
/* ---------- per instance of driver ---------- */
/* Test Data and Function declaration--------------------------------*/
extern U8 PCF8574RegisterValue;
extern U32 DemodHandleOne;
extern U32 DemodHandleTwo;
extern U32 LnbHandleOne ;
extern U32 LnbHandleTwo ;
U8 AccessFlag=0;
/* Test Data and Function declaration ------------------------------------------------*/
typedef struct
{
ST_DeviceName_t *DeviceName; /* unique name for opening under */
STTUNER_Handle_t TopLevelHandle; /* access tuner, demod etc. using this */
IOARCH_Handle_t IOHandle; /* instance access to I/O driver */
STTUNER_IOREG_DeviceMap_t DeviceMap; /* stem register map & data table */
LNB_Config_t Config; /* LNB config for each instance */
ST_Partition_t *MemoryPartition; /* which partition this data block belongs to */
void *InstanceChainPrev; /* previous data block in chain or NULL if not */
void *InstanceChainNext; /* next data block in chain or NULL if last */
} LSTEM_InstanceData_t;
/* instance chain, the default boot value is invalid, to catch errors */
static LSTEM_InstanceData_t *InstanceChainTop = (LSTEM_InstanceData_t *)0x7fffffff;
/* functions --------------------------------------------------------------- */
/* API */
ST_ErrorCode_t lnb_lSTEM_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams);
ST_ErrorCode_t lnb_lSTEM_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams);
ST_ErrorCode_t lnb_lSTEM_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle);
ST_ErrorCode_t lnb_lSTEM_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams);
ST_ErrorCode_t lnb_lSTEM_GetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
ST_ErrorCode_t lnb_lSTEM_SetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
/* I/O API */
ST_ErrorCode_t lnb_lSTEM_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_lSTEM_ioctl(LNB_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
/* local functions */
void LSTEM_SetLnb (IOARCH_Handle_t LNBHandle, int Lnb);
void LSTEM_SetPolarization(IOARCH_Handle_t LNBHandle, LNB_Polarization_t Polarization);
ST_ErrorCode_t LSTEM_SetPower (IOARCH_Handle_t LNBHandle, LNB_Status_t Status);
ST_ErrorCode_t LSTEM_GetPower (IOARCH_Handle_t LNBHandle, LNB_Status_t *Status);
void LSTEM_UpdateLNB (IOARCH_Handle_t LNBHandle);
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STEM_Install()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_STEM_Install(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c STTUNER_DRV_LNB_STEM_Install()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == TRUE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s fail driver already installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s installing sat:lnb:STEM...", identity));
#endif
/* mark ID in database */
Lnb->ID = STTUNER_LNB_STEM;
/* map API */
Lnb->lnb_Init = lnb_lSTEM_Init;
Lnb->lnb_Term = lnb_lSTEM_Term;
Lnb->lnb_Open = lnb_lSTEM_Open;
Lnb->lnb_Close = lnb_lSTEM_Close;
Lnb->lnb_GetConfig = lnb_lSTEM_GetConfig;
Lnb->lnb_SetConfig = lnb_lSTEM_SetConfig;
Lnb->lnb_ioaccess = lnb_lSTEM_ioaccess;
Lnb->lnb_ioctl = lnb_lSTEM_ioctl;
#if defined(STTUNER_DRV_SAT_LNB21) || defined(STTUNER_DRV_SAT_LNBH21) /*Added for 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_lstem_overloadcheck;
#if defined(STTUNER_DRV_SAT_LNBH21)
Lnb->lnb_setttxmode = lnb_lstem_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_LSTEM
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STEM_UnInstall()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_STEM_UnInstall(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c STTUNER_DRV_LNB_STEM_UnInstall()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
if(Lnb->ID != STTUNER_LNB_STEM)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
return(ST_ERROR_OPEN_HANDLE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s uninstalling sat:lnb:STEM...", 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_LSTEM
STTBX_Print(("<"));
#endif
#ifdef ST_OS21
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print((">"));
#endif
InstanceChainTop = (LSTEM_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ API /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c lnb_lSTEM_Init()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
LSTEM_InstanceData_t *InstanceNew, *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LSTEM_InstanceData_t ));
if (InstanceNew == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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; /* mark as not used */
InstanceNew->IOHandle = InitParams->IOHandle;
InstanceNew->MemoryPartition = InitParams->MemoryPartition;
InstanceNew->DeviceMap.Timeout = IOREG_DEFAULT_TIMEOUT;
InstanceNew->DeviceMap.Registers = DEF_LNB_STEM_NBREG;
InstanceNew->DeviceMap.Fields = DEF_LNB_STEM_NBFIELD;
InstanceNew->DeviceMap.Mode = IOREG_MODE_NOSUBADR; /* Required for STEM LNB type */
InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
InstanceNew->InstanceChainNext = NULL; /* always last in the chain */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( LSTEM_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -