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

Subversion Repositories i2c

[/] [i2c/] [trunk/] [bench/] [verilog/] [tst_bench_top.v] - Blame information for rev 49

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

Line No. Rev Author Line
1 19 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  WISHBONE rev.B2 compliant I2C Master controller Testbench  ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Richard Herveille                                  ////
7
////          richard@asics.ws                                   ////
8
////          www.asics.ws                                       ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/projects/i2c/    ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2001 Richard Herveille                        ////
15
////                    richard@asics.ws                         ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39 10 rherveille
//
40 49 rherveille
//  $Id: tst_bench_top.v,v 1.5 2004-02-28 15:32:55 rherveille Exp $
41 10 rherveille
//
42 49 rherveille
//  $Date: 2004-02-28 15:32:55 $
43
//  $Revision: 1.5 $
44 19 rherveille
//  $Author: rherveille $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50 45 rherveille
//
51 10 rherveille
 
52
`include "timescale.v"
53
 
54
module tst_bench_top();
55
 
56
        //
57
        // wires && regs
58
        //
59
        reg  clk;
60
        reg  rstn;
61
 
62
        wire [31:0] adr;
63
        wire [ 7:0] dat_i, dat_o;
64
        wire we;
65
        wire stb;
66
        wire cyc;
67
        wire ack;
68
        wire inta;
69
 
70 49 rherveille
        reg [1:0] cpol, cpha;
71
        reg [2:0] e;
72 10 rherveille
 
73 49 rherveille
        wire sck, mosi, miso;
74
        reg [7:0] q;
75 10 rherveille
 
76 49 rherveille
        parameter SPCR = 2'b00;
77
        parameter SPSR = 2'b01;
78
        parameter SPDR = 2'b10;
79
        parameter SPER = 2'b11;
80 10 rherveille
 
81
        //
82
        // Module body
83
        //
84 49 rherveille
        integer n;
85 10 rherveille
 
86
        // generate clock
87
        always #5 clk = ~clk;
88
 
89
        // hookup wishbone master model
90 19 rherveille
        wb_master_model #(8, 32) u0 (
91 49 rherveille
                .clk (clk),
92
                .rst (rstn),
93
                .adr (adr),
94
                .din (dat_i),
95 10 rherveille
                .dout(dat_o),
96 49 rherveille
                .cyc (cyc),
97
                .stb (stb),
98
                .we  (we),
99
                .sel (),
100
                .ack (ack),
101
                .err (1'b0),
102
                .rty (1'b0)
103 10 rherveille
        );
104
 
105 49 rherveille
        // hookup spi core
106
        simple_spi_top spi_top (
107 10 rherveille
                // wishbone interface
108 49 rherveille
                .clk_i (clk),
109
                .rst_i (rstn),
110
                .cyc_i (cyc),
111
                .stb_i (stb),
112
                .adr_i (adr[1:0]),
113
                .we_i  (we),
114
                .dat_i (dat_o),
115
                .dat_o (dat_i),
116
                .ack_o (ack),
117
                .inta_o(inta),
118 10 rherveille
 
119 49 rherveille
                .sck_o (sck),
120
                .mosi_o(mosi),
121
                .miso_i(miso)
122 10 rherveille
        );
123
 
124 49 rherveille
        // hookup spi slave model
125
        spi_slave_model spi_slave (
126
                .csn(1'b0),
127
                .sck(sck),
128
                .di(mosi),
129
                .do(miso)
130 10 rherveille
        );
131
 
132
        initial
133 25 rherveille
          begin
134
              `ifdef WAVES
135
                 $shm_open("waves");
136
                 $shm_probe("AS",tst_bench_top,"AS");
137
                 $display("INFO: Signal dump enabled ...\n\n");
138
              `endif
139 19 rherveille
 
140 49 rherveille
//            force spi_slave.debug = 1'b1; // enable spi_slave debug information
141
              force spi_slave.debug = 1'b0; // disable spi_slave debug information
142 19 rherveille
 
143 25 rherveille
              $display("\nstatus: %t Testbench started\n\n", $time);
144 19 rherveille
 
145 10 rherveille
 
146 25 rherveille
              // initially values
147
              clk = 0;
148 19 rherveille
 
149 25 rherveille
              // reset system
150
              rstn = 1'b1; // negate reset
151
              #2;
152
              rstn = 1'b0; // assert reset
153 45 rherveille
              repeat(1) @(posedge clk);
154 25 rherveille
              rstn = 1'b1; // negate reset
155 10 rherveille
 
156 25 rherveille
              $display("status: %t done reset", $time);
157 10 rherveille
 
158 25 rherveille
              @(posedge clk);
159 10 rherveille
 
160 25 rherveille
              //
161
              // program core
162
              //
163 49 rherveille
              for (cpol=0; cpol<=1; cpol=cpol+1)
164
              for (cpha=0; cpha<=1; cpha=cpha+1)
165
              for (e=0; e<=3; e=e+1)
166
              begin
167
                  //set cpol/cpha in spi slave model
168
                  force spi_slave.cpol=cpol[0];
169
                  force spi_slave.cpha=cpha[0];
170
                  $display("cpol:%b, cpha:%b, e:%b", cpol[0],cpha[0],e[1:0]);
171 19 rherveille
 
172 49 rherveille
                  // program internal registers
173 19 rherveille
 
174 49 rherveille
                  // load control register
175
                  u0.wb_write(1, SPCR, {4'b0101,cpol[0],cpha[0],e[1:0]} );
176
                  //verify control register
177
                  u0.wb_cmp  (0, SPCR, {4'b0101,cpol[0],cpha[0],e[1:0]} );
178 19 rherveille
 
179 49 rherveille
 
180
                  // load extended control register
181
                  u0.wb_write(1,SPER,8'h0);
182
                  //verify extended control register
183
                  u0.wb_cmp (0,SPER,8'h0);
184 10 rherveille
 
185 49 rherveille
                  //fill memory
186
                  for(n=0;n<8;n=n+1) begin
187
                    u0.wb_write(1,SPDR,{cpol[0],cpha[0],e[1:0],n[3:0]});
188
                    //wait for transfer to finish
189
                    u0.wb_read(1,SPSR,q);
190
                    while(~q[7]) u0.wb_read(1,SPSR,q);
191
                    //clear 'spif' bit
192
                    u0.wb_write(1,SPSR,8'h80);
193
                  end
194 19 rherveille
 
195 49 rherveille
                  //verify memory
196
                  for(n=0;n<8;n=n+1) begin
197
                    u0.wb_write(1,SPDR,~n);
198
                    //wait for transfer to finish
199
                    u0.wb_read(1,SPSR,q);
200
                    while(~q[7]) u0.wb_read(1,SPSR,q);
201
                    //clear 'spif' bit
202
                    u0.wb_write(1,SPSR,8'h80);
203
                    //verify memory content
204
                    u0.wb_cmp(0,SPDR,{cpol[0],cpha[0],e[1:0],n[3:0]});
205
                  end
206
              end
207 10 rherveille
 
208 25 rherveille
              // check tip bit
209 49 rherveille
//            u0.wb_read(1, SR, q);
210
//            while(q[1])
211
//            u0.wb_read(1, SR, q); // poll it until it is zero
212
//            $display("status: %t tip==0", $time);
213 10 rherveille
 
214 45 rherveille
              #250000; // wait 250us
215 25 rherveille
              $display("\n\nstatus: %t Testbench done", $time);
216
              $finish;
217
          end
218 19 rherveille
 
219 10 rherveille
endmodule
220
 

powered by: WebSVN 2.1.0

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