source: PlatformSupport/Deprecated/pcores/radio_controller_v1_04_a/hdl/verilog/spi_shift.v

Last change on this file was 255, checked in by sgupta, 18 years ago

Added License to all necessary Radio Controller files

File size: 6.2 KB
Line 
1//////////////////////////////////////////////////////////////////////
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//// /* Modifications to spi_shift.v            */
42//// /* Copyright (c) 2006 Rice University      */
43//// /* All Rights Reserved             */
44//// /* This code is covered by the Rice-WARP license   */
45//// /* See http://warp.rice.edu/license/ for details   */
46
47`include "spi_defines.v"
48
49module spi_shift (clk, rst, len, lsb, go,
50                  pos_edge, neg_edge, rx_negedge, tx_negedge,
51                  tip, last, 
52                  p_in, p_out, s_clk, s_out);
53
54  parameter Tp = 1;
55 
56  input                          clk;          // system clock
57  input                          rst;          // reset
58  input [`SPI_CHAR_LEN_BITS-1:0] len;          // data len in bits (minus one)
59  input                          lsb;          // lbs first on the line
60  input                          go;           // start stansfer
61  input                          pos_edge;     // recognize posedge of sclk
62  input                          neg_edge;     // recognize negedge of sclk
63  input                          rx_negedge;   // s_in is sampled on negative edge
64  input                          tx_negedge;   // s_out is driven on negative edge
65  output                         tip;          // transfer in progress
66  output                         last;         // last bit
67  input           /*31*/  [17:0] p_in;         // parallel in
68  output     [`SPI_MAX_CHAR-1:0] p_out;        // parallel out
69  input                          s_clk;        // serial clock
70  output                         s_out;        // serial out
71                                               
72  reg                            s_out;       
73  reg                            tip;
74                             
75  reg     [`SPI_CHAR_LEN_BITS:0] cnt;          // data bit count
76  wire        [`SPI_MAX_CHAR-1:0] data;         // shift register
77  wire    [`SPI_CHAR_LEN_BITS:0] tx_bit_pos;   // next bit position
78  wire    [`SPI_CHAR_LEN_BITS:0] rx_bit_pos;   // next bit position
79  wire                           rx_clk;       // rx clock enable
80  wire                           tx_clk;       // tx clock enable
81 
82  //assign p_out = data;
83  assign data = p_in;
84 
85  assign tx_bit_pos = lsb ? {!(|len), len} - cnt : cnt - {{`SPI_CHAR_LEN_BITS{1'b0}},1'b1};
86  assign rx_bit_pos = lsb ? {!(|len), len} - (rx_negedge ? cnt + {{`SPI_CHAR_LEN_BITS{1'b0}},1'b1} : cnt) : 
87                            (rx_negedge ? cnt : cnt - {{`SPI_CHAR_LEN_BITS{1'b0}},1'b1});
88 
89  assign last = !(|cnt);
90 
91  assign rx_clk = (rx_negedge ? neg_edge : pos_edge) && (!last || s_clk);
92  assign tx_clk = (tx_negedge ? neg_edge : pos_edge) && !last;
93 
94  // Character bit counter
95  always @(posedge clk or posedge rst)
96  begin
97    if(rst)
98      cnt <= #Tp {`SPI_CHAR_LEN_BITS+1{1'b0}};
99    else
100      begin
101        if(tip)
102          cnt <= #Tp pos_edge ? (cnt - {{`SPI_CHAR_LEN_BITS{1'b0}}, 1'b1}) : cnt;
103        else
104          cnt <= #Tp !(|len) ? {1'b1, {`SPI_CHAR_LEN_BITS{1'b0}}} : {1'b0, len};
105      end
106  end
107 
108  // Transfer in progress
109  always @(posedge clk or posedge rst)
110  begin
111    if(rst)
112      tip <= #Tp 1'b0;
113  else if(go && ~tip)
114    tip <= #Tp 1'b1;
115  else if(tip && last && pos_edge)
116    tip <= #Tp 1'b0;
117  end
118 
119  // Sending bits to the line
120  always @(posedge clk or posedge rst)
121  begin
122    if (rst)
123      s_out   <= #Tp 1'b0;
124    else
125      s_out <= #Tp (tx_clk || !tip) ? data[tx_bit_pos[`SPI_CHAR_LEN_BITS-1:0]] : s_out;
126  end
127 
128 
129endmodule
130
Note: See TracBrowser for help on using the repository browser.