OpenCores
URL https://opencores.org/ocsvn/apb_mstr/apb_mstr/trunk

Subversion Repositories apb_mstr

[/] [apb_mstr/] [trunk/] [src/] [base/] [axi_master_single.v] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 eyalhoc
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Author: Eyal Hochberg                                      ////
4
////          eyal@provartec.com                                 ////
5
////                                                             ////
6
////  Downloaded from: http://www.opencores.org                  ////
7
/////////////////////////////////////////////////////////////////////
8
////                                                             ////
9
//// Copyright (C) 2010 Provartec LTD                            ////
10
//// www.provartec.com                                           ////
11
//// info@provartec.com                                          ////
12
////                                                             ////
13
//// This source file may be used and distributed without        ////
14
//// restriction provided that this copyright statement is not   ////
15
//// removed from the file and that any derivative work contains ////
16
//// the original copyright notice and the associated disclaimer.////
17
////                                                             ////
18
//// This source file is free software; you can redistribute it  ////
19
//// and/or modify it under the terms of the GNU Lesser General  ////
20
//// Public License as published by the Free Software Foundation.////
21
////                                                             ////
22
//// This source is distributed in the hope that it will be      ////
23
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
24
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
25
//// PURPOSE.  See the GNU Lesser General Public License for more////
26
//// details. http://www.gnu.org/licenses/lgpl.html              ////
27
////                                                             ////
28
/////////////////////////////////////////////////////////////////////
29
 
30
OUTFILE PREFIX_single.v
31
 
32
INCLUDE def_axi_master.txt
33
 
34
module PREFIX_single(PORTS);
35
 
36
   parameter                           MASTER_NUM  = 0;
37
   parameter                           MASTER_ID   = 0;
38
   parameter                           MASTER_PEND = 0;
39
 
