您的位置:首页 > 其它

verilog文件系统函数调用

2017-03-01 22:45 330 查看
1 $open
Integermulti_channel_descriptor= $fopen ( "file_name" );
返回文件的多通道描述符,只允许写数据,最多能打开31个文件,最高位保留。
注意:用$fopen打开文件会将原来的文件清空,若要读数据就用$readmemb,$readmemh就可以了,这个语句不会清空原来文件中的数据。integerfd = $fopen
( " file_name",type);
返回文件描述符
type枚举:
"r" or "rb"

"w" or "wb"

"a" or "ab"

"r+", "r+b", or "rb+"

"w+", "w+b", or "wb+"

"a+", "a+b", or "ab+"
以只读的方式打开
清除文件内容并以只写的方式打开

在文件末尾写数据

以可读写的方式打开文件

读写打开或建立一个文件,允许读写

读写打开或建立一个文本文件,允许读,或在末尾追加信息
打开失败可调用$ferror

2 $close
关闭文件,同时隐式终结$fmonitor、$fstrobe等任务
3 文件写入指令
file_output_task_name (multi_channel_descriptor , list_of_arguments ) ;

file_output_task_name ( fd , list_of_arguments ) ;
file_output_task_name ::=

$fdisplay | $fdisplayb | $fdisplayh | $fdisplayo

| $fwrite | $fwriteb | $fwriteh | $fwriteo

| $fstrobe | $fstrobeb | $fstrobeh | $fstrobeo

| $fmonitor | $fmonitorb | $fmonitorh | $fmonitoro

//$fmonitor只要有变化就一直记录
  $fmonitor(file_id,"%format_char", parameter);
  $fmonitor(file_id, "%m:%t in1=%d o1=%h", $time, in1, o1);
//$fwrite需要触发条件才记录,不自动换行
  $fwrite(file_id,"%format_char", parameter);
//$fdisplay需要触发条件才记录
  $fdisplay(file_id,"%format_char", parameter);
$fstrobe();当该时刻的所有事件处理完后,在这个时间步的结尾写入。推荐使用。
4 文本格式化
$sformat ( output_reg, format, list_of_arguments );
example
integer file, r, a, b;
reg [80*8:1] string;
file = $fopenw("output.log");
r = $sformat(string, "Formatted %d %x", a, b);
r = $sprintf(string, "Formatted %d %x", a, b);
r = $fprintf(file, "Formatted %d %x", a, b);
5 从文件中读取数据
c = $fgetc ( fd )
从文件中读取一个byte,若发声错误或读完,返回eof(-1),宽度位8位
code = $ungetc ( c, fd );
将由c指定的字符插入到由文件描述符fd指定的缓冲区中。字符c应为
由该文件描述符的下一个$ fgetc调用返回。文件本身不变。
integer code = $fgets ( str,fd );
从由fd指定的文件中读取字符到str,直到str被填满,或换行符被读取并传输到str,或遇到文件结束条件。如果str的长度不是byte的倍数,则部分最高位将舍弃不用保证填满整数个字节。
integer code = $fscanf ( fd,format, args );
按照固定格式从fd制定的文件中读取数据,args为读取的位置
integer code = $sscanf ( str,format, args );
$sscanf reads from the reg str
integer code = $fread( myreg,fd);

integer code = $fread( mem, fd);

integer code = $fread( mem, fd, start);

integer code = $fread( mem, fd, start, count);

integer code = $fread( mem, fd, , count);

读取二进制流,将数据从fd读向myreg或mem,不可读x,z.start是指mem的位置,
For start = 12 and the memory up[10:20],the first data would be loaded at
up[12]. For the memory down[20:10],the first location loaded would be
down[12], then down[13]。
缺省情况下myreg将mem填满或自身读完截至。
文件中的数据逐字节读取。使用一个8位宽的存储器加载一个字节,而使用每个存储器字2个字节宽加载9位宽的存储器。数据是以大尾数方式从文件中读取;第一个字节读取用于填充最重要的位置存储元件。如果内存宽度不能被8(8,16,24,32)整除,则由于截断并不是文件中的所有数据都加载到内存中。
6 定位
integerpos = $ftell ( fd );
返回fd当前字节与fd文件开头的偏移至pos,可以用于后续的$fseek使用,以将文件重新定位到此点。
code= $fseek ( fd, offset, operation );

code = $rewind ( fd );
operation:
       0:设置位置到偏移地址
       1:设置位置到当前位置加偏移量
       2:设置位置到文件结束位置$fseek(fd,0,0)
When a file is opened forappend (that is, when type is "a", or "a+"), it isimpossible to overwrite information already in the file.
7 文件冲洗
$fflush ( mcd );

$fflush ( fd );

$fflush ( );
将所有缓冲区的数据写入制定的mcd或fd,若参数缺省,冲写所有打开的文件
8 加载文件到存储区
$readmemb ( " file_name ", memory_name [ , start_addr [ , finish_addr ] ] ) ;

| $readmemh ( " file_name " , memory_name [ , start_addr [ , finish_addr] ] ) ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: