source: PlatformSupport/Deprecated/pcores/radio_controller_v1_03_a/hdl/verilog/spi_top.v

Last change on this file was 156, checked in by murphpo, 18 years ago

Updating radio controller from (apparently) newer version on apps3

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