src/occ_405/proc/proc_pstate.c
// Function Specification
//
// Name:  proc_freq2pstate
//
// Description:  Convert Frequency to Nearest Pstate
//
// End Function Specification
Function Specification
Name:  proc_freq2pstate

Convert Frequency to Nearest Pstate

End Function Specification
Function Specification Name : proc_freq2pstate Convert Frequency to Nearest Pstate End Function Specification
Pstate proc_freq2pstate(uint32_t i_freq_mhz)
{
    int8_t   l_pstate = 0;
    int8_t   l_temp_pstate = 0;
    int32_t  l_temp_freq_khz = 0;
    uint32_t l_freq_khz = 0;
    do
    {
        l_freq_khz = i_freq_mhz * 1000;
        if(l_freq_khz <= G_oppb.frequency_min_khz )
        {
            l_pstate = G_oppb.pstate_min;
            break;
        }
        if(i_freq_mhz < G_sysConfigData.sys_mode_freq.table[OCC_MODE_MIN_FREQUENCY])
        {
            l_freq_khz =  G_sysConfigData.sys_mode_freq.table[OCC_MODE_MIN_FREQUENCY] * 1000;
        }
        if(l_freq_khz < G_oppb.frequency_max_khz)
        {
            l_temp_freq_khz = G_oppb.frequency_max_khz - l_freq_khz;
            l_temp_pstate = l_temp_freq_khz / (int32_t) G_oppb.frequency_step_khz;
            l_pstate = PMAX + l_temp_pstate;
            if(l_pstate > G_oppb.pstate_min)
            {
                TRAC_ERR("proc_freq2pstate: Invalid calculated Pstate[%d] for freq[%dkHz] PGPE min Pstate[%d] freq[%dkHz]",
                          l_pstate, l_freq_khz, G_oppb.pstate_min, G_oppb.frequency_min_khz);
                l_pstate = G_oppb.pstate_min;
            }
        }
        else
        {
            l_pstate = PMAX;
        }
    }
    while(0);
    return (Pstate) l_pstate;
}
Pstate proc_freq2pstate ( uint32_t i_freq_mhz ) { int8_t l_pstate = 0 ; int8_t l_temp_pstate = 0 ; int32_t l_temp_freq_khz = 0 ; uint32_t l_freq_khz = 0 ; do { l_freq_khz = i_freq_mhz * 1000 ; if ( l_freq_khz <= G_oppb . frequency_min_khz ) { l_pstate = G_oppb . pstate_min ; break ; } if ( i_freq_mhz < G_sysConfigData . sys_mode_freq . table [ OCC_MODE_MIN_FREQUENCY ] ) { l_freq_khz = G_sysConfigData . sys_mode_freq . table [ OCC_MODE_MIN_FREQUENCY ] * 1000 ; } if ( l_freq_khz < G_oppb . frequency_max_khz ) { l_temp_freq_khz = G_oppb . frequency_max_khz - l_freq_khz ; l_temp_pstate = l_temp_freq_khz / ( int32_t ) G_oppb . frequency_step_khz ; l_pstate = PMAX + l_temp_pstate ; if ( l_pstate > G_oppb . pstate_min ) { TRAC_ERR ( " " , l_pstate , l_freq_khz , G_oppb . pstate_min , G_oppb . frequency_min_khz ) ; l_pstate = G_oppb . pstate_min ; } } else { l_pstate = PMAX ; } } while ( 0 ) ; return ( Pstate ) l_pstate ; }
Function Specification
Name:  proc_freq2pstate
Function Specification Name : proc_freq2pstate
// Freq Units need to be in kHz, not Mhz for the following calculations // Return Pmin if the frequency is below or equal to the min Freq for the lowest Pstate // First, calculate the delta between passed in freq, and Pmax // Next, calculate how many Pstate steps there are in that delta // Higher Pstates are lower frequency, add number of steps to the highest frequency Pstate // As an extra safety check make sure the calculated Pstate is not out of the PGPE range // this should never happen! // Freq is higher than or equal to the maximum frequency -- return Pmax