function set_param(this, p, v)
% SET_PARAM  Set the value of an HDL Coder parameter. Also works for other
% configset parameters.

%   Copyright 2013-2016 The MathWorks, Inc.

cli = this.CLI;
if isempty(cli)  
    this.createCLI;
    cli = this.CLI;
end

if ~isempty(cli) && isprop(cli, p)  % if CLI has not been created yet
    if this.hasDownstreamIntegrationDriver && ismember(p, downstream.DownstreamIntegrationDriver.DownstreamParameterNames)
        % If this is a parameter that belongs to the
        % DownstreamIntegrationDriver (currently just parameters on the
        % Target pane), set the parameter value on the
        % DownstreamIntegrationDriver first. This will do proper validation
        % and update any dependent settings (e.g. changing tool will update
        % device settings)
        %
        % Ideally, these dependent setting updates would happen directly at
        % the CLI level. But right now the CLI only stores a flat list of
        % parameters and does very basic validation. Due to legacy behavior
        % of hdlset_param, which accepts parameter updates in any order,
        % updating this at the CLI level would cause backwards
        % compatibility issues
        hDI = this.getDownstreamIntegrationDriver;
        hDI.openTransaction;
        optionID = hDI.getCorrespondingOptionID(p);
        hDI.set(optionID, v);

        % After updating parameters on the DownstreamIntegrationDriver,
        % this method will apply all newly updated parameters to the CLI
        hDI.syncWithConfigSet(cli);
    else
        % Just set the individual parameter on the CLI
        this.CLI.(p) = v;
    end
    
    if ( ~isempty(this.Components) )  % mannamal: c1514243
        set_param(gcs, 'Dirty', 'on')
    end
else
    % Parameter is not in the CLI object. Use the configset set_param
    % method.  It could be a UDD param in hdlcc.
    pConfigSet = this.getParent;
    pConfigSet.set_param(p, v);
end
