source: PlatformSupport/CustomPeripherals/pcores/radio_controller_v1_22_a/hdl/verilog/spi_top.v

Last change on this file was 889, checked in by murphpo, 16 years ago

adding PLB46 version of radio controller

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