function IRInfo = getCompatibleTHWRData (modelName)
%GETCOMPATIBLETHRMDATA Returns the data in IRInfo format for backward compatibility

%   Copyright 2013-2024 The MathWorks, Inc.

cs = getActiveConfigSet(modelName);

data = codertarget.targethardware.getTargetHardware(cs);
ctd = codertarget.data.getData(cs);
Runtime_data = codertarget.data.getParameterValue(cs, 'Runtime');
if isfield(Runtime_data, 'DeviceID')
    IRInfo.sysinfo.tgtPrefs.chipInfo.deviceID = Runtime_data.DeviceID; % 'F2808';
else
    IRInfo.sysinfo.tgtPrefs.chipInfo.deviceID = data.DeviceID; % 'F2808';
end
IRInfo.sysinfo.tgtPrefs.chipInfo.subFamily= data.SubFamily; % '280x';

IRInfo.DSPchipLabel = lower(IRInfo.sysinfo.tgtPrefs.chipInfo.deviceID);
IRInfo.numIXbars = 0;
IRInfo.numOXbars = 0;
IRInfo.OverrunDetection = 0;
IRInfo.numADCs = 0;
IRInfo.numPWMs = 0;
IRInfo.numPWMXbars = 0;
IRInfo.numCANs = 0;
IRInfo.numCAPs = 0;
IRInfo.numCAPsOpModeeCAPHR = 0;
IRInfo.numHRCAPs = 0;
IRInfo.numCAPsOpModeeCAP = 0; %gives number of eCAP blocks with operating mode 'eCAP' used in Xbar
IRInfo.numQEPs = 0;
IRInfo.numRTDXs = 0;
IRInfo.numSCIs = 0;
IRInfo.numSPIs = 0;
IRInfo.numInterrupts = 0;
IRInfo.numSWInterrupts = 0;
IRInfo.numI2Cs = 0;
IRInfo.numIdleTasks = 0;
IRInfo.numLINs = 0;
IRInfo.numDMA = 0;
IRInfo.numEMIF = 0;
IRInfo.PWMblock16HRPWMmode = 0;
IRInfo.numTimers = 0;
IRInfo.numCLAs = 0;
IRInfo.numIPCs = 0;
IRInfo.numCpu1IPCs = 0;
IRInfo.numCpu2IPCs = 0;
IRInfo.numCLBs = 0;
IRInfo.numCLBXbars = 0;
IRInfo.newHWINTBlock = 0;
IRInfo.hasBaseRate = 1;
peripheralinModelref = 0;
IRInfo.HREnable = 0;
IRInfo.continuousCalibration = 0;
IRInfo.calibrationPeriod = 1.6;
IRInfo.outputTypeHR = [];
IRInfo.HRMode = [] ;
IRInfo.linkedePWM = [];
IRInfo.CMPALinkedePWM = [];
IRInfo.CMPBLinkedePWM = [];
IRInfo.CMPCLinkedePWM = [];
IRInfo.CMPDLinkedePWM = [];
IRInfo.ProcessingUnit = 'CPU1';

clocking = codertarget.data.getParameterValue(cs, 'Clocking');
IRInfo.cpuClkRate = str2double(clocking.ClosestCpuClock)* 1e6;

if isequal(get_param(modelName,'ModelReferenceTargetType'),'NONE')
    % Use the find_mdlrefs to get information related to the reference model
    % and register the same as part of resourcemanager
    modelHandle = get_param(modelName,'Handle');
    if ~codertarget.resourcemanager.isregistered(modelHandle, 'modelInfo', 'modelRefs')
        codertarget.resourcemanager.register(modelHandle, 'modelInfo', 'modelRefs', []);
	childModels =  find_mdlrefs(modelName,'ReturnTopModelAsLastElement', 1, ...
		'MatchFilter', @Simulink.match.codeCompileVariants);
        codertarget.resourcemanager.set(modelHandle, 'modelInfo', 'modelRefs', childModels);
    else
        childModels = codertarget.resourcemanager.get(modelHandle, 'modelInfo', 'modelRefs');
    end
    if ~isempty(childModels) && (length(childModels) > 1)
        for i = 1:length(childModels)-1
            buildDirStruct = RTW.getBuildDir(childModels{i});
            childModelFolder = fullfile(buildDirStruct.CodeGenFolder, buildDirStruct.ModelRefRelativeBuildDir);
            if isfile(fullfile(childModelFolder,'peripheralInfo.mat'))
                matfileData = load(fullfile(childModelFolder,'peripheralInfo.mat'));
                childmodelIRInfo{i} = matfileData.peripheralInfo; %#ok<AGROW> 
                peripheralinModelref = 1;
            end
        end
    end
end

%--------------------------------------------------------------------------
% ADC Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'ADC', 'numADCs', cs)
    IRInfo.numADCs = codertarget.resourcemanager.get('', 'ADC', 'numADCs', cs);
else
    IRInfo.numADCs = 0;
    IRInfo.ADC = [];
end
if codertarget.resourcemanager.isregistered('', 'ADC', 'ADCBlocks', cs)
    IRInfo.ADC = codertarget.resourcemanager.get('', 'ADC', 'ADCBlocks', cs);
    IRInfo.AnalogSubsys.ADCTrig    = codertarget.resourcemanager.get('','ADC','ADCTrig',cs);
    IRInfo.AnalogSubsys.ADCTrigCnt = codertarget.resourcemanager.get('','ADC','ADCTrigCount',cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'ADC')
            for j = 1:length(childmodelIRInfo{i}.ADC.ADCBlocks)
                IRInfo.ADC{end+1} = childmodelIRInfo{i}.ADC.ADCBlocks{j};
            end
            IRInfo.numADCs = IRInfo.numADCs + childmodelIRInfo{i}.ADC.numADCs;
        end
    end
end

%--------------------------------------------------------------------------
% CAP Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'CAP', 'numCAPs', cs)
    IRInfo.numCAPs = codertarget.resourcemanager.get('', 'CAP', 'numCAPs', cs);
else
    IRInfo.numCAPs = 0;
    IRInfo.CAP = [];
end
if codertarget.resourcemanager.isregistered('', 'CAP', 'CAPBlocks', cs)
    IRInfo.CAP = codertarget.resourcemanager.get('', 'CAP', 'CAPBlocks', cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'CAP')
            for j = 1:length(childmodelIRInfo{i}.CAP.CAPBlocks)
                IRInfo.CAP{end+1} = childmodelIRInfo{i}.CAP.CAPBlocks{j};
            end
            IRInfo.numCAPs = IRInfo.numCAPs + childmodelIRInfo{i}.CAP.numCAPs;
        end
    end
end

%getting number of CAP blocks with mode eCAP
numCAPsOpModeeCAP = 0;
numCAPsOpModeeCAPHR = 0;
for numBlocks = 1:IRInfo.numCAPs
    if isfield(IRInfo.CAP{1,numBlocks},'operatingMode') && isequal(IRInfo.CAP{1,numBlocks}.operatingMode,'eCAP')
        numCAPsOpModeeCAP = numCAPsOpModeeCAP + 1;
         if isfield(IRInfo.CAP{1,numBlocks},'HREnable') && isequal(IRInfo.CAP{1,numBlocks}.HREnable,'on')
            numCAPsOpModeeCAPHR = numCAPsOpModeeCAPHR + 1; 
         end
    end
end
IRInfo.numCAPsOpModeeCAP = numCAPsOpModeeCAP;
IRInfo.numCAPsOpModeeCAPHR = numCAPsOpModeeCAPHR;

%--------------------------------------------------------------------------
% HRCAP Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'HRCAP', 'numHRCAPs', cs)
    IRInfo.numHRCAPs = codertarget.resourcemanager.get('', 'HRCAP', 'numHRCAPs', cs);
end
if codertarget.resourcemanager.isregistered('', 'HRCAP', 'HRCAPMode', cs)
    IRInfo.HRMode = codertarget.resourcemanager.get('', 'HRCAP', 'HRCAPMode', cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'HRCAP')
            IRInfo.numHRCAPs = IRInfo.numHRCAPs + childmodelIRInfo{i}.HRCAP.numHRCAPs;
        end
    end
end


%--------------------------------------------------------------------------
% PWM Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'PWM', 'numPWMs', cs)
    IRInfo.numPWMs = codertarget.resourcemanager.get('', 'PWM', 'numPWMs', cs);
else
    IRInfo.numPWMs = 0;
    IRInfo.PWM = [];
end
if codertarget.resourcemanager.isregistered('', 'PWM', 'PWMBlocks', cs)
    IRInfo.PWM = codertarget.resourcemanager.get('', 'PWM', 'PWMBlocks', cs);
end
if codertarget.resourcemanager.isregistered('', 'PWM', 'HRPWMMode', cs)
    IRInfo.PWMblock16HRPWMmode = codertarget.resourcemanager.get('', 'PWM', 'HRPWMMode', cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'PWM')
            for j = 1:length(childmodelIRInfo{i}.PWM.PWMBlocks)
                IRInfo.PWM{end+1} = childmodelIRInfo{i}.PWM.PWMBlocks{j};
            end
            IRInfo.numPWMs = IRInfo.numPWMs + childmodelIRInfo{i}.PWM.numPWMs;
        end
    end
end

%updating all the Linked ePWM Info
%Checking if even one PWM has ePWMxLINKTBPRD field. If yes then that is
%ePWM Type1-4
if IRInfo.numPWMs>0 && isfield(IRInfo.PWM{1},'ePWMxLINKTBPRD') 
    for pwmidx = 1 : IRInfo.numPWMs
        if ~isequal(IRInfo.PWM{pwmidx}.ePWMxLINKTBPRD,'Not Linked')
            pwmModule = str2double(strtok(IRInfo.PWM{pwmidx}.ePWMxLINKTBPRD,'ePWM'));
            if isempty(IRInfo.linkedePWM)
                IRInfo.linkedePWM = pwmModule;
            else
                if ~ismember(IRInfo.linkedePWM,pwmModule)
                    IRInfo.linkedePWM = [IRInfo.linkedePWM pwmModule];
                end
            end
        end
    
        if ~isequal(IRInfo.PWM{pwmidx}.ePWMxLINKCMPA,'Not Linked')
            pwmModule = str2double(strtok(IRInfo.PWM{pwmidx}.ePWMxLINKCMPA,'ePWM'));
            if isempty(IRInfo.CMPALinkedePWM)
                IRInfo.CMPALinkedePWM = pwmModule;
            else
                if ~ismember(IRInfo.CMPALinkedePWM,pwmModule)
                    IRInfo.CMPALinkedePWM = [IRInfo.CMPALinkedePWM pwmModule];
                end
            end
        end
    
        if ~isequal(IRInfo.PWM{pwmidx}.ePWMxLINKCMPB,'Not Linked')
            pwmModule = str2double(strtok(IRInfo.PWM{pwmidx}.ePWMxLINKCMPB,'ePWM'));
            if isempty(IRInfo.CMPBLinkedePWM)
                IRInfo.CMPBLinkedePWM = pwmModule;
            else
                if ~ismember(IRInfo.CMPBLinkedePWM,pwmModule)
                    IRInfo.CMPBLinkedePWM = [IRInfo.CMPBLinkedePWM pwmModule];
                end
            end
        end
    	
        if ~isequal(IRInfo.PWM{pwmidx}.ePWMxLINKCMPC,'Not Linked')
            pwmModule = str2double(strtok(IRInfo.PWM{pwmidx}.ePWMxLINKCMPC,'ePWM'));
            if isempty(IRInfo.CMPCLinkedePWM)
                IRInfo.CMPCLinkedePWM = pwmModule;
            else
                if ~ismember(IRInfo.CMPCLinkedePWM,pwmModule)
                    IRInfo.CMPCLinkedePWM = [IRInfo.CMPCLinkedePWM pwmModule];
                end
            end
        end
    	
        if ~isequal(IRInfo.PWM{pwmidx}.ePWMxLINKCMPD,'Not Linked')
            pwmModule = str2double(strtok(IRInfo.PWM{pwmidx}.ePWMxLINKCMPD,'ePWM'));
            if isempty(IRInfo.CMPDLinkedePWM)
                IRInfo.CMPDLinkedePWM = pwmModule;
            else
                if ~ismember(IRInfo.CMPDLinkedePWM,pwmModule)
                    IRInfo.CMPDLinkedePWM = [IRInfo.CMPDLinkedePWM pwmModule];
                end
            end
        end
    end
end

%HRCAP_Cal() function
if IRInfo.numHRCAPs > 0 && isfield(IRInfo.HRMode,'High resolution')
    hrcapCalFcnName = 'MW_HRCAP_Calibration()';
    modelHandle = get_param(modelName,'Handle');
    %  re assignment of linked HRCAP at the end
    if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
        codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
        BlockInit = {};
    else
        BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
    end
    if ~isempty(BlockInit)
        isInitPresent = find(cellfun(@(p)strcmp(p,hrcapCalFcnName),BlockInit), 1);
    else
        isInitPresent = [];
    end
    if isempty(isInitPresent)
        BlockInit{end+1} = hrcapCalFcnName; %#ok<AGROW>
        codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
    end
end

% base rate related settings needed for soc
notCLAPU = true;
socCPUPU = false;
if isfield(ctd, 'ESB') && isfield(ctd.ESB, 'ProcessingUnit')
    pu = codertarget.data.getParameterValue(cs, 'ESB.ProcessingUnit');
    if contains(pu, 'CLA')
        notCLAPU = false;
    elseif contains(pu, 'CPU')
        isESBEnabled = codertarget.utils.isESBEnabled(modelName) && codertarget.utils.isTaskManagerFound(modelName);
        if isESBEnabled
            socCPUPU = true;
        end
    end
end

%unitStatus is present only for F281x and the TBSync function should not be called
%for this processor.
if IRInfo.numPWMs>0 && ~isfield(IRInfo.PWM{1},'unitStatus')
    if isequal(notCLAPU, false)
        pwmTBSyncFcnName = 'config_ePWM_TBSync_CLA()';
    else
    pwmTBSyncFcnName = 'config_ePWM_TBSync()';
    end
    modelHandle = get_param(modelName,'Handle');
    % place ePWM TBSync init and re assignment of linked ePWM at the end
    if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
        codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
        BlockInit = {};
    else
        BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
    end
    if peripheralinModelref
        for i = 1 : length(childmodelIRInfo)
            if isfield(childmodelIRInfo{i},'BlockInit')
                for j = 1:length(childmodelIRInfo{i}.BlockInit.BlockInitFcn)
                    BlockInit{end+1} = childmodelIRInfo{i}.BlockInit.BlockInitFcn{j}; %#ok<AGROW>
                end
            end
        end
    end
    isInitCLAPresent = [];
    isInitPresent = [];
    if ~isempty(BlockInit)
        isInitPresent = find(cellfun(@(p)strcmp(p,'config_ePWM_TBSync()'),BlockInit), 1);
        isInitCLAPresent = find(cellfun(@(p)strcmp(p,'config_ePWM_TBSync_CLA()'),BlockInit), 1);
    end            
    if isempty(isInitPresent) && isempty(isInitCLAPresent)
        BlockInit{end+1} = pwmTBSyncFcnName; %#ok<AGROW>
        codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
    end
end

%HRCAP scale factor calculation for Type-1
if IRInfo.numCAPs > 0
    if IRInfo.numCAPsOpModeeCAPHR > 0
        HRSFcName = 'HRCAPInterruptEnable()';
        modelHandle = get_param(modelName,'Handle');
        % place re assignment of HRCAP at the end
        if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
            codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
            BlockInit = {};
        else
            BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
        end
        if peripheralinModelref
            for i = 1 : length(childmodelIRInfo)
                if isfield(childmodelIRInfo{i},'BlockInit')
                    for j = 1:length(childmodelIRInfo{i}.BlockInit.BlockInitFcn)
                        BlockInit{end+1} = childmodelIRInfo{i}.BlockInit.BlockInitFcn{j}; %#ok<AGROW>
                    end
                end
            end
        end
        isInitPresent = [];
        if ~isempty(BlockInit)
            isInitPresent = find(cellfun(@(p)strcmp(p,HRSFcName),BlockInit), 1);
        end
        if isempty(isInitPresent)
            BlockInit{end+1} = HRSFcName; %#ok<AGROW>
            codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
        end
    end
end
%--------------------------------------------------------------------------
% PWM Xbar Module
%--------------------------------------------------------------------------
numPWMXbars = 0;
if isfield(ctd,'ePWM')
    paramName = 'ePWM';
    tag = 'EXBAR_TRIP4';
    if isfield(ctd.(paramName),tag)
        if isequal(data.SubFamily,'28p65x')
            validTRIPnum = [1:12, 14, 15];
        else
            validTRIPnum = [4 5 7 8 9 10 11 12];
        end
        for TRIPnum = validTRIPnum
            tag = ['EXBAR_TRIP' num2str(TRIPnum)];
            ePWMTrip = ctd.(paramName).(tag);
            if ~isequal(ePWMTrip,'Disable all')
                numPWMXbars = numPWMXbars + 1;
            end
        end
    end
end
IRInfo.numPWMXbars = numPWMXbars;

%--------------------------------------------------------------------------
% SCI Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'SCI', 'numSCIs', cs)
    IRInfo.numSCIs = codertarget.resourcemanager.get('', 'SCI', 'numSCIs', cs);
else
    IRInfo.numSCIs = 0;
end
if codertarget.resourcemanager.isregistered('', 'SCI', 'SCI', cs)
    IRInfo.SCI = codertarget.resourcemanager.get('', 'SCI', 'SCI', cs);
end
if codertarget.resourcemanager.isregistered('', 'SCI', 'SCI_PostInterrupt', cs)
    IRInfo.SCI_PostInterrupt = codertarget.resourcemanager.get('', 'SCI', 'SCI_PostInterrupt', cs);
