Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.91 MB, 402 trang )
312
Appendix B
$displayh The $displayh task displays its arguments in the order that they
appear. Display will be done to the standard output device. When invoked, it
always inserts a newline character at the end of its output string. Strings to be
displayed as well as format specifications must appear in double quotes as an
argument of this task. Task invocation,
$displayh ( “Counter value is: %b”, cnt);
prints value of cnt variable in binary format. Hexadecimal format is assumed
if no format specification exists for a variable or expression.
$displayo The $displayo task displays its arguments in the order that they
appear. Display will be done to the standard output device. When invoked, it
always inserts a newline character at the end of its output string. Strings to be
displayed, as well as, format specifications must appear in double quotes as an
argument of this task. Task invocation,
$displayo ( “Counter value is: %h”, cnt);
prints value of cnt variable in hexadecimal format. Octal format is assumed if
no format specification exists for a variable or expression.
$monitoron Turns on the monitor flag used by various forms of the $monitor
system task. Monitoring will be enabled.
$monitoroff Turns off the monitor flag used by various forms of the $monitor
system task. Monitoring will be disabled.
$monitor While monitor flag is on, when a variable or an expression on
the argument list changes value, the entire argument list is displayed as in the
$display system task.
$monitorb While monitor flag is on, when a variable or an expression on
the argument list changes value, the entire argument list is displayed as in the
$displayb system task.
$monitorh While monitor flag is on, when a variable or an expression on
the argument list changes value, the entire argument list is displayed as in the
$displayh system task.
$monitoro While monitor flag is on, when a variable or an expression on
the argument list changes value, the entire argument list is displayed as in the
$displayo system task.
$strobe Using the same format as in $display, the $strobe system task displays its arguments in a simulation cycle after all events have expired.
$strobeb Using the same format as in $displayb, the $strobeb system task
displays its arguments in a simulation cycle after all events have expired.
$strobeh Using the same format as in $displayh, the $strobeh system task
displays its arguments in a simulation cycle after all events have expired.
Frequently Used System Tasks and Functions
313
$strobeo Using the same format as in $displayo, the $strobeo system task
displays its arguments in a simulation cycle after all events have expired.
$write The $write task displays its arguments in the order that they appear
using the same format as in $display. Unlike the $display task a newline
character is not added to the end of its output, and consecutive outputs continue
on the same line.
$writeb The $writeb task displays its arguments in the order that they
appear using the same format as in $displayb. Unlike the $displayb task a
newline character is not added to the end of its output, and consecutive outputs
continue on the same line.
$writeh The $writeh task displays its arguments in the order that they
appear using the same format as in $displayh. Unlike the $displayh task a
newline character is not added to the end of its output, and consecutive outputs
continue on the same line.
$writeo The $writeo task displays its arguments in the order that they
appear using the same format as in $displayo. Unlike the $displayo task a
newline character is not added to the end of its output, and consecutive outputs
continue on the same line.
B.2
File I/O Tasks
$fopen The $fopen system function returns a file descriptor for the physical
file specified as a string in the function argument. The following example makes
desc a descriptor for the physical file dataset.dat.
integer desc = $fopen (“dataset.dat”);
$fclose The $fclose task closes an open file. The only argument of this task
is a file descriptor for an open file.
$fdisplay The $fdisplay task outputs its arguments in the order that they
appear. Writing will be done to a file specified by its descriptor. The file descriptor must appear first in the task argument list. This task uses the same formatting as in the $display task. Task invocation,
$fdisplay (desc, “Counter value is: %d”, cnt);
prints value of cnt variable in decimal format. Decimal format is assumed if no
format specification exists for a variable or expression.
$fdisplayb The $fdisplay task outputs its arguments in the order that they
appear. Writing will be done to a file specified by its descriptor. The file descriptor must appear first in the task argument list. This task uses the same formatting as in the $displayb task. Task invocation,
$fdisplayb (desc, “Counter value is: %d”, cnt);
314
Appendix B
prints value of cnt variable in decimal format. Binary format is assumed if no
format specification exists for a variable or expression.
$fdisplayh The $fdisplayh task outputs its arguments in the order that
they appear. Writing will be done to a file specified by its descriptor. The file
descriptor must appear first in the task argument list. This task uses the same
formatting as in the $displayh task. Task invocation,
$fdisplayh (desc, “Counter value is: %d”, cnt);
prints value of cnt variable in decimal format. Hexadecimal format is assumed
if no format specification exists for a variable or expression.
$fdisplayo The $fdisplayo task outputs its arguments in the order that they
appear. Writing will be done to a file specified by its descriptor. The file descriptor must appear first in the task argument list. This task uses the same formatting as in the $displayo task. Task invocation,
$fdisplayo (desc, “Counter value is: %d”, cnt);
prints value of cnt variable in decimal format. Octal format is assumed if no
format specification exists for a variable or expression.
$fmonitor While monitor flag is on, when a variable or an expression on the
argument list changes value, the entire argument list is written into a file. The
file is specified by its descriptor which is the first argument in the task argument list. This task uses the same formatting as in the $display task.
$fmonitorb While monitor flag is on, when a variable or an expression on the
argument list changes value, the entire argument list is written into a file. The
file is specified by its descriptor which is the first argument in the task argument list. This task uses the same formatting as in the $displayb task.
$fmonitorh While monitor flag is on, when a variable or an expression on the
argument list changes value, the entire argument list is written into a file. The
file is specified by its descriptor which is the first argument in the task argument list. This task uses the same formatting as in the $displayh task.
$fmonitoro While monitor flag is on, when a variable or an expression on the
argument list changes value, the entire argument list is written into a file. The
file is specified by its descriptor which is the first argument in the task argument list. This task uses the same formatting as in the $displayo task.
$fstrobe Using the same format as in $display, the $fstrobe system task
writes its arguments into a file specified by its descriptor as the first argument
of the task. Writing will be done in a simulation cycle after all events have
expired.
$fstrobeb Using the same format as in $displayb, the $fstrobeb system task
writes its arguments into a file specified by its descriptor as the first argument
of the task. Writing will be done in a simulation cycle after all events have expired.
Frequently Used System Tasks and Functions
315
$fstrobeh Using the same format as in $displayh, the $fstrobeh system task
writes its arguments into a file specified by its descriptor as the first argument
of the task. Writing will be done in a simulation cycle after all events have
expired.
$fstrobeo Using the same format as in $displayo, the $fstrobeo system
task writes its arguments into a file specified by its descriptor as the first argument of the task. Writing will be done in a simulation cycle after all events have
expired.
$fwrite The $fwrite task is similar to the $fdisplay task except that it does
not insert a newline character at the end of its output string. Descriptor for the
file into which writing is done appears first in the argument list of this task.
$fwriteb The $fwriteb task is similar to the $fdisplayb task except that it
does not insert a newline character at the end of its output string. Descriptor for
the file into which writing is done appears first in the argument list of this task.
$fwriteh The $fwriteh task is similar to the $fdisplayh task except that it
does not insert a newline character at the end of its output string. Descriptor for
the file into which writing is done appears first in the argument list of this task.
$fwriteo The $fwriteo task is similar to the $fdisplayo task except that it
does not insert a newline character at the end of its output string. Descriptor for
the file into which writing is done appears first in the argument list of this task.
$readmemb A physical file name and a memory name are required arguments
of the $readmemb task. When invoked, this task reads binary data from file
specified in its argument and loads this data into the memory specified as its
second parameter. Optionally, invocation of this task may contain range of
memory words to fill.
If mem is declared as
reg [15:0] mem [0:511],
then, invocation shown below reads 16 bit words in binary from memdata.dat
file and loads this data into memory locations 12 to 412.
$readmemb(“memdata.dat”, mem, 12, 412);
$readmemh A physical file name and a memory name are required arguments
of the #readmemh task. When invoked, this task reads hexadecimal data from
file specified in its argument and loads this data into the memory specified as
its second parameter. Optionally, invocation of this task may contain range of
memory words to fill.
If mem is declared as
reg [15:0] mem [0:511],
316
Appendix B
then, invocation shown below reads 16 bit words in hexadecimal from memdata.dat
file and loads this data into memory locations 12 to 412.
$readmemh(“memdata.dat”, mem, 12, 412);
$swrite The $swrite string output system task is similar to $fwrite but
instead of writing to a file it writes its arguments into a register. This task can
be used to convert data to string.
$sformat The $sformat task is another string output system task. This task
is similar to $swrite with one major difference; it always interprets its arguments as a format string.
$fgetc The $fgetc reads a byte (character) from a specified file, i.e., $fgetc
(fd), reads from fd. The specified file must be opened with either r or r+ type
values to make them available for reading.
$ungetc The $ungetc inserts a character into the buffer of a specified file.
The character shall be returned by the next $fgetc call of the specified file. The
file itself remains unchanged.
$fgets It reads characters from a specified file into a string register until
either the register is filled or a newline character is read from the file. An example usage is:
$fgets (string_name, file_descriptor);
$fscanf It reads data from a specified file into a register. It reads characters
and interprets them according to the format specified by it arguments.
$sscanf The $sscanf is similar to the $fscanf. The difference is that $sscanf
reads from a string register.
$fread It reads binary data from a specified file and writes into a memory. The
address of the first data to be written and the number of them can be specified
in this task.
$ftell The $ftell returns the offset from the beginning of a specified file. This
task is useful for file positioning.
$fseek The $fseek task sets the position of the next input or output operation on a specified file. The positioning can be specified by offset bytes from beginning of the file or current position, or from the end of the file. General format
of use of $fseek is shown below. The value of operation (0, 1, or 2) determines
if position is set to offset, offset plus current location, or EOF plus offset.
Code = $fseek (fd, offset, operation);
$rewind The $rewind task sets the position of a specified file to the beginning of the file.
Frequently Used System Tasks and Functions
317
$fflush The $fflush task writes any buffered output to a specified file. If $fflush
is invoked with no arguments, it writes any buffered output to all open files.
$ferror It creates a string description of the type of the error encountered by
the most recent file I/O operation and writes it into a specified register.
B.3
Timescale Tasks
$printtimescale The $printtimescale task prints time unit and time precision specified by `timescale directive. If used without an argument this task considers `timescale of the module within which it is invoked. If used with an
argument, the argument must be the hierarchical name of the module considered.
$timeformat The $timeformat task specifies how %t format specification
reports time information for various forms of display tasks. Arguments of this
task are unit number, precision number, suffix string, and field width. Unit
number is an integer between 0 and 15 specifying time units 1s to 1fs respectively. Precision number argument specifies number of fractional digits of time
reported. Suffix string argument is a string for textual representation of time
unit. The last argument specifies the width of time information output string.
B.3.1
Simulation control tasks
$finish When encountered in a procedural flow the $finish system task terminates and exits simulation. An integer between 0 and 2 passed to this task
as an argument specifies the type of message printed when task is invoked.
$stop The $stop system task suspends simulation when invoked. An integer
between 0 and 2 passed to this task as an argument specifies the type of message printed when task is invoked.
B.4
Timing Check Tasks
$hold The $hold system task reports a violation when a reference event
occurs too close to a data event. A time limit specifying hold time is the allowed
time distance between the reference and data events. The first argument specifies the reference event such as the clock edge. The second argument specifies
the data signal. The third argument specifies the hold time.
$hold (posedge clk, data, holdtime);
$period Time distance between consecutive events of the same kind (positive
or negative) is monitored by the $period task. The first argument is the reference event and the second event is the time specifying the period.
$setup The $setup system task reports a violation when a data event occurs
too close to a reference event. A time limit, which is the setup time, specifies
318
Appendix B
allowed time distance between the data and reference events. The first argument specifies the name of data signal. The second argument specifies the reference event such as the clock edge. The third argument is the setup time. An
example is:
$setup (data, posedge clk, setuptime);
$skew The $skew system task reports a violation when a reference event and
a data event are too far a part in time. As in the $hold task, the reference event
is the first argument, the data event is the second argument and the skew time
is the third argument of this task.
$nochange The $nochange task reports a violation if during a level specified by transition on reference event of its first argument, its second argument
changes value. Offset time values specified by third and fourth arguments
expand or shrink the time within which data events are monitored. The following
statement report a violation if go changes while start is 0.
$nochange (negedge start, go, 0, 0);
$recovery The $recovery task is similar to the $setup task except that the
$recovery task reports a violation if the data event and reference event occur
at the same simulation time.
$setuphold The $setuphold task is invoked with arguments specifying a reference event, a data event, setup time, and hold time in this order. This task
performs both $setup and $hold tasks.
$width The $width system task reports a violation when a reference event,
specified by its first argument, occurs too close to an opposite event on this
argument. The second argument of this task is the allowed pulse width.
Appendix
C
Compiler Directives
This appendix briefly describes Verilog HDL compiler directives. Use
and examples of such a language utility where described in Chaps. 7
and 9.
`celldefine
`endcelldefine
Bracketing modules between `celldefine and
`endcelldefine tags the modules as cells.
`default_nettype
The `default_nettype directive sets the type of
implicit nets. The default is wire.
`define
`undef
The `define directive aliases an expression with
a name. The `undef directive turns of aliases set
by `define.
`ifdef
`else
`endif
`include
Directives `ifdef, `else, and `endif are if-then-else
type bracketing for optional compilation of a
Verilog code.
The `include directive inserts text from an external
file.
`unconnected_drive
`nounconnected_drive
The `unconnected_drive and `nounconnected_
drive directives bracket a portion of code for which
unconnected input ports will be treated pulled up
or pulled down instead of normal default.
`resetall
The `resetall directive resets all directives to their
default values.
`timescale
For setting time scale and time precision,
`timescale is used.
319
Copyright © 2006 by The McGraw-Hill Publishing Companies, Inc. Click here for terms of use.
This page intentionally left blank
Appendix
D
Verilog Formal
Syntax Definition
The formal syntax of Verilog HDL is described using Backus-Naur Form
(BNF).
D.1
D.1.1
Source text
Library Source Text
library_text ::= { library_descriptions }
library_descriptions ::=
library_declaration
|include_statement
|config_declaration
library_declaration ::=
library library_identifier file_path_spec [ { , file_path_spec } ]
[ -incdir file_path_spec [ { , file_path_spec } ] ;
file_path_spec ::= file_path
include_statement ::= include
D.1.2
Configuration Source Text
config_declaration ::=
config config_identifier ;
design_statement
{config_rule_statement}
endconfig
design_statement ::= design { [library_identifier.]cell_identifier } ;
config_rule_statement ::=
321
Copyright © 2006 by The McGraw-Hill Publishing Companies, Inc. Click here for terms of use.
322
Appendix D
default_clause liblist_clause
|inst_clause liblist_clause
|inst_clause use_clause
|cell_clause liblist_clause
|cell_clauseuse_clause
default_clause ::= default
inst_clause ::= instance inst_name
inst_name ::= topmodule_identifier{.instance_identifier}
cell_clause ::= cell [ library_identifier.]cell_identifier
liblist_clause ::= liblist [{library_identifier}]
use_clause ::= use [library_identifier.]cell_identifier[:config]
D.1.3
Module and Primitive Source Text
source_text ::= { description }
description ::=
module_declaration
|udp_declaration
module_declaration ::=
{ attribute_instance } module_keyword module_identifier [ module_
param eter_port_list ]
[ list_of_ports ] ; { module_item }
endmodule
|{ attribute_instance } module_keyword module_identifier [ module_
parameter_port_list ]
[ list_of_port_declarations ] ; { non_port_module_item }
endmodule
module_keyword ::= module |macromodule
D.1.4
Module Parameters and Ports
module_parameter_port_list ::= # ( parameter_declaration { , parameter_declaration } )
list_of_ports ::= ( port { , port } )
list_of_port_declarations ::=
( port_declaration { , port_declaration } )
|( )
port ::=
[ port_expression ]
|. port_identifier ( [ port_expression ] )
port_expression ::=
port_reference
|{ port_reference { , port_reference } }
port_reference ::=
port_identifier
|port_identifier [ constant_expression ]
|port_identifier [ range_expression ]
port_declaration ::=
{attribute_instance} inout_declaration
|{attribute_instance} input_declaration
|{attribute_instance} output_declaration