function [ success ] = CreatePackage( type, name, vector)
|
function [ success ] = CreatePackage( type, name, vector)
|
% creates a VHDL package with a constat array from a vector
|
% creates a VHDL package with a constat array from a vector
|
% Author: Alexander Lindert
|
% Author: Alexander Lindert
|
% type ... VHDL typ
|
% type ... VHDL typ
|
% name ... array name
|
% name ... array name
|
% vector ... single dimensional array
|
% vector ... single dimensional array
|
% TODO ... more dimensions
|
% TODO ... more dimensions
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
% GNU Lesser General Public License Version 3
|
% GNU Lesser General Public License Version 3
|
% =============================================
|
% =============================================
|
% Copyright 2005 by Sun Microsystems, Inc.
|
% Copyright 2005 by Sun Microsystems, Inc.
|
% 901 San Antonio Road, Palo Alto, CA 94303, USA
|
% 901 San Antonio Road, Palo Alto, CA 94303, USA
|
%
|
%
|
% This library is free software; you can redistribute it and/or
|
% This library is free software; you can redistribute it and/or
|
% modify it under the terms of the GNU Lesser General Public
|
% modify it under the terms of the GNU Lesser General Public
|
% License version 3, as published by the Free Software Foundation.
|
% License version 3, as published by the Free Software Foundation.
|
%
|
%
|
% This library is distributed in the hope that it will be useful,
|
% This library is distributed in the hope that it will be useful,
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
% Lesser General Public License for more details.
|
% Lesser General Public License for more details.
|
%
|
%
|
% You should have received a copy of the GNU Lesser General Public
|
% You should have received a copy of the GNU Lesser General Public
|
% License along with this library; if not, write to the Free Software
|
% License along with this library; if not, write to the Free Software
|
% Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
% Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
% MA 02111-1307 USA
|
% MA 02111-1307 USA
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
filename = sprintf('%s-p.vhd',name);
|
filename = sprintf('%s-p.vhd',name);
|
system(sprintf('rm %s', filename));
|
system(sprintf('rm %s', filename));
|
hFile = fopen(filename,'w');
|
hFile = fopen(filename,'w');
|
|
|
fprintf(hFile,'------------------------------------------------------------------------\n');
|
fprintf(hFile,'------------------------------------------------------------------------\n');
|
fprintf(hFile,'-- Script created table file\n');
|
fprintf(hFile,'-- Script created table file\n');
|
fprintf(hFile,'------------------------------------------------------------------------\n');
|
fprintf(hFile,'------------------------------------------------------------------------\n');
|
fprintf(hFile,'library ieee;\n');
|
fprintf(hFile,'library ieee;\n');
|
fprintf(hFile,'use ieee.std_logic_1164.all;\n');
|
fprintf(hFile,'use ieee.std_logic_1164.all;\n');
|
fprintf(hFile,'use ieee.numeric_std.all;\n');
|
fprintf(hFile,'use ieee.numeric_std.all;\n');
|
%fprintf(hFile,'use work.Fractional.all;\n');
|
%fprintf(hFile,'use work.Fractional.all;\n');
|
%fprintf(hFile,'use work.Global.all;\n\n');
|
%fprintf(hFile,'use work.Global.all;\n\n');
|
fprintf(hFile,'package p%s is\n',name);
|
fprintf(hFile,'package p%s is\n',name);
|
fprintf(hFile,'constant c%s : %s',name,type);
|
fprintf(hFile,'constant c%s : %s',name,type);
|
VectorSize = length(vector);
|
VectorSize = length(vector);
|
Dimension = length(VectorSize);
|
Dimension = length(VectorSize);
|
VectorPos = ones(1,VectorSize);
|
VectorPos = ones(1,VectorSize);
|
|
|
if Dimension == 1
|
if Dimension == 1
|
fprintf(hFile,'(0 to %d-1) := (',VectorSize);
|
fprintf(hFile,'(0 to %d-1) := (',VectorSize);
|
for i = 1:VectorSize
|
for i = 1:VectorSize
|
fprintf(hFile,' %d',round(vector(i)));
|
fprintf(hFile,' %d',round(vector(i)));
|
if i ~= VectorSize
|
if i ~= VectorSize
|
fprintf(hFile,',');
|
fprintf(hFile,',');
|
end
|
end
|
end
|
end
|
fprintf(hFile,')');
|
fprintf(hFile,')');
|
end
|
end
|
fprintf(hFile,';\nend;\n');
|
fprintf(hFile,';\nend;\n');
|
fclose(hFile);
|
fclose(hFile);
|
|
|
|
|
|
|
|
|