VLA 27 0.secured - Lab
VLA 27 0.secured - Lab
VLA 27 0.secured - Lab
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 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:
The publication may be used solely for personal, informational, and noncommercial purposes;
The publication may not be modified in any way;
Any copy of the publication or portion thereof must include all original copyright, trademark, and other proprietary
notices and this permission statement; and
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 customers in accordance with, a written
agreement between Cadence and the 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.
2 January 3, 2022
(c) Cadence Design Systems Inc. Do not distribute.
Table of Contents
Verilog Language and Application
Module 1: About This Course .......................................................................................................................... 7
There are no labs for this module. ..................................................................................................... 9
Module 21: Using System Tasks and System Functions .............................................................................. 105
Lab 21-1 Adding System Tasks and System Functions to a Beverage Dispenser Design ..................... 107
Specifications ................................................................................................................................ 107
Designing a Beverage Dispenser FSM Design ............................................................................. 108
Verifying the Serial-to-Parallel ..................................................................................................... 109
Objective: To understand and become familiar with the VeriRISC lab model.
The VeriRISC model is a very-reduced-instruction-set processor coded in the Verilog HDL. Its
instruction consists of a three-bit operation code and a five-bit operand. That restricts its instruction
set to eight instructions and its address space to 32 locations. To simplify visualization and debug, it
implements the fetch-and-execute cycle in eight phases.
As an exercise, you can easily reduce this to two phases, or with a dual-port memory, to one phase.
Input to the model is a clock and a reset, and output from the model is a halt signal. Tests determine
pass or fail status by the number of clocks the program consumes. Spend some time and
understand the architecture of VeriRISC in this lab. Do not worry about implementation and
simulation at this point. You will be implementing and testing this architecture in further labs.
clk clk
rst register_ac: register_ir:
accumulator rst
ld_ac instruction
register sel
ld_ir
ac_out data
ir_addr
opcode
alu_inst:
alu clk address_mux:
rst multiplexor
counter_pc:
alu_out pc_addr
ld_pc program
counter clk
inc_pc
zero
rd
wr
addr
ld_ir
ld_ac
controller_inst:: ld_pc memory_inst::
controller inc_pc memory
clk
counter_clk: phase halt
phase data_e data
rst generator
sel
The upcoming labs until Lab 12-1 are based on the above design. In each of these labs, you develop
and verify individual components of the VeryRISC processor like Address Multiplexor, Counter,
Controller, Register, ALU, etc. In Lab 12-1, you verify the complete design for a few basic
instructions under consideration.
In this lab, you create a simple multiplexor design using Verilog constructs and verify it using the
supplied testbench.
You will create the MUX design as per the specification and verify it using the provided testbench.
Please make sure to use the same variable name as the ones shown in block diagrams.
sel
5
in0
5
Multiplexor
mux_out
5
in1
Specifications
The address multiplexor selects between the instruction address during the instruction
fetch phase and the operand address during the instruction execution phase.
2. Create the multiplexor.v file, and using your favorite editor, describe the multiplexor
module named “multiplexor”.
3. Parameterize the multiplexor input and output widths and assign a default value of 5.
1. Using the provided test module, check your multiplexor design using the following
command with Xcelium™.
xrun multiplexor.v multiplexor_test.v (Batch Mode)
or
xrun multiplexor.v multiplexor_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
The driver output is equal to the input value when enabled (data_en is true) and is high-impedance
when not enabled (data_en is false).
In this lab, you create a data driver as per the specification and verify it using the provided testbench.
Please make sure to use the same variable name as the ones shown in block diagrams.
8 8
data_en
Specifications
2. Create the driver.v file, and using your favorite editor, describe the driver module
named “driver”.
3. Parameterize the driver input and output width and assign a default value of 8.
1. Using the provided testbench module, check your driver design using the following
command with Xcelium™.
xrun driver.v driver_test.v (Batch Mode)
or
xrun driver.v driver_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
ALU performs arithmetic operations on numbers depending upon the operation encoded in the
instruction. This ALU will perform 8 operations on the 8-bit inputs (see table in the Specification)
and generate an 8-bit output and single-bit output.
In this lab, you create an ALU design as per the specification and verify it using the provided
testbench. Please make sure to use the same variable name as the ones shown in block diagrams.
parameter WIDTH=8
8
in_a 8
8 alu_out
in_b
ALU
3
a_is_zero
opcode
Specifications
in_a, in_b, and alu_out are all 8-bit long. The opcode is a 3-bit value for
the CPU operation code, as defined in the following table.
a_is_zero is a single bit asynchronous output with a value of 1 when in_a equals
0. Otherwise, a_is_zero is 0.
The output alu_out value will depend on the opcode value as per the following
table.
To select which of the 8 operations to perform, you will use opcode as the selection
lines.
The following table states the opcode/instruction, opcode encoding, operation, and
output.
Designing an ALU
2. Use your favorite editor to create the alu.v file. Describe the ALU module named as
alu.
a. Parameterize the ALU input and output width so that the instantiating module can
specify the width of each instance.
1. Using the provided testbench module, check your ALU design using the following
command with Xcelium™.
xrun alu.v alu_test.v (Batch Mode)
or
xrun alu.v alu_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
The controller generates all control signals for the VeriRISC CPU. The operation code, fetch-and-
execute phase, and whether the accumulator is zero determine the control signal levels.
rst
zero sel
rd
ld_ir
Phase Controller halt
inc_pc
ld_ac
Opcode
wr
ld_pc
clk
data_e
Specifications
zero is an input which is 1 when the CPU accumulator is zero and 0 otherwise.
opcode is a 3-bit input for CPU operation, as shown in the following table.
Output Function
sel select
rd memory read
halt halt
wr memory write
The controller has a single-bit phase input with a total of 8 phases processed. Phase
transitions are unconditional, i.e., the controller passes through the same 8-phase
sequence, from INST_ADDR to STORE, every 8 clk cycles. The reset state is
INST_ADDR.
rst
INST_ADDR
STORE INST_FETCH
ALU_OP INST_LOAD
OP_FETCH IDLE
OP_ADDR
The controller outputs will be decoded w.r.t phase and opcode, as shown in this table.
Designing a Controller
2. Use your favorite editor to create the controller.v file and describe the controller
module named “control ”.
3. Declare a reg for each of these intermediate terms and establish their value
immediately before entering the case statement.
1. Using the provided test module, check your controller design using the following
command with Xcelium™.
xrun controller.v controller_test.v (Batch Mode)
or
xrun controller.v controller_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
The VeriRISC CPU contains an accumulator register and an instruction register. One generic register
definition can serve both purposes.
In this lab, you create a simple register design as per the specification and verify it using the
provided testbench. Please make sure to use the same variable name as the ones shown in block
diagrams.
8
data_in
8
clk
rst
Specifications
Designing a Register
2. Use your favorite editor to create the register.v file and to describe the register
module named “register ”.
a. Parameterize the register data input and output width so that the instantiating
module can specify the width of each instance.
c. Write the register model using the Verilog always procedural block.
1. Using the provided test module, check your register design using the following
command with Xcelium™.
xrun register.v register_test.v (Batch Mode)
or
xrun register.v register_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
The VeriRISC CPU uses the same memory for instructions and data. The memory has a single
bidirectional data port and separate write and read control inputs. It cannot perform simultaneous
write and read operations.
In this lab, you create a simple register design as per the specification and verify it using the
provided testbench. Please make sure to use the same variable name as the ones shown in block
diagrams.
parameter AWIDTH=5
parameter DWIDTH=8
5 8
clk wr rd
Specifications
Analyze the memory read and write operation timing diagram, as shown in the
following graphic.
write
read
clk
write
read
Designing a Memory
2. Use your favorite editor to create the memory.v file and to describe the memory
module named “memory “.
3. Parameterize the address and data widths so that the instantiating module can specify
the width and depth of each instance.
5. Write data on the active clock edge when the wr input is true and drive data when the
rd input is true.
6. Perform the write operation in a procedural block and perform the read operation as a
continuous assignment.
1. Using the provided test module, check your memory design using the following
command with Xcelium™.
xrun memory.v memory_test.v (Batch Mode)
or
xrun memory.v memory_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
The VeriRISC CPU contains a program counter and a phase counter. One generic counter definition
can serve both purposes.
In this lab, you create a simple register design as per the specification and verify it using the
provided testbench. Please make sure to use the same variable name as the ones shown in block
diagrams.
5 5
cnt_in cnt_out
enab Counter
load
clk
rst
Specifications
2. Use your favorite editor to create the counter.v file and to describe the counter
module named as “counter ”.
3. Parameterize the counter data input and output width so that the instantiating module
can specify the width of each instance. Assign a default value to the parameter.
1. Using the provided test module, check your counter design using the following
command with Xcelium™.
xrun counter.v counter_test.v (Batch Mode)
or
xrun counter.v counter_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
You typically use a function to encapsulate an operation performed multiple times with multiple
different sets of operands. Encapsulating functionality reduces code “bloat” to make it more
understandable and thus more reusable.
In this lab, you create a counter design as per the specification using functions to practice the
construct and verify it using the provided testbench. Please make sure to use the same variable name
as the ones shown in block diagrams.
5
cnt_in
5
enab
cnt_out
Counter
load
clk
rst
Specifications
Designing a Counter
2. Use your favorite editor to modify the counter.v file name it as “counter”.
3. Describe the combinational logic of the counter using functional block. You can use
an 'if' construct to model the counter combinational block.
1. Using the test module, to test your counter design using the following command with
Xcelium™.
xrun counter.v counter_test.v (Batch Mode)
or
xrun counter.v counter_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
You typically use a function to encapsulate an operation performed multiple times with multiple
different sets of operands. Encapsulating functionality reduces code “bloat” to make it more
understandable and thus more reusable.
In this lab, you create a memory design as per the specification using tasks to practice the construct
and verify it using the provided testbench. Please make sure to use the same variable name as the
ones shown in block diagrams.
parameter AWIDTH=5
parameter DWIDTH=8
5 memory 8
addr data
clk wr rd
Specifications
Analyze memory read and write operation timing diagram given in Lab 9-1.
2. Use your favorite editor to modify the memory_test.v file to code the write procedure
and read procedure using tasks.
3. In the memory test block, call the appropriate read and write tasks to verify the
memory block.
Note: The statement sets that you code read and write procedures given the
following task calls.
For write: wr=1; rd=0; memory_test.addr=addr; rdata=data; @(negedge
clk);
For read: wr=0; rd=1; memory_test.addr=addr; rdata='bz; @(negedge
clk) expect(data);
1. Using the provided test module, check your counter design using the following
command with Xcelium™.
xrun memory.v memory_test.v (Batch Mode)
or
xrun memory.v memory_test.v -gui -access +rwc ( GUI Mode)
2. You might find it easier to list all the files and simulation options in a text file and
pass the file into the simulator using the –f xrun option.
xrun -f filelist.txt -access rwc
At the behavioral level of abstraction, you code behavior with no regard for an actual hardware
implementation, so you can utilize any Verilog construct. The behavioral level of abstraction is
useful for exploring design architecture and especially useful for developing test benches. As both
uses are beyond the scope of this training module, it only briefly introduces testbench concepts.
Read the specification first and then follow the instructions provided.
Specifications
The MUX (mux) selects between the program address or the address field of the
instruction.
The Memory (memory) accepts data and provides instructions and data.
The ALU (alu) accepts memory and accumulator data, and the opcode field of the
instruction, and provides new data to the accumulator and memory.
5. Store results back into either the memory or the accumulator. This process is repeated
for every instruction in a program until an HLT instruction is found.
2. Review the supplied testbench in the file risc_test.sv. The testbench verifies
your CPU design using three diagnostic programs as follows.
CPUtest1.txt (Basic Test) – This diagnostic program tests the basic instruction set of the
VeriRisc system. If the system executes each instruction correctly, then it should halt
when the HLT instruction at address 17(hex) is executed. If the system halts at any other
location, then an instruction did not execute properly. Refer to the comments in this file
to see which instruction failed.
CPUtest2.txt (Advanced Test) – This diagnostic program tests the advanced instruction
set of the VeriRisc system. If the system executes each instruction correctly, then it
should halt when the HLT instruction at address 10(hex) is executed. If the system halts
at any other location, then an instruction did not execute properly. Refer to the comments
in this file to see which instruction failed.
CPUtest3.txt (Fibonacci Calculator) – This is an actual program that calculates the
Fibonacci number sequence from 0 to 144. The Fibonacci number sequence is a series of
numbers in which each number in the sequence is the sum of the preceding two numbers
(i.e., 0, 1, 1, 2, 3, 5, 8, 13 ...). If all the instructions execute correctly, the CPU will
encounter an HLT instruction at Program Counter address 0x0C. If the CPU halts at some
other address, then an instruction did not execute properly. Refer to the comments in this
file to see which instruction failed.
3. Use your favorite editor to modify the risc_test.v file to complete the RISC
verification environment to verify the JMP instructions only. In the file comments
are mentioned where code needs to be added; also, you can refer to the SKZ
instruction.
Please follow the comments in the risc_test.v file.
4. Using the following command with Xcelium, simulate the design and testbench.
xrun -f files.txt (Batch Mode)
Objective: To briefly observe the synthesis process and examine the results.
In this lab, you synthesize a small multiplexor model and examine the synthesis results
select
>= 3 == 2 <= 1
? 0 0 0
mux_out
1 1 1
clock
in3 in2 in1
Important Information
2. Verify the RTL model using the the commands with Xcelium™.
xrun mux.v mux_test.v (Batch Mode)
3. Synthesize the RTL model by using the Genus™ Synthesis Solution tool.
genus -f genus_shell.tcl
4. In your favorite editor, examine the mux.vs pre-synthesis netlist and attempt to
correlate its contents with the multiplexor behavioral description.
How many multiplexors does it contain?
Answer: _______________
How many operators does it contain?
Answer: _______________
How many latches does it contain?
Answer: _______________
5. In your favorite editor, examine the mux.vg post-synthesis netlist and attempt to
correlate its contents with the multiplexor behavioral description.
How many multiplexors does it contain?
Answer: _______________
How many operators does it contain?
Answer: _______________
How many latches does it contain?
Answer: _______________
6. Verify the gate-level model using the following commands with Xcelium.
xrun mux.vg mux_test.v -v ../tutorial.v -vlogext vg
7. Save the mux.vs and mux.vg as mux_ifdef.vs and mux_ifdef.vg for future comparison
with the USE_CASE version.
8. Again, verify the RTL model but this time use the following commands with
Xcelium.
xrun mux.v mux_test.v -define USE_CASE
9. Synthesize the design again and examine the pre-synthesis and post-synthesis netlists.
For this model, does coding style significantly affect the pre-synthesis netlist?
Answer: ______________
For this model, does coding style significantly affect the post-synthesis netlist?
Answer: ______________
In this lab, you will code and synthesize some representative models.
d latchrs q
a7 drive8 y7
e
a7 priority7 a6 y6
a6 a5 y5
r
a5 a4 y4
y2
a4 a3 y3
y1
s a2 y2
a3 y0
a2 a1 y1
dffrs
d q
a1 a0 y0
e
e
c
Note: To facilitate your development effort, the library and tests can conditionally
compile and test individual models. You specify the models and tests to
compile by defining some combination of the priority7, latchrs, dffrs, and
drive8 macros on the invocation command line, as described in the previous
lab. If you do not specify any, then all are compiled and tested.
2. In your favorite editor, modify the lib.v file to complete the model definitions. Set and
reset are asynchronous and active low. You can elect to individually complete and
test each model.
Note: From the latch template, the synthesis tool cannot infer an asynchronous set or
reset. The latch model includes the async_set_reset pragma to specify the
signals to directly connect to the component’s asynchronous set and reset pins.
3. Verify the RTL model(s) using the following commands with Xcelium™.
a. Fill in the macro name (or omit the option to test all models).
xrun lib.v lib_test.v -define macrolib (Batch Mode)
5. When all models pass their test, synthesize the RTL models by using the Genus™
Synthesis Solution tool.
genus -f genus_shell.tcl
6. Verify the gate-level models using the following commands with Xcelium.
xrun *.vg lib_test.v -v ../tutorial.v -vlogext vg -define macrolib
a. Fill in the macro name (or omit the option to test all models).
c. If any model fails its test, then you can ask the instructor for help or try again after
you study the lecture module Avoiding Simulation Mismatches.
In this lab, you code the serial-to-parallel interface receiver as an FSM in different styles. Instead of
shifting the matching character, the FSM steps to the next state upon receiving a correct match bit
and returns to a previous state while receiving an incorrect match bit.
Read the specification first and then follow the instructions in this lab. Please make sure to use the
same variable name as the ones shown in block diagrams.
data_out
clock
output_reg
reset
clock
body_reg
reset
data_in
ready
clock control overrun
{FSM, ready, overrun}
reading
Specifications
data_out is an 8-bit output signal, whereas ready and overrun are 1-bit output.
Every serial bit transmission has a preamble that needs to be sent before sending the
character. For this lab, the preamble value is fixed to 8’hA5.
3. In your favorite editor, modify the rcvr.v file to comply with the coding style.
1. Verify the RTL model using the following commands with Xcelium™.
xrun rcvr.v rcvr_test.v (Batch Mode)
4. When all models pass their test, synthesize the RTL model using the Genus™
Synthesis Solution.
genus -f genus_shell.tcl
5. Check to see that the synthesis succeeded. Correct your model until it is synthesized.
6. Verify the gate-level model using the following commands with Xcelium.
xrun rcvr.vg rcvr_test.v -v ../tutorial.v -vlogext vg
7. Check to see the messages I Love Verilog and TEST PASSED as above. If the model
fails its test, then you can ask the instructor for help or try again after you study the
lecture module Avoiding Simulation Mismatches.
In this lab, you code a moderately difficult Verilog design for synthesis. Read the specification first
and then follow the instructions in the lab section. Please make sure to use the same variable name as
the ones shown in block diagrams.
data_out
clock
output_reg
control
clock
body_reg
control
data_in
clock
head_reg
control
ready
clock
control overrun
{phase, match, count, ready, overrun}
reading
Specifications
data_out is an 8-bit output signal, whereas ready and overrun are 1-bit output.
a. The receiver searches the serial input stream for a match character, and when
found, loads the next serial input character to the output buffer, asserts a “ready”
flag, and immediately searches for the next match. Modeling the individual parts
of the receiver is like modeling individual components.
2. In your favorite editor, modify the rcvr.v file to complete the receiver definition.
Verify the RTL model using the following commands with Xcelium™.
xrun rcvr.v rcvr_test.v
3. When all models pass their test, synthesize the RTL model by entering:
genus -f genus_shell.tcl
4. Verify the gate-level model using the following commands with Xcelium.
xrun rcvr.vg rcvr_test.v -v ../tutorial.v -vlogext vg
Check to see the messages I Love Verilog and TEST PASSED similar to, as shown above.
If the model fails its test, then you can ask the instructor for help or try again after you
study the lecture module Avoiding Simulation Mismatches.
You will frequently encounter the situation where the test environment waits an undetermined time
for the system being tested to respond to some stimulus. The system might malfunction so that it
does not ever respond. The test must anticipate this failure mode and report it.
The lab model is an arbiter that arbitrates between two users of a resource. The arbiter prioritizes the
requests for the resource. The lab does not model the resource.
The test environment is two instances of the arbiter and two instances of the device making the
requests. The device at random intervals requires one or both resources. It requests the first resource,
and upon being granted the first resource, sometimes also requests a second resource. Due to the
random nature of the requests, the simulation will invariably eventually come to a point at which
both devices have one resource and cannot continue until they have the second resource – hence both
become “deadlocked.”
REQ/GNT
bridge
2. Simulate the test case using the following commands with Xcelium™.
xrun test.v
Note: The r column is the requester 1 and requester 2 requests and the g column is
the requester 1 and requester 2 grants. The test is limited to 99ns, which is
probably sufficient to develop a deadlock.
a. Define a watchdog task that after a reasonable amount of time (the solution uses
17ns) drops both request signals and disables the request loop (the request loop
will immediately automatically restart).
b. Each place where the requester waits for a request to be granted, replace the wait
statement with a block that does two things in parallel:
Enables the watchdog task
Waits for the grant, and when the grant occurs, disable the watchdog task
5. Simulate the test case as before and correct any reported errors.
The lab model is a beverage dispenser (drink machine). Read the specification first and then follow
the instructions in the lab section. Please make sure to use the same variable name as the ones shown
in block diagrams.
DIME_IN
NICKEL_OUT
COIN
DIME_OUT
COUNTER
QUARTER_IN USE_EXACT
FSM
Specifications
The drink machine operates on the positive clock edge and has a synchronous high-
active reset.
After resetting the machine, you load it with coins and cans.
This drink machine has no coin return feature and inserted coins are not available
later as change.
If the EMPTY signal is true, then you lose any coins you insert.
If the USE_EXACT signal is true, then you might find yourself short-changed.
Drink Machine State Table: Models the behavior for accepting coins and dispensing
drinks:
▪ Amount of money that the user has deposited so far defines the current state.
▪ The type of coin that the user deposits determines the machine’s next state.
dkm.v DUT
test.v Test(incomplete)
Note: The test developer developed the test in a top-down manner, determining and
coding top-level tasks first, then subtasks, and then more subtasks. Only the
lowest-level tasks actually interact with the machine. You can also adopt this
approach to test development.
2. Design and test are given; you have to modify the test file as instructed.
a. Improve the expect() task so that it displays an error message and displays each
machine output that is erroneous.
d. Add a monitor code in the test file with the following functionality.
i. Monitors drink machine inputs and outputs to a disk file. The monitor should
print the simulation time of each signal change and should use the %t formatter
so that the printed time value takes a fixed number of columns.
ii. Dumps all top-level drink machine nets and variables into a VCD file.
iii. Dumps all drink machine ports to an extended VCD file.
Simulate the design and test using the following commands with Xcelium.
xrun dkm.v test.v (Batch Mode)
or
xrun dkm.v test.v -gui -access +rwc ( GUI Mode)
3. If you have sufficient remaining lab time, add the interactive test by adding the
+INTERACTIVE=1 invocation option. The interactive test should add some cans and
coins and then, in a loop, repeatedly request the user to insert a coin. Your code can
read an input character, discard the remainder of the input line, and, depending upon
the character, insert a nickel, dime, or quarter. Your code should check and report the
machine outputs after each can is dispensed. You may find the following information
useful.
4. Simulate the design and test and correct the test as needed.
5. Load the VCD file into a graphical simulation analysis environment by entering:
simvision your_dumpfile_name
The lab model is a serial interface receiver. The receiver interfaces between a serial input stream and
a parallel output stream.
In this lab, read the specification first and then follow the instructions. Please make sure to use the
same variable name as the ones shown in block diagrams.
Specifications
The receiver operates on the positive edge of the serial clock SCLK and has a
synchronous active-high reset RST.
The receiver initially shifts input data left into the header register until it detects the
header value.
For this reason, the header register must be initialized to a value opposite the leftmost
header value bit.
Upon detecting the packet header, the receiver clears the header register and shifts
input data left into the body register while counting to 16.
Upon the 16th count, the receiver moves the data to the output buffer, clears the
counter, asserts the ready output, and again shifts input data left into the header
register. The receiver can thus move a packet every 24 clocks.
data_out
SCLK
buffer
RST
SCLK
body
RST
SDATA
SCLK
header
RST
READY
SCLK
control
{state, count, rdycnt}
ACK
1. The test environment reads the leftmost buffer byte while acknowledging the ready
signal. The receiver shifts the output buffer left by one byte upon each such
acknowledgment. The receiver counts acknowledge and drop the ready signal upon
the last acknowledge. The test environment can delay the last acknowledge up to and
including the clock that loads the next data into the output buffer. Failure of the test
environment to retrieve data within that interval results in lost data.
2. In this lab, you have to generate a simple test of the serial interface receiver, which
generates random data for four packets.
3. You statically construct a 256-bit stream containing four valid packets that are
surrounded by values other than the header value.
5. You reset the receiver and give this stream as an input to the receiver inputs. While
adhering to the output protocol, you retrieve the receiver output data and verify that
all packets are received and correct.
rcvr.v DUT
2. Simulate the design and test using the following commands with Xcelium.
xrun rcvr.v your_test_file_name -access +rwc
Objective: To interactively select and download test microcode and run it.
The lab model is a VeriRISC CPU. In the Lab-12 specification, the CPU architecture and operation
is explained. In this specification, a few more operations are explained.
Read the specification first and then follow the instructions in the lab.
Specifications
The 8-bit CPU instruction consists of a 3-bit leftmost operation code encoding eight
instructions.
rvalue
program
memory
counter
(mem)
(pc)
instr ALU
CLK RST
accumulator
(ac)
CLK operand
opcode
CLK
control
HALT
1. In the previous block diagram, you can observe the CPU has only HALT as output.
2. The testbench environment can detect program failure only by detecting that the CPU
halted at an incorrect address.
3. This lab provides three programs with incremental levels of complexity that halt
(when operating correctly) at different program counter values:
For program 1 halt value is – 0x17
For program 2 halt value is – 0x10
For program 3 halt value is – 0x0c
4. You have to code the specified testbench, which can have well-defined tasks for the
smoother execution of the programs.
a. First, code a task displaying an initial message informing the user what
commands to use to operate the test. You can write the task by using the
following interactive command in which you have to place a value in a test
register.
5. Code a task to run a program in which the task creates a filename (which is a string)
by concatenating the value of a register/variable that the user sets by using the deposit
command. In the lab directory, you can see the txt filename convention that you use
to name the programs such as PROGn.txt.
Note: The ASCII value of the 0 character is 0x30 so your concatenation would be
something like {"PROG", 8 'h30 + test_number_reg, ".txt "}.
6. Load that program file into the CPU memory. Reset the CPU. To avoid a clock/data
race, you can move the reset signal on the opposite clock edge in which the CPU
works (use negedge). After reset, the CPU automatically starts executing at location 0.
7. Code a task displaying a final message informing the user of the program counter
address where the CPU halted and whether that is correct.
10. Code a procedural block that upon every assertion of the HALT signal:
2. Code the specified test with well-defined tasks for the smoother execution of the
programs.
3. Simulate the design and test using the following commands with Xcelium.
xrun cpu.v your_test_file_name -access +rwc
4. Execute the following commands and compare the outputs after each run.
xcelium> deposit test.run.number 1; task test.run; run
Halted at address = 17
Expected address = 17
TEST PASSED
It is possible to define a set of instructions by which the operation of a testbench can be controlled.
This collection of user-defined instructions is often called “Pseudo-code” and a testbench usually
reads these instructions from a text file. This type of testbench is also called a script-driven
testbench. The testbench is written to interpret the text of each instruction and then perform that
operation. You will see an example in this lab.
One issue that we have to remember is that the user-defined instructions are more likely to be written
by hand, and therefore contain errors than a file of stimulus data created by, for example, a graphics
package. Therefore, our testbench needs to carefully check the instruction data it is trying to read. In
this lab, you write a Verilog 1995 vreadmem_test.v that uses the system task $readmemh for getting
the required commands from a data.txt into the procedure call within the testbench.
2. In the incomplete module, comments are given to write a procedure using the system
task $readmemh to get the commands from data.txt into the cmdarray “cmdarr”
defined.
3. Create a loop (using the if statement) wherein 8 commands are read, corresponding to
each bit of the cmdarray, and then when encountered, the 16'bx or Fh displays “end of
commands” and then stops reading using $stop.
4. In the next part of the loop, check for the SEND, ADDR, NEXT commands (using
the case statement) and create respective tasks. Have the default display as “unknown
command” for any other command encountered.
5. Simulate the design and test using the following commands with Xcelium.
xrun vreadmem_test95.v
For this testbench, write a Verilog 2001 vfopen_test.v that uses the system task $fopen to get the file
containing the cmds to be opened by the procedure call within the testbench.
The declarations of necessary variables and a set of tasks have been created in the testbench file.
Follow the instructions in the comments in the vfopen_test2001.v and vreadmem_test95.v tests and
create the procedures using readmemh and fopen to get the data.txt and cmd.txt into the procedures
within the testbenches, respectively.
2. Given the test file is incomplete, follow the comments inside to write a procedure
using the system task $fopen to get the commands from given cmd.txt.
Note: Use variable fid = fopen the cmd.txt.
3. Use the while condition with $feof to check that it is not the end-of-file of fid, then
scanf the cmd and addr using $fscanf.
4. In the second part of the loop, for cmd SEND, ADDR, NEXT, use the above tasks
created. If any other cmd is encountered, have a default display "unknown
command".
5. Simulate the design and test using the following commands with Xcelium.
xrun vfopen_test2001
Appendix A: Configurations
(c) Cadence Design Systems Inc. Do not distribute.
(c) Cadence Design Systems Inc. Do not distribute.
Configurations
Objective: To use a library map file to define a configuration that includes at least
one gate-level component.
Verilog configurations provide a standard portable way to select among multiple implementations of
components stored in multiple libraries to assemble a simulation. The multiple implementations can
be, for example, different levels of abstraction or different internal functionality, or different speeds.
This lab provides a library of components duplicating all components you have previously
developed for this training. The library components are coded using accelerated Verilog primitives.
Your configuration can specify to use any of these components except the memory, as the test does
not know how to download a program into a gate-level memory.
2. Create the libmap.txt file and use your favorite editor to define the library mapping
and configuration. This file is partially provided below to help you get started.
library celllib cell_lib.v;
library projlib proj_lib.v;
library worklib "../.../*";
config risc_test;
design worklib.risc_test;
default liblist worklib projlib celllib;
// TO DO: FOR SOME SET OF RISC CELLS OR INSTANCES USE THE PROJECT
LIBRARY.
// FOR THE MEMORY YOU MUST STILL USE THE DEFAULT WORK LIBRARY.
endconfig
The -libverbose option logs verbose elaboration information. The -top option causes the
risc_test configuration to elaborate instead of the risc_test unit.
5. Examine the log file to verify that the elaborator bound the specified gate-level units.
For this lab, you modify a provided macro library file to replace the RTL descriptions with
descriptions based upon the Verilog built-in primitives.
SN
CK
QN
DFFRS - TTL
D
RN
ck SN ckn RN
Q
D
ckn ck QN
ckn ck
RN SN
CK ck ck ckn
DFFRS - CMOS
ckn
2. Verify the RTL technology library for each test using the following commands with
Xcelium.
xrun testdir/test_name.v -v techlib.v
3. Modify the macro library file to replace the RTL descriptions with descriptions based
on the Verilog built-in primitives. Refer as needed to the flip-flop diagrams on the
first page of this lab. The first diagram is of a positive edge-triggered TTL flip-flop.
Replace the nand primitives with nor primitives to create a negative edge-triggered
TTL flip-flop. The second diagram is of a positive pulse-triggered CMOS master-
slave flip-flop. Do not overly concern yourself with whether it is the preset or the
reset that “wins” because no synthesis tool will activate them both simultaneously.
A user-defined Verilog primitive (UDP) is essentially a look-up table (LUT). The LUT requires
substantial memory, so you generally define a UDP only to replace several built-in primitives,
especially if the module is instantiated multiple times.
For this lab, you modify the macro library file further to define a sequential flip-flop UDP and to
replace the primitive-based flip-flops with UDP-based flip-flops.
b. Modify the flip-flop descriptions to instantiate the UDP instead of the built-in
primitives. Invert the clock where needed. Tie off unused preset and/or reset
inputs. Buffer the Q and QN outputs.
3. Verify the RTL technology library for each test using the following commands with
Xcelium.
xrun testdir/test_name.v -v techlib.v
In this lab, you annotate timing data to a design. The design is a serial interface receiver. It receives
characters serially and transmits them in parallel.
rcvr_test.v Test
rcvr.sdf Timing
2. Simulate the RTL design and test using the following commands with Xcelium.
xrun rcvr.v rcvr_test.v
3. Copy your modified technology library from the previous lab. If you have not
completed the lab, then copy the technology library from its solutions directory.
4. Simulate the gate-level design and test using the following commands with Xcelium.
xrun rcvr.vg rcvr_test.v -timescale 1ns/10ps -v techlib.v -vlogext vg
The -timescale option provides a default timescale for the gate-level description.
The -vlogext option registers an additional Verilog file extension.
Check that you have multiple hold violations and that you see TEST TIMEOUT.
d. Verify that these are the maximum delays the library specifies for this type.
6. In an initial block at time 0, modify the test to annotate the timing in the rcvr.sdf file
to the receiver instance.
7. Use the graphical simulation analysis environment (as before) to verify the annotated
body_reg_reg[0] propagation delay.
8. Verify that these are the maximum delays that the rcvr.sdf file specifies for this
instance.