function ret = getTgtPrefPeripherals (modelname)
% GETTGTPREFPERIPHERALS  Returns list of the properties and values in a flat structure

% Copyright 2012-2022 The MathWorks, Inc.

ret = [];
userdata = get_param(modelname,'CoderTargetData');
ret = getfieldvalues (ret, userdata, 'DSPBoardDSPChip');


%-------------------------------------------------------------------------------
function ret = getfieldvalues (ret, parrentobj, pref)
fn = fieldnames (parrentobj);
for i=1:length(fn)
    obj = parrentobj.(fn{i});
    if isstruct (obj)
        if (length(obj)>1)
            for j=1:length(obj)
                ret = getfieldvalues (ret, obj(j), [pref fn{i} num2str(j)]);
            end
        else
            ret = getfieldvalues (ret, obj, [pref fn{i}]);
        end
    else
        % textToExclude - Text to be excluded from the field name.
        % The intention is to keep the fieldnames short.
        textToExclude = {'HardwareMappingPeripherals'};
        fname = replace([pref fn{i}], textToExclude, '');
        % Ensure that the fieldname is valid
        fname = matlab.lang.makeValidName(fname);
        ret.(fname) = obj;
    end
end