?? lnb199.c
字號:
/*****************************************************************************File Name : lnb199.cDescription : ST LNBP implementation of the SAT API for STV0199.Copyright (C) 1999 STMicroelectronicsReference :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************/#define SAT_PROTOTYPE static /* Local pre-include defs *//* Includes --------------------------------------------------------------- */#include <string.h> /* C libs */#include <stdio.h>#include "stlite.h" /* Standard includes */#include "stddefs.h"#include "sttuner.h" /* STAPI Error codes, etc */#include "sat.h" /* SAT Device API */#include "stv199.h" /* Low-level device access *//* Private types/constants ------------------------------------------------ */typedef struct{ SAT_MapTable_t *MapTable_p; /* Maptable */ ST_Partition_t *MemoryPartition; SAT_Config_t Config; /* SAT device configuration */ STV0199A_Device_t STV0199ADevice; /* 199 device access */} SAT_ControlBlock_t;/* Private variables ------------------------------------------------------ */extern SAT_MapTable_t __STV0199LNBMapTable;/* Private macros --------------------------------------------------------- */#define STV0199A_HANDLE(x) ((STV0199A_Device_t *) \ (&(((SAT_ControlBlock_t *)x)->STV0199ADevice)))#define SAT_HANDLE(x) ((SAT_ControlBlock_t *)x)/* Private function prototypes -------------------------------------------- *//* API routines ----------------------------------------------------------- *//*****************************************************************************Name: SAT_Init()Description: Initializes the SAT device for the ST LNBP.Parameters: InitParams_p, pointer to the initialization parameters.Return Value: SAT_NO_ERROR, the operation completed without error. SAT_ERROR_BAD_PARAMETER, one or more parameters were invalid. SAT_ERROR_LNB_HW, a hardware error in the LNB circuit.See Also: SAT_Term()*****************************************************************************/static SAT_ErrorCode_t SAT_Init(SAT_InitParams_t *InitParams_p, SAT_Handle_t *Handle_p, SAT_Capability_t *Capability_p){ SAT_ErrorCode_t Error = SAT_NO_ERROR; SAT_ControlBlock_t *Sat_p; /* Allocate control block memory */ Sat_p = memory_allocate(InitParams_p->MemoryPartition, sizeof(SAT_ControlBlock_t)); /* Ensure allocation succeeded */ if (Sat_p == NULL) return ST_ERROR_NO_MEMORY; /* Set map table information */ Sat_p->MapTable_p = &__STV0199LNBMapTable; Sat_p->MemoryPartition = InitParams_p->MemoryPartition; /* Set the low-level device access pointer */ Sat_p->STV0199ADevice.Handle_p = InitParams_p->DeviceAccess_p; /* Set capabilities of the LNBP */ Capability_p->LNBShortCircuitDetect = TRUE; Capability_p->LNBPowerAvailable = TRUE; Capability_p->PolarizationSelect = SAT_PLR_ALL; /* Obtains latest LNBP configuration */ Error = SAT_GetConfig((SAT_Handle_t)Sat_p, &Sat_p->Config); /* Allocate the handle */ *Handle_p = Sat_p; /* Check to ensure there is no problem with the LNB circuit */ if (Error == ST_NO_ERROR && Sat_p->Config.LNBStatus == SAT_LNB_SHORT_CIRCUIT) Error = SAT_ERROR_LNB_HW; /* Ensure device communications is working */ if (Error != ST_NO_ERROR) { /* Deallocate control block */ memory_deallocate(InitParams_p->MemoryPartition, Sat_p); } return Error;} /* SAT_Init() *//*****************************************************************************Name: SAT_Term()Description: Performs any required tidying up in order to cleanly terminate the SAT device.Parameters: Sat_p, pointer to the SAT device.Return Value: SAT_NO_ERROR, the operation completed without error.See Also: SAT_Init()*****************************************************************************/static SAT_ErrorCode_t SAT_Term(SAT_Handle_t Handle){ memory_deallocate(SAT_HANDLE(Handle)->MemoryPartition, Handle); return ST_NO_ERROR;} /* SAT_Term() *//*****************************************************************************Name: SAT_GetConfig()Description: Obtains the current SAT device configuration and stores it in the configuration structure for the SAT device.Parameters: Sat_p, pointer to the SAT device. SatConfig_p, pointer to area to store current SAT config.Return Value: SAT_NO_ERROR, the operation completed without error. STI2C_xxxx, there was a problem accessing the device.See Also: SAT_SetConfig()*****************************************************************************/static SAT_ErrorCode_t SAT_GetConfig(SAT_Handle_t Handle, SAT_Config_t *SatConfig_p){ SAT_ErrorCode_t Error = SAT_NO_ERROR; STV0199A_ErrorCode_t RegError; U8 LnbReg; /* Read the current value of the FC22CR register */ RegError = STV0199A_Read(STV0199A_HANDLE(Handle), &LnbReg, STV0199A_F22CR); /* Check the operation completed successfully */ if (RegError == STV0199A_NO_ERROR) { /* Get the LNB power */ SAT_HANDLE(Handle)->Config.LNBStatus = (LnbReg & STV0199A_F22CR_OP1_MSK)?SAT_LNB_ON:SAT_LNB_OFF; /* Get LNB tone state */ SAT_HANDLE(Handle)->Config.ToneState = (LnbReg & STV0199A_F22CR_P22_MSK)?SAT_TONE_22KHZ:SAT_TONE_OFF; /* Get polarization */ SAT_HANDLE(Handle)->Config.Polarization = (LnbReg & STV0199A_F22CR_OP2_MSK)?SAT_PLR_VERTICAL:SAT_PLR_HORIZONTAL; /* Copy params to caller */ *SatConfig_p = SAT_HANDLE(Handle)->Config; } else { /* Problem accessing device */ Error = RegError; } return Error;} /* SAT_GetConfig() *//*****************************************************************************Name: SAT_SetConfig()Description: Configures the SAT device's power/tone/polarization.Parameters: Sat_p, pointer to the SAT device. Config_p, pointer to the new device configuration.Return Value: SAT_NO_ERROR, the operation completed successfully. SAT_ERROR_BAD_PARAMETER, one of the parametes was invalid. STI2C_xxxx, there was a problem accessing the device.See Also: SAT_GetConfig()*****************************************************************************/static SAT_ErrorCode_t SAT_SetConfig(SAT_Handle_t Handle, SAT_Config_t *Config_p){ SAT_ErrorCode_t Error = SAT_NO_ERROR; STV0199A_ErrorCode_t RegError; /* Check power setting is valid */ if ((Config_p->LNBStatus == SAT_LNB_ON || /* Valid LNB */ Config_p->LNBStatus == SAT_LNB_OFF) && (Config_p->Polarization == SAT_PLR_HORIZONTAL || /* Valid PLR */ (Config_p->ToneState >= SAT_TONE_DEFAULT && Config_p->ToneState <= SAT_TONE_22KHZ))) /* Valid TONE */ { U8 LnbReg; /* Check the new settings differ from the old ones -- this * can save time. */ if (SAT_HANDLE(Handle)->Config.LNBStatus != Config_p->LNBStatus || SAT_HANDLE(Handle)->Config.Polarization != Config_p->Polarization || SAT_HANDLE(Handle)->Config.ToneState != Config_p->ToneState) { /* Read the current value of the FC22CR register */ RegError = STV0199A_Read(STV0199A_HANDLE(Handle), &LnbReg, STV0199A_F22CR); /* Check the operation completed successfully */ if (RegError == STV0199A_NO_ERROR) { /* Select the LNB power */ switch (Config_p->LNBStatus) { case SAT_LNB_ON: LnbReg |= STV0199A_F22CR_OP1_MSK; SAT_HANDLE(Handle)->Config.LNBStatus = SAT_LNB_ON; break; case SAT_LNB_OFF: LnbReg &= ~STV0199A_F22CR_OP1_MSK; SAT_HANDLE(Handle)->Config.LNBStatus = SAT_LNB_OFF; break; default: break; } /* Select LNB band */ LnbReg &= ~STV0199A_F22CR_F22_ENA_MSK; /* F22 simple output port */ switch (Config_p->ToneState) { case SAT_TONE_OFF: /* No tone */ LnbReg &= ~STV0199A_F22CR_P22_MSK; SAT_HANDLE(Handle)->Config.ToneState = SAT_TONE_OFF; break; case SAT_TONE_22KHZ: /* 22KHz tone */ LnbReg |= STV0199A_F22CR_P22_MSK; SAT_HANDLE(Handle)->Config.ToneState = SAT_TONE_22KHZ; break; default: break; } /* Select polarization */ switch (Config_p->Polarization) { case SAT_PLR_VERTICAL: /* OP_2 controls -- 18V (high) */ LnbReg &= ~STV0199A_F22CR_OP2_MSK; SAT_HANDLE(Handle)->Config.Polarization = SAT_PLR_VERTICAL; break; case SAT_PLR_HORIZONTAL: /* OP_2 controls -- 13V (low) */ LnbReg |= STV0199A_F22CR_OP2_MSK; SAT_HANDLE(Handle)->Config.Polarization = SAT_PLR_HORIZONTAL; break; default: break; } /* Now write out the new value */ RegError = STV0199A_Write(STV0199A_HANDLE(Handle), LnbReg, STV0199A_F22CR); /* Only update our local copy of the settings if the new value * was written out successfully. */ if (RegError != STV0199A_NO_ERROR) { /* Unable to write to new settings */ Error = RegError; } } else { /* Unable to read existing settings */ Error = RegError; } } } else { /* One or more parameters are invalid */ Error = SAT_ERROR_BAD_PARAMETER; } return Error;} /* SAT_SetConfig() *//* Exported Map Table ------------------------------------------------------------ */SAT_MapTable_t __STV0199LNBMapTable ={ SAT_Init, SAT_Term, SAT_GetConfig, SAT_SetConfig};/* End of lnb199.c */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -