
%

%   Copyright 2015-2021 The MathWorks, Inc.

classdef (Abstract) Plugin_Tcl_Libero < handle
    % Libero Tcl generation functions

    methods( Static )
        function getTclPortInterfaceConnection(fid,topSmartDesign,topModuleInstance,clockPinConnection,resetPinConnection,interfaceName)
            fprintf(fid,'sd_connect_pins -sd_name {%s} -pin_names {"%s" "%s:%s"} \n',topSmartDesign,clockPinConnection, ...
                topModuleInstance,[interfaceName '_ACLK']);
            fprintf(fid,'sd_connect_pins -sd_name {%s} -pin_names {"%s" "%s:%s"} \n',topSmartDesign,resetPinConnection, ...
                topModuleInstance,[interfaceName '_ARESETN']);
        end

        function getTclGenerateComponent(fid,topSmartDesign)
            fprintf(fid,'save_smartdesign -sd_name {%s\n', [topSmartDesign '_MSS}']);
            fprintf(fid,'generate_component -component_name {%s -recursive 0 \n',[topSmartDesign '_MSS}']);
        end

        function getTclHdlIPInterfaceConnection(fid,topSmartDesign,topModuleInstance,masterConnection,interfaceName)
            masterConnection = strrep(masterConnection,'/',':');
            fprintf(fid,'sd_connect_pins -sd_name {%s} -pin_names {"%s:%s" "%s"} \n',topSmartDesign, ...
                topModuleInstance,interfaceName,masterConnection);
        end

        function getTclAddBusInterfaceDefn(fid,hdlCoreName,bifDefination,bifName)
                fprintf(fid,'hdl_core_add_bif -hdl_core_name %s -bif_definition {AXI4:AMBA:AMBA4:%s} -bif_name %s\n',hdlCoreName, ...
                    bifDefination,bifName);
        end

        function getTclAddBusInterfaceSignals(fid,hdlCoreName,bifName,bifSignalName,coreSignalName)
            fprintf(fid,'hdl_core_assign_bif_signal -hdl_core_name %s -bif_name %s -bif_signal_name %s -core_signal_name %s \n', ...
                hdlCoreName,bifName,bifSignalName,coreSignalName);
        end

        function getTclCreateNewProject(fid,prjLocation,prjName,targetLanguage,family,die,package,speed)
            fprintf(fid, ['new_project -location {./%s} -name {%s} -project_description {} -block_mode 0 ' ...
                ['-standalone_peripheral_initialization 0 -instantiate_in_smartdesign 1 -ondemand_build_dh 1' ...
                ' -hdl {%s} -family {%s} -die {%s} -package {%s} -speed {%s} \n' ...
                ]],prjLocation,prjName, targetLanguage,family,die,package,speed);
        end

        function getTclCreateClockConstraint(fid, clkName,clkFreq)
            % generate a clock constraint
            period = (1/clkFreq)*1000;  %period is in ns, clkFreq in MHz
            fprintf(fid, 'create_clock -name {%s}  -period %0.3f\n',clkName, period);

        end
    end
end
