Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `include "fifo.sv"
- `include "memory2port.sv"
- `include "iface.sv"
- module TestTop();
- class Transaction;
- rand bit [3:0] data;
- bit [3:0] data_rd;
- rand bit write_enable;
- rand bit read_enable;
- rand bit reset;
- bit full;
- bit empty;
- constraint write_90 { write_enable dist {1 := 70,
- 0 := 20};}
- constraint reset_10 {
- ~reset -> write_enable == 0 ;
- ~reset -> read_enable == 0 ; }
- endclass // Transaction
- class Generator;
- rand Transaction tr;
- mailbox #(Transaction) mb;
- function new(mailbox #(Transaction) mb);
- this.mb = mb;
- endfunction // new
- task run();
- $display("Generator starting...");
- repeat(150) begin
- tr = new();
- $display("Generator running...");
- $display("Puting into mailbox generated data");
- if(!tr.randomize() ) $fatal("Gen:: tr randomization failed");
- mb.put(tr);
- end
- endtask
- endclass // Generator
- class Monitor;
- virtual iface viface;
- byte readed_data;
- Transaction tr_monitor;
- mailbox #(Transaction) monitor_mb;
- function new(virtual iface viface, mailbox #(Transaction) monitor_mb);
- this.viface = viface;
- this.monitor_mb = monitor_mb;
- endfunction // new
- task run();
- $display("Monitor starting..");
- tr_monitor = new();
- forever begin
- @(negedge viface.clk)begin //read
- $display("Monitor runing...");
- tr_monitor.data_rd <= viface.rd_data;
- tr_monitor.write_enable <= viface.write_enable;
- tr_monitor.read_enable <= viface.read_enable;
- tr_monitor.reset <= viface.reset;
- tr_monitor.empty <= viface.empty;
- tr_monitor.full <= viface.full;
- tr_monitor.data <= viface.data;
- $display("INTERFACEDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", viface.rd_data, viface.write_enable, viface.read_enable, viface.reset, viface.empty, viface.full, viface.data);
- $display("TRDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", tr_monitor.data_rd, tr_monitor.write_enable, tr_monitor.read_enable, tr_monitor.reset, tr_monitor.empty, tr_monitor.full, tr_monitor.data);
- monitor_mb.put(tr_monitor);
- end
- end
- endtask //
- endclass // Monitor
- class Scoreboard;
- byte queue[$:16];
- byte queue_data;
- byte queue_data2;
- bit read_enable_2;
- bit empty_2;
- mailbox #(Transaction) monitor_mb;
- Transaction tr_scoreboard;
- function new(mailbox #(Transaction) monitor_mb);
- this.monitor_mb = monitor_mb;
- endfunction // new
- task run();
- $display("Scoreboard starting..");
- forever begin
- monitor_mb.get(tr_scoreboard);
- read_enable_2 <= tr_scoreboard.read_enable;
- empty_2 <= tr_scoreboard.empty;
- $display("Data tranfered to scoreboard!");
- $display("SCOREDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", tr_scoreboard.data_rd, tr_scoreboard.write_enable, tr_scoreboard.read_enable, tr_scoreboard.reset, tr_scoreboard.empty, tr_scoreboard.full, tr_scoreboard.data);
- if (~tr_scoreboard.reset)begin
- queue = {};
- qsize = queue.size();
- $display("Reseting...");
- end
- else begin
- $display("Runing scoreboard");
- if(read_enable_2 & qsize != 0 & ~empty_2)begin
- $display("Reading from queue..");
- queue_data = queue.pop_front();
- qsize = queue.size();
- assert (queue_data == tr_scoreboard.data_rd) //sravnqvame edin cykal po kasno zaradi zakasnenieto ot pametta
- $display("TRUE");
- end
- if(tr_scoreboard.write_enable & qsize < 16 & ~tr_scoreboard.full)begin //write
- $display("Writing to queue...");
- queue.push_back(tr_scoreboard.data);
- qsize <= queue.size();
- end
- end
- end
- // end
- endtask // run
- endclass // Scoreboard
- class Driver;
- Transaction tr;
- mailbox #(Transaction) mb;
- virtual iface viface;
- function new(mailbox #(Transaction) mb, virtual iface viface);
- this.mb = mb;
- this.viface = viface;
- endfunction // new
- task run();
- $display("Driver starting..");
- forever begin
- @(posedge viface.clk)begin
- $display("Driver runing..");
- $display("Getting generated data from mailbox");
- mb.get(tr);
- viface.reset <= tr.reset;
- viface.data <= tr.data;
- viface.write_enable <= tr.write_enable;
- viface.read_enable <= tr.read_enable;
- end
- end
- endtask // run
- endclass // Driver
- class Agent;
- Scoreboard sb;
- Monitor mntr;
- Generator gen;
- Driver drv;
- mailbox #(Transaction) mb;
- mailbox #(Transaction) monitor_mb;
- virtual iface viface;
- function new(virtual iface viface);
- this.viface = viface;
- endfunction // new
- task build();
- $display("Build...");
- monitor_mb = new();
- sb = new(monitor_mb);
- mb = new();
- gen = new(mb);
- mntr = new(viface,monitor_mb);
- drv = new(mb,viface);
- endtask // build
- task run();
- $display("Test running..");
- fork
- gen.run();
- drv.run();
- sb.run();
- mntr.run();
- join_any
- endtask // testrun
- endclass // Agent
- bit clk;
- byte qsize;
- iface viface(.clk(clk));
- Agent agnt;
- initial begin
- clk = 0;
- end
- initial begin
- agnt = new(viface);
- agnt.build();
- agnt.run();
- end
- initial begin
- #10000 $finish;
- end
- always begin
- #10 clk = ~clk;
- end
- fifo dut(.reset(iface.reset), //vrazka s interface
- .data_in(iface.data),
- .WE(iface.write_enable),
- .RE(iface.read_enable),
- .write_clk(clk),
- .read_clk(clk),
- .data_out(iface.rd_data),
- .full(iface.full),
- .empty(iface.empty)
- );
- endmodule // TestTop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement