Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_hfo.c
/***************************************************************************/
/**
 *
 *  HfoBinCoarseTune - Coarse tune HFO and return its frequency.
 *
 *  @param ui32Window The +/- tolerance for success.
 *  @param ui32NumSamples How many samples to average for getting frequency.
 *  @param ui32Timeout Number of calibration cycles after which the algorithm
 *                     gives up.
 *  @return The HFO frequency.
 *
 ******************************************************************************/
Coarse tune HFO and return its frequency.
@param ui32Window The +/- tolerance for success.
@param ui32NumSamples How many samples to average for getting frequency.
@param ui32Timeout Number of calibration cycles after which the algorithm
gives up.
@return The HFO frequency.
Coarse tune HFO and return its frequency . @param ui32Window The + / - tolerance for success . @param ui32NumSamples How many samples to average for getting frequency . @param ui32Timeout Number of calibration cycles after which the algorithm gives up . @return The HFO frequency .
static uint32_t
HfoBinCoarseTune(uint32_t ui32Window,
                 uint32_t ui32NumSamples,
                 uint32_t ui32Timeout)
{
    uint32_t ui32Count     = 0;
    uint32_t ui32HfoFreq   = 0;
    uint8_t ui8TrimMax     = 0xFF >> 2;
    uint8_t ui8TrimMin     = 0;
    uint8_t ui8TrimMean    = 0x80 >> 2;
    uint32_t ui32UpWindow  = (244 + ui32Window);
    uint32_t ui32LowWindow = (244 - ui32Window);
     Write new trim and get new frequency.
    TrimSet((ui8TrimMean << 2), 0);
    ui32HfoFreq = FreqGet(ui32NumSamples);
     Use a binary search strategy to set trim until the frequency within
     ui32Window.
    while((ui32HfoFreq > ui32UpWindow) | (ui32HfoFreq < ui32LowWindow))
    {
        if(ui32HfoFreq > ui32UpWindow)
        {
            ui8TrimMin = ui8TrimMean;
        }
        else
        {
            ui8TrimMax = ui8TrimMean;
        }
        ui8TrimMean = ((ui8TrimMax + ui8TrimMin) >> 1);  div by 2
         Write new trim and get new frequency.
        TrimSet((ui8TrimMean << 2), 0);
        ui32HfoFreq = FreqGet(ui32NumSamples);
         Stop if maximum number of loop iterations.
        if(++ui32Count >= ui32Timeout)
        {
            break;
        }
    }
     Return the HFO frequency.
    return(ui32HfoFreq);
}
static uint32_t HfoBinCoarseTune ( uint32_t ui32Window , uint32_t ui32NumSamples , uint32_t ui32Timeout ) { uint32_t ui32Count = 0 ; uint32_t ui32HfoFreq = 0 ; uint8_t ui8TrimMax = 0xFF >> 2 ; uint8_t ui8TrimMin = 0 ; uint8_t ui8TrimMean = 0x80 >> 2 ; uint32_t ui32UpWindow = ( 244 + ui32Window ) ; uint32_t ui32LowWindow = ( 244 - ui32Window ) ; TrimSet ( ( ui8TrimMean << 2 ) , 0 ) ; ui32HfoFreq = FreqGet ( ui32NumSamples ) ; while ( ( ui32HfoFreq > ui32UpWindow ) | ( ui32HfoFreq < ui32LowWindow ) ) { if ( ui32HfoFreq > ui32UpWindow ) { ui8TrimMin = ui8TrimMean ; } else { ui8TrimMax = ui8TrimMean ; } ui8TrimMean = ( ( ui8TrimMax + ui8TrimMin ) >> 1 ) ; TrimSet ( ( ui8TrimMean << 2 ) , 0 ) ; ui32HfoFreq = FreqGet ( ui32NumSamples ) ; if ( ++ ui32Count >= ui32Timeout ) { break ; } } return ( ui32HfoFreq ) ; }
HfoBinCoarseTune - Coarse tune HFO and return its frequency.
HfoBinCoarseTune - Coarse tune HFO and return its frequency .
// // Write new trim and get new frequency. // // // Use a binary search strategy to set trim until the frequency within // ui32Window. // // div by 2 // // Write new trim and get new frequency. // // // Stop if maximum number of loop iterations. // // // Return the HFO frequency. //