在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 11599|回复: 8

[转贴] verilog文件读写操作指南,比较详细,有函数说明

[复制链接]
发表于 2014-1-23 12:09:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x

Reading and writing files from verilog models

Introduction

This describes how you can read and write files in aVerilog model using a set of user functions, based on the C stdio package. Withthese functions you can perform file input and output directly in Verilogmodels without having to learn C or the PLI. This code works with VCS, MTI,Verilog-XL, and NC-Verilog (see $freadfor one restriction).

Note that Synopsys' VCS 6.1, NC-Verilog 3.3, and MTI's ModelSim 5.5 offernative support for the IEEE-1364 2001 standard. Verilog-XL does not supportthese 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

[Chris Spear's PLI Page]


Copyright

All code and user guide are copyright (C) 1995-2000 byChristian B. Spear, chris @ spear.net, (508) 486-5214 or snail-mail atSynopsys, Inc., 154 Crane Meadow  Drive, Marlboro, MA 01752.If you have any updates, bug fixes, or enhancements, or want the latestversion, please contact me!

This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at your option) anylater version.

This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for moredetails.

You should have received a copy of the GNU General Public License alongwith 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 ortestbench can read text and binary files to load memories, apply stimulus, andcontrol simulation. Files can also be written. The format of the file I/Ofunctions is based on the C stdio routines, such as fopen, fgetc, fprintf, andfscanf.

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 $readmemformat, you would have to learn the Programming Language Interface (PLI) andthe 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 limitedto 32 open files at a time.

However, using the new file I/O system functions you can perform your fileI/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 theexamples directory for the file I/O functions.

Note that these system tasks behave the same as theequivalent stdio routines. For example, $fscanf will skip over white-space,including blank lines, just like fscanf(). You can prototype code in C thenconvert it to Verilog.


Differences between fileio andIEEE-1364 Verilog-2001 (V2K) standard

The following list describes the differences between myfile 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 indicatedby 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 switchbut 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 notreturn a status.  Errors can be determined by using $ferror.

Fileio supports the V2K $fclose format under a package compilation switchbut that then blocks any use of MCDs since it hides the builtin $fclose.

3) Fileio $getchar is not directly supported in Verilog-2001.  Theoperation can be done by using $fgetc('h8000_0000) which makes use of thereserved 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 thetarget is done.

Fileio's $gets is not directly supported in Verilog 2001.  Theoperation 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.  Theoperation 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; V2Kdoes.

8) Fileio supports %f, but not the synonyms %e and %g.  V2K supportsall three.  Fileio does not support %f on in $sscanf; V2K supports allspecifiers 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 thememory referend.  V2K requires "mem" since "mem[0]"will be taken as a register read.

12) Fileio defines $sprintf and $fprintf which are not defined inV2K.  V2K defines the $swrite family of tasks for string ouput and allowsboth MCDs and FDs in the $fwrite, $fdisplay, $fmonitor, and $fstrobe familiesof tasks.  V2K supports $sformat where the difference in $sformat and$swrite is in the management of format specification strings.  Fileiorequires a single format string in $sprintf, etc; V2K follows the normalVerilog convention of treating any constant strings as format specifiers for$swrite.  In V2K, all output format specifications are consistent andproduce the same result independent of whether the target is a string, file, orstandard output.

13) Fileio $ferror only returns a status.  V2k $ferror takes a secondparameter and stores the error string in that register.  Additionally, V2K$ferror accepts a file descriptor with the value 0 and simple produces the mostrecent system error status.

14) Fileio requires an argument to $fflush; V2K permits a parameterless calland flushes all files (including MCD files) in that case.  V2K $fflushsupports 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.


File InputFunctions

The file I/O system functions and tasks are based on theC stdio routines. For more information on the stdio routines, consult a Cmanual. The major differences between these system tasks and C are caused bythe lack of a pointer variable in the Verilog language. Strings in Verilog arestored in registers, with 8 bits needed to store a single character.

OPEN A FILE

integer file;

file = $fopenr("filename");

file = $fopenw("filename");

file = $fopena("filename");

The function $fopenr opens an existing file for reading.$fopenw opens a new file for writing, and $fopena opens a new file for writingwhere any data will be appended to the end of the file. The file name can beeither a quoted string or a reg holding the file name. If the file wassuccessfully opened, it returns an integer containing the file number(1..MAX_FILES) or NULL (0) if there was an error. Note that these functions arenot the same as the built-in system function $fopen which opens a file forwriting by $fdisplay. The files are opened in C with 'rb', 'wb', and 'ab' whichallows reading and writing binary data on the PC. The 'b' is ignored on Unix.

CLOSE A FILE

integer file, r;

r = $fcloser(file);

r = $fclosew(file);

The function $fcloser closes a file for input. $fclosewcloses a file for output. It returns EOF if there was an error, otherwise 0.Note that these are not the same as $fclose which closes files for writing.

TEST FOR END OF FILE

integer file;

reg eof;

eof = $feof(file);

The function $feof tests for end of file. If anend-of-file has been reached while reading from the file, a non-zero value isreturned; otherwise, a 0 is returned.

RETURN FILE STATUS

integer file;
reg error;
error = $ferror(file);

The function $ferror returns the error status of a file. If an error hasoccurred while reading from a file, $ferror returns a non-zero value, else 0.The error value is returned once, then reset to 0.

READ A SINGLE CHARACTER

integer file, char;

char = $fgetc(file);

char = $getc();

The function $fgetc reads a single character from thespecified file and returns it. If the end-of-file is reached, $fgetc returnsEOF. You should use a 32-bit register to hold the result from $fgetc to tellthe difference between the character with the value 255 and EOF. $getc readsfrom stdin.

PUSH BACK A CHARACTER

integer file;

reg [7:0] char, r;

r = $ungetc(char, file);

The function $ungetc pushes the character back into thefile stream. That character will be the next read by $fgetc. It returns thecharacter if it was successfully pushed back or EOF if it fails.

Note that since there is no $ungetc for stdin in C, there will not be onein the file I/O package.

WRITE A SINGLE CHARACTER

integer stream, r, char;

r = $fputc(stream, char);

The function $fputc writes a single character to thespecified file. It returns EOF if there was an error, 0 otherwise.

READ A STRING

integer file, n, r;

reg [n*8-1:0] string;

r = $fgets(string, n, file);

r = $gets(string);

The function $fgets reads a string from the file.Characters are read from the file into string until a newline is seen,end-of-file is reached, or n-1 characters have been read. If the end-of-file isencountered, $fgets returns a 0 and string is unchanged; otherwise, $fgetsreturns a 1. $gets reads from stdin.

The function $gets is no longer supported by default in fileio v3.4. Ifyou want to use it, you must compile fileio.c with -DGETS. This is because someC compilers will give an error message when compiling fileio.c:

fileio.o: In function `fileio_gets_call`:

fileio.o: the gets function is dangerous and should notbe used

You can either ignore this message, or stop using -DGETSto remove the gets function call from fileio.c.

READ FORMATTED TEXT

integer file, count;

count = $fscanf(file, format, args);

count = $sscanf(string, format, args);

count = $scanf(format, args);

The function $fscanf parses formatted text from the fileaccording to the format and writes the results to args. $sscanf parsesformatted text from a string. $scanf parses formated text from stdin. See a Creference manual for detailed information on fscanf, plus examples later inthis note.

The format can be either a string constant or a reg. It can contain:

  • Whitespace     characters such as space, tab (\t), or newline (\n). One or more     whitespace characters are treated as a single character, and can match     zero or more whitespace characters from the input.
  • Conversion     specifications which start with a %. Next is an optional *, which     suppresses assignment. Then is an optional field width in decimal. Lastly     is the operator character as follows:
  • b -- Binary     values 0, 1, X, x, Z, z, _
  • d -- Decimal     values 0-9, _, no X, x, Z, or z. Note that negative numbers are NOT     supported because of a Verilog language limitation.
  • o -- Octal     values 0-7, _, X, x, Z, z
  • h or x --     Hexadecimal values, 0-9, A-F, a-f, _, X, x, Z, z
  • c -- A single     character
  • f -- A     floating point number, no _, X, x, Z, or z
  • s -- A string     
  • % -- The     percent character
  • Other     characters which must match the characters read from the file. Special     characters are \" for the " character, \\ for the \ character,     \oNNN is a single character whose ASCII value is specified by the octal     number NNN, and %% for the character %.

The args is an optional list of registers to be assignedby $fscanf, $sscanf, and $scanf. There must be a register for each conversionoperator (except those with %*). Bit subscripts are ignored.

Formatting & padding is closer to Verilog than C. For example, %x of16'h24 is '0024', not '24', and %0x returns '24', not '0024'.

$fscanf, $sscanf, and $scanf return the number of successful assignmentsperformed. If you do not want a return value from these routines, compilefileio.c (and veriuser.c for Cadence users) with -Dscanf_task. VCS users shouldswitch from fileio.tab to fileio_task.tab

FIND THE FILE POSITION

integer file, position;

position = $ftell(file);

The function $ftell returns the position in the file foruse by $fseek. If there is an error, it returns a -1.

POSITION A FILE

`define SEEK_SET 0

`define SEEK_CUR 1

`define SEEK_END 2

integer file, offset, position, r;

r = $fseek(file, 0, `SEEK_SET); /* Beginning */

r = $fseek(file, 0, `SEEK_CUR); /* No effect */

r = $fseek(file, 0, `SEEK_END); /* End of file */

r = $fseek(file, position, `SEEK_SET); /* Previous loc */

The function $fseek allows random access in a file. Youcan position at the beginning or end of a file, or use the position returnedfrom $ftell.

READ BINARY DATA

integer r, file, start, count;

reg [15:0] mem[0:10], r16;

r = $fread(file, mem[0], start, count);

r = $fread(file, r16);

The function $fread reads a binary file into a Verilogmemory. The first argument is either a register or a memory name, which musthave a subscript, though the value of the subscript is ignored. start and countare optional.

By default $fread will store data in the first data location through thefinal location. For the memory up[10:20], the first location loaded would beup[10], then up[11]. For down[20:10], the first location would be down[10],then down[11].

start and count are ignored if $fread storing data in a reg instead of amemory. No warning is printed if the file contains more data than will fit inthe memory.

start is the word offset from the lowest element in the memory. For start= 2 and the memory up[10:20], the first data would be loaded at up[12]. For thememory down[20:10] , the first location loaded would be down[12], thendown[13].

$fread returns the number of elements read from the file, If $freadterminates early because of an error, it will return the number of elementssuccessfully read. $feof can be used to determine whether the end-of-file wasreached during $fread.

The data in the file is broken into bytes according to the width of thememory. An 8-bit wide memory takes one byte per location, while a 9-bit widememory takes 2 bytes. Care should be taken when using memories with widths notevenly divisible by 8 as there may be gaps in the data in the memory vs. datain the file.

The $fread system task only works with NC-Verilog if you use the -MEMPACKswitch as in:

ncverilog +ncvlogargs+-NOMEMPACK foo.v

WRITING A FORMATTED STRING

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);

The functions $sformat and $sprintf writes a formattedstring into a Verilog register.  The two functions are identical. $fprintfwrites a formatted string to a file.  It has most, but not the formattingcapabilites of C stdio package.  The first argument is a register toreceive the formatted data, and the second is a format string.  Additionalarguments may be included.

The supported formats include b, c, d, e, f, g, h, m, o, r, s, and x. %tfor printing formatted time is NOT supported yet.

FLUSHING THE FILE STREAM

integer file, r;

file = $fopenw("output.log");

r = $fflush(file);

The function $fflush(stream) causes any buffered datawaiting to be written for the named stream to be written to that file. If thestream is 0, all files open for writing are flushed.


Restrictions and Caveats

You should be aware of following restrictions in usingthese Verilog functions vs. the stdio functions in C, which are imposed by theVerilog language :

  • Because these     are Verilog system functions, you must always use the return value as in:

r = $fscanf(...)

  • Verilog does     not allow assignments inside a conditional. Thus the C code fragment:

while (c=fgetc(stream) != EOF) {

    <process input>

    }

turns into the Verilog code:

c = $fgetc(file);

while (c !== `EOF)

    begin

    <process input>

    c = $fgetc(file);

    end

  • $fgets and     $gets return only a single bit, 0 = error, 1 = no error, unlike fgets /     gets in C, which return a string pointer.
  • $fread is     very different from fread in C. The order of arguments is different, and     the arguments are oriented towards writing to a Verilog memory instead of     a C character string. See page 5 for more info.
  • $fscanf can     not be used to read binary files, or any files with null characters.     $fprintf can not be used to write binary files with null characters.     Because of the string processing that $fscanf uses, a null in the middle     of an ASCII field will prematurely terminate the field.

