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

Subversion Repositories gpio

[/] [gpio/] [tags/] [rel_15/] [rtl/] [verilog/] [gpio_top.v] - Blame information for rev 65

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  WISHBONE General-Purpose I/O                                ////
4
////                                                              ////
5
////  This file is part of the GPIO project                       ////
6
////  http://www.opencores.org/cores/gpio/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Implementation of GPIO IP core according to                 ////
10
////  GPIO IP core specification document.                        ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   Nothing                                                    ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Damjan Lampret, lampret@opencores.org                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 62 simont
// Revision 1.17  2004/05/05 08:21:00  andreje
49
// Bugfixes when GPIO_RGPIO_ECLK/GPIO_RGPIO_NEC disabled, gpio oe name change and set to active-high according to spec
50
//
51 60 andreje
// Revision 1.16  2003/12/17 13:00:52  gorand
52
// added ECLK and NEC registers, all tests passed.
53
//
54 56 gorand
// Revision 1.15  2003/11/10 23:21:22  gorand
55
// bug fixed. all tests passed.
56
//
57 36 gorand
// Revision 1.14  2003/11/06 13:59:07  gorand
58
// added support for 8-bit access to registers.
59
//
60 34 gorand
// Revision 1.13  2002/11/18 22:35:18  lampret
61
// Bug fix. Interrupts were also asserted when condition was not met.
62
//
63 31 lampret
// Revision 1.12  2002/11/11 21:36:28  lampret
64
// Added ifdef to remove mux from clk_pad_i if mux is not allowed. This also removes RGPIO_CTRL[NEC].
65
//
66 29 lampret
// Revision 1.11  2002/03/13 20:56:28  lampret
67
// Removed zero padding as per Avi Shamli suggestion.
68
//
69 26 lampret
// Revision 1.10  2002/03/13 20:47:57  lampret
70
// Ports changed per Ran Aviram suggestions.
71
//
72 25 lampret
// Revision 1.9  2002/03/09 03:43:27  lampret
73
// Interrupt is asserted only when an input changes (code patch by Jacob Gorban)
74
//
75 24 lampret
// Revision 1.8  2002/01/14 19:06:28  lampret
76
// Changed registered WISHBONE outputs wb_ack_o/wb_err_o to follow WB specification.
77
//
78 23 lampret
// Revision 1.7  2001/12/25 17:21:21  lampret
79
// Fixed two typos.
80
//
81 22 lampret
// Revision 1.6  2001/12/25 17:12:35  lampret
82
// Added RGPIO_INTS.
83
//
84 21 lampret
// Revision 1.5  2001/12/12 20:35:53  lampret
85
// Fixing style.
86
//
87 20 lampret
// Revision 1.4  2001/12/12 07:12:58  lampret
88
// Fixed bug when wb_inta_o is registered (GPIO_WB_REGISTERED_OUTPUTS)
89
//
90 19 lampret
// Revision 1.3  2001/11/15 02:24:37  lampret
91
// Added GPIO_REGISTERED_WB_OUTPUTS, GPIO_REGISTERED_IO_OUTPUTS and GPIO_NO_NEGEDGE_FLOPS.
92
//
93 17 lampret
// Revision 1.2  2001/10/31 02:26:51  lampret
94
// Fixed wb_err_o.
95
//
96 15 lampret
// Revision 1.1  2001/09/18 18:49:07  lampret
97
// Changed top level ptc into gpio_top. Changed defines.v into gpio_defines.v.
98
//
99 14 lampret
// Revision 1.1  2001/08/21 21:39:28  lampret
100
// Changed directory structure, port names and drfines.
101
//
102
// Revision 1.2  2001/07/14 20:39:26  lampret
103
// Better configurability.
104
//
105
// Revision 1.1  2001/06/05 07:45:26  lampret
106
// Added initial RTL and test benches. There are still some issues with these files.
107
//
108
//
109
 
110
// synopsys translate_off
111
`include "timescale.v"
112
// synopsys translate_on
113
`include "gpio_defines.v"
114
 
115
module gpio_top(
116
        // WISHBONE Interface
117
        wb_clk_i, wb_rst_i, wb_cyc_i, wb_adr_i, wb_dat_i, wb_sel_i, wb_we_i, wb_stb_i,
118
        wb_dat_o, wb_ack_o, wb_err_o, wb_inta_o,
119
 
120 62 simont
`ifdef GPIO_AUX_IMPLEMENT
121 14 lampret
        // Auxiliary inputs interface
122
        aux_i,
123 62 simont
`endif //  GPIO_AUX_IMPLEMENT
124 14 lampret
 
125
        // External GPIO Interface
126 62 simont
        ext_pad_i, ext_pad_o, ext_padoe_o
127
`ifdef GPIO_CLKPAD
128
  , clk_pad_i
129
`endif
130 14 lampret
);
131
 
132
parameter dw = 32;
133
parameter aw = `GPIO_ADDRHH+1;
134
parameter gw = `GPIO_IOS;
135
//
136
// WISHBONE Interface
137
//
138 62 simont
input             wb_clk_i;     // Clock
139
input             wb_rst_i;     // Reset
140
input             wb_cyc_i;     // cycle valid input
141
input   [aw-1:0] wb_adr_i;       // address bus inputs
142
input   [dw-1:0] wb_dat_i;       // input data bus
143
input     [3:0]     wb_sel_i;    // byte select inputs
144
input             wb_we_i;      // indicates write transfer
145
input             wb_stb_i;     // strobe input
146
output  [dw-1:0]  wb_dat_o;      // output data bus
147
output            wb_ack_o;     // normal termination
148
output            wb_err_o;     // termination w/ error
149
output            wb_inta_o;    // Interrupt request output
150 14 lampret
 
151 62 simont
`ifdef GPIO_AUX_IMPLEMENT
152 14 lampret
// Auxiliary Inputs Interface
153 62 simont
input     [gw-1:0]  aux_i;               // Auxiliary inputs
154
`endif // GPIO_AUX_IMPLEMENT
155 14 lampret
 
156
//
157
// External GPIO Interface
158
//
159 62 simont
input   [gw-1:0]  ext_pad_i;     // GPIO Inputs
160
`ifdef GPIO_CLKPAD
161
input             clk_pad_i;    // GPIO Eclk
162
`endif //  GPIO_CLKPAD
163
output  [gw-1:0]  ext_pad_o;     // GPIO Outputs
164
output  [gw-1:0]  ext_padoe_o;   // GPIO output drivers enables
165 14 lampret
 
166
`ifdef GPIO_IMPLEMENTED
167
 
168
//
169
// GPIO Input Register (or no register)
170
//
171
`ifdef GPIO_RGPIO_IN
172
reg     [gw-1:0] rgpio_in;       // RGPIO_IN register
173
`else
174
wire    [gw-1:0] rgpio_in;       // No register
175
`endif
176
 
