function runPostTargetValidation(this)
% Perform any cross parameter validations for reference design settings

% Copyright 2022-2023 The MathWorks, Inc.

% TODO: Return early if target settings were not changed
% hObj.CLI

hDI = this.getDownstreamIntegrationDriver;
if isempty(hDI)
    return;
end

if ~hDI.HasOpenTransaction
    % No need to run validation if none of the related settings are being
    % changed
    return;
end

if hdlwa.isWorkflowAdvisorOpenForModel(this.getModelName)
    % Do not validateTargetReferenceDesign again when HDLWA is already
    % open. HDLWA expects that the top-level settings in the downstream
    % integration driver (e.g. board, tool, ref design, etc.) are only
    % changed from within the HDLWA. With the in-canvas workflow, the
    % configset can also be used to change the downstream integration
    % driver settings. So when the HDLWA is open, we disable the top-level
    % settings from being edited in the configset. We also prevent
    % reloading existing top-level settings into the downstream integration
    % driver.
    % 
    % For example, calling "loadTopLevelSettings" will refresh the
    % reference design, which can affect the interface table. In
    % particular:
    % (1) Default register addresses (e.g. timestamp) allocated
    % during "validateInterfaceTable" can get erased.
    % (2) The default bus interface can get cleared, even though it was
    % already assigned. This will cause is to get resolved again later, but
    % to the first available address-based interface. This can cause an
    % issue if the previously assigned default bus interface (e.g. AXI4)
    % is not the first one in the list.
    return;
end

validateCell = {};

%% Validate reference design settings
if hDI.isIPWorkflow    
    if hDI.showReferenceDesignTasks
        validateCell = hDI.hIP.validateTargetReferenceDesign;
        
        if downstream.tool.hasErrorInValidateCell(validateCell)
            % Directly throw the error, which will prevent the configset from
            % closing until it is resolved
            downstream.tool.displayValidateCell(validateCell);
        end
    end
    % Adjust CDC enable
    validateCell{end+1} = hDI.hIP.adjustRegisterInterfaceCDCEnable; 
end

%% Update dependent DUT-level settings
try    
    hDI.updateInterfaceTable;    
catch ME    
    validateCell{end+1} = hdlvalidatestruct('Warning', ME.message, ME.identifier);
end
% filter out empty cell array elements
validateCell = downstream.tool.filterEmptyCell(validateCell);
%% Display messages
if isempty(validateCell)
    return;
end

% Display any warning messages to the Diagnostic Viewer (since we don't
% have a better place to display them)
modelName = this.getModelName;

hdlCoderStage = sldiagviewer.createStage('HDL Coder', ModelName=modelName); %#ok<NASGU>
downstream.tool.openDiagnosticViewer(modelName);

validationStage = sldiagviewer.createStage(message('HDLShared:hdldialog:ConfigsetTargetValidation').getString,...
    'ModelName', modelName); %#ok<NASGU>
downstream.tool.displayValidateCellToDiagnosticViewer(modelName, validateCell, false);
