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_out.v] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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