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

Subversion Repositories simple_spi

[/] [simple_spi/] [trunk/] [bench/] [verilog/] [tst_bench_top.v] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  simple_spi ('HC11 compatible) testbench                    ////
4
////                                                             ////
5
////  Author: Richard Herveille                                  ////
6
////          richard@asics.ws                                   ////
7
////          www.asics.ws                                       ////
8
////                                                             ////
9
////////////////////////////////////////////////////////////////////
10
////                                                             ////
11
//// Copyright (C) 2004 Richard Herveille                        ////
12
////                    richard@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: tst_bench_top.v,v 1.1 2004-02-28 16:01:47 rherveille Exp $
38
//
39
//  $Date: 2004-02-28 16:01:47 $
40
//  $Revision: 1.1 $
41
//  $Author: rherveille $
42
//  $Locker:  $
43
//  $State: Exp $
44
//
45
// Change History:
46
//               $Log: not supported by cvs2svn $
47
//
48
//
49
 
50
`include "timescale.v"
51
 
52
module tst_bench_top();
53
 
54
        //
55
        // wires && regs
56
        //
57
        reg  clk;
58
        reg  rstn;
59
 
60
        wire [31:0] adr;
61
        wire [ 7:0] dat_i, dat_o;
62
        wire we;
63
        wire stb;
64
        wire cyc;
65
        wire ack;
66
        wire inta;
67
 
68
        reg [1:0] cpol, cpha;
69
        reg [2:0] e;
70
 
71
        wire sck, mosi, miso;
72
        reg [7:0] q;
73
 
74
        parameter SPCR = 2'b00;
75
        parameter SPSR = 2'b01;
76
        parameter SPDR = 2'b10;
77
        parameter SPER = 2'b11;
78
 
79
        //
80
        // Module body
81
        //
82
        integer n;
83
 
84
        // generate clock
85
        always #5 clk = ~clk;
86
 
87
        // hookup wishbone master model
88
        wb_master_model #(8, 32) u0 (
89
                .clk (clk),
90
                .rst (rstn),
91
                .adr (adr),
92
                .din (dat_i),
93
                .dout(dat_o),
94
                .cyc (cyc),
95
                .stb (stb),
96
                .we  (we),
97
                .sel (),
98
                .ack (ack),
99
                .err (1'b0),
100
                .rty (1'b0)
101
        );
102
 
103
        // hookup spi core
104
        simple_spi_top spi_top (
105
                // wishbone interface
106
                .clk_i (clk),
107
                .rst_i (rstn),
108
                .cyc_i (cyc),
109
                .stb_i (stb),
110
                .adr_i (adr[1:0]),
111
                .we_i  (we),
112
                .dat_i (dat_o),
113
                .dat_o (dat_i),
114
                .ack_o (ack),
115
                .inta_o(inta),
116
 
117
                .sck_o (sck),
118
                .mosi_o(mosi),
119
                .miso_i(miso)
120
        );
121
 
122
        // hookup spi slave model
123
        spi_slave_model spi_slave (
124
                .csn(1'b0),
125
                .sck(sck),
126
                .di(mosi),
127
                .do(miso)
128
        );
129
 
130
        initial
131
          begin
132
              `ifdef WAVES
133
                 $shm_open("waves");
134
                 $shm_probe("AS",tst_bench_top,"AS");
135
                 $display("INFO: Signal dump enabled ...\n\n");
136
              `endif
137
 
138
//            force spi_slave.debug = 1'b1; // enable spi_slave debug information
139
              force spi_slave.debug = 1'b0; // disable spi_slave debug information
140
 
141
              $display("\nstatus: %t Testbench started\n\n", $time);
142
 
143
 
144
              // initially values
145
              clk = 0;
146
 
147
              // reset system
148
              rstn = 1'b1; // negate reset
149
              #2;
150
              rstn = 1'b0; // assert reset
151
              repeat(1) @(posedge clk);
152
              rstn = 1'b1; // negate reset
153
 
154
              $display("status: %t done reset", $time);
155
 
156
              @(posedge clk);
157
 
158
              //
159
              // program core
160
              //
161
              for (cpol=0; cpol<=1; cpol=cpol+1)
162
              for (cpha=0; cpha<=1; cpha=cpha+1)
163
              for (e=0; e<=3; e=e+1)
164
              begin
165
                  //set cpol/cpha in spi slave model
166
                  force spi_slave.cpol=cpol[0];
167
                  force spi_slave.cpha=cpha[0];
168
                  $display("cpol:%b, cpha:%b, e:%b", cpol[0],cpha[0],e[1:0]);
169
 
170
                  // program internal registers
171
 
172
                  // load control register
173
                  u0.wb_write(1, SPCR, {4'b0101,cpol[0],cpha[0],e[1:0]} );
174
                  //verify control register
175
                  u0.wb_cmp  (0, SPCR, {4'b0101,cpol[0],cpha[0],e[1:0]} );
176
 
177
 
178
                  // load extended control register
179
                  u0.wb_write(1,SPER,8'h0);
180
                  //verify extended control register
181
                  u0.wb_cmp (0,SPER,8'h0);
182
 
183
                  //fill memory
184
                  for(n=0;n<8;n=n+1) begin
185
                    u0.wb_write(1,SPDR,{cpol[0],cpha[0],e[1:0],n[3:0]});
186
                    //wait for transfer to finish
187
                    u0.wb_read(1,SPSR,q);
188
                    while(~q[7]) u0.wb_read(1,SPSR,q);
189
                    //clear 'spif' bit
190
                    u0.wb_write(1,SPSR,8'h80);
191
                  end
192
 
193
                  //verify memory
194
                  for(n=0;n<8;n=n+1) begin
195
                    u0.wb_write(1,SPDR,~n);
196
                    //wait for transfer to finish
197
                    u0.wb_read(1,SPSR,q);
198
                    while(~q[7]) u0.wb_read(1,SPSR,q);
199
                    //clear 'spif' bit
200
                    u0.wb_write(1,SPSR,8'h80);
201
                    //verify memory content
202
                    u0.wb_cmp(0,SPDR,{cpol[0],cpha[0],e[1:0],n[3:0]});
203
                  end
204
              end
205
 
206
              // check tip bit
207
//            u0.wb_read(1, SR, q);
208
//            while(q[1])
209
//            u0.wb_read(1, SR, q); // poll it until it is zero
210
//            $display("status: %t tip==0", $time);
211
 
212
              #250000; // wait 250us
213
              $display("\n\nstatus: %t Testbench done", $time);
214
              $finish;
215
          end
216
 
217
endmodule
218
 

powered by: WebSVN 2.1.0

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