?? tuner.c
字號:
if (Tuner_p->BandList.BandList != NULL) memory_deallocate((partition_t *)Tuner_p->InitParams.DriverPartition, Tuner_p->BandList.BandList ); if (Tuner_p->ThresholdList.ThresholdList != NULL) memory_deallocate((partition_t *)Tuner_p->InitParams.DriverPartition, Tuner_p->ThresholdList.ThresholdList ); if (Tuner_p->ThresholdHits != NULL) memory_deallocate((partition_t *)Tuner_p->InitParams.DriverPartition, Tuner_p->ThresholdHits ); /* Terminate TNR device */ Error = TNR_Term(Tuner_p->TunerHandle); if (Error == TUNER_NO_ERROR) { /* Terminate DEMOD device */ Error = DEMOD_Term(Tuner_p->DemodHandle); /* Terminate SAT device */ if (Error == TUNER_NO_ERROR) Error = SAT_Term(Tuner_p->SatHandle); } return Error;} /* TUNER_Term() *//*****************************************************************************Name: TUNER_AbortScan()Description: This routine will abort the current scan step. NOTE: This call will block until it is able to safely abort the current scan operation -- a callback may be invoked if the caller has set one up.Parameters: Tuner_p, pointer to the tuner control block.Return Value: TUNER_NO_ERROR, the operation completed without error.See Also: Nothing.*****************************************************************************/TUNER_ErrorCode_t TUNER_AbortScan(TUNER_ControlBlock_t *Tuner_p){ TUNER_ErrorCode_t Error = TUNER_NO_ERROR; /* Lock out the scan task whilst we modify the status code. */ semaphore_wait(&Tuner_p->ScanTask.GuardSemaphore); /* Forcibly unlock the tuner */ Tuner_p->TunerInfo.Status = STTUNER_STATUS_UNLOCKED; LNBPowerDown(Tuner_p); /* Try to power down LNB */ /* Release semaphore -- allows scan task to resume */ semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore); return Error;} /* TUNER_AbortScan() *//*****************************************************************************Name: TUNER_StartScan()Description: This routine will commence a new scan based on the current scan list. The scan list is first examined to ensure it is valid, if not an error is generated. If the scan list is ok, the scan task is awoken and the first scan step will be started. NOTE: If a scan is already in progress, the current scan will be aborted and re-started at the next available opportunity.Parameters: Tuner_p, pointer to the tuner control block.Return Value: TUNER_ERROR_BAD_PARAMETER, the scan list is invalid. TUNER_NO_ERROR, the operation completed without error.See Also: Nothing.*****************************************************************************/TUNER_ErrorCode_t TUNER_StartScan(TUNER_ControlBlock_t *Tuner_p){ TUNER_ErrorCode_t Error = TUNER_NO_ERROR; U32 SymbolMin, i; STTUNER_Scan_t *Scan_p; /* Wakeup the scan task and lock out the scan task whilst * we modify the status code. */ semaphore_wait(&Tuner_p->ScanTask.GuardSemaphore); semaphore_signal(&Tuner_p->ScanTask.TimeoutSemaphore); /* Set the scan status and reset the scan element pointer */ Tuner_p->TunerInfo.Status = STTUNER_STATUS_SCANNING; /* First calculate the minimum symbol rate for the scan */ SymbolMin = ((U32)~0); Scan_p = Tuner_p->ScanList.ScanList; for (i = 0; i < Tuner_p->ScanList.NumElements; i++, Scan_p++) { if (Scan_p->SymbolRate < SymbolMin) SymbolMin = Scan_p->SymbolRate; } /* Store the minimum symbol width for future reference */ Tuner_p->SymbolWidthMin = ((SymbolMin / 1000) * SCALED_DIG_ROLL_OFF) / (DIG_ROLL_OFF_SCALING); /* Set frequency step to default */ Tuner_p->ScanInfo.FrequencyStep = (Tuner_p->SymbolWidthMin / 2); /* Setup scan parameters is we're using the scan list */ if (!Tuner_p->ScanExact) { Tuner_p->ScanInfo.Scan_p = Tuner_p->ScanList.ScanList; Tuner_p->ScanInfo.ScanIndex = 0; Tuner_p->ScanInfo.NextFrequency = Tuner_p->ScanInfo.FrequencyStart; Tuner_p->ScanInfo.PlrMask = STTUNER_PLR_HORIZONTAL; /* H first */ /* Find out what polarizations are in use */ Tuner_p->PolarizationMask = 0; for (i = 0, Scan_p = Tuner_p->ScanList.ScanList; i < Tuner_p->ScanList.NumElements; i++, Scan_p++) { Tuner_p->PolarizationMask |= Scan_p->Polarization; } } else { /* We only have one scan parameter for an exact scan */ Tuner_p->ScanInfo.Scan_p = &Tuner_p->SingleScan; Tuner_p->ScanInfo.PlrMask = Tuner_p->ScanInfo.Scan_p->Polarization; Tuner_p->ScanInfo.NextFrequency = Tuner_p->ScanInfo.FrequencyStart; Tuner_p->PolarizationMask = Tuner_p->ScanInfo.Scan_p->Polarization; Tuner_p->FECRates = Tuner_p->ScanInfo.Scan_p->FECRates; } /* Ensure polarization mask is within device capabilities */ Tuner_p->PolarizationMask &= Tuner_p->Capability.Polarization; /* Release semaphore -- allows scan task to resume */ semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore); return Error;} /* TUNER_StartScan() *//*****************************************************************************Name: TUNER_ContinueScan()Description: This routine will proceed to the next scan step in the scan list. The scan task must be in the "not found" or "locked" state in order for this call to succeed, otherwise an error will be returned. NOTE: If the end of the scan list has been encountered, then a call to TUNER_StartScan() must be done.Parameters: Tuner_p, pointer to the tuner control block.Return Value: TUNER_ERROR_BAD_PARAMETER, invalid scan status, or end of scan list. TUNER_NO_ERROR, the operation completed without error.See Also: TUNER_StartScan()*****************************************************************************/TUNER_ErrorCode_t TUNER_ContinueScan(TUNER_ControlBlock_t *Tuner_p){ TUNER_ErrorCode_t Error = TUNER_NO_ERROR; /* Wakeup the scan task and lock out the scan task whilst * we modify the status code. */ semaphore_wait(&Tuner_p->ScanTask.GuardSemaphore); semaphore_signal(&Tuner_p->ScanTask.TimeoutSemaphore); /* A scan may only be continued if the current scan status is * "locked" or "unlocked". i.e., "not found" implies the end * of the frequency range has been encountered or a scan has not * yet started. "scanning" implies the current scan step has * not yet completed, therefore it doesn't make sense to * continue yet. */ if ((Tuner_p->TunerInfo.Status == STTUNER_STATUS_LOCKED || Tuner_p->TunerInfo.Status == STTUNER_STATUS_UNLOCKED)) { /* The last scan was successful -- so a bigger step * can be calculated. */ if (Tuner_p->TunerInfo.Status == STTUNER_STATUS_LOCKED) { U32 FrequencyStep, SymbolLocked; /* Get the current locked symbol rate (Khz) */ SymbolLocked = Tuner_p->ScanInfo.Scan_p->SymbolRate / 1000; /* Calculate new step size */ FrequencyStep = SymbolLocked * SCALED_DIG_ROLL_OFF / (2 * DIG_ROLL_OFF_SCALING) + (Tuner_p->SymbolWidthMin / 2); /* Set the new frequency step to be post incremented */ Tuner_p->ScanInfo.FrequencyStep = FrequencyStep; } /* Continue at the next frequency step */ Tuner_p->ScanInfo.ScanIndex = Tuner_p->ScanList.NumElements; Tuner_p->TunerInfo.Status = STTUNER_STATUS_SCANNING; } else { /* Unable to continue the scan -- the scan task is in the wrong * state or the we've reached the end of the scan list. */ Error = TUNER_ERROR_BAD_PARAMETER; } /* Release semaphore -- allows scan task to resume */ semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore); return Error;} /* TUNER_ContinueScan() *//* Private functions ------------------------------------------------------- *//*****************************************************************************Name: GetCapability()Description: This routine interrogates the low-level API to establish the capabilites of the tuner system. The information is copied into the capability member of the tuner control block structure. NOTE: Must be called after all interfaces have been initialized.Parameters: Tuner_p, pointer to a tuner control block.Return Value: Nothing.See Also: Nothing.*****************************************************************************/static void GetCapability(TUNER_ControlBlock_t *Tuner_p){ DEMOD_Capability_t *DemodCaps_p; SAT_Capability_t *SatCaps_p; STTUNER_Capability_t *Caps_p; /* Set up pointers to capability structures */ DemodCaps_p = &Tuner_p->DEMODCapability; SatCaps_p = &Tuner_p->SatCapability; Caps_p = &Tuner_p->Capability; /* Ascertain device type */ Caps_p->Device = Tuner_p->InitParams.Device; /* Ascertain demod type */ Caps_p->DemodType = Tuner_p->InitParams.DemodType; /* Ascertain tuner type */ Caps_p->TunerType = Tuner_p->InitParams.TunerType; /* Ascertain modulation capabilities (DEMOD) */ Caps_p->Modulation = DemodCaps_p->ModulationAvail; /* Ascertain puncture rates (DEMOD) */ Caps_p->FECRates = DemodCaps_p->FECAvail; /* Ascertain AGC control caps (DEMOD) */ Caps_p->AGCControl = DemodCaps_p->AGCControl; /* Ascertain symbol rate (DEMOD) */ Caps_p->SymbolMin = DemodCaps_p->SymbolMin; Caps_p->SymbolMax = DemodCaps_p->SymbolMax; /* Ascertain polarization modes (SAT) */ Caps_p->Polarization = SatCaps_p->PolarizationSelect; /* Measurement settings */ Caps_p->BerMax = MAX_BER; Caps_p->SignalQualityMax = MAX_SIGNAL_QUALITY; Caps_p->AgcMax = MAX_AGC;} /* GetCapability() *//*****************************************************************************Name: ScanTask()Description: This routine should be run in its own thread of execution e.g., OS task. It is responsible for managing the process of a tuner scan based on the current working scan list. The scan task is a state machine that may be in any one of the following states: a) "scanning" -- tuner is currently scanning for a signal b) "locked" -- tuner is locked to a valid signal c) "unlocked" -- tuner is not locked d) "not found" -- the last scan failedParameters: Tuner_p, a pointer to a tuner control block structure.Return Value: Nothing.See Also: TUNER_AbortScan() TUNER_StartScan() TUNER_ContinueScan()*****************************************************************************/static void ScanTask(TUNER_ControlBlock_t *Tuner_p){ clock_t clk; STTUNER_EventType_t Event; TUNER_ErrorCode_t Error = TUNER_NO_ERROR; for (;;) { /* Calculate wake-up time for next scan process */ clk = time_plus(time_now(), ((ST_GetClocksPerSecond() * Tuner_p->ScanTask.TimeoutDelayMs)/ 1000)); /* Delay until either we're awoken or the wake-up time comes */ semaphore_wait_timeout(&Tuner_p->ScanTask.TimeoutSemaphore, &clk); /* We are about to enter a critical section of code -- we must not * allow external interruptions whilst checking the scan status, etc. */ semaphore_wait(&Tuner_p->ScanTask.GuardSemaphore); /* If the driver is being terminated then this flag will be set * to TRUE -- we should cleanly exit the task. */ if (Tuner_p->ScanTask.DeleteTask) { semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore); break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -