?? sttuner.c
字號:
/*****************************************************************************File Name : sttuner.cDescription : STTUNER device driver.Copyright (C) 1999 STMicroelectronicsHistory : 23/09/99 New threshold API calls added Timeout parameter added to API calls Added new 'tune to exact frequency' API call. 21/01/00 API modifications to scan, band and threshold lists. Major changes to tuner initialization params. New API call for direct control over tuner LNB. Events now exported to the Event Handler. 23/06/00 Event handler close problem solved.Reference :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************//* Includes --------------------------------------------------------------- */#include <string.h> /* C libs */#include <stdio.h>#include "stlite.h" /* Standard includes */#include "sttuner.h" /* STAPI includes */#include "sti2c.h"#include "sttbx.h"#include "stevt.h"#include "demod.h" /* DEMOD Device API */#include "tnr.h" /* TNR Device API */#include "sat.h" /* SAT Device API */#include "tuner.h" /* Core Tuner API *//* Private types/constants ------------------------------------------------ */#define DEFAULT_FREQUENCY_SCAN_STEP 10000/* Private variables ------------------------------------------------------ *//* Driver revision */static const ST_Revision_t Revision = "STTUNER-REL_3.0.0";/* Queue management */typedef struct Node_s{ TUNER_ControlBlock_t ControlBlock; void *This_p; struct Node_s *Next_p;} Node_t;static Node_t *DeviceQueue_p = NULL;/* Private macros --------------------------------------------------------- */#define GetControlBlockFromHandle(h) \ (TUNER_ControlBlock_t *) \ (FindNode(DeviceQueue_p, \ IsHandle, \ &h, \ NULL))#define GetControlBlockFromName(n) \ (TUNER_ControlBlock_t *) \ (FindNode(DeviceQueue_p, \ IsDeviceName, \ n, \ NULL))#define IsInit(n) (GetControlBlockFromName(n) != NULL)/* Private function prototypes -------------------------------------------- */static void InsertNode(Node_t *Start_p, Node_t *New_p, void *Data_p);static void AppendNode(Node_t *Start_p, Node_t *New_p, void *Data_p);static void RemoveNode(Node_t *Before_p, Node_t *Old_p);static Node_t *FindNode(const Node_t *Start_p, BOOL (*CompareFunction)(const void *Arg1, const void *Arg2), const void *Compare_p, Node_t **Predecessor_p);static Node_t *NextNode(const Node_t *Start_p);static Node_t *LastNode(const Node_t *Start_p);static BOOL IsDeviceName(const void *Tuner_p, const void *DeviceName_p);static BOOL IsHandle(const void *Tuner_p, const void *Handle_p);/* STUART API routines (alphabetical order) ------------------------------- *//*****************************************************************************Name: STTUNER_Close()Description: Closes the tuner device - no further activity can take place on the handle, until re-opened.Parameters: Handle, the handle of the tuner device.Return Value: ST_NO_ERROR, the operation was carried out without error. ST_ERROR_INVALID_HANDLE, the handle was invalid. ST_ERROR_BAD_PARAMETER Handle NULLSee Also: STTUNER_Open()*****************************************************************************/ST_ErrorCode_t STTUNER_Close(STTUNER_Handle_t Handle){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if(Handle == 0) { return ST_ERROR_BAD_PARAMETER; } /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromHandle(Handle); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* Nullify the device handle to ensure no further calls * can be made. */ Tuner_p->Handle = 0; /* We must ensure that all activity on the tuner is idle * before we return to the caller. Note that this call will not * return until the current scan step has completed. */ TUNER_AbortScan(Tuner_p); /* This call can not fail */ /* Close the event handler if being used */ if (Tuner_p->InitParams.EVTDeviceName[0] != 0) { /* No more events until driver is opened again */ STEVT_Close(Tuner_p->EVTHandle); /* Close handle to EVT */ } } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_Close() *//*****************************************************************************Name: STTUNER_GetBandList()Description: Obtains the current frequency bands and associated local oscillator frequencies.Parameters: Handle, the handle of the tuner device.Return Value: ST_NO_ERROR, the operation was carried out without error ST_ERROR_INVALID_HANDLE, the handle was invalid ST_ERROR_BAD_PARAMETER Handle or BandList_p NULLSee Also: STTUNER_SetBandList()*****************************************************************************/ST_ErrorCode_t STTUNER_GetBandList(STTUNER_Handle_t Handle, STTUNER_BandList_t *BandList_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((Handle == 0) || (BandList_p == NULL)) { return ST_ERROR_BAD_PARAMETER; } /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromHandle(Handle); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* Copy the band/lo frequency list to the caller supplied area */ BandList_p->NumElements = Tuner_p->BandList.NumElements; memcpy(BandList_p->BandList, Tuner_p->BandList.BandList, (Tuner_p->BandList.NumElements * sizeof(STTUNER_Band_t))); } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_GetBandList() *//*****************************************************************************Name: STTUNER_GetCapability()Description: Obtain the capabilities of the tuner, including version and name.Parameters: DeviceName, the device name of the initialized tuner device. Capability_p, caller supplied area to copy device capabilties.Return Value: ST_NO_ERROR, the operation was carried out without error. ST_ERROR_UNKNOWN_DEVICE, the device is not known to the driver. ST_ERROR_BAD_PARAMETER Capability_p NULLSee Also: Nothing.*****************************************************************************/ST_ErrorCode_t STTUNER_GetCapability(const ST_DeviceName_t DeviceName, STTUNER_Capability_t *Capability_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if(Capability_p == NULL) { return ST_ERROR_BAD_PARAMETER; } /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromName(DeviceName); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* It is safe to simply copy across the capabilty parameters as * we must be initialized at this point. */ *Capability_p = Tuner_p->Capability; } else { /* The device name is invalid */ Error = ST_ERROR_UNKNOWN_DEVICE; } /* Common exit point */ return Error;} /* STTUNER_GetCapability() *//*****************************************************************************Name: STTUNER_GetRevision()Description: Obtains the revision number of the tuner device driver.Parameters: None.Return Value: Global driver revision number.See Also: Revision (top of module).*****************************************************************************/ST_Revision_t STTUNER_GetRevision(void){ return Revision;} /* STTUNER_GetRevision() *//*****************************************************************************Name: STTUNER_GetScanList()Description: Obtains the ordered scan list that dictates the criteria during a tuner scan at each frequency step.Parameters: Handle, the handle of the tuner device.Return Value: ST_NO_ERROR, the operation was carried out without error ST_ERROR_INVALID_HANDLE, the handle was invalid ST_ERROR_BAD_PARAMETER Handle or ScanList_p NULLSee Also: STTUNER_SetScanList()*****************************************************************************/ST_ErrorCode_t STTUNER_GetScanList(STTUNER_Handle_t Handle, STTUNER_ScanList_t *ScanList_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((Handle == 0) || (ScanList_p == NULL) ) { return ST_ERROR_BAD_PARAMETER; } /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromHandle(Handle); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* Copy the scan list for the caller */ ScanList_p->NumElements = Tuner_p->ScanList.NumElements; memcpy(ScanList_p->ScanList, Tuner_p->ScanList.ScanList, (Tuner_p->ScanList.NumElements * sizeof(STTUNER_Scan_t))); } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_GetScanList() *//*****************************************************************************Name: STTUNER_GetStatus()Description: Obtains the current status of driver i.e., whether the tuner is locked, unlocked, scanning or failed.Parameters: Handle, the handle of the tuner device.Return Value: ST_NO_ERROR, the operation was carried out without error ST_ERROR_INVALID_HANDLE, the handle was invalid ST_ERROR_BAD_PARAMETER Handle or Status_p NULLSee Also: Nothing.*****************************************************************************/ST_ErrorCode_t STTUNER_GetStatus(STTUNER_Handle_t Handle, STTUNER_Status_t *Status_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((Handle == 0) || (Status_p == NULL) ) { return ST_ERROR_BAD_PARAMETER; } /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromHandle(Handle); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* Set the status for the caller */ *Status_p = Tuner_p->TunerInfo.Status; } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_GetStatus() *//*****************************************************************************Name: STTUNER_GetTunerInfo()Description: Obtains the current scanning status, even during a scan.Parameters: Handle, the handle of the tuner device.Return Value: ST_NO_ERROR, the operation was carried out without error ST_ERROR_INVALID_HANDLE, the handle was invalid ST_ERROR_BAD_PARAMETER Handle or TunerInfo_p NULLSee Also: Nothing.*****************************************************************************/ST_ErrorCode_t STTUNER_GetTunerInfo(STTUNER_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((Handle == 0) || (TunerInfo_p == NULL) ) { return ST_ERROR_BAD_PARAMETER;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -