forked from TaoL24/Verification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandc.sv
More file actions
65 lines (50 loc) · 1.07 KB
/
randc.sv
File metadata and controls
65 lines (50 loc) · 1.07 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
class randc_imp #(int N = 8);
parameter iter = 2**N;
logic [N-1:0] pool [$];
// int index;
function new();
this.reset();
endfunction
function void reset();
pool.delete();
// index = 0;
for(int i=0; i<iter; i++) begin
pool.push_back(i);
end
pool.shuffle();
// while(pool.size()>0) begin
// index = $urandom(0, iter);
// if (pool.exist(index)) begin
// pool.delete(index);
// end
// end
endfunction
function logic [N-1:0] get_next_value();
if (pool.size()>0) begin
return pool.pop_front();
end else begin
$fatal("No more unique values. Please call reset().");
end
endfunction
endclass
randc_imp #(4) ins = new();
repeat(16) begin
$display("Randc Value: %d",ins.get_next_value);
end
// async reset, sync release
module reset_gen(
input clk,
input a_rstn,
output logic rstn_1 // this is relavant to clk, so it is SYNC!!!!
);
logic rstn_0;
always @(posedge clk, negedge a_rstn) begin
if (!a_rstn) begin
rstn_0 <= 0;
rstn_1 <= 0;
end else begin
rstn_0 <= 1'b1; // !!!
rstn_1 <= rstn_0;
end
end
endmodule