Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
dsd1-10 / dsd-07=Verilog / vlogmsg.pdf
Скачиваний:
79
Добавлен:
05.06.2015
Размер:
276.27 Кб
Скачать

Verilog® -XL Modeling Style Guide

Product Version 3.2

January 2001

© 1990-2001 Cadence Design Systems, Inc. All rights reserved. Printed in the United States of America.

Cadence Design Systems, Inc., 555 River Oaks Parkway, San Jose, CA 95134, USA

Trademarks: Trademarks and service marks of Cadence Design Systems, Inc. (Cadence) contained in this document are attributed to Cadence with the appropriate symbol. For queries regarding Cadence’s trademarks, contact the corporate legal department at the address shown above or call 1-800-862-4522.

All other trademarks are the property of their respective holders.

Restricted Print Permission: This publication is protected by copyright and any unauthorized use of this publication may violate copyright, trademark, and other laws. Except as specified in this permission statement, this publication may not be copied, reproduced, modified, published, uploaded, posted, transmitted, or distributed in any way, without prior written permission from Cadence. This statement grants you permission to print one (1) hard copy of this publication subject to the following conditions:

1.The publication may be used solely for personal, informational, and noncommercial purposes;

2.The publication may not be modified in any way;

3.Any copy of the publication or portion thereof must include all original copyright, trademark, and other proprietary notices and this permission statement; and

4.Cadence reserves the right to revoke this authorization at any time, and any such use shall be discontinued immediately upon written notice from Cadence.

Disclaimer: Information in this publication is subject to change without notice and does not represent a commitment on the part of Cadence. The information contained herein is the proprietary and confidential information of Cadence or its licensors, and is supplied subject to, and may be used only by Cadence’s customer in accordance with, a written agreement between Cadence and its customer. Except as may be explicitly set forth in such agreement, Cadence does not make, and expressly disclaims, any representations or warranties as to the completeness, accuracy or usefulness of the information contained in this document. Cadence does not warrant that use of such information will not infringe any third party rights, nor does Cadence assume any liability for damages or costs of any kind that may result from use of such information.

Restricted Rights: Use, duplication, or disclosure by the Government is subject to restrictions as set forth in FAR52.227-14 and DFAR252.227-7013 et seq. or its successor.

Verilog-XL Modeling Style Guide

Contents

1

 

Modeling Your Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 5

Using Comments and White Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

Defining a Module That Has No Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

Defining a Module That Has Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

Instantiating a Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

Specifying Time Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

Defining Text Substitution Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

Resetting Compiler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

Declaring Nets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

Assigning Values to Nets (Continuous Assignments) . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

Declaring Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

Example: Declaring registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

Declaring and Using Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

Declaring and Using Reals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

Declaring and Using Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

Declaring Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18

Declaring Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19

Declaring and Loading Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

20

Defining and Overriding Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

Using Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

Defining Module Path Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

2

 

Modeling Your Hardware (Gate-Level) . . . . . . . . . . . . . . . . . . . . . . . . .

29

Instantiating Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

29

Specifying Drive Strengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

Specifying Gate Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

Defining Conditional Continuous Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

January 2001

3

Product Version 3.2

Verilog-XL Modeling Style Guide

3

 

Modeling Your Hardware (Behavior-Level) . . . . . . . . . . . . . . . . . . . .

33

Defining Procedures That Execute Once (initial) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33

Defining Procedures That Execute Continually (always) . . . . . . . . . . . . . . . . . . . . . . . . .

34

Defining Sequential Blocks (begin-end) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

Defining Parallel Blocks (fork-join) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

Assigning Values to Registers (Procedural Assignments) . . . . . . . . . . . . . . . . . . . . . . . .

37

Specifying Intra-Assignment Timing Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

Defining Conditionals (if-else) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39

Defining Conditionals (?:) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

40

Defining Conditionals (case) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41

Defining Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

42

Defining and Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

Defining and Enabling Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

44

Disabling Named Blocks and Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46

Controlling Timing with Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46

Controlling Timing with Event Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47

Declaring and Triggering Named Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48

Overriding Procedural Assignments on Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49

January 2001

4

Product Version 3.2

January 2001
5
Product Version 3.2
always @(posedge clk) if (!clr)
begin
/* Use tabs or spaces to indent statements within a block */
#8 q = d; #1 qb = ~q;
end
always wait(clr==0)
Use blank lines (carriage returns or form feeds) to logically separate parts of your source file.*/
/*
This block comment gives the name of the file that defines the DFF module and gives a brief
description. For comments that span multiple lines, use the block-comment delimiters.
*/
module DFF(d, clk, clr, q, qb); input clk, d, clr;
output q, qb; reg q,qb;
/*
File dff.v
Module for a positive-edge trigger D flip-flop
Verilog-XL Modeling Style Guide
1
Modeling Your Hardware
This chapter describes how to model your hardware with Verilog HDL programming code.
Using Comments and White Space
Commenting your source code makes your design easier to read and maintain. Verilog HDL provides both block comments /* */ (to indicate comments that span more than one line) and single-line comments //. You can also use white space (spaces, tabs, blank lines, form feeds) to improve readability; Verilog-XL ignores all white space.
“Example: Using comments and white space” on page 5 shows how comments and white space make source code more readable.
Example: Using comments and white space

 

 

Verilog-XL Modeling Style Guide

 

 

Modeling Your Hardware

 

 

begin

 

 

#4 q =0;

 

 

#1 qb =1;

 

wait (clr==1);

// hold simulation until clr is deasserted

/*

For brief (single line or partial line) comments, use

 

the double slash comment delimiter as shown above.

 

Verilog-XL ignores all characters between the double slash

end

and the end of the line. */

 

 

endmodule // DFF

 

Defining a Module That Has No Ports

You can define a module without ports when your module is a top-level module, which is a module that is not instantiated into another module, such as a test fixture. Use the module and endmodule statements to define a module. Begin a module definition with the module statement. You must provide a module name. End the module definition with the endmodule statement. Note that endmodule is not followed by a semicolon.

The following example shows a segment of a module that has no port definitions. This module is called harddrive, which is a test fixture for the hardreg module and therefore needs no module ports.

Example: Defining a module that has no ports

module harddrive;

reg clk, clr; // Specify Verilog HDL statements or Verilog-XL // constructs you want in your module definition.

reg [3:0] data; wire [3:0] q;

‘define stim #100 data = 4’b event end_first_pass;

hardreg h1 (data, clk, clr, q);

initial

 

begin

 

clr = 1;

 

clk = 0;

 

end

 

endmodule

// harddrive

Defining a Module That Has Ports

You can define a module with ports if your module will be instantiated into another module. This creates a module hierarchy.

You can define input, output, or inout (bidirectional) ports.

January 2001

6

Product Version 3.2

Соседние файлы в папке dsd-07=Verilog