% This script was automatically generated on 04-Jan-2019 00:17:32, during
% SoC Blockset design generation

% NOTE: You must program the FPGA with the generated bitstream file
% before running this script
%       You can use the provided, pre-generated bitstream files:
%       soc_histogram_equalization_top-zc706.bit 



% Copyright 2019 The MathWorks, Inc.

%% Load saved AXI master info
% This file contains information used by this script
% Available structs in this file: histogramequalization_ip, vdma_frame_buffer, perf_mon, vtc, vdma_hdmi_out, memRegions
load('soc_histogram_equalization_top_zc706_aximaster.mat');

%% Create hardware object
hwObj = socHardwareBoard('Xilinx Zynq ZC706 evaluation kit','Connect',false);

%% Create socAXIMaster object
AXIMasterobj = socAXIMaster(hwObj);

%% User settings

% Performance monitor parameters
perfMonMode = 'Profile';% Profile/Trace direction

%% Initialize built-in IP core(s) 

% Create IPCore object for VTC core
vtcCoreObj=socIPCore(AXIMasterobj, vtc,'VTC');
% Initialize VTC core 
initialize(vtcCoreObj);
frameParam=vtcCoreObj.FrameInfo;
% Create IPCore object for VDMA Frame Buffer core 
vdma_frame_bufferCoreObj=socIPCore(AXIMasterobj, vdma_frame_buffer,'FrameBuffer');
% Initialize VDMA Frame Buffer core 
initialize(vdma_frame_bufferCoreObj,'frameParam', frameParam,'memoryRegion', memRegions);
% Create IPCore object for performance monitor core
apmCoreObj=socIPCore(AXIMasterobj, perf_mon,'PerformanceMonitor','Mode',perfMonMode); % Mode is Profile/Trace
% Create IPCore object for VDMA core for HDMI output
vdma_hdmi_outCoreObj=socIPCore(AXIMasterobj, vdma_hdmi_out,'HDMI');
% Initialize VDMA core for HDMI output
initialize(vdma_hdmi_outCoreObj,'frameParam', frameParam,'memoryRegion', memRegions);

%% Initialize user IP core(s)

init_histogramequalization_ip(AXIMasterobj, histogramequalization_ip, frameParam);

initialize(apmCoreObj);
%% Run testbench

switch perfMonMode 
    case 'Profile'...

        profilerObj=socMemoryProfiler(hwObj,apmCoreObj);

        % Adjust 'NumRuns' variable to change the number of consecutive runs of the testbench
        NumRuns = 100;
        for n = 1:NumRuns
            collectMemoryStatistics(profilerObj);

        end

        % Plot the Performance
        plotMemoryStatistics(profilerObj);
    case 'Trace'...

        profilerObj=socMemoryProfiler(hwObj,apmCoreObj);

        % Stop trace mode and obtain trace data.
        % Make sure AXI transactions finished before stopping trace mode.
        collectMemoryStatistics(profilerObj);

        % Display diagnostic trace waveforms in Logic Analyzer
        plotMemoryStatistics(profilerObj);
end


%% Release MATLAB as AXI Master object

AXIMasterobj.release;

%%
% -------------------------------------------------------------------------------
%
% SUPPORT FUNCTIONS
%
% -------------------------------------------------------------------------------
%%

function init_histogramequalization_ip(socHwObj, histogramequalization_ip, frameParam)

%% Register space for histogramequalization_ip IP core.
writememory(socHwObj,histogramequalization_ip.IPCore_Reset, uint32(1)); % Reset IP core

% Default values for AXI4_Stream_Video_0_Slave interface -- histogramequalization_ip
% Active pixels per line in each video frame. Default value is 1920.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_0_Slave_ImageWidth, uint32(frameParam.width));
% Active video lines in each video frame. Default value is 1080.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_0_Slave_ImageHeight, uint32(frameParam.height));
% Horizontal porch length in each video frame. Default value is 280.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_0_Slave_HPorch, uint32(frameParam.horizontalPorch));
% Vertical porch length in each video frame. Default value is 45.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_0_Slave_VPorch, uint32(frameParam.verticalPorch));

% Default values for AXI4_Stream_Video_1_Slave interface -- histogramequalization_ip
% Active pixels per line in each video frame. Default value is 1920.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_1_Slave_ImageWidth, uint32(frameParam.width));
% Active video lines in each video frame. Default value is 1080.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_1_Slave_ImageHeight, uint32(frameParam.height));
% Horizontal porch length in each video frame. Default value is 280.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_1_Slave_HPorch, uint32(frameParam.horizontalPorch));
% Vertical porch length in each video frame. Default value is 45.
writememory(socHwObj,histogramequalization_ip.AXI4_Stream_Video_1_Slave_VPorch, uint32(frameParam.verticalPorch));
end
