├── .gitignore ├── 02_Conventional_Testbench ├── dut.f ├── run.do ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_tb.sv └── wave.do ├── 03_Interfaces_and_BFMs ├── coverage.sv ├── dut.f ├── run.do ├── scoreboard.sv ├── tb.f ├── tester.sv ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_pkg.sv └── top.sv ├── 05_Classes_and_Extension ├── classes.sv ├── rectangle_only.sv ├── run_class.do ├── run_rectangle.do ├── run_struct.do ├── structs.sv └── sv.f ├── 06_Polymorphism ├── 01_Not_Virtual │ ├── not_virtual.sv │ ├── run.do │ └── sv.f ├── 02_Virtual │ ├── run.do │ ├── sv.f │ └── virtual.sv └── 03_Pure_Virtual │ ├── pure_virtual.sv │ ├── run.do │ └── sv.f ├── 07_Static_Methods ├── 01_Static_Variables │ ├── run.do │ ├── static_variables.sv │ └── sv.f └── 02_Static_Methods │ ├── run.do │ ├── static_methods.sv │ └── sv.f ├── 08_Parameterized_Classes ├── 01_memory_example │ ├── ram.sv │ ├── run.do │ └── top.sv ├── 02_static │ ├── cages.sv │ ├── run.do │ └── sv.f └── 03_instantiated │ ├── cages.sv │ ├── run.do │ └── sv.f ├── 09_Factory_Pattern ├── factory.sv ├── run.do └── sv.f ├── 10_An_Object_Oriented_Testbench ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── coverage.svh │ ├── scoreboard.svh │ ├── testbench.svh │ └── tester.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 11_UVM_Test ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── coverage.svh │ ├── random_test.svh │ ├── random_tester.svh │ ├── scoreboard.svh │ └── selfcheck.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 12_UVM_Components ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── coverage.svh │ ├── random_test.svh │ ├── random_tester.svh │ └── scoreboard.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 13_UVM_Environments ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── base_tester.svh │ ├── coverage.svh │ ├── env.svh │ ├── random_test.svh │ ├── random_tester.svh │ ├── scoreboard.svh │ └── vcs_base_tester.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 15_Talking_Objects ├── 01_No_Analysis_Port │ ├── #dice_test.svh# │ ├── average.svh │ ├── coverage.svh │ ├── dice_pkg.sv │ ├── dice_roller.svh │ ├── dice_test.svh │ ├── histogram.svh │ ├── run.do │ └── top.sv └── 02_With_Analysis_Port │ ├── average.svh │ ├── coverage.svh │ ├── dice_pkg.sv │ ├── dice_roller.svh │ ├── dice_test.svh │ ├── histogram.svh │ ├── run.do │ └── top.sv ├── 16_Analysis_Ports_In_the_Testbench ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── base_tester.svh │ ├── command_monitor.svh │ ├── coverage.svh │ ├── env.svh │ ├── random_test.svh │ ├── random_tester.svh │ ├── result_monitor.svh │ ├── scoreboard.svh │ └── vcs_base_tester.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 17_Interthread_Communication ├── 01_Modules │ ├── modules.sv │ └── run.do ├── 02_Blocking │ ├── communication_test.svh │ ├── consumer.svh │ ├── example_pkg.sv │ ├── producer.svh │ ├── run.do │ └── top.sv └── 03_NonBlocking │ ├── communication_test.svh │ ├── consumer.svh │ ├── example_pkg.sv │ ├── producer.svh │ ├── run.do │ └── top.sv ├── 18_Put_and_Get_in_Action ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── base_tester.svh │ ├── command_monitor.svh │ ├── coverage.svh │ ├── driver.svh │ ├── env.svh │ ├── random_test.svh │ ├── random_tester.svh │ ├── result_monitor.svh │ ├── scoreboard.svh │ └── vcs_base_tester.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 19_UVM_Reporting ├── dut.f ├── run.do ├── run.txt ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_tester.svh │ ├── base_tester.svh │ ├── command_monitor.svh │ ├── coverage.svh │ ├── driver.svh │ ├── env.svh │ ├── random_test.svh │ ├── random_tester.svh │ ├── result_monitor.svh │ ├── scoreboard.svh │ └── vcs_base_tester.svh ├── tinyalu_bfm.sv ├── tinyalu_driver_c.svh ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv ├── tinyalu_tlm_bfm.sv └── top.sv ├── 20_Deep_Operations ├── deep.sv ├── run.do ├── sv.f └── wrong.sv ├── 21_UVM_Transactions ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_test.svh │ ├── add_transaction.svh │ ├── command_monitor.svh │ ├── command_transaction.svh │ ├── coverage.svh │ ├── driver.svh │ ├── env.svh │ ├── random_test.svh │ ├── result_monitor.svh │ ├── result_transaction.svh │ ├── scoreboard.svh │ └── tester.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── 22_UVM_Agents ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_transaction.svh │ ├── command_monitor.svh │ ├── command_transaction.svh │ ├── coverage.svh │ ├── driver.svh │ ├── dual_test.svh │ ├── env.svh │ ├── env_config.svh │ ├── result_monitor.svh │ ├── result_transaction.svh │ ├── scoreboard.svh │ ├── tester.svh │ ├── tinyalu_agent.svh │ └── tinyalu_agent_config.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv ├── tinyalu_tester_module.sv └── top.sv ├── 23_UVM_Sequences ├── dut.f ├── run.do ├── tb.f ├── tb_classes │ ├── add_sequence.svh │ ├── add_sequence_item.svh │ ├── command_monitor.svh │ ├── coverage.svh │ ├── driver.svh │ ├── env.svh │ ├── fibonacci_sequence.svh │ ├── fibonacci_test.svh │ ├── full_test.svh │ ├── maxmult_sequence.svh │ ├── parallel_sequence.svh │ ├── parallel_test.svh │ ├── random_sequence.svh │ ├── reset_sequence.svh │ ├── result_monitor.svh │ ├── result_transaction.svh │ ├── runall_sequence.svh │ ├── scoreboard.svh │ ├── sequence_item.svh │ ├── short_random_sequence.svh │ ├── tinyalu_base_test.svh │ ├── tinyalu_run_sequence.svh │ └── tinyalu_sequence.svh ├── tinyalu_bfm.sv ├── tinyalu_dut │ ├── single_cycle_add_and_xor.vhd │ ├── three_cycle_mult.vhd │ └── tinyalu.vhd ├── tinyalu_macros.svh ├── tinyalu_pkg.sv └── top.sv ├── LICENSE-2.0.txt ├── README.md ├── VCS_README.md └── misc ├── README.md └── tinyalu.sv /.gitignore: -------------------------------------------------------------------------------- 1 | *.ucdb 2 | *.wlf 3 | work 4 | transcript 5 | *.code-workspace 6 | -------------------------------------------------------------------------------- /02_Conventional_Testbench/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /02_Conventional_Testbench/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | #vlog ../misc/tinyalu.sv 12 | 13 | vlog tinyalu_tb.sv 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | vsim top_optimized -coverage 16 | set NoQuitOnFinish 1 17 | onbreak {resume} 18 | log /* -r 19 | run -all 20 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 21 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 22 | coverage save tinyalu.ucdb 23 | vcover report tinyalu.ucdb 24 | vcover report tinyalu.ucdb -cvg -details 25 | quit 26 | -------------------------------------------------------------------------------- /02_Conventional_Testbench/wave.do: -------------------------------------------------------------------------------- 1 | onerror {resume} 2 | quietly WaveActivateNextPane {} 0 3 | add wave -noupdate /top/clk 4 | add wave -noupdate -radix hexadecimal /top/DUT/A 5 | add wave -noupdate -radix hexadecimal /top/DUT/B 6 | add wave -noupdate -radix hexadecimal /top/DUT/clk 7 | add wave -noupdate -radix hexadecimal /top/op_set 8 | add wave -noupdate -radix hexadecimal /top/DUT/op 9 | add wave -noupdate -radix hexadecimal /top/DUT/reset_n 10 | add wave -noupdate -radix hexadecimal /top/DUT/start 11 | add wave -noupdate -radix hexadecimal /top/DUT/done 12 | add wave -noupdate -radix hexadecimal /top/DUT/result 13 | TreeUpdate [SetDefaultTree] 14 | WaveRestoreCursors {{Cursor 1} {50316229 ns} 0} 15 | quietly wave cursor active 1 16 | configure wave -namecolwidth 150 17 | configure wave -valuecolwidth 100 18 | configure wave -justifyvalue left 19 | configure wave -signalnamewidth 0 20 | configure wave -snapdistance 10 21 | configure wave -datasetprefix 0 22 | configure wave -rowmargin 4 23 | configure wave -childrowmargin 2 24 | configure wave -gridoffset 0 25 | configure wave -gridperiod 1 26 | configure wave -griddelta 40 27 | configure wave -timeline 0 28 | configure wave -timelineunits ns 29 | update 30 | WaveRestoreZoom {0 ns} {212795720 ns} 31 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | #vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | vsim top_optimized -coverage 16 | set NoQuitOnFinish 1 17 | onbreak {resume} 18 | log /* -r 19 | run -all 20 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 21 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 22 | coverage save tinyalu.ucdb 23 | vcover report tinyalu.ucdb 24 | vcover report tinyalu.ucdb -cvg -details 25 | quit 26 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/scoreboard.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module scoreboard(tinyalu_bfm bfm); 17 | import tinyalu_pkg::*; 18 | 19 | always @(posedge bfm.done) begin 20 | shortint predicted_result; 21 | #1; 22 | case (bfm.op_set) 23 | add_op: predicted_result = bfm.A + bfm.B; 24 | and_op: predicted_result = bfm.A & bfm.B; 25 | xor_op: predicted_result = bfm.A ^ bfm.B; 26 | mul_op: predicted_result = bfm.A * bfm.B; 27 | endcase // case (op_set) 28 | 29 | if ((bfm.op_set != no_op) && (bfm.op_set != rst_op)) 30 | if (predicted_result != bfm.result) 31 | $error ("FAILED: A: %0h B: %0h op: %s result: %0h", 32 | bfm.A, bfm.B, bfm.op_set.name(), bfm.result); 33 | 34 | end 35 | endmodule : scoreboard 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | tester.sv 4 | coverage.sv 5 | scoreboard.sv 6 | top.sv 7 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | typedef enum bit[2:0] {no_op = 3'b000, 18 | add_op = 3'b001, 19 | and_op = 3'b010, 20 | xor_op = 3'b011, 21 | mul_op = 3'b100, 22 | rst_op = 3'b111} operation_t; 23 | 24 | endpackage : tinyalu_pkg 25 | -------------------------------------------------------------------------------- /03_Interfaces_and_BFMs/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | tinyalu_bfm bfm(); 18 | tester tester_i (bfm); 19 | coverage coverage_i (bfm); 20 | scoreboard scoreboard_i(bfm); 21 | 22 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 23 | .clk(bfm.clk), .reset_n(bfm.reset_n), 24 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 25 | endmodule : top 26 | 27 | 28 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/classes.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class rectangle; 17 | int length; 18 | int width; 19 | 20 | function new(int l, int w); 21 | length = l; 22 | width = w; 23 | endfunction 24 | 25 | function int area(); 26 | return length * width; 27 | endfunction 28 | endclass 29 | 30 | class square extends rectangle; 31 | 32 | function new(int side); 33 | super.new(.l(side), .w(side)); 34 | endfunction 35 | 36 | endclass 37 | 38 | module top_class ; 39 | rectangle rectangle_h; 40 | square square_h; 41 | 42 | initial begin 43 | 44 | rectangle_h = new(.l(50),.w(20)); 45 | $display("rectangle area: %0d", rectangle_h.area()); 46 | 47 | square_h = new(.side(50)); 48 | $display("square area: %0d", square_h.area()); 49 | 50 | end 51 | endmodule 52 | 53 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/rectangle_only.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class rectangle; 17 | int length; 18 | int width; 19 | 20 | function new(int l, int w); 21 | length = l; 22 | width = w; 23 | endfunction 24 | 25 | function int area; 26 | return length * width; 27 | endfunction 28 | endclass : rectangle 29 | 30 | 31 | module top_rectangle ; 32 | 33 | rectangle rectangle_h; 34 | 35 | initial begin 36 | 37 | rectangle_h = new(.l(50),.w(20)); 38 | 39 | $display("rectangle area: %0d", rectangle_h.area()); 40 | 41 | end 42 | endmodule : top_rectangle 43 | 44 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/run_class.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top_class 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/run_rectangle.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top_rectangle 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/run_struct.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top_struct 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/structs.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | typedef struct { 17 | int length; 18 | int width; 19 | } rectangle_struct; 20 | 21 | typedef struct { 22 | int side; 23 | } square_struct; 24 | 25 | module top_struct ; 26 | rectangle_struct rectangle_s; 27 | square_struct square_s; 28 | initial begin 29 | rectangle_s.length = 50; 30 | rectangle_s.width = 20; 31 | $display("rectangle area: %0d", rectangle_s.length * rectangle_s.width); 32 | square_s.side = 50; 33 | $display("square area: %0d", square_s.side ** 2); 34 | end 35 | endmodule 36 | 37 | -------------------------------------------------------------------------------- /05_Classes_and_Extension/sv.f: -------------------------------------------------------------------------------- 1 | classes.sv 2 | structs.sv 3 | rectangle_only.sv 4 | 5 | -------------------------------------------------------------------------------- /06_Polymorphism/01_Not_Virtual/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /06_Polymorphism/01_Not_Virtual/sv.f: -------------------------------------------------------------------------------- 1 | not_virtual.sv 2 | -------------------------------------------------------------------------------- /06_Polymorphism/02_Virtual/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /06_Polymorphism/02_Virtual/sv.f: -------------------------------------------------------------------------------- 1 | virtual.sv 2 | 3 | -------------------------------------------------------------------------------- /06_Polymorphism/03_Pure_Virtual/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /06_Polymorphism/03_Pure_Virtual/sv.f: -------------------------------------------------------------------------------- 1 | pure_virtual.sv 2 | -------------------------------------------------------------------------------- /07_Static_Methods/01_Static_Variables/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /07_Static_Methods/01_Static_Variables/sv.f: -------------------------------------------------------------------------------- 1 | static_variables.sv 2 | 3 | -------------------------------------------------------------------------------- /07_Static_Methods/02_Static_Methods/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /07_Static_Methods/02_Static_Methods/sv.f: -------------------------------------------------------------------------------- 1 | static_methods.sv 2 | 3 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/01_memory_example/ram.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module RAM #(awidth, dwidth) ( 17 | input wire [awidth-1:0] address, 18 | inout wire [dwidth-1:0] data, 19 | input we); 20 | 21 | initial $display("awidth: %0d dwidth %0d",awidth, dwidth); 22 | // code to implement RAM 23 | endmodule // RAM 24 | 25 | 26 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/01_memory_example/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog ram.sv top.sv 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/01_memory_example/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | wire [ 7:0] address; 18 | wire [15:0] data; 19 | wire write_enable; 20 | RAM #(.awidth(8), .dwidth(16)) my_ram(address, data, write_enable); 21 | endmodule // top 22 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/02_static/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/02_static/sv.f: -------------------------------------------------------------------------------- 1 | cages.sv 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/03_instantiated/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /08_Parameterized_Classes/03_instantiated/sv.f: -------------------------------------------------------------------------------- 1 | cages.sv 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /09_Factory_Pattern/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog -f sv.f 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /09_Factory_Pattern/sv.f: -------------------------------------------------------------------------------- 1 | factory.sv 2 | 3 | 4 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | vsim top_optimized -coverage 16 | set NoQuitOnFinish 1 17 | onbreak {resume} 18 | log /* -r 19 | run -all 20 | quit 21 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/tb_classes/scoreboard.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class scoreboard; 17 | virtual tinyalu_bfm bfm; 18 | 19 | function new (virtual tinyalu_bfm b); 20 | bfm = b; 21 | endfunction : new 22 | 23 | task execute(); 24 | shortint predicted_result; 25 | forever begin : self_checker 26 | @(posedge bfm.done) 27 | #1; 28 | case (bfm.op_set) 29 | add_op: predicted_result = bfm.A + bfm.B; 30 | and_op: predicted_result = bfm.A & bfm.B; 31 | xor_op: predicted_result = bfm.A ^ bfm.B; 32 | mul_op: predicted_result = bfm.A * bfm.B; 33 | endcase // case (op_set) 34 | 35 | if ((bfm.op_set != no_op) && (bfm.op_set != rst_op)) 36 | if (predicted_result != bfm.result) 37 | $error ("FAILED: A: %0h B: %0h op: %s result: %0h", 38 | bfm.A, bfm.B, bfm.op_set.name(), bfm.result); 39 | 40 | end : self_checker 41 | endtask : execute 42 | 43 | 44 | endclass : scoreboard 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/tb_classes/testbench.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class testbench; 17 | 18 | virtual tinyalu_bfm bfm; 19 | 20 | tester tester_h; 21 | coverage coverage_h; 22 | scoreboard scoreboard_h; 23 | 24 | function new (virtual tinyalu_bfm b); 25 | bfm = b; 26 | endfunction : new 27 | 28 | task execute(); 29 | tester_h = new(bfm); 30 | coverage_h = new(bfm); 31 | scoreboard_h = new(bfm); 32 | 33 | fork 34 | tester_h.execute(); 35 | coverage_h.execute(); 36 | scoreboard_h.execute(); 37 | join_none 38 | endtask : execute 39 | endclass : testbench 40 | 41 | 42 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | typedef enum bit[2:0] {no_op = 3'b000, 18 | add_op = 3'b001, 19 | and_op = 3'b010, 20 | xor_op = 3'b011, 21 | mul_op = 3'b100, 22 | rst_op = 3'b111} operation_t; 23 | 24 | 25 | `include "coverage.svh" 26 | `include "tester.svh" 27 | `include "scoreboard.svh" 28 | `include "testbench.svh" 29 | endpackage : tinyalu_pkg 30 | 31 | -------------------------------------------------------------------------------- /10_An_Object_Oriented_Testbench/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import tinyalu_pkg::*; 18 | `include "tinyalu_macros.svh" 19 | 20 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 21 | .clk(bfm.clk), .reset_n(bfm.reset_n), 22 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 23 | 24 | tinyalu_bfm bfm(); 25 | 26 | testbench testbench_h; 27 | 28 | 29 | initial begin 30 | testbench_h = new(bfm); 31 | testbench_h.execute(); 32 | end 33 | 34 | endmodule : top 35 | 36 | 37 | -------------------------------------------------------------------------------- /11_UVM_Test/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /11_UVM_Test/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | 16 | vsim top_optimized -coverage +UVM_TESTNAME=random_test 17 | 18 | set NoQuitOnFinish 1 19 | onbreak {resume} 20 | log /* -r 21 | run -all 22 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 23 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 24 | coverage save random_test.ucdb 25 | 26 | 27 | vsim top_optimized -coverage +UVM_TESTNAME=add_test 28 | 29 | set NoQuitOnFinish 1 30 | onbreak {resume} 31 | log /* -r 32 | run -all 33 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 34 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 35 | coverage save add_test.ucdb 36 | 37 | vcover merge tinyalu.ucdb random_test.ucdb add_test.ucdb 38 | vcover report tinyalu.ucdb -cvg -details 39 | quit 40 | -------------------------------------------------------------------------------- /11_UVM_Test/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /11_UVM_Test/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends uvm_test; 17 | `uvm_component_utils(add_test); 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 24 | $fatal("Failed to get BFM"); 25 | endfunction : new 26 | 27 | 28 | task run_phase(uvm_phase phase); 29 | add_tester add_tester_h; 30 | coverage coverage_h; 31 | scoreboard scoreboard_h; 32 | 33 | phase.raise_objection(this); 34 | 35 | add_tester_h = new(bfm); 36 | coverage_h = new(bfm); 37 | scoreboard_h = new(bfm); 38 | 39 | fork 40 | coverage_h.execute(); 41 | scoreboard_h.execute(); 42 | join_none 43 | 44 | add_tester_h.execute(); 45 | phase.drop_objection(this); 46 | endtask : run_phase 47 | 48 | endclass 49 | -------------------------------------------------------------------------------- /11_UVM_Test/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | 18 | function new (virtual tinyalu_bfm b); 19 | super.new(b); 20 | endfunction : new 21 | 22 | function operation_t get_op(); 23 | bit [2:0] op_choice; 24 | return add_op; 25 | endfunction : get_op 26 | 27 | endclass : add_tester 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /11_UVM_Test/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 24 | $fatal("Failed to get BFM"); 25 | endfunction : new 26 | 27 | 28 | task run_phase(uvm_phase phase); 29 | random_tester random_tester_h; 30 | coverage coverage_h; 31 | scoreboard scoreboard_h; 32 | 33 | phase.raise_objection(this); 34 | 35 | random_tester_h = new(bfm); 36 | coverage_h = new(bfm); 37 | scoreboard_h = new(bfm); 38 | 39 | fork 40 | coverage_h.execute(); 41 | scoreboard_h.execute(); 42 | join_none 43 | 44 | random_tester_h.execute(); 45 | phase.drop_objection(this); 46 | endtask : run_phase 47 | 48 | endclass 49 | -------------------------------------------------------------------------------- /11_UVM_Test/tb_classes/scoreboard.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class scoreboard; 17 | virtual tinyalu_bfm bfm; 18 | 19 | function new (virtual tinyalu_bfm b); 20 | bfm = b; 21 | endfunction : new 22 | 23 | task execute(); 24 | shortint predicted_result; 25 | forever begin : self_checker 26 | @(posedge bfm.done) 27 | #1; 28 | case (bfm.op_set) 29 | add_op: predicted_result = bfm.A + bfm.B; 30 | and_op: predicted_result = bfm.A & bfm.B; 31 | xor_op: predicted_result = bfm.A ^ bfm.B; 32 | mul_op: predicted_result = bfm.A * bfm.B; 33 | endcase // case (op_set) 34 | 35 | if ((bfm.op_set != no_op) && (bfm.op_set != rst_op)) 36 | if (predicted_result != bfm.result) 37 | $error ("FAILED: A: %0h B: %0h op: %s result: %0h", 38 | bfm.A, bfm.B, bfm.op_set.name(), bfm.result); 39 | 40 | end : self_checker 41 | endtask : execute 42 | 43 | 44 | endclass : scoreboard 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /11_UVM_Test/tb_classes/selfcheck.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class scoreboard; 17 | virtual tinyalu_bfm bfm; 18 | 19 | function new (virtual tinyalu_bfm b); 20 | bfm = b; 21 | endfunction : new 22 | 23 | task execute(); 24 | shortint predicted_result; 25 | forever begin : self_checker 26 | @(posedge bfm.done) 27 | case (bfm.op_set) 28 | add_op: predicted_result = bfm.A + bfm.B; 29 | and_op: predicted_result = bfm.A & bfm.B; 30 | xor_op: predicted_result = bfm.A ^ bfm.B; 31 | mul_op: predicted_result = bfm.A * bfm.B; 32 | endcase // case (op_set) 33 | 34 | if ((bfm.op_set != no_op) && (bfm.op_set != rst_op)) 35 | if (predicted_result != bfm.result) 36 | $error ("FAILED: A: %0h B: %0h op: %s result: %0h", 37 | bfm.A, bfm.B, bfm.op_set.name(), bfm.result); 38 | 39 | end : self_checker 40 | endtask : execute 41 | 42 | 43 | endclass : scoreboard 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /11_UVM_Test/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /11_UVM_Test/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | virtual tinyalu_bfm bfm_g; 28 | 29 | 30 | `include "coverage.svh" 31 | `include "random_tester.svh" 32 | `include "add_tester.svh" 33 | `include "scoreboard.svh" 34 | `include "random_test.svh" 35 | `include "add_test.svh" 36 | 37 | 38 | endpackage : tinyalu_pkg 39 | -------------------------------------------------------------------------------- /11_UVM_Test/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | import tinyalu_pkg::*; 21 | `include "tinyalu_macros.svh" 22 | 23 | tinyalu_bfm bfm(); 24 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 25 | .clk(bfm.clk), .reset_n(bfm.reset_n), 26 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /12_UVM_Components/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /12_UVM_Components/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | vsim top_optimized -coverage +UVM_TESTNAME=random_test 16 | set NoQuitOnFinish 1 17 | onbreak {resume} 18 | log /* -r 19 | run -all 20 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 21 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 22 | coverage save random_test.ucdb 23 | 24 | 25 | vsim top_optimized -coverage +UVM_TESTNAME=add_test 26 | set NoQuitOnFinish 1 27 | onbreak {resume} 28 | log /* -r 29 | run -all 30 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 31 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 32 | coverage save add_test.ucdb 33 | 34 | vcover merge tinyalu.ucdb random_test.ucdb add_test.ucdb 35 | vcover report tinyalu.ucdb -cvg -details 36 | quit 37 | 38 | -------------------------------------------------------------------------------- /12_UVM_Components/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /12_UVM_Components/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends random_test; 17 | `uvm_component_utils(add_test); 18 | 19 | add_tester tester_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | tester_h = new("tester_h", this); 27 | coverage_h = new("coverage_h", this); 28 | scoreboard_h = new("scoreboard_h", this); 29 | endfunction 30 | 31 | endclass 32 | 33 | 34 | -------------------------------------------------------------------------------- /12_UVM_Components/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | `uvm_component_utils(add_tester) 18 | 19 | function new (string name, uvm_component parent); 20 | super.new(name, parent); 21 | endfunction : new 22 | 23 | function operation_t get_op(); 24 | bit [2:0] op_choice; 25 | return add_op; 26 | endfunction : get_op 27 | 28 | endclass : add_tester 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /12_UVM_Components/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | random_tester tester_h; 20 | coverage coverage_h; 21 | scoreboard scoreboard_h; 22 | 23 | function void build_phase(uvm_phase phase); 24 | tester_h = new("tester_h", this); 25 | coverage_h = new("coverage_h", this); 26 | scoreboard_h = new("scoreboard_h", this); 27 | endfunction : build_phase 28 | 29 | function new (string name, uvm_component parent); 30 | super.new(name,parent); 31 | endfunction : new 32 | 33 | endclass 34 | 35 | 36 | -------------------------------------------------------------------------------- /12_UVM_Components/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /12_UVM_Components/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | virtual tinyalu_bfm bfm_g; 28 | 29 | 30 | `include "coverage.svh" 31 | `include "random_tester.svh" 32 | `include "add_tester.svh" 33 | `include "scoreboard.svh" 34 | `include "random_test.svh" 35 | `include "add_test.svh" 36 | 37 | 38 | endpackage : tinyalu_pkg 39 | -------------------------------------------------------------------------------- /12_UVM_Components/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | tinyalu_pkg::bfm_g = bfm; 30 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 31 | run_test(); 32 | end 33 | 34 | endmodule : top 35 | 36 | 37 | -------------------------------------------------------------------------------- /13_UVM_Environments/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /13_UVM_Environments/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | 5 | # Comment out either the SystemVerilog or VHDL DUT. 6 | # There can be only one! 7 | 8 | #VHDL DUT 9 | vcom -f dut.f 10 | 11 | # SystemVerilog DUT 12 | # vlog ../misc/tinyalu.sv 13 | 14 | vlog -f tb.f 15 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 16 | vsim top_optimized -coverage +UVM_TESTNAME=random_test 17 | set NoQuitOnFinish 1 18 | onbreak {resume} 19 | log /* -r 20 | run -all 21 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 22 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 23 | coverage save random_test.ucdb 24 | 25 | 26 | vsim top_optimized -coverage +UVM_TESTNAME=add_test 27 | set NoQuitOnFinish 1 28 | onbreak {resume} 29 | log /* -r 30 | run -all 31 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 32 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 33 | coverage save add_test.ucdb 34 | 35 | vcover merge tinyalu.ucdb random_test.ucdb add_test.ucdb 36 | vcover report tinyalu.ucdb -cvg -details 37 | quit 38 | 39 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends uvm_test; 17 | `uvm_component_utils(add_test); 18 | 19 | env env_h; 20 | 21 | function void build_phase(uvm_phase phase); 22 | base_tester::type_id::set_type_override(add_tester::get_type()); 23 | env_h = env::type_id::create("env_h",this); 24 | endfunction : build_phase 25 | 26 | function new (string name, uvm_component parent); 27 | super.new(name,parent); 28 | endfunction : new 29 | 30 | endclass 31 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | `uvm_component_utils(add_tester) 18 | 19 | function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | return add_op; 22 | endfunction : get_op 23 | 24 | function new (string name, uvm_component parent); 25 | super.new(name, parent); 26 | endfunction : new 27 | 28 | endclass : add_tester 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/base_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | `ifdef QUESTA 17 | virtual class base_tester extends uvm_component; 18 | `else 19 | class base_tester extends uvm_component; 20 | `endif 21 | 22 | `uvm_component_utils(base_tester) 23 | virtual tinyalu_bfm bfm; 24 | 25 | function void build_phase(uvm_phase phase); 26 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 27 | $fatal("Failed to get BFM"); 28 | endfunction : build_phase 29 | 30 | pure virtual function operation_t get_op(); 31 | 32 | pure virtual function byte get_data(); 33 | 34 | task run_phase(uvm_phase phase); 35 | byte unsigned iA; 36 | byte unsigned iB; 37 | operation_t op_set; 38 | shortint result; 39 | 40 | phase.raise_objection(this); 41 | bfm.reset_alu(); 42 | repeat (1000) begin : random_loop 43 | op_set = get_op(); 44 | iA = get_data(); 45 | iB = get_data(); 46 | bfm.send_op(iA, iB, op_set, result); 47 | end : random_loop 48 | #500; 49 | phase.drop_objection(this); 50 | endtask : run_phase 51 | 52 | 53 | function new (string name, uvm_component parent); 54 | super.new(name, parent); 55 | endfunction : new 56 | 57 | endclass : base_tester 58 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/env.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class env extends uvm_env; 17 | `uvm_component_utils(env); 18 | 19 | base_tester tester_h; 20 | coverage coverage_h; 21 | scoreboard scoreboard_h; 22 | 23 | function void build_phase(uvm_phase phase); 24 | tester_h = base_tester::type_id::create("tester_h",this); 25 | coverage_h = coverage::type_id::create ("coverage_h",this); 26 | scoreboard_h = scoreboard::type_id::create("scoreboard_h",this); 27 | endfunction : build_phase 28 | 29 | function new (string name, uvm_component parent); 30 | super.new(name,parent); 31 | endfunction : new 32 | 33 | endclass 34 | 35 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | env env_h; 20 | 21 | function void build_phase(uvm_phase phase); 22 | base_tester::type_id::set_type_override(random_tester::get_type()); 23 | env_h = env::type_id::create("env_h",this); 24 | endfunction : build_phase 25 | 26 | function new (string name, uvm_component parent); 27 | super.new(name,parent); 28 | endfunction : new 29 | 30 | endclass 31 | 32 | 33 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/random_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_tester extends base_tester; 17 | `uvm_component_utils (random_tester) 18 | 19 | function byte get_data(); 20 | bit [1:0] zero_ones; 21 | zero_ones = $random; 22 | if (zero_ones == 2'b00) 23 | return 8'h00; 24 | else if (zero_ones == 2'b11) 25 | return 8'hFF; 26 | else 27 | return $random; 28 | endfunction : get_data 29 | 30 | function operation_t get_op(); 31 | bit [2:0] op_choice; 32 | op_choice = $random; 33 | case (op_choice) 34 | 3'b000 : return no_op; 35 | 3'b001 : return add_op; 36 | 3'b010 : return and_op; 37 | 3'b011 : return xor_op; 38 | 3'b100 : return mul_op; 39 | 3'b101 : return no_op; 40 | 3'b110 : return rst_op; 41 | 3'b111 : return rst_op; 42 | endcase // case (op_choice) 43 | endfunction : get_op 44 | 45 | function new (string name, uvm_component parent); 46 | super.new(name, parent); 47 | endfunction : new 48 | 49 | endclass : random_tester 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /13_UVM_Environments/tb_classes/vcs_base_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class base_tester extends uvm_component; 17 | `uvm_component_utils(base_tester) 18 | virtual tinyalu_bfm bfm; 19 | 20 | function void build_phase(uvm_phase phase); 21 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 22 | $fatal("Failed to get BFM"); 23 | endfunction : build_phase 24 | 25 | virtual function operation_t get_op(); 26 | return no_op; 27 | endfunction 28 | 29 | virtual function byte get_data(); 30 | return 0; 31 | endfunction 32 | 33 | task run_phase(uvm_phase phase); 34 | byte unsigned iA; 35 | byte unsigned iB; 36 | operation_t op_set; 37 | shortint result; 38 | 39 | phase.raise_objection(this); 40 | bfm.reset_alu(); 41 | repeat (1000) begin : random_loop 42 | op_set = get_op(); 43 | iA = get_data(); 44 | iB = get_data(); 45 | bfm.send_op(iA, iB, op_set, result); 46 | end : random_loop 47 | #500; 48 | phase.drop_objection(this); 49 | endtask : run_phase 50 | 51 | 52 | function new (string name, uvm_component parent); 53 | super.new(name, parent); 54 | endfunction : new 55 | 56 | endclass : base_tester 57 | -------------------------------------------------------------------------------- /13_UVM_Environments/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /13_UVM_Environments/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | 28 | `include "coverage.svh" 29 | `include "base_tester.svh" 30 | `include "random_tester.svh" 31 | `include "add_tester.svh" 32 | `include "scoreboard.svh" 33 | `include "env.svh" 34 | `include "random_test.svh" 35 | `include "add_test.svh" 36 | 37 | 38 | endpackage : tinyalu_pkg 39 | -------------------------------------------------------------------------------- /13_UVM_Environments/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/#dice_test.svh#: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2013 Ray Salemi 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | class dice_test extends uvm_test; 18 | `uvm_component_utils(dice_test); 19 | 20 | dice_roller dice_roller_h; 21 | coverage coverage_h; 22 | histogram histogram_h; 23 | average average_h; 24 | 25 | function void build_phase(uvm_phase phase); 26 | coverage_h = new("coverage_h", this); 27 | histogram_h = new("histogram_h",this); 28 | average_h = new("average_h",this); 29 | dice_roller_h = new("dice_roller_h",this); 30 | endfunction : build_phase 31 | 32 | task run_phase(uvm_phase phase); 33 | int the_roll; 34 | phase.raise_objection(this); 35 | repeat (20) begin 36 | the_roll = dice_roller_h.two_dice(); 37 | coverage_h.write(the_roll); 38 | histogram_h.write(the_roll); 39 | average_h.write(the_roll); 40 | end 41 | phase.drop_objection(this); 42 | endtask : run_phase 43 | 44 | function new(string name, uvm_component parent); 45 | super.new(name,parent); 46 | endfunction : new 47 | 48 | endclass : dice_test 49 | 50 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/average.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class average extends uvm_component; 17 | `uvm_component_utils(average); 18 | 19 | protected real dice_total; 20 | protected real count; 21 | 22 | function new(string name, uvm_component parent = null); 23 | super.new(name,parent); 24 | dice_total = 0.0; 25 | count = 0.0; 26 | endfunction : new 27 | 28 | function void write(int t); 29 | dice_total = dice_total + t; 30 | count++; 31 | endfunction : write 32 | 33 | function void report_phase(uvm_phase phase); 34 | $display ("DICE AVERAGE: %2.1f",dice_total/count); 35 | endfunction : report_phase 36 | endclass : average 37 | 38 | 39 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/coverage.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class coverage extends uvm_component; 17 | `uvm_component_utils(coverage); 18 | int the_roll; 19 | 20 | covergroup dice_cg; 21 | coverpoint the_roll{ 22 | bins twod6[] = {2,3,4,5,6,7,8,9,10,11,12};} 23 | endgroup 24 | 25 | function new(string name, uvm_component parent = null); 26 | super.new(name,parent); 27 | dice_cg = new(); 28 | endfunction : new 29 | 30 | function void write (int t); 31 | the_roll = t; 32 | dice_cg.sample(); 33 | endfunction : write 34 | 35 | function void report_phase(uvm_phase phase); 36 | 37 | $display("\nCOVERAGE: %2.0f%% ", dice_cg.get_coverage()); 38 | endfunction : report_phase 39 | 40 | endclass : coverage 41 | 42 | 43 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/dice_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package dice_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | `include "dice_roller.svh" 21 | `include "coverage.svh" 22 | `include "histogram.svh" 23 | `include "average.svh" 24 | `include "dice_test.svh" 25 | 26 | endpackage : dice_pkg 27 | 28 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/dice_roller.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class dice_roller extends uvm_component; 17 | `uvm_component_utils(dice_roller); 18 | 19 | rand byte die1; 20 | rand byte die2; 21 | 22 | constraint d6 { die1 >= 1; die1 <= 6; 23 | die2 >= 1; die2 <= 6; } 24 | 25 | function new(string name, uvm_component parent); 26 | super.new(name,parent); 27 | endfunction : new 28 | 29 | function byte two_dice(); 30 | byte the_roll; 31 | void'(randomize()); 32 | the_roll = die1 + die2; 33 | return the_roll; 34 | endfunction : two_dice 35 | 36 | endclass : dice_roller 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/dice_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class dice_test extends uvm_test; 17 | `uvm_component_utils(dice_test); 18 | 19 | dice_roller dice_roller_h; 20 | coverage coverage_h; 21 | histogram histogram_h; 22 | average average_h; 23 | 24 | function void build_phase(uvm_phase phase); 25 | coverage_h = new("coverage_h", this); 26 | histogram_h = new("histogram_h",this); 27 | average_h = new("average_h",this); 28 | dice_roller_h = new("dice_roller_h",this); 29 | endfunction : build_phase 30 | 31 | task run_phase(uvm_phase phase); 32 | int the_roll; 33 | phase.raise_objection(this); 34 | repeat (20) begin 35 | the_roll = dice_roller_h.two_dice(); 36 | coverage_h.write(the_roll); 37 | histogram_h.write(the_roll); 38 | average_h.write(the_roll); 39 | end 40 | phase.drop_objection(this); 41 | endtask : run_phase 42 | 43 | function new(string name, uvm_component parent); 44 | super.new(name,parent); 45 | endfunction : new 46 | 47 | endclass : dice_test 48 | 49 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/histogram.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class histogram extends uvm_component; 17 | `uvm_component_utils(histogram); 18 | 19 | int rolls[int]; 20 | 21 | function new(string name, uvm_component parent); 22 | super.new(name,parent); 23 | for (int ii = 2; ii <= 12; ii++) rolls[ii] = 0; 24 | endfunction : new 25 | 26 | function void write(int t); 27 | rolls[t]++; 28 | endfunction : write 29 | 30 | 31 | function void report_phase(uvm_phase phase); 32 | string bar; 33 | string message; 34 | 35 | message = "\n"; 36 | foreach (rolls[ii]) begin 37 | string roll_msg; 38 | bar = ""; 39 | repeat (rolls[ii]) bar = {bar,"#"}; 40 | roll_msg = $sformatf( "%2d: %s\n", ii, bar); 41 | message = {message,roll_msg}; 42 | end 43 | $display(message); 44 | endfunction : report_phase 45 | endclass : histogram 46 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | vlog dice_pkg.sv; 5 | vlog top.sv; 6 | 7 | vsim -c top 8 | run -all 9 | exit 10 | -------------------------------------------------------------------------------- /15_Talking_Objects/01_No_Analysis_Port/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | import dice_pkg::*; 20 | initial run_test("dice_test"); 21 | endmodule : top 22 | 23 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/average.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class average extends uvm_subscriber #(int); 17 | `uvm_component_utils(average); 18 | 19 | real dice_total; 20 | real count; 21 | 22 | function new(string name, uvm_component parent = null); 23 | super.new(name,parent); 24 | dice_total = 0.0; 25 | count = 0.0; 26 | endfunction : new 27 | 28 | function void write(int t); 29 | dice_total = dice_total + t; 30 | count++; 31 | endfunction : write 32 | 33 | function void report_phase(uvm_phase phase); 34 | 35 | $display ("DICE AVERAGE: %2.1f",dice_total/count); 36 | endfunction : report_phase 37 | 38 | endclass : average 39 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/coverage.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class coverage extends uvm_subscriber#(int); 17 | `uvm_component_utils(coverage); 18 | int the_roll; 19 | 20 | covergroup dice_cg; 21 | coverpoint the_roll{ 22 | bins twod6[] = {2,3,4,5,6,7,8,9,10,11,12};} 23 | endgroup 24 | 25 | 26 | function new(string name, uvm_component parent = null); 27 | super.new(name,parent); 28 | dice_cg = new(); 29 | endfunction : new 30 | 31 | 32 | function void write (int t); 33 | the_roll = t; 34 | dice_cg.sample(); 35 | endfunction : write 36 | 37 | function void report_phase(uvm_phase phase); 38 | 39 | $display("\nCOVERAGE: %2.0f%% ", dice_cg.get_coverage()); 40 | endfunction : report_phase 41 | endclass : coverage 42 | 43 | 44 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/dice_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package dice_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | `include "coverage.svh" 21 | `include "histogram.svh" 22 | `include "average.svh" 23 | `include "dice_roller.svh" 24 | `include "dice_test.svh" 25 | 26 | endpackage : dice_pkg 27 | 28 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/dice_roller.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class dice_roller extends uvm_component; 17 | `uvm_component_utils(dice_roller); 18 | 19 | uvm_analysis_port #(int) roll_ap; 20 | 21 | function void build_phase (uvm_phase phase); 22 | 23 | roll_ap = new("roll_ap",this); 24 | 25 | endfunction : build_phase 26 | 27 | rand byte die1; 28 | rand byte die2; 29 | 30 | constraint d6 { die1 >= 1; die1 <= 6; 31 | die2 >= 1; die2 <= 6; } 32 | 33 | 34 | task run_phase(uvm_phase phase); 35 | int the_roll; 36 | phase.raise_objection(this); 37 | void'(randomize()); 38 | repeat (20) begin 39 | void'(randomize()); 40 | the_roll = die1 + die2; 41 | roll_ap.write(the_roll); 42 | end 43 | phase.drop_objection(this); 44 | endtask : run_phase 45 | 46 | 47 | 48 | function new(string name, uvm_component parent); 49 | super.new(name,parent); 50 | endfunction : new 51 | 52 | endclass : dice_roller 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/dice_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class dice_test extends uvm_test; 17 | `uvm_component_utils(dice_test); 18 | 19 | dice_roller dice_roller_h; 20 | coverage coverage_h; 21 | histogram histogram_h; 22 | average average_h; 23 | 24 | function void connect_phase(uvm_phase phase); 25 | dice_roller_h.roll_ap.connect(coverage_h.analysis_export); 26 | dice_roller_h.roll_ap.connect(histogram_h.analysis_export); 27 | dice_roller_h.roll_ap.connect(average_h.analysis_export); 28 | endfunction : connect_phase 29 | 30 | 31 | function new(string name, uvm_component parent); 32 | super.new(name,parent); 33 | endfunction : new 34 | 35 | 36 | function void build_phase(uvm_phase phase); 37 | 38 | 39 | dice_roller_h = new("dice_roller_h", this); 40 | coverage_h = new("coverage_h", this); 41 | histogram_h = new("histogram_h",this); 42 | average_h = new("average_h",this); 43 | 44 | endfunction : build_phase 45 | 46 | 47 | endclass : dice_test 48 | 49 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/histogram.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class histogram extends uvm_subscriber #(int); 17 | `uvm_component_utils(histogram); 18 | 19 | int rolls[int]; 20 | 21 | 22 | function new(string name, uvm_component parent); 23 | super.new(name,parent); 24 | for (int ii = 2; ii <= 12; ii++) rolls[ii] = 0; 25 | endfunction : new 26 | 27 | function void write(int t); 28 | rolls[t]++; 29 | endfunction : write 30 | 31 | 32 | function void report_phase(uvm_phase phase); 33 | string bar; 34 | string message; 35 | 36 | message = "\n"; 37 | foreach (rolls[ii]) begin 38 | string roll_msg; 39 | bar = ""; 40 | repeat (rolls[ii]) bar = {bar,"#"}; 41 | roll_msg = $sformatf( "%2d: %s\n", ii, bar); 42 | message = {message,roll_msg}; 43 | end 44 | $display(message); 45 | endfunction : report_phase 46 | endclass : histogram 47 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | vlog dice_pkg.sv; 5 | vlog top.sv; 6 | 7 | vsim -c top 8 | run -all 9 | exit 10 | -------------------------------------------------------------------------------- /15_Talking_Objects/02_With_Analysis_Port/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | import dice_pkg::*; 20 | initial run_test("dice_test"); 21 | endmodule : top 22 | 23 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | 5 | # Comment out either the SystemVerilog or VHDL DUT. 6 | # There can be only one! 7 | 8 | #VHDL DUT 9 | vcom -f dut.f 10 | 11 | # SystemVerilog DUT 12 | # vlog ../misc/tinyalu.sv 13 | 14 | 15 | vlog -f tb.f 16 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 17 | vsim top_optimized -coverage +UVM_TESTNAME=random_test +UVM_VERBOSITY=UVM_DEBUG 18 | set NoQuitOnFinish 1 19 | onbreak {resume} 20 | log /* -r 21 | run -all 22 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 23 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 24 | coverage save random_test.ucdb 25 | 26 | 27 | vsim top_optimized -coverage +UVM_TESTNAME=add_test 28 | set NoQuitOnFinish 1 29 | onbreak {resume} 30 | log /* -r 31 | run -all 32 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 33 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 34 | coverage save add_test.ucdb 35 | 36 | vcover merge tinyalu.ucdb random_test.ucdb add_test.ucdb 37 | vcover report tinyalu.ucdb -cvg -details 38 | quit 39 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends random_test; 17 | `uvm_component_utils(add_test); 18 | 19 | 20 | function new (string name, uvm_component parent); 21 | super.new(name,parent); 22 | endfunction : new 23 | 24 | function void build_phase(uvm_phase phase); 25 | random_tester::type_id::set_type_override(add_tester::get_type()); 26 | super.build_phase(phase); 27 | endfunction : build_phase 28 | 29 | endclass 30 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | `uvm_component_utils(add_tester) 18 | 19 | function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | return add_op; 22 | endfunction : get_op 23 | 24 | function new (string name, uvm_component parent); 25 | super.new(name, parent); 26 | endfunction : new 27 | 28 | endclass : add_tester 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/env.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class env extends uvm_env; 17 | `uvm_component_utils(env); 18 | 19 | random_tester random_tester_h; 20 | coverage coverage_h; 21 | scoreboard scoreboard_h; 22 | command_monitor command_monitor_h; 23 | result_monitor result_monitor_h; 24 | 25 | function new (string name, uvm_component parent); 26 | super.new(name,parent); 27 | endfunction : new 28 | 29 | function void build_phase(uvm_phase phase); 30 | random_tester_h = random_tester::type_id::create("random_tester_h",this); 31 | coverage_h = coverage::type_id::create ("coverage_h",this); 32 | scoreboard_h = scoreboard::type_id::create("scoreboard_h",this); 33 | command_monitor_h = command_monitor::type_id::create("command_monitor_h",this); 34 | result_monitor_h= result_monitor::type_id::create("result_monitor_h",this); 35 | 36 | 37 | endfunction : build_phase 38 | 39 | function void connect_phase(uvm_phase phase); 40 | 41 | result_monitor_h.ap.connect(scoreboard_h.analysis_export); 42 | command_monitor_h.ap.connect(scoreboard_h.cmd_f.analysis_export); 43 | command_monitor_h.ap.connect(coverage_h.analysis_export); 44 | 45 | endfunction : connect_phase 46 | 47 | endclass 48 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | env env_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | env_h = env::type_id::create("env_h",this); 27 | endfunction : build_phase 28 | 29 | endclass 30 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/random_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_tester extends base_tester; 17 | `uvm_component_utils (random_tester) 18 | 19 | function byte get_data(); 20 | bit [1:0] zero_ones; 21 | zero_ones = $random; 22 | if (zero_ones == 2'b00) 23 | return 8'h00; 24 | else if (zero_ones == 2'b11) 25 | return 8'hFF; 26 | else 27 | return $random; 28 | endfunction : get_data 29 | 30 | function operation_t get_op(); 31 | bit [2:0] op_choice; 32 | op_choice = $random; 33 | case (op_choice) 34 | 3'b000 : return no_op; 35 | 3'b001 : return add_op; 36 | 3'b010 : return and_op; 37 | 3'b011 : return xor_op; 38 | 3'b100 : return mul_op; 39 | 3'b101 : return no_op; 40 | 3'b110 : return rst_op; 41 | 3'b111 : return rst_op; 42 | endcase // case (op_choice) 43 | endfunction : get_op 44 | 45 | function new (string name, uvm_component parent); 46 | super.new(name, parent); 47 | endfunction : new 48 | 49 | endclass : random_tester 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | uvm_analysis_port #(shortint) ap; 20 | 21 | function void write_to_monitor(shortint r); 22 | $display ("RESULT MONITOR: resultA: 0x%0h",r); 23 | ap.write(r); 24 | endfunction : write_to_monitor 25 | 26 | function void build_phase(uvm_phase phase); 27 | virtual tinyalu_bfm bfm; 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | $fatal("Failed to get BFM"); 30 | bfm.result_monitor_h = this; 31 | ap = new("ap",this); 32 | endfunction : build_phase 33 | 34 | function new (string name, uvm_component parent); 35 | super.new(name, parent); 36 | endfunction : new 37 | 38 | endclass : result_monitor 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tb_classes/vcs_base_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class base_tester extends uvm_component; 17 | `uvm_component_utils(base_tester) 18 | virtual tinyalu_bfm bfm; 19 | 20 | function void build_phase(uvm_phase phase); 21 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 22 | $fatal("Failed to get BFM"); 23 | endfunction : build_phase 24 | 25 | virtual function operation_t get_op(); 26 | return no_op; 27 | endfunction 28 | 29 | virtual function byte get_data(); 30 | return 0; 31 | endfunction 32 | 33 | task run_phase(uvm_phase phase); 34 | byte unsigned iA; 35 | byte unsigned iB; 36 | operation_t op_set; 37 | shortint result; 38 | 39 | phase.raise_objection(this); 40 | bfm.reset_alu(); 41 | repeat (1000) begin : random_loop 42 | op_set = get_op(); 43 | iA = get_data(); 44 | iB = get_data(); 45 | bfm.send_op(iA, iB, op_set, result); 46 | end : random_loop 47 | #500; 48 | phase.drop_objection(this); 49 | endtask : run_phase 50 | 51 | 52 | function new (string name, uvm_component parent); 53 | super.new(name, parent); 54 | endfunction : new 55 | 56 | endclass : base_tester 57 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | 28 | typedef struct { 29 | byte unsigned A; 30 | byte unsigned B; 31 | operation_t op; 32 | } command_s; 33 | 34 | 35 | 36 | 37 | `include "coverage.svh" 38 | `include "base_tester.svh" 39 | `include "random_tester.svh" 40 | `include "add_tester.svh" 41 | `include "scoreboard.svh" 42 | `include "command_monitor.svh" 43 | `include "result_monitor.svh" 44 | 45 | `include "env.svh" 46 | 47 | `include "random_test.svh" 48 | `include "add_test.svh" 49 | 50 | endpackage : tinyalu_pkg 51 | -------------------------------------------------------------------------------- /16_Analysis_Ports_In_the_Testbench/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /17_Interthread_Communication/01_Modules/modules.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module producer(output byte shared, input bit put_it, output bit get_it); 17 | initial 18 | repeat(3) begin 19 | $display("Sent %0d", ++shared); 20 | get_it = ~get_it; 21 | @(put_it); 22 | end 23 | endmodule : producer 24 | 25 | module consumer(input byte shared, output bit put_it, input bit get_it); 26 | initial 27 | forever begin 28 | @(get_it); 29 | $display("Received: %0d", shared); 30 | put_it = ~put_it; 31 | end 32 | endmodule : consumer 33 | 34 | module top; 35 | byte shared; 36 | producer p (shared, put_it, get_it); 37 | consumer c (shared, put_it, get_it); 38 | endmodule : top 39 | 40 | -------------------------------------------------------------------------------- /17_Interthread_Communication/01_Modules/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | vlog modules.sv 5 | vsim -c top 6 | run -all 7 | exit 8 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/communication_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class communication_test extends uvm_test; 17 | `uvm_component_utils(communication_test) 18 | 19 | producer producer_h; 20 | consumer consumer_h; 21 | uvm_tlm_fifo #(int) fifo_h; 22 | 23 | function new(string name, uvm_component parent); 24 | super.new(name, parent); 25 | endfunction : new 26 | 27 | function void build_phase(uvm_phase phase); 28 | producer_h = new("producer_h", this); 29 | consumer_h = new("consumer_h", this); 30 | fifo_h = new("fifo_h",this); 31 | endfunction : build_phase 32 | 33 | function void connect_phase(uvm_phase phase); 34 | producer_h.put_port_h.connect(fifo_h.put_export); 35 | consumer_h.get_port_h.connect(fifo_h.get_export); 36 | endfunction : connect_phase 37 | 38 | endclass : communication_test 39 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/consumer.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class consumer extends uvm_component; 17 | `uvm_component_utils(consumer); 18 | 19 | uvm_get_port #(int) get_port_h; 20 | int shared; 21 | 22 | function void build_phase(uvm_phase phase); 23 | get_port_h = new("get_port_h", this); 24 | endfunction : build_phase 25 | 26 | 27 | function new(string name, uvm_component parent); 28 | super.new(name, parent); 29 | endfunction : new 30 | 31 | task run_phase(uvm_phase phase); 32 | forever begin 33 | get_port_h.get(shared); 34 | $display("Received: %0d", shared); 35 | end 36 | endtask : run_phase 37 | endclass : consumer 38 | 39 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/example_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package example_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | 21 | `include "producer.svh" 22 | `include "consumer.svh" 23 | `include "communication_test.svh" 24 | endpackage : example_pkg 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/producer.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class producer extends uvm_component; 17 | `uvm_component_utils(producer); 18 | 19 | int shared; 20 | uvm_put_port #(int) put_port_h; 21 | 22 | function void build_phase(uvm_phase phase); 23 | put_port_h = new("put_port_h", this); 24 | endfunction : build_phase 25 | 26 | 27 | function new(string name, uvm_component parent); 28 | super.new(name, parent); 29 | endfunction : new 30 | 31 | 32 | task run_phase(uvm_phase phase); 33 | phase.raise_objection(this); 34 | repeat (3) begin 35 | put_port_h.put(++shared); 36 | $display("Sent %0d", shared); 37 | end 38 | phase.drop_objection(this); 39 | endtask : run_phase 40 | endclass : producer 41 | 42 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | vlog example_pkg.sv 5 | vlog top.sv; 6 | 7 | vsim -c top 8 | run -all 9 | exit 10 | -------------------------------------------------------------------------------- /17_Interthread_Communication/02_Blocking/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | import example_pkg::*; 21 | 22 | initial run_test("communication_test"); 23 | endmodule : top 24 | 25 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/communication_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class communication_test extends uvm_test; 17 | `uvm_component_utils(communication_test) 18 | 19 | producer producer_h; 20 | consumer consumer_h; 21 | uvm_tlm_fifo #(int) fifo_h; 22 | 23 | function void build_phase(uvm_phase phase); 24 | producer_h = new("producer_h", this); 25 | consumer_h = new("consumer_h", this); 26 | fifo_h = new("fifo_h",this); 27 | endfunction : build_phase 28 | 29 | function new(string name, uvm_component parent); 30 | super.new(name, parent); 31 | endfunction : new 32 | 33 | function void connect_phase(uvm_phase phase); 34 | producer_h.put_port_h.connect(fifo_h.put_export); 35 | consumer_h.get_port_h.connect(fifo_h.get_export); 36 | 37 | endfunction : connect_phase 38 | endclass : communication_test 39 | 40 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/consumer.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class consumer extends uvm_component; 17 | `uvm_component_utils(consumer); 18 | 19 | uvm_get_port #(int) get_port_h; 20 | virtual clk_bfm clk_bfm_i; 21 | int shared; 22 | 23 | function void build_phase(uvm_phase phase); 24 | 25 | get_port_h = new("get_port_h", this); 26 | clk_bfm_i = example_pkg::clk_bfm_i; 27 | endfunction : build_phase 28 | 29 | task run_phase(uvm_phase phase); 30 | forever begin 31 | @(posedge clk_bfm_i.clk); 32 | if(get_port_h.try_get(shared)) 33 | $display("%0tns Received: %0d", $time,shared); 34 | end 35 | endtask : run_phase 36 | 37 | 38 | function new(string name, uvm_component parent); 39 | super.new(name, parent); 40 | endfunction : new 41 | 42 | endclass : consumer 43 | 44 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/example_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package example_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | virtual clk_bfm clk_bfm_i; 21 | 22 | `include "producer.svh" 23 | `include "consumer.svh" 24 | `include "communication_test.svh" 25 | endpackage : example_pkg 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/producer.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class producer extends uvm_component; 17 | `uvm_component_utils(producer); 18 | 19 | int shared; 20 | uvm_put_port #(int) put_port_h; 21 | 22 | function void build_phase(uvm_phase phase); 23 | 24 | put_port_h = new("put_port_h", this); 25 | endfunction : build_phase 26 | 27 | task run_phase(uvm_phase phase); 28 | phase.raise_objection(this); 29 | repeat (3) begin 30 | #17; 31 | put_port_h.put(++shared); 32 | $display("%0tns Sent %0d", $time, shared); 33 | end 34 | #17; 35 | phase.drop_objection(this); 36 | endtask : run_phase 37 | 38 | function new(string name, uvm_component parent); 39 | super.new(name, parent); 40 | endfunction : new 41 | 42 | endclass : producer 43 | 44 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | vlog example_pkg.sv 5 | vlog top.sv; 6 | 7 | vsim -c top 8 | run -all 9 | exit 10 | -------------------------------------------------------------------------------- /17_Interthread_Communication/03_NonBlocking/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | interface clk_bfm; 18 | bit clk; 19 | initial clk = 0; 20 | always #7 clk = ~clk; 21 | endinterface : clk_bfm 22 | 23 | 24 | module top; 25 | import uvm_pkg::*; 26 | `include "uvm_macros.svh" 27 | 28 | import example_pkg::*; 29 | 30 | clk_bfm clk_bfm_i(); 31 | 32 | initial begin 33 | example_pkg::clk_bfm_i = clk_bfm_i; 34 | run_test("communication_test"); 35 | end 36 | 37 | endmodule : top 38 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | 14 | 15 | vlog -f tb.f 16 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 17 | vsim top_optimized -coverage +UVM_TESTNAME=random_test 18 | set NoQuitOnFinish 1 19 | onbreak {resume} 20 | log /* -r 21 | run -all 22 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 23 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 24 | coverage save random_test.ucdb 25 | 26 | 27 | vsim top_optimized -coverage +UVM_TESTNAME=add_test 28 | set NoQuitOnFinish 1 29 | onbreak {resume} 30 | log /* -r 31 | run -all 32 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 33 | coverage exclude -src ../../tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 34 | coverage save add_test.ucdb 35 | 36 | vcover merge tinyalu.ucdb random_test.ucdb add_test.ucdb 37 | vcover report tinyalu.ucdb -cvg -details 38 | quit 39 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends random_test; 17 | `uvm_component_utils(add_test); 18 | 19 | 20 | function new (string name, uvm_component parent); 21 | super.new(name,parent); 22 | endfunction : new 23 | 24 | function void build_phase(uvm_phase phase); 25 | random_tester::type_id::set_type_override(add_tester::get_type()); 26 | super.build_phase(phase); 27 | endfunction : build_phase 28 | 29 | endclass 30 | 31 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | `uvm_component_utils(add_tester) 18 | 19 | function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | return add_op; 22 | endfunction : get_op 23 | 24 | function new (string name, uvm_component parent); 25 | super.new(name, parent); 26 | endfunction : new 27 | 28 | endclass : add_tester 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/driver.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class driver extends uvm_component; 17 | `uvm_component_utils(driver) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_get_port #(command_s) command_port; 22 | 23 | function void build_phase(uvm_phase phase); 24 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 25 | $fatal("Failed to get BFM"); 26 | command_port = new("command_port",this); 27 | endfunction : build_phase 28 | 29 | task run_phase(uvm_phase phase); 30 | command_s command; 31 | shortint result; 32 | 33 | forever begin : command_loop 34 | command_port.get(command); 35 | bfm.send_op(command.A, command.B, command.op, result); 36 | end : command_loop 37 | endtask : run_phase 38 | 39 | function new (string name, uvm_component parent); 40 | super.new(name, parent); 41 | endfunction : new 42 | 43 | endclass : driver 44 | 45 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | env env_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | env_h = env::type_id::create("env_h",this); 27 | endfunction : build_phase 28 | 29 | endclass 30 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/random_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_tester extends base_tester; 17 | `uvm_component_utils (random_tester) 18 | 19 | virtual function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | op_choice = $random; 22 | case (op_choice) 23 | 3'b000 : return no_op; 24 | 3'b001 : return add_op; 25 | 3'b010 : return and_op; 26 | 3'b011 : return xor_op; 27 | 3'b100 : return mul_op; 28 | 3'b101 : return no_op; 29 | 3'b110 : return rst_op; 30 | 3'b111 : return rst_op; 31 | endcase // case (op_choice) 32 | endfunction : get_op 33 | 34 | virtual function byte get_data(); 35 | bit [1:0] zero_ones; 36 | zero_ones = $random; 37 | if (zero_ones == 2'b00) 38 | return 8'h00; 39 | else if (zero_ones == 2'b11) 40 | return 8'hFF; 41 | else 42 | return $random; 43 | endfunction : get_data 44 | 45 | function new (string name, uvm_component parent); 46 | super.new(name, parent); 47 | endfunction : new 48 | 49 | endclass : random_tester 50 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | uvm_analysis_port #(shortint) ap; 20 | 21 | function void write_to_monitor(shortint r); 22 | $display ("RESULT MONITOR: resultA: 0x%0h",r); 23 | ap.write(r); 24 | endfunction : write_to_monitor 25 | 26 | function void build_phase(uvm_phase phase); 27 | virtual tinyalu_bfm bfm; 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | $fatal("Failed to get BFM"); 30 | bfm.result_monitor_h = this; 31 | ap = new("ap",this); 32 | endfunction : build_phase 33 | 34 | function new (string name, uvm_component parent); 35 | super.new(name, parent); 36 | endfunction : new 37 | 38 | endclass : result_monitor 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tb_classes/vcs_base_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class base_tester extends uvm_component; 17 | `uvm_component_utils(base_tester) 18 | virtual tinyalu_bfm bfm; 19 | 20 | function void build_phase(uvm_phase phase); 21 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 22 | $fatal("Failed to get BFM"); 23 | endfunction : build_phase 24 | 25 | virtual function operation_t get_op(); 26 | return no_op; 27 | endfunction 28 | 29 | virtual function byte get_data(); 30 | return 0; 31 | endfunction 32 | 33 | task run_phase(uvm_phase phase); 34 | byte unsigned iA; 35 | byte unsigned iB; 36 | operation_t op_set; 37 | shortint result; 38 | 39 | phase.raise_objection(this); 40 | bfm.reset_alu(); 41 | repeat (1000) begin : random_loop 42 | op_set = get_op(); 43 | iA = get_data(); 44 | iB = get_data(); 45 | bfm.send_op(iA, iB, op_set, result); 46 | end : random_loop 47 | #500; 48 | phase.drop_objection(this); 49 | endtask : run_phase 50 | 51 | 52 | function new (string name, uvm_component parent); 53 | super.new(name, parent); 54 | endfunction : new 55 | 56 | endclass : base_tester 57 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | 28 | 29 | typedef struct { 30 | byte unsigned A; 31 | byte unsigned B; 32 | operation_t op; 33 | } command_s; 34 | 35 | 36 | 37 | 38 | `include "coverage.svh" 39 | `include "base_tester.svh" 40 | `include "random_tester.svh" 41 | `include "add_tester.svh" 42 | `include "scoreboard.svh" 43 | `include "driver.svh" 44 | `include "command_monitor.svh" 45 | `include "result_monitor.svh" 46 | 47 | `include "env.svh" 48 | 49 | `include "random_test.svh" 50 | `include "add_test.svh" 51 | 52 | endpackage : tinyalu_pkg 53 | 54 | -------------------------------------------------------------------------------- /18_Put_and_Get_in_Action/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /19_UVM_Reporting/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /19_UVM_Reporting/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optim +acc +cover=sbfec+tinyalu(rtl). 15 | 16 | 17 | vsim top_optim -coverage +UVM_TESTNAME=random_test 18 | 19 | 20 | set NoQuitOnFinish 1 21 | onbreak {resume} 22 | log /* -r 23 | run -all 24 | 25 | quit 26 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends random_test; 17 | `uvm_component_utils(add_test); 18 | 19 | function new (string name, uvm_component parent); 20 | super.new(name,parent); 21 | endfunction : new 22 | 23 | function void build_phase(uvm_phase phase); 24 | random_tester::type_id::set_type_override(add_tester::get_type()); 25 | 26 | endfunction : build_phase 27 | 28 | endclass 29 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/add_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_tester extends random_tester; 17 | `uvm_component_utils(add_tester) 18 | 19 | function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | return add_op; 22 | endfunction : get_op 23 | 24 | function new (string name, uvm_component parent); 25 | super.new(name, parent); 26 | endfunction : new 27 | 28 | endclass : add_tester 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/driver.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class driver extends uvm_component; 17 | `uvm_component_utils(driver) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_get_port #(command_s) command_port; 22 | 23 | function void build_phase(uvm_phase phase); 24 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 25 | `uvm_fatal("DRIVER", "Failed to get BFM"); 26 | command_port = new("command_port",this); 27 | endfunction : build_phase 28 | 29 | task run_phase(uvm_phase phase); 30 | command_s command; 31 | shortint result; 32 | 33 | forever begin : command_loop 34 | command_port.get(command); 35 | bfm.send_op(command.A, command.B, command.op, result); 36 | end : command_loop 37 | endtask : run_phase 38 | 39 | function new (string name, uvm_component parent); 40 | super.new(name, parent); 41 | endfunction : new 42 | 43 | endclass : driver 44 | 45 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | env env_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | env_h = env::type_id::create("env_h",this); 27 | endfunction : build_phase 28 | 29 | endclass 30 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/random_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_tester extends base_tester; 17 | `uvm_component_utils (random_tester) 18 | 19 | virtual function operation_t get_op(); 20 | bit [2:0] op_choice; 21 | op_choice = $random; 22 | case (op_choice) 23 | 3'b000 : return no_op; 24 | 3'b001 : return add_op; 25 | 3'b010 : return and_op; 26 | 3'b011 : return xor_op; 27 | 3'b100 : return mul_op; 28 | 3'b101 : return no_op; 29 | 3'b110 : return rst_op; 30 | 3'b111 : return rst_op; 31 | endcase // case (op_choice) 32 | endfunction : get_op 33 | 34 | virtual function byte get_data(); 35 | bit [1:0] zero_ones; 36 | zero_ones = $random; 37 | if (zero_ones == 2'b00) 38 | return 8'h00; 39 | else if (zero_ones == 2'b11) 40 | return 8'hFF; 41 | else 42 | return $random; 43 | endfunction : get_data 44 | 45 | function new (string name, uvm_component parent); 46 | super.new(name, parent); 47 | endfunction : new 48 | 49 | endclass : random_tester 50 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | uvm_analysis_port #(shortint) ap; 20 | 21 | function void write_to_monitor(shortint r); 22 | `uvm_info ("RESULT MONITOR",$sformatf("resultA: 0x%0h",r), UVM_HIGH) 23 | ap.write(r); 24 | endfunction : write_to_monitor 25 | 26 | function void build_phase(uvm_phase phase); 27 | virtual tinyalu_bfm bfm; 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | `uvm_fatal("RESULT MONITOR", "Failed to get BFM") 30 | 31 | bfm.result_monitor_h = this; 32 | ap = new("ap",this); 33 | endfunction : build_phase 34 | 35 | function new (string name, uvm_component parent); 36 | super.new(name, parent); 37 | endfunction : new 38 | 39 | endclass : result_monitor 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tb_classes/vcs_base_tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class base_tester extends uvm_component; 17 | `uvm_component_utils(base_tester) 18 | virtual tinyalu_bfm bfm; 19 | 20 | function void build_phase(uvm_phase phase); 21 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 22 | $fatal("Failed to get BFM"); 23 | endfunction : build_phase 24 | 25 | virtual function operation_t get_op(); 26 | return no_op; 27 | endfunction 28 | 29 | virtual function byte get_data(); 30 | return 0; 31 | endfunction 32 | 33 | task run_phase(uvm_phase phase); 34 | byte unsigned iA; 35 | byte unsigned iB; 36 | operation_t op_set; 37 | shortint result; 38 | 39 | phase.raise_objection(this); 40 | bfm.reset_alu(); 41 | repeat (1000) begin : random_loop 42 | op_set = get_op(); 43 | iA = get_data(); 44 | iB = get_data(); 45 | bfm.send_op(iA, iB, op_set, result); 46 | end : random_loop 47 | #500; 48 | phase.drop_objection(this); 49 | endtask : run_phase 50 | 51 | 52 | function new (string name, uvm_component parent); 53 | super.new(name, parent); 54 | endfunction : new 55 | 56 | endclass : base_tester 57 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tinyalu_driver_c.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class tinyalu_driver_c extends uvm_component; 17 | `uvm_component_utils(tinyalu_driver_c) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_get_port #(command_s) command_port; 22 | 23 | function new (string name, uvm_component parent); 24 | super.new(name, parent); 25 | endfunction : new 26 | 27 | function void build_phase(uvm_phase phase); 28 | bfm = tinyalu_pkg::bfm_g; 29 | command_port = new("command_port",this); 30 | endfunction : build_phase 31 | 32 | task run_phase(uvm_phase phase); 33 | command_s command; 34 | shortint result; 35 | 36 | forever begin : command_loop 37 | command_port.get(command); 38 | bfm.send_op(command.A, command.B, command.op, result); 39 | end : command_loop 40 | endtask : run_phase 41 | 42 | 43 | endclass : tinyalu_driver_c 44 | 45 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /19_UVM_Reporting/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] {no_op = 3'b000, 21 | add_op = 3'b001, 22 | and_op = 3'b010, 23 | xor_op = 3'b011, 24 | mul_op = 3'b100, 25 | rst_op = 3'b111} operation_t; 26 | 27 | 28 | 29 | typedef struct { 30 | byte unsigned A; 31 | byte unsigned B; 32 | operation_t op; 33 | } command_s; 34 | 35 | 36 | 37 | 38 | `include "coverage.svh" 39 | `include "base_tester.svh" 40 | `include "random_tester.svh" 41 | `include "add_tester.svh" 42 | `include "scoreboard.svh" 43 | `include "driver.svh" 44 | `include "command_monitor.svh" 45 | `include "result_monitor.svh" 46 | 47 | `include "env.svh" 48 | 49 | `include "random_test.svh" 50 | `include "add_test.svh" 51 | 52 | endpackage : tinyalu_pkg 53 | 54 | -------------------------------------------------------------------------------- /19_UVM_Reporting/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /20_Deep_Operations/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | vlog deep.sv 4 | vsim -c -voptargs="+acc" top 5 | run -all 6 | quit 7 | -------------------------------------------------------------------------------- /20_Deep_Operations/sv.f: -------------------------------------------------------------------------------- 1 | pure_virtual.sv 2 | -------------------------------------------------------------------------------- /21_UVM_Transactions/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /21_UVM_Transactions/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | 14 | vlog -f tb.f 15 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 16 | vsim top_optimized -coverage +UVM_TESTNAME=random_test 17 | set NoQuitOnFinish 1 18 | onbreak {resume} 19 | log /* -r 20 | run -all 21 | 22 | 23 | vsim top_optimized -coverage +UVM_TESTNAME=add_test -uvmcontrol=debug 24 | set NoQuitOnFinish 1 25 | onbreak {resume} 26 | log /* -r 27 | run -all 28 | quit 29 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+./tb_classes 5 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/add_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_test extends random_test; 17 | `uvm_component_utils(add_test); 18 | 19 | function void build_phase(uvm_phase phase); 20 | command_transaction::type_id::set_type_override(add_transaction::get_type()); 21 | super.build_phase(phase); 22 | endfunction : build_phase 23 | 24 | function new (string name, uvm_component parent); 25 | super.new(name,parent); 26 | endfunction : new 27 | 28 | 29 | endclass 30 | 31 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/add_transaction.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_transaction extends command_transaction; 17 | `uvm_object_utils(add_transaction) 18 | 19 | constraint add_only {op == add_op;} 20 | 21 | function new(string name="");super.new(name);endfunction 22 | endclass : add_transaction 23 | 24 | 25 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/command_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class command_monitor extends uvm_component; 17 | `uvm_component_utils(command_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_analysis_port #(command_transaction) ap; 22 | 23 | function new (string name, uvm_component parent); 24 | super.new(name,parent); 25 | endfunction 26 | 27 | function void build_phase(uvm_phase phase); 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | `uvm_fatal("COMMAND MONITOR", "Failed to get BFM") 30 | bfm.command_monitor_h = this; 31 | ap = new("ap",this); 32 | endfunction : build_phase 33 | 34 | function void write_to_monitor(byte A, byte B, operation_t op); 35 | command_transaction cmd; 36 | `uvm_info("COMMAND MONITOR",$sformatf("MONITOR: A: %2h B: %2h op: %s", 37 | A, B, op.name()), UVM_HIGH); 38 | cmd = new("cmd"); 39 | cmd.A = A; 40 | cmd.B = B; 41 | cmd.op = op; 42 | ap.write(cmd); 43 | endfunction : write_to_monitor 44 | endclass : command_monitor 45 | 46 | 47 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/driver.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class driver extends uvm_component; 17 | `uvm_component_utils(driver) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_get_port #(command_transaction) command_port; 22 | 23 | function new (string name, uvm_component parent); 24 | super.new(name, parent); 25 | endfunction : new 26 | 27 | function void build_phase(uvm_phase phase); 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | `uvm_fatal("DRIVER", "Failed to get BFM") 30 | command_port = new("command_port",this); 31 | endfunction : build_phase 32 | 33 | task run_phase(uvm_phase phase); 34 | byte unsigned iA; 35 | byte unsigned iB; 36 | operation_t op_set; 37 | shortint result; 38 | command_transaction command; 39 | forever begin : command_loop 40 | command_port.get(command); 41 | bfm.send_op(command.A, command.B, command.op, result); 42 | end : command_loop 43 | endtask : run_phase 44 | 45 | 46 | endclass : driver 47 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/random_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_test extends uvm_test; 17 | `uvm_component_utils(random_test); 18 | 19 | env env_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | env_h = env::type_id::create("env",this); 27 | endfunction : build_phase 28 | 29 | endclass 30 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | uvm_analysis_port #(result_transaction) ap; 21 | 22 | function new (string name, uvm_component parent); 23 | super.new(name, parent); 24 | endfunction : new 25 | 26 | function void build_phase(uvm_phase phase); 27 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 28 | `uvm_fatal("RESULT MONITOR", "Failed to get BFM") 29 | 30 | bfm.result_monitor_h = this; 31 | ap = new("ap",this); 32 | endfunction : build_phase 33 | 34 | function void write_to_monitor(shortint r); 35 | result_transaction result_t; 36 | result_t = new("result_t"); 37 | result_t.result = r; 38 | ap.write(result_t); 39 | endfunction : write_to_monitor 40 | 41 | endclass : result_monitor 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tb_classes/tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class tester extends uvm_component; 17 | `uvm_component_utils (tester) 18 | 19 | uvm_put_port #(command_transaction) command_port; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name, parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | command_port = new("command_port", this); 27 | endfunction : build_phase 28 | 29 | task run_phase(uvm_phase phase); 30 | command_transaction command; 31 | 32 | phase.raise_objection(this); 33 | 34 | command = new("command"); 35 | command.op = rst_op; 36 | command_port.put(command); 37 | 38 | repeat (10) begin 39 | command = command_transaction::type_id::create("command"); 40 | assert(command.randomize()); 41 | command_port.put(command); 42 | end 43 | 44 | command = new("command"); 45 | command.op = mul_op; 46 | command.A = 8'hFF; 47 | command.B = 8'hFF; 48 | command_port.put(command); 49 | 50 | #500; 51 | phase.drop_objection(this); 52 | endtask : run_phase 53 | endclass : tester 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /21_UVM_Transactions/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] { 21 | no_op = 3'b000, 22 | add_op = 3'b001, 23 | and_op = 3'b010, 24 | xor_op = 3'b011, 25 | mul_op = 3'b100, 26 | rst_op = 3'b111} operation_t; 27 | 28 | 29 | `include "command_transaction.svh" 30 | `include "add_transaction.svh" 31 | `include "result_transaction.svh" 32 | `include "coverage.svh" 33 | `include "tester.svh" 34 | `include "scoreboard.svh" 35 | `include "driver.svh" 36 | `include "command_monitor.svh" 37 | `include "result_monitor.svh" 38 | 39 | `include "env.svh" 40 | 41 | `include "random_test.svh" 42 | `include "add_test.svh" 43 | 44 | endpackage : tinyalu_pkg 45 | -------------------------------------------------------------------------------- /21_UVM_Transactions/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /22_UVM_Agents/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /22_UVM_Agents/run.do: -------------------------------------------------------------------------------- 1 | if [file exists "work"] {vdel -all} 2 | vlib work 3 | 4 | # Comment out either the SystemVerilog or VHDL DUT. 5 | # There can be only one! 6 | 7 | #VHDL DUT 8 | vcom -f dut.f 9 | 10 | # SystemVerilog DUT 11 | # vlog ../misc/tinyalu.sv 12 | 13 | vlog -f tb.f 14 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 15 | vsim top_optimized -coverage 16 | set NoQuitOnFinish 1 17 | onbreak {resume} 18 | log /* -r 19 | run -all 20 | quit 21 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_tester_module.sv 3 | tinyalu_bfm.sv 4 | top.sv 5 | +incdir+tb_classes 6 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/add_transaction.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_transaction extends command_transaction; 17 | `uvm_object_utils(add_transaction) 18 | 19 | constraint add_only {op == add_op;} 20 | 21 | function new(string name="");super.new(name);endfunction 22 | endclass : add_transaction 23 | 24 | 25 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/command_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class command_monitor extends uvm_component; 17 | `uvm_component_utils(command_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_analysis_port #(command_transaction) ap; 22 | 23 | function new (string name, uvm_component parent); 24 | super.new(name,parent); 25 | endfunction 26 | 27 | function void build_phase(uvm_phase phase); 28 | tinyalu_agent_config tinyalu_agent_config_h; 29 | if(!uvm_config_db #(tinyalu_agent_config)::get(this, "","config", tinyalu_agent_config_h)) 30 | `uvm_fatal("COMMAND MONITOR", "Failed to get CONFIG"); 31 | tinyalu_agent_config_h.bfm.command_monitor_h = this; 32 | ap = new("ap",this); 33 | endfunction : build_phase 34 | 35 | function void write_to_monitor(byte A, byte B, operation_t op); 36 | command_transaction cmd; 37 | `uvm_info("COMMAND MONITOR",$sformatf("MONITOR: A: %2h B: %2h op: %s", 38 | A, B, op.name()), UVM_HIGH); 39 | cmd = new("cmd"); 40 | cmd.A = A; 41 | cmd.B = B; 42 | cmd.op = op; 43 | ap.write(cmd); 44 | endfunction : write_to_monitor 45 | endclass : command_monitor 46 | 47 | 48 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/driver.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class driver extends uvm_component; 17 | `uvm_component_utils(driver) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | uvm_get_port #(command_transaction) command_port; 22 | 23 | function new (string name, uvm_component parent); 24 | super.new(name, parent); 25 | endfunction : new 26 | 27 | function void build_phase(uvm_phase phase); 28 | tinyalu_agent_config tinyalu_agent_config_h; 29 | if(!uvm_config_db #(tinyalu_agent_config)::get(this, "","config", tinyalu_agent_config_h)) 30 | `uvm_fatal("DRIVER", "Failed to get BFM"); 31 | bfm = tinyalu_agent_config_h.bfm; 32 | command_port = new("command_port",this); 33 | endfunction : build_phase 34 | 35 | task run_phase(uvm_phase phase); 36 | byte unsigned iA; 37 | byte unsigned iB; 38 | operation_t op_set; 39 | shortint result; 40 | command_transaction command; 41 | forever begin : command_loop 42 | command_port.get(command); 43 | bfm.send_op(command.A, command.B, command.op, result); 44 | end : command_loop 45 | endtask : run_phase 46 | 47 | 48 | endclass : driver 49 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/dual_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class dual_test extends uvm_test; 17 | `uvm_component_utils(dual_test); 18 | 19 | env env_h; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name,parent); 23 | endfunction : new 24 | 25 | 26 | function void build_phase(uvm_phase phase); 27 | 28 | virtual tinyalu_bfm class_bfm, module_bfm; 29 | env_config env_config_h; 30 | 31 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(this, "","class_bfm", class_bfm)) 32 | `uvm_fatal("DUAL TEST", "Failed to get CLASS BFM"); 33 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(this, "","module_bfm", module_bfm)) 34 | `uvm_fatal("DUAL TEST", "Failed to get MODULE BFM"); 35 | 36 | env_config_h = new(.class_bfm(class_bfm), .module_bfm(module_bfm)); 37 | 38 | uvm_config_db #(env_config)::set(this, "env_h*", "config", env_config_h); 39 | 40 | env_h = env::type_id::create("env_h",this); 41 | endfunction : build_phase 42 | 43 | 44 | endclass 45 | 46 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/env_config.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class env_config; 17 | virtual tinyalu_bfm class_bfm; 18 | virtual tinyalu_bfm module_bfm; 19 | 20 | function new(virtual tinyalu_bfm class_bfm, virtual tinyalu_bfm module_bfm); 21 | this.class_bfm = class_bfm; 22 | this.module_bfm = module_bfm; 23 | endfunction : new 24 | endclass : env_config 25 | 26 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | uvm_analysis_port #(result_transaction) ap; 21 | 22 | function new (string name, uvm_component parent); 23 | super.new(name, parent); 24 | endfunction : new 25 | 26 | function void build_phase(uvm_phase phase); 27 | tinyalu_agent_config tinyalu_agent_config_h; 28 | if(!uvm_config_db #(tinyalu_agent_config)::get(this, "","config", tinyalu_agent_config_h)) 29 | `uvm_fatal("RESULT MONITOR", "Failed to get CONFIG"); 30 | 31 | tinyalu_agent_config_h.bfm.result_monitor_h = this; 32 | ap = new("ap",this); 33 | endfunction : build_phase 34 | 35 | function void write_to_monitor(shortint r); 36 | result_transaction result_t; 37 | result_t = new("result_t"); 38 | result_t.result = r; 39 | ap.write(result_t); 40 | endfunction : write_to_monitor 41 | 42 | endclass : result_monitor 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/result_transaction.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_transaction extends uvm_transaction; 17 | 18 | shortint result; 19 | 20 | function new(string name = ""); 21 | super.new(name); 22 | endfunction : new 23 | 24 | 25 | function void do_copy(uvm_object rhs); 26 | result_transaction copied_transaction_h; 27 | assert(rhs != null) else 28 | $fatal(1,"Tried to copy null transaction"); 29 | super.do_copy(rhs); 30 | assert($cast(copied_transaction_h,rhs)) else 31 | $fatal(1,"Faied cast in do_copy"); 32 | result = copied_transaction_h.result; 33 | endfunction : do_copy 34 | 35 | function string convert2string(); 36 | string s; 37 | s = $sformatf("result: %4h",result); 38 | return s; 39 | endfunction : convert2string 40 | 41 | function bit do_compare(uvm_object rhs, uvm_comparer comparer); 42 | result_transaction RHS; 43 | bit same; 44 | assert(rhs != null) else 45 | $fatal(1,"Tried to copare null transaction"); 46 | 47 | same = super.do_compare(rhs, comparer); 48 | 49 | $cast(RHS, rhs); 50 | same = (result == RHS.result) && same; 51 | return same; 52 | endfunction : do_compare 53 | 54 | 55 | 56 | endclass : result_transaction 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/tester.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class tester extends uvm_component; 17 | `uvm_component_utils (tester) 18 | 19 | uvm_put_port #(command_transaction) command_port; 20 | 21 | function new (string name, uvm_component parent); 22 | super.new(name, parent); 23 | endfunction : new 24 | 25 | function void build_phase(uvm_phase phase); 26 | command_port = new("command_port", this); 27 | endfunction : build_phase 28 | 29 | task run_phase(uvm_phase phase); 30 | command_transaction command; 31 | 32 | phase.raise_objection(this); 33 | 34 | command = new("command"); 35 | command.op = rst_op; 36 | command_port.put(command); 37 | 38 | repeat (10) begin 39 | command = command_transaction::type_id::create("command"); 40 | assert(command.randomize()); 41 | command_port.put(command); 42 | end 43 | 44 | command = new("command"); 45 | command.op = mul_op; 46 | command.A = 8'hFF; 47 | command.B = 8'hFF; 48 | command_port.put(command); 49 | 50 | #500; 51 | phase.drop_objection(this); 52 | endtask : run_phase 53 | endclass : tester 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /22_UVM_Agents/tb_classes/tinyalu_agent_config.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class tinyalu_agent_config; 17 | 18 | virtual tinyalu_bfm bfm; 19 | protected uvm_active_passive_enum is_active; 20 | 21 | function new (virtual tinyalu_bfm bfm, uvm_active_passive_enum 22 | is_active); 23 | this.bfm = bfm; 24 | this.is_active = is_active; 25 | endfunction : new 26 | 27 | function uvm_active_passive_enum get_is_active(); 28 | return is_active; 29 | endfunction : get_is_active 30 | 31 | endclass : tinyalu_agent_config 32 | -------------------------------------------------------------------------------- /22_UVM_Agents/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /22_UVM_Agents/tinyalu_pkg.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package tinyalu_pkg; 17 | import uvm_pkg::*; 18 | `include "uvm_macros.svh" 19 | 20 | typedef enum bit[2:0] { 21 | no_op = 3'b000, 22 | add_op = 3'b001, 23 | and_op = 3'b010, 24 | xor_op = 3'b011, 25 | mul_op = 3'b100, 26 | rst_op = 3'b111} operation_t; 27 | 28 | 29 | 30 | `include "env_config.svh" 31 | `include "tinyalu_agent_config.svh" 32 | `include "command_transaction.svh" 33 | `include "add_transaction.svh" 34 | `include "result_transaction.svh" 35 | `include "coverage.svh" 36 | `include "tester.svh" 37 | `include "scoreboard.svh" 38 | `include "driver.svh" 39 | `include "command_monitor.svh" 40 | `include "result_monitor.svh" 41 | `include "tinyalu_agent.svh" 42 | `include "env.svh" 43 | 44 | `include "dual_test.svh" 45 | 46 | 47 | endpackage : tinyalu_pkg 48 | -------------------------------------------------------------------------------- /22_UVM_Agents/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm class_bfm(); 23 | 24 | tinyalu class_dut (.A(class_bfm.A), .B(class_bfm.B), .op(class_bfm.op), 25 | .clk(class_bfm.clk), .reset_n(class_bfm.reset_n), 26 | .start(class_bfm.start), .done(class_bfm.done), 27 | .result(class_bfm.result)); 28 | 29 | tinyalu_bfm module_bfm(); 30 | 31 | tinyalu module_dut (.A(module_bfm.A), .B(module_bfm.B), .op(module_bfm.op), 32 | .clk(module_bfm.clk), .reset_n(module_bfm.reset_n), 33 | .start(module_bfm.start), .done(module_bfm.done), 34 | .result(module_bfm.result)); 35 | 36 | tinyalu_tester_module stim_module(module_bfm); 37 | 38 | initial begin 39 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "class_bfm", class_bfm); 40 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "module_bfm", module_bfm); 41 | run_test("dual_test"); 42 | end 43 | 44 | endmodule : top 45 | 46 | 47 | -------------------------------------------------------------------------------- /23_UVM_Sequences/dut.f: -------------------------------------------------------------------------------- 1 | tinyalu_dut/single_cycle_add_and_xor.vhd 2 | tinyalu_dut/three_cycle_mult.vhd 3 | tinyalu_dut/tinyalu.vhd 4 | -------------------------------------------------------------------------------- /23_UVM_Sequences/run.do: -------------------------------------------------------------------------------- 1 | 2 | if [file exists "work"] {vdel -all} 3 | vlib work 4 | 5 | # Comment out either the SystemVerilog or VHDL DUT. 6 | # There can be only one! 7 | 8 | #VHDL DUT 9 | vcom -f dut.f 10 | 11 | # SystemVerilog DUT 12 | # vlog ../misc/tinyalu.sv 13 | 14 | vlog -f tb.f 15 | vopt top -o top_optimized +acc +cover=sbfec+tinyalu(rtl). 16 | 17 | vsim top_optimized -coverage +UVM_TESTNAME=fibonacci_test 18 | set NoQuitOnFinish 1 19 | onbreak {resume} 20 | log /* -r 21 | run -all 22 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 23 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 24 | coverage attribute -name TESTNAME -value fibonacci_test 25 | coverage save fibonacci_test.ucdb 26 | 27 | vsim top_optimized -coverage +UVM_TESTNAME=parallel_test 28 | set NoQuitOnFinish 1 29 | onbreak {resume} 30 | log /* -r 31 | run -all 32 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 33 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 34 | coverage attribute -name TESTNAME -value parallel_test 35 | coverage save parallel_test.ucdb 36 | 37 | vsim top_optimized -coverage +UVM_TESTNAME=full_test 38 | set NoQuitOnFinish 1 39 | onbreak {resume} 40 | log /* -r 41 | run -all 42 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -line 49 -code s 43 | coverage exclude -src tinyalu_dut/single_cycle_add_and_xor.vhd -scope /top/DUT/add_and_xor -line 49 -code b 44 | coverage attribute -name TESTNAME -value full_test 45 | coverage save full_test.ucdb 46 | 47 | vcover merge tinyalu.ucdb fibonacci_test.ucdb parallel_test.ucdb full_test.ucdb 48 | vcover report tinyalu.ucdb -cvg -details 49 | 50 | quit 51 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb.f: -------------------------------------------------------------------------------- 1 | tinyalu_pkg.sv 2 | tinyalu_bfm.sv 3 | top.sv 4 | +incdir+tb_classes 5 | -suppress 2286 6 | 7 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/add_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(add_sequence); 18 | 19 | sequence_item command; 20 | 21 | function new(string name = "add"); 22 | super.new(name); 23 | endfunction : new 24 | 25 | 26 | task body(); 27 | repeat (10) begin 28 | command = add_sequence_item::type_id::create("command"); 29 | start_item(command); 30 | assert(command.randomize()); 31 | finish_item(command); 32 | end 33 | endtask : body 34 | endclass : add_sequence 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/add_sequence_item.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class add_sequence_item extends sequence_item; 17 | `uvm_object_utils(add_sequence_item) 18 | 19 | function new(input string name = "add_sequence_item"); 20 | super.new(name); 21 | endfunction 22 | 23 | constraint add_only {op == add_op;} 24 | 25 | endclass : add_sequence_item 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/command_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class command_monitor extends uvm_component; 17 | `uvm_component_utils(command_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | uvm_analysis_port #(sequence_item) ap; 21 | 22 | function new (string name, uvm_component parent); 23 | super.new(name,parent); 24 | endfunction 25 | 26 | function void build_phase(uvm_phase phase); 27 | 28 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 29 | `uvm_fatal("DRIVER", "Failed to get BFM") 30 | 31 | ap = new("ap",this); 32 | endfunction : build_phase 33 | 34 | function void connect_phase(uvm_phase phase); 35 | bfm.command_monitor_h = this; 36 | endfunction : connect_phase 37 | 38 | function void write_to_monitor(byte A, byte B, operation_t op); 39 | sequence_item cmd; 40 | `uvm_info ("COMMAND MONITOR", $sformatf("MONITOR: A: %2h B: %2h op: %s", 41 | A, B, op.name()), UVM_HIGH); 42 | cmd = new("cmd"); 43 | cmd.A = A; 44 | cmd.B = B; 45 | cmd.op = op; 46 | ap.write(cmd); 47 | endfunction : write_to_monitor 48 | endclass : command_monitor 49 | 50 | 51 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/driver.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class driver extends uvm_driver #(sequence_item); 17 | `uvm_component_utils(driver) 18 | 19 | virtual tinyalu_bfm bfm; 20 | 21 | function void build_phase(uvm_phase phase); 22 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 23 | `uvm_fatal("DRIVER", "Failed to get BFM") 24 | endfunction : build_phase 25 | 26 | task run_phase(uvm_phase phase); 27 | sequence_item cmd; 28 | 29 | forever begin : cmd_loop 30 | shortint unsigned result; 31 | seq_item_port.get_next_item(cmd); 32 | bfm.send_op(cmd.A, cmd.B, cmd.op, result); 33 | cmd.result = result; 34 | seq_item_port.item_done(); 35 | end : cmd_loop 36 | endtask : run_phase 37 | 38 | function new (string name, uvm_component parent); 39 | super.new(name, parent); 40 | endfunction : new 41 | 42 | endclass : driver 43 | 44 | 45 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/fibonacci_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class fibonacci_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(fibonacci_sequence); 18 | 19 | function new(string name = "fibonacci"); 20 | super.new(name); 21 | endfunction : new 22 | 23 | 24 | task body(); 25 | byte unsigned n_minus_2=0; 26 | byte unsigned n_minus_1=1; 27 | sequence_item command; 28 | 29 | command = sequence_item::type_id::create("command"); 30 | 31 | start_item(command); 32 | command.op = rst_op; 33 | finish_item(command); 34 | 35 | `uvm_info("FIBONACCI", " Fib(01) = 00", UVM_MEDIUM); 36 | `uvm_info("FIBONACCI", " Fib(02) = 01", UVM_MEDIUM); 37 | for(int ff = 3; ff<=14; ff++) begin 38 | start_item(command); 39 | command.A = n_minus_2; 40 | command.B = n_minus_1; 41 | command.op = add_op; 42 | finish_item(command); 43 | n_minus_2 = n_minus_1; 44 | n_minus_1 = command.result; 45 | `uvm_info("FIBONACCI", $sformatf("Fib(%02d) = %02d", ff, n_minus_1), 46 | UVM_MEDIUM); 47 | end 48 | endtask : body 49 | endclass : fibonacci_sequence 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/fibonacci_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class fibonacci_test extends tinyalu_base_test; 17 | `uvm_component_utils(fibonacci_test); 18 | 19 | task run_phase(uvm_phase phase); 20 | fibonacci_sequence fibonacci; 21 | fibonacci = new("fibonacci"); 22 | 23 | phase.raise_objection(this); 24 | fibonacci.start(sequencer_h); 25 | phase.drop_objection(this); 26 | endtask : run_phase 27 | 28 | function new(string name, uvm_component parent); 29 | super.new(name,parent); 30 | endfunction : new 31 | 32 | endclass 33 | 34 | 35 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/full_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class full_test extends tinyalu_base_test; 17 | `uvm_component_utils(full_test); 18 | 19 | runall_sequence runall_seq; 20 | 21 | task run_phase(uvm_phase phase); 22 | runall_seq = new("runall_seq"); 23 | phase.raise_objection(this); 24 | runall_seq.start(null); 25 | phase.drop_objection(this); 26 | endtask : run_phase 27 | 28 | 29 | function new (string name, uvm_component parent); 30 | super.new(name,parent); 31 | endfunction : new 32 | 33 | endclass 34 | 35 | 36 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/maxmult_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class maxmult_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(maxmult_sequence); 18 | 19 | sequence_item command; 20 | 21 | function new(string name = "maxmult_sequence"); 22 | super.new(name); 23 | endfunction : new 24 | 25 | 26 | task body(); 27 | command = sequence_item::type_id::create("command"); 28 | start_item(command); 29 | command.op = mul_op; 30 | command.A = 8'hFF; 31 | command.B = 8'hFF; 32 | finish_item(command); 33 | endtask : body 34 | 35 | endclass : maxmult_sequence 36 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/parallel_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class parallel_sequence extends uvm_sequence #(uvm_sequence_item); 17 | `uvm_object_utils(parallel_sequence); 18 | 19 | protected reset_sequence reset; 20 | protected short_random_sequence short_random; 21 | protected fibonacci_sequence fibonacci; 22 | 23 | function new(string name = "parallel_sequence"); 24 | super.new(name); 25 | reset = reset_sequence::type_id::create("reset"); 26 | fibonacci = fibonacci_sequence::type_id::create("fibonacci"); 27 | short_random = short_random_sequence::type_id::create("short_random"); 28 | endfunction : new 29 | 30 | task body(); 31 | reset.start(m_sequencer); 32 | fork 33 | fibonacci.start(m_sequencer); 34 | short_random.start(m_sequencer); 35 | join 36 | endtask : body 37 | endclass : parallel_sequence 38 | 39 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/parallel_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class parallel_test extends tinyalu_base_test; 17 | `uvm_component_utils(parallel_test); 18 | 19 | parallel_sequence parallel_h; 20 | 21 | function new(string name, uvm_component parent); 22 | super.new(name,parent); 23 | parallel_h = new("parallel_h"); 24 | endfunction : new 25 | 26 | task run_phase(uvm_phase phase); 27 | phase.raise_objection(this); 28 | parallel_h.start(sequencer_h); 29 | phase.drop_objection(this); 30 | endtask : run_phase 31 | 32 | endclass 33 | 34 | 35 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/random_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class random_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(random_sequence); 18 | 19 | sequence_item command; 20 | 21 | function new(string name = "random_sequence"); 22 | super.new(name); 23 | endfunction : new 24 | 25 | 26 | 27 | task body(); 28 | repeat (5000) begin : random_loop 29 | command = sequence_item::type_id::create("command"); 30 | start_item(command); 31 | assert(command.randomize()); 32 | finish_item(command); 33 | end : random_loop 34 | endtask : body 35 | endclass : random_sequence 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/reset_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class reset_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(reset_sequence) 18 | 19 | sequence_item command; 20 | 21 | function new(string name = "reset"); 22 | super.new(name); 23 | endfunction : new 24 | 25 | task body(); 26 | command = sequence_item::type_id::create("command"); 27 | start_item(command); 28 | command.op = rst_op; 29 | finish_item(command); 30 | endtask : body 31 | endclass : reset_sequence 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/result_monitor.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_monitor extends uvm_component; 17 | `uvm_component_utils(result_monitor); 18 | 19 | virtual tinyalu_bfm bfm; 20 | uvm_analysis_port #(result_transaction) ap; 21 | 22 | function new (string name, uvm_component parent); 23 | super.new(name, parent); 24 | endfunction : new 25 | 26 | function void build_phase(uvm_phase phase); 27 | if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) 28 | `uvm_fatal("DRIVER", "Failed to get BFM"); 29 | ap = new("ap",this); 30 | endfunction : build_phase 31 | 32 | function void connect_phase(uvm_phase phase); 33 | bfm.result_monitor_h = this; 34 | endfunction : connect_phase 35 | 36 | function void write_to_monitor(shortint r); 37 | result_transaction result_t; 38 | result_t = new("result_t"); 39 | result_t.result = r; 40 | ap.write(result_t); 41 | endfunction : write_to_monitor 42 | 43 | endclass : result_monitor 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/result_transaction.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class result_transaction extends uvm_transaction; 17 | 18 | shortint result; 19 | 20 | function new(string name = ""); 21 | super.new(name); 22 | endfunction : new 23 | 24 | 25 | function void do_copy(uvm_object rhs); 26 | result_transaction copied_transaction_h; 27 | assert(rhs != null) else 28 | $fatal(1,"Tried to copy null transaction"); 29 | super.do_copy(rhs); 30 | assert($cast(copied_transaction_h,rhs)) else 31 | $fatal(1,"Faied cast in do_copy"); 32 | result = copied_transaction_h.result; 33 | endfunction : do_copy 34 | 35 | function string convert2string(); 36 | string s; 37 | s = $sformatf("result: %4h",result); 38 | return s; 39 | endfunction : convert2string 40 | 41 | function bit do_compare(uvm_object rhs, uvm_comparer comparer); 42 | result_transaction RHS; 43 | bit same; 44 | assert(rhs != null) else 45 | $fatal(1,"Tried to copare null transaction"); 46 | 47 | same = super.do_compare(rhs, comparer); 48 | 49 | $cast(RHS, rhs); 50 | same = (result == RHS.result) && same; 51 | return same; 52 | endfunction : do_compare 53 | 54 | 55 | 56 | endclass : result_transaction 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/runall_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class runall_sequence extends uvm_sequence #(uvm_sequence_item); 17 | `uvm_object_utils(runall_sequence); 18 | 19 | protected reset_sequence reset; 20 | protected maxmult_sequence maxmult; 21 | protected random_sequence random; 22 | protected sequencer sequencer_h; 23 | protected uvm_component uvm_component_h; 24 | 25 | function new(string name = "runall_sequence"); 26 | super.new(name); 27 | 28 | uvm_component_h = uvm_top.find("*.env_h.sequencer_h"); 29 | 30 | if (uvm_component_h == null) 31 | `uvm_fatal("RUNALL SEQUENCE", "Failed to get the sequencer") 32 | 33 | if (!$cast(sequencer_h, uvm_component_h)) 34 | `uvm_fatal("RUNALL SEQUENCE", "Failed to cast from uvm_component_h.") 35 | 36 | 37 | reset = reset_sequence::type_id::create("reset"); 38 | maxmult = maxmult_sequence::type_id::create("maxmult"); 39 | random = random_sequence::type_id::create("random"); 40 | endfunction : new 41 | 42 | task body(); 43 | reset.start(sequencer_h); 44 | maxmult.start(sequencer_h); 45 | random.start(sequencer_h); 46 | endtask : body 47 | 48 | endclass : runall_sequence 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/short_random_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class short_random_sequence extends uvm_sequence #(sequence_item); 17 | `uvm_object_utils(short_random_sequence); 18 | 19 | sequence_item command; 20 | 21 | function new(string name = "short_random_sequence"); 22 | super.new(name); 23 | endfunction : new 24 | 25 | 26 | 27 | task body(); 28 | repeat (14) begin : short_random_loop 29 | command = sequence_item::type_id::create("command"); 30 | start_item(command); 31 | assert(command.randomize()); 32 | finish_item(command); 33 | // Moved relative to the book example so as to show result 34 | `uvm_info("SHORT RANDOM", $sformatf("random command: %s", command.convert2string), UVM_MEDIUM) 35 | end : short_random_loop 36 | endtask : body 37 | endclass : short_random_sequence 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/tinyalu_base_test.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | `ifdef QUESTA 17 | virtual class tinyalu_base_test extends uvm_test; 18 | `else 19 | class tinyalu_base_test extends uvm_test; 20 | `endif 21 | 22 | env env_h; 23 | sequencer sequencer_h; 24 | 25 | function void build_phase(uvm_phase phase); 26 | env_h = env::type_id::create("env_h",this); 27 | endfunction : build_phase 28 | 29 | function void end_of_elaboration_phase(uvm_phase phase); 30 | sequencer_h = env_h.sequencer_h; 31 | endfunction : end_of_elaboration_phase 32 | 33 | function new (string name, uvm_component parent); 34 | super.new(name,parent); 35 | endfunction : new 36 | 37 | endclass 38 | 39 | 40 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/tinyalu_run_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class runall_sequence extends tinyalu_sequence; 17 | `uvm_object_utils(tinyalu_runall_sequence); 18 | 19 | reset_sequence reset; 20 | maxmult_sequence maxmult; 21 | random_sequence random; 22 | 23 | task body(); 24 | reset = reset_sequence::type_id::create("reset"); 25 | maxmult = maxmult_sequence::type_id::create("maxmult"); 26 | random = random_sequence::type_id::create("random"); 27 | 28 | reset.start(m_sequencer); 29 | maxmult.start(m_sequencer); 30 | random.start(m_sequencer); 31 | endtask : body 32 | endclass : tinyalu_runall_sequence 33 | 34 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tb_classes/tinyalu_sequence.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | class tinyalu_sequence extends uvm_sequence #(tinyalu_sequence_item); 17 | 18 | tinyalu_sequence_item command; 19 | 20 | task body(); 21 | $fatal(1,"You cannot use tinalu_sequence directly. You must override it"); 22 | endtask : body 23 | 24 | endclass : tinyalu_sequence 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /23_UVM_Sequences/tinyalu_macros.svh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /23_UVM_Sequences/top.sv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Ray Salemi 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module top; 17 | import uvm_pkg::*; 18 | import tinyalu_pkg::*; 19 | `include "tinyalu_macros.svh" 20 | `include "uvm_macros.svh" 21 | 22 | tinyalu_bfm bfm(); 23 | tinyalu DUT (.A(bfm.A), .B(bfm.B), .op(bfm.op), 24 | .clk(bfm.clk), .reset_n(bfm.reset_n), 25 | .start(bfm.start), .done(bfm.done), .result(bfm.result)); 26 | 27 | 28 | initial begin 29 | uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm); 30 | run_test(); 31 | end 32 | 33 | endmodule : top 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THE UVM PRIMER CODE EXAMPLES 2 | 3 | There is nothing worse than a syntax error in a technical teaching 4 | book; the poor student is already learning new things and the error is 5 | just an unnecessary curve ball. 6 | 7 | To avoid that problem, I've compiled and simulated every example in 8 | THE UVM PRIMER and included the examples here. You can run these code 9 | examples with any simulator that supports the UVM. 10 | 11 | All the examples come with a run.do file that compiles and runs the 12 | example in Mentor Graphic's Questa simulator. You can run these 13 | examples with this command line: 14 | 15 | `% vsim -c -do run.do` 16 | 17 | If you'd like to use the GUI, remove the `-c` option. 18 | 19 | The example directories follow the chapter numbers and titles in the 20 | book. In some cases there are several examples in a chapter, so there 21 | are subdirectories for those. 22 | 23 | You can watch videos that describe the examples on Youtube. There is a 24 | link to the videos on . 25 | 26 | You can ask questions about the examples on the [UVM Primer Google group](https://groups.google.com/forum/#!forum/uvmprimer) 27 | 28 | Enjoy the examples! 29 | 30 | Ray Salemi 31 | -------------------------------------------------------------------------------- /VCS_README.md: -------------------------------------------------------------------------------- 1 | # Pure Virtual Classes and VCS 2 | 3 | It turns out that VCS and Questa have different opinions about what constitutes an error when using pure virtual classes. 4 | 5 | * Questa says that it is OK to write code that could instantiate a pure virtual class as long as no pure virtual class is ever instantiated. 6 | 7 | * VCS says that it is not OK to write code that could instantiate a pure virtual class. 8 | 9 | Several examples (starting in chapter 13) use a pure virtual class to define a `base_tester` class, but then override that class using the factory. VCS does not like these examples. 10 | 11 | To fix this I've included a file named `vcs_base_tester.svh`. To use the `vcs_base_tester.svh` file simply copy it over the `base_tester.svh` file in directories where you see it. 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /misc/README.md: -------------------------------------------------------------------------------- 1 | This directory contains miscellaneous files that don't necessarily fit 2 | into any of the examples but can be useful. 3 | 4 | * tinyalu.sv---This file provides the TinyALU as a SystemVerilog file. 5 | You use it by replacing the `vcom` line in the `run.do` file with 6 | another `vlog` line that compiles this file. 7 | 8 | 9 | --------------------------------------------------------------------------------