OpenCores
URL https://opencores.org/ocsvn/xgate/xgate/trunk

Subversion Repositories xgate

[/] [xgate/] [trunk/] [rtl/] [verilog/] [xgate_wbs_bus.v] - Blame information for rev 96

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Xgate Coprocessor - Slave Bus interface
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/xgate.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// This source file is free software: you can redistribute it and/or modify
14
// it under the terms of the GNU Lesser General Public License as published
15
// by the Free Software Foundation, either version 3 of the License, or
16
// (at your option) any later version.
17
//
18
// Supplemental terms.
19
//     * Redistributions of source code must retain the above copyright
20
//       notice, this list of conditions and the following disclaimer.
21
//     * Neither the name of the <organization> nor the
22
//       names of its contributors may be used to endorse or promote products
23
//       derived from this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
29
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
//
36
// You should have received a copy of the GNU General Public License
37
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
38
////////////////////////////////////////////////////////////////////////////////
39
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
40
 
41
module xgate_wbs_bus #(parameter ARST_LVL = 1'b0,    // asynchronous reset level
42 89 rehayes
                       parameter DWIDTH   = 16,
43
                       parameter WB_RD_DEFAULT = 0,  // WISHBONE Read Bus default state
44
                       parameter SINGLE_CYCLE  = 1'b0)
45 2 rehayes
  (
46
  // Wishbone Signals
47 67 rehayes
  output      [DWIDTH-1:0] wbs_dat_o,     // databus output - Pseudo Register
48 2 rehayes
  output                   wbs_ack_o,     // bus cycle acknowledge output
49 53 rehayes
  output                   wbs_err_o,     // bus error, lost module select durning wait state
50 2 rehayes
  input                    wbs_clk_i,     // master clock input
51
  input                    wbs_rst_i,     // synchronous active high reset
52
  input                    arst_i,        // asynchronous reset
53 67 rehayes
  input             [ 6:1] wbs_adr_i,     // lower address bits
54 2 rehayes
  input                    wbs_we_i,      // write enable input
55
  input                    wbs_stb_i,     // stobe/core select signal
56
  input                    wbs_cyc_i,     // valid bus cycle input
57
  input              [1:0] wbs_sel_i,     // Select byte in word bus transaction
58 5 rehayes
  // XGATE Control Signals
59 2 rehayes
  output reg               write_xgmctl, // Write Strobe for XGMCTL register
60 17 rehayes
  output reg               write_xgchid, // Write Strobe for XGCHID register
61 2 rehayes
  output reg               write_xgisp74,// Write Strobe for XGISP74 register
62
  output reg               write_xgisp30,// Write Strobe for XGISP30 register
63 41 rehayes
  output reg         [1:0] write_xgvbr,  // Write Strobe for XGVBR register
64
  output reg         [1:0] write_xgif_7, // Write Strobe for Interrupt Flag Register 7
65
  output reg         [1:0] write_xgif_6, // Write Strobe for Interrupt Flag Register 6
66
  output reg         [1:0] write_xgif_5, // Write Strobe for Interrupt Flag Register 5
67
  output reg         [1:0] write_xgif_4, // Write Strobe for Interrupt Flag Register 4
68
  output reg         [1:0] write_xgif_3, // Write Strobe for Interrupt Flag Register 3
69
  output reg         [1:0] write_xgif_2, // Write Strobe for Interrupt Flag Register 2
70
  output reg         [1:0] write_xgif_1, // Write Strobe for Interrupt Flag Register 1
71
  output reg         [1:0] write_xgif_0, // Write Strobe for Interrupt Flag Register 0
72 2 rehayes
  output reg               write_xgswt,  // Write Strobe for XGSWT register
73
  output reg               write_xgsem,  // Write Strobe for XGSEM register
74
  output reg               write_xgccr,  // Write Strobe for XGATE Condition Code Register
75 41 rehayes
  output reg         [1:0] write_xgpc,   // Write Strobe for XGATE Program Counter
76
  output reg         [1:0] write_xgr7,   // Write Strobe for XGATE Data Register R7
77
  output reg         [1:0] write_xgr6,   // Write Strobe for XGATE Data Register R6
78
  output reg         [1:0] write_xgr5,   // Write Strobe for XGATE Data Register R5
79
  output reg         [1:0] write_xgr4,   // Write Strobe for XGATE Data Register R4
80
  output reg         [1:0] write_xgr3,   // Write Strobe for XGATE Data Register R3
81
  output reg         [1:0] write_xgr2,   // Write Strobe for XGATE Data Register R2
82
  output reg         [1:0] write_xgr1,   // Write Strobe for XGATE Data Register R1
83 67 rehayes
  output reg         [1:0] write_irw_en_7, // Write Strobe for Interrupt Bypass Control Register 7
84
  output reg         [1:0] write_irw_en_6, // Write Strobe for Interrupt Bypass Control Register 6
85
  output reg         [1:0] write_irw_en_5, // Write Strobe for Interrupt Bypass Control Register 5
86
  output reg         [1:0] write_irw_en_4, // Write Strobe for Interrupt Bypass Control Register 4
87
  output reg         [1:0] write_irw_en_3, // Write Strobe for Interrupt Bypass Control Register 3
88
  output reg         [1:0] write_irw_en_2, // Write Strobe for Interrupt Bypass Control Register 2
89
  output reg         [1:0] write_irw_en_1, // Write Strobe for Interrupt Bypass Control Register 1
90
  output reg         [1:0] write_irw_en_0, // Write Strobe for Interrupt Bypass Control Register 0
91
  output                   async_rst_b,    //
92
  output                   sync_reset,     //
93
  input            [415:0] read_risc_regs, // status register bits for WISHBONE Read bus
94 72 rehayes
  input            [127:1] irq_bypass      // IRQ status bits WISHBONE Read bus
95 2 rehayes
  );
96
 
97
 
98
  // registers
99
  reg                bus_wait_state;  // Holdoff wbs_ack_o for one clock to add wait state
100 89 rehayes
  reg         [5:0]  addr_latch;      // Capture WISHBONE Address
101
 
102 17 rehayes
  reg                write_reserv1;   // Dummy Reg decode for Reserved address
103
  reg                write_reserv2;   // Dummy Reg decode for Reserved address
104 89 rehayes
 
105 67 rehayes
  reg  [DWIDTH-1:0]  read_mux_irq;    // Psudo register for WISHBONE IRQ read data bus mux
106 2 rehayes
 
107
  // Wires
108 57 rehayes
  wire       module_sel;      // This module is selected for bus transaction
109
  wire       wbs_wacc;        // WISHBONE Write Strobe (Clock gating signal)
110
  wire       wbs_racc;        // WISHBONE Read Access (Clock gating signal)
111 67 rehayes
  wire [5:0] address;         // Select either direct or latched address
112 2 rehayes
 
113 89 rehayes
  reg [DWIDTH-1:0] read_mux_risc;  // Pseudo regester for WISHBONE RISC read data bus mux
114
 
115 2 rehayes
  //
116
  // module body
117
  //
118
 
119
  // generate internal resets
120
  assign async_rst_b = arst_i ^ ARST_LVL;
121
  assign sync_reset  = wbs_rst_i;
122
 
123
  // generate wishbone signals
124
  assign module_sel  = wbs_cyc_i && wbs_stb_i;
125
  assign wbs_wacc    = module_sel && wbs_we_i && (wbs_ack_o || SINGLE_CYCLE);
126
  assign wbs_racc    = module_sel && !wbs_we_i;
127 53 rehayes
  assign wbs_ack_o   = SINGLE_CYCLE ? module_sel : (bus_wait_state && module_sel);
128
  assign wbs_err_o   = !SINGLE_CYCLE && !module_sel && bus_wait_state;
129 57 rehayes
  assign address     = SINGLE_CYCLE ? wbs_adr_i : addr_latch;
130 89 rehayes
 
131 67 rehayes
  assign wbs_dat_o   = read_mux_risc | read_mux_irq;
132 2 rehayes
 
133
  // generate acknowledge output signal, By using register all accesses takes two cycles.
134 67 rehayes
  //  Accesses in back to back clock cycles are not possible.
135 2 rehayes
  always @(posedge wbs_clk_i or negedge async_rst_b)
136
    if (!async_rst_b)
137
      bus_wait_state <=  1'b0;
138
    else if (sync_reset)
139
      bus_wait_state <=  1'b0;
140
    else
141
      bus_wait_state <=  module_sel && !bus_wait_state;
142
 
143 57 rehayes
  // Capture address in first cycle of WISHBONE Bus tranaction
144
  //  Only used when Wait states are enabled
145 2 rehayes
  always @(posedge wbs_clk_i)
146 57 rehayes
    if ( module_sel )                  // Clock gate for power saving
147
      addr_latch <= wbs_adr_i;
148 89 rehayes
 
149 67 rehayes
  // WISHBONE Read Data Mux for RISC status and control registers
150 2 rehayes
  always @*
151 67 rehayes
      case ({wbs_racc, address}) // synopsys parallel_case
152 89 rehayes
        // 16 bit Bus, 16 bit Granularity
153
        7'b100_0000: read_mux_risc = read_risc_regs[ 15:  0];
154
        7'b100_0001: read_mux_risc = read_risc_regs[ 31: 16];
155
        7'b100_0010: read_mux_risc = read_risc_regs[ 47: 32];
156
        7'b100_0011: read_mux_risc = read_risc_regs[ 63: 48];
157
        7'b100_0100: read_mux_risc = read_risc_regs[ 79: 64];
158
        7'b100_0101: read_mux_risc = read_risc_regs[ 95: 80];
159
        7'b100_0110: read_mux_risc = read_risc_regs[111: 96];
160
        7'b100_0111: read_mux_risc = read_risc_regs[127:112];
161
        7'b100_1000: read_mux_risc = read_risc_regs[143:128];
162
        7'b100_1001: read_mux_risc = read_risc_regs[159:144];
163
        7'b100_1010: read_mux_risc = read_risc_regs[175:160];
164
        7'b100_1011: read_mux_risc = read_risc_regs[191:176];
165
        7'b100_1100: read_mux_risc = read_risc_regs[207:192];
166
        7'b100_1101: read_mux_risc = read_risc_regs[223:208];
167
        7'b100_1110: read_mux_risc = read_risc_regs[239:224];
168
        7'b100_1111: read_mux_risc = read_risc_regs[255:240];
169
        7'b101_0000: read_mux_risc = read_risc_regs[271:256];
170
        7'b101_0001: read_mux_risc = read_risc_regs[287:272];
171
        7'b101_0010: read_mux_risc = read_risc_regs[303:288];
172
        7'b101_0011: read_mux_risc = read_risc_regs[319:304];
173
        7'b101_0100: read_mux_risc = read_risc_regs[335:320];
174
        7'b101_0101: read_mux_risc = read_risc_regs[351:336];
175
        7'b101_0110: read_mux_risc = read_risc_regs[367:352];
176
        7'b101_0111: read_mux_risc = read_risc_regs[383:368];
177
        7'b101_1000: read_mux_risc = read_risc_regs[399:384];
178
        7'b101_1001: read_mux_risc = read_risc_regs[415:400];
179
        default: read_mux_risc = {DWIDTH{WB_RD_DEFAULT}};
180 2 rehayes
      endcase
181
 
182 89 rehayes
  // generate wishbone write register strobes for Xgate RISC
183 2 rehayes
  always @*
184
    begin
185 17 rehayes
      write_reserv1 = 1'b0;
186
      write_reserv2 = 1'b0;
187
      write_xgmctl  = 1'b0;
188
      write_xgchid  = 1'b0;
189 2 rehayes
      write_xgisp74 = 1'b0;
190
      write_xgisp30 = 1'b0;
191 41 rehayes
      write_xgvbr  = 2'b00;
192
      write_xgif_7 = 2'b00;
193
      write_xgif_6 = 2'b00;
194
      write_xgif_5 = 2'b00;
195
      write_xgif_4 = 2'b00;
196
      write_xgif_3 = 2'b00;
197
      write_xgif_2 = 2'b00;
198
      write_xgif_1 = 2'b00;
199
      write_xgif_0 = 2'b00;
200 2 rehayes
      write_xgswt  = 1'b0;
201
      write_xgsem  = 1'b0;
202
      write_xgccr  = 1'b0;
203 41 rehayes
      write_xgpc   = 2'b00;
204
      write_xgr7   = 2'b00;
205
      write_xgr6   = 2'b00;
206
      write_xgr5   = 2'b00;
207
      write_xgr4   = 2'b00;
208
      write_xgr3   = 2'b00;
209
      write_xgr2   = 2'b00;
210
      write_xgr1   = 2'b00;
211 2 rehayes
      if (wbs_wacc)
212 89 rehayes
        case (address) // synopsys parallel_case
213 41 rehayes
           // 16 bit Bus, 8 bit Granularity
214 89 rehayes
           6'b00_0000 : write_xgmctl  = &wbs_sel_i;
215
           6'b00_0001 : write_xgchid  = wbs_sel_i[0];
216
           6'b00_0010 : write_xgisp74 = 1'b1;
