├── examples ├── automatic_function.sv ├── callbacks │ └── callbacks.sv ├── constraint_dist.sv ├── constraints_function_gotcha.sv ├── deep_copy │ └── shallow_vs_deep_copy.sv └── polymorphism.sv └── projects ├── counter_sv_tb ├── .gitattributes ├── .gitignore ├── env │ ├── counter_assertion.sv │ ├── counter_env.sv │ ├── counter_gen.sv │ ├── counter_if.sv │ ├── counter_pkg.sv │ ├── counter_rd_mon.sv │ ├── counter_rm.sv │ ├── counter_sb.sv │ ├── counter_trans.sv │ ├── counter_wr_bfm.sv │ ├── counter_wr_mon.sv │ └── top.sv ├── rtl │ ├── counter.v │ └── counter_tb.v ├── sim │ └── Makefile └── test │ └── test.sv └── sha3_sv_tb ├── .gitignore ├── LICENSE ├── README └── env ├── sha3_environment.sv ├── sha3_generator.sv ├── sha3_if.sv ├── sha3_pkg.sv ├── sha3_read_monitor.sv ├── sha3_transaction.sv ├── sha3_write_bfm.sv ├── sha3_write_monitor.sv └── top.sv /examples/automatic_function.sv: -------------------------------------------------------------------------------- 1 | //-------------------------- 2 | // Automatic/reentrant function 3 | // Mayur Kubavat 4 | //-------------------------- 5 | 6 | module test; 7 | 8 | // Automatic functions is re-entrant and have separate 9 | // function variable scope for each funciton call 10 | 11 | // Module functions are by default static, use automatic 12 | // identifier to make function re-entrant 13 | function automatic int factorial(int num); 14 | if(num > 1) 15 | factorial = factorial(num - 1) * num; 16 | else 17 | factorial = 1; 18 | endfunction 19 | 20 | 21 | int result; 22 | 23 | initial 24 | begin 25 | 26 | $display("\n\n\tFactorial from 1 to 5..\n"); 27 | 28 | for(int i = 0; i < 6; i++) 29 | begin 30 | 31 | // Function calls itself recursively with different 32 | // variable scope for 'int num' each time 33 | result = factorial(i); 34 | 35 | $display("\t%0d factorial = %0d", i, result); 36 | end 37 | 38 | $display("\n\tEnd of simulation..\n\n"); 39 | 40 | end //initial 41 | 42 | endmodule //test 43 | -------------------------------------------------------------------------------- /examples/callbacks/callbacks.sv: -------------------------------------------------------------------------------- 1 | module top; 2 | 3 | 4 | // Callback driver/Facade class implementing empty virtual method. 5 | // These methods are extended by specific drivers to implement 6 | // scenarios on available hooks. 7 | class Driver_cbs; 8 | 9 | virtual task pre_run(); endtask 10 | virtual task post_run(); endtask 11 | 12 | endclass // Driver_cbs 13 | 14 | 15 | // Protocol driver 16 | class Driver; 17 | 18 | Driver_cbs drv_cb_h = new(); 19 | 20 | // Pre-planned hooks in Driver class 21 | // By default does nothing. 22 | task pre_run(); 23 | drv_cb_h.pre_run(); 24 | endtask 25 | 26 | task post_run(); 27 | drv_cb_h.post_run(); 28 | endtask 29 | 30 | task run(); 31 | 32 | // Hook1 33 | pre_run(); 34 | 35 | // Protocol specific logic 36 | $display("Driver protocol execution.\n"); 37 | 38 | // Hook2 39 | post_run(); 40 | 41 | endtask // run 42 | 43 | endclass // Driver 44 | 45 | class test extends Driver_cbs; 46 | 47 | task pre_run(); 48 | $display("\n\nExecute test specific functionality.\n"); 49 | endtask 50 | 51 | endclass // test 52 | 53 | Driver drv_h; 54 | test t_h; 55 | 56 | initial 57 | begin 58 | 59 | drv_h = new(); 60 | 61 | // 62 | // To achieve callback 63 | // 64 | t_h = new(); 65 | drv_h.drv_cb_h = t_h; 66 | 67 | drv_h.run(); 68 | 69 | #100; 70 | $display("End of simulation..\n"); 71 | $finish; 72 | end 73 | 74 | endmodule // top 75 | -------------------------------------------------------------------------------- /examples/constraint_dist.sv: -------------------------------------------------------------------------------- 1 | // Random value distribution by Weight 2 | 3 | module test; 4 | 5 | class pkt; 6 | 7 | rand int data; 8 | 9 | constraint data_range { 10 | data dist {'h0000:/1, 'hffff:/95, ['h0001:'hfffe]:/ 4}; 11 | } 12 | endclass 13 | 14 | 15 | pkt pkt_; 16 | 17 | // Collect randomized hits on PKT distribution data values 18 | int set_1, set_2, set_3; 19 | int loopCount = 100; 20 | 21 | initial 22 | begin 23 | pkt_ = new(); 24 | 25 | for(int idx = 0; idx < loopCount; idx++) 26 | begin 27 | if(!pkt_.randomize()) 28 | $fatal; 29 | $display(" [RANDOMIZE]: Index (%0d) Data Value = %h", idx, pkt_.data); 30 | 31 | categorize(pkt_.data); 32 | end 33 | 34 | $display(" [RESULT]: Total Hits: %0d, SET1 = %0d, SET2 = %0d, SET3 = %0d", 35 | loopCount, set_1, set_2, set_3); 36 | end 37 | 38 | 39 | // Count number of Hits for a given range of values in CASE 40 | function void categorize(int data); 41 | case(data) 42 | 'h0 : set_1++; 43 | 'hFFFF : set_2++; 44 | default: set_3++; // For range of 'h1 to 'hFFFE 45 | endcase 46 | endfunction 47 | 48 | endmodule 49 | -------------------------------------------------------------------------------- /examples/constraints_function_gotcha.sv: -------------------------------------------------------------------------------- 1 | 2 | class constraints_gotcha; 3 | 4 | rand bit[7:0] a; 5 | 6 | function int get(bit[7:0] x); 7 | return x; 8 | endfunction 9 | 10 | constraint c1{ 11 | get(a) inside {[50:200]}; // Gotcha - Intended value a inside 50..200 12 | } 13 | 14 | endclass 15 | 16 | module top; 17 | 18 | constraints_gotcha cg_h; 19 | 20 | initial 21 | begin 22 | cg_h = new(); 23 | 24 | repeat(10) 25 | begin 26 | assert(cg_h.randomize()); 27 | $display("Value of a = %0d", cg_h.a); 28 | end 29 | 30 | $finish; 31 | end 32 | 33 | endmodule 34 | -------------------------------------------------------------------------------- /examples/deep_copy/shallow_vs_deep_copy.sv: -------------------------------------------------------------------------------- 1 | //-------------------------- 2 | // SV Shallow copy vs. Deep copy 3 | // Mayur Kubavat 4 | //-------------------------- 5 | 6 | 7 | //-------------------- 8 | // Shallow copy 9 | //-------------------- 10 | class Preamble; 11 | 12 | bit [7:0] value; 13 | 14 | endclass //Preamble 15 | 16 | 17 | class Packet; 18 | 19 | int data; 20 | 21 | Preamble pr1 = new(); 22 | 23 | endclass //Packet 24 | 25 | 26 | //-------------------- 27 | // Deep copy 28 | //-------------------- 29 | class PreambleDC; 30 | 31 | bit [7:0] value; 32 | 33 | // to perform deep copy on PreambleDC 34 | function PreambleDC copy(); 35 | 36 | // Create class object 37 | // copy is handle of class PreambleDC 38 | // copy value field to the object and return the 39 | // object handle(copy) 40 | copy = new(); 41 | copy.value = this.value; 42 | 43 | endfunction 44 | 45 | endclass //PreambleDC 46 | 47 | 48 | class PacketDC; 49 | 50 | int data; 51 | 52 | PreambleDC pr1 = new(); 53 | 54 | function PacketDC copy(); 55 | 56 | // copy is handle of class PacketDC 57 | // and copy data to the object 58 | copy = new(); 59 | copy.data = this.data; 60 | 61 | // call to copy method of PreambleDC creates and return 62 | // objects of PreambleDC 63 | copy.pr1 = pr1.copy(); 64 | 65 | endfunction 66 | 67 | endclass //PacketDC 68 | 69 | 70 | 71 | //-------------------- 72 | // module to test 73 | //-------------------- 74 | module test; 75 | 76 | 77 | // Copy method not implemented in Packet/Premable class 78 | Packet pkt1, pkt2; 79 | 80 | // Copy method implemented for deep copy 81 | PacketDC pkt_dc1, pkt_dc2; 82 | 83 | 84 | initial 85 | begin 86 | 87 | $display("\n\n\tShallow copy.."); 88 | 89 | // Create packet 1 90 | pkt1 = new(); 91 | pkt1.data = 'hFFFF; 92 | pkt1.pr1.value = 'hAA; 93 | 94 | // Performs shallow copy 95 | pkt2 = new pkt1; 96 | 97 | pkt2.data = 'hCCCC; 98 | 99 | // pkt1 and pkt2 points to same object of Preamble class: pkt2 = new pkt1 100 | // Updating sub-class field(Preamble::value) in pkt2 changes pkt1 sub-class field 101 | pkt2.pr1.value = 'h55; 102 | 103 | $display("\tPacket 1: Data %h, Preamble %h", pkt1.data, pkt1.pr1.value); 104 | $display("\tPacket 2: Data %h, Preamble %h\n", pkt2.data, pkt2.pr1.value); 105 | 106 | 107 | $display("\tDeep copy.."); 108 | 109 | // Create packet 1 110 | pkt_dc1 = new(); 111 | pkt_dc1.data = 'hFFFF; 112 | pkt_dc1.pr1.value = 'hAA; 113 | 114 | // Performs deep copy 115 | pkt_dc2 = pkt_dc1.copy(); 116 | 117 | pkt_dc2.data = 'hCCCC; 118 | pkt_dc2.pr1.value = 'h55; 119 | 120 | $display("\tPacket 1: Data %h, Preamble %h", pkt_dc1.data, pkt_dc1.pr1.value); 121 | $display("\tPacket 2: Data %h, Preamble %h\n\n", pkt_dc2.data, pkt_dc2.pr1.value); 122 | 123 | end 124 | 125 | endmodule //test 126 | 127 | -------------------------------------------------------------------------------- /examples/polymorphism.sv: -------------------------------------------------------------------------------- 1 | //--------------------------------- 2 | // Polymorphism, Virtual Functions 3 | // 4 | // When method is declared VIRTUAL in parent 5 | // class, VIRTUAL keyword in not required in 6 | // any level of extended class(e.g. Class B/C/..). 7 | // 8 | // Mayur Kubavat 9 | //--------------------------------- 10 | 11 | module polymorphism; 12 | 13 | class A; 14 | 15 | // For polymorphism to work, method prototype 16 | // (method name, return type, arguments) must 17 | // be the same. 18 | virtual function void display(); 19 | $display("Display: Class A"); 20 | endfunction 21 | 22 | function void message(); 23 | $display("Message: Class A"); 24 | endfunction 25 | 26 | endclass 27 | 28 | 29 | class B extends A; 30 | 31 | // As display() function is virtual in 32 | // class A, no need to explicitly diclare 33 | // it virtual here 34 | function void display(); 35 | $display("Display: Class B"); 36 | endfunction 37 | 38 | function void message(); 39 | $display("Message: Class B"); 40 | endfunction 41 | 42 | endclass 43 | 44 | 45 | class C extends B; 46 | 47 | // As display() function is virtual in 48 | // class A, hece class B as well, no 49 | // need to explicitly diclare it virtual here 50 | function void display(); 51 | $display("Display: Class C"); 52 | endfunction 53 | 54 | function void message(); 55 | $display("Message: Class C"); 56 | endfunction 57 | 58 | endclass 59 | 60 | 61 | A a_h; 62 | B b_h; 63 | C c_h; 64 | 65 | initial 66 | begin 67 | a_h = new(); 68 | b_h = new(); 69 | c_h = new(); 70 | 71 | a_h = b_h; 72 | 73 | $display("\n\n----------------"); 74 | $display("Accessing object B using class A handle.\n"); 75 | a_h.display(); 76 | a_h.message(); 77 | $display("----------------"); 78 | 79 | 80 | b_h = c_h; 81 | 82 | $display("\n\n----------------"); 83 | $display("Accessing object C using class B handle.\n"); 84 | b_h.display(); 85 | b_h.message(); 86 | $display("----------------\n\n"); 87 | end 88 | 89 | endmodule //polymorphism 90 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_assertion.sv: -------------------------------------------------------------------------------- 1 | module counter_assertion(clk, rst, data, updown, load, count); 2 | 3 | input logic clk, rst; 4 | input logic updown, load; 5 | input logic [3:0] data, count; 6 | 7 | 8 | property reset_prpty; 9 | @(posedge clk) rst |=> (count == 4'b0); 10 | endproperty 11 | 12 | sequence up_seq; 13 | !load && updown; 14 | endsequence 15 | 16 | sequence down_seq; 17 | !load && !updown; 18 | endsequence 19 | 20 | property up_count_prpty; 21 | @(posedge clk) disable iff(rst) 22 | up_seq |=> (count == ($past(count, 1) + 1'b1)); 23 | endproperty 24 | 25 | property down_count_prpty; 26 | @(posedge clk) disable iff(rst) 27 | down_seq |=> (count == ($past(count, 1) - 1'b1)); 28 | endproperty 29 | 30 | property count_Fto0_prpty; 31 | @(posedge clk) disable iff(rst) 32 | (!load && updown) && (count == 4'hF) |=> (count == 4'b0); 33 | endproperty 34 | 35 | property count_0toF_prpty; 36 | @(posedge clk) disable iff(rst) 37 | (!load && !updown) && (count == 4'b0) |=> (count == 4'hF); 38 | endproperty 39 | 40 | property load_prpty; 41 | @(posedge clk) disable iff(rst) 42 | load |=> (count == $past(data, 1)); 43 | endproperty 44 | 45 | 46 | 47 | 48 | RST: assert property (reset_prpty); 49 | UP_COUNT: assert property (up_count_prpty); 50 | DOWN_COUNT: assert property (down_count_prpty); 51 | F2O: assert property (count_Fto0_prpty); 52 | O2F: assert property (count_0toF_prpty); 53 | LOAD: assert property (load_prpty); 54 | 55 | endmodule 56 | 57 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_env.sv: -------------------------------------------------------------------------------- 1 | class counter_env; 2 | 3 | virtual counter_if.WR_BFM wr_if; 4 | virtual counter_if.WR_MON wrmon_if; 5 | virtual counter_if.RD_MON rdmon_if; 6 | 7 | mailbox #(counter_trans) gen2wr = new; 8 | mailbox #(counter_trans) wrmon2rm = new; 9 | mailbox #(counter_trans) rm2sb = new; 10 | mailbox #(counter_trans) rdmon2sb = new; 11 | 12 | counter_gen gen_h; 13 | counter_wr_bfm wr_h; 14 | counter_wr_mon wrmon_h; 15 | counter_rd_mon rdmon_h; 16 | counter_rm rm_h; 17 | counter_sb sb_h; 18 | 19 | function new( virtual counter_if.WR_BFM wr_if, 20 | virtual counter_if.WR_MON wrmon_if, 21 | virtual counter_if.RD_MON rdmon_if); 22 | this.wr_if = wr_if; 23 | this.wrmon_if = wrmon_if; 24 | this.rdmon_if = rdmon_if; 25 | endfunction 26 | 27 | 28 | task build(); 29 | gen_h = new(gen2wr); 30 | wr_h = new(wr_if, gen2wr); 31 | wrmon_h = new(wrmon_if, wrmon2rm); 32 | rdmon_h = new(rdmon_if, rdmon2sb); 33 | rm_h = new(wrmon2rm, rm2sb); 34 | sb_h = new(rm2sb, rdmon2sb); 35 | endtask 36 | 37 | task reset(); 38 | @(wr_if.wr_cb); 39 | wr_if.wr_cb.rst <= 1; 40 | @(wr_if.wr_cb); 41 | @(wr_if.wr_cb); 42 | @(wr_if.wr_cb); 43 | @(wr_if.wr_cb); 44 | @(wr_if.wr_cb); 45 | wr_if.wr_cb.rst <= 0; 46 | 47 | endtask 48 | 49 | task start(); 50 | gen_h.start(); 51 | wr_h.start(); 52 | wrmon_h.start(); 53 | rdmon_h.start(); 54 | rm_h.start(); 55 | sb_h.start(); 56 | endtask 57 | 58 | task stop(); 59 | wait(sb_h.DONE.triggered); 60 | endtask 61 | 62 | task run(); 63 | reset(); 64 | start(); 65 | stop(); 66 | sb_h.report(); 67 | endtask 68 | 69 | endclass: counter_env 70 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_gen.sv: -------------------------------------------------------------------------------- 1 | class counter_gen; 2 | 3 | counter_trans trans_h; 4 | counter_trans trans2wr_h; 5 | 6 | mailbox #(counter_trans) gen2wr; 7 | 8 | function new(mailbox #(counter_trans) gen2wr); 9 | this.gen2wr = gen2wr; 10 | trans_h = new; 11 | endfunction 12 | 13 | virtual task start(); 14 | fork 15 | begin 16 | trans_h.trans_id++; 17 | trans_h.load = 1; 18 | trans_h.data = 0; 19 | trans2wr_h = new trans_h; 20 | gen2wr.put(trans2wr_h); 21 | 22 | for(int i = 0; i < (no_of_transaction - 1); i++) 23 | begin 24 | trans_h.trans_id++; 25 | assert(trans_h.randomize()); 26 | trans2wr_h = new trans_h; 27 | gen2wr.put(trans2wr_h); 28 | end 29 | end 30 | join_none 31 | endtask 32 | 33 | endclass: counter_gen 34 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_if.sv: -------------------------------------------------------------------------------- 1 | interface counter_if(input logic clk); 2 | 3 | logic rst, updown, load; 4 | logic [3:0] data; 5 | logic [3:0] data_out; 6 | 7 | clocking wr_cb@(posedge clk); 8 | output load, updown, rst; 9 | output data; 10 | endclocking 11 | 12 | clocking wrmon_cb@(posedge clk); 13 | input data; 14 | input load, rst, updown; 15 | endclocking 16 | 17 | clocking rdmon_cb@(posedge clk); 18 | input data_out; 19 | endclocking 20 | 21 | modport WR_BFM(clocking wr_cb); 22 | modport WR_MON(clocking wrmon_cb); 23 | modport RD_MON(clocking rdmon_cb); 24 | 25 | endinterface: counter_if 26 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_pkg.sv: -------------------------------------------------------------------------------- 1 | package counter_pkg; 2 | 3 | int no_of_transaction; 4 | 5 | `include "counter_trans.sv" 6 | `include "counter_gen.sv" 7 | `include "counter_wr_bfm.sv" 8 | `include "counter_wr_mon.sv" 9 | `include "counter_rd_mon.sv" 10 | `include "counter_rm.sv" 11 | `include "counter_sb.sv" 12 | `include "counter_env.sv" 13 | 14 | endpackage 15 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_rd_mon.sv: -------------------------------------------------------------------------------- 1 | class counter_rd_mon; 2 | 3 | virtual counter_if.RD_MON rdmon_if; 4 | 5 | mailbox #(counter_trans) rdmon2sb; 6 | 7 | counter_trans trans_h; 8 | counter_trans rd2sb_h; 9 | 10 | function new( virtual counter_if.RD_MON rdmon_if, 11 | mailbox #(counter_trans) rdmon2sb); 12 | this.rdmon_if = rdmon_if; 13 | this.rdmon2sb = rdmon2sb; 14 | trans_h = new; 15 | endfunction 16 | 17 | task monitor(); 18 | @(rdmon_if.rdmon_cb) 19 | trans_h.data_out = rdmon_if.rdmon_cb.data_out; 20 | if($isunknown(rdmon_if.rdmon_cb.data_out)) 21 | trans_h.data_out = 0; 22 | endtask 23 | 24 | task start(); 25 | fork 26 | forever 27 | begin 28 | monitor(); 29 | trans_h.display("DATA FROM READ MONITOR"); 30 | rd2sb_h = new trans_h; 31 | rdmon2sb.put(rd2sb_h); 32 | end 33 | join_none 34 | endtask 35 | 36 | endclass: counter_rd_mon 37 | 38 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_rm.sv: -------------------------------------------------------------------------------- 1 | class counter_rm; 2 | 3 | mailbox #(counter_trans) rm2sb, wrmon2rm; 4 | 5 | counter_trans wrmon2rm_h, temp_h; 6 | 7 | int count; 8 | 9 | function new(mailbox #(counter_trans) wrmon2rm, mailbox #(counter_trans) rm2sb); 10 | this.rm2sb = rm2sb; 11 | this.wrmon2rm = wrmon2rm; 12 | temp_h = new(); 13 | endfunction 14 | 15 | task model(); 16 | ++count; 17 | if(count > 1) 18 | begin 19 | temp_h.rst = wrmon2rm_h.rst; 20 | temp_h.load = wrmon2rm_h.load; 21 | temp_h.updown = wrmon2rm_h.updown; 22 | temp_h.data = wrmon2rm_h.data; 23 | if(wrmon2rm_h.rst) 24 | temp_h.data_out = 0; 25 | else if(wrmon2rm_h.load) 26 | temp_h.data_out = wrmon2rm_h.data; 27 | else if(wrmon2rm_h.updown) 28 | temp_h.data_out = ++temp_h.data_out; 29 | else if(!wrmon2rm_h.updown) 30 | temp_h.data_out = --temp_h.data_out; 31 | end 32 | endtask 33 | 34 | task start(); 35 | fork 36 | forever 37 | begin 38 | wrmon2rm.get(wrmon2rm_h); 39 | rm2sb.put(temp_h); 40 | temp_h = new temp_h; 41 | model(); 42 | end 43 | join_none 44 | endtask 45 | 46 | endclass :counter_rm 47 | 48 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_sb.sv: -------------------------------------------------------------------------------- 1 | class counter_sb; 2 | 3 | mailbox #(counter_trans) rm2sb, rdmon2sb; 4 | 5 | event DONE; 6 | 7 | int count_transaction, data_verified; 8 | 9 | counter_trans cov_h, rcvd_h; 10 | 11 | covergroup counter_cov; 12 | option.per_instance = 1; 13 | RST: coverpoint cov_h.rst {bins r[] = {0,1};} 14 | LD: coverpoint cov_h.load {bins l[] = {0,1};} 15 | UD: coverpoint cov_h.updown {bins ud[] = {0,1};} 16 | DATA: coverpoint cov_h.data {bins d[] = {[0:15]};} 17 | DOUT: coverpoint cov_h.data_out {bins dout[] = {[0:15]};} 18 | 19 | LDxDATA: cross LD, DATA; 20 | UDxDOUT: cross UD, DOUT; 21 | RSTxLDxDATA: cross RST, LD, DATA; 22 | RSTxLDxUD: cross RST, LD, UD; 23 | endgroup 24 | 25 | function new(mailbox #(counter_trans) rm2sb, mailbox #(counter_trans) rdmon2sb); 26 | this.rm2sb = rm2sb; 27 | this.rdmon2sb = rdmon2sb; 28 | counter_cov = new(); 29 | endfunction 30 | 31 | task start; 32 | fork 33 | forever 34 | begin 35 | rm2sb.get(rcvd_h); 36 | cov_h = rcvd_h; 37 | counter_cov.sample(); 38 | //--------------------// 39 | rdmon2sb.get(cov_h); 40 | check(rcvd_h); 41 | end 42 | join_none 43 | endtask 44 | 45 | task check(counter_trans rcvd_h); 46 | 47 | count_transaction++; 48 | 49 | if(cov_h.compare(rcvd_h)) 50 | begin 51 | counter_cov.sample(); 52 | data_verified++; 53 | end 54 | 55 | if(count_transaction >= no_of_transaction) 56 | ->DONE; 57 | endtask 58 | 59 | function void report; 60 | $display("--------------SCOREBOARD REPORT----------------"); 61 | $display("Number of transactions received : %0d", count_transaction); 62 | $display("Number of transactions verified : %0d", data_verified); 63 | $display("-----------------------------------------------"); 64 | endfunction 65 | 66 | 67 | 68 | 69 | endclass :counter_sb 70 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_trans.sv: -------------------------------------------------------------------------------- 1 | class counter_trans; 2 | 3 | rand bit [3:0] data; 4 | rand bit rst; 5 | rand bit load; 6 | rand bit updown; 7 | 8 | bit [3:0] data_out; 9 | 10 | static int trans_id; 11 | 12 | 13 | //Constraints to control frequency of reset and load 14 | constraint r1{rst dist {0:=50, 1:=1};} 15 | constraint l1{load dist {0:=20, 1:=1};} 16 | 17 | function void post_randomize(); 18 | this.display("RANDOMIZED DATA"); 19 | endfunction 20 | 21 | function void display(string message); 22 | $display("-------------------------------------------------"); 23 | $display("%s",message); 24 | $display("\tTransaction ID: %d", trans_id); 25 | $display("\tRESET = %d\n\tLOAD = %d\n\tUP-DOWN = %d\n\tDATA = %d", rst, load, updown, data); 26 | $display("-------------------------------------------------"); 27 | endfunction 28 | 29 | function bit compare(counter_trans rcvd); 30 | compare = 1'b1; 31 | if(this.data_out != rcvd.data_out) 32 | begin 33 | compare = 1'b0; 34 | $display("DATA MISMATCH"); 35 | $display(this.data_out, " != ", rcvd.data_out); 36 | $stop; 37 | end 38 | endfunction 39 | 40 | endclass: counter_trans 41 | 42 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_wr_bfm.sv: -------------------------------------------------------------------------------- 1 | class counter_wr_bfm; 2 | 3 | virtual counter_if.WR_BFM wr_if; 4 | 5 | mailbox #(counter_trans) gen2wr; 6 | 7 | counter_trans trans_h; 8 | 9 | function new( virtual counter_if.WR_BFM wr_if, 10 | mailbox #(counter_trans) gen2wr); 11 | this.wr_if = wr_if; 12 | this.gen2wr = gen2wr; 13 | this.trans_h = new; 14 | endfunction 15 | 16 | task drive(); 17 | @(wr_if.wr_cb); 18 | wr_if.wr_cb.rst <= trans_h.rst; 19 | wr_if.wr_cb.load <= trans_h.load; 20 | wr_if.wr_cb.updown <= trans_h.updown; 21 | wr_if.wr_cb.data <= trans_h.data; 22 | endtask 23 | 24 | task start(); 25 | fork 26 | forever 27 | begin 28 | gen2wr.get(trans_h); 29 | drive(); 30 | end 31 | join_none 32 | endtask 33 | 34 | endclass: counter_wr_bfm 35 | 36 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/counter_wr_mon.sv: -------------------------------------------------------------------------------- 1 | class counter_wr_mon; 2 | 3 | virtual counter_if.WR_MON wrmon_if; 4 | 5 | mailbox #(counter_trans) wrmon2rm; 6 | 7 | counter_trans trans_h, wrmon2rm_h; 8 | 9 | function new( virtual counter_if.WR_MON wrmon_if, 10 | mailbox #(counter_trans) wrmon2rm); 11 | this.wrmon_if = wrmon_if; 12 | this.wrmon2rm = wrmon2rm; 13 | this.trans_h = new; 14 | endfunction 15 | 16 | task monitor(); 17 | @(wrmon_if.wrmon_cb) 18 | begin 19 | trans_h.rst = wrmon_if.wrmon_cb.rst; 20 | trans_h.load = wrmon_if.wrmon_cb.load; 21 | trans_h.updown = wrmon_if.wrmon_cb.updown; 22 | trans_h.data = wrmon_if.wrmon_cb.data; 23 | trans_h.display("DATA FROM WRITE MONITOR"); 24 | end 25 | endtask 26 | 27 | task start(); 28 | fork 29 | forever 30 | begin 31 | monitor(); 32 | wrmon2rm_h = new trans_h; 33 | wrmon2rm.put(wrmon2rm_h); 34 | end 35 | join_none 36 | endtask 37 | 38 | endclass: counter_wr_mon 39 | 40 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/env/top.sv: -------------------------------------------------------------------------------- 1 | `include "test.sv" 2 | 3 | module top; 4 | 5 | reg clk; 6 | 7 | counter_if intf(clk); 8 | 9 | counter DUV( .clk(clk), 10 | .rst(intf.rst), 11 | .load(intf.load), 12 | .updown(intf.updown), 13 | .data(intf.data), 14 | .data_out(intf.data_out)); 15 | 16 | bind DUV counter_assertion C_A( .clk(clk), 17 | .rst(intf.rst), 18 | .load(intf.load), 19 | .updown(intf.updown), 20 | .data(intf.data), 21 | .count(intf.data_out)); 22 | 23 | test test_h; 24 | 25 | initial 26 | begin 27 | test_h = new(intf, intf, intf); 28 | test_h.build_and_run(); 29 | end 30 | 31 | initial 32 | begin 33 | clk = 0; 34 | forever #10 clk = ~clk; 35 | end 36 | 37 | endmodule: top 38 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/rtl/counter.v: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // 4-bit loadable up-down counter ////// 3 | ////////////////////////////////////////////////////////////// 4 | 5 | module counter(clk, rst, data, updown, load, data_out); 6 | 7 | input clk, rst, load; 8 | input updown; 9 | input [3:0] data; 10 | 11 | output reg [3:0] data_out; 12 | 13 | 14 | always@(posedge clk) 15 | begin 16 | if(rst) 17 | data_out <= 4'b0; 18 | else if(load) 19 | data_out <= data; 20 | else 21 | data_out <= ((updown)?(data_out + 1'b1):(data_out -1'b1)); 22 | end 23 | 24 | endmodule 25 | 26 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/rtl/counter_tb.v: -------------------------------------------------------------------------------- 1 | module tb; 2 | 3 | reg clk, rst, load; 4 | reg updown; 5 | reg [3:0] data; 6 | 7 | wire [3:0] data_out; 8 | 9 | counter c(clk, rst, data, updown, load, data_out); 10 | 11 | //Generate Clock 12 | initial 13 | begin 14 | clk = 0; 15 | forever #10 clk = ~clk; 16 | end 17 | 18 | //Reset 19 | task reset_t; 20 | begin 21 | rst = 0; 22 | @(negedge clk) 23 | rst = 1; 24 | @(negedge clk) 25 | rst = 0; 26 | end 27 | endtask 28 | 29 | //Load 30 | task load_t; 31 | input [3:0] data_in; 32 | begin 33 | @(negedge clk) 34 | load = 1; 35 | data = data_in; 36 | @(negedge clk) 37 | load = 0; 38 | end 39 | endtask 40 | 41 | initial 42 | begin 43 | reset_t; 44 | updown = 1; 45 | #200; 46 | load_t(7); 47 | #200; 48 | load_t(15); 49 | #200; 50 | updown = 0; 51 | load_t(0); 52 | #200; 53 | #200 $stop; 54 | end 55 | 56 | endmodule 57 | 58 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/sim/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Memory - Regression Testing 2 | RTL= ../rtl/counter.v 3 | work= work #library name 4 | COVOP= -coveropt 3 +cover +acc 5 | SVTB1= ../env/counter_if.sv ../env/counter_assertion.sv ../env/top.sv 6 | INC = +incdir+../env +incdir+../test 7 | SVTB2 = ../env/counter_pkg.sv 8 | TEST = ../test/test.sv 9 | #TEST1 = ../test/test1.sv 10 | #TEST2 = ../test/test2.sv 11 | VSIMOPT= -coverage -novopt -sva -sv_seed 2475652473 work.top 12 | VSIMCOV= coverage save -onexit -assert -directive -cvg -codeAll counter_cov 13 | VSIMBATCH= -c -do "$(VSIMCOV); run -all; exit" 14 | VSIMBATCH1 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov1;run -all;exit" 15 | VSIMBATCH2 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov2;run -all;exit" 16 | VSIMBATCH3 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov3;run -all;exit" 17 | VSIMBATCH4 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov4;run -all;exit" 18 | VSIMBATCH5 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov5;run -all;exit" 19 | VSIMBATCH6 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov6;run -all;exit" 20 | VSIMBATCH7 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov7;run -all;exit" 21 | VSIMBATCH8 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov8;run -all;exit" 22 | VSIMBATCH9 = -c -do "coverage save -onexit -assert -directive -cvg -codeAll counter_cov9;run -all;exit" 23 | 24 | 25 | html: 26 | firefox covhtmlreport/pages/__frametop.htm 27 | 28 | sv_cmp: 29 | vlib $(work) 30 | vmap work $(work) 31 | vlog -work $(work) $(COVOP) $(RTL) $(SVTB2) $(SVTB1) $(INC) #$(TEST) 32 | 33 | run_sim: 34 | vsim $(VSIMBATCH1) $(VSIMOPT) -l test1_sim.log +TEST1 +nowarn3829 35 | vcover report -html counter_cov1 36 | 37 | run_testg: 38 | vsim -novopt -sva -sv_seed random work.top +TEST1 39 | clear 40 | 41 | clean: 42 | rm -rf modelsim.* transcript* vlog.* work vsim.wlf counter_cov* fcover* covhtml* vcover* *.log 43 | clear 44 | 45 | TC2: 46 | vsim $(VSIMBATCH2) -coverage -novopt -sva -sv_seed 598761566 -l test2_sim.log work.top +TEST2 47 | vcover report -html counter_cov2 48 | TC3: 49 | vsim $(VSIMBATCH3) -coverage -novopt -sva -sv_seed 74473697 -l test3_sim.log work.top +TEST3 50 | vcover report -html counter_cov3 51 | TC4: 52 | vsim $(VSIMBATCH4) -coverage -novopt -sva -sv_seed 4275076933 -l test4_sim.log work.top +TEST4 53 | vcover report -html counter_cov4 54 | 55 | TC5: 56 | vsim $(VSIMBATCH5) -coverage -novopt -sva -sv_seed 3868229417 -l test5_sim.log work.top +TEST5 57 | vcover report -html counter_cov5 58 | 59 | TC6: 60 | vsim $(VSIMBATCH6) -coverage -novopt -sva -sv_seed 749764269 -l test6_sim.log work.top +TEST6 61 | vcover report -html counter_cov6 62 | 63 | TC7: 64 | vsim $(VSIMBATCH7) -coverage -novopt -sva -sv_seed 1982889551 -l test7_sim.log work.top +TEST7 65 | vcover report -html counter_cov7 66 | 67 | TC8: 68 | vsim $(VSIMBATCH8) -coverage -novopt -sva -sv_seed 1987083824 -l test8_sim.log work.top +TEST8 69 | vcover report -html counter_cov8 70 | 71 | TC9: 72 | vsim $(VSIMBATCH9) -coverage -novopt -sva -sv_seed 1987083824 -l test8_sim.log work.top +TEST9 73 | vcover report -html counter_cov9 74 | report: 75 | vcover merge counter_cov counter_cov1 counter_cov2 #counter_cov3 counter_cov4 counter_cov5 counter_cov6 counter_cov7 76 | vcover report -html counter_cov 77 | 78 | regress: clean run_test TC2 report html #TC3 TC4 TC5 TC6 TC7 report html 79 | 80 | gui: 81 | vsim $(VSIMOPT) -l test1_sim.log +TEST1 +nowarn3829 82 | 83 | run_gui: sv_cmp gui 84 | 85 | run_test: clean sv_cmp run_sim 86 | 87 | 88 | -------------------------------------------------------------------------------- /projects/counter_sv_tb/test/test.sv: -------------------------------------------------------------------------------- 1 | import counter_pkg::*; 2 | 3 | 4 | class counter_trans_load extends counter_trans; 5 | 6 | randc logic [3:0] data; 7 | 8 | constraint r1 {rst inside {0, 1};} 9 | constraint l1 {load inside {0, 1};} 10 | constraint d1{super.data == data;} 11 | 12 | endclass 13 | 14 | 15 | class test; 16 | 17 | virtual counter_if.WR_BFM wr_if; 18 | virtual counter_if.WR_MON wrmon_if; 19 | virtual counter_if.RD_MON rdmon_if; 20 | 21 | counter_env env; 22 | 23 | counter_trans_load trans_ld_h; 24 | 25 | function new( virtual counter_if.WR_BFM wr_if, 26 | virtual counter_if.WR_MON wrmon_if, 27 | virtual counter_if.RD_MON rdmon_if); 28 | 29 | this.wr_if = wr_if; 30 | this.wrmon_if = wrmon_if; 31 | this.rdmon_if = rdmon_if; 32 | 33 | env = new(wr_if, wrmon_if, rdmon_if); 34 | endfunction 35 | 36 | 37 | 38 | task build_and_run; 39 | if($test$plusargs("TEST1")) 40 | begin 41 | no_of_transaction = 250; 42 | env.build(); 43 | env.run(); 44 | $finish; 45 | end 46 | if($test$plusargs("TEST2")) 47 | begin 48 | trans_ld_h = new(); 49 | no_of_transaction = 250; 50 | env.build(); 51 | env.gen_h.trans_h = trans_ld_h; 52 | env.run(); 53 | $finish; 54 | end 55 | endtask 56 | 57 | endclass :test 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /projects/sha3_sv_tb/.gitignore: -------------------------------------------------------------------------------- 1 | /rtl 2 | /sim -------------------------------------------------------------------------------- /projects/sha3_sv_tb/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /projects/sha3_sv_tb/README: -------------------------------------------------------------------------------- 1 | SystemVerilog Based Verification Environment for SHA-3 Cryptographic Core. 2 | (In Development Phase.) -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_environment.sv: -------------------------------------------------------------------------------- 1 | class sha3_environment; 2 | 3 | virtual sha3_if.WR_BFM wr_if; 4 | virtual sha3_if.WR_MON wrmon_if; 5 | virtual sha3_if.RD_MON rdmon_if; 6 | 7 | sha3_generator gen; 8 | sha3_write_bfm wr_bfm; 9 | sha3_write_monitor wr_mon; 10 | sha3_read_monitor rd_mon; 11 | sha3_model model; 12 | sha3_scoreboard sb; 13 | 14 | mailbox #(sha3_transaction) gen2wr = new(); 15 | mailbox #(sha3_transaction) wrmon2rm = new(); 16 | mailbox #(sha3_transaction) rm2sb = new(); 17 | mailbox #(sha3_transaction) rdmon2sb = new(); 18 | 19 | function new( virtual sha3_if.WR_BFM wr_if, 20 | virtual sha3_if.WR_MON wrmon_if, 21 | virtual sha3_if.RD_MON rdmon_if); 22 | this.wr_if = wr_if; 23 | this.wrmon_if = wrmon_if; 24 | this.rdmon_if = rdmon_if; 25 | endfunction 26 | 27 | virtual task build(); 28 | gen = new(); 29 | wr_bfm = new(); 30 | wr_mon = new(); 31 | rd_mon = new(); 32 | model = new(); 33 | sb = new(); 34 | endtask 35 | 36 | virtual task start(); 37 | gen.start(); 38 | wr_bfm.start(); 39 | wr_mon.start(); 40 | rd_mon.start(); 41 | model.start(); 42 | sb.start(); 43 | endtask 44 | 45 | virtual task stop(); 46 | wait(sb.DONE.triggered); 47 | endtask: stop 48 | 49 | virtual task run(); 50 | start(); 51 | stop(); 52 | sb.report(); 53 | endtask 54 | 55 | endclass: sha3_environment -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_generator.sv: -------------------------------------------------------------------------------- 1 | class sha3_generator; 2 | 3 | mailbox #(sha3_transaction) gen2wrbfm; 4 | 5 | sha3_transaction trans_h; 6 | sha3_transaction send_h; 7 | 8 | function new(mailbox #(sha3_transaction) gen2wrbfm); 9 | this.gen2wrbfm = gen2wrbfm; 10 | trans_h = new(); 11 | endfunction 12 | 13 | virtual task start(); 14 | fork 15 | for(int i; i < no_of_transaction; i++) 16 | begin 17 | trans_h.trans_id++; 18 | assert(trans_h.randomize()); 19 | send_h = new trans_h; 20 | gen2wrbfm.put(send_h); 21 | end 22 | join_none 23 | endtask 24 | 25 | endclass: sha3_generator -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_if.sv: -------------------------------------------------------------------------------- 1 | interface sha3_if(input logic clock); 2 | 3 | logic reset; 4 | logic [31:0] in; 5 | logic [1:0] byte_num; 6 | logic in_ready; 7 | logic is_last; 8 | 9 | logic buffer_full; 10 | logic [511:0] out; 11 | logic out_ready; 12 | 13 | clocking wr_cb(@posedge clock); 14 | output reset; 15 | output in; 16 | output byte_num; 17 | output in_ready; 18 | output is_last; 19 | endclocking 20 | 21 | clocking wrmon_cb(@posedge clock); 22 | input reset; 23 | input in; 24 | input byte_num; 25 | input in_ready; 26 | input is_last; 27 | endclocking 28 | 29 | clocking rdmon_cb(@posedge clock); 30 | input buffer_full; 31 | input out_ready; 32 | input out; 33 | endclocking 34 | 35 | modport WR_BFM(clocking wr_cb); 36 | 37 | modport WR_MON(clocking wrmon_cb); 38 | 39 | modport RD_MON(clocking rdmon_cb); 40 | 41 | endinterface: sha3_if -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_pkg.sv: -------------------------------------------------------------------------------- 1 | package sha3_pkg; 2 | 3 | int number_of_transaction; 4 | 5 | `include "sha3_transaction.sv" 6 | `include "sha3_generator.sv" 7 | `include "sha3_write_bfm.sv" 8 | `include "sha3_write_monitor.sv" 9 | `include "sha3_read_monitor.sv" 10 | `include "sha3_model.sv" 11 | `include "sha3_scoreboard.sv" 12 | `include "sha3_environment.sv" 13 | 14 | endpackage: sha3_pkg -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_read_monitor.sv: -------------------------------------------------------------------------------- 1 | class sha3_read_monitor; 2 | 3 | virtual sha3_if.RD_MON rdmon_if; 4 | 5 | mailbox #(sha3_transaction) rdmon2sb; 6 | 7 | sha3_transaction trans_h; 8 | sha3_transaction send_h; 9 | 10 | function new( virtual sha3_if.RD_MON rdmon_if, 11 | mailbox #(sha3_transaction) rdmon2sb); 12 | this.rdmon_if = rdmon_if; 13 | this.rdmon2sb = rdmon2sb; 14 | trans_h = new(); 15 | endfunction 16 | 17 | virtual task monitor(); 18 | @(rdmon_if.rdmon_cb); 19 | trans_h.buffer_full = rdmon_if.buffer_full; 20 | trans_h.out_ready = rdmon_if.out_ready; 21 | trans_h.out = rdmon_if.out; 22 | endtask 23 | 24 | virtual task start(); 25 | fork 26 | forever 27 | begin 28 | monitor(); 29 | if(out_ready) 30 | begin 31 | send_h = new trans_h; 32 | rdmon2sb.put(send_h); 33 | end 34 | end 35 | join_none 36 | endtask 37 | 38 | endclass: sha3_read_monitor -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_transaction.sv: -------------------------------------------------------------------------------- 1 | class sha3_transaction; 2 | 3 | rand logic reset; 4 | rand logic [31:0] in; 5 | rand logic [1:0] byte_num; 6 | rand logic in_ready; 7 | rand logic is_last; 8 | 9 | logic buffer_full; 10 | logic [511:0] out; 11 | logic out_ready; 12 | 13 | static int trans_id; 14 | static int no_of_message; 15 | 16 | constraint r1{reset dist {1:=1, 0:=100};} 17 | constraint b_n{if(is_last) -> byte_num == (in.size()%4);} 18 | constraint i_r{in_ready dist {0:=50, 1:=1};} 19 | 20 | function void post_randomize(); 21 | if(is_last) 22 | no_of_message++; 23 | this.display("\tRANDOMIZED DATA"); 24 | endfunction 25 | 26 | function void display(string message); 27 | $display("--------------------------------------"); 28 | $display("\tTransaction No. %0d", trans_id); 29 | $display("\treset = %b\n\tin = %0h\n\tbyte_num = %0d\n\tin_ready = %b\n\tis_last = %b",reset , in, byte_num, in_ready, is_last); 30 | $display("\t----------------"); 31 | $display("\tbuffer_full = %b\n\tout = %0h\n\tout_ready = %b", buffer_full, out, out_ready); 32 | $display("--------------------------------------"); 33 | endfunction 34 | 35 | endclass: sha3_transaction -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_write_bfm.sv: -------------------------------------------------------------------------------- 1 | class sha3_write_bfm; 2 | 3 | virtual sha3_if.WR_BFM wr_if; 4 | 5 | mailbox #(sha3_transaction) gen2wrbfm; 6 | 7 | sha3_transaction trans_h; 8 | 9 | function new( virtual sha3_if.WR_BFM wr_if, 10 | mailbox #(sha3_transaction) gen2wrbfm); 11 | this.wr_if = wr_if; 12 | this.gen2wrbfm = gen2wrbfm; 13 | trans_h = new(); 14 | endfunction 15 | 16 | virtual task drive(); 17 | @(wr_if.wrbfm_cb); 18 | wr_if.reset <= trans_h.reset; 19 | wr_if.in <= trans_h.in; 20 | wr_if.byte_num <= trans_h.byte_num; 21 | wr_if.in_ready <= trans_h.in_ready; 22 | wr_if.is_last <= is_last; 23 | endtask 24 | 25 | virtual task start(); 26 | fork 27 | forever 28 | begin 29 | gen2wrbfm.get(trans_h); 30 | drive(); 31 | end 32 | join_none 33 | endtask 34 | 35 | endclass: sha3_write_bfm -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/sha3_write_monitor.sv: -------------------------------------------------------------------------------- 1 | class sha3_write_monitor; 2 | 3 | virtual sha3_if.WR_MON wrmon_if; 4 | 5 | mailbox #(sha3_transaction) gen2rm; 6 | 7 | sha3_transaction trans_h; 8 | sha3_transaction send_h; 9 | 10 | function new( virtual sha3_if.WR_MON wrmon_if, 11 | mailbox #(sha3_transaction) gen2rm); 12 | this.wrmon_if = wrmon_if; 13 | this.gen2rm = gen2rm; 14 | endfunction 15 | 16 | virtual task monitor(); 17 | @(wrmon_if.wrmon_cb); 18 | trans_h.reset = wrmon_if.reset; 19 | trans_h.in = wrmon_if.in; 20 | trans_h.byte_num = wrmon_if.byte_num; 21 | trans_h.in_ready = wrmon_if.in_ready; 22 | trans_h.is_last = wrmon_if.is_last; 23 | endtask 24 | 25 | virtual task start(); 26 | fork 27 | forever 28 | begin 29 | monitor(); 30 | send_h = new trans_h; 31 | gen2rm.put(send_h); 32 | end 33 | join_none 34 | 35 | endclass: sha3_write_monitor -------------------------------------------------------------------------------- /projects/sha3_sv_tb/env/top.sv: -------------------------------------------------------------------------------- 1 | `include "test.sv" 2 | module top; 3 | 4 | reg clock; 5 | 6 | sha3_if intf(clock); 7 | 8 | test test_h; 9 | 10 | keccak (.clock(clock), 11 | .reset(intf.reset), 12 | .in(intf.in), 13 | .in_ready(intf.in_ready), 14 | .byte_num(intf.byte_num), 15 | .is_last(intf.is_last), 16 | .buffer_full(intf.buffer_full), 17 | .out_ready(intf.out_ready), 18 | .out(intf.out) 19 | ); 20 | 21 | initial 22 | begin 23 | test_h = new(intf, intf, intf); 24 | test_h.build_and_run(); 25 | end 26 | 27 | initial 28 | begin 29 | clock = 0; 30 | forever #10 clock = ~clock; 31 | end 32 | 33 | endmodule --------------------------------------------------------------------------------