30.04.2013 Views

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.1.3 (* synthesize *)<br />

Items contained within (* and *) are <strong>BSV</strong> attributes, used to guide the compiler in its decisions.<br />

The (*synthesize*) attribute specifies that the module that follows is synthesized separately into a<br />

hardware (Verilog) module. The top-level module of a design must be a synthesis boundary. Interior<br />

modules can also represent synthesis boundaries. The design in this example has only one module.<br />

You can also use the -g command-line flag when compiling to specify modules that are synthesis<br />

boundaries, but we recommend using the (* synthesize *) attribute in the source text instead.<br />

2.1.4 Module definition<br />

The statement:<br />

module mkTb (Empty);<br />

defines a module named mkTb providing an Empty interface. By convention, we call our modules<br />

“mkFoo”, for “make Foo”, to suggest that the module can be instantiated multiple times, possibly<br />

with different parameters. Empty is a pre-defined interface with no methods. The keyword Empty is<br />

not required, the statement could also be written as:<br />

module mkTb();<br />

<strong>BSV</strong> does not have input, output, and inout pins like Verilog and VHDL. Signals and buses are<br />

driven in and out of modules with methods; these methods are grouped together into interfaces. An<br />

Empty interface has no inputs or outputs.<br />

Modules and interfaces form the heart of <strong>BSV</strong>. Modules and interfaces turn into actual hardware.<br />

A module consists of three things: state, rules that operate on that state, and an interface to<br />

the outside world (surrounding hierarchy). A module definition specifies a scheme that can be<br />

instantiated multiple times.<br />

2.1.5 Rule<br />

The statement:<br />

rule greet;<br />

$display ("Hello World!");<br />

$finish (0);<br />

endrule<br />

defines a rule named greet with no explicit rule condition. (An explicit rule condition is a boolean<br />

expression in parentheses after the rule name; when omitted, it defaults to True.)<br />

Rules are used to describe how data is moved from one state to another, instead of the Verilog<br />

method of using always blocks. Rules have two components:<br />

• Rule conditions: Boolean expressions which determine when the rule is enabled.<br />

• Rule body: a set of actions which describe state transitions<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!