217
           6'b00_0011 : write_xgisp30 = 1'b1;
218
           6'b00_0100 : write_xgvbr   = wbs_sel_i;
219
           6'b00_0101 : write_xgif_7  = wbs_sel_i;
220
           6'b00_0110 : write_xgif_6  = wbs_sel_i;
221
           6'b00_0111 : write_xgif_5  = wbs_sel_i;
222
           6'b00_1000 : write_xgif_4  = wbs_sel_i;
223
           6'b00_1001 : write_xgif_3  = wbs_sel_i;
224
           6'b00_1010 : write_xgif_2  = wbs_sel_i;
225
           6'b00_1011 : write_xgif_1  = wbs_sel_i;
226
           6'b00_1100 : write_xgif_0  = wbs_sel_i;
227
           6'b00_1101 : write_xgswt   = &wbs_sel_i;
228
           6'b00_1110 : write_xgsem   = &wbs_sel_i;
229
           6'b00_1111 : write_reserv1 = 1'b1;
230
           6'b01_0000 : write_xgccr   = wbs_sel_i[0];
231
           6'b01_0001 : write_xgpc    = wbs_sel_i;
232
           6'b01_0010 : write_reserv2 = 1'b1;
233
           6'b01_0011 : write_xgr1    = wbs_sel_i;
234
           6'b01_0100 : write_xgr2    = wbs_sel_i;
235
           6'b01_0101 : write_xgr3    = wbs_sel_i;
236
           6'b01_0110 : write_xgr4    = wbs_sel_i;
237
           6'b01_0111 : write_xgr5    = wbs_sel_i;
238
           6'b01_1000 : write_xgr6    = wbs_sel_i;
239
           6'b01_1001 : write_xgr7    = wbs_sel_i;
240
           default: ;
241
        endcase
242 2 rehayes
    end
243
 
244 67 rehayes
  // WISHBONE Read Data Mux for IRQ control registers
245
  always @*
246
      case ({wbs_racc, address}) // synopsys parallel_case
247 89 rehayes
        // 16 bit Bus, 16 bit Granularity
248
        7'b110_0000: read_mux_irq = {irq_bypass[ 15:  1], 1'b0};
249
        7'b110_0001: read_mux_irq = irq_bypass[ 31: 16];
250
        7'b110_0010: read_mux_irq = irq_bypass[ 47: 32];
251
        7'b110_0011: read_mux_irq = irq_bypass[ 63: 48];
252
        7'b110_0100: read_mux_irq = irq_bypass[ 79: 64];
253
        7'b110_0101: read_mux_irq = irq_bypass[ 95: 80];
254
        7'b110_0110: read_mux_irq = irq_bypass[111: 96];
255
        7'b110_0111: read_mux_irq = irq_bypass[127:112];
256
        default: read_mux_irq = {DWIDTH{WB_RD_DEFAULT}};
257 67 rehayes
      endcase
258
 
259
  // generate wishbone write register strobes for interrupt control
260
  always @*
261
    begin
262
      write_irw_en_7 = 2'b00;
263
      write_irw_en_6 = 2'b00;
264
      write_irw_en_5 = 2'b00;
265
      write_irw_en_4 = 2'b00;
266
      write_irw_en_3 = 2'b00;
267
      write_irw_en_2 = 2'b00;
268
      write_irw_en_1 = 2'b00;
269
      write_irw_en_0 = 2'b00;
270
      if (wbs_wacc)
271 89 rehayes
        case (address) // synopsys parallel_case
272 67 rehayes
           // 16 bit Bus, 8 bit Granularity
273 89 rehayes
           6'b10_0000 : write_irw_en_0  = wbs_sel_i;
274
           6'b10_0001 : write_irw_en_1  = wbs_sel_i;
275
           6'b10_0010 : write_irw_en_2  = wbs_sel_i;
276
           6'b10_0011 : write_irw_en_3  = wbs_sel_i;
277
           6'b10_0100 : write_irw_en_4  = wbs_sel_i;
278
           6'b10_0101 : write_irw_en_5  = wbs_sel_i;
279
           6'b10_0110 : write_irw_en_6  = wbs_sel_i;
280
           6'b10_0111 : write_irw_en_7  = wbs_sel_i;
281
           default: ;
282
        endcase
283 67 rehayes
    end
284
 
285 2 rehayes
endmodule  // xgate_wbs_bus

powered by: WebSVN 2.1.0

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