177
//
178
// GPIO Output Register (or no register)
179
//
180
`ifdef GPIO_RGPIO_OUT
181
reg     [gw-1:0] rgpio_out;      // RGPIO_OUT register
182
`else
183
wire    [gw-1:0] rgpio_out;      // No register
184
`endif
185
 
186
//
187
// GPIO Output Driver Enable Register (or no register)
188
//
189
`ifdef GPIO_RGPIO_OE
190
reg     [gw-1:0] rgpio_oe;       // RGPIO_OE register
191
`else
192
wire    [gw-1:0] rgpio_oe;       // No register
193
`endif
194
 
195
//
196
// GPIO Interrupt Enable Register (or no register)
197
//
198
`ifdef GPIO_RGPIO_INTE
199
reg     [gw-1:0] rgpio_inte;     // RGPIO_INTE register
200
`else
201
wire    [gw-1:0] rgpio_inte;     // No register
202
`endif
203
 
204
//
205
// GPIO Positive edge Triggered Register (or no register)
206
//
207
`ifdef GPIO_RGPIO_PTRIG
208
reg     [gw-1:0] rgpio_ptrig;    // RGPIO_PTRIG register
209
`else
210
wire    [gw-1:0] rgpio_ptrig;    // No register
211
`endif
212
 
213
//
214
// GPIO Auxiliary select Register (or no register)
215
//
216
`ifdef GPIO_RGPIO_AUX
217
reg     [gw-1:0] rgpio_aux;      // RGPIO_AUX register
218
`else
219
wire    [gw-1:0] rgpio_aux;      // No register
220
`endif
221
 
222
//
223
// GPIO Control Register (or no register)
224
//
225
`ifdef GPIO_RGPIO_CTRL
226 56 gorand
reg     [1:0]            rgpio_ctrl;     // RGPIO_CTRL register
227 14 lampret
`else
228 56 gorand
wire    [1:0]            rgpio_ctrl;     // No register
229 14 lampret
`endif
230
 
231
//
232 21 lampret
// GPIO Interrupt Status Register (or no register)
233
//
234
`ifdef GPIO_RGPIO_INTS
235
reg     [gw-1:0] rgpio_ints;     // RGPIO_INTS register
236
`else
237
wire    [gw-1:0] rgpio_ints;     // No register
238
`endif
239
 
240
//
241 56 gorand
// GPIO Enable Clock  Register (or no register)
242
//
243
`ifdef GPIO_RGPIO_ECLK
244
reg     [gw-1:0] rgpio_eclk;     // RGPIO_ECLK register
245
`else
246
wire    [gw-1:0] rgpio_eclk;     // No register
247
`endif
248
 
249
//
250
// GPIO Active Negative Edge  Register (or no register)
251
//
252
`ifdef GPIO_RGPIO_NEC
253
reg     [gw-1:0] rgpio_nec;      // RGPIO_NEC register
254
`else
255
wire    [gw-1:0] rgpio_nec;      // No register
256
`endif
257
 
258 62 simont
 
259 56 gorand
//
260 62 simont
// Synchronization flops for input signals
261
//
262
`ifdef GPIO_SYNC_IN_WB
263
reg  [gw-1:0]  sync      ,
264
               ext_pad_s ;
265
`else
266
wire [gw-1:0]  ext_pad_s ;
267
`endif
268
 
269
 
270
 
271
//
272 14 lampret
// Internal wires & regs
273
//
274 62 simont
wire            rgpio_out_sel;  // RGPIO_OUT select
275
wire            rgpio_oe_sel; // RGPIO_OE select
276
wire            rgpio_inte_sel; // RGPIO_INTE select
277
wire            rgpio_ptrig_sel;// RGPIO_PTRIG select
278
wire            rgpio_aux_sel;  // RGPIO_AUX select
279
wire            rgpio_ctrl_sel; // RGPIO_CTRL select
280
wire            rgpio_ints_sel; // RGPIO_INTS select
281
wire            rgpio_eclk_sel ;
282
wire            rgpio_nec_sel ;
283
wire            full_decoding;  // Full address decoding qualification
284 56 gorand
wire  [gw-1:0]  in_muxed; // Muxed inputs
285 62 simont
wire            wb_ack;   // WB Acknowledge
286
wire            wb_err;   // WB Error
287
wire            wb_inta;  // WB Interrupt
288
reg   [dw-1:0]  wb_dat;   // WB Data out
289 17 lampret
`ifdef GPIO_REGISTERED_WB_OUTPUTS
290 62 simont
reg             wb_ack_o; // WB Acknowledge
291
reg             wb_err_o; // WB Error
292
reg             wb_inta_o;  // WB Interrupt
293
reg   [dw-1:0]  wb_dat_o; // WB Data out
294 17 lampret
`endif
295 56 gorand
wire  [gw-1:0]  out_pad;  // GPIO Outputs
296 17 lampret
`ifdef GPIO_REGISTERED_IO_OUTPUTS
297 62 simont
reg   [gw-1:0]  ext_pad_o;  // GPIO Outputs
298 17 lampret
`endif
299 62 simont
`ifdef GPIO_CLKPAD
300 56 gorand
wire  [gw-1:0]  extc_in;  // Muxed inputs sampled by external clock
301
wire  [gw-1:0]  pext_clk; // External clock for posedge flops
302 62 simont
reg   [gw-1:0]  pextc_sampled;  // Posedge external clock sampled inputs
303 17 lampret
`ifdef GPIO_NO_NEGEDGE_FLOPS
304 62 simont
`ifdef GPIO_NO_CLKPAD_LOGIC
305 17 lampret
`else
306 62 simont
reg   [gw-1:0]  nextc_sampled;  // Negedge external clock sampled inputs
307
`endif //  GPIO_NO_CLKPAD_LOGIC
308
`else
309
reg   [gw-1:0]  nextc_sampled;  // Negedge external clock sampled inputs
310 17 lampret
`endif
311 62 simont
`endif //  GPIO_CLKPAD
312 14 lampret
 
313 56 gorand
 
314 14 lampret
//
315
// All WISHBONE transfer terminations are successful except when:
316
// a) full address decoding is enabled and address doesn't match
317
//    any of the GPIO registers
318
// b) wb_sel_i evaluation is enabled and one of the wb_sel_i inputs is zero
319
//
320 17 lampret
 
321
//
322
// WB Acknowledge
323
//
324
assign wb_ack = wb_cyc_i & wb_stb_i & !wb_err_o;
325
 
