-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregfilewrite_queue.sv
48 lines (40 loc) · 1.6 KB
/
regfilewrite_queue.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
`timescale 1ps/1ps
// This unit builds a regfilewrite_queue out of 4 regfilewrite_queue_sub.
// Recieves a clock and reset to coordinate operation within unit.
// Additionally takes a 1 bit input (RegWrt), 2 bit input (RegWData), and 5 bit input (Rd)
// that will be loaded into the register.
// Output of the register is projected onto RegWrtO, RegWDataO, and RdO.
// Takes 4 clock cycles.
module regfilewrite_queue (clk, reset, RegWrt, Rd, RegWrtO, RdO);
input logic clk, reset, RegWrt;
input logic [4:0] Rd;
output logic RegWrtO;
output logic [4:0] RdO;
logic RW1, RW2;
logic [4:0] Rd1, Rd2;
regfilewrite_queue_sub r1 (.clk, .reset, .RegWrt, .Rd, .RegWrtO(RW1), .RdO(Rd1));
regfilewrite_queue_sub r2 (.clk, .reset, .RegWrt(RW1), .Rd(Rd1), .RegWrtO(RW2), .RdO(Rd2));
regfilewrite_queue_sub r4 (.clk, .reset, .RegWrt(RW2), .Rd(Rd2), .RegWrtO, .RdO);
endmodule
module regfilewrite_queue_testbench();
logic clk, reset, RegWrt;
logic [4:0] Rd;
logic RegWrtO;
logic [4:0] RdO;
// Simulated clock for the testing
parameter clock_period = 100;
initial begin
clk <= 0;
forever #(clock_period / 2) clk <= ~clk;
end
regfilewrite_queue dut (.*);
initial begin
reset <= 0; RegWrt <= 1'd0; Rd <= 5'd0; @(posedge clk);
reset <= 1; @(posedge clk);
reset <= 0; @(posedge clk);
RegWrt <= 1'd1; Rd <= 5'd0; repeat(6)@(posedge clk); // RegWrtO gets a 1
RegWrt <= 1'd1; Rd <= 5'd0; repeat(6)@(posedge clk); // RegWDataO gets a 3
RegWrt <= 1'd1; Rd <= 5'd12; repeat(6)@(posedge clk); // RdO gets a 12
$stop;
end
endmodule