1 /////////////////////////////////////////////////////////////////////
3 //// WISHBONE Master Model ////
6 //// Author: Rudolf Usselmann ////
7 //// rudi@asics.ws ////
9 /////////////////////////////////////////////////////////////////////
11 //// Copyright (C) 2001 Rudolf Usselmann ////
12 //// rudi@asics.ws ////
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.////
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. ////
33 /////////////////////////////////////////////////////////////////////
37 // $Id: wb_mast.v,v 1.1 2001/12/03 21:44:23 gorban Exp $
39 // $Date: 2001/12/03 21:44:23 $
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.
66 - Fills local burst read (rd_buf[]) and write(wr_buf[]) buffers with random values.
69 task wb_wr1( 32 bit address, 4 bit byte select, 32 bit write data);
71 - Performs a single WISHBONE write
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);
77 - Performs 4 consecutive WISHBONE writes
78 - Strobe is deasserted between writes for 'delay' number of cycles
79 (This simulates wait state insertion ...)
82 task wb_wr_mult( 32 bit address, 4 bit byte select, integer delay,
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 ...)
91 task wb_rmw( 32 bit address, 4 bit byte select, integer delay,
92 integer rcount, integer wcount);
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 ...)
101 task wb_rd1( 32 bit address, 4 bit byte select, 32 bit read data);
103 - Performs a single WISHBONE write
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);
109 - Performs 4 consecutive WISHBONE reads
110 - Strobe is deasserted between reads for 'delay' number of cycles
111 (This simulates wait state insertion ...)
114 task wb_rd_mult( 32 bit address, 4 bit byte select, integer delay,
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 ...)
126 //`include "wb_model_defines.v"
128 module wb_mast(clk, rst, adr, din, dout, cyc, stb, sel, we, ack, err, rty);
139 ////////////////////////////////////////////////////////////////////
144 parameter mem_size = 4096;
152 reg [31:0] rd_mem[mem_size:0];
153 reg [31:0] wr_mem[mem_size:0];
157 ////////////////////////////////////////////////////////////////////
165 dout = 32'hxxxx_xxxx;
173 $display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)\n");
184 for(n=0;n<mem_size;n=n+1)
192 ////////////////////////////////////////////////////////////////////
214 while(~ack & ~err) @(posedge clk);
219 dout = 32'hxxxx_xxxx;
226 ////////////////////////////////////////////////////////////////////
228 // Write 4 Words Task
258 while(~ack & ~err) @(posedge clk);
262 dout = 32'hxxxx_xxxx;
275 while(~ack & ~err) @(posedge clk);
279 dout = 32'hxxxx_xxxx;
292 while(~ack & ~err) @(posedge clk);
296 dout = 32'hxxxx_xxxx;
309 while(~ack & ~err) @(posedge clk);
315 dout = 32'hxxxx_xxxx;
339 for(n=0;n<count;n=n+1)
347 dout = wr_mem[n + wr_cnt];
351 if(n!=0) @(posedge clk);
352 while(~ack & ~err) @(posedge clk);
357 dout = 32'hxxxx_xxxx;
364 wr_cnt = wr_cnt + count;
388 repeat(delay) @(posedge clk);
390 for(n=0;n<rcount-1;n=n+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] );
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] );
423 rd_cnt = rd_cnt + rcount;
425 for(n=0;n<wcount;n=n+1)
433 dout = wr_mem[n + wr_cnt];
439 while(~ack & ~err) @(posedge clk);
444 dout = 32'hxxxx_xxxx;
451 wr_cnt = wr_cnt + wcount;
457 ////////////////////////////////////////////////////////////////////
477 while(~ack & ~err) @(posedge clk);
483 dout = 32'hxxxx_xxxx;
491 ////////////////////////////////////////////////////////////////////
514 repeat(delay) @(posedge clk);
518 while(~ack & ~err) @(posedge clk);
536 while(~ack & ~err) @(posedge clk);
555 while(~ack & ~err) @(posedge clk);
573 while(~ack & ~err) @(posedge clk);
602 repeat(delay) @(posedge clk);
604 for(n=0;n<count-1;n=n+1)
608 while(~ack & ~err) @(posedge clk);
609 rd_mem[n + rd_cnt] = din;
627 while(~ack & ~err) @(posedge clk);
628 rd_mem[n + rd_cnt] = din;
636 rd_cnt = rd_cnt + count;