-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsha256_1kb_processor_tb.v
More file actions
104 lines (88 loc) · 2.95 KB
/
sha256_1kb_processor_tb.v
File metadata and controls
104 lines (88 loc) · 2.95 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
`timescale 1ns/1ps
/* verilator lint_off STMTDLY */
module sha256_1kb_processor_tb;
// Clock and reset
reg clk;
reg rst;
// Processor interface
reg start;
reg [8191:0] data_in; // 1KB input data
wire [255:0] hash_out;
wire done;
// Simulation control
reg [31:0] cycle_count;
reg test_started;
reg test_completed;
// Instantiate the processor
sha256_1kb_processor uut (
.clk(clk),
.rst(rst),
.start(start),
.data_in(data_in),
.hash_out(hash_out),
.done(done)
);
// Clock generation
initial begin
clk = 0;
forever #5 clk = ~clk; // 100MHz clock
end
// Test data generation and control
integer i;
initial begin
// Initialize
rst = 1;
start = 0;
data_in = 0;
cycle_count = 0;
test_started = 0;
test_completed = 0;
// Generate test data - pattern of incrementing bytes
for (i = 0; i < 1024; i = i + 1) begin
data_in[8191 - i*8 -: 8] = i[7:0]; // Fill with pattern 0x00, 0x01, 0x02, ...
end
$display("=== SHA256 1KB Processor Test ===");
$display("Input data: 1024 bytes of incrementing pattern (0x00, 0x01, 0x02, ...)");
end
// Main test control
always @(posedge clk) begin
cycle_count <= cycle_count + 1;
// Reset sequence
if (cycle_count < 10) begin
rst <= 1;
end else if (cycle_count == 10) begin
rst <= 0;
$display("Starting SHA256 computation...");
end else if (cycle_count == 15 && !test_started) begin
// Start processing
start <= 1;
test_started <= 1;
end else if (cycle_count == 16) begin
start <= 0;
end
// Check for completion
if (done && !test_completed) begin
test_completed <= 1;
$display("=== SHA256 Computation Complete ===");
$display("Final SHA256 Hash: %064h", hash_out);
$display("Hash in hex format:");
$display("%08h%08h%08h%08h%08h%08h%08h%08h",
hash_out[255:224], hash_out[223:192], hash_out[191:160], hash_out[159:128],
hash_out[127:96], hash_out[95:64], hash_out[63:32], hash_out[31:0]);
$display("Test completed successfully!");
end
// Finish after completion or timeout
if ((done && test_completed && cycle_count > 100) || cycle_count > 100000) begin
if (cycle_count > 100000) begin
$display("ERROR: Test timed out!");
end
$finish;
end
end
// Monitor progress
always @(posedge clk) begin
if (uut.state == uut.PROCESSING && uut.core_ready && !uut.core_start) begin
$display("Processing block %d/17...", uut.block_count + 1);
end
end
endmodule