function peripherals_updated = EMIFClockCallback(peripherals_data, EMIFModule)
%EMIF_CLOCKCALLBACK Callback for the all EMIF timing calculations

% Copyright 2018 The MathWorks, Inc.

peripherals_updated = peripherals_data;

% EMIF clock frequency calculation
clockDivValue = getDividerValueFromString(peripherals_data.(EMIFModule).ClockDiv);
EMIFClockFrequency = str2double(peripherals_data.Clocking.ClosestCpuClock) / clockDivValue;
peripherals_updated.(EMIFModule).ClockFrequency = EMIFClockFrequency;
% Synchronous CS0 memory timings
peripherals_updated.(EMIFModule).t_rfc_ns = (str2double(peripherals_data.(EMIFModule).t_rfc) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_rp_ns = (str2double(peripherals_data.(EMIFModule).t_rp) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_rcd_ns = (str2double(peripherals_data.(EMIFModule).t_rcd) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_wr_ns = (str2double(peripherals_data.(EMIFModule).t_wr) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_ras_ns = (str2double(peripherals_data.(EMIFModule).t_ras) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_rc_ns = (str2double(peripherals_data.(EMIFModule).t_rc) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_rrd_ns = (str2double(peripherals_data.(EMIFModule).t_rrd) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).t_xsr_ns = (str2double(peripherals_data.(EMIFModule).t_xsr) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).RefreshRate = floor((str2double(peripherals_data.(EMIFModule).RefreshPeriod) / str2double(peripherals_data.(EMIFModule).RefreshCycle)) * EMIFClockFrequency * 1000);
% Asynchronous CS2 memory timings
peripherals_updated.(EMIFModule).CS2_R_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS2_R_Setup) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).CS2_R_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS2_R_Strobe) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).CS2_R_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS2_R_Hold) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).CS2_W_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS2_W_Setup) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).CS2_W_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS2_W_Strobe) + 1) * 1000 / EMIFClockFrequency;
peripherals_updated.(EMIFModule).CS2_W_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS2_W_Hold) + 1) * 1000 / EMIFClockFrequency;
if strcmp(EMIFModule,'EMIF1')
    % Asynchronous CS3 memory timings
    peripherals_updated.(EMIFModule).CS3_R_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS3_R_Setup) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS3_R_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS3_R_Strobe) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS3_R_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS3_R_Hold) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS3_W_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS3_W_Setup) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS3_W_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS3_W_Strobe) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS3_W_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS3_W_Hold) + 1) * 1000 / EMIFClockFrequency;
    % Asynchronous CS4 memory timings
    peripherals_updated.(EMIFModule).CS4_R_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS4_R_Setup) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS4_R_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS4_R_Strobe) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS4_R_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS4_R_Hold) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS4_W_Setup_ns = (str2double(peripherals_data.(EMIFModule).CS4_W_Setup) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS4_W_Strobe_ns = (str2double(peripherals_data.(EMIFModule).CS4_W_Strobe) + 1) * 1000 / EMIFClockFrequency;
    peripherals_updated.(EMIFModule).CS4_W_Hold_ns = (str2double(peripherals_data.(EMIFModule).CS4_W_Hold) + 1) * 1000 / EMIFClockFrequency;
end
%end %EMIF_ClockCallback