In addition, $save / $restart are loosely supported withVCS on SunOS. In a test, $feof never returned EOF when running from a savefile, but $fgetc did. On other simulators and hardware platforms you can mimicthese functions using $ftell and $fseek to find the position in a file andlater jump to that location.

The maximum number of files (MAX_FILES) is set in the C code to 12. Themaximum string size is 1000 characters. There is no known limit to the numberof conversion operators in $fscanf or $sscanf.


Reading pattern files

This first example shows how to read input stimulus froma text file.

This is the pattern file - read_pattern.pat , included in the examplesdirectory:

// This is a pattern file

// time bin dec hex

10: 001 1 1

20.0: 010 20 020

50.02: 111 5 FFF

62.345: 100 4 DEADBEEF

75.789: XXX 2 ZzZzZzZz

Note that the binary and hexadecimal values have X and Zvalues, but these are not allowed in the decimal values. You can use whitespace when formatting your file to make it more readable. Lastly, any line beginningwith a / is treated as a comment.

The module read_pattern.v reads the time for the next pattern from anASCII file. It then waits until the absolute time specified in the input file,and reads the new values for the input signals (bin, dec, hex). The time in thefile is a real value and, when used in a delay, is rounded according to thetimescale directive. Thus the time 75.789 is rounded to 75.79 ns.

`timescale 1ns / 10 ps

`define EOF 32'hFFFF_FFFF

`define NULL 0

`define MAX_LINE_LENGTH 1000

module read_pattern;

integer file, c, r;

reg [3:0] bin;

reg [31:0] dec, hex;

real real_time;

reg [8*`MAX_LINE_LENGTH:0] line; /* Line of text readfrom file */

initial

    begin : file_block

    $timeformat(-9, 3, "ns", 6);

    $display("time bin decimal hex");

    file =$fopenr("read_pattern.pat");

    if (file == `NULL) // If error openingfile

        disablefile_block; // Just quit

    c = $fgetc(file);

    while (c != `EOF)

        begin

        /* Check thefirst character for comment */

        if (c =="/")

           r = $fgets(line, `MAX_LINE_LENGTH, file);

        else

           begin

           // Push the character back to the file then read the next time

           r = $ungetc(c, file);

           r = $fscanf(file," %f:\n", real_time);

           // Wait until the absolute time in the file, then read stimulus

           if ($realtime > real_time)

               $display("Error - absolute time in file is out of order - %t",

                       real_time);

               else

                   #(real_time - $realtime)

                       r = $fscanf(file," %b %d %h\n",bin,dec,hex);

               end // if c else

           c = $fgetc(file);

        end // whilenot EOF

    r = $fcloser(file);

    end // initial

// Display changes to the signals

always @(bin or dec or hex)

    $display("%t %b %d %h",$realtime, bin, dec, hex);

endmodule // read_pattern


Comparing outputs with expectedresults

The following model, compare.v, reads a file containingboth

stimulus and expected results. The input signals aretoggled at the

beginning of a clock cycle and the output is comparedjust before the

end of the cycle.

`define EOF 32'hFFFF_FFFF

`define NULL 0

`define MAX_LINE_LENGTH 1000

module compare;

integer file, r;

reg a, b, expect, clock;

wire out;

reg [`MAX_LINE_LENGTH*8:1];

parameter cycle = 20;

