📄 lnbio.c
字号:
/* ----------------------------------------------------------------------------
File Name: lnbIO.c
Description:
This file is to control LNB IC through GPIOs of demod .
Copyright (C) 2005-2006 STMicroelectronics
History:
date: 30-March-2006
version: 0.1.0
author: SD
Reference:
---------------------------------------------------------------------------- */
#ifdef ST_OSLINUX
#include "stos.h"
#else
/* C libs */
#include <string.h>
/* Standard includes */
#include "stlite.h"
#include "sttbx.h"
#endif
/* STAPI */
#include "stcommon.h" /* for ST_GetClocksPerSecond() */
#include "stevt.h"
#include "lnbIO.h" /* header for this file */
#include "sttuner.h"
#include "util.h"
#ifndef STTUNER_MINIDRIVER
/* local to stlnb */
/* 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 "sioctl.h" /* data structure typedefs for all the the sat ioctl functions */
#endif
#ifdef STTUNER_MINIDRIVER
#include "dbtypes.h" /* data types for databases */
#include "sysdbase.h" /* functions to accesss system data */
#include "iodirect.h"
#ifdef STTUNER_DRV_SAT_STV0299
#include "reg0299.h"
#elif defined(STTUNER_DRV_SAT_STV0399E)
#include "init399E.h"
#endif
#endif
#ifndef STTUNER_MINIDRIVER
/* private variables ------------------------------------------------------- */
#if defined(ST_OS21) || defined(ST_OSLINUX)
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 ---------- */
typedef struct
{
ST_DeviceName_t *DeviceName;
STTUNER_Handle_t TopLevelHandle; /* access tuner, demod etc. using this */
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 */
#ifdef STTUNER_BASIC
#ifdef STTUNER_DRV_SAT_SCR
BOOL DISECQ_ST_ENABLE;
#endif
#endif
} LNB_DemodIO_InstanceData_t;
#endif
#ifdef STTUNER_MINIDRIVER
typedef struct
{
LNB_Config_t Config; /* LNB config for each instance */
STTUNER_Handle_t TopLevelHandle;
ST_Partition_t *MemoryPartition; /* which partition this data block belongs to */
} LNB_DemodIO_InstanceData_t;
#endif
/* instance chain, the default boot value is invalid, to catch errors */
/************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
#ifndef STTUNER_MINIDRIVER
static LNB_DemodIO_InstanceData_t *InstanceChainTop = (LNB_DemodIO_InstanceData_t *)0x7fffffff;
#endif
#ifdef STTUNER_MINIDRIVER
LNB_DemodIO_InstanceData_t *LNBInstance;
#endif
/* functions --------------------------------------------------------------- */
#ifndef STTUNER_MINIDRIVER
/* I/O API */
ST_ErrorCode_t lnb_lnb_demodIO_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_lnb_demodIO_ioctl(LNB_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
ST_ErrorCode_t lnb_lnb_demodIO_overloadcheck(LNB_Handle_t Handle, BOOL *IsOverTemp, BOOL *IsCurrentOvrLoad);
ST_ErrorCode_t lnb_lnb_demodIO_setttxmode(LNB_Handle_t Handle, STTUNER_LnbTTxMode_t Ttxmode);
#endif
/* local functions */
#ifndef STTUNER_MINIDRIVER
void LNB_DemodIO_SetLnb (STTUNER_demod_instance_t *DemodInstance, int Lnb);
void LNB_DemodIO_SetTone_Demod (STTUNER_demod_instance_t *DemodInstance, int Lnb);
void LNB_DemodIO_SetPolarization(STTUNER_demod_instance_t *DemodInstance, LNB_Polarization_t Polarization);
void LNB_DemodIO_SetDACPolarization(STTUNER_demod_instance_t *DemodInstance, LNB_Polarization_t Polarization);
ST_ErrorCode_t LNB_DemodIO_SetPower (STTUNER_demod_instance_t *DemodInstance, LNB_Status_t Status);
ST_ErrorCode_t LNB_DemodIO_Set_DACPower (STTUNER_demod_instance_t *DemodInstance, LNB_Status_t Status);
ST_ErrorCode_t LNB_DemodIO_GetPower (STTUNER_demod_instance_t *DemodInstance, LNB_Status_t *Status);
#endif
#ifdef STTUNER_MINIDRIVER
void LNB_DemodIO_SetLnb(int Lnb);
void LNB_DemodIO_SetPolarization(LNB_Polarization_t Polarization);
ST_ErrorCode_t LNB_DemodIO_SetPower(LNB_Status_t Status);
#ifdef STTUNER_DRV_SAT_STV0299
#define VEN_REG_INDEX R0299_IOCFG
#define VEN_FIELD_INDEX F0299_OP1VALUE
#define VEN_FIELD_INDEX_L F0299_OP1VALUE_L
#ifdef STTUNER_LNB_TONE_THRU_DEMOD_DISEQC_PIN
#define TEN_REG_INDEX R0299_DISEQC
#define TEN_FIELD_INDEX F0299_DISEQCMODE
#define TEN_FIELD_INDEX_L F0299_DISEQCMODE_L
#else
#define TEN_REG_INDEX R0299_IOCFG
#define TEN_FIELD_INDEX F0299_OP0VALUE
#define TEN_FIELD_INDEX_L F0299_OP0VALUE_L
#endif
#define VSEL_REG_INDEX R0299_DISEQC
#define VSEL_FIELD_INDEX F0299_LOCKOUTPUT
#define VSEL_FIELD_INDEX_L F0299_LOCKOUTPUT_L
#elif defined(STTUNER_DRV_SAT_STV0399E)
#define VEN_REG_INDEX R399_IOCFG2
#define VEN_FIELD_INDEX F399_OP1_1
#define VEN_FIELD_INDEX_L F399_OP1_1_L
#define TEN_REG_INDEX R399_IOCFG2
#define TEN_FIELD_INDEX F399_OP0_1
#define TEN_FIELD_INDEX_L F399_OP0_1_L
#define VSEL_REG_INDEX R399_IOCFG1
#define VSEL_FIELD_INDEX F399_LOCK_CONF
#define VSEL_FIELD_INDEX_L F399_LOCK_CONF_L
#endif
#endif
#ifndef STTUNER_MINIDRIVER
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0299_Install()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_DemodIO_Install(STTUNER_lnb_dbase_t *Lnb)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == TRUE)
{
return(STTUNER_ERROR_INITSTATE);
}
/* mark ID in database */
Lnb->ID = STTUNER_LNB_DEMODIO;
/* map API */
Lnb->lnb_Init = lnb_lnb_demodIO_Init;
Lnb->lnb_Term = lnb_lnb_demodIO_Term;
Lnb->lnb_Open = lnb_lnb_demodIO_Open;
Lnb->lnb_Close = lnb_lnb_demodIO_Close;
Lnb->lnb_GetConfig = lnb_lnb_demodIO_GetConfig;
Lnb->lnb_SetConfig = lnb_lnb_demodIO_SetConfig;
Lnb->lnb_ioaccess = lnb_lnb_demodIO_ioaccess;
Lnb->lnb_ioctl = lnb_lnb_demodIO_ioctl;
Lnb->lnb_overloadcheck = lnb_lnb_demodIO_overloadcheck;
Lnb->lnb_setttxmode = lnb_lnb_demodIO_setttxmode;
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;
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0299_UnInstall()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_DemodIO_UnInstall(STTUNER_lnb_dbase_t *Lnb)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
return(STTUNER_ERROR_INITSTATE);
}
if(Lnb->ID != STTUNER_LNB_DEMODIO)
{
return(STTUNER_ERROR_ID);
}
/* has all memory been freed, by Term() */
if(InstanceChainTop != NULL)
{
return(ST_ERROR_OPEN_HANDLE);
}
/* 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;
Lnb->lnb_overloadcheck = NULL;
Lnb->lnb_setttxmode = NULL;
#if defined(ST_OS21) || defined(ST_OSLINUX)
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
InstanceChainTop = (LNB_DemodIO_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
return(Error);
}
#endif
/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
LNB_DemodIO_InstanceData_t *InstanceNew, *Instance;
if(Installed == FALSE)
{
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)
{
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB_DemodIO_InstanceData_t ));
if (InstanceNew == NULL)
{
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->MemoryPartition = InitParams->MemoryPartition;
InstanceNew->InstanceChainNext = NULL; /* always last in the chain */
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
LNBInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB_DemodIO_InstanceData_t ));
LNBInstance->MemoryPartition = InitParams->MemoryPartition;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
LNB_DemodIO_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
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)
{
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
Instance = InstanceChainTop;
while(1)
{
if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
/* 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);
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 */
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
else
{
Instance = Instance->InstanceChainNext; /* next block */
}
}
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
memory_deallocate(LNBInstance->MemoryPartition, LNBInstance);
Error = ST_NO_ERROR;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_Open()
Description:
Parameters:
Return Value:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -