?? sttuner.c
字號:
} /* Obtain the control block from the handle */ Tuner_p = GetControlBlockFromHandle(Handle); /* Ensure the handle is valid */ if (Tuner_p != NULL) { /* Copy the current tuner information to the user */ *TunerInfo_p = Tuner_p->TunerInfo; } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_GetTunerInfo() *//*****************************************************************************Name: STTUNER_GetThresholdList()Description: Obtains the ordered threshold list that contain the high/low signal quality thresholds for notifying signal quality change events.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 ThresholdList_p or QualityFormat_p NULLSee Also: STTUNER_SetScanList()*****************************************************************************/ST_ErrorCode_t STTUNER_GetThresholdList(STTUNER_Handle_t Handle, STTUNER_ThresholdList_t *ThresholdList_p, STTUNER_QualityFormat_t *QualityFormat_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((Handle == 0) || (ThresholdList_p == NULL) || (QualityFormat_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 information for the caller */ ThresholdList_p->NumElements = Tuner_p->ThresholdList.NumElements; memcpy(ThresholdList_p->ThresholdList, Tuner_p->ThresholdList.ThresholdList, (Tuner_p->ThresholdList.NumElements * sizeof(STTUNER_SignalThreshold_t))); *QualityFormat_p = Tuner_p->QualityFormat; } else { /* The handle is invalid */ Error = ST_ERROR_INVALID_HANDLE; } /* Common exit point */ return Error;} /* STTUNER_GetThresholdList() *//*****************************************************************************Name: STTUNER_Init()Description: Initializes the tuner device.Parameters: DeviceName, the tuner device name as set during initialization. InitParams_p, the initialization parameters.Return Value: ST_NO_ERROR, the operation was carried out without error. ST_ERROR_ALREADY_INITIALIZED, the device has already been initialized. ST_ERROR_BAD_PARAMETER, one or more parameters was invalid. STTUNER_ERROR_LNB_HW a hardware error in the LNB circuit. ST_ERROR_NO_MEMORY, not used -- no memory allocation. STI2C_ERROR_LINE_STATE, I2C initialization failed.See Also: STTUNER_Term()*****************************************************************************/ST_ErrorCode_t STTUNER_Init( ST_DeviceName_t DeviceName, STTUNER_InitParams_t *InitParams_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ErrorCode_t TunerError; TUNER_ControlBlock_t *Tuner_p; BOOL InitMemory = FALSE; BOOL InitI2c = FALSE; /* Check the parameters */ if(InitParams_p == NULL) { return ST_ERROR_BAD_PARAMETER; } /* Ensure the tuner device is not already initialized */ if (!IsInit(DeviceName)) { /* Check the device name does not violate the maximum length */ if (strlen(DeviceName) <= ST_MAX_DEVICE_NAME) { /* Ensure device types are all supported */ if (InitParams_p->Device >= STTUNER_DEVICE_SATELLITE && InitParams_p->Device < STTUNER_DEVICE_UNKNOWN && InitParams_p->DemodType >= STTUNER_DEMOD_STV0199 && InitParams_p->DemodType < STTUNER_DEMOD_UNKNOWN && InitParams_p->TunerType >= STTUNER_TUNER_S68G21 && InitParams_p->TunerType < STTUNER_TUNER_UNKNOWN) { Node_t *New_p; /* Allocate required memory for new control block */ New_p = memory_allocate((partition_t *)InitParams_p->DriverPartition, sizeof(Node_t)); /* Ensure allocation was successful */ if (New_p != NULL) { STI2C_OpenParams_t I2cOpenParams; /* Flag memory as successfully allocated */ InitMemory = TRUE; /* Setup node information */ Tuner_p = (TUNER_ControlBlock_t *)New_p; /* Copy init params and device name */ Tuner_p->InitParams = *InitParams_p; strcpy(Tuner_p->DeviceName, DeviceName); /* Initialize the I2C interface */ I2cOpenParams.AddressType = STI2C_ADDRESS_7_BITS; I2cOpenParams.BusAccessTimeOut = 20; I2cOpenParams.I2cAddress = InitParams_p->I2CTunerAddress;#ifdef STTUNER_DEBUG_I2C STTBX_Print(("Device=%s Address=0x%02x\n", InitParams_p->I2CTunerDevice, I2cOpenParams.I2cAddress));#endif Error = STI2C_Open(InitParams_p->I2CTunerDevice, &I2cOpenParams, &Tuner_p->I2CTunerHandle);#ifdef STTUNER_DEBUG_I2C STTBX_Print(("Handle=%d\n", Tuner_p->I2CTunerHandle));#endif if (Error == ST_NO_ERROR) { /* Re-use old open parameters structure, but modify the address * to be used. */ I2cOpenParams.I2cAddress = InitParams_p->I2CDemodAddress;#ifdef STTUNER_DEBUG_I2C STTBX_Print(("Device=%s Address=0x%02x\n", InitParams_p->I2CDemodDevice, I2cOpenParams.I2cAddress));#endif Error = STI2C_Open(InitParams_p->I2CDemodDevice, &I2cOpenParams, &Tuner_p->I2CDemodHandle);#ifdef STTUNER_DEBUG_I2C STTBX_Print(("Handle=%d\n", Tuner_p->I2CDemodHandle));#endif } else { /* Clean-up previously allocated resources */ STI2C_Close(Tuner_p->I2CTunerHandle); } if (Error == ST_NO_ERROR) { /* Flag I2C as successfully setup */ InitI2c = TRUE; /* Initialize the hardware */ TunerError = TUNER_Init(Tuner_p, (STTUNER_InitParams_t *)InitParams_p); if (TunerError != TUNER_NO_ERROR) { /* Map tuner error to STAPI error */ Error = TunerError; } else { /* Finally, add the device to the device queue */ interrupt_lock(); /* Ensure queue changes are atomic */ /* Append new node */ AppendNode(DeviceQueue_p, New_p, Tuner_p); /* Check for first init. */ if (DeviceQueue_p == NULL) DeviceQueue_p = New_p; interrupt_unlock(); } } } else { /* Memory allocate error */ Error = ST_ERROR_NO_MEMORY; } } else { /* The required tuner device is not supported */ Error = ST_ERROR_FEATURE_NOT_SUPPORTED; } } else { /* The device name exceeds the maximum length limit */ Error = ST_ERROR_BAD_PARAMETER; } } else { /* The device is already initialized */ Error = ST_ERROR_ALREADY_INITIALIZED; } /* Tidy-up previously allocated resources if anything failed */ if (Error != ST_NO_ERROR) { if (InitI2c) /* Free I2C? */ { (void)STI2C_Close(Tuner_p->I2CTunerHandle); (void)STI2C_Close(Tuner_p->I2CDemodHandle); } if (InitMemory) /* Free memory? */ { memory_deallocate(InitParams_p->DriverPartition, Tuner_p); } } /* Common exit point */ return Error;} /* STTUNER_Init() *//*****************************************************************************Name: STTUNER_Open()Description:Parameters: DeviceName, the tuner device name as set during initialization.Return Value: ST_NO_ERROR, the operation was carried out without error. ST_ERROR_UNKNOWN_DEVICE, the device is not initialized. ST_ERROR_NO_FREE_HANDLES, the device is already open. ST_ERROR_BAD_PARAMETER OpenParams_p or Handle_p NULLSee Also: STTUNER_Close()*****************************************************************************/ST_ErrorCode_t STTUNER_Open(const ST_DeviceName_t DeviceName, const STTUNER_OpenParams_t *OpenParams_p, STTUNER_Handle_t *Handle_p){ ST_ErrorCode_t Error = ST_NO_ERROR; TUNER_ControlBlock_t *Tuner_p; /* Check the parameters */ if((OpenParams_p == NULL) || (Handle_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) { /* Ensure the device is not already open */ if (Tuner_p->Handle == 0) { /* Select some sensible defaults for the scan list and * band/lo list -- note that we do not need to worry about * mutual exclusion yet as the scan task must be idle. */ /* Copy the open params to the tuner control block */ Tuner_p->OpenParams = *OpenParams_p; /* Allocate the handle for the tuner -- we use the tuner * control block, as this will always give us a non-zero * value at this point. */ *Handle_p = Tuner_p->Handle = (STTUNER_Handle_t)Tuner_p; /* Try to open the event handler driver */ if (Tuner_p->InitParams.EVTDeviceName[0] != 0) { STEVT_OpenParams_t EVTOpenParams; Error = STEVT_Open(Tuner_p->InitParams.EVTDeviceName, &EVTOpenParams, &Tuner_p->EVTHandle); if (Error == ST_NO_ERROR) { if (STEVT_Register(Tuner_p->EVTHandle, STTUNER_EV_LOCKED, &Tuner_p->EvtId[EventToId(STTUNER_EV_LOCKED)] ) != ST_NO_ERROR || STEVT_Register(Tuner_p->EVTHandle, STTUNER_EV_UNLOCKED, &Tuner_p->EvtId[EventToId(STTUNER_EV_UNLOCKED)] ) != ST_NO_ERROR || STEVT_Register(Tuner_p->EVTHandle, STTUNER_EV_SCAN_FAILED, &Tuner_p->EvtId[EventToId(STTUNER_EV_SCAN_FAILED)] ) != ST_NO_ERROR || STEVT_Register(Tuner_p->EVTHandle, STTUNER_EV_TIMEOUT, &Tuner_p->EvtId[EventToId(STTUNER_EV_TIMEOUT)] ) != ST_NO_ERROR || STEVT_Register(Tuner_p->EVTHandle, STTUNER_EV_SIGNAL_CHANGE, &Tuner_p->EvtId[EventToId(STTUNER_EV_SIGNAL_CHANGE)] ) != ST_NO_ERROR ) { /* Event registration failed */ STEVT_Close(Tuner_p->EVTHandle); /* Close handle to EVT */ Error = STTUNER_ERROR_EVT_REGISTER; } } else { /* Event registration failed */ Error = STTUNER_ERROR_EVT_REGISTER; } } } else { /* The device is already open */ Error = ST_ERROR_NO_FREE_HANDLES; } } else { /* The device name is not recognised */ Error = ST_ERROR_UNKNOWN_DEVICE; } /* Common exit point */ return Error;} /* STTUNER_Open() *//*****************************************************************************Name: STTUNER_SetFrequency()Description: Scan for an exact frequency.Parameters: Handle, handle to sttuner device Frequency, required frequency to scan to ScanParams_p, scan settings to use during scan Timeout, timeout (in ms) to allow for lockReturn Value: ST_NO_ERROR, the operation was carried out without error. ST_ERROR_BAD_PARAMETER one or more params was invalid.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -