function generateASAP2(modelName, buildFolder)
% GENERATEASAP2 Generates ASAP2 file if the Communication Interface supports it

% Copyright 2021-2024 The MathWorks, Inc.

hCS = getActiveConfigSet(modelName);
if codertarget.data.isValidParameter(hCS, 'ExtMode.Configuration')
    commInterface = codertarget.data.getParameterValue(hCS, 'ExtMode.Configuration');
    cd ..
    
    mapFile = '';
    if (exist([modelName '.dwo'], 'file') == 2)
        mapFile = [modelName '.dwo'];
    elseif (exist([modelName '.elf'], 'file') == 2)
        mapFile = [modelName '.elf'];
    end
    
    selectedToolchain = get_param(hCS,'Toolchain');
    if isequal(commInterface, 'XCP on CAN') && ~codertarget.tic2000.internal.isSimulinkHostInterface(hCS) 
        if ~isequal(selectedToolchain, 'Texas Instruments Code Composer Studio - EABI (C2000)')
            coder.asap2.export(modelName, 'MapFile', mapFile, 'Folder', '.', 'Version', '1.31', Support64bitIntegers=false);
        else
            coder.asap2.export(modelName, 'MapFile', mapFile, 'Folder', '.', 'Version', '1.31');
        end
    end
    
    cd(buildFolder);
end

end