end
if codertarget.resourcemanager.isregistered('', 'SCI', 'SCI_RxBlockingMode', cs)
    IRInfo.SCI_RxBlockingMode = codertarget.resourcemanager.get('', 'SCI', 'SCI_RxBlockingMode', cs);
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'SCI')
            if ~isfield(IRInfo,'SCI')
                for j = 1:2
                    IRInfo.SCI(j).module_A = 0;
                    IRInfo.SCI(j).module_B = 0;
                    IRInfo.SCI(j).module_C = 0;
                    IRInfo.SCI(j).module_D = 0;
                end
            end
            for j = 1:length(childmodelIRInfo{i}.SCI.SCI)
                IRInfo.SCI(j).module_A = IRInfo.SCI(j).module_A | childmodelIRInfo{i}.SCI.SCI(j).module_A;
                IRInfo.SCI(j).module_B = IRInfo.SCI(j).module_B | childmodelIRInfo{i}.SCI.SCI(j).module_B;
                IRInfo.SCI(j).module_C = IRInfo.SCI(j).module_C | childmodelIRInfo{i}.SCI.SCI(j).module_C;
                IRInfo.SCI(j).module_D = IRInfo.SCI(j).module_D | childmodelIRInfo{i}.SCI.SCI(j).module_D;
            end
            IRInfo.numSCIs = IRInfo.numSCIs + childmodelIRInfo{i}.SCI.numSCIs;
        end
        if isfield(childmodelIRInfo{i},'SCI') && isfield(childmodelIRInfo{i}.SCI,'SCI_PostInterrupt')
            if ~isfield(IRInfo,'SCI_PostInterrupt')
                for j = 1:2
                    IRInfo.SCI_PostInterrupt(j).module_A = 0;
                    IRInfo.SCI_PostInterrupt(j).module_B = 0;
                    IRInfo.SCI_PostInterrupt(j).module_C = 0;
                    IRInfo.SCI_PostInterrupt(j).module_D = 0;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_A = 0;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_B = 0;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_C = 0;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_D = 0;
                end
            end
            for j = 1:length(childmodelIRInfo{i}.SCI.SCI_PostInterrupt)
                if childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).module_A
                    IRInfo.SCI_PostInterrupt(j).module_A = 1;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_A = childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).fifoIntLevel_A;
                end
                if childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).module_B
                    IRInfo.SCI_PostInterrupt(j).module_B = 1;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_B = childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).fifoIntLevel_B;
                end
                if childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).module_C
                    IRInfo.SCI_PostInterrupt(j).module_C = 1;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_C = childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).fifoIntLevel_C;
                end
                if childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).module_D
                    IRInfo.SCI_PostInterrupt(j).module_D = 1;
                    IRInfo.SCI_PostInterrupt(j).fifoIntLevel_D = childmodelIRInfo{i}.SCI.SCI_PostInterrupt(j).fifoIntLevel_D;
                end
            end
        end
        if isfield(childmodelIRInfo{i},'SCI') && isfield(childmodelIRInfo{i}.SCI,'SCI_RxBlockingMode')
            if ~isfield(IRInfo,'SCI_RxBlockingMode')
                IRInfo.SCI_RxBlockingMode.isEnabled_A = 0;
                IRInfo.SCI_RxBlockingMode.isEnabled_B = 0;
                IRInfo.SCI_RxBlockingMode.isEnabled_C = 0;
                IRInfo.SCI_RxBlockingMode.isEnabled_D = 0;
                IRInfo.SCI_RxBlockingMode.timeout_A = 0;
                IRInfo.SCI_RxBlockingMode.timeout_B = 0;
                IRInfo.SCI_RxBlockingMode.timeout_C = 0;
                IRInfo.SCI_RxBlockingMode.timeout_D = 0;
            end
            if childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.isEnabled_A
                IRInfo.SCI_RxBlockingMode.isEnabled_A = 1;
                IRInfo.SCI_RxBlockingMode.timeout_A = childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.timeout_A;
            end
            if childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.isEnabled_B
                IRInfo.SCI_RxBlockingMode.isEnabled_B = 1;
                IRInfo.SCI_RxBlockingMode.timeout_B = childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.timeout_B;
            end
            if childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.isEnabled_C
                IRInfo.SCI_RxBlockingMode.isEnabled_C = 1;
                IRInfo.SCI_RxBlockingMode.timeout_C = childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.timeout_C;
            end
            if childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.isEnabled_D
                IRInfo.SCI_RxBlockingMode.isEnabled_D = 1;
                IRInfo.SCI_RxBlockingMode.timeout_D = childmodelIRInfo{i}.SCI.SCI_RxBlockingMode.timeout_D;
            end
        end
    end
end

%--------------------------------------------------------------------------
% CAN Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'CAN', 'numCANs', cs)
    IRInfo.numCANs = codertarget.resourcemanager.get('', 'CAN', 'numCANs', cs);
else
    IRInfo.numCANs = 0;
    IRInfo.CAN = [];
    IRInfo.eCAN.numCANModule = 0;
    IRInfo.eCAN.CANModule = [];
    IRInfo.eCAN.numOfMailboxInstanceA = zeros(1,32);
    IRInfo.eCAN.numOfMailboxInstanceB = zeros(1,32);
end
if codertarget.resourcemanager.isregistered('', 'CAN', 'CANBlocks', cs)
    IRInfo.CAN = codertarget.resourcemanager.get('', 'CAN', 'CANBlocks', cs);
end
if codertarget.resourcemanager.isregistered('', 'CAN', 'numCANModule', cs)
    IRInfo.eCAN.numCANModule = codertarget.resourcemanager.get('', 'CAN', 'numCANModule', cs);
end
if codertarget.resourcemanager.isregistered('', 'CAN', 'CANModule', cs)
    IRInfo.eCAN.CANModule = codertarget.resourcemanager.get('', 'CAN', 'CANModule', cs);
end
if codertarget.resourcemanager.isregistered('', 'CAN', 'numOfMailboxInstanceA', cs)
    IRInfo.eCAN.numOfMailboxInstanceA = codertarget.resourcemanager.get('', 'CAN', 'numOfMailboxInstanceA', cs);
end
if codertarget.resourcemanager.isregistered('', 'CAN', 'numOfMailboxInstanceB', cs)
    IRInfo.eCAN.numOfMailboxInstanceB = codertarget.resourcemanager.get('', 'CAN', 'numOfMailboxInstanceB', cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'CAN')
            IRInfo.numCANs = IRInfo.numCANs + childmodelIRInfo{i}.CAN.numCANs;
            for j = 1 : length(childmodelIRInfo{i}.CAN.CANBlocks)
                IRInfo.CAN{end+1} =  childmodelIRInfo{i}.CAN.CANBlocks{j};
            end
            for j = 1 : length(childmodelIRInfo{i}.CAN.CANModule)
                if ~ismember(IRInfo.eCAN.CANModule, childmodelIRInfo{i}.CAN.CANModule{j})
                    IRInfo.eCAN.CANModule{end+1} =  childmodelIRInfo{i}.CAN.CANModule{j};
                end
            end
            IRInfo.eCAN.numCANModule = length(IRInfo.eCAN.CANModule);
            if isfield(childmodelIRInfo{i}.CAN,'numOfMailboxInstanceA')
                IRInfo.eCAN.numOfMailboxInstanceA(:) = IRInfo.eCAN.numOfMailboxInstanceA(:) | ...
                    childmodelIRInfo{i}.CAN.numOfMailboxInstanceA(:);
            end
            if isfield(childmodelIRInfo{i}.CAN,'numOfMailboxInstanceB')
                IRInfo.eCAN.numOfMailboxInstanceB(:) = IRInfo.eCAN.numOfMailboxInstanceB(:) | ...
                    childmodelIRInfo{i}.CAN.numOfMailboxInstanceB(:);
            end
        end
    end
end

% -------------------------------------------
% eQEP Blocks
% -------------------------------------------
if codertarget.resourcemanager.isregistered('', 'eQEP', 'numQEPs', cs)
    IRInfo.numQEPs = codertarget.resourcemanager.get('', 'eQEP', 'numQEPs', cs);
else
    IRInfo.numQEPs = 0;
    IRInfo.QEP = [];
end
if codertarget.resourcemanager.isregistered('', 'eQEP', 'eQEPBlocks', cs)
    IRInfo.QEP = codertarget.resourcemanager.get('', 'eQEP', 'eQEPBlocks', cs);
end
if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'eQEP')
            IRInfo.numQEPs = IRInfo.numQEPs + childmodelIRInfo{i}.eQEP.numQEPs;
            for j = 1 : length(childmodelIRInfo{i}.eQEP.eQEPBlocks)
                IRInfo.QEP{end+1} =  childmodelIRInfo{i}.eQEP.eQEPBlocks{j};
            end
        end
    end
end

%--------------------------------------------------------------------------
% I2C Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'I2C', 'numI2Cs', cs)
    IRInfo.numI2Cs = codertarget.resourcemanager.get('', 'I2C', 'numI2Cs', cs);
else
    IRInfo.numI2Cs = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2C', 'numI2Cs_Rx', cs)
    IRInfo.numI2Cs_Rx = codertarget.resourcemanager.get('', 'I2C', 'numI2Cs_Rx', cs);
