function validateSDCardLogging(hCS)
% VALIDATESDCARDLOGGING Validate SD Card logging settings

%   Copyright 2023 The MathWorks, Inc.

modelName = get_param(hCS.getModel, 'Name');
if isfield(codertarget.data.getData(hCS),'SDCard') &&...
        isfield(codertarget.data.getParameterValue(hCS, 'SDCard'), 'Enable')
    if codertarget.data.getParameterValue(hCS, 'SDCard.Enable') == 1
        spiModule = codertarget.data.getParameterValue(hCS, 'SDCard.SPIModule');
        % Error out in case of incorrect SPI configuration
        if isfield(codertarget.data.getParameterValue(hCS, spiModule),'EnableThreeWire')
            if strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.Mode']), 'Peripheral') || ...
                    isequal(codertarget.data.getParameterValue(hCS, [spiModule '.EnableThreeWire']), 1) || ...
                    isequal(codertarget.data.getParameterValue(hCS, [spiModule '.EnableLoopback']), 1)
                DAStudio.error('TIC2000:codegen:SDCardLoggingIncorrectSPIModeTRIWire', spiModule);
            end
        else
            if strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.Mode']), 'Peripheral') || ...
                    isequal(codertarget.data.getParameterValue(hCS, [spiModule '.EnableLoopback']), 1)
                DAStudio.error('TIC2000:codegen:SDCardLoggingIncorrectSPIMode', spiModule);
            end
        end
        % Error out in case of wrong GPIO configuration
        if strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.PinAssignment_SIMO']), 'None') || ...
                strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.PinAssignment_SOMI']), 'None') || ...
                strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.PinAssignment_CLK']), 'None') || ...
                strcmp(codertarget.data.getParameterValue(hCS, [spiModule '.PinAssignment_STE']), 'None')
            DAStudio.error('TIC2000:codegen:SDCardLoggingIncorrectlyConfigured', spiModule);
        end
        % Throw out a warning the SD card logging will not work if the stack
        % size is less than the minimum value required
		
        targetData = codertarget.targethardware.getTargetHardware(hCS);
        if isequal(targetData.SubFamily, '2802x') || isequal(targetData.SubFamily, '2803x') || ...
                isequal(targetData.SubFamily, '2805x') || isequal(targetData.SubFamily, '2834x') || ...
                isequal(targetData.SubFamily, '2804x') || isequal(targetData.SubFamily, '28M35x') || ...
                isequal(targetData.SubFamily, '28M36x')
            if str2double(get_param(hCS,'MaxStackSize')) < 768
                msg = message('TIC2000:codegen:SDCardLoggingMinimumStackSize', get_param(modelName, 'Name'), 768);
                sldiagviewer.reportWarning(msg.getString,'MessageId',msg.Identifier);
            end
        else
            if str2double(get_param(hCS,'MaxStackSize')) < 1024
                msg = message('TIC2000:codegen:SDCardLoggingMinimumStackSize', get_param(modelName, 'Name'), 1024);
                sldiagviewer.reportWarning(msg.getString,'MessageId',msg.Identifier);
            end
        end
    end
end
end