Table of Contents
Contents
Preface xv
Chapter
1
Introduction 1
1.1. What is Verilog HDL?,
1
1.2. History, 2
1.3. Major
Capabilities, 2
1.4. Exercises, 5
Chapter 2
A
Tutorial 6
2.1. A Module,
6
2.2. Delays, 8
2.3. Describing in Dataflow
Style, 9
2.4. Describing in Behavioral Style,
11
2.5. Describing in Structural Style,
14
2.6. Describing in Mixed-design Style,
16
2.7. Simulating a Design,
17
2.8. Exercises, 22
Chapter 3
Language
Elements 24
3.1. Identifiers,
24
3.2. Comments, 25
3.3. Format,
26
3.4. System Tasks and Functions,
26
3.5. Compiler Directives, 27
3.5.1. `define
and `undef, 27
3.5.2. `ifdef, `else and `endif,
28
3.5.3. `default_nettype,
28
3.5.4. `include, 28
3.5.5. `resetall,
29
3.5.6. `timescale,
29
3.5.7. `unconnected_drive and `nounconnected_drive,
31
3.5.8. `celldefine and `endcelldefine,
31
3.6. Value Set, 32
3.6.1. Integers,
32
Simple Decimal Form, 33
Base Format Notation,
33
3.6.2. Reals, 34
3.6.3. Strings,
35
3.7. Data Types, 36
3.7.1. Net Types,
36
Wire and Tri Nets, 37
Wor and Trior Nets,
38
Wand and Triand Nets, 39
Trireg Net,
39
Tri0 and Tri1 Nets, 40
Supply0 and Supply1
Nets, 40
3.7.2. Undeclared Nets,
40
3.7.3. Vectored and Scalared Nets,
41
3.7.4. Register Types, 41
Reg Register,
41
Memories, 42
Integer Register, 45
Time
Register, 46
Real and Realtime Register,
46
3.8. Parameters, 47
3.9. Exercises,
48
Chapter 4
Expressions 50
4.1. Operands,
50
4.1.1. Constant, 51
4.1.2. Parameter,
52
4.1.3. Net, 52
4.1.4. Register,
52
4.1.5. Bit-select,
53
4.1.6. Part-select, 53
4.1.7. Memory
Element, 54
4.1.8. Function Call,
54
4.2. Operators, 55
4.2.1. Arithmetic
Operators, 57
Result Size, 57
Unsigned and
Signed, 58
4.2.2. Relational Operators,
60
4.2.3. Equality Operators,
61
4.2.4. Logical Operators,
62
4.2.5. Bit-wise Operators,
63
4.2.6. Reduction Operators, 65
4.2.7. Shift
Operators, 66
4.2.8. Conditional Operator,
67
4.2.9. Concatenation and Replication,
67
4.3. Kinds of Expressions,
68
4.4. Exercises, 69
Chapter 5
Gate-level
Modeling 70
5.1. The Built-in Primitive Gates,
70
5.2. Multiple-input Gates,
71
5.3. Multiple-output Gates,
74
5.4. Tristate Gates, 75
5.5. Pull
Gates, 77
5.6. MOS Switches,
77
5.7. Bidirectional Switches, 80
5.8. Gate
Delays, 80
5.8.1. Min:typ:max Delay Form,
82
5.9. Array of Instances, 83
5.10. Implicit
Nets, 83
5.11. A Simple Example,
84
5.12. A 2-to-4 Decoder Example, 85
5.13. A
Master-slave Flip-flop Example, 86
5.14. A Parity
Circuit, 87
5.15. Exercises, 88
Chapter
6
User-Defined Primitives 90
6.1. Defining a UDP,
90
6.2. Combinational UDP, 91
6.3. Sequential
UDP, 93
6.3.1. Initializing the State Register,
93
6.3.2. Level-sensitive Sequential UDP,
93
6.3.3. Edge-triggered Sequential UDP,
94
6.3.4. Mixing Edge-triggered and Level-sensitive
Behavior, 95
6.4. Another Example,
96
6.5. Summary of Table Entries,
96
6.6. Exercises, 97
Chapter 7
Dataflow
Modeling 98
7.1. Continuous Assignment,
98
7.2. An Example, 100
7.3. Net Declaration
Assignment, 101
7.4. Delays,
101
7.5. Net Delays, 104
7.6. Examples,
105
7.6.1. Master-slave Flip-flop,
105
7.6.2. Magnitude Comparator,
106
7.7. Exercises, 106
Chapter 8
Behavioral
Modeling 107
8.1. Procedural Constructs,
107
8.1.1. Initial Statement,
108
8.1.2. Always Statement, 110
8.1.3. In One
Module, 112
8.2. Timing Controls,
114
8.2.1. Delay Control, 114
8.2.2. Event
Control, 116
Edge-triggered Event Control,
116
Level-sensitive Event Control, 118
8.3. Block
Statement, 119
8.3.1. Sequential Block,
119
8.3.2. Parallel Block, 121
8.4. Procedural
Assignments, 123
8.4.1. Intra-statement Delay,
125
8.4.2. Blocking Procedural Assignment,
126
8.4.3. Non-blocking Procedural Assignment,
128
8.4.4. Continuous Assignment vs Procedural Assignment,
130
8.5. Conditional Statement, 131
8.6. Case
Statement, 133
8.6.1. Don't-cares in Case,
136
8.7. Loop Statement,
136
8.7.1. Forever-loop Statement,
137
8.7.2. Repeat-loop Statement,
137
8.7.3. While-loop Statement,
138
8.7.4. For-loop Statement,
139
8.8. Procedural Continuous Assignment,
139
8.8.1. Assign - deassign, 140
8.8.2. Force
- release, 141
8.9. A Handshake Example,
143
8.10. Exercises, 145
Chapter 9
Structural
Modeling 147
9.1. Module,
147
9.2. Ports, 148
9.3. Module
Instantiation, 148
9.3.1. Unconnected Ports,
151
9.3.2. Different Port Lengths,
151
9.3.3. Module Parameter Values, 152
Defparam
Statement, 152
Module Instance Parameter Value Assignment,
153
9.4. External Ports,
155
9.5. Examples, 158
9.6. Exercises,
160
Chapter 10
Other Topics 161
10.1. Tasks,
161
10.1.1. Task Definition, 161
10.1.2. Task
Calling, 163
10.2. Functions,
165
10.2.1. Function Definition,
166
10.2.2. Function Call, 167
10.3. System
Tasks and Functions, 168
10.3.1. Display Tasks,
168
Display and Write Tasks, 168
Strobe Tasks,
170
Monitor Tasks, 171
10.3.2. File I/O
Tasks, 172
Opening and Closing Files, 172
Writing
out to a File, 173
Reading from a File,
174
10.3.3. Timescale Tasks,
175
10.3.4. Simulation Control Tasks,
176
10.3.5. Timing Check Tasks,
177
10.3.6. Simulation Time Functions,
180
10.3.7. Conversion Functions,
181
10.3.8. Probabilistic Distribution Functions,
181
10.4. Disable Statement, 183
10.5. Named
Events, 184
10.6. Mixing Structure with Behavior,
187
10.7. Hierarchical Path Name,
188
10.8. Sharing Tasks and Functions,
191
10.9. Value Change Dump (VCD) File,
193
10.9.1. An Example, 195
10.9.2. Format of
VCD File, 196
10.10. Specify Block,
198
10.11. Strengths, 201
10.11.1. Drive
Strength, 201
10.11.2. Charge Strength,
202
10.12. Race Condition,
203
10.13. Exercises, 205
Chapter
11
Verification 207
11.1. Writing a Test Bench,
207
11.2. Waveform Generation, 208
11.2.1. A
Sequence of Values, 208
11.2.2. Repetitive Patterns,
210
11.3. Testbench Examples, 216
11.3.1. A
Decoder, 216
11.3.2. A Flip-flop,
217
11.4. Reading Vectors from a Text File,
219
11.5. Writing Vectors to a Text File,
222
11.6. Some More Examples, 223
11.6.1. A
Clock Divider, 223
11.6.2. A Factorial Design,
225
11.6.3. A Sequence Detector,
229
11.7. Exercises, 231
Chapter 12
Modeling
Examples 233
12.1. Modeling Simple Elements,
233
12.2. Different Styles of Modeling,
238
12.3. Modeling Delays, 240
Transport
Delays, 243
12.4. Modeling Conditional Operations,
244
12.5. Modeling Synchronous Logic,
245
12.6. A Generic Shift Register,
249
12.7. State Machine Modeling,
250
12.8. Interacting State Machines,
253
12.9. Modeling a Moore FSM,
257
12.10. Modeling a Mealy FSM, 259
12.11. A
Simplified Blackjack Program, 261
12.12. Exercises,
264
Appendix A
Syntax
Reference 266
A.1. Keywords,
266
A.2. Syntax Conventions, 268
A.3. The
Syntax, 268
Bibliography 285
Index 287