-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileIO.v
More file actions
75 lines (64 loc) · 1.58 KB
/
fileIO.v
File metadata and controls
75 lines (64 loc) · 1.58 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module fileio;
integer in,out, mon;
reg clk;
reg enable;
wire valid;
reg [31:0] din;
reg [31:0] exp;
wire [31:0] dout;
integer statusI, statusO;
dut dut (clk, enable, din, dout, valid); // instantiated the dut
initial begin
clk = 0;
enable = 0;
din = 0;
exp = 0;
in = $fopen("input.txt", "r"); // 'in' is a descriptor for file 'input.txt'
out = $fopen("output.txt", "r"); // 'out' is a descriptor for file 'output.txt'
mon = $fopen("monitor.txt", "w"); // 'mon' is a descriptor for file 'monitor.txt'
end
always #1 clk = ~clk;
// DUT input driver code
initial begin
repeat(10) @ (posedge clk);
while (!$feof(in)) begin
@(negedge clk); // what does this mean? This means wait for one clock
enable = 1;
statusI = $fscanf(in, "%h %h\n", din[31:16], din[15:0]);
@(negedge clk);
enable = 0;
end
repeat(10) @ (posedge clk);
$fclose(in);
$fclose(out);
$fclose(mon);
#100 $finish;
end
// DUT output monitor and compare logic
always @ (posedge clk)
if (valid) begin
$fwrite(mon,"%h %h\n", dout[31:16], dout[15:0]);
statusO = $fscanf(out, "%h %h\n", exp[31:16], exp[15:0]);
if (dout !== exp) begin
$display("%0dns Error: input and output does not match", $time);
$display(" Got %h", dout);
$display(" Exp %h", exp);
end else begin
$display("%0dns Match : input and output match", $time);
$display(" Got %h", dout);
$display(" Exp %h", exp);
end
end
endmodule
// DUT model
module dut(
input wire clk, enable,
input wire [31:0] din,
output reg [31:0] dout,
output reg valid
);
always @ (posedge clk) begin
dout <= din + 1;
valid <= enable;
end
endmodule