function sXcpConfig = computeBufferParameters(cs, lTimerType, hasCPUIDField, hasThreadIDField, maxNumSamples)
%

%   Copyright 2018-2020 The MathWorks, Inc.
%
%   This method computes the maximum number of profiling samples that can
%   be stored in the buffer. Note, the maximum size of the buffer is 255
%   bytes (due to the XCP framework)
%   Moreover, it computes the size of all the internal fields
    
    if nargin < 5 || isempty(maxNumSamples)
        maxNumSamples = [];
    end
    
    hh = targetrepository.getHardwareImplementationHelper();
    m2 = hh.getDevice(get_param(cs, 'ProdHWDeviceType'));
    if ~isempty(m2) && ~isempty(m2.XCPBuffer)
        lBufferName = m2.XCPBuffer.BufferName;
        lMaxBufferSizeInBytes = m2.XCPBuffer.MaxBufferSizeOnTarget;
    else
        lBufferName = 'xcpProfilingBuffer';
        lMaxBufferSizeInBytes = 255;
    end
    
    bitTargetWordSize = get_param(cs, 'TargetWordSize');
    bitsInByte = get_param(cs, 'TargetBitPerChar');
    bitSectionIDSize = coder.profile.ExecTimeConfig.getIdTypeSize(bitTargetWordSize);
    timerInBytes = rtw.connectivity.TypeUtils.builtinHostByteSize(lTimerType);
    bitTimerValueSize = timerInBytes * 8; 
    
    sXcpConfig = coder.profile.xcp.computeBufferParametersCmp(bitTargetWordSize, ...
        bitsInByte, bitSectionIDSize, bitTimerValueSize, ...
        hasCPUIDField, hasThreadIDField, maxNumSamples, ...
        lBufferName, lMaxBufferSizeInBytes);
end
