-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb.sv
90 lines (72 loc) · 2.08 KB
/
tb.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
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
`timescale 1ns/1ps
program get_mapping(output logic [7:0] source_mapping [`NSOURCES-1:0]);
class mapping;
randc bit [7:0] mapping [`NSOURCES-1:0];
endclass
task gen();
endtask
endprogram
module tb();
reg pclk, rstn;
reg [`NSINKS-1:0] sink_valids;
reg [`DATA_WIDTH-1:0] sink_data [`NSINKS-1:0];
reg [`DATA_WIDTH-1:0] source_data;
reg [`NSOURCES-1:0] source_valids;
reg [7:0] source_mapping [`NSOURCES-1:0]; // mapping from regbank
logic [$clog2(`NSINKS)-1:0] i;
logic [5:0] delay;
logic [5:0] rnd_address;
//////////////////////////////////////////
//
// Instantiate the interconnect
//
//////////////////////////////////////////
apb_interconnect apb_bus (
.rstn( rstn ), .pclk( pclk ),
.sink_data( sink_data ), .sink_valids( sink_valids ),
.source_data( source_data ), .source_valids( source_valids ), .source_mapping( source_mapping )
);
// Instantiate your driver
driver sink_driver()
//////////////////////////////////////////
//
// MAIN
//
//////////////////////////////////////////
initial begin
pclk = 0;
rstn = 0;
sink_valids = 0;
source_mapping = ;
#5000
rstn = 1;
for (i = 0; i < `NSOURCES; i = i + 1) begin
source_mapping[i] = $random;
end
end
always begin
pclk <= ~pclk;
#500; // 1 MHz
end
// Generate Address, data and valids
always @(posedge pclk)
begin
#(5000*24)
for (i = 0; i < `NSINKS; i = i + 1) begin
sink_data[i] = $random;
sink_addrs[i] = i;
end
#1;
// Assign random values 32bits at a time
for (i = 0; i < `NSINKS / 32; i = i + 1) begin
sink_valids[i*32 +: 32] = $random;
end
// assign remaining bits
for (i = 0; i < `NSINKS % 32; i = i + 1) begin
sink_valids[(`NSINKS / 32)*32 + i +: 1] = $random;
end
// de-assert valids after 1 clock cycle
#1001;
sink_valids = 0;
end
endmodule