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

Subversion Repositories simple_spi

[/] [simple_spi/] [trunk/] [bench/] [verilog/] [spi_slave_model.v] - Blame information for rev 9

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

Line No. Rev Author Line
1 9 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  SPI Slave Model                                            ////
4
////                                                             ////
5
////  Authors: Richard Herveille (richard@asics.ws) www.asics.ws ////
6
////                                                             ////
7
////  http://www.opencores.org/projects/simple_spi/              ////
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: spi_slave_model.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
 
51
 
52
// Requires: Verilog2001
53
 
54
`include "timescale.v"
55
 
56
module spi_slave_model (
57
        input  wire csn;
58
        input  wire sck
59
        input  wire di;
60
        output wire do
61
);
62
 
63
        //
64
        // Variable declaration
65
        //
66
        wire debug = 1'b1;
67
 
68
        wire cpol = 1'b0;
69
        wire cpha  = 1'b0;
70
 
71
        reg [7:0] mem [7:0]; // initiate memory
72
        reg [2:0] mem_adr;   // memory address
73
        reg [7:0] mem_do;    // memory data output
74
 
75
        reg [7:0] sri, sro;  // 8bit shift register
76
 
77
        reg [2:0] bit_cnt;
78
        reg       ld;
79
 
80
        wire clk;
81
 
82
        //
83
        // module body
84
        //
85
 
86
        assign clk = cpol ^ cpha ^ sck;
87
 
88
        // generate shift registers
89
        always @(posedge clk)
90
          sri <= #1 {sri[6:0],di};
91
 
92
        always @(posedge clk)
93
          if (&bit_cnt)
94
            sro <= #1 mem[mem_adr];
95
          else
96
            sro <= #1 {sro[6:0],1'bx};
97
 
98
        assign do = sro[7];
99
 
100
        //generate bit-counter
101
        always @(posedge clk, posedge csn)
102
          if(csn)
103
            bit_cnt <= #1 3'b111;
104
          else
105
            bit_cnt <= #1 bit_cnt - 3'h1;
106
 
107
        //generate access done signal
108
        always @(posedge clk)
109
          ld <= #1 ~(|bit_cnt);
110
 
111
        always @(negedge clk)
112
          if (ld) begin
113
            mem[mem_adr] <= #1 sri;
114
            mem_adr      <= #1 mem_adr + 1'b1;
115
          end
116
 
117
        initial
118
        begin
119
          bit_cnt=3'b111;
120
          mem_adr = 0;
121
          sro = mem[mem_adr];
122
        end
123
endmodule
124
 
125
 

powered by: WebSVN 2.1.0

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