remove debugging code
[debian/gnuradio] / usrp2 / fpga / opencores / uart16550 / bench / verilog / wb_mast.v
1 /////////////////////////////////////////////////////////////////////
2 ////                                                             ////
3 ////  WISHBONE Master Model                                      ////
4 ////                                                             ////
5 ////                                                             ////
6 ////  Author: Rudolf Usselmann                                   ////
7 ////          rudi@asics.ws                                      ////
8 ////                                                             ////
9 /////////////////////////////////////////////////////////////////////
10 ////                                                             ////
11 //// Copyright (C) 2001 Rudolf Usselmann                         ////
12 ////                    rudi@asics.ws                            ////
13 ////                                                             ////
14 //// This source file may be used and distributed without        ////
15 //// restriction provided that this copyright statement is not   ////
16 //// removed from the file and that any derivative work contains ////
17 //// the original copyright notice and the associated disclaimer.////
18 ////                                                             ////
19 ////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
20 //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
21 //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
22 //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
23 //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
24 //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
25 //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
26 //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
27 //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
28 //// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
29 //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
30 //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
31 //// POSSIBILITY OF SUCH DAMAGE.                                 ////
32 ////                                                             ////
33 /////////////////////////////////////////////////////////////////////
34
35 //  CVS Log
36 //
37 //  $Id: wb_mast.v,v 1.1 2001/12/03 21:44:23 gorban Exp $
38 //
39 //  $Date: 2001/12/03 21:44:23 $
40 //  $Revision: 1.1 $
41 //  $Author: gorban $
42 //  $Locker:  $
43 //  $State: Exp $
44 //
45 // Change History:
46 //               $Log: wb_mast.v,v $
47 //               Revision 1.1  2001/12/03 21:44:23  gorban
48 //               Updated specification documentation.
49 //               Added full 32-bit data bus interface, now as default.
50 //               Address is 5-bit wide in 32-bit data bus mode.
51 //               Added wb_sel_i input to the core. It's used in the 32-bit mode.
52 //               Added debug interface with two 32-bit read-only registers in 32-bit mode.
53 //               Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
54 //               My small test bench is modified to work with 32-bit mode.
55 //
56 //
57 //
58 //
59 //
60 //                        
61
62 /*
63
64 task mem_fill;
65
66 - Fills local burst read (rd_buf[]) and write(wr_buf[]) buffers with random values.
67
68
69 task wb_wr1( 32 bit address, 4 bit byte select, 32 bit write data);
70
71 - Performs a single WISHBONE write
72
73
74 task wb_wr4( 32 bit address, 4 bit byte select, integer delay,
75         32 bit data 1, 32 bit data 2, 32 bit data 3, 32 bit data 4);
76
77 - Performs 4 consecutive WISHBONE writes
78 - Strobe is deasserted between writes for 'delay' number of cycles
79   (This simulates wait state insertion ...)
80
81
82 task wb_wr_mult( 32 bit address, 4 bit byte select, integer delay,
83         integer count);
84
85 - Simular to wb_wr4, except it pwrforms "count" number of write cycles.
86   The data is taken from the internal wr_bub[] memory.
87 - Strobe is deasserted between writes for 'delay' number of cycles
88   (This simulates wait state insertion ...)
89
90
91 task wb_rmw( 32 bit address, 4 bit byte select, integer delay,
92         integer rcount, integer wcount);
93
94 - This task performs "rcount" read cycles, followed by wcount write cycles.
95 - read data is placed in to the internal rd_buf[] memory, write data is
96   taken from the internal wr_buf[] memory.
97 - Strobe is deasserted between writes for 'delay' number of cycles
98   (This simulates wait state insertion ...)
99
100
101 task wb_rd1( 32 bit address, 4 bit byte select, 32 bit read data);
102
103 - Performs a single WISHBONE write
104
105
106 task wb_rd4( 32 bit address, 4 bit byte select, integer delay,
107         32 bit data 1, 32 bit data 2, 32 bit data 3, 32 bit data 4);
108
109 - Performs 4 consecutive WISHBONE reads
110 - Strobe is deasserted between reads for 'delay' number of cycles
111   (This simulates wait state insertion ...)
112
113
114 task wb_rd_mult( 32 bit address, 4 bit byte select, integer delay,
115         integer count);
116
117 - Simular to wb_rd4, except it pwrforms "count" number of read cycles.
118   The data is read in to the internal rd_buf[] memory.
119 - Strobe is deasserted between reads for 'delay' number of cycles
120   (This simulates wait state insertion ...)
121
122
123 */
124
125
126 //`include "wb_model_defines.v"
127
128 module wb_mast(clk, rst, adr, din, dout, cyc, stb, sel, we, ack, err, rty);
129
130 input           clk, rst;
131 output  [31:0]  adr;
132 input   [31:0]  din;
133 output  [31:0]  dout;
134 output          cyc, stb;
135 output  [3:0]   sel;
136 output          we;
137 input           ack, err, rty;
138
139 ////////////////////////////////////////////////////////////////////
140 //
141 // Local Wires
142 //
143
144 parameter mem_size = 4096;
145
146 reg     [31:0]  adr;
147 reg     [31:0]  dout;
148 reg             cyc, stb;
149 reg     [3:0]   sel;
150 reg             we;
151
152 reg     [31:0]  rd_mem[mem_size:0];
153 reg     [31:0]  wr_mem[mem_size:0];
154 integer         rd_cnt;
155 integer         wr_cnt;
156
157 ////////////////////////////////////////////////////////////////////
158 //
159 // Memory Logic
160 //
161
162 initial
163    begin
164         adr = 32'hxxxx_xxxx;
165         dout = 32'hxxxx_xxxx;
166         cyc = 0;
167         stb = 0;
168         sel = 4'hx;
169         we = 1'hx;
170         rd_cnt = 0;
171         wr_cnt = 0;
172         #1;
173         $display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)\n");
174    end
175
176
177
178 task mem_fill;
179
180 integer n;
181 begin
182 rd_cnt = 0;
183 wr_cnt = 0;
184 for(n=0;n<mem_size;n=n+1)
185    begin
186         rd_mem[n] = $random;
187         wr_mem[n] = $random;
188    end
189 end
190 endtask
191
192 ////////////////////////////////////////////////////////////////////
193 //
194 // Write 1 Word Task
195 //
196
197 task wb_wr1;
198 input   [31:0]  a;
199 input   [3:0]   s;
200 input   [31:0]  d;
201
202 begin
203
204 @(posedge clk);
205 #1;
206 adr = a;
207 dout = d;
208 cyc = 1;
209 stb = 1;
210 we=1;
211 sel = s;
212
213 @(posedge clk);
214 while(~ack & ~err)      @(posedge clk);
215 #1;
216 cyc=0;
217 stb=0;
218 adr = 32'hxxxx_xxxx;
219 dout = 32'hxxxx_xxxx;
220 we = 1'hx;
221 sel = 4'hx;
222
223 end
224 endtask
225
226 ////////////////////////////////////////////////////////////////////
227 //
228 // Write 4 Words Task
229 //
230
231 task wb_wr4;
232 input   [31:0]  a;
233 input   [3:0]   s;
234 input           delay;
235 input   [31:0]  d1;
236 input   [31:0]  d2;
237 input   [31:0]  d3;
238 input   [31:0]  d4;
239
240 integer         delay;
241
242 begin
243
244 @(posedge clk);
245 #1;
246 cyc = 1;
247 sel = s;
248
249 repeat(delay)
250    begin
251         @(posedge clk);
252         #1;
253    end
254 adr = a;
255 dout = d1;
256 stb = 1;
257 we=1;
258 while(~ack & ~err)      @(posedge clk);
259 #2;
260 stb=0;
261 we=1'bx;
262 dout = 32'hxxxx_xxxx;
263 adr = 32'hxxxx_xxxx;
264
265 repeat(delay)
266    begin
267         @(posedge clk);
268         #1;
269    end
270 stb=1;
271 adr = a+4;
272 dout = d2;
273 we=1;
274 @(posedge clk);
275 while(~ack & ~err)      @(posedge clk);
276 #2;
277 stb=0;
278 we=1'bx;
279 dout = 32'hxxxx_xxxx;
280 adr = 32'hxxxx_xxxx;
281
282 repeat(delay)
283    begin
284         @(posedge clk);
285         #1;
286    end
287 stb=1;
288 adr = a+8;
289 dout = d3;
290 we=1;
291 @(posedge clk);
292 while(~ack & ~err)      @(posedge clk);
293 #2;
294 stb=0;
295 we=1'bx;
296 dout = 32'hxxxx_xxxx;
297 adr = 32'hxxxx_xxxx;
298
299 repeat(delay)
300    begin
301         @(posedge clk);
302         #1;
303    end
304 stb=1;
305 adr = a+12;
306 dout = d4;
307 we=1;
308 @(posedge clk);
309 while(~ack & ~err)      @(posedge clk);
310 #1;
311 stb=0;
312 cyc=0;
313
314 adr = 32'hxxxx_xxxx;
315 dout = 32'hxxxx_xxxx;
316 we = 1'hx;
317 sel = 4'hx;
318
319 end
320 endtask
321
322
323 task wb_wr_mult;
324 input   [31:0]  a;
325 input   [3:0]   s;
326 input           delay;
327 input           count;
328
329 integer         delay;
330 integer         count;
331 integer         n;
332
333 begin
334
335 @(posedge clk);
336 #1;
337 cyc = 1;
338
339 for(n=0;n<count;n=n+1)
340    begin
341         repeat(delay)
342            begin
343                 @(posedge clk);
344                 #1;
345            end
346         adr = a + (n*4);
347         dout = wr_mem[n + wr_cnt];
348         stb = 1;
349         we=1;
350         sel = s;
351         if(n!=0)        @(posedge clk);
352         while(~ack & ~err)      @(posedge clk);
353         #2;
354         stb=0;
355         we=1'bx;
356         sel = 4'hx;
357         dout = 32'hxxxx_xxxx;
358         adr = 32'hxxxx_xxxx;
359    end
360
361 cyc=0;
362 adr = 32'hxxxx_xxxx;
363
364 wr_cnt = wr_cnt + count;
365 end
366 endtask
367
368
369 task wb_rmw;
370 input   [31:0]  a;
371 input   [3:0]   s;
372 input           delay;
373 input           rcount;
374 input           wcount;
375
376 integer         delay;
377 integer         rcount;
378 integer         wcount;
379 integer         n;
380
381 begin
382
383 @(posedge clk);
384 #1;
385 cyc = 1;
386 we = 0;
387 sel = s;
388 repeat(delay)   @(posedge clk);
389
390 for(n=0;n<rcount-1;n=n+1)
391    begin
392         adr = a + (n*4);
393         stb = 1;
394         while(~ack & ~err)      @(posedge clk);
395         rd_mem[n + rd_cnt] = din;
396         //$display("Rd Mem[%0d]: %h", (n + rd_cnt), rd_mem[n + rd_cnt] );
397         #2;
398         stb=0;
399         we = 1'hx;
400         sel = 4'hx;
401         adr = 32'hxxxx_xxxx;
402         repeat(delay)
403            begin
404                 @(posedge clk);
405                 #1;
406            end
407         we = 0;
408         sel = s;
409    end
410
411 adr = a+(n*4);
412 stb = 1;
413 @(posedge clk);
414 while(~ack & ~err)      @(posedge clk);
415 rd_mem[n + rd_cnt] = din;
416 //$display("Rd Mem[%0d]: %h", (n + rd_cnt), rd_mem[n + rd_cnt] );
417 #1;
418 stb=0;
419 we = 1'hx;
420 sel = 4'hx;
421 adr = 32'hxxxx_xxxx;
422
423 rd_cnt = rd_cnt + rcount;
424
425 for(n=0;n<wcount;n=n+1)
426    begin
427         repeat(delay)
428            begin
429                 @(posedge clk);
430                 #1;
431            end
432         adr = a + (n*4);
433         dout = wr_mem[n + wr_cnt];
434         stb = 1;
435         we=1;
436         sel = s;
437 //      if(n!=0)
438                 @(posedge clk);
439         while(~ack & ~err)      @(posedge clk);
440         #2;
441         stb=0;
442         we=1'bx;
443         sel = 4'hx;
444         dout = 32'hxxxx_xxxx;
445         adr = 32'hxxxx_xxxx;
446    end
447
448 cyc=0;
449 adr = 32'hxxxx_xxxx;
450
451 wr_cnt = wr_cnt + wcount;
452 end
453 endtask
454
455
456
457 ////////////////////////////////////////////////////////////////////
458 //
459 // Read 1 Word Task
460 //
461
462 task wb_rd1;
463 input   [31:0]  a;
464 input   [3:0]   s;
465 output  [31:0]  d;
466
467 begin
468
469 @(posedge clk);
470 #1;
471 adr = a;
472 cyc = 1;
473 stb = 1;
474 we  = 0;
475 sel = s;
476
477 while(~ack & ~err)      @(posedge clk);
478 d = din;
479 #1;
480 cyc=0;
481 stb=0;
482 adr = 32'hxxxx_xxxx;
483 dout = 32'hxxxx_xxxx;
484 we = 1'hx;
485 sel = 4'hx;
486
487 end
488 endtask
489
490
491 ////////////////////////////////////////////////////////////////////
492 //
493 // Read 4 Words Task
494 //
495
496
497 task wb_rd4;
498 input   [31:0]  a;
499 input   [3:0]   s;
500 input           delay;
501 output  [31:0]  d1;
502 output  [31:0]  d2;
503 output  [31:0]  d3;
504 output  [31:0]  d4;
505
506 integer         delay;
507 begin
508
509 @(posedge clk);
510 #1;
511 cyc = 1;
512 we = 0;
513 sel = s;
514 repeat(delay)   @(posedge clk);
515
516 adr = a;
517 stb = 1;
518 while(~ack & ~err)      @(posedge clk);
519 d1 = din;
520 #2;
521 stb=0;
522 we = 1'hx;
523 sel = 4'hx;
524 adr = 32'hxxxx_xxxx;
525 repeat(delay)
526    begin
527         @(posedge clk);
528         #1;
529    end
530 we = 0;
531 sel = s;
532
533 adr = a+4;
534 stb = 1;
535 @(posedge clk);
536 while(~ack & ~err)      @(posedge clk);
537 d2 = din;
538 #2;
539 stb=0;
540 we = 1'hx;
541 sel = 4'hx;
542 adr = 32'hxxxx_xxxx;
543 repeat(delay)
544    begin
545         @(posedge clk);
546         #1;
547    end
548 we = 0;
549 sel = s;
550
551
552 adr = a+8;
553 stb = 1;
554 @(posedge clk);
555 while(~ack & ~err)      @(posedge clk);
556 d3 = din;
557 #2;
558 stb=0;
559 we = 1'hx;
560 sel = 4'hx;
561 adr = 32'hxxxx_xxxx;
562 repeat(delay)
563    begin
564         @(posedge clk);
565         #1;
566    end
567 we = 0;
568 sel = s;
569
570 adr = a+12;
571 stb = 1;
572 @(posedge clk);
573 while(~ack & ~err)      @(posedge clk);
574 d4 = din;
575 #1;
576 stb=0;
577 cyc=0;
578 we = 1'hx;
579 sel = 4'hx;
580 adr = 32'hxxxx_xxxx;
581 end
582 endtask
583
584
585 task wb_rd_mult;
586 input   [31:0]  a;
587 input   [3:0]   s;
588 input           delay;
589 input           count;
590
591 integer         delay;
592 integer         count;
593 integer         n;
594
595 begin
596
597 @(posedge clk);
598 #1;
599 cyc = 1;
600 we = 0;
601 sel = s;
602 repeat(delay)   @(posedge clk);
603
604 for(n=0;n<count-1;n=n+1)
605    begin
606         adr = a + (n*4);
607         stb = 1;
608         while(~ack & ~err)      @(posedge clk);
609         rd_mem[n + rd_cnt] = din;
610         #2;
611         stb=0;
612         we = 1'hx;
613         sel = 4'hx;
614         adr = 32'hxxxx_xxxx;
615         repeat(delay)
616            begin
617                 @(posedge clk);
618                 #1;
619            end
620         we = 0;
621         sel = s;
622    end
623
624 adr = a+(n*4);
625 stb = 1;
626 @(posedge clk);
627 while(~ack & ~err)      @(posedge clk);
628 rd_mem[n + rd_cnt] = din;
629 #1;
630 stb=0;
631 cyc=0;
632 we = 1'hx;
633 sel = 4'hx;
634 adr = 32'hxxxx_xxxx;
635
636 rd_cnt = rd_cnt + count;
637 end
638 endtask
639
640 endmodule