没有合适的资源?快使用搜索试试~ 我知道了~
首页Reading and writing files from Verilog model.pdf
资源详情
资源评论
资源推荐
Reading and writing files from Verilog models
http://larc.ee.nthu.edu.tw/~lmdenq/doc/fileio.htm
Introduction
This describes how you can read and write files in a Verilog model using a set of user functions,
based on the C stdio package. With these functions you can perform file input and output directly
in Verilog models without having to learn C or the PLI. This code works with VCS, MTI, Verilog-XL,
and NC-Verilog (see $fread for one restriction).
Note that Synopsys' VCS 6.1, NC-Verilog 3.3, and MTI's ModelSim 5.5 offer native support for the
IEEE-1364 2001 standard. Verilog-XL does not support these tasks except through this PLI
application.
Copyright
Overview
Differences between fileio and IEEE-1364 Verilog-2001 standard
File Input Functions
Restrictions and Caveats
Reading pattern files
Comparing outputs with expected results
Reading script files
Reading data files into memories
Linking with VCS
Linking with Verilog-XL
Linking with MTI
Linking with NC-Verilog
--------------------------------------------------------------------------------
Copyright
All code and user guide are copyright (C) 1995-2000 by Christian B. Spear, chris @ spear.net, (508)
486-5214 or snail-mail at Synopsys, Inc., 154 Crane Meadow Drive, Marlboro, MA 01752. If you
have any updates, bug fixes, or enhancements, or want the latest version, please contact me!
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if
not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--------------------------------------------------------------------------------
Overview
This application note describes how your Verilog model or testbench can read text and binary
files to load memories, apply stimulus, and control simulation. Files can also be written. The
format of the file I/O functions is based on the C stdio routines, such as fopen, fgetc, fprintf, and
fscanf.
The Verilog language has a rich set of system functions to write files ($fdisplay, $fwrite, etc.) but
only reads files with a single, fixed format ($readmem). In the past if you wanted to read a file
that was not in $readmem format, you would have to learn the Programming Language Interface
(PLI) and the C language, write C code to read the file and pass values into Verilog, then debug
the combined C and Verilog code. In addition, the Verilog is limited to 32 open files at a time.
However, using the new file I/O system functions you can perform your file I/O directly from
Verilog. You can write Verilog HDL to:
read stimulus files to apply patterns to the inputs of a model
read a file of expected values for comparison with your model
read a script of commands to drive a simulation
read either ASCII or binary files into Verilog registers and memories
have hundreds of log files open simultaneously (though they are written to one at a time)
Code for all the examples in this file is included in the examples directory for the file I/O
functions.
Note that these system tasks behave the same as the equivalent stdio routines. For example,
$fscanf will skip over white-space, including blank lines, just like fscanf(). You can prototype code
in C then convert it to Verilog.
--------------------------------------------------------------------------------
Differences between fileio and IEEE-1364
Verilog-2001 (V2K) standard
The following list describes the differences between my file I/O package (fileio) and the IEEE-1364
Verilog-2001 standard (V2K).
1) In fileio $fopen has read, write, append variants:
file = $fopenr("filename");
file = $fopenw("filename");
file = $fopena("filename");
In V2K, there is a single $fopen for both multi-channel descriptors (MCD) and file descriptors (FD).
Whether an FD or MCD is produced is indicated by the presence of a mode string added to
$fopen in V2K:
file = $fopen("filename", "w"); // FD
file = $fopen("filename"); // MCD
Fileio supports the V2K $fopen format under a package compilation switch but that then blocks
any use of MCDs since it hides the builtin $fopen.
2) Fileio $fclose has read and write variants that return a status:
r = $fcloser(file);
r = $fclosew(file);
In V2K, there is a single $fclose for both MCDs and FDs. It does not return a status. Errors can
be determined by using $ferror.
Fileio supports the V2K $fclose format under a package compilation switch but that then blocks
any use of MCDs since it hides the builtin $fclose.
3) Fileio $getchar is not directly supported in Verilog-2001. The operation can be done by using
$fgetc('h8000_0000) which makes use of the reserved FD for stdin.
4) Fileio defines $fgets as:
r = $fgets(string, n, file);
V2K does not support a maximum count "n" of characters to read. Input in V2K always terminates
at end of line and then string assignment to the target is done.
Fileio's $gets is not directly supported in Verilog 2001. The operation can be done by using:
$fgets(string, 'h8000_0000);
that makes use of the reserved FD for stdin.
5) Fileio $scanf is not directly supported in Verilog 2001. The operation can be done by using:
$fscanf('h8000_0000, format, args);
which makes use of the reserved FD for stdin.
6) Fileio does not support ? as an alias for X; V2K does.
7) Fileio does not support reading X or Z for %d format specification; V2K does.
8) Fileio supports %f, but not the synonyms %e and %g. V2K supports all three. Fileio does not
support %f on in $sscanf; V2K supports all specifiers in $sscanf.
9) Fileio does not support %u, %z, %v, %t, or %m input format specifiers; V2K supports all of
them.
10) Fileio supports special character input handling for \ (i.e. \\, \oNNN); V2K does not support
this (not in LRM).
11) Fileio requires that $fread on a memory use "mem[0]" as the memory referend. V2K
requires "mem" since "mem[0]" will be taken as a register read.
12) Fileio defines $sprintf and $fprintf which are not defined in V2K. V2K defines the $swrite
family of tasks for string ouput and allows both MCDs and FDs in the $fwrite, $fdisplay, $fmonitor,
and $fstrobe families of tasks. V2K supports $sformat where the difference in $sformat and
$swrite is in the management of format specification strings. Fileio requires a single format
string in $sprintf, etc; V2K follows the normal Verilog convention of treating any constant strings
as format specifiers for $swrite. In V2K, all output format specifications are consistent and
produce the same result independent of whether the target is a string, file, or standard output.
13) Fileio $ferror only returns a status. V2k $ferror takes a second parameter and stores the
error string in that register. Additionally, V2K $ferror accepts a file descriptor with the value 0
and simple produces the most recent system error status.
14) Fileio requires an argument to $fflush; V2K permits a parameterless call and flushes all files
(including MCD files) in that case. V2K $fflush supports either MCDs or FDs.
15) V2K supports $rewind which Fileio does not.
16) Fileio supports $fputc which V2K does not.
17) Fileio supports $feof which V2K does not. Some functions such as $fgetc return EOF (-1) but
this is not the same.
剩余19页未读,继续阅读
jevei01
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3