326
//
327
// Optional registration of WB Ack
328
//
329
`ifdef GPIO_REGISTERED_WB_OUTPUTS
330
always @(posedge wb_clk_i or posedge wb_rst_i)
331
        if (wb_rst_i)
332
                wb_ack_o <= #1 1'b0;
333
        else
334 34 gorand
                wb_ack_o <= #1 wb_ack & ~wb_ack_o & (!wb_err) ;
335 17 lampret
`else
336
assign wb_ack_o = wb_ack;
337
`endif
338
 
339
//
340
// WB Error
341
//
342 14 lampret
`ifdef GPIO_FULL_DECODE
343
`ifdef GPIO_STRICT_32BIT_ACCESS
344 17 lampret
assign wb_err = wb_cyc_i & wb_stb_i & (!full_decoding | (wb_sel_i != 4'b1111));
345 14 lampret
`else
346 17 lampret
assign wb_err = wb_cyc_i & wb_stb_i & !full_decoding;
347 14 lampret
`endif
348
`else
349
`ifdef GPIO_STRICT_32BIT_ACCESS
350 17 lampret
assign wb_err = wb_cyc_i & wb_stb_i & (wb_sel_i != 4'b1111);
351 14 lampret
`else
352 17 lampret
assign wb_err = 1'b0;
353 14 lampret
`endif
354
`endif
355
 
