image thumbnail

EZ Video Component Builder for Altera Avalon Streaming

by

 

Sample models to create Altera Avalon Streaming Components with Simulink HDL Coder.

Param_avalon_template.m
% Parameter File for Avalon ST Template

% -------------- Parameters for Testbench ------------------------------
% Based on NTSC/PAL image size(720*480)
ScaleFactor = 5;	% change this parameter for image size
% ScaleFactor = 2: Image Size 360x240;
% ScaleFactor = 3: Image Size 240x160;
% ScaleFactor = 4: Image Size 180x120;
% ScaleFactor = 4.8: Image Size 150x100;
% ScaleFactor = 5: Image Size 144x96;
% ScaleFactor = 8: Image Size 90x60;
% ScaleFactor = 10: Image Size 72x48;
% ScaleFactor = 12: Image Size 60x40;
Ts = 1; % Pixel rate

% YCbCr in/RGB out for optical flow model
Ycbcr_en = 1;  % Use YCbCr input
OutYcbcr_en = 0;  % Use YCbCr output
TestImage_en = 1;	% Use Test Image. If 1, use avi video file

% Put User Logic parameter here

% image size parameter. don't change here
ImageLengthH = 720/ScaleFactor;
ImageLengthV = 480/ScaleFactor;
sprintf('H size = %d, V size = %d',ImageLengthH, ImageLengthV)
PixelSize = ImageLengthH*ImageLengthV;

% don't care following parameter. not important for simulation
% this parameter is blank data size.
pad_l = 8;		% Image Pad Left Side>5(Control Packet Size)
pad_r = 8;		% Image Pad R Side
pad_u = 4;		% Image Pad Upper Side
pad_d = 4;		% Image Pad Lower Side
FrameRate = (ImageLengthH+pad_l+pad_r)*(ImageLengthV+pad_u+pad_d)*Ts;

