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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gleichmann/] [sim/] [spi_slave_model.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
`timescale 1ns / 10ps
2
 
3
/////////////////////////////////////////////////////////////////////
4
////                                                             ////
5
////  SPI Slave Model                                            ////
6
////                                                             ////
7
////  Authors: Richard Herveille (richard@asics.ws) www.asics.ws ////
8
////                                                             ////
9
////  http://www.opencores.org/projects/simple_spi/              ////
10
////                                                             ////
11
/////////////////////////////////////////////////////////////////////
12
////                                                             ////
13
//// Copyright (C) 2004 Richard Herveille                        ////
14
////                         richard@asics.ws                    ////
15
////                                                             ////
16
//// This source file may be used and distributed without        ////
17
//// restriction provided that this copyright statement is not   ////
18
//// removed from the file and that any derivative work contains ////
19
//// the original copyright notice and the associated disclaimer.////
20
////                                                             ////
21
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
22
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
23
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
24
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
25
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
26
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
27
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
28
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
29
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
30
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
31
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
32
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
33
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
34
////                                                             ////
35
/////////////////////////////////////////////////////////////////////
36
 
37
//  CVS Log
38
//
39
//  $Id: spi_slave_model.v,v 1.2 2006/11/20 17:22:05 tame Exp $
40
//
41
//  $Date: 2006/11/20 17:22:05 $
42
//  $Revision: 1.2 $
43
//  $Author: tame $
44
//  $Locker:  $
45
//  $State: Exp $
46
//
47
// Change History:
48
//               $Log: spi_slave_model.v,v $
49
//               Revision 1.2  2006/11/20 17:22:05  tame
50
//               Added seperate read address so that valid data from previousl write address is sent
51
//               automatically.
52
//
53
//               Revision 1.1  2006/11/14 16:34:07  tame
54
//               Added testbench. Simulation running.
55
//
56
//               Revision 1.1  2006/11/10 14:47:52  chu
57
//               initial definition
58
//
59
//               Revision 1.1  2004/02/28 16:01:47  rherveille
60
//               Initial testbench release added
61
//
62
//
63
//
64
//
65
 
66
 
67
// Requires: Verilog2001
68
 
69
// `include "timescale.v"
70
 
71
module spi_slave_model (
72
        input  wire csn,
73
        input  wire sck,
74
        input  wire di,
75
        output wire do
76
);
77
 
78
        //
79
        // Variable declaration
80
        //
81
        wire debug = 1'b1;
82
 
83
        wire cpol = 1'b0;
84
        wire cpha  = 1'b0;
85
 
86
        reg [7:0] mem [7:0]; // initiate memory
87
        reg [2:0] mem_adr;   // memory address
88
        reg [7:0] mem_do;    // memory data output
89
 
90
        reg [7:0] sri, sro;  // 8bit shift register
91
 
92
        reg [2:0] bit_cnt;
93
        reg       ld;
94
 
95
        wire clk;
96
 
97
    // slave shall automatically send what has been
98
    // written previously
99
    wire [2:0] mem_adr_read;
100
    assign mem_adr_read = mem_adr - 1;
101
 
102
        integer ID=99;
103
 
104
        // module body
105
        //
106
 
107
        assign clk = cpol ^ cpha ^ sck;
108
 
109
        // generate shift registers
110
        always @(posedge clk)
111
          sri <= #1 {sri[6:0],di};
112
 
113
        always @(posedge clk)
114
          if (&bit_cnt)
115
                    sro <= #1 mem[mem_adr_read];
116
          else
117
            sro <= #1 {sro[6:0],1'bx};
118
 
119
        assign do = csn==0 ? sro[7] : 1'bz;
120
 
121
        //generate bit-counter
122
        always @(posedge clk, posedge csn)
123
          if(csn)
124
            bit_cnt <= #1 3'b111;
125
          else
126
            bit_cnt <= #1 bit_cnt - 3'h1;
127
 
128
        //generate access done signal
129
        always @(posedge clk)
130
          ld <= #1 ~(|bit_cnt);
131
 
132
        always @(negedge clk)
133
          if (ld) begin
134
            mem[mem_adr] <= #1 sri;
135
            mem_adr      <= #1 mem_adr + 1'b1;
136
                if (debug==1)
137
                                $display("slave: received %8b", sri);
138
          end
139
 
140
        initial
141
        begin
142
          bit_cnt=3'b111;
143
          mem_adr = 0;
144
          sro = mem[mem_adr_read];
145
        end
146
        always @(negedge csn)
147
                        if (csn==1'b0) $display("slave: my ID is %2d", ID);
148
 
149
endmodule
150
 
151
 

powered by: WebSVN 2.1.0

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