else
    IRInfo.numI2Cs_Rx = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2C', 'numI2Cs_Tx', cs)
    IRInfo.numI2Cs_Tx = codertarget.resourcemanager.get('', 'I2C', 'numI2Cs_Tx', cs);
else
    IRInfo.numI2Cs_Tx = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2C', 'I2Cblocks', cs)
    IRInfo.I2C = codertarget.resourcemanager.get('', 'I2C', 'I2Cblocks', cs);
else
    IRInfo.I2C.I2CRxTxblocks = 0;
    IRInfo.I2C.numI2Cs_Tx = 0;
    IRInfo.I2C.numI2Cs_Rx = 0;
    IRInfo.I2C.numI2CModule = 0;
    IRInfo.I2C.I2CModule = [];
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'I2C')
            IRInfo.numI2Cs = IRInfo.numI2Cs + childmodelIRInfo{i}.I2C.numI2Cs;
            if isfield(childmodelIRInfo{i}.I2C,'numI2Cs_Rx')
                IRInfo.numI2Cs_Rx = IRInfo.numI2Cs_Rx + childmodelIRInfo{i}.I2C.numI2Cs_Rx;
            end
            if isfield(childmodelIRInfo{i}.I2C,'numI2Cs_Tx')
                IRInfo.numI2Cs_Tx = IRInfo.numI2Cs_Tx + childmodelIRInfo{i}.I2C.numI2Cs_Tx;
            end
            IRInfo.I2C.I2CRxTxblocks = IRInfo.I2C.I2CRxTxblocks + childmodelIRInfo{i}.I2C.I2Cblocks.I2CRxTxblocks;
            IRInfo.I2C.numI2CModule = IRInfo.I2C.numI2CModule + childmodelIRInfo{i}.I2C.I2Cblocks.numI2CModule;

            for j = 1 : length(childmodelIRInfo{i}.I2C.I2Cblocks.I2CModule)
                if isempty(IRInfo.I2C.I2CModule) || ...
                        ~ismember(IRInfo.I2C.I2CModule, childmodelIRInfo{i}.I2C.I2Cblocks.I2CModule{j})
                    IRInfo.I2C.I2CModule{end+1} =  childmodelIRInfo{i}.I2C.I2Cblocks.I2CModule{j};
                end
            end
        end
    end
end

%--------------------------------------------------------------------------
% I2C Sensor Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'I2CSensor', 'numI2CSensor', cs)
    IRInfo.numI2CSensors = codertarget.resourcemanager.get('', 'I2CSensor', 'numI2CSensor', cs);
else
    IRInfo.numI2CSensors = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2CSensor', 'numI2CAs', cs)
    IRInfo.numI2CAs = codertarget.resourcemanager.get('', 'I2CSensor', 'numI2CAs', cs);
else
    IRInfo.numI2CAs = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2CSensor', 'numI2CBs', cs)
    IRInfo.numI2CBs = codertarget.resourcemanager.get('', 'I2CSensor', 'numI2CBs', cs);
else
    IRInfo.numI2CBs = 0;
end
if codertarget.resourcemanager.isregistered('', 'I2CSensor', 'I2CSensorblocks', cs)
    IRInfo.I2CSensor = codertarget.resourcemanager.get('', 'I2CSensor', 'I2CSensorblocks', cs);
else
    IRInfo.I2CSensor.I2CModule = [];
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'I2CSensor')
            IRInfo.numI2CSensors = IRInfo.numI2CSensors + childmodelIRInfo{i}.I2CSensor.numI2CSensor;
            if isfield(childmodelIRInfo{i}.I2CSensor, 'numI2CAs')
                IRInfo.numI2CAs = IRInfo.numI2CAs + childmodelIRInfo{i}.I2CSensor.numI2CAs;
            end
            if isfield(childmodelIRInfo{i}.I2CSensor, 'numI2CBs')
                IRInfo.numI2CBs = IRInfo.numI2CBs + childmodelIRInfo{i}.I2CSensor.numI2CBs;
            end
            
            for j = 1 : length(childmodelIRInfo{i}.I2CSensor.I2CSensorblocks.I2CModule)
                if ~ismember(IRInfo.I2CSensor.I2CModule, childmodelIRInfo{i}.I2CSensor.I2CSensorblocks.I2CModule{j})
                    IRInfo.I2CSensor.I2CModule{end+1} =  childmodelIRInfo{i}.I2CSensor.I2CSensorblocks.I2CModule{j};
                end
            end
        end
    end
end

%--------------------------------------------------------------------------
% HW Interrupt Blocks -legacy code
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'HWINT', 'numInterrupts', cs)
    IRInfo.numInterrupts = codertarget.resourcemanager.get('', 'HWINT', 'numInterrupts', cs);
elseif codertarget.resourcemanager.isregistered('', 'TIHWINT', 'numTIHWINT', cs)
    IRInfo.numInterrupts = codertarget.resourcemanager.get('', 'TIHWINT', 'numTIHWINT', cs);
else
    IRInfo.numInterrupts = 0;
end

% base rate related settings needed for soc
notCLAPU = true;
isTMFound = false;
if isfield(ctd, 'ESB') && isfield(ctd.ESB, 'ProcessingUnit')
    pu = codertarget.data.getParameterValue(cs, 'ESB.ProcessingUnit');
    if contains(pu, 'CLA')
        notCLAPU = false;
    elseif contains(pu, 'CPU')
        taskManagerBlk = codertarget.utils.findTaskManager(modelName);
        if ~isempty(taskManagerBlk)
            if numel(taskManagerBlk) > 1
                % there could be CLA TM in swc model
                claTMBlk = codertarget.utils.findCLATaskManager(modelName);
                % remove CLA TM from list
                taskManagerBlk(ismember(taskManagerBlk, claTMBlk)) = [];

                % Register custom init function to allocate peripherals to CLA
                if ~isempty(claTMBlk)
                    initBoardCLAFcnName = 'init_board_CLA()';
                    codertarget.resourcemanager.addunique(modelName, modelName, 'CustomCode', 'CustomCodeInitFcn', initBoardCLAFcnName);
                end
            end
            % Register TM block similar to registerTIC2000HWInterruptBlocks or registerCLATaskManagerBlock
            soc.tic2000.registry.registerTaskManagerBlock(taskManagerBlk{1});
            isTMFound = true;
            % Always only 1 TM in cg model
        end
    end
end

if notCLAPU
    schedulerIntSrc = codertarget.data.getParameterValue(cs, 'Scheduler_interrupt_source');
    if codertarget.resourcemanager.isregistered('', 'HWINT', 'HWINTBlocks', cs)
        HWINT = codertarget.resourcemanager.get('', 'HWINT', 'HWINTBlocks', cs);
        IRInfo.interrupts = HWINT.interrupts;
        IRInfo.pienumbers = HWINT.pienumbers;
        IRInfo.priority   = HWINT.priority;
        IRInfo.isrpreempt = HWINT.isrpreempt;
        IRInfo.newHWINTBlock =0;
    elseif codertarget.resourcemanager.isregistered('', 'TIHWINT', 'TIHWINTBlocks', cs)
        HWINT = codertarget.resourcemanager.get('', 'TIHWINT', 'TIHWINTBlocks', cs);
        for i = 1:IRInfo.numInterrupts
            [intnum,pienum] = codertarget.tic2000.internal.getInterruptPieNumber(HWINT{i}.isrNumber);
            IRInfo.interrupts{i} = intnum;
            IRInfo.pienumbers{i} = pienum;
            IRInfo.priority{i} = str2double(HWINT{i}.isrPriority);
            IRInfo.isrpreempt{i} = HWINT{i}.isrpreempt;
        end
        % Flag to identify whether new hardware interrutp block is used in
        % the model
        IRInfo.newHWINTBlock =1;
    elseif codertarget.resourcemanager.isregistered('', 'TITaskManager', 'TITaskManagerBlock', cs)      
        TMInfo = codertarget.resourcemanager.get('', 'TITaskManager', 'TITaskManagerBlock', cs);
        IRInfo.numInterrupts = length(TMInfo);
        for i = 1:IRInfo.numInterrupts
            [intnum,pienum] = codertarget.tic2000.internal.getInterruptPieNumber(TMInfo{i}.isrNumber);
            IRInfo.interrupts{i} = intnum;
            IRInfo.pienumbers{i} = pienum;
            IRInfo.priority{i} = str2double(TMInfo{i}.isrPriority);
            IRInfo.isrpreempt{i} = TMInfo{i}.isrpreempt;
    end
    end
    if IRInfo.numInterrupts>=1
        % Code to include the base rate interrupt
        IRInfo.numInterrupts = IRInfo.numInterrupts + 1;
        IRInfo.interrupts{end+1} = 1;
        IRInfo.priority{end+1}   = 40;
        IRInfo.isrpreempt{end+1} = 1;
        if (schedulerIntSrc == 0)
            IRInfo.pienumbers{end+1} = 7;
        elseif (schedulerIntSrc == 1)
            IRInfo.pienumbers{end+1} = 1;
        elseif (schedulerIntSrc == 2)
            if(isfield(ctd,'ADCB')) || (isfield(ctd,'ADC'))
                IRInfo.pienumbers{end+1} = 2;
            else
                IRInfo.pienumbers{end+1} = 3;
            end
        elseif (schedulerIntSrc == 3)
            if(isfield(ctd,'ADCC'))
                IRInfo.pienumbers{end+1} = 3;
            else
                IRInfo.pienumbers{end+1} = 6;
            end
        else
            IRInfo.pienumbers{end+1} = 6;
        end    
    else
        IRInfo.numInterrupts = 1;
        IRInfo.interrupts    = 1;
        IRInfo.priority      = 40;
        IRInfo.isrpreempt    = 1;
        if (schedulerIntSrc == 0)
            IRInfo.pienumbers = 7;
        elseif (schedulerIntSrc == 1)
            IRInfo.pienumbers = 1;
        elseif (schedulerIntSrc == 2)            
            if(isfield(ctd,'ADCB')) || (isfield(ctd,'ADC'))
                IRInfo.pienumbers = 2;
            else
                IRInfo.pienumbers = 3;
            end
        elseif (schedulerIntSrc == 3)
            if(isfield(ctd,'ADCC'))
                IRInfo.pienumbers = 3;
            else
                IRInfo.pienumbers = 6;
            end
        else
            IRInfo.pienumbers = 6;
        end
    end
