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

Subversion Repositories spi_core_dsp_s3ean_kits

[/] [spi_core_dsp_s3ean_kits/] [trunk/] [rtl/] [verilog/] [spi_shift_in.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 williamgib
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  spi_shift.v                                                 ////
4
////                                                              ////
5
////  This file is part of the SPI IP core project                ////
6
////  http://www.opencores.org/projects/spi/                      ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Simon Srot (simons@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2002 Authors                                   ////
17
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
 
41
`include "spi_defines.v"
42
`include "timescale.v"
43
 
44
module spi_shift_in (clk, rst, go,
45
                  pos_edge, neg_edge, rx_negedge,
46
                  tip, last, p_out, s_clk, s_in);
47
 
48
        parameter Tp = 1;
49
 
50
        input                          clk;          // system clock
51
        input                          rst;          // reset
52
//      input [`SPI_ADC_CHAR_LEN_BITS-1:0] len;          // data len in bits (minus one)
53
        input                          go;           // start stansfer
54
        input                          pos_edge;     // recognize posedge of sclk
55
        input                          neg_edge;     // recognize negedge of sclk
56
        input                          rx_negedge;   // s_in is sampled on negative edge 
57
        output                         tip;          // transfer in progress
58
        output                         last;         // last bit
59
        output     [`SPI_ADC_CHAR-1:0] p_out;        // parallel out
60
        input                                           s_clk;                  // serial clk
61
        input                          s_in;         // serial in
62
 
63
        reg                            tip;
64
 
65
        reg     [`SPI_ADC_CHAR_LEN_BITS:0] cnt;          // data bit count
66
        reg        [`SPI_ADC_CHAR-1:0] data;         // shift register
67
        wire    [`SPI_ADC_CHAR_LEN_BITS:0] rx_bit_pos;   // next bit position
68
        wire                           rx_clk;       // rx clock enable
69
        wire [`SPI_ADC_CHAR_LEN_BITS-1:0] len;          // data len in bits (minus one)
70
 
71
        assign len = 'h20; //Fix LEN since that won't be changing, unless you only want to sample one channel
72
        assign p_out = data;
73
 
74
        //LSB last
75
        assign rx_bit_pos =     (rx_negedge ? cnt : cnt - {{`SPI_ADC_CHAR_LEN_BITS{1'b0}},1'b1});
76
 
77
        assign last = !(|cnt);
78
 
79
        assign rx_clk = (rx_negedge ? neg_edge : pos_edge) && (!last || s_clk);
80
 
81
        // Character bit counter
82
        always @(posedge clk or posedge rst)
83
        begin
84
                if(rst)
85
                        cnt <= #Tp {`SPI_ADC_CHAR_LEN_BITS+1{1'b0}};
86
                else
87
                begin
88
                        if(tip)
89
                                cnt <= #Tp pos_edge ? (cnt - {{`SPI_ADC_CHAR_LEN_BITS{1'b0}}, 1'b1}) : cnt;
90
                        else
91
                                cnt <= #Tp !(|len) ? {1'b1, {`SPI_ADC_CHAR_LEN_BITS{1'b0}}} : {1'b0, len};
92
                end
93
        end
94
 
95
        // Transfer in progress
96
        always @(posedge clk or posedge rst)
97
        begin
98
                if(rst)
99
                        tip <= #Tp 1'b0;
100
                else if(go && ~tip)
101
                        tip <= #Tp 1'b1;
102
                else if(tip && last && pos_edge)
103
                        tip <= #Tp 1'b0;
104
        end
105
 
106
        // Receiving bits from the line
107
        always @(posedge clk or posedge rst)
108
        begin
109
                if (rst)
110
                        data   <= #Tp {`SPI_ADC_CHAR{1'b0}};
111
                else if (tip)
112
                        data[rx_bit_pos[`SPI_ADC_CHAR_LEN_BITS-1:0]] <= #Tp rx_clk ? s_in : data[rx_bit_pos[`SPI_ADC_CHAR_LEN_BITS-1:0]];
113
        end
114
 
115
endmodule
116
 

powered by: WebSVN 2.1.0

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