initial

    begin : file_block

    $display("Time Stim ExpectOutput");

    clock = 0;

    file =$fopenr("compare.pat");

    if (file == `NULL)

        disablefile_block;

    r = $fgets(line, MAX_LINE_LENGTH,file); // Skip comments

    r = $fgets(line, MAX_LINE_LENGTH,file);

    while (!$feof(file))

        begin

        // Wait untilrising clock, read stimulus

        @(posedgeclock)

        r =$fscanf(file, " %b %b %b\n", a, b, expect);

        // Wait justbefore the end of cycle to do compare

        #(cycle - 1)

       $display("%d %b %b %b %b", $stime, a, b, expect, out);

       $strobe_compare(expect, out);

        end // whilenot EOF

    r = $fcloser(file);

    $stop;

    end // initial

always #(cycle / 2) clock = !clock; // Clock generator

and #4 (out, a, b); // Circuit under test

endmodule // compare


Reading script files

Sometimes a detailed simulation model for a device is notavailable, such as a microprocessor. As a substitute, you can write abus-functional model which reads a script of bus transactions and performsthese actions. The following, script.v, reads a file with commands plus datavalues.

`define EOF 32'hFFFF_FFFF

`define NULL 0

module script;

integer file, r;

reg [80*8:1] command;

reg [31:0] addr, data;

initial

    begin : file_block

    clock = 0;

    file =$fopenr("script.txt");

    if (file == `NULL)

        disablefile_block;

    while (!$feof(file))

        begin

        r = $fscanf(file," %s %h %h \n", command, addr, data);

        case (command)

       "read":

           $display("READ mem[%h], expect = %h", addr, data);

       "write":

           $display("WRITE mem[%h] = %h", addr, data);

        default:

           $display("Unknown command '%0s'", command);

        endcase

        end // whilenot EOF

    r = $fcloser(file);

    end // initial

endmodule // script

The file script.txt is the script read by the abovemodel:

read 9 0

write 300a feedface

read 2FF xxxxxxxx

bad


Reading data files into memories

Reading a formatted ASCII file is easy with the systemtasks. The following

is an example of reading a binary file into a Verilogmemory. $fread can

also read a file one word at a time and copy the wordinto memory, but

this is about 100 times slower than using $fread to readthe entire array

directly.

This is the file load_mem.v

`define EOF 32'HFFFF_FFFF

`define MEM_SIZE 200_000

module load_mem;

integer file, i;

