simulink,Simulink HDL Coder中的BlackBox及RAM仿真初始化

两种RAM--HDL Demo模块&EML
源文件下载:http://download.csdn.net/source/3144044
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink
屏幕剪辑的捕获时间: 2011/3/29 14:05
HDL Demo中的RAM模块可以直接生成HDL,设置下HDL Block Properties 的RAMStyle修改下,默认的生成的占用资源比较大(Altera的)。
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink
屏幕剪辑的捕获时间: 2011/3/29 14:09
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink


IP Core作为BlackBox以及仿真初始化
2011年3月28日
10:12
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink
Simulink HDL Coder中的BlackBox及RAM仿真初始化simulink


RAM MegaCore初始化
2011年3月29日
15:05


function MIFWrt(fName,MifPad,WL,BW,myData)
% 写MIf文件
%Author by McCrocodile ZHENG 20110323
%myData必须和WL描述的长度一致
%% 下面是Altera对MIf文件的描述
% An ASCII text file (with the extension .mif) that specifies the initial
% content of a memory block (CAM, RAM, or ROM), that is, the initial values
% for each address. This file is used during project compilation and/or simulation.
% You can create a Memory Initialization File in the Memory Editor, the In-System Memory Content Editor,
% or the Quartus II Text Editor.
% A Memory Initialization File serves as an input file for memory initialization in the Compiler and Simulator.
% You can also use a Hexadecimal (Intel-Format) File (.hex) to provide memory initialization data.
% A Memory Initialization File contains the initial values for each address in the memory.
% A separate file is required for each memory block. In a Memory Initialization File,
% you must specify the memory depth and width values. In addition, you can specify data radixes as binary (BIN),
% hexadecimal (HEX), octal (OCT), signed decimal (DEC), or unsigned decimal (UNS) to display and interpret
% addresses and data values. Data values must match the specified data radix.
% When creating a Memory Initialization File in the Quartus II Text Editor, you must start with the DEPTH,
% WIDTH, ADDRESS_RADIX and DATA_RADIX keywords. You can use Tab "\t" and Space " " characters as separators,
% and insert multiple lines of comments with the percent "%" character, or a single comment with double dash
% "--" characters. Address : data pairs represent data contained inside certain memory addresses and you must
% place them between the CONTENT BEGIN and END keywords, as shown in the following examples.
%% 打开文件
fid1=fopen(fName,'w+');
fid2=fopen(MifPad,'r');
%% 创建需要的数据
hello_index = [0:WL-1]';
hello_temp=zeros(length(myData),1);
for mm=1:WL
if myData(mm)<0
hello_temp(mm)=2^BW+myData(mm);
else
hello_temp(mm)=myData(mm);
end
end
hello=[num2str(hello_index),char(58*ones(WL,1)),num2str(hello_temp),...
char(59*ones(WL,1)),char(10*ones(WL,1))];
%% 写文件头部
% flag=min(myData)<0;
tline=fgetl(fid2);%读取文件2的第一行
n=0;%初始化计数器
while ischar(tline)
if n==16
fprintf(fid1,'%s\n',['WIDTH=',num2str(BW),';']);
elseif n==17
fprintf(fid1,'%s\n',['DEPTH=',num2str(WL),';']);
% elseif n==20&&flag==1
% fprintf(fid1,'%s\n','DATA_RADIX=DEC;');
else
fprintf(fid1,'%s\n',tline);
end
tline=fgetl(fid2);
n=n+1;
if n==23
break;
end
end
%% 写数据部分
fprintf(fid1,'%s',hello');
fprintf(fid1,'END;');
fclose(fid1);
fclose(fid2);
end
% 生成RAM初始化数据
clear all;close all;clc;
%% 存储器参数
WL=256; %存储器长度
BW=8; %存储器位宽
fName='Mif1.mif';
MifPad='MifPad.mif';
%% 需要写的数据
myData=zeros(WL,1);
% 如果数据是定点的,那么还需要做处理
%%
MIFWRT(fName,MifPad,WL,BW,myData)
% copyfile(fName,'./core')

上面是两个M文件,MifPad就是空的mif文件,如下。
-- Copyright (C) 1991-2010 Altera Corporation
-- Your use of Altera Corporation's design tools, logic functions
-- and other software and tools, and its AMPP partner logic
-- functions, and any output files from any of the foregoing
-- (including device programming or simulation files), and any
-- associated documentation or information are expressly subject
-- to the terms and conditions of the Altera Program License
-- Subscription Agreement, Altera MegaCore Function License
-- Agreement, or other applicable license agreement, including,
-- without limitation, that your use is for the sole purpose of
-- programming logic devices manufactured by Altera and sold by
-- Altera or its authorized distributors. Please refer to the
-- applicable agreement for further details.
-- Quartus II generated Memory Initialization File (.mif)
WIDTH=8;
DEPTH=256;
ADDRESS_RADIX=UNS;
DATA_RADIX=UNS;
CONTENT BEGIN
END;

Tags: 

延伸阅读

最新评论

发表评论