clear TestImageRGB
tmp1 = repmat(im2uint8((1:2:ImageLengthH)/ImageLengthH),[ImageLengthV/2 2]);
tmp2 = im2uint8((1:2:ImageLengthV)/ImageLengthV);
TestImageRGB = [tmp1;fliplr(tmp1)];		% R
TestImageRGB(:,:,2) = [tmp1;tmp1];		% G
TestImageRGB(:,:,3) = repmat(tmp2',[2 ImageLengthH]);		% B
clear tmp1 tmp2

% YCbCr to RGB 
% R = 1.164(Y-16)                 + 1.596(Cr-128)
% G = 1.164(Y-16) - 0.391(Cb-128) - 0.813(Cr-128)
% B = 1.164(Y-16) + 2.018(Cb-128)
CSC_Gain_inv = [1.164 0 1.596;
	1.164 -0.391 -0.813;
	1.164 2.018 0];
Offset = [16;128;128]/255;

% ------- Avalon ST spec  Don't Change parameters below ----------
Ctrl_packet_size = 1+3+1;  % Control ID(1)+Packet(3)+Data ID(1)
Valid_Sample = ImageLengthH*ImageLengthV+Ctrl_packet_size;
% startofpacket/endofpacket
sop_packet = boolean(zeros(ImageLengthV+pad_u+pad_d, ImageLengthH+pad_l+pad_r));
sop_packet(pad_u+1,pad_l) = 1;								% data startofpacket
sop_packet(pad_u+1,pad_l-Ctrl_packet_size+1) = 1;								% control startofpacket
eop_packet = boolean(zeros(ImageLengthV+pad_u+pad_d, ImageLengthH+pad_l+pad_r));
eop_packet(pad_u+ImageLengthV,pad_l+ImageLengthH) = 1;		% data endofpacket
eop_packet(pad_u+1,pad_l-1) = 1;								% control endofpacket
% Control Packet
% 0h : startofpacket data
% fh : startofpacket control
control_IH = dec2hex(ImageLengthH,4);	% control packet image size
control_IV = dec2hex(ImageLengthV,4);	% control packet image size
control_prog = 0;					% Progressive = 00, Interlace = 10/11
% zero data
ctrl_packet = uint8(zeros(ImageLengthV+pad_u+pad_d, ImageLengthH+pad_l+pad_r));	% B
ctrl_packet(:,:,2) = ctrl_packet;			% G
ctrl_packet(:,:,3) = ctrl_packet(:,:,1);	% R
% control packet
ctrl_packet(pad_u+1,pad_l-4,1) = hex2dec('f');	% control packet start = Fh = 15
ctrl_packet(pad_u+1,pad_l,3) = 0;				% data packet start = 0;
ctrl_packet(pad_u+1,pad_l-3,1) = hex2dec(control_IH(1));	% Image size H 1
ctrl_packet(pad_u+1,pad_l-3,2) = hex2dec(control_IH(2));	% Image size H 2
ctrl_packet(pad_u+1,pad_l-3,3) = hex2dec(control_IH(3));	% Image size H 3
ctrl_packet(pad_u+1,pad_l-2,1) = hex2dec(control_IH(4));	% Image size H 4
ctrl_packet(pad_u+1,pad_l-2,2) = hex2dec(control_IV(1));	% Image size V 1
ctrl_packet(pad_u+1,pad_l-2,3) = hex2dec(control_IV(2));	% Image size V 2
ctrl_packet(pad_u+1,pad_l-1,1) = hex2dec(control_IV(3));	% Image size V 3
ctrl_packet(pad_u+1,pad_l-1,2) = hex2dec(control_IV(4));	% Image size V 4
ctrl_packet(pad_u+1,pad_l-1,3) = hex2dec(control_prog);		% Progressive / Interlace
ctrl_packet_sf1 =  bitconcat(fi(0,0,8,0),fi(0,0,8,0),fi(15,0,8,0),...
	fi(1,0,1,0),fi(0,0,1,0));	% sop 'f'
ctrl_packet_sf2 =  bitconcat(fi(hex2dec(control_IH(3)),0,8,0),...
	fi(hex2dec(control_IH(2)),0,8,0),fi(hex2dec(control_IH(1)),0,8,0),...
	fi(0,0,1,0),fi(0,0,1,0));	% ''
ctrl_packet_sf3 =  bitconcat(fi(hex2dec(control_IH(2)),0,8,0),...
	fi(hex2dec(control_IV(1)),0,8,0),fi(hex2dec(control_IH(4)),0,8,0),...
	fi(0,0,1,0),fi(0,0,1,0));	% ''
ctrl_packet_sf4 =  bitconcat(fi(0,0,8,0),...
	fi(hex2dec(control_IV(2)),0,8,0),fi(hex2dec(control_IV(1)),0,8,0),...
	fi(0,0,1,0),fi(1,0,1,0));	% eop''
ctrl_packet_sf5 =  bitconcat(fi(0,0,8,0),fi(0,0,8,0),fi(0,0,8,0),...
	fi(1,0,1,0),fi(0,0,1,0));	% sop '0'


valid_packet = boolean(zeros(ImageLengthV+pad_u+pad_d, ImageLengthH+pad_l+pad_r));
valid_packet(pad_u+1:pad_u+ImageLengthV,pad_l+1:pad_l+ImageLengthH) = 1;	% data
valid_packet(pad_u+1,pad_l-Ctrl_packet_size+1:pad_l) = 1;	% control

%% Fixed Point Settings for Color Space Converter YCbCr to RGB
dt_csc_ofst = fixdt(0,8,8);
% dt_csc_sub = 'Inherit: Same as first input';
dt_csc_sub = fixdt(1,10,8);
dt_csc_gain = fixdt(1,10,7);
dt_csc_gainout = fixdt(1,10,7);
dt_csc_sum = fixdt(0,8,8);


% -------------- Parameter for User Logic ------------------
% Adjust these parameter due to User logic latency
Latency_processing = 10+1+2;	% Latency in user logic

FIFO_lgth_in = FrameRate * 8;
FIFO_lgth_dutin = ImageLengthH*2;			% ImageLengthV*2;
FIFO_lgth_dutout = Latency_processing+ImageLengthH*2;	% ;

% -------------- Parameters for Fixed Point ------------------------------

Contact us