reg [7:0] mem[0:`MEM_SIZE];

reg [80*8:1] file_name;

initial

    begin

    file_name = "data.bin";

    file = $fopenr(file_name);

    i = $fread(file, mem[0]);

    $display("Loaded %0d entries\n", i);

    i = $fcloser(file);

    $stop;

    end

endmodule // load_mem

The file data.bin contains the 200 binary values 0 to199. You can

look at the program data.c which generated the file. Todump out the binary

file in Unix use the command od data.bin


Linking with VCS

Note that VCS 6.1 and later supports the IEEE-1364 2001standard.

To use the file I/O system functions with VCS, you willneed to:

1.

2.
Compile fileio.cwith the command:

3.

4.

cc -c fileio.c -I$VCS_HOME/include

5.
On the DEC/Alphause:

6.

cc -c fileio.c -I$VCS_HOME/`vcs -platform`/lib -taso -xtaso_short

7.
On Windows, usethe Microsoft C++ compiler included with VCS:

8.

cl -c -Zp4 fileio.c

9.
The -Zp4 switchtells the compiler to use longword alignment. Note

10.that the compiler produces fileio.obj, not fileio.o. Inthe example below,

11.if you compile on Windows, change the file extension.

12.Note that the system variable "include" mustcontain a reference

13.to the VCS include files, such as:

14.
c:\vcs422\Windows_NT\lib

15.

16.

17.Compile your Verilog model with the fileio routines onUnix with:

18.

% vcs load_mem.v fileio.o -P fileio.tab -R

                        Chronologic VCS (TM)

             Version 5.1 -- Tue Jan 11 09:00:41 2000

              Copyright (c) 1991-2000 by Synopsys Inc.

                        ALL RIGHTS RESERVED

This program is proprietary and confidential informationof Synopsys Inc.

and may be used and disclosed only as authorized in alicense agreement

controlling such use and disclosure.

Compiling load_mem.v

Top Level Modules:

load_mem

( cd csrc ; make -f Makefile DEFAULT_RUNTIME=TRUE product)

../simv up to date

Chronologic VCS simulator copyright 1991-2000

Contains Synopsys proprietary information.

Compiler version 5.1; Runtime version 5.1;  Jan 1109:00 2000

Loaded 200 entries

$stop at time 0 Scope: load_mem File: load_mem.v Line: 13

cli_0 >


Linking with Verilog-XL

Verilog-XL does not natively support the IEEE-1364 2001tasks except through

this PLI application.

Note: this information is based on an older version ofVerilog-XL.

Send me an update if you have one.

To use the file I/O system functions with Verilog-XL, youwill need to:

1.

2.
Modify yourveriuser.c to point to the system functions in fileio.c

3.
. You should copythese two files into your current directory from the

4.
examplesdirectory.

5.

6.

7.

8.
Type vconfig togenerate a script to link Verilog-XL. Use the following

9.
table to chooseyour responses.

10.

    

Running vconfig

  
    

Prompt issued from vconfig :

      

You type:

  
    

Please enter the name of the output script

      

cr_vlog

  
    

Please choose a target

      

1  Stand Alone

  
    

Please choose how to link in PLI application

      

4  Static with user PLI application

  
    

What do you want to name the Verilog-XL target?

      

verilog_fileio

  
    

Do you want to compile for the SimVision  environment?

      

n

  
    

Do you want to include GR_WAVES

      

n

  
    

Do you want to include the Simulation History Manager

      

n

  
    

The LAI interface in no longer supported

      

n

  
    

Do you want to include the LMSI HARDWARE MODELER  interface software in this executable?

      

return

  
    

Do you want to include the Verilog Mixed-Signal  interface software in this executable?

      

return

  
    

Do you want to include the Standard Delay File  Annotator in this executable?

      

return

  
    

The user template file 'veriuser.c' must always be  included in the link statement. What is the path name of this file?

      

./veriuser.c

  
    

Please list any other user files to be linked with this  Verilog-XL ... terminating with a single '.'

      

./fileio.c

  

. (period)

  

·

·
Add the switch -Dverilogxlto cr_vlog to compile fileio.c:

·

·
cc -Dverilogxl-o verilog_read $1 $2 -g \

·
   ...

·
   fileio.c\

·
   ...

·

·

·

·
Run cr_vlog andlink Verilog-XL, producing the new executable verilog_read

·

·

·

·
Run the newexecutable and simulate your models with calls to the read

·
functions.

·

·

·

·
You should see thefollowing printed when you run verilog_read to simulate

·
the modelload_mem.v :

·

% ./verilog_read load_mem.v

VERILOG-XL 2.1.12 Jun 21, 1995 14:55:32

Copyright (c) 2000 Cadence Design Systems, Inc. AllRights Reserved.

.

.

.

<<< Routines for file read linked in >>

Compiling source file "load_mem.v"

Highest level modules:

load_mem

Loaded 200 entries

L13 "load_mem.v": $stop at simulation time 0

Type ? for help

C1>

Linking with MTI

MTI's ModelSim 5.5 and later offer native support theseIEEE-1364 2001

system tasks.

Create fileio.so, the shareable object:

        make MTI=1fileio.so

or:

        gcc -c -gfileio.c -DMTI -I$MTI_PATH/include

        ld -G-Bdynamic -o fileio.so fileio.o

Compile and run your design with:

        rm -rf work

        vlib work

        vlogtest1.v    # Your Verilog code here

        vsim -c test1-pli fileio.so -do "run -all"

You might have to set the environment variableLD_LIBRARY_PATH to point

to the directory where fileio.so resides.

Linking with NC-Verilog

NC-Verilog 3.3 and later offer native support for theseIEEE-1364 2001

system tasks.

NC-Verilog does not support the tf_nodeinfo PLI callwhich is used in

several places by fileio.c. If you want to use thesesystem functions with

NC-Verilog, compile fileio.c with the -DNCVerilog switch.This will disable

the $fread routine, and passing some strings using aregister, such as

the format string to $fscanf.

If you have any information on linking with NC-Verilog,please pass

it on to me!

You can use makefile_fileio_ncv to compile and link withNC-Verilog.

I make no promises!

发表于 2014-1-25 11:36:24 | 显示全部楼层
顶一个
发表于 2014-1-25 13:46:16 | 显示全部楼层
好像手册里面都可以查得到。顶一个~
发表于 2014-2-11 21:14:34 | 显示全部楼层
回复 1# icqw1983


    看看!
发表于 2014-8-6 09:22:09 | 显示全部楼层
好长啊……
发表于 2015-6-5 03:08:59 | 显示全部楼层
Thnx!
发表于 2015-12-18 15:13:05 | 显示全部楼层
useful!!!!
发表于 2016-3-18 01:15:01 | 显示全部楼层
没有fileio.c啊·····
发表于 2018-7-26 11:45:18 | 显示全部楼层
good~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-3 09:06 , Processed in 0.045508 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表