356
//
357 17 lampret
// Optional registration of WB error
358 14 lampret
//
359 17 lampret
`ifdef GPIO_REGISTERED_WB_OUTPUTS
360
always @(posedge wb_clk_i or posedge wb_rst_i)
361
        if (wb_rst_i)
362
                wb_err_o <= #1 1'b0;
363
        else
364 23 lampret
                wb_err_o <= #1 wb_err & ~wb_err_o;
365 17 lampret
`else
366
assign wb_err_o = wb_err;
367
`endif
368 14 lampret
 
369
//
370
// Full address decoder
371
//
372
`ifdef GPIO_FULL_DECODE
373
assign full_decoding = (wb_adr_i[`GPIO_ADDRHH:`GPIO_ADDRHL] == {`GPIO_ADDRHH-`GPIO_ADDRHL+1{1'b0}}) &
374
                        (wb_adr_i[`GPIO_ADDRLH:`GPIO_ADDRLL] == {`GPIO_ADDRLH-`GPIO_ADDRLL+1{1'b0}});
375
`else
376
assign full_decoding = 1'b1;
377
`endif
378
 
379
//
380
// GPIO registers address decoder
381
//
382 60 andreje
`ifdef GPIO_RGPIO_OUT
383 14 lampret
assign rgpio_out_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_OUT) & full_decoding;
384 60 andreje
`endif
385
`ifdef GPIO_RGPIO_OE
386 14 lampret
assign rgpio_oe_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_OE) & full_decoding;
387 60 andreje
`endif
388
`ifdef GPIO_RGPIO_INTE
389 14 lampret
assign rgpio_inte_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_INTE) & full_decoding;
390 60 andreje
`endif
391
`ifdef GPIO_RGPIO_PTRIG
392 14 lampret
assign rgpio_ptrig_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_PTRIG) & full_decoding;
393 60 andreje
`endif
394
`ifdef GPIO_RGPIO_AUX
395 14 lampret
assign rgpio_aux_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_AUX) & full_decoding;
396 60 andreje
`endif
397
`ifdef GPIO_RGPIO_CTRL
398 14 lampret
assign rgpio_ctrl_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_CTRL) & full_decoding;
399 60 andreje
`endif
400
`ifdef GPIO_RGPIO_INTS
401 21 lampret
assign rgpio_ints_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_INTS) & full_decoding;
402 60 andreje
`endif
403
`ifdef GPIO_RGPIO_ECLK
404 56 gorand
assign rgpio_eclk_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_ECLK) & full_decoding;
405 60 andreje
`endif
406
`ifdef GPIO_RGPIO_NEC
407 56 gorand
assign rgpio_nec_sel = wb_cyc_i & wb_stb_i & (wb_adr_i[`GPIO_OFS_BITS] == `GPIO_RGPIO_NEC) & full_decoding;
408 60 andreje
`endif
409 56 gorand
 
410
 
411 14 lampret
//
412
// Write to RGPIO_CTRL or update of RGPIO_CTRL[INT] bit
413
//
414
`ifdef GPIO_RGPIO_CTRL
415
always @(posedge wb_clk_i or posedge wb_rst_i)
416
        if (wb_rst_i)
417 56 gorand
                rgpio_ctrl <= #1 2'b0;
418 14 lampret
        else if (rgpio_ctrl_sel && wb_we_i)
419 56 gorand
                rgpio_ctrl <= #1 wb_dat_i[1:0];
420 14 lampret
        else if (rgpio_ctrl[`GPIO_RGPIO_CTRL_INTE])
421 21 lampret
                rgpio_ctrl[`GPIO_RGPIO_CTRL_INTS] <= #1 rgpio_ctrl[`GPIO_RGPIO_CTRL_INTS] | wb_inta_o;
422 14 lampret
`else
423 56 gorand
assign rgpio_ctrl = 2'h01;      // RGPIO_CTRL[EN] = 1
424 14 lampret
`endif
425
 
426
//
427
// Write to RGPIO_OUT
428
//
429
`ifdef GPIO_RGPIO_OUT
430
always @(posedge wb_clk_i or posedge wb_rst_i)
431
        if (wb_rst_i)
432
                rgpio_out <= #1 {gw{1'b0}};
433
        else if (rgpio_out_sel && wb_we_i)
434 34 gorand
    begin
435
`ifdef GPIO_STRICT_32BIT_ACCESS
436 14 lampret
                rgpio_out <= #1 wb_dat_i[gw-1:0];
437 34 gorand
`endif
438
 
439
`ifdef GPIO_WB_BYTES4
440
     if ( wb_sel_i [3] == 1'b1 )
441
       rgpio_out [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
442
     if ( wb_sel_i [2] == 1'b1 )
443
       rgpio_out [23:16] <= #1 wb_dat_i [23:16] ;
444
     if ( wb_sel_i [1] == 1'b1 )
445
       rgpio_out [15:8] <= #1 wb_dat_i [15:8] ;
446
     if ( wb_sel_i [0] == 1'b1 )
447
       rgpio_out [7:0] <= #1 wb_dat_i [7:0] ;
448
`endif
449
`ifdef GPIO_WB_BYTES3
450
     if ( wb_sel_i [2] == 1'b1 )
451
       rgpio_out [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
452
     if ( wb_sel_i [1] == 1'b1 )
453
       rgpio_out [15:8] <= #1 wb_dat_i [15:8] ;
454
     if ( wb_sel_i [0] == 1'b1 )
455
       rgpio_out [7:0] <= #1 wb_dat_i [7:0] ;
456
`endif
457
`ifdef GPIO_WB_BYTES2
458
     if ( wb_sel_i [1] == 1'b1 )
459
       rgpio_out [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
460
     if ( wb_sel_i [0] == 1'b1 )
461
       rgpio_out [7:0] <= #1 wb_dat_i [7:0] ;
462
`endif
463
`ifdef GPIO_WB_BYTES1
464
     if ( wb_sel_i [0] == 1'b1 )
465
       rgpio_out [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
466
`endif
467
   end
468
 
469 14 lampret
`else
470 17 lampret
assign rgpio_out = `GPIO_DEF_RGPIO_OUT; // RGPIO_OUT = 0x0
471 14 lampret
`endif
472
 
473
//
474 60 andreje
// Write to RGPIO_OE.
475 14 lampret
//
476
`ifdef GPIO_RGPIO_OE
477 36 gorand
always @(posedge wb_clk_i or posedge wb_rst_i)
478
        if (wb_rst_i)
479 14 lampret
                rgpio_oe <= #1 {gw{1'b0}};
480 36 gorand
        else if (rgpio_oe_sel && wb_we_i)
481 34 gorand
  begin
482
`ifdef GPIO_STRICT_32BIT_ACCESS
483 60 andreje
                rgpio_oe <= #1 wb_dat_i[gw-1:0];
484 34 gorand
`endif
485
 
486
`ifdef GPIO_WB_BYTES4
487 36 gorand
     if ( wb_sel_i [3] == 1'b1 )
488 60 andreje
       rgpio_oe [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
489 36 gorand
     if ( wb_sel_i [2] == 1'b1 )
490 60 andreje
       rgpio_oe [23:16] <= #1 wb_dat_i [23:16] ;
491 36 gorand
     if ( wb_sel_i [1] == 1'b1 )
492 60 andreje
       rgpio_oe [15:8] <= #1 wb_dat_i [15:8] ;
493 36 gorand
     if ( wb_sel_i [0] == 1'b1 )
494 60 andreje
       rgpio_oe [7:0] <= #1 wb_dat_i [7:0] ;
495 34 gorand
`endif
496
`ifdef GPIO_WB_BYTES3
497 36 gorand
     if ( wb_sel_i [2] == 1'b1 )
498 60 andreje
       rgpio_oe [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
499 36 gorand
     if ( wb_sel_i [1] == 1'b1 )
500 60 andreje
       rgpio_oe [15:8] <= #1 wb_dat_i [15:8] ;
501 36 gorand
     if ( wb_sel_i [0] == 1'b1 )
502 60 andreje
       rgpio_oe [7:0] <= #1 wb_dat_i [7:0] ;
503 34 gorand
`endif
504
`ifdef GPIO_WB_BYTES2
505 36 gorand
     if ( wb_sel_i [1] == 1'b1 )
506 60 andreje
       rgpio_oe [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
507 36 gorand
     if ( wb_sel_i [0] == 1'b1 )
508 60 andreje
       rgpio_oe [7:0] <= #1 wb_dat_i [7:0] ;
509 34 gorand
`endif
510
`ifdef GPIO_WB_BYTES1
511 36 gorand
     if ( wb_sel_i [0] == 1'b1 )
512 60 andreje
       rgpio_oe [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
513 34 gorand
`endif
514
   end
515
 
516 14 lampret
`else
517 60 andreje
assign rgpio_oe = `GPIO_DEF_RGPIO_OE;   // RGPIO_OE = 0x0
518 14 lampret
`endif
519
 
520
//
521
// Write to RGPIO_INTE
522
//
523
`ifdef GPIO_RGPIO_INTE
524
always @(posedge wb_clk_i or posedge wb_rst_i)
525
        if (wb_rst_i)
526
                rgpio_inte <= #1 {gw{1'b0}};
527
        else if (rgpio_inte_sel && wb_we_i)
528 34 gorand
  begin
529
`ifdef GPIO_STRICT_32BIT_ACCESS
530 14 lampret
                rgpio_inte <= #1 wb_dat_i[gw-1:0];
531 34 gorand
`endif
532
 
533
`ifdef GPIO_WB_BYTES4
534
     if ( wb_sel_i [3] == 1'b1 )
535
       rgpio_inte [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
536
     if ( wb_sel_i [2] == 1'b1 )
537
       rgpio_inte [23:16] <= #1 wb_dat_i [23:16] ;
538
     if ( wb_sel_i [1] == 1'b1 )
539
       rgpio_inte [15:8] <= #1 wb_dat_i [15:8] ;
540
     if ( wb_sel_i [0] == 1'b1 )
541
       rgpio_inte [7:0] <= #1 wb_dat_i [7:0] ;
542
`endif
543
`ifdef GPIO_WB_BYTES3
544
     if ( wb_sel_i [2] == 1'b1 )
545
       rgpio_inte [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
546
     if ( wb_sel_i [1] == 1'b1 )
547
       rgpio_inte [15:8] <= #1 wb_dat_i [15:8] ;
548
     if ( wb_sel_i [0] == 1'b1 )
549
       rgpio_inte [7:0] <= #1 wb_dat_i [7:0] ;
550
`endif
551
`ifdef GPIO_WB_BYTES2
552
     if ( wb_sel_i [1] == 1'b1 )
553
       rgpio_inte [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
554
     if ( wb_sel_i [0] == 1'b1 )
555
       rgpio_inte [7:0] <= #1 wb_dat_i [7:0] ;
556
`endif
557
`ifdef GPIO_WB_BYTES1
558
     if ( wb_sel_i [0] == 1'b1 )
559
       rgpio_inte [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
560
`endif
561
   end
562
 
563
 
564 14 lampret
`else
565 60 andreje
assign rgpio_inte = `GPIO_DEF_RGPIO_INTE;       // RGPIO_INTE = 0x0
566 14 lampret
`endif
567
 
568
//
569
// Write to RGPIO_PTRIG
570
//
571
`ifdef GPIO_RGPIO_PTRIG
572
always @(posedge wb_clk_i or posedge wb_rst_i)
573
        if (wb_rst_i)
574
                rgpio_ptrig <= #1 {gw{1'b0}};
575
        else if (rgpio_ptrig_sel && wb_we_i)
576 34 gorand
  begin
577
`ifdef GPIO_STRICT_32BIT_ACCESS
578 14 lampret
                rgpio_ptrig <= #1 wb_dat_i[gw-1:0];
579 34 gorand
`endif
580
 
581
`ifdef GPIO_WB_BYTES4
582
     if ( wb_sel_i [3] == 1'b1 )
583
       rgpio_ptrig [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
584
     if ( wb_sel_i [2] == 1'b1 )
585
       rgpio_ptrig [23:16] <= #1 wb_dat_i [23:16] ;
586
     if ( wb_sel_i [1] == 1'b1 )
587
       rgpio_ptrig [15:8] <= #1 wb_dat_i [15:8] ;
588
     if ( wb_sel_i [0] == 1'b1 )
589
       rgpio_ptrig [7:0] <= #1 wb_dat_i [7:0] ;
590
`endif
591
`ifdef GPIO_WB_BYTES3
592
     if ( wb_sel_i [2] == 1'b1 )
593
       rgpio_ptrig [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
594
     if ( wb_sel_i [1] == 1'b1 )
595
       rgpio_ptrig [15:8] <= #1 wb_dat_i [15:8] ;
596
     if ( wb_sel_i [0] == 1'b1 )
597
       rgpio_ptrig [7:0] <= #1 wb_dat_i [7:0] ;
598
`endif
599
`ifdef GPIO_WB_BYTES2
600
     if ( wb_sel_i [1] == 1'b1 )
601
       rgpio_ptrig [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
602
     if ( wb_sel_i [0] == 1'b1 )
603
       rgpio_ptrig [7:0] <= #1 wb_dat_i [7:0] ;
604
`endif
605
`ifdef GPIO_WB_BYTES1
606
     if ( wb_sel_i [0] == 1'b1 )
607
       rgpio_ptrig [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
608
`endif
609
   end
610
 
611 14 lampret
`else
612 60 andreje
assign rgpio_ptrig = `GPIO_DEF_RGPIO_PTRIG;     // RGPIO_PTRIG = 0x0
613 14 lampret
`endif
614
 
615
//
616
// Write to RGPIO_AUX
617
//
618
`ifdef GPIO_RGPIO_AUX
619
always @(posedge wb_clk_i or posedge wb_rst_i)
620
        if (wb_rst_i)
621
                rgpio_aux <= #1 {gw{1'b0}};
622
        else if (rgpio_aux_sel && wb_we_i)
623 34 gorand
  begin
624
`ifdef GPIO_STRICT_32BIT_ACCESS
625 14 lampret
                rgpio_aux <= #1 wb_dat_i[gw-1:0];
626 34 gorand
`endif
627
 
628
`ifdef GPIO_WB_BYTES4
629
     if ( wb_sel_i [3] == 1'b1 )
630
       rgpio_aux [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
631
     if ( wb_sel_i [2] == 1'b1 )
632
       rgpio_aux [23:16] <= #1 wb_dat_i [23:16] ;
633
     if ( wb_sel_i [1] == 1'b1 )
634
       rgpio_aux [15:8] <= #1 wb_dat_i [15:8] ;
635
     if ( wb_sel_i [0] == 1'b1 )
636
       rgpio_aux [7:0] <= #1 wb_dat_i [7:0] ;
637
`endif
638
`ifdef GPIO_WB_BYTES3
639
     if ( wb_sel_i [2] == 1'b1 )
640
       rgpio_aux [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
641
     if ( wb_sel_i [1] == 1'b1 )
642
       rgpio_aux [15:8] <= #1 wb_dat_i [15:8] ;
643
     if ( wb_sel_i [0] == 1'b1 )
644
       rgpio_aux [7:0] <= #1 wb_dat_i [7:0] ;
645
`endif
646
`ifdef GPIO_WB_BYTES2
647
     if ( wb_sel_i [1] == 1'b1 )
648
       rgpio_aux [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
649
     if ( wb_sel_i [0] == 1'b1 )
650
       rgpio_aux [7:0] <= #1 wb_dat_i [7:0] ;
651
`endif
652
`ifdef GPIO_WB_BYTES1
653
     if ( wb_sel_i [0] == 1'b1 )
654
       rgpio_aux [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
655
`endif
656
   end
657
 
658 14 lampret
`else
659 60 andreje
assign rgpio_aux = `GPIO_DEF_RGPIO_AUX; // RGPIO_AUX = 0x0
660 14 lampret
`endif
661
 
662 56 gorand
 
663 14 lampret
//
664 56 gorand
// Write to RGPIO_ECLK
665
//
666
`ifdef GPIO_RGPIO_ECLK
667
always @(posedge wb_clk_i or posedge wb_rst_i)
668
        if (wb_rst_i)
669
                rgpio_eclk <= #1 {gw{1'b0}};
670
        else if (rgpio_eclk_sel && wb_we_i)
671
  begin
672
`ifdef GPIO_STRICT_32BIT_ACCESS
673
                rgpio_eclk <= #1 wb_dat_i[gw-1:0];
674
`endif
675
 
676
`ifdef GPIO_WB_BYTES4
677
     if ( wb_sel_i [3] == 1'b1 )
678
       rgpio_eclk [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
679
     if ( wb_sel_i [2] == 1'b1 )
680
       rgpio_eclk [23:16] <= #1 wb_dat_i [23:16] ;
681
     if ( wb_sel_i [1] == 1'b1 )
682
       rgpio_eclk [15:8] <= #1 wb_dat_i [15:8] ;
683
     if ( wb_sel_i [0] == 1'b1 )
684
       rgpio_eclk [7:0] <= #1 wb_dat_i [7:0] ;
685
`endif
686
`ifdef GPIO_WB_BYTES3
687
     if ( wb_sel_i [2] == 1'b1 )
688
       rgpio_eclk [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
689
     if ( wb_sel_i [1] == 1'b1 )
690
       rgpio_eclk [15:8] <= #1 wb_dat_i [15:8] ;
691
     if ( wb_sel_i [0] == 1'b1 )
692
       rgpio_eclk [7:0] <= #1 wb_dat_i [7:0] ;
693
`endif
694
`ifdef GPIO_WB_BYTES2
695
     if ( wb_sel_i [1] == 1'b1 )
696
       rgpio_eclk [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
697
     if ( wb_sel_i [0] == 1'b1 )
698
       rgpio_eclk [7:0] <= #1 wb_dat_i [7:0] ;
699
`endif
700
`ifdef GPIO_WB_BYTES1
701
     if ( wb_sel_i [0] == 1'b1 )
702
       rgpio_eclk [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
703
`endif
704
   end
705
 
706
 
707
`else
708 60 andreje
assign rgpio_eclk = `GPIO_DEF_RGPIO_ECLK;       // RGPIO_ECLK = 0x0
709 56 gorand
`endif
710
 
711
 
712
 
713
//
714
// Write to RGPIO_NEC
715
//
716
`ifdef GPIO_RGPIO_NEC
717
always @(posedge wb_clk_i or posedge wb_rst_i)
718
        if (wb_rst_i)
719
                rgpio_nec <= #1 {gw{1'b0}};
720
        else if (rgpio_nec_sel && wb_we_i)
721
  begin
722
`ifdef GPIO_STRICT_32BIT_ACCESS
723
                rgpio_nec <= #1 wb_dat_i[gw-1:0];
724
`endif
725
 
726
`ifdef GPIO_WB_BYTES4
727
     if ( wb_sel_i [3] == 1'b1 )
728
       rgpio_nec [gw-1:24] <= #1 wb_dat_i [gw-1:24] ;
729
     if ( wb_sel_i [2] == 1'b1 )
730
       rgpio_nec [23:16] <= #1 wb_dat_i [23:16] ;
731
     if ( wb_sel_i [1] == 1'b1 )
732
       rgpio_nec [15:8] <= #1 wb_dat_i [15:8] ;
733
     if ( wb_sel_i [0] == 1'b1 )
734
       rgpio_nec [7:0] <= #1 wb_dat_i [7:0] ;
735
`endif
736
`ifdef GPIO_WB_BYTES3
737
     if ( wb_sel_i [2] == 1'b1 )
738
       rgpio_nec [gw-1:16] <= #1 wb_dat_i [gw-1:16] ;
739
     if ( wb_sel_i [1] == 1'b1 )
740
       rgpio_nec [15:8] <= #1 wb_dat_i [15:8] ;
741
     if ( wb_sel_i [0] == 1'b1 )
742
       rgpio_nec [7:0] <= #1 wb_dat_i [7:0] ;
743
`endif
744
`ifdef GPIO_WB_BYTES2
745
     if ( wb_sel_i [1] == 1'b1 )
746
       rgpio_nec [gw-1:8] <= #1 wb_dat_i [gw-1:8] ;
747
     if ( wb_sel_i [0] == 1'b1 )
748
       rgpio_nec [7:0] <= #1 wb_dat_i [7:0] ;
749
`endif
750
`ifdef GPIO_WB_BYTES1
751
     if ( wb_sel_i [0] == 1'b1 )
752
       rgpio_nec [gw-1:0] <= #1 wb_dat_i [gw-1:0] ;
753
`endif
754
   end
755
 
756
 
757
`else
758 60 andreje
assign rgpio_nec = `GPIO_DEF_RGPIO_NEC; // RGPIO_NEC = 0x0
759 56 gorand
`endif
760
 
761
//
762 62 simont
// synchronize inputs to systam clock
763
//
764
`ifdef  GPIO_SYNC_IN_WB
765
always @(posedge wb_clk_i or posedge wb_rst_i)
766
  if (wb_rst_i) begin
767
    sync      <= #1 {gw{1'b0}} ;
768
    ext_pad_s <= #1 {gw{1'b0}} ;
769
  end else begin
770
    sync      <= #1 ext_pad_i  ;
771
    ext_pad_s <= #1 sync       ;
772
  end
773
`else
774
assign  ext_pad_s = ext_pad_i;
775
`endif // GPIO_SYNC_IN_WB
776
 
777
//
778 14 lampret
// Latch into RGPIO_IN
779
//
780
`ifdef GPIO_RGPIO_IN
781 17 lampret
always @(posedge wb_clk_i or posedge wb_rst_i)
782 14 lampret
        if (wb_rst_i)
783
                rgpio_in <= #1 {gw{1'b0}};
784
        else
785 17 lampret
                rgpio_in <= #1 in_muxed;
786 14 lampret
`else
787 17 lampret
assign rgpio_in = in_muxed;
788 14 lampret
`endif
789
 
790 62 simont
`ifdef GPIO_CLKPAD
791 17 lampret
 
792 62 simont
`ifdef GPIO_SYNC_CLK_WB
793 17 lampret
//
794 62 simont
// external clock enabled
795
// synchronized to system clock
796
// (one clock domain)
797 17 lampret
//
798 56 gorand
 
799 62 simont
reg  sync_clk,
800
     clk_s   ,
801
     clk_r   ;
802
wire pedge   ,
803
     nedge   ;
804
wire [gw-1:0] pedge_vec   ,
805
              nedge_vec   ;
806
wire [gw-1:0] in_lach     ;
807 56 gorand
 
808 62 simont
assign pedge =  clk_s & !clk_r ;
809
assign nedge = !clk_s &  clk_r ;
810
assign pedge_vec = {gw{pedge}} ;
811
assign nedge_vec = {gw{nedge}} ;
812 56 gorand
 
813 62 simont
assign in_lach = (~rgpio_nec & pedge_vec) | (rgpio_nec & nedge_vec) ;
814
assign extc_in = (in_lach & ext_pad_s) | (~in_lach & pextc_sampled) ;
815 56 gorand
 
816 62 simont
always @(posedge wb_clk_i or posedge wb_rst_i)
817
  if (wb_rst_i) begin
818
    sync_clk <= #1 1'b0 ;
819
    clk_s    <= #1 1'b0 ;
820
    clk_r    <= #1 1'b0 ;
821
  end else begin
822
    sync_clk <= #1 clk_pad_i ;
823
    clk_s    <= #1 sync_clk  ;
824
    clk_r    <= #1 clk_s     ;
825
  end
826 56 gorand
 
827 62 simont
always @(posedge wb_clk_i or posedge wb_rst_i)
828
  if (wb_rst_i) begin
829
    pextc_sampled <= #1 {gw{1'b0}};
830
  end else begin
831
    pextc_sampled <= #1 extc_in ;
832
  end
833 56 gorand
 
834 62 simont
assign in_muxed = (rgpio_eclk & pextc_sampled) | (~rgpio_eclk & ext_pad_s) ;
835 56 gorand
 
836 17 lampret
`else
837
//
838 62 simont
// external clock enabled
839
// not  synchronized to system clock
840
// (two clock domains)
841 17 lampret
//
842 56 gorand
 
843 62 simont
`ifdef GPIO_SYNC_IN_CLK_WB
844 56 gorand
 
845 62 simont
reg [gw-1:0] syn_extc  ,
846
             extc_s    ;
847 17 lampret
 
848 62 simont
always @(posedge wb_clk_i or posedge wb_rst_i)
849
  if (wb_rst_i) begin
850
    syn_extc  <= #1 {gw{1'b0}};
851
    extc_s    <= #1 {gw{1'b0}};
852
  end else begin
853
    syn_extc  <= #1 extc_in ;
854
    extc_s    <= #1 syn_extc;
855
  end
856 56 gorand
 
857 62 simont
`else
858 56 gorand
 
859 62 simont
wire [gw-1:0] extc_s   ;
860
assign extc_s = syn_extc ;
861 56 gorand
 
862 62 simont
`endif // GPIO_SYNC_IN_CLK_WB
863 56 gorand
 
864 62 simont
`ifdef GPIO_SYNC_IN_CLK
865
reg [gw-1:0] syn_pclk    ,
866
             ext_pad_spc ;
867 56 gorand
 
868 62 simont
always @(posedge clk_pad_i or posedge wb_rst_i)
869
  if (wb_rst_i) begin
870
    syn_pclk    <= #1 {gw{1'b0}} ;
871
    ext_pad_spc <= #1 {gw{1'b0}} ;
872
  end else begin
873
    syn_pclk    <= #1 ext_pad_i ;
874
    ext_pad_spc <= #1 syn_pclk  ;
875
  end
876 56 gorand
 
877 62 simont
`else
878 56 gorand
 
879 62 simont
wire [gw-1:0] ext_pad_spc      ;
880
assign ext_pad_spc = ext_pad_i ;
881 56 gorand
 
882 62 simont
`endif // GPIO_SYNC_IN_CLK
883 56 gorand
 
884 62 simont
always @(posedge clk_pad_i or posedge wb_rst_i)
885
  if (wb_rst_i) begin
886
    pextc_sampled <= #1 {gw{1'b0}};
887
  end else begin
888
    pextc_sampled <= #1 ext_pad_spc ;
889
  end
890 56 gorand
 
891
 
892 62 simont
`ifdef GPIO_NO_NEGEDGE_FLOPS
893 56 gorand
 
894 62 simont
`ifdef GPIO_NO_CLKPAD_LOGIC
895 56 gorand
 
896 62 simont
assign extc_in = pextc_sampled;
897 56 gorand
 
898 62 simont
`else
899 56 gorand
 
900 62 simont
wire  clk_n;
901
assign clk_n = !clk_pad_i;
902 56 gorand
 
903 62 simont
`ifdef GPIO_SYNC_IN_CLK
904
reg [gw-1:0] syn_nclk    ,
905
             ext_pad_snc ;
906 56 gorand
 
907 62 simont
always @(posedge clk_n or posedge wb_rst_i)
908
  if (wb_rst_i) begin
909
    syn_nclk    <= #1 {gw{1'b0}} ;
910
    ext_pad_snc <= #1 {gw{1'b0}} ;
911
  end else begin
912
    syn_nclk    <= #1 ext_pad_i ;
913
    ext_pad_snc <= #1 syn_nclk  ;
914
  end
915 56 gorand
 
916 62 simont
`else
917 56 gorand
 
918 62 simont
wire [gw-1:0] ext_pad_snc      ;
919
assign ext_pad_snc = ext_pad_i ;
920 56 gorand
 
921 62 simont
`endif // GPIO_SYNC_IN_CLK
922 56 gorand
 
923 62 simont
always @(posedge clk_n or posedge wb_rst_i)
924
  if (wb_rst_i) begin
925
    nextc_sampled <= #1 {gw{1'b0}};
926
  end else begin
927
    nextc_sampled <= #1 ext_pad_snc ;
928
  end
929 56 gorand
 
930 62 simont
assign extc_in = (~rgpio_nec & pextc_sampled) | (rgpio_nec & nextc_sampled) ;
931 56 gorand
 
932 62 simont
`endif //  GPIO_NO_CLKPAD_LOGIC
933 56 gorand
 
934
 
935 62 simont
`else
936 56 gorand
 
937 62 simont
`ifdef GPIO_SYNC_IN_CLK
938
reg [gw-1:0] syn_nclk    ,
939
             ext_pad_snc ;
940 56 gorand
 
941 62 simont
always @(negedge clk_n or posedge wb_rst_i)
942
  if (wb_rst_i) begin
943
    syn_nclk    <= #1 {gw{1'b0}} ;
944
    ext_pad_snc <= #1 {gw{1'b0}} ;
945
  end else begin
946
    syn_nclk    <= #1 ext_pad_i ;
947
    ext_pad_snc <= #1 syn_nclk  ;
948
  end
949 56 gorand
 
950 62 simont
`else
951 56 gorand
 
952 62 simont
wire [gw-1:0] ext_pad_snc      ;
953
assign ext_pad_snc = ext_pad_i ;
954 56 gorand
 
955 62 simont
`endif // GPIO_SYNC_IN_CLK
956 56 gorand
 
957 62 simont
always @(negedge clk_pad_i or posedge wb_rst_i)
958
  if (wb_rst_i) begin
959
    nextc_sampled <= #1 {gw{1'b0}};
960
  end else begin
961
    nextc_sampled <= #1 ext_pad_snc ;
962
  end
963 56 gorand
 
964 62 simont
assign extc_in = (~rgpio_nec & pextc_sampled) | (rgpio_nec & nextc_sampled) ;
965 56 gorand
 
966 62 simont
`endif //  GPIO_NO_NEGEDGE_FLOPS
967 17 lampret
 
968 62 simont
assign in_muxed = (rgpio_eclk & extc_s)      | (~rgpio_eclk & ext_pad_s) ;
969 56 gorand
 
970
 
971 62 simont
`endif //  GPIO_SYNC_CLK_WB
972 56 gorand
 
973
 
974 62 simont
`else
975 56 gorand
 
976 62 simont
assign  in_muxed  = ext_pad_s ;
977 56 gorand
 
978 62 simont
`endif //  GPIO_CLKPAD
979 56 gorand
 
980
 
981
 
982 17 lampret
//
983
// Mux all registers when doing a read of GPIO registers
984
//
985 14 lampret
always @(wb_adr_i or rgpio_in or rgpio_out or rgpio_oe or rgpio_inte or
986 56 gorand
                rgpio_ptrig or rgpio_aux or rgpio_ctrl or rgpio_ints or rgpio_eclk or rgpio_nec)
987 14 lampret
        case (wb_adr_i[`GPIO_OFS_BITS]) // synopsys full_case parallel_case
988
`ifdef GPIO_READREGS
989 60 andreje
  `ifdef GPIO_RGPIO_OUT
990
        `GPIO_RGPIO_OUT: begin
991 26 lampret
                        wb_dat[dw-1:0] = rgpio_out;
992 14 lampret
                end
993 60 andreje
  `endif
994
  `ifdef GPIO_RGPIO_OE
995 14 lampret
                `GPIO_RGPIO_OE: begin
996 60 andreje
                        wb_dat[dw-1:0] = rgpio_oe;
997 14 lampret
                end
998 60 andreje
  `endif
999
  `ifdef GPIO_RGPIO_INTE
1000 14 lampret
                `GPIO_RGPIO_INTE: begin
1001 26 lampret
                        wb_dat[dw-1:0] = rgpio_inte;
1002 14 lampret
                end
1003 60 andreje
  `endif
1004
  `ifdef GPIO_RGPIO_PTRIG
1005 14 lampret
                `GPIO_RGPIO_PTRIG: begin
1006 26 lampret
                        wb_dat[dw-1:0] = rgpio_ptrig;
1007 14 lampret
                end
1008 60 andreje
  `endif
1009
  `ifdef GPIO_RGPIO_NEC
1010 56 gorand
                `GPIO_RGPIO_NEC: begin
1011
                        wb_dat[dw-1:0] = rgpio_nec;
1012
                end
1013 60 andreje
  `endif
1014
  `ifdef GPIO_RGPIO_ECLK
1015 56 gorand
                `GPIO_RGPIO_ECLK: begin
1016
                        wb_dat[dw-1:0] = rgpio_eclk;
1017
                end
1018 60 andreje
  `endif
1019
  `ifdef GPIO_RGPIO_AUX
1020 14 lampret
                `GPIO_RGPIO_AUX: begin
1021 26 lampret
                        wb_dat[dw-1:0] = rgpio_aux;
1022 14 lampret
                end
1023 60 andreje
  `endif
1024
  `ifdef GPIO_RGPIO_CTRL
1025 14 lampret
                `GPIO_RGPIO_CTRL: begin
1026 56 gorand
                        wb_dat[1:0] = rgpio_ctrl;
1027
                        wb_dat[dw-1:2] = {dw-2{1'b0}};
1028 14 lampret
                end
1029 60 andreje
  `endif
1030 14 lampret
`endif
1031 60 andreje
  `ifdef GPIO_RGPIO_INTS
1032 21 lampret
                `GPIO_RGPIO_INTS: begin
1033 26 lampret
                        wb_dat[dw-1:0] = rgpio_ints;
1034 21 lampret
                end
1035 60 andreje
  `endif
1036 14 lampret
                default: begin
1037 26 lampret
                        wb_dat[dw-1:0] = rgpio_in;
1038 14 lampret
                end
1039
        endcase
1040
 
1041
//
1042 17 lampret
// WB data output
1043
//
1044
`ifdef GPIO_REGISTERED_WB_OUTPUTS
1045
always @(posedge wb_clk_i or posedge wb_rst_i)
1046
        if (wb_rst_i)
1047
                wb_dat_o <= #1 {dw{1'b0}};
1048
        else
1049
                wb_dat_o <= #1 wb_dat;
1050
`else
1051
assign wb_dat_o = wb_dat;
1052
`endif
1053
 
1054
//
1055 21 lampret
// RGPIO_INTS
1056
//
1057
`ifdef GPIO_RGPIO_INTS
1058
always @(posedge wb_clk_i or posedge wb_rst_i)
1059
        if (wb_rst_i)
1060
                rgpio_ints <= #1 {gw{1'b0}};
1061
        else if (rgpio_ints_sel && wb_we_i)
1062
                rgpio_ints <= #1 wb_dat_i[gw-1:0];
1063 31 lampret
        else if (rgpio_ctrl[`GPIO_RGPIO_CTRL_INTE])
1064 62 simont
                rgpio_ints <= #1 (rgpio_ints | ((in_muxed ^ rgpio_in) & ~(in_muxed ^ rgpio_ptrig)) & rgpio_inte);
1065 21 lampret
`else
1066 62 simont
assign rgpio_ints = (rgpio_ints | ((in_muxed ^ rgpio_in) & ~(in_muxed ^ rgpio_ptrig)) & rgpio_inte);
1067 21 lampret
`endif
1068
 
1069
//
1070 14 lampret
// Generate interrupt request
1071
//
1072 21 lampret
assign wb_inta = |rgpio_ints ? rgpio_ctrl[`GPIO_RGPIO_CTRL_INTE] : 1'b0;
1073 14 lampret
 
1074
//
1075 17 lampret
// Optional registration of WB interrupt
1076 14 lampret
//
1077 17 lampret
`ifdef GPIO_REGISTERED_WB_OUTPUTS
1078
always @(posedge wb_clk_i or posedge wb_rst_i)
1079
        if (wb_rst_i)
1080 19 lampret
                wb_inta_o <= #1 1'b0;
1081 17 lampret
        else
1082
                wb_inta_o <= #1 wb_inta;
1083
`else
1084
assign wb_inta_o = wb_inta;
1085 62 simont
`endif // GPIO_REGISTERED_WB_OUTPUTS
1086 14 lampret
 
1087
//
1088 17 lampret
// Output enables are RGPIO_OE bits
1089 14 lampret
//
1090 60 andreje
assign ext_padoe_o = rgpio_oe;
1091 14 lampret
 
1092 17 lampret
//
1093
// Generate GPIO outputs
1094
//
1095 62 simont
`ifdef GPIO_AUX_IMPLEMENT
1096 17 lampret
assign out_pad = rgpio_out & ~rgpio_aux | aux_i & rgpio_aux;
1097 62 simont
`else
1098
assign out_pad = rgpio_out ;
1099
`endif //  GPIO_AUX_IMPLEMENT
1100 17 lampret
 
1101
//
1102
// Optional registration of GPIO outputs
1103
//
1104
`ifdef GPIO_REGISTERED_IO_OUTPUTS
1105
always @(posedge wb_clk_i or posedge wb_rst_i)
1106
        if (wb_rst_i)
1107 25 lampret
                ext_pad_o <= #1 {gw{1'b0}};
1108 17 lampret
        else
1109 25 lampret
                ext_pad_o <= #1 out_pad;
1110 14 lampret
`else
1111 25 lampret
assign ext_pad_o = out_pad;
1112 62 simont
`endif // GPIO_REGISTERED_IO_OUTPUTS
1113 14 lampret
 
1114 62 simont
 
1115 17 lampret
`else
1116
 
1117 14 lampret
//
1118
// When GPIO is not implemented, drive all outputs as would when RGPIO_CTRL
1119
// is cleared and WISHBONE transfers complete with errors
1120
//
1121
assign wb_inta_o = 1'b0;
1122
assign wb_ack_o = 1'b0;
1123
assign wb_err_o = wb_cyc_i & wb_stb_i;
1124 60 andreje
assign ext_padoe_o = {gw{1'b1}};
1125 25 lampret
assign ext_pad_o = {gw{1'b0}};
1126 14 lampret
 
1127
//
1128
// Read GPIO registers
1129
//
1130
assign wb_dat_o = {dw{1'b0}};
1131
 
1132 62 simont
`endif //  GPIO_IMPLEMENTED
1133 14 lampret
 
1134
endmodule
1135 56 gorand
 

powered by: WebSVN 2.1.0

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