end

%--------------------------------------------------------------------------
% Idle Task Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'IdleTask', 'numIdleTasks', cs)
    IRInfo.numIdleTasks = codertarget.resourcemanager.get('', 'IdleTask', 'numIdleTasks', cs);
else
    IRInfo.numIdleTasks = 0;
end
if codertarget.resourcemanager.isregistered('', 'IdleTask', 'IdleTaskBlocks', cs)
    IdleTask = codertarget.resourcemanager.get('', 'IdleTask', 'IdleTaskBlocks', cs);
    IRInfo.idletasks        = IdleTask.idletasks;
    IRInfo.idletaskpreempt  = IdleTask.idletaskpreempt;
else
    IRInfo.numIdleTasks     = 0;
    IRInfo.idletasks        = 0;
    IRInfo.idletaskpreempt  = 0;
end

%--------------------------------------------------------------------------
% LIN Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'LIN', 'numLINs', cs)
    IRInfo.numLINs = codertarget.resourcemanager.get('', 'LIN', 'numLINs', cs);
else
    IRInfo.numLINs = 0;
end
if codertarget.resourcemanager.isregistered('', 'LIN', 'LINBlocks', cs)
    LIN = codertarget.resourcemanager.get('', 'LIN', 'LINBlocks', cs);
    IRInfo.LIN                      = LIN.LIN;
    IRInfo.LIN_PostInterrupt        = LIN.LIN_PostInterrupt;
    IRInfo.LIN_SendChecksum         = LIN.LIN_SendChecksum;
    IRInfo.LIN_PhyBusErrInterrupt   = LIN.LIN_PhyBusErrInterrupt;
    IRInfo.LIN_CompChecksum         = LIN.LIN_CompChecksum;
    IRInfo.LIN_BitErrInterrupt      = LIN.LIN_BitErrInterrupt;
    IRInfo.LIN_ChecksumErrInterrupt = LIN.LIN_ChecksumErrInterrupt;
    IRInfo.LIN_FrameErrInterrupt    = LIN.LIN_FrameErrInterrupt;
    IRInfo.LIN_OverrunErrInterrupt  = LIN.LIN_OverrunErrInterrupt;
    IRInfo.LIN_IDParityErrInterrupt = LIN.LIN_IDParityErrInterrupt;
    IRInfo.LIN_IDMatchInterrupt     = LIN.LIN_IDMatchInterrupt;
    IRInfo.LIN_dataType             = LIN.LIN_dataType;
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'LIN')
            IRInfo.numLINs = IRInfo.numLINs + childmodelIRInfo{i}.LIN.numLINs;
            if isequal(length(childmodelIRInfo.LIN.LINBlocks.LIN), 1)
                if isequal(childmodelIRInfo.LIN.LINBlocks.LIN(1).module_A, 1)
                    IRInfo.LIN(1).module_A                       = childmodelIRInfo.LIN.LINBlocks.LIN(1).module_A;
                    IRInfo.LIN_PostInterrupt(1).bufferIntLevel_A = childmodelIRInfo.LIN.LINBlocks.LIN_PostInterrupt(1).bufferIntLevel_A;
                    IRInfo.LIN_SendChecksum(1).module_A          = childmodelIRInfo.LIN.LINBlocks.LIN_SendChecksum(1).module_A;
                    IRInfo.LIN_PhyBusErrInterrupt(1).module_A    = childmodelIRInfo.LIN.LINBlocks.LIN_PhyBusErrInterrupt(1).module_A;
                    IRInfo.LIN_CompChecksum(1).module_A          = childmodelIRInfo.LIN.LINBlocks.LIN_CompChecksum(1).module_A;
                    IRInfo.LIN_BitErrInterrupt(1).module_A       = childmodelIRInfo.LIN.LINBlocks.LIN_BitErrInterrupt(1).module_A;
                    IRInfo.LIN_ChecksumErrInterrupt(1).module_A  = childmodelIRInfo.LIN.LINBlocks.LIN_ChecksumErrInterrupt(1).module_A;
                    IRInfo.LIN_FrameErrInterrupt(1).module_A     = childmodelIRInfo.LIN.LINBlocks.LIN_FrameErrInterrupt(1).module_A;
                    IRInfo.LIN_OverrunErrInterrupt(1).module_A   = childmodelIRInfo.LIN.LINBlocks.LIN_OverrunErrInterrupt(1).module_A;
                    IRInfo.LIN_IDParityErrInterrupt(1).module_A  = childmodelIRInfo.LIN.LINBlocks.LIN_IDParityErrInterrupt(1).module_A;
                    IRInfo.LIN_IDMatchInterrupt(1).module_A      = childmodelIRInfo.LIN.LINBlocks.LIN_IDMatchInterrupt(1).module_A;
                    IRInfo.LIN_dataType(1).module_A              = childmodelIRInfo.LIN.LINBlocks.LIN_dataType(1).module_A;
                end
            else
                for j = 1 : length(childmodelIRInfo.LIN.LINBlocks.LIN)
                    if isequal(childmodelIRInfo.LIN.LINBlocks.LIN(j).module_A, 1)
                        IRInfo.LIN(j).module_A                       = childmodelIRInfo.LIN.LINBlocks.LIN(j).module_A;
                        IRInfo.LIN_PostInterrupt(j).bufferIntLevel_A = childmodelIRInfo.LIN.LINBlocks.LIN_PostInterrupt(j).bufferIntLevel_A;
                        IRInfo.LIN_SendChecksum(j).module_A          = childmodelIRInfo.LIN.LINBlocks.LIN_SendChecksum(j).module_A;
                        IRInfo.LIN_PhyBusErrInterrupt(j).module_A    = childmodelIRInfo.LIN.LINBlocks.LIN_PhyBusErrInterrupt(j).module_A;
                        IRInfo.LIN_CompChecksum(j).module_A          = childmodelIRInfo.LIN.LINBlocks.LIN_CompChecksum(j).module_A;
                        IRInfo.LIN_BitErrInterrupt(j).module_A       = childmodelIRInfo.LIN.LINBlocks.LIN_BitErrInterrupt(j).module_A;
                        IRInfo.LIN_ChecksumErrInterrupt(j).module_A  = childmodelIRInfo.LIN.LINBlocks.LIN_ChecksumErrInterrupt(j).module_A;
                        IRInfo.LIN_FrameErrInterrupt(j).module_A     = childmodelIRInfo.LIN.LINBlocks.LIN_FrameErrInterrupt(j).module_A;
                        IRInfo.LIN_OverrunErrInterrupt(j).module_A   = childmodelIRInfo.LIN.LINBlocks.LIN_OverrunErrInterrupt(j).module_A;
                        IRInfo.LIN_IDParityErrInterrupt(j).module_A  = childmodelIRInfo.LIN.LINBlocks.LIN_IDParityErrInterrupt(j).module_A;
                        IRInfo.LIN_IDMatchInterrupt(j).module_A      = childmodelIRInfo.LIN.LINBlocks.LIN_IDMatchInterrupt(j).module_A;
                    end
                end
            end
        end
    end
end

%--------------------------------------------------------------------------
% EVTimer Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'EVT', 'numTimers', cs)
    IRInfo.numTimers = codertarget.resourcemanager.get('', 'EVT', 'numTimers', cs);
else
    IRInfo.numTimers = 0;
    IRInfo.timerModule = [];
    IRInfo.timerNumber = [];
