Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_hfo.c
/***************************************************************************/
/**
 *
 *  HfoLinFineTune - Fine 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.
 *  @param ui32Check Clock gates the HFO before each trim adjustment
 *                     gives up.
 *  @return Return its frequency.
 *
 ******************************************************************************/
Fine 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.
@param ui32Check Clock gates the HFO before each trim adjustment
gives up.
@return Return its frequency.
Fine 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 . @param ui32Check Clock gates the HFO before each trim adjustment gives up . @return Return its frequency .
static uint32_t
HfoLinFineTune(uint32_t ui32Window, uint32_t ui32NumSamples,
               uint32_t ui32Timeout, uint32_t ui32Check)
{
    uint32_t ui32Count = 0;
    uint8_t  ui8Trim = TrimGet();
    uint32_t ui32HfoFreq = FreqGet(ui32NumSamples);
    uint32_t ui32UpWindow = (244 + ui32Window);
    uint32_t ui32LowWindow = (244 - ui32Window);
    if ((ui8Trim < 128) && (ui8Trim > 80))
    {
        ui8Trim += 48;
        TrimSet(ui8Trim, ui32Check);
        ui32HfoFreq = FreqGet(ui32NumSamples);
    }
     Adjust trim in single steps until frequency is within ui32Window.
    while((ui32HfoFreq > ui32UpWindow) | (ui32HfoFreq < ui32LowWindow))
    {
         Be sure to check for overflow/underflow.
        if(ui32HfoFreq > 244)
        {
            if(ui8Trim != 0xFF)
            {
                ui8Trim += ((ui8Trim & 0x3) == 0x1) + 1;
            }
        }
        else
        {
            if(ui8Trim != 0x00)
            {
                ui8Trim -= ((ui8Trim & 0x3) == 0x2) + 1;
            }
        }
        if ((ui8Trim < 128) && (ui8Trim > 80))
        {
            ui8Trim += 48;
        }
         Write new trim and get new frequency.
        TrimSet(ui8Trim, ui32Check);
        ui32HfoFreq = FreqGet(ui32NumSamples);
         Stop if maximum number of loop iterations.
        if(++ui32Count >= ui32Timeout)
        {
            break;
        }
    }
     Return the HFO frequency.
    return(ui32HfoFreq);
}
static uint32_t HfoLinFineTune ( uint32_t ui32Window , uint32_t ui32NumSamples , uint32_t ui32Timeout , uint32_t ui32Check ) { uint32_t ui32Count = 0 ; uint8_t ui8Trim = TrimGet ( ) ; uint32_t ui32HfoFreq = FreqGet ( ui32NumSamples ) ; uint32_t ui32UpWindow = ( 244 + ui32Window ) ; uint32_t ui32LowWindow = ( 244 - ui32Window ) ; if ( ( ui8Trim < 128 ) && ( ui8Trim > 80 ) ) { ui8Trim += 48 ; TrimSet ( ui8Trim , ui32Check ) ; ui32HfoFreq = FreqGet ( ui32NumSamples ) ; } while ( ( ui32HfoFreq > ui32UpWindow ) | ( ui32HfoFreq < ui32LowWindow ) ) { if ( ui32HfoFreq > 244 ) { if ( ui8Trim != 0xFF ) { ui8Trim += ( ( ui8Trim & 0x3 ) == 0x1 ) + 1 ; } } else { if ( ui8Trim != 0x00 ) { ui8Trim -= ( ( ui8Trim & 0x3 ) == 0x2 ) + 1 ; } } if ( ( ui8Trim < 128 ) && ( ui8Trim > 80 ) ) { ui8Trim += 48 ; } TrimSet ( ui8Trim , ui32Check ) ; ui32HfoFreq = FreqGet ( ui32NumSamples ) ; if ( ++ ui32Count >= ui32Timeout ) { break ; } } return ( ui32HfoFreq ) ; }
HfoLinFineTune - Fine tune HFO and return its frequency.
HfoLinFineTune - Fine tune HFO and return its frequency .
// We don't want to be within values between 80 and 128 // // Adjust trim in single steps until frequency is within ui32Window. // // // Be sure to check for overflow/underflow. // // We don't want to be within values between 80 and 128 // // Write new trim and get new frequency. // // // Stop if maximum number of loop iterations. // // // Return the HFO frequency. //