source: PlatformSupport/Deprecated/pcores/radio_controller_v1_07_a/hdl/verilog/spi_top.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.4 KB
Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  spi_top.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_top.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_top
50(
51  // OPB signals
52  opb_clk_i, opb_rst_i,
53 
54  // SPI registers
55  reg_ctrl, reg_ss, reg_divider, reg_tx, ctrlwrite, busval, go,
56
57  // SPI signals
58  ss_pad_o, sclk_pad_o, mosi_pad_o
59);
60
61  parameter Tp = 1;
62
63
64
65  // OPB signals
66  input                            opb_clk_i;         // master clock input
67  input                            opb_rst_i;         // synchronous active high reset
68 
69  // SPI registers
70  input         [13:0]     reg_ctrl;
71  input         [7:0]      reg_ss;
72  input                reg_divider;
73  input         [17:0]     reg_tx;
74  input                ctrlwrite;
75  input                busval;
76  output               go;
77 
78  // SPI signals                                     
79  output          [`SPI_SS_NB-1:0] ss_pad_o;         // slave select
80  output                           sclk_pad_o;       // serial clock
81  output                           mosi_pad_o;       // master out slave in
82                                                     
83  // Internal signals
84 
85  wire         [`SPI_MAX_CHAR-1:0] rx;               // Rx register
86  wire                             rx_negedge;       // miso is sampled on negative edge
87  wire                             tx_negedge;       // mosi is driven on negative edge
88  wire    [`SPI_CHAR_LEN_BITS-1:0] char_len;         // char len
89  //wire                             go;               // go
90  wire                             lsb;              // lsb first on line
91  wire                             ie;               // interrupt enable
92  wire                             ass;              // automatic slave select
93  wire                             spi_divider_sel;  // divider register select
94  wire                             spi_ctrl_sel;     // ctrl register select
95  wire                       [3:0] spi_tx_sel;       // tx_l register select
96  wire                             spi_ss_sel;       // ss register select
97  wire                             tip;              // transfer in progress
98  wire                             pos_edge;         // recognize posedge of sclk
99  wire                             neg_edge;         // recognize negedge of sclk
100  wire                             last_bit;         // marks last character bit
101  reg                  ctrlbitgo;
102 
103 
104  assign rx_negedge = reg_ctrl[`SPI_CTRL_RX_NEGEDGE];
105  assign tx_negedge = reg_ctrl[`SPI_CTRL_TX_NEGEDGE];
106  assign go         = ctrlbitgo;
107  assign char_len   = reg_ctrl[`SPI_CTRL_CHAR_LEN];
108  assign lsb        = reg_ctrl[`SPI_CTRL_LSB];
109  assign ie         = reg_ctrl[`SPI_CTRL_IE];
110  assign ass        = reg_ctrl[`SPI_CTRL_ASS];
111 
112  always @(posedge opb_clk_i or posedge opb_rst_i)
113  begin
114    if (opb_rst_i)
115        ctrlbitgo <= #Tp 1'b0;
116    else if(ctrlwrite && !tip)
117        ctrlbitgo <= #Tp busval;
118    else if(tip && last_bit && pos_edge)
119        ctrlbitgo <= #Tp 1'b0;
120  end
121 
122  assign ss_pad_o = ~((reg_ss & {`SPI_SS_NB{tip & ass}}) | (reg_ss & {`SPI_SS_NB{!ass}}));
123 
124  spi_clgen clgen (.clk_in(opb_clk_i), .rst(opb_rst_i), .go(go), .enable(tip), .last_clk(last_bit),
125                   .divider(reg_divider), .clk_out(sclk_pad_o), .pos_edge(pos_edge), 
126                   .neg_edge(neg_edge));
127 
128  spi_shift shift (.clk(opb_clk_i), .rst(opb_rst_i), .len(char_len[`SPI_CHAR_LEN_BITS-1:0]),
129                   .lsb(lsb), .go(go), .pos_edge(pos_edge), .neg_edge(neg_edge), 
130                   .rx_negedge(rx_negedge), .tx_negedge(tx_negedge),
131                   .tip(tip), .last(last_bit), 
132                   .p_in(reg_tx), .p_out(rx), 
133                   .s_clk(sclk_pad_o), .s_out(mosi_pad_o));
134endmodule
135 
Note: See TracBrowser for help on using the repository browser.