28
Chap. 4 Modules and Ports

Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary

Embed Size (px)

Citation preview

Chap. 4 Modules and Ports

2

Modules and Ports

Modules Ports Hierarchical Names Summary

3

Modules

Basic component in Verilog for describing/defining a hardware

module <module_name> (<module_terminal_list>);<I/O declaration><parameter declaration>…<module internals>……endmodule

4

Components of Modules - I

Variables Declaration Dataflow Statement Module Instantiation Behavior Statement Tasks and Functions

5

Components of Modules - II

These components are optional!

6

An Example – SR Gate

7

Module Description of SR Gate

No “variable declaration”, “dataflow statement” and “behavioral statement” are included in this module

8

Testbench for SR Gate

9

Modules and Ports

Modules Ports Hierarchical Names Summary

10

Ports

I/O Interface used to communicate with external module

“No” port declaration if do not need to communicate with other module, such as Top module

11

Module fulladd4 has five ports while top has no port.a, b, and c_in are input ports and sum and c_out are output ports.

List of Ports - I

12

List of Ports - II

13

Port Declaration

Three types input output inout

14

Port Declaration of fulladd4

Default data type of I/O ports is regarded as “wire”.

15

Port Declaration of D Flip-Flop

16

ANSI C Port Declaration

17

Input Port Internal view - viewed as “a wire/net” External view - can be connected to a reg or wire

Output Port Internal view - declared as a reg or wire External view - only be connected to a wire

Inout Port viewed as a wire/net regardless of internal or extern

al module

Port Connection Rules - I

18

Port Connection Rules - II

19

Mismatch of internal and external port connections Simulation should issue a warning for this conditio

n Floating of port connection

Fulladd4 fa0(sum, , a, b, c_in); // c_out floating

Illegal connection of internal and external ports

Port Connection Rules - II

20

An Example of Illegal Internal/External Port Connection

21

Connecting Ports to External Signals Connecting ports by module declaration

sequence Connecting ports by name

22

Connecting Ports by Module Declaration Sequence

23

Connecting Ports by Name Fulladd4 fa_byname(.c_out(c_out), .sum(sum),

.b(b), .c_in(c_in), .a(a));

Fulladd4 fa_byname(.sum(sum), .b(b),

.c_in(c_in), .a(a));

24

Modules and Ports

Modules Ports Hierarchical Names Summary

25

Hierarchical Names

Named each instance, variables and signals in hierarchical design

Root module Never be referenced by other modules, such as

stimulus Hierarchical instances are separated by dot

sign “.” $display (“%m”)

display hierarchical level of that module

26

An Example of Hierarchical Names

27

Modules and Ports

Modules Ports Hierarchical Names Summary

28

Summary

A module contains module, endmodule keyword Port list, port declaration, variable declaration, dataflow statement,

behavioral block, module instantiation, task and function Ports provide an interface communicated with external environm

ent Input, output, inout

Connecting ports to external signals By port declaration sequence By port name

Hierarchical name Root module Separated by “.” between instances