end
if codertarget.resourcemanager.isregistered('', 'EVT', 'EVTBlocks', cs)
    EVT = codertarget.resourcemanager.get('', 'EVT', 'EVTBlocks',cs);
    IRInfo.timerModule = EVT.timerModule;
    IRInfo.timerNumber = EVT.timerNumber;
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'EVT')
            IRInfo.numTimers = IRInfo.numTimers + childmodelIRInfo{i}.EVT.numTimers;
            for j = 1 : childmodelIRInfo{i}.EVT.numTimers
                IRInfo.timerModule{end+1} = childmodelIRInfo.EVT.EVTBlocks.timerModule{j};
                IRInfo.timerNumber{end+1} = childmodelIRInfo.EVT.EVTBlocks.timerNumber{j};
            end
        end
    end
end

%--------------------------------------------------------------------------
% DMA Modules
%--------------------------------------------------------------------------
enable_idx = 0;
initDMAFcnName = 'StartDMA()';
for i = 1 : 6
    if codertarget.data.isValidParameter(cs,['DMA_ch', num2str(i)])
        if (codertarget.data.getParameterValue(cs, ['DMA_ch', num2str(i), '.EnableDMAChannel']))

            modelHandle = get_param(modelName,'Handle');
            % place DMA start function call before enable interrupt function call
            if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
                codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
                BlockInit = {};
            else
                BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
            end
            if ~isempty(BlockInit)
                isInitPresent = find(cellfun(@(p)strcmp(p,initDMAFcnName),BlockInit), 1);
            else
                isInitPresent = [];
            end            
            if isempty(isInitPresent)
                BlockInit{end+1} = initDMAFcnName; %#ok<AGROW>
                codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
            end

            enable_idx = enable_idx + 1;
            IRInfo.DMA{enable_idx} = codertarget.data.getParameterValue(cs, ['DMA_ch', num2str(i)]);
            IRInfo.DMA{enable_idx}.TPDMACH = num2str(i);
            if i==1
                if (codertarget.data.getParameterValue(cs, 'DMA_ch1.SetCh1ToHigh'))
                    IRInfo.DMA{enable_idx}.SetCh1ToHigh = 'on';
                else
                    IRInfo.DMA{enable_idx}.SetCh1ToHigh = 'off';
                end
            end
            if strcmp('XINT', IRInfo.DMA{enable_idx}.InterruptSrc(1:4))
                IRInfo.DMA{enable_idx}.ExtIntNumber = IRInfo.DMA{enable_idx}.InterruptSrc(5:end);
            else
                IRInfo.DMA{enable_idx}.ExtIntNumber = '0';
            end
            if (IRInfo.DMA{enable_idx}.EnableDMAChannel)
                IRInfo.DMA{enable_idx}.EnableDMAChannel = 'on';
            else
                IRInfo.DMA{enable_idx}.EnableDMAChannel = 'off';
            end
            if (IRInfo.DMA{enable_idx}.EnableOneShot)
                IRInfo.DMA{enable_idx}.EnableOneShot = 'on';
            else
                IRInfo.DMA{enable_idx}.EnableOneShot = 'off';
            end
            if (IRInfo.DMA{enable_idx}.EnableContinuous)
                IRInfo.DMA{enable_idx}.EnableContinuous = 'on';
            else
                IRInfo.DMA{enable_idx}.EnableContinuous = 'off';
            end
            if(isfield(IRInfo.DMA{enable_idx},'SyncEnable'))
                if (IRInfo.DMA{enable_idx}.SyncEnable)
                    IRInfo.DMA{enable_idx}.SyncEnable = 'on';
                else
                    IRInfo.DMA{enable_idx}.SyncEnable = 'off';
                end
            else
                IRInfo.DMA{enable_idx}.SyncEnable = 'off';
            end
            if(isfield(IRInfo.DMA{enable_idx},'EnableDSTSync'))
                if (IRInfo.DMA{enable_idx}.EnableDSTSync)
                    IRInfo.DMA{enable_idx}.EnableDSTSync = 'on';
                else
                    IRInfo.DMA{enable_idx}.EnableDSTSync = 'off';
                end
            else
                IRInfo.DMA{enable_idx}.EnableDSTSync = 'off';
            end
            if (IRInfo.DMA{enable_idx}.EnableOverFlow)
                IRInfo.DMA{enable_idx}.EnableOverFlow = 'on';
            else
                IRInfo.DMA{enable_idx}.EnableOverFlow = 'off';
            end
        end
    end
end

IRInfo.numDMA = enable_idx;

%--------------------------------------------------------------------------
% EMIF Modules
%--------------------------------------------------------------------------
peripheral_lists = fieldnames(ctd);
emif_indexes = find(cellfun(@any,strfind(peripheral_lists,'EMIF')));
emif_idx = 0;
for i = 1 : length(emif_indexes)
    EMIFStr = peripheral_lists{emif_indexes(i)};
    emif_idx = emif_idx + 1;
    if isfield(ctd, EMIFStr)
        IRInfo.EMIF{emif_idx} = ctd.(EMIFStr);
        IRInfo.EMIF{emif_idx}.EMIFEnable = ctd.(EMIFStr).CS0 || ctd.(EMIFStr).CS2;
        if isfield(ctd.(EMIFStr), 'CS3')
            IRInfo.EMIF{emif_idx}.EMIFEnable = IRInfo.EMIF{emif_idx}.EMIFEnable || ctd.(EMIFStr).CS3;
        end
        if isfield(ctd.(EMIFStr), 'CS4')
            IRInfo.EMIF{emif_idx}.EMIFEnable = IRInfo.EMIF{emif_idx}.EMIFEnable || ctd.(EMIFStr).CS4;
        end
    end
end
IRInfo.numEMIFs = emif_idx;

%--------------------------------------------------------------------------
% CLA Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'CLA', 'numCLAs', cs)
    IRInfo.numCLAs = codertarget.resourcemanager.get('', 'CLA', 'numCLAs', cs);
else
    IRInfo.numCLAs = 0;
end
if codertarget.resourcemanager.isregistered('', 'CLA', 'CLABlocks', cs)
    IRInfo.CLA = codertarget.resourcemanager.get('', 'CLA', 'CLABlocks', cs);
end

%--------------------------------------------------------------------------
% IPC Blocks
%--------------------------------------------------------------------------
if codertarget.resourcemanager.isregistered('', 'IPC', 'numIPCs', cs)
    IRInfo.numIPCs = codertarget.resourcemanager.get('', 'IPC', 'numIPCs', cs);
else
    IRInfo.numIPCs = 0;
    IRInfo.IPC.IPCAllocatedChannels = [];
end
if codertarget.resourcemanager.isregistered('', 'IPC', 'IPCblocks', cs)
    IRInfo.IPC = codertarget.resourcemanager.get('', 'IPC', 'IPCblocks', cs);
end

if peripheralinModelref
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'IPC') && isfield(childmodelIRInfo{i}.IPC, 'numIPCs')
            IRInfo.numIPCs = IRInfo.numIPCs + childmodelIRInfo{i}.IPC.numIPCs;
            IRInfo.IPC.IPCAllocatedChannels = [IRInfo.IPC.IPCAllocatedChannels childmodelIRInfo{i}.IPC.IPCblocks.IPCAllocatedChannels];
        end
    end
end

%--------------------------------------------------------------------------
% Output Xbar Module
%--------------------------------------------------------------------------
numOXbars = 0;
if isfield(ctd,'OUTPUTXBAR')
    paramName = 'OUTPUTXBAR';
    for Xbarnum = 1:8
        tag = ['OXBAR' num2str(Xbarnum)];
        OXbar = ctd.(paramName).(tag);
        if ~isequal(OXbar,'Disable all')
            numOXbars = numOXbars + 1;
        end
    end
end