40 4 eyalhoc
CREATE prgen_rand.v DEFCMD(DEFINE NOT_IN_LIST)
41 2 eyalhoc
`include "prgen_rand.v"
42
 
43
   parameter                           MAX_CMDS    = 16; //Depth of command FIFO
44
   parameter                           DATA_LOG    = LOG2(EXPR(DATA_BITS/8));
45
   parameter                           PEND_BITS   =
46
                                       (MAX_CMDS <= 16)  ? 4 :
47
                                       (MAX_CMDS <= 32)  ? 5 :
48
                                       (MAX_CMDS <= 64)  ? 6 :
49
                                       (MAX_CMDS <= 128) ? 7 :
50
                                       (MAX_CMDS <= 256) ? 8 :
51
                                       (MAX_CMDS <= 512) ? 9 : 0; //0 is ilegal
52
 
53
 
54
 
55
   input                               clk;
56
   input                               reset;
57
 
58
   port                                GROUP_STUB_AXI;
59
 
60
   output                              idle;
61
   output                              scrbrd_empty;
62
 
63
 
64
 
65
   //random parameters   
66
   integer                             GROUP_AXI_MASTER_RAND = GROUP_AXI_MASTER_RAND.DEFAULT;
67
 
68
   reg                                 AWVALID_pre;
69
   reg                                 WVALID_pre;
70
   wire                                BREADY_pre;
71
   reg                                 ARVALID_pre;
72
   wire                                RREADY_pre;
73
 
74
   reg                                 enable = 0;
75
   reg                                 rd_enable = 0;
76
   reg                                 wr_enable = 0;
77
   reg                                 wait_for_write = 0;
78
 
79
   reg                                 scrbrd_enable = 0;
80
   reg [LEN_BITS-1:0]                   wvalid_cnt;
81
 
82
   reg                                 rd_cmd_push = 0;
83
   wire                                rd_cmd_pop;
84
   wire [PEND_BITS:0]                  rd_cmd_fullness;
85
   wire                                rd_cmd_empty;
86
   wire                                rd_cmd_full;
87
   reg [ADDR_BITS-1:0]                  rd_cmd_addr_in;
88
   reg [LEN_BITS-1:0]                   rd_cmd_len_in;
89
   reg [SIZE_BITS-1:0]                  rd_cmd_size_in;
90
   wire [ADDR_BITS-1:0]         rd_cmd_addr;
91
   wire [LEN_BITS-1:0]                  rd_cmd_len;
92
   wire [SIZE_BITS-1:0]         rd_cmd_size;
93
 
94
   reg                                 rd_resp_push = 0;
95
   wire                                rd_resp_pop;
96
   wire                                rd_resp_empty;
97
   wire                                rd_resp_full;
98
   reg [ADDR_BITS-1:0]                  rd_resp_addr_in;
99
   reg [SIZE_BITS-1:0]                  rd_resp_size_in;
100
   wire [ADDR_BITS-1:0]         rd_resp_addr;
101
   wire [SIZE_BITS-1:0]         rd_resp_size;
102
 
103
   reg                                 wr_cmd_push = 0;
104
   wire                                wr_cmd_pop;
105
   wire [PEND_BITS:0]                  wr_cmd_fullness;
106
   wire                                wr_cmd_empty;
107
   wire                                wr_cmd_full;
108
   reg [ADDR_BITS-1:0]                  wr_cmd_addr_in;
109
   reg [LEN_BITS-1:0]                   wr_cmd_len_in;
110
   reg [SIZE_BITS-1:0]                  wr_cmd_size_in;
111
   wire [ADDR_BITS-1:0]         wr_cmd_addr;
112
   wire [LEN_BITS-1:0]                  wr_cmd_len;
113
   wire [SIZE_BITS-1:0]         wr_cmd_size;
114
 
115
   reg                                 wr_data_push = 0;
116
   wire                                wr_data_pop;
117
   wire [PEND_BITS:0]                  wr_data_fullness;
118
   wire                                wr_data_empty;
119
   wire                                wr_data_full;
120
   reg [ADDR_BITS-1:0]                  wr_data_addr_in;
121
   reg [LEN_BITS-1:0]                   wr_data_len_in;
122
   reg [SIZE_BITS-1:0]                  wr_data_size_in;
123
   wire [ADDR_BITS-1:0]         wr_data_addr;
124
   wire [LEN_BITS-1:0]                  wr_data_len;
125
   wire [SIZE_BITS-1:0]         wr_data_size;
126
   wire [DATA_BITS/8-1:0]               wr_data_strb;
127
   wire [7:0]                           wr_data_bytes;
128
   wire [ADDR_BITS-1:0]         wr_data_addr_prog;
129
   wire [7:0]                           wr_data_offset;
130
 
131
   wire                                wr_resp_push;
132
   reg                                 wr_resp_pop = 0;
133
   wire                                wr_resp_empty;
134
   wire                                wr_resp_full;
135
   wire [1:0]                          wr_resp_resp_in;
136
   wire [1:0]                          wr_resp_resp;
137
 
138
   reg                                 wr_fifo_push = 0;
139
   wire                                wr_fifo_pop;
140
   wire                                wr_fifo_empty;
141
   wire                                wr_fifo_full;
142
   reg [DATA_BITS-1:0]                 wr_fifo_data_in;
143
   wire [DATA_BITS-1:0]                wr_fifo_data;
144
 
145
   wire                                rd_fifo_push;
146
   reg                                 rd_fifo_pop = 0;
147
   wire                                rd_fifo_empty;
148
   wire                                rd_fifo_full;
149
   wire [DATA_BITS-1:0]                rd_fifo_data_in;
150
   wire [1:0]                          rd_fifo_resp_in;
151
   wire [DATA_BITS-1:0]                rd_fifo_data;
152
   wire [1:0]                          rd_fifo_resp;
153
 
154
   reg                                 scrbrd_push = 0;
155
   reg                                 scrbrd_pop = 0;
156
   wire                                scrbrd_empty;
157
   wire                                scrbrd_full;
158
   reg [ADDR_BITS-1:0]                 scrbrd_addr_in;
159
   reg [DATA_BITS-1:0]                 scrbrd_data_in;
160
   reg [DATA_BITS-1:0]                 scrbrd_mask_in;
161
   wire [ADDR_BITS-1:0]                scrbrd_addr;
162
   wire [DATA_BITS-1:0]                scrbrd_data;
163
   wire [DATA_BITS-1:0]                scrbrd_mask;
164
 
165
   integer                             wr_fullness;
166
   integer                             rd_fullness;
167
   integer                             rd_completed;
168
   integer                             wr_completed;
169
   integer                             wr_pend_max = MASTER_PEND;
170
   integer                             rd_pend_max = MASTER_PEND;
171
   wire                                wr_hold;
172
   wire                                rd_hold;
173
 
174
   integer                             rand_chk_num = 0;
175
 
176
 
177
   assign                              idle = rd_cmd_empty & rd_resp_empty & wr_cmd_empty & wr_data_empty & wr_resp_empty;
178
 
179
   always @(rand_chk_num)
180
     if (rand_chk_num > 0)
181
       insert_rand_chk_loop(rand_chk_num);
182
 
183
   always @(posedge enable)
184
     begin
185
        @(posedge clk);
186
        wr_enable = 1;
187
        repeat (50) @(posedge clk);
188
        rd_enable = 1;
189
     end
190
 
191
   //for incremental data
192
   reg [DATA_BITS-1:0]                 base_data = 0;
193
   integer                             ww;
194
   initial
195
     begin
196
        ww=0;
197
        while (ww < DATA_BITS/8)
198
          begin
199
             base_data = base_data + ((MASTER_NUM + ww) << (ww*8));
200
             ww = ww + 1;
201
          end
202
     end
203
 
204
   assign         rd_cmd_pop   = ARVALID & ARREADY;
205
   assign         rd_resp_pop  = RVALID & RREADY & RLAST;
206
   assign         rd_fifo_push = RVALID & RREADY;
207
   assign         wr_cmd_pop   = AWVALID & AWREADY;
208
   assign         wr_data_pop  = WVALID & WREADY & WLAST;
209
   assign         wr_fifo_pop  = WVALID & WREADY;
210
   assign         wr_resp_push = BVALID & BREADY;
211
 
212
   assign         RREADY_pre = 1;
213
   assign         BREADY_pre = 1;
214
 
215
 
216
   always @(posedge clk or posedge reset)
217
     if (reset)
218
       AWVALID_pre <= #FFD 1'b0;
219
     else if ((wr_cmd_fullness == 1) & wr_cmd_pop)
220
       AWVALID_pre <= #FFD 1'b0;
221
     else if ((!wr_cmd_empty) & wr_enable)
222
       AWVALID_pre <= #FFD 1'b1;
223
 
224
 
225
   assign         AWADDR  = wr_cmd_addr;
226
   assign         AWLEN   = wr_cmd_len;
227
   assign         AWSIZE  = wr_cmd_size;
228
   assign         AWID    = MASTER_ID;
229
   assign         AWBURST = 2'd1; //INCR only
230
   assign         AWCACHE = 4'd0; //not supported
231
   assign         AWPROT  = 4'd0; //not supported
232
   assign         AWLOCK  = 2'd0; //not supported
233
 
234
   always @(posedge clk or posedge reset)
235
     if (reset)
236
       ARVALID_pre <= #FFD 1'b0;
237
     else if (((rd_cmd_fullness == 1)) & rd_cmd_pop)
238
       ARVALID_pre <= #FFD 1'b0;
239
     else if ((!rd_cmd_empty) & rd_enable)
240
       ARVALID_pre <= #FFD 1'b1;
241
 
242
   assign         ARADDR  = rd_cmd_addr;
243
   assign         ARLEN   = rd_cmd_len;
244
   assign         ARSIZE  = rd_cmd_size;
245
   assign         ARID    = MASTER_ID;
246
   assign         ARBURST = 2'd1; //INCR only
247
   assign         ARCACHE = 4'd0; //not supported
248
   assign         ARPROT  = 4'd0; //not supported
249
   assign         ARLOCK  = 2'd0; //not supported
250
 
251
   assign         rd_fifo_data_in = RDATA;
252
   assign         rd_fifo_resp_in = BRESP;
253
 
254
   assign         wr_data_bytes = 1'b1 << wr_data_size;
255
 
256
   assign         wr_data_strb =
257
                  wr_data_size == 'd0 ? 1'b1       :
258
                  wr_data_size == 'd1 ? 2'b11      :
259
                  wr_data_size == 'd2 ? 4'b1111    :
260
                  wr_data_size == 'd3 ? {8{1'b1}}  :
261
                  wr_data_size == 'd4 ? {16{1'b1}} : 'd0;
262
 
263
   assign         wr_data_addr_prog = wr_data_addr + (wvalid_cnt * wr_data_bytes);
264
 
265
   always @(posedge clk or posedge reset)
266
     if (reset)
267
       WVALID_pre <= #FFD 1'b0;
268
     else if ((wr_data_fullness == 1) & wr_data_pop)
269
       WVALID_pre <= #FFD 1'b0;
270
     else if ((!wr_data_empty) & wr_enable)
271
       WVALID_pre <= #FFD 1'b1;
272
 
273
 
274
   assign         wr_data_offset = wr_data_addr_prog[DATA_LOG-1:0];
275
 
276
   assign         WID   = MASTER_ID;
277
   assign         WDATA = wr_fifo_empty ? 0 : wr_fifo_data;
278
   assign         WSTRB = wr_data_strb << wr_data_offset;
279
 
280
 
281
   always @(posedge clk or posedge reset)
282
     if (reset)
283
       wvalid_cnt <= #FFD {LEN_BITS{1'b0}};
284
     else if (wr_data_pop)
285
       wvalid_cnt <= #FFD {LEN_BITS{1'b0}};
286
     else if (WVALID & WREADY)
287
       wvalid_cnt <= #FFD wvalid_cnt + 1'b1;
288
 
289
   assign         WLAST = WVALID & (wvalid_cnt == wr_data_len);
290
 
291
   assign         wr_resp_resp_in = BRESP;
292
 
293
   always @(posedge clk or posedge reset)
294
     if (reset)
295
       begin
296
          wr_fullness <= #FFD 0;
297
          rd_fullness <= #FFD 0;
298
          rd_completed <= #FFD 0;
299
          wr_completed <= #FFD 0;
300
       end
301
     else
302
       begin
303
          wr_fullness <= #FFD wr_fullness + wr_cmd_pop - wr_resp_push;
304
          rd_fullness <= #FFD rd_fullness + rd_cmd_pop - rd_resp_pop;
305
          rd_completed <= #FFD rd_completed + rd_resp_pop;
306
          wr_completed <= #FFD wr_completed + wr_resp_push;
307
       end
308
 
309
   assign         wr_hold = wr_fullness >= wr_pend_max;
310
   assign         rd_hold = (rd_fullness >= rd_pend_max) | (wait_for_write & (wr_completed <= rd_completed + rd_fullness));
311
 
312
 
313
 
314
   task insert_rd_cmd;
315
      input [ADDR_BITS-1:0]  addr;
316
      input [LEN_BITS-1:0]   len;
317
      input [SIZE_BITS-1:0]  size;
318
 
319
      begin
320
         rd_cmd_addr_in  = addr;
321
         rd_cmd_len_in   = len;
322
         rd_cmd_size_in  = size;
323
         rd_resp_addr_in = addr;
324
         rd_resp_size_in = size;
325
 
326
         if (rd_cmd_full) enable = 1; //start stub not started yet
327
 
328
         wait ((!rd_cmd_full) & (!rd_resp_full));
329
         @(negedge clk); #FFD;
330
         rd_cmd_push  = 1;
331
         rd_resp_push = 1;
332
         @(posedge clk); #FFD;
333
         rd_cmd_push  = 0;
334
         rd_resp_push = 0;
335
      end
336
   endtask
337
 
338
   task insert_wr_cmd;
339
      input [ADDR_BITS-1:0]  addr;
340
      input [LEN_BITS-1:0]   len;
341
      input [SIZE_BITS-1:0]  size;
342
 
343
      begin
344
         wr_cmd_addr_in  = addr;
345
         wr_cmd_len_in   = len;
346
         wr_cmd_size_in  = size;
347
         wr_data_addr_in = addr;
348
         wr_data_len_in  = len;
349
         wr_data_size_in = size;
350
 
351
         if (wr_cmd_full) enable = 1; //start stub not started yet
352
 
353
         wait ((!wr_cmd_full) & (!wr_data_full));
354
         @(negedge clk); #FFD;
355
         wr_cmd_push  = 1;
356
         wr_data_push = 1;
357
         @(posedge clk); #FFD;
358
         wr_cmd_push  = 0;
359
         wr_data_push = 0;
360
      end
361
   endtask
362
 
363
   task insert_wr_data;
364
      input [DATA_BITS-1:0]  wdata;
365
 
366
      begin
367
         wr_fifo_data_in  = wdata;
368
 
369
         wait (!wr_fifo_full);
370
         @(negedge clk); #FFD;
371
         wr_fifo_push = 1;
372
         @(posedge clk); #FFD;
373
         wr_fifo_push = 0;
374
      end
375
   endtask
376
 
377
   task insert_wr_incr_data;
378
      input [ADDR_BITS-1:0]  addr;
379
      input [LEN_BITS-1:0]   len;
380
      input [SIZE_BITS-1:0]  size;
381
 
382
      integer valid_cnt;
383
      integer wdata_cnt;
384
      reg [7:0] data_cnt;
385
      integer bytes;
386
      reg [DATA_BITS-1:0] add_data;
387
      reg [DATA_BITS-1:0] next_data;
388
      begin
389
         //insert data
390
         valid_cnt = 0;
391
         while (valid_cnt <= len)
392
           begin
393
              bytes = 1'b1 << size;
394
              wdata_cnt = valid_cnt+(addr[DATA_LOG-1:0]/bytes);
395
              data_cnt  = ((wdata_cnt)/(DATA_BITS/(bytes*8))) * (DATA_BITS/8);
396
              add_data  = {DATA_BITS/8{data_cnt}};
397
              next_data = (use_addr_base ? addr : base_data) + add_data;
398
              insert_wr_data(next_data);
399
              valid_cnt = valid_cnt+1;
400
           end
401
         //insert command
402
         insert_wr_cmd(addr, len, size);
403
      end
404
   endtask
405
 
406
   task insert_scrbrd;
407
      input [ADDR_BITS-1:0]  addr;
408
      input [DATA_BITS-1:0]  data;
409
      input [DATA_BITS-1:0]  mask;
410
      begin
411
         scrbrd_enable = 1;
412
         scrbrd_addr_in  = addr;
413
         scrbrd_data_in  = data;
414
         scrbrd_mask_in  = mask;
415
 
416
         wait (!scrbrd_full);
417
         @(negedge clk); #FFD;
418
         scrbrd_push = 1;
419
         @(posedge clk); #FFD;
420
         scrbrd_push = 0;
421
      end
422
   endtask
423
 
424
   task insert_scrbrd_incr_data;
425
      input [ADDR_BITS-1:0]  addr;
426
      input [LEN_BITS-1:0]   len;
427
      input [SIZE_BITS-1:0]  size;
428
 
429
      integer valid_cnt;
430
      integer wdata_cnt;
431
      reg [7:0] data_cnt;
432
      integer bytes;
433
      reg [DATA_BITS-1:0] add_data;
434
      reg [DATA_BITS-1:0] next_data;
435
      reg [DATA_BITS:0] strb;
436
      reg [DATA_BITS-1:0] mask;
437
      reg [ADDR_BITS-1:0] next_addr;
438
      begin
439
         valid_cnt = 0;
440
         while (valid_cnt <= len)
441
           begin
442
              bytes = 1'b1 << size;
443
              wdata_cnt = valid_cnt+(addr[DATA_LOG-1:0]/bytes);
444
              data_cnt  = ((wdata_cnt)/(DATA_BITS/(bytes*8))) * (DATA_BITS/8);
445
              add_data  = {DATA_BITS/8{data_cnt}};
446
              next_data = (use_addr_base ? addr : base_data) + add_data;
447
              next_addr = addr + (bytes * valid_cnt);
448
              strb = (1 << (bytes*8)) - 1;
449
              mask = strb << (next_addr[DATA_LOG-1:0]*8);
450
              insert_scrbrd(next_addr, next_data, mask);
451
              valid_cnt = valid_cnt+1;
452
           end
453
      end
454
   endtask
455
 
456
   task insert_rd_scrbrd;
457
      input [ADDR_BITS-1:0]  addr;
458
      input [LEN_BITS-1:0]   len;
459
      input [SIZE_BITS-1:0]  size;
460
 
461
      begin
462
         insert_scrbrd_incr_data(addr, len, size);
463
         insert_rd_cmd(addr, len, size);
464
      end
465
   endtask
466
 
467
   task insert_wr_rd_scrbrd;
468
      input [ADDR_BITS-1:0]  addr;
469
      input [LEN_BITS-1:0]   len;
470
      input [SIZE_BITS-1:0]  size;
471
 
472
      begin
473
         wait_for_write=1;
474
         insert_wr_incr_data(addr, len, size);
475
         insert_rd_scrbrd(addr, len, size);
476
      end
477
   endtask
478
 
479
   task insert_wr_rd_scrbrd_rand;
480
      reg [ADDR_BITS-1:0]  addr;
481
      reg [LEN_BITS-1:0]   len;
482
      reg [SIZE_BITS-1:0]  size;
483
 
484
      begin
485
         len   = rand(len_min, len_max);
486
         size  = rand(size_min, size_max);
487
         addr  = rand_align(addr_min, addr_max, 1 << size);
488
         insert_wr_rd_scrbrd(addr, len, size);
489
      end
490
   endtask
491
 
492
   task insert_rand_chk;
493
      input [31:0]  num;
494
 
495
      rand_chk_num = num;
496
   endtask
497
 
498
   task insert_rand_chk_loop;
499
      input [31:0]  num;
500
 
501
      integer i;
502
      begin
503
         i = 0;
504
         while (i < num)
505
           begin
506
              insert_wr_rd_scrbrd_rand;
507
              i = i + 1;
508
           end
509
      end
510
   endtask
511
 
512
   task insert_wr_single;
513
      input [ADDR_BITS-1:0]  addr;
514
      input [DATA_BITS-1:0]  wdata;
515
 
516
      reg [SIZE_BITS-1:0] size;
517
      begin
518
         size = EXPR((DATA_BITS/32)+1);
519
         insert_wr_data(wdata);
520
         insert_wr_cmd(addr, 0, size);
521
      end
522
   endtask
523
 
524
   task get_rd_resp;
525
      output [DATA_BITS-1:0] rdata;
526
      output [1:0] resp;
527
 
528
      reg [DATA_BITS-1:0] rdata;
529
      reg [1:0] resp;
530
      begin
531
         wait (!rd_fifo_empty);
532
         rdata = rd_fifo_data;
533
         resp = rd_fifo_resp;
534
         @(negedge clk); #FFD;
535
         rd_fifo_pop = 1;
536
         @(posedge clk); #FFD;
537
         rd_fifo_pop = 0;
538
      end
539
   endtask
540
 
541
   task get_scrbrd;
542
      output [ADDR_BITS-1:0] addr;
543
      output [DATA_BITS-1:0] rdata;
544
      output [DATA_BITS-1:0] mask;
545
 
546
      reg [ADDR_BITS-1:0] addr;
547
      reg [DATA_BITS-1:0] rdata;
548
      reg [DATA_BITS-1:0] mask;
549
      begin
550
         wait (!scrbrd_empty);
551
         addr = scrbrd_addr;
552
         rdata = scrbrd_data;
553
         mask = scrbrd_mask;
554
         @(negedge clk); #FFD;
555
         scrbrd_pop = 1;
556
         @(posedge clk); #FFD;
557
         scrbrd_pop = 0;
558
      end
559
   endtask
560
 
561
   task get_wr_resp;
562
      output [1:0] resp;
563
 
564
      reg [1:0] resp;
565
      begin
566
         wait (!wr_resp_empty);
567
         resp = wr_resp_resp;
568
         @(negedge clk); #FFD;
569
         wr_resp_pop = 1;
570
         @(posedge clk); #FFD;
571
         wr_resp_pop = 0;
572
      end
573
   endtask
574
 
575
   task insert_rd_single;
576
      input [ADDR_BITS-1:0]  addr;
577
 
578
      reg [SIZE_BITS-1:0] size;
579
      begin
580
         size = EXPR((DATA_BITS/32)+1);
581
         insert_rd_cmd(addr, 0, size);
582
      end
583
   endtask
584
 
585
   task read_single_ack;
586
      input [ADDR_BITS-1:0]  addr;
587
      output [DATA_BITS-1:0] rdata;
588
      output [1:0]           resp;
589
 
590
      reg [1:0] resp;
591
      begin
592
         insert_rd_single(addr);
593
         get_rd_resp(rdata, resp);
594
      end
595
   endtask
596
 
597
   task write_single_ack;
598
      input [ADDR_BITS-1:0]  addr;
599
      input [DATA_BITS-1:0]  wdata;
600
      output [1:0]           resp;
601
 
602
      reg [1:0] resp;
603
      begin
604
         insert_wr_single(addr, wdata);
605
         get_wr_resp(resp);
606
      end
607
   endtask
608
 
609
   task read_single;
610
      input [ADDR_BITS-1:0]  addr;
611
      output [DATA_BITS-1:0] rdata;
612
 
613
      reg [1:0] resp;
614
      begin
615
         read_single_ack(addr, rdata, resp);
616
      end
617
   endtask
618
 
619
   task check_single;
620
      input [ADDR_BITS-1:0]  addr;
621
      input [DATA_BITS-1:0]  expected;
622
 
623
      reg [1:0] resp;
624
      reg [DATA_BITS-1:0] rdata;
625
      begin
626
         read_single_ack(addr, rdata, resp);
627
         if (rdata !== expected)
628
           $display("MASTER%0d: CHK_SINGLE_ERROR: Address: 0x%0h, Expected: 0x%0h, Received: 0x%0h.\tTime: %0d ns.", MASTER_NUM, addr, expected, rdata, $time);
629
      end
630
   endtask
631
 
632
   task write_and_check_single;
633
      input [ADDR_BITS-1:0]  addr;
634
      input [DATA_BITS-1:0]  data;
635
 
636
      begin
637
         write_single(addr, data);
638
         check_single(addr, data);
639
      end
640
   endtask
641
 
642
   task write_single;
643
      input [ADDR_BITS-1:0]  addr;
644
      input [DATA_BITS-1:0]  wdata;
645
 
646
      reg [1:0] resp;
647
      begin
648
         write_single_ack(addr, wdata, resp);
649
      end
650
   endtask
651
 
652
   task chk_scrbrd;
653
      reg [ADDR_BITS-1:0] addr;
654
      reg [DATA_BITS-1:0] mask;
655
      reg [DATA_BITS-1:0] expected_data;
656
      reg [DATA_BITS-1:0] rdata;
657
      reg [DATA_BITS-1:0] rdata_masked;
658
      reg [1:0] resp;
659
 
660
      begin
661
         if (!wr_resp_empty) get_wr_resp(resp);
662
         get_scrbrd(addr, expected_data, mask);
663
         get_rd_resp(rdata, resp);
664
         expected_data = expected_data & mask; //TBD insert z as dontcare (for print)
665
         rdata_masked = rdata & mask;
666
 
667
         if (expected_data !== rdata_masked)
668
           $display("MASTER%0d: SCRBRD_ERROR: Address: 0x%0h, Expected: 0x%0h, Received: 0x%0h.\tTime: %0d ns.", MASTER_NUM, addr, expected_data, rdata, $time);
669
      end
670
   endtask
671
 
672
   always @(posedge scrbrd_enable)
673
     begin
674
        while (scrbrd_enable)
675
          begin
676
             chk_scrbrd;
677
          end
678
     end
679
 
680
 
681
CREATE prgen_fifo.v DEFCMD(DEFINE STUB)
682
   prgen_fifo_stub #(ADDR_BITS+LEN_BITS+SIZE_BITS, MAX_CMDS)
683
   rd_cmd_list(
684
               .clk(clk),
685
               .reset(reset),
686
               .push(rd_cmd_push),
687
               .pop(rd_cmd_pop),
688
               .din({
689
                     rd_cmd_size_in,
690
                     rd_cmd_len_in,
691
                     rd_cmd_addr_in
692
                     }),
693
               .dout({
694
                      rd_cmd_size,
695
                      rd_cmd_len,
696
                      rd_cmd_addr
697
                      }),
698
               .fullness(rd_cmd_fullness),
699
               .empty(rd_cmd_empty),
700
               .full(rd_cmd_full)
701
               );
702
 
703
   prgen_fifo_stub #(ADDR_BITS+SIZE_BITS, MAX_CMDS)
704
   rd_resp_list(
705
                .clk(clk),
706
                .reset(reset),
707
                .push(rd_resp_push),
708
                .pop(rd_resp_pop),
709
                .din({
710
                      rd_resp_addr_in,
711
                      rd_resp_size_in
712
                      }),
713
                .dout({
714
                       rd_resp_addr,
715
                       rd_resp_size
716
                       }),
717
                .empty(rd_resp_empty),
718
                .full(rd_resp_full)
719
                );
720
 
721
   prgen_fifo_stub #(ADDR_BITS+LEN_BITS+SIZE_BITS, MAX_CMDS)
722
   wr_cmd_list(
723
               .clk(clk),
724
               .reset(reset),
725
               .push(wr_cmd_push),
726
               .pop(wr_cmd_pop),
727
               .din({
728
                     wr_cmd_size_in,
729
                     wr_cmd_len_in,
730
                     wr_cmd_addr_in
731
                     }),
732
               .dout({
733
                      wr_cmd_size,
734
                      wr_cmd_len,
735
                      wr_cmd_addr
736
                      }),
737
               .fullness(wr_cmd_fullness),
738
               .empty(wr_cmd_empty),
739
               .full(wr_cmd_full)
740
               );
741
 
742
   prgen_fifo_stub #(ADDR_BITS+LEN_BITS+SIZE_BITS, MAX_CMDS)
743
   wr_data_list(
744
                .clk(clk),
745
                .reset(reset),
746
                .push(wr_data_push),
747
                .pop(wr_data_pop),
748
                .din({
749
                      wr_data_size_in,
750
                      wr_data_len_in,
751
                      wr_data_addr_in
752
                      }),
753
                .dout({
754
                       wr_data_size,
755
                       wr_data_len,
756
                       wr_data_addr
757
                       }),
758
                .fullness(wr_data_fullness),
759
                .empty(wr_data_empty),
760
                .full(wr_data_full)
761
                );
762
 
763
   prgen_fifo_stub #(2, MAX_CMDS)
764
   wr_resp_list(
765
                .clk(clk),
766
                .reset(reset),
767
                .push(wr_resp_push),
768
                .pop(wr_resp_pop),
769
                .din(wr_resp_resp_in),
770
                .dout(wr_resp_resp),
771
                .empty(wr_resp_empty),
772
                .full(wr_resp_full)
773
                );
774
 
775
 
776
   prgen_fifo_stub #(DATA_BITS, MAX_CMDS*EXPR(2^LEN_BITS))
777
   wr_data_fifo(
778
                .clk(clk),
779
                .reset(reset),
780
                .push(wr_fifo_push),
781
                .pop(wr_fifo_pop),
782
                .din(wr_fifo_data_in),
783
                .dout(wr_fifo_data),
784
                .empty(wr_fifo_empty),
785
                .full(wr_fifo_full)
786
                );
787
 
788
   prgen_fifo_stub #(DATA_BITS+2, MAX_CMDS*EXPR(2^LEN_BITS))
789
   rd_data_fifo(
790
                .clk(clk),
791
                .reset(reset),
792
                .push(rd_fifo_push),
793
                .pop(rd_fifo_pop),
794
                .din({
795
                      rd_fifo_data_in,
796
                      rd_fifo_resp_in
797
                      }),
798
                .dout({
799
                       rd_fifo_data,
800
                       rd_fifo_resp
801
                       }),
802
                .empty(rd_fifo_empty),
803
                .full(rd_fifo_full)
804
                );
805
 
806
   prgen_fifo_stub #(ADDR_BITS+2*DATA_BITS, MAX_CMDS*EXPR(2^LEN_BITS))
807
   scrbrd_fifo(
808
                .clk(clk),
809
                .reset(reset),
810
                .push(scrbrd_push),
811
                .pop(scrbrd_pop),
812
               .din({
813
                     scrbrd_addr_in,
814
                     scrbrd_data_in,
815
                     scrbrd_mask_in
816
                     }),
817
                .dout({
818
                       scrbrd_addr,
819
                       scrbrd_data,
820
                       scrbrd_mask
821
                       }),
822
                .empty(scrbrd_empty),
823
                .full(scrbrd_full)
824
                );
825
 
826
 
827
CREATE axi_master_stall.v
828
   PREFIX_stall
829
     PREFIX_stall (
830
                       .clk(clk),
831
                       .reset(reset),
832
 
833
                       .rd_hold(rd_hold),
834
                       .wr_hold(wr_hold),
835
 
836
                       .ARVALID_pre(ARVALID_pre),
837
                       .RREADY_pre(RREADY_pre),
838
                       .AWVALID_pre(AWVALID_pre),
839
                       .WVALID_pre(WVALID_pre),
840
                       .BREADY_pre(BREADY_pre),
841
 
842
                       .ARREADY(ARREADY),
843
                       .AWREADY(AWREADY),
844
                       .WREADY(WREADY),
845
 
846
                       .ARVALID(ARVALID),
847
                       .RREADY(RREADY),
848
                       .AWVALID(AWVALID),
849
                       .WVALID(WVALID),
850
                       .BREADY(BREADY)
851
                       );
852
 
853
 
854
endmodule
855
 
856
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.