-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPB_MASTER_TB.v
412 lines (357 loc) · 12.8 KB
/
APB_MASTER_TB.v
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//////////////////////////////////////////////////////////////////////////////////
// Create Date: 02/09/2022 05:17:28 PM
// Design Name: APB_Master_Bridge_testbench
// Module Name: APB_Master_Bridge_TB
// Project Name: AMBA BUS Assignment
//
// Description: Test cases of the APB Master including read and write transfers
// with wait states and without wait states, each case is teseted
// when transfer still high after transfer happens and when transfer
// becomes low after a certain transfer
//
// Team Members: 1- Mohamed Hosam Elden Abd Alhakim Abd Alhady
// 2- Fatma Ali Gamal Eldin Mohammed
// 3- Fatma Hazem Abdel Salam Mohamed
// 4- Tasneem Abo El-Esaad Abd El-Razik Abo El-Esaad
// 5- Hadeer Muhammed Ali Abdo Saleh
// 6- Yousef Sherif Abdel Fadil
//////////////////////////////////////////////////////////////////////////////////
`timescale 1ns/100ps
module APB_MASTER_TB ();
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////Parameters and input/output signals///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
parameter DATA_WIDTH_TB = 'd32, ADDRESS_WIDTH_TB = 'd32, STRB_WIDTH_TB = 'd4, SLAVES_NUM_TB = 'd8;
reg PCLK_TB ;
reg PRESETn_TB ;
reg [ADDRESS_WIDTH_TB-1:0] IN_ADDR_TB ;
reg [DATA_WIDTH_TB-1:0] IN_DATA_TB ;
reg [DATA_WIDTH_TB-1:0] PRDATA_TB ;
reg [2:0] IN_PROT_TB ;
reg IN_WRITE_TB ;
reg [STRB_WIDTH_TB-1:0] IN_STRB_TB ;
reg Transfer_TB ;
reg PREADY_TB ;
reg PSLVERR_TB ;
wire OUT_SLVERR_TB;
wire [DATA_WIDTH_TB-1:0] OUT_RDATA_TB ;
wire [ADDRESS_WIDTH_TB-1:0] PADDR_TB ;
wire [DATA_WIDTH_TB-1:0] PWDATA_TB ;
wire PWRITE_TB ;
wire PENABLE_TB ;
wire [2:0] PPROT_TB ;
wire [STRB_WIDTH_TB-1:0] PSTRB_TB ;
wire [SLAVES_NUM_TB-1:0] PSEL_TB ;
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////Initial Block///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
initial
begin
init();
rst();
$display("===================== Test write opteration with no waits=====================");
write_no_wait('b01000000,'b00100000);
$display("===================== Test write opteration with waits=====================");
write_with_wait('b01000000,'b00100000);
$display("===================== Test read opteration with no waits=====================");
read_no_wait('b01000000,'b00100000);
$display("===================== Test read opteration with waits=====================");
read_with_wait('b01000000,'b00100000);
#20
$finish;
end
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////Clock_Generator//////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
always #5 PCLK_TB = ~ PCLK_TB;
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////DUT instantiation/////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
APB_MASTER #(.DATA_WIDTH(DATA_WIDTH_TB), .ADDRESS_WIDTH(ADDRESS_WIDTH_TB), .STRB_WIDTH(STRB_WIDTH_TB), .SLAVES_NUM(SLAVES_NUM_TB))
DUT (
.PCLK(PCLK_TB),
.PRESETn(PRESETn_TB),
.IN_ADDR(IN_ADDR_TB),
.IN_DATA(IN_DATA_TB),
.PRDATA(PRDATA_TB),
.IN_WRITE(IN_WRITE_TB),
.Transfer(Transfer_TB),
.PREADY(PREADY_TB),
.PSLVERR(PSLVERR_TB),
.IN_PROT(IN_PROT_TB),
.IN_STRB(IN_STRB_TB),
.PPROT(PPROT_TB),
.PSTRB(PSTRB_TB),
.OUT_SLVERR(OUT_SLVERR_TB),
.OUT_RDATA(OUT_RDATA_TB),
.PADDR(PADDR_TB),
.PWDATA(PWDATA_TB),
.PWRITE(PWRITE_TB),
.PENABLE(PENABLE_TB),
.PSEL(PSEL_TB)
);
task init();
begin
# 10
PCLK_TB = 'b0;
PRESETn_TB = 'b1;
PSLVERR_TB = 'b0;
Transfer_TB = 'b0;
PREADY_TB = 'b0;
IN_ADDR_TB = 'd58;
IN_DATA_TB = 'd0;
IN_PROT_TB = 3'b0;
IN_STRB_TB = 'b0101;
IN_WRITE_TB = 'b0;
PRDATA_TB = 'b0;
end
endtask
task rst();
begin
PRESETn_TB = 'b1;
#10
PRESETn_TB = 'b0;
#10
PRESETn_TB = 'b1;
end
endtask
///////////////////////////////////////////////////////////////////////////////////
///////////////////////Write operation with no waits///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
task write_no_wait(
input reg [SLAVES_NUM_TB-1:0] SLAVE1,
input reg [SLAVES_NUM_TB-1:0] SLAVE2
);
begin
#10
Transfer_TB = 'b1;
IN_ADDR_TB = 'hBAB84CD3; //address = 1011_1010_1011_1000_0100_1100_1101_0011;
IN_DATA_TB = 'd98;
IN_WRITE_TB = 'b1;
PREADY_TB = 'b0;
#15
$display("************First write operation test************");
if (PSEL_TB == SLAVE1 && PADDR_TB == IN_ADDR_TB && PWDATA_TB == IN_DATA_TB)
$display("First Setup process done successfully");
else
$display("First Setup process has an error");
#5
PREADY_TB = 'b1;
#10
//Put the second transfer data
IN_ADDR_TB = 'hB6B84CD3; //address = 1011_0110_1011_1000_0100_1100_1101_0011;
IN_DATA_TB = 'd90;
PREADY_TB = 'b0;
#5
if (PENABLE_TB == 1'b0)
$display("First write operation done successfully");
else
$display("First write operation has an error");
#5
$display("************Second write operation test************");
if (PSEL_TB == SLAVE2 && PADDR_TB == IN_ADDR_TB && PWDATA_TB == IN_DATA_TB)
$display("Second Setup process done successfully");
else
$display("Second Setup process has an error");
PREADY_TB = 'b1;
Transfer_TB = 'b0;
#10
PREADY_TB = 'b0;
#5
if (PENABLE_TB == 1'b0)
$display("Second write operation done successfully");
else
$display("Second write operation has an error");
#15
$display("************No anthoer write operation needed test************");
if (PENABLE_TB == 1'b0)
$display("Master return to idle state successsfully when no anthor wirte operation needed");
else
$display("Master operation has an error");
end
endtask
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////Write operation with waits///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
task write_with_wait(
input reg [SLAVES_NUM_TB-1:0] SLAVE1,
input reg [SLAVES_NUM_TB-1:0] SLAVE2
);
begin
#10
Transfer_TB = 'b1;
IN_ADDR_TB = 'hBAB84CD3; //address = 1011_1010_1011_1000_0100_1100_1101_0011;
IN_DATA_TB = 'd98;
IN_WRITE_TB = 'b1;
PREADY_TB = 'b0;
#15
$display("************First write operation test************");
if (PSEL_TB == SLAVE1 && PADDR_TB == IN_ADDR_TB && PWDATA_TB == IN_DATA_TB)
$display("First Setup process done successfully");
else
$display("First Setup process has an error");
#25
if (PENABLE_TB == 1'b1)
$display("Master is waiting");
else
$display("An Error occur: Master didn't wait");
PREADY_TB = 'b1;
#10
//Put the second transfer data
IN_ADDR_TB = 'hB6B84CD3; //address = 1011_0110_1011_1000_0100_1100_1101_0011;
IN_DATA_TB = 'd90;
PREADY_TB = 'b0;
#5
if (PENABLE_TB == 1'b0)
$display("First write operation done successfully");
else
$display("First write operation has an error");
#5
$display("************Second write operation test************");
if (PSEL_TB == SLAVE2 && PADDR_TB == IN_ADDR_TB && PWDATA_TB == IN_DATA_TB)
$display("Second Setup process done successfully");
else
$display("Second Setup process has an error");
#20
if (PENABLE_TB == 1'b1)
$display("Master is waiting");
else
$display("An Error occur: Master didn't wait");
PREADY_TB = 'b1;
Transfer_TB = 'b0;
#10
PREADY_TB = 'b0;
#5
if (PENABLE_TB == 1'b0)
$display("Second write operation done successfully");
else
$display("Second write operation has an error");
#15
$display("************No anthoer write operation needed test************");
if (PENABLE_TB == 1'b0)
$display("Master return to idle state successsfully when no anthor wirte operation needed");
else
$display("Master operation has an error");
end
endtask
///////////////////////////////////////////////////////////////////////////////////
///////////////////////Read operation with no waits///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
task read_no_wait(
input reg [SLAVES_NUM_TB-1:0] SLAVE1,
input reg [SLAVES_NUM_TB-1:0] SLAVE2
);
begin
#10
Transfer_TB = 'b1;
IN_ADDR_TB = 'hBAB84CD3; //address = 1011_1010_1011_1000_0100_1100_1101_0011;
IN_WRITE_TB = 'b0;
PREADY_TB = 'b0;
#15
$display("************First read operation test************");
if (PSEL_TB == SLAVE1 && PADDR_TB == IN_ADDR_TB)
$display("First Setup process done successfully");
else
$display("First Setup process has an error");
#5
PREADY_TB = 'b1;
PRDATA_TB = 'd98;
#10
//Put the second transfer data
IN_ADDR_TB = 'hB6B84CD3; //address = 1011_0110_1011_1000_0100_1100_1101_0011;
PREADY_TB = 'b0;
#5
if (OUT_RDATA_TB == PRDATA_TB && PENABLE_TB == 1'b0)
$display("First read operation done successfully");
else
$display("First read operation has an error");
$display("************Second read operation test************");
if (PSEL_TB == SLAVE2 && PADDR_TB == IN_ADDR_TB)
$display("Second Setup process done successfully");
else
$display("Second Setup process has an error");
#5
PREADY_TB = 'b1;
PRDATA_TB = 'd90;
#5
Transfer_TB = 'b0;
#5
PREADY_TB = 'b0;
#5
if (OUT_RDATA_TB == PRDATA_TB && PENABLE_TB == 1'b0)
$display("Second read operation done successfully");
else
$display("Second read operation has an error");
#25
$display("************No anthoer read operation needed test************");
if (PENABLE_TB == 1'b0)
$display("Master return to idle state successsfully when no anthor read operation needed");
else
$display("Master operation has an error");
end
endtask
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////Read operation with waits///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
task read_with_wait(
input reg [SLAVES_NUM_TB-1:0] SLAVE1,
input reg [SLAVES_NUM_TB-1:0] SLAVE2
);
begin
#10
Transfer_TB = 'b1;
IN_ADDR_TB = 'hBAB84CD3; //address = 1011_1010_1011_1000_0100_1100_1101_0011;
IN_WRITE_TB = 'b0;
PREADY_TB = 'b0;
#15
$display("************First read operation test************");
if (PSEL_TB == SLAVE1 && PADDR_TB == IN_ADDR_TB)
$display("First Setup process done successfully");
else
$display("First Setup process has an error");
#25
if (PENABLE_TB == 1'b1)
$display("Master is waiting");
else
$display("An Error occur: Master didn't wait");
PREADY_TB = 'b1;
PRDATA_TB = 'd98;
#10
//Put the second transfer data
IN_ADDR_TB = 'hB6B84CD3; //address = 1011_0110_1011_1000_0100_1100_1101_0011;
PREADY_TB = 'b0;
#5
if (OUT_RDATA_TB == PRDATA_TB && PENABLE_TB == 1'b0)
$display("First read operation done successfully");
else
$display("First read operation has an error");
$display("************Second read operation test************");
if (PSEL_TB == SLAVE2 && PADDR_TB == IN_ADDR_TB)
$display("Second Setup process done successfully");
else
$display("Second Setup process has an error");
#25
if (PENABLE_TB == 1'b1)
$display("Master is waiting");
else
$display("An Error occur: Master didn't wait");
PREADY_TB = 'b1;
PRDATA_TB = 'd90;
#5
Transfer_TB = 'b0;
#5
PREADY_TB = 'b0;
#5
if (OUT_RDATA_TB == PRDATA_TB && PENABLE_TB == 1'b0)
$display("Second read operation done successfully");
else
$display("Second read operation has an error");
#25
$display("************No anthoer read operation needed test************");
if (PENABLE_TB == 1'b0)
$display("Master return to idle state successsfully when no anthor read operation needed");
else
$display("Master operation has an error");
end
endtask
endmodule