%--------------------------------------------------------------------------
% Input Xbar Module
%--------------------------------------------------------------------------
numIXbars = 0;
xbarInfo = zeros(1,16);
if codertarget.data.isValidParameter(cs,'IXBAR')
        if isequal(data.SubFamily,'2837xD')
            processorSubFamily = 'F2837xS';
        else
            processorSubFamily = ['F' data.SubFamily];
        end
        % eCAP
        if IRInfo.numCAPsOpModeeCAP > 0
            eCAPData = codertarget.data.getParameterValue(cs, 'eCAP');
            for numBlocks = 1:IRInfo.numCAPs
                if isfield(IRInfo.CAP{1,numBlocks},'operatingMode') && isequal(IRInfo.CAP{1,numBlocks}.operatingMode,'eCAP')
                    % ECAP in CAP mode and XBAR pin is configured
                    if ~strcmpi(eCAPData.(['PinAssignment_ECAP' IRInfo.CAP{1,numBlocks}.CAPModule]), 'None')
                        xbarVal = eCAPData.(['PinAssignment_ECAP' IRInfo.CAP{1,numBlocks}.CAPModule '_IXBAR']);
                        % get the last digits of XBAR (INPUT6 -> 6) and set the array
                        xbarInfo(str2double(xbarVal(regexp(xbarVal,'[0-9]','once'):end))) = 1;
                    end
                end
            end
        end

        % External interrupt (XINT) configuration
        interruptNum = [1 1 12 12 12];
        pieNum = [4 5 1 2 3];
        IntXbarNum = [4 5 6 13 14];
        for intIdx = 1 : length(IntXbarNum)
            % Hardware interrupt config - XINT
            if (IRInfo.numInterrupts == 1)
                validHWInterrupt = isequal(IRInfo.interrupts,interruptNum(intIdx)) && ...
                    isequal(IRInfo.pienumbers,pieNum(intIdx));
            elseif (IRInfo.numInterrupts > 1)
                % Use cellfun to loop through the cell array of interrupts in
                % IRinfo. Use find function to get the index for matching entry
                % of interrupt number (IRInfo) and verify if pienumber (IRInfo)
                % is expected for that particular index
                matchingIndex = cellfun(@(p)isequal(p,interruptNum(intIdx)), IRInfo.interrupts);
                if isempty(matchingIndex)
                    validHWInterrupt = false;
                else
                    matchingElements = IRInfo.pienumbers(matchingIndex);
                    validHWInterrupt = ~isempty(find(cellfun(@(p)isequal(p,pieNum(intIdx)), matchingElements),1));
                end
            else
                validHWInterrupt = false;
            end

            % Overrun detection config - XINT
            if codertarget.data.isValidParameter(cs,'OverRunDetection')
                overrunData = codertarget.data.getParameterValue(cs, 'OverRunDetection');
                % Overrun detection with custom interrupt trigger
                overRunDetectionenabled = (codertarget.data.isValidParameter(cs,'OverRunDetection') && ...
                    overrunData.Enable_overrun_detection && isequal(overrunData.Custom_Logic,'Trigger interrupt'));
                validOverrunInterrupt = overRunDetectionenabled && ...
                    contains(overrunData.CPU_Number, num2str(interruptNum(intIdx))) && ...
                    isequal(overrunData.PIE_Number,num2str(pieNum(intIdx)));
            else
                validOverrunInterrupt = false;
            end

            % Software interrupt config - XINT
            if codertarget.resourcemanager.isregistered('', 'SWINT', 'numInterrupts', cs)
                IRInfo.numSWInterrupts = codertarget.resourcemanager.get('', 'SWINT', 'numInterrupts', cs);
            else
                IRInfo.numSWInterrupts = 0;
            end
            if codertarget.resourcemanager.isregistered('', 'SWINT', 'SWINTBlocks', cs)
                SWINT = codertarget.resourcemanager.get('', 'SWINT', 'SWINTBlocks', cs);
                IRInfo.SWInterrupts = SWINT.interrupts;
                IRInfo.SWPienumbers = SWINT.pienumbers;
            else
                IRInfo.SWInterrupts = 0;
                IRInfo.SWPienumbers = 0;
                IRInfo.numSWInterrupts = 0;
            end
            if (IRInfo.numSWInterrupts == 1)
                validSWInterrupt = isequal(IRInfo.SWInterrupts,interruptNum(intIdx)) && ...
                    isequal(IRInfo.SWPienumbers,pieNum(intIdx));
            elseif (IRInfo.numSWInterrupts > 1)
                % Use cellfun to loop through the cell array of interrupts in
                % IRinfo. Use find function to get the index for matching entry
                % of interrupt number (IRInfo) and verify if pienumber (IRInfo)
                % is expected for that particular index
                matchingIndex = cellfun(@(p)isequal(p,interruptNum(intIdx)), IRInfo.SWInterrupts);
                if isempty(matchingIndex)
                    validSWInterrupt = false;
                else
                    matchingElements = IRInfo.SWPienumbers(matchingIndex);
                    validSWInterrupt = ~isempty(find(cellfun(@(p)isequal(p,pieNum(intIdx)), matchingElements),1));
                end
            else
                validSWInterrupt = false;
            end

            % Update XBar info based on the interrupt configuration
            inputXbarTag = ['IXBAR.I' num2str(IntXbarNum(intIdx))];
            inputXbarGPIO = codertarget.data.getParameterValue(cs, inputXbarTag);
            if ~strcmpi(inputXbarGPIO,'None') && ... % Input XBar GPIO is valid
                (validHWInterrupt || validOverrunInterrupt || validSWInterrupt)
                xbarInfo(IntXbarNum(intIdx)) = 1;
            end
        end


        % DMA trigger source - XINT
        for dmaIdx = 1 : IRInfo.numDMA
            xintVal = IRInfo.DMA{dmaIdx}.InterruptSrc;
            if contains(xintVal,'XINT')
                xintNum = xintVal(regexp(xintVal,'[0-9]'):end);
                inputXbarTag = ['IXBAR.I' num2str(IntXbarNum(str2double(xintNum)))];
                inputXbarGPIO = codertarget.data.getParameterValue(cs, inputXbarTag);
                if ~strcmpi(inputXbarGPIO,'None') % XINT field is valid
                    xbarInfo(IntXbarNum(str2double(xintNum))) = 1;
                end
            end
        end

        % ADC SOC trigger - XINT
        for adcidx = 1 : IRInfo.numADCs
            if contains(IRInfo.ADC{adcidx}.triggerSOC, 'XINT2_XINT2SOC')
                ADCModule = IRInfo.ADC{adcidx}.ADCModule;
                if codertarget.data.isValidParameter(cs, ['ADC' ADCModule])
                    ADCData = codertarget.data.getParameterValue(cs, ['ADC' ADCModule]);
                    if ~strcmpi(ADCData.XINT2GPIO,'None')
                        xbarInfo(IntXbarNum(2)) = 1; %XINT2
                    end
                end
            end
        end

        % ePWM trips
        if codertarget.data.isValidParameter(cs,'ePWM')
            ePWMData = codertarget.data.getParameterValue(cs, 'ePWM');
            if IRInfo.numPWMs > 0
                %F28P65x has TRIP 1 -15 without 13.
                if isequal(data.SubFamily,'28p65x')
                    numTrips = [1:12, 14, 15];
                    fieldName = '_MUXSELECT1';
                else
                    % Trip4-12 without 6
                    numTrips = [4 5 7 8 9 10 11 12];
                    fieldName = '_MUXSELECT';
                end
                for idx = 1 : length(numTrips)
                    tripIdx = numTrips(idx);
                    if ~strcmp(ePWMData.(['EXBAR_TRIP' num2str(tripIdx)]), 'Disable all') % ePWM XBar not disabled
                        % Extract the position of valid integers from MUX list of format XXX12XX34XXX
                        % The position gives the mux number
                        muxNumList = strfind(ePWMData.(['EXBAR_TRIP' num2str(tripIdx) fieldName]),digitsPattern);%1-32
                        for index = 1 : length(muxNumList)
                            muxIdx = muxNumList(index);
                            % get the list of options for given mux number %0-31
                            inputList = codertarget.tic2000.pinmap.(processorSubFamily).getMUXInputforePWMXbar(cs, ['ePWM.EXBAR_TRIP' num2str(tripIdx)], (muxIdx-1));
                            % Check the value corresponding item in the list for
                            % the value set in XXX12XX34XXX for the mux %1-32
                            optionNumMatch = [ePWMData.(['EXBAR_TRIP' num2str(tripIdx) fieldName])(muxIdx) ':'];
                            xbarVal = inputList{contains(inputList, optionNumMatch)};
                            if contains(xbarVal,'INPUTXBAR')
                                % If xbar, extract the last digits discarding the
                                % first digit
                                xbarVal = strrep(xbarVal, optionNumMatch, '');
                                xbarNumIdx = regexp(xbarVal,'[0-9]');
                                xbarInfo(str2double(xbarVal(xbarNumIdx(1):end))) = 1;
                            end
                        end
                    end
                end
                % Trip1-3
                tripZoneEnabled = zeros(1,3);
                tripZoneEventEnabled = zeros(1,3);
                for pwmidx = 1 : IRInfo.numPWMs
                    % Check is any oneshot or CBCP trips are configured for any
                    % ePWMs
                    for tzselidx = 1 : 3
                        if (IRInfo.PWM{pwmidx}.(['tzselOSHT_CBC' num2str(tzselidx)]) > 0) ||...
                                ~strcmp(IRInfo.PWM{pwmidx}.tripzonesource, "Specify via dialog")
                            tripZoneEnabled(tzselidx) = 1;
                        end
                        % Check is any DC Events are configured for any ePWMs
                        if (IRInfo.PWM{pwmidx}.enDCEvent > 0)
                            if (IRInfo.PWM{pwmidx}.(['tzselEVENTTZ' num2str(tzselidx)]) > 0)
                                tripZoneEventEnabled(tzselidx) = 1;
                            end
                        end
                    end
                end
                for tzidx = 1 : 3
                    if ~strcmpi(ePWMData.(['PinAssignment_TZ' num2str(tzidx)]), 'None') && ...
                            ((tripZoneEnabled(tzidx) > 0) || (tripZoneEventEnabled(tzidx) > 0))
                        xbarVal = ePWMData.(['PinAssignment_TZ' num2str(tzidx) '_IXBAR']);
                        % get the last digits of XBAR (INPUT6 -> 6) and set the array
                        xbarInfo(str2double(xbarVal(regexp(xbarVal,'[0-9]'):end))) = 1;
                    end
                end
            end

            %SYNCI1 for ePWM and eCAP sync
            if ~strcmpi(ePWMData.PinAssignment_SYNCI, 'None') && ...
                    ((IRInfo.numCAPs > 0) || IRInfo.numPWMs > 0)
                xbarVal = ePWMData.PinAssignment_SYNCI_IXBAR;
                % get the last digits of XBAR (INPUT6 -> 6) and set the array
                xbarInfo(str2double(xbarVal(regexp(xbarVal,'[0-9]'):end))) = 1;
            end
        end
        % Output XBar
        if codertarget.data.isValidParameter(cs,'OUTPUTXBAR')
            OXbarData = codertarget.data.getParameterValue(cs, 'OUTPUTXBAR');
            for outidx = 1 : 8
                if ~strcmp(OXbarData.(['OXBAR' num2str(outidx)]), 'Disable all')% Output XBar not disabled
                    % Extract the position of valid integers from MUX list of format XXX12XX34XXX
                    % The position gives the mux number 1-32
                    if ~isequal(data.SubFamily,'28p65x')
                         muxNumList = strfind(OXbarData.(['OXBAR' num2str(outidx) '_MUXSELECT']),digitsPattern);
                    else
                         muxNumList = strfind(OXbarData.(['OXBAR' num2str(outidx) '_MUXSELECT1']),digitsPattern);
                    end
                    for index = 1 : length(muxNumList)
                        muxIdx = muxNumList(index);
                        % get the list of options for given mux number 0-31
                        inputList = codertarget.tic2000.pinmap.(processorSubFamily).getMUXInputforOutputXbar(cs, ['OUTPUTXBAR.OXBAR' num2str(outidx)], muxIdx-1);
                        % Check the value corresponding item in the list for
                        % the value set in XXX12XX34XXX for the mux %1-32
                        if ~isequal(data.SubFamily,'28p65x')
                             optionNumMatch = [OXbarData.(['OXBAR' num2str(outidx) '_MUXSELECT'])(muxIdx) ':'];
                        else
                             optionNumMatch = [OXbarData.(['OXBAR' num2str(outidx) '_MUXSELECT1'])(muxIdx) ':'];
                        end
                        xbarVal = inputList{contains(inputList, optionNumMatch)};
                        if contains(xbarVal,'INPUTXBAR')
                            % If xbar, extract the last digits discarding the
                            % first digit
                            xbarVal = strrep(xbarVal, optionNumMatch, '');
                            xbarNumIdx = regexp(xbarVal,'[0-9]');
                            xbarInfo(str2double(xbarVal(xbarNumIdx(1):end))) = 1;
                        end
                    end
                end
            end
        end

        % CLB XBar
        if codertarget.data.isValidParameter(cs,'CLBXBAR')
            ClbXbarData = codertarget.data.getParameterValue(cs, 'CLBXBAR');
            for clbidx = 0 : 7
                if ~strcmp(ClbXbarData.(['AUXSIG' num2str(clbidx)]), 'Disable all')% CLB XBar not disabled
                    % Extract the position of valid integers from MUX list of format XXX12XX34XXX
                    % The position gives the mux number 1-32
                    muxNumList = strfind(ClbXbarData.(['AUXSIG' num2str(clbidx) '_MUXSELECT']),digitsPattern);
                    for index = 1 : length(muxNumList)
                        muxIdx = muxNumList(index);
                        % get the list of options for given mux number 0-31
                        inputList = codertarget.tic2000.pinmap.(processorSubFamily).getMUXInputforClbXbar(cs, ['CLBXBAR.AUXSIG' num2str(clbidx)], muxIdx-1);
                        % Check the value corresponding item in the list for
                        % the value set in XXX12XX34XXX for the mux 1-32
                        optionNumMatch = [ClbXbarData.(['AUXSIG' num2str(clbidx) '_MUXSELECT'])(muxIdx) ':'];
                        xbarVal = inputList{contains(inputList, optionNumMatch)};
                        if contains(xbarVal,'INPUTXBAR')
                            % If xbar, extract the last digits discarding the
                            % first digit
                            xbarVal = strrep(xbarVal, optionNumMatch, '');
                            xbarNumIdx = regexp(xbarVal,'[0-9]');
                            xbarInfo(str2double(xbarVal(xbarNumIdx(1):end))) = 1;
                        end
                    end
                end
            end
        end
        numIXbars = sum(xbarInfo);
