function ret = autosetPLL(hObj, reg, maxclk)
%CALCCLOCKSPEED Set the state of the auto-detect

% Copyright 2013-2017 The MathWorks, Inc.


ret = '0';
if codertarget.target.isCoderTarget(hObj.getConfigSet())
    data = codertarget.data.getParameterValue(hObj, 'Clocking');
    cs  = hObj.getConfigSet();
    tgt_data = codertarget.targethardware.getTargetHardware(cs);
    if (data.AutoSetPllSettings)
        cpu_clock_freq = str2double(data.cpuClockRateMHz);
        if ischar(data.OSCCLK)
            osc_freq = str2num(data.OSCCLK);     %#ok<ST2NM>
        else
            osc_freq = data.OSCCLK;
        end
        [~, closest_pllcr, closest_clkin_div] = autoSetPLLSettings(cpu_clock_freq, osc_freq, tgt_data.SubFamily, maxclk);
        closest_clkin_div = ['(OSCCLK * PLLCR)/' num2str(closest_clkin_div)];
    else
        closest_pllcr = data.PLLCR;
        closest_clkin_div = data.DIVSEL;
    end
    if strcmpi(reg, 'PLLCR')
        ret = num2str(closest_pllcr);
    elseif strcmpi(reg, 'DIVSEL')
        ret = closest_clkin_div;
    end
end
end