end

IRInfo.numIXbars = numIXbars;
IRInfo.xbarInfo = xbarInfo;
IRInfo.numOXbars = numOXbars;
%ExtInterrupt addition:
%-------------------------------------------------------------------------
if ~strcmp(data.SubFamily,'281x') && notCLAPU
    isExternalInterrupt = codertarget.tic2000.internal.checkExtInterrupt(data.SubFamily, IRInfo);
    if isExternalInterrupt && (IRInfo.newHWINTBlock ==1 || isTMFound)
        initXINTFcnName = 'enableExtInterrupt()';    
        modelHandle = get_param(modelName,'Handle');
        % place XINT start function call before enable interrupt function call
        if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
            codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
            BlockInit = {};
        else
            BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
        end
        if ~isempty(BlockInit)
            isInitPresent = find(cellfun(@(p)strcmp(p,initXINTFcnName),BlockInit), 1);
        else
            isInitPresent = [];
        end
        if isempty(isInitPresent)        
            if IRInfo.numIXbars == 0
                % Add Configure GPIO external interruptfunction for old
                % processors
                initGPIOExtFcnName = 'configureGPIOExtInterrupt()';
                BlockInit{end+1} = initGPIOExtFcnName;%#ok<AGROW>
            end
            BlockInit{end+1} = initXINTFcnName; %#ok<AGROW>
            codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
        end
    end
end

% Overrun detection
%--------------------------------------------------------------------------
isEnabledOverrunDetection = 0;
if isfield(ctd,'OverRunDetection')
    paramName = 'OverRunDetection';
    tag = 'Enable_overrun_detection';
    if isfield(ctd.(paramName),tag)
        isEnabledOverrunDetection = ctd.(paramName).(tag);
    end
end
IRInfo.OverrunDetection = isEnabledOverrunDetection;

%--------------------------------------------------------------------------
% CLB Module
%--------------------------------------------------------------------------
numCLBs = 0;
CLBEnabled = {};
if isfield(ctd,'CLB')
    paramName = 'CLB';
    for tileNum = 1:8
        tag = ['TILE' num2str(tileNum)];
        % No of tiles varies. Hence need to check is tile present
        if isfield(ctd.(paramName),tag)
            if (ctd.(paramName).(tag))
                numCLBs = numCLBs + 1;
                CLBEnabled = [CLBEnabled num2str(tileNum)]; %#ok<AGROW>
            end
        end
    end
end
IRInfo.numCLBs = numCLBs;
IRInfo.CLBEnabled = CLBEnabled;

%--------------------------------------------------------------------------
% CLB Xbar Module
%--------------------------------------------------------------------------
numCLBXbars = 0;
if isfield(ctd,'CLBXBAR')
    paramName = 'CLBXBAR';
    for Xbarnum = 0:7
        tag = ['AUXSIG' num2str(Xbarnum)];
        CLBXbar = ctd.(paramName).(tag);
        if ~isequal(CLBXbar,'Disable all')
            numCLBXbars = numCLBXbars + 1;
        end
    end
end
IRInfo.numCLBXbars = numCLBXbars;

%--------------------------------------------------------------------------
% Blockinit function
% -------------------------------------------------------------------------
if peripheralinModelref
    modelHandle = get_param(modelName,'Handle');
    for i = 1 : length(childmodelIRInfo)
        if isfield(childmodelIRInfo{i},'BlockInit')
            if ~codertarget.resourcemanager.isregistered(modelHandle, 'BlockInit', 'BlockInitFcn')
                codertarget.resourcemanager.register(modelHandle, 'BlockInit', 'BlockInitFcn', []);
                BlockInit = {};
            else
                BlockInit = codertarget.resourcemanager.get(modelHandle, 'BlockInit', 'BlockInitFcn');
            end
            for indx = 1: length(childmodelIRInfo{i}.BlockInit.BlockInitFcn)
                if ~isempty(BlockInit)
                    isInitPresent = find(cellfun(@(p)strcmp(p,childmodelIRInfo{i}.BlockInit.BlockInitFcn{indx}),BlockInit), 1);
                else
                    isInitPresent = [];
                end
                if isempty(isInitPresent)
                    BlockInit{end+1} = childmodelIRInfo{i}.BlockInit.BlockInitFcn{indx}; %#ok<AGROW>
                end
            end
            if ~isempty(BlockInit)
                codertarget.resourcemanager.set(modelHandle, 'BlockInit', 'BlockInitFcn', BlockInit);
            end
        end
    end
end

%getting processing unit for multicore processors.
if isfield(ctd, 'ESB') && isfield(ctd.ESB, 'ProcessingUnit')
    pu = codertarget.data.getParameterValue(cs, 'ESB.ProcessingUnit');
    if contains(pu, 'CPU2')
        IRInfo.ProcessingUnit = 'CPU2';
    end
end
end
