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

Subversion Repositories can

[/] [can/] [tags/] [rel_7/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 71

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 66 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  can_top.v                                                   ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the CAN Protocol Controller            ////
7
////  http://www.opencores.org/projects/can/                      ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is available in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2002, 2003 Authors                             ////
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
//// The CAN protocol is developed by Robert Bosch GmbH and       ////
44
//// protected by patents. Anybody who wants to implement this    ////
45
//// CAN IP core on silicon has to obtain a CAN protocol license  ////
46
//// from Bosch.                                                  ////
47
////                                                              ////
48
//////////////////////////////////////////////////////////////////////
49
//
50
// CVS Revision History
51
//
52
// $Log: not supported by cvs2svn $
53 71 mohor
// Revision 1.31  2003/03/26 11:19:46  mohor
54
// CAN interrupt is active low.
55
//
56 67 mohor
// Revision 1.30  2003/03/20 17:01:17  mohor
57
// unix.
58
//
59 66 mohor
// Revision 1.28  2003/03/14 19:36:48  mohor
60
// can_cs signal used for generation of the cs.
61
//
62
// Revision 1.27  2003/03/12 05:56:33  mohor
63
// Bidirectional port_0_i changed to port_0_io.
64
// input cs_can changed to cs_can_i.
65
//
66
// Revision 1.26  2003/03/12 04:39:40  mohor
67
// rd_i and wr_i are active high signals. If 8051 is connected, these two signals
68
// need to be negated one level higher.
69
//
70
// Revision 1.25  2003/03/12 04:17:36  mohor
71
// 8051 interface added (besides WISHBONE interface). Selection is made in
72
// can_defines.v file.
73
//
74
// Revision 1.24  2003/03/10 17:24:40  mohor
75
// wire declaration added.
76
//
77
// Revision 1.23  2003/03/05 15:33:13  mohor
78
// tx_o is now tristated signal. tx_oen and tx_o combined together.
79
//
80
// Revision 1.22  2003/03/05 15:01:56  mohor
81
// Top level signal names changed.
82
//
83
// Revision 1.21  2003/03/01 22:53:33  mohor
84
// Actel APA ram supported.
85
//
86
// Revision 1.20  2003/02/19 15:09:02  mohor
87
// Incomplete sensitivity list fixed.
88
//
89
// Revision 1.19  2003/02/19 15:04:14  mohor
90
// Typo fixed.
91
//
92
// Revision 1.18  2003/02/19 14:44:03  mohor
93
// CAN core finished. Host interface added. Registers finished.
94
// Synchronization to the wishbone finished.
95
//
96
// Revision 1.17  2003/02/18 00:10:15  mohor
97
// Most of the registers added. Registers "arbitration lost capture", "error code
98
// capture" + few more still need to be added.
99
//
100
// Revision 1.16  2003/02/14 20:17:01  mohor
101
// Several registers added. Not finished, yet.
102
//
103
// Revision 1.15  2003/02/12 14:25:30  mohor
104
// abort_tx added.
105
//
106
// Revision 1.14  2003/02/11 00:56:06  mohor
107
// Wishbone interface added.
108
//
109
// Revision 1.13  2003/02/09 18:40:29  mohor
110
// Overload fixed. Hard synchronization also enabled at the last bit of
111
// interframe.
112
//
113
// Revision 1.12  2003/02/09 02:24:33  mohor
114
// Bosch license warning added. Error counters finished. Overload frames
115
// still need to be fixed.
116
//
117
// Revision 1.11  2003/02/04 14:34:52  mohor
118
// *** empty log message ***
119
//
120
// Revision 1.10  2003/01/31 01:13:38  mohor
121
// backup.
122
//
123
// Revision 1.9  2003/01/15 13:16:48  mohor
124
// When a frame with "remote request" is received, no data is stored to
125
// fifo, just the frame information (identifier, ...). Data length that
126
// is stored is the received data length and not the actual data length
127
// that is stored to fifo.
128
//
129
// Revision 1.8  2003/01/14 17:25:09  mohor
130
// Addresses corrected to decimal values (previously hex).
131
//
132
// Revision 1.7  2003/01/10 17:51:34  mohor
133
// Temporary version (backup).
134
//
135
// Revision 1.6  2003/01/09 21:54:45  mohor
136
// rx fifo added. Not 100 % verified, yet.
137
//
138
// Revision 1.5  2003/01/08 02:10:56  mohor
139
// Acceptance filter added.
140
//
141
// Revision 1.4  2002/12/28 04:13:23  mohor
142
// Backup version.
143
//
144
// Revision 1.3  2002/12/27 00:12:52  mohor
145
// Header changed, testbench improved to send a frame (crc still missing).
146
//
147
// Revision 1.2  2002/12/26 16:00:34  mohor
148
// Testbench define file added. Clock divider register added.
149
//
150
// Revision 1.1.1.1  2002/12/20 16:39:21  mohor
151
// Initial
152
//
153
//
154
//
155
 
156
// synopsys translate_off
157
`include "timescale.v"
158
// synopsys translate_on
159
`include "can_defines.v"
160
 
161
module can_top
162
(
163
  `ifdef CAN_WISHBONE_IF
164
    wb_clk_i,
165
    wb_rst_i,
166
    wb_dat_i,
167
    wb_dat_o,
168
    wb_cyc_i,
169
    wb_stb_i,
170
    wb_we_i,
171
    wb_adr_i,
172
    wb_ack_o,
173
  `else
174
    rst_i,
175
    ale_i,
176
    rd_i,
177
    wr_i,
178
    port_0_io,
179
  `endif
180
  cs_can_i,
181
  clk_i,
182
  rx_i,
183
  tx_o,
184 67 mohor
  irq_on,
185 66 mohor
  clkout_o
186 71 mohor
  // Bist
187
`ifdef CAN_BIST
188
  ,
189
  // debug chain signals
190
  scanb_rst,      // bist scan reset
191
  scanb_clk,      // bist scan clock
192
  scanb_si,       // bist scan serial in
193
  scanb_so,       // bist scan serial out
194
  scanb_en        // bist scan shift enable
195
`endif
196 66 mohor
);
197
 
198
parameter Tp = 1;
199
 
200
`ifdef CAN_WISHBONE_IF
201
  input        wb_clk_i;
202
  input        wb_rst_i;
203
  input  [7:0] wb_dat_i;
204
  output [7:0] wb_dat_o;
205
  input        wb_cyc_i;
206
  input        wb_stb_i;
207
  input        wb_we_i;
208
  input  [7:0] wb_adr_i;
209
  output       wb_ack_o;
210
 
211
  reg          wb_ack_o;
212
  reg          cs_sync1;
213
  reg          cs_sync2;
214
  reg          cs_sync3;
215
 
216
  reg          cs_ack1;
217
  reg          cs_ack2;
218
  reg          cs_ack3;
219
  reg          cs_sync_rst1;
220
  reg          cs_sync_rst2;
221
`else
222
  input        rst_i;
223
  input        ale_i;
224
  input        rd_i;
225
  input        wr_i;
226
  inout  [7:0] port_0_io;
227
 
228
  reg    [7:0] addr_latched;
229
  reg          wr_i_q;
230
  reg          rd_i_q;
231
`endif
232
 
233
input        cs_can_i;
234
input        clk_i;
235
input        rx_i;
236
output       tx_o;
237 67 mohor
output       irq_on;
238 66 mohor
output       clkout_o;
239
 
240 71 mohor
// Bist
241
`ifdef CAN_BIST
242
input   scanb_rst;      // bist scan reset
243
input   scanb_clk;      // bist scan clock
244
input   scanb_si;       // bist scan serial in
245
output  scanb_so;       // bist scan serial out
246
input   scanb_en;       // bist scan shift enable
247
`endif
248
 
249 66 mohor
reg          data_out_fifo_selected;
250
 
251
 
252 67 mohor
wire         irq_o;
253 66 mohor
wire   [7:0] data_out_fifo;
254
wire   [7:0] data_out_regs;
255
 
256
 
257
/* Mode register */
258
wire         reset_mode;
259
wire         listen_only_mode;
260
wire         acceptance_filter_mode;
261
wire         self_test_mode;
262
 
263
/* Command register */
264
wire         release_buffer;
265
wire         tx_request;
266
wire         abort_tx;
267
wire         self_rx_request;
268
wire         single_shot_transmission;
269
 
270
/* Arbitration Lost Capture Register */
271
wire         read_arbitration_lost_capture_reg;
272
 
273
/* Error Code Capture Register */
274
wire         read_error_code_capture_reg;
275
wire   [7:0] error_capture_code;
276
 
277
/* Bus Timing 0 register */
278
wire   [5:0] baud_r_presc;
279
wire   [1:0] sync_jump_width;
280
 
281
/* Bus Timing 1 register */
282
wire   [3:0] time_segment1;
283
wire   [2:0] time_segment2;
284
wire         triple_sampling;
285
 
286
/* Error Warning Limit register */
287
wire   [7:0] error_warning_limit;
288
 
289
/* Rx Error Counter register */
290
wire         we_rx_err_cnt;
291
 
292
/* Tx Error Counter register */
293
wire         we_tx_err_cnt;
294
 
295
/* Clock Divider register */
296
wire         extended_mode;
297
 
298
/* This section is for BASIC and EXTENDED mode */
299
/* Acceptance code register */
300
wire   [7:0] acceptance_code_0;
301
 
302
/* Acceptance mask register */
303
wire   [7:0] acceptance_mask_0;
304
/* End: This section is for BASIC and EXTENDED mode */
305
 
306
 
307
/* This section is for EXTENDED mode */
308
/* Acceptance code register */
309
wire   [7:0] acceptance_code_1;
310
wire   [7:0] acceptance_code_2;
311
wire   [7:0] acceptance_code_3;
312
 
313
/* Acceptance mask register */
314
wire   [7:0] acceptance_mask_1;
315
wire   [7:0] acceptance_mask_2;
316
wire   [7:0] acceptance_mask_3;
317
/* End: This section is for EXTENDED mode */
318
 
319
/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
320
wire   [7:0] tx_data_0;
321
wire   [7:0] tx_data_1;
322
wire   [7:0] tx_data_2;
323
wire   [7:0] tx_data_3;
324
wire   [7:0] tx_data_4;
325
wire   [7:0] tx_data_5;
326
wire   [7:0] tx_data_6;
327
wire   [7:0] tx_data_7;
328
wire   [7:0] tx_data_8;
329
wire   [7:0] tx_data_9;
330
wire   [7:0] tx_data_10;
331
wire   [7:0] tx_data_11;
332
wire   [7:0] tx_data_12;
333
/* End: Tx data registers */
334
 
335
wire         cs;
336
 
337
/* Output signals from can_btl module */
338
wire         clk_en;
339
wire         sample_point;
340
wire         sampled_bit;
341
wire         sampled_bit_q;
342
wire         tx_point;
343
wire         hard_sync;
344
wire         resync;
345
 
346
 
347
/* output from can_bsp module */
348
wire         rx_idle;
349
wire         transmitting;
350
wire         last_bit_of_inter;
351
wire         set_reset_mode;
352
wire         node_bus_off;
353
wire         error_status;
354
wire   [7:0] rx_err_cnt;
355
wire   [7:0] tx_err_cnt;
356
wire         rx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
357
wire         tx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
358
wire         transmit_status;
359
wire         receive_status;
360
wire         tx_successful;
361
wire         need_to_tx;
362
wire         overrun;
363
wire         info_empty;
364
wire         set_bus_error_irq;
365
wire         set_arbitration_lost_irq;
366
wire   [4:0] arbitration_lost_capture;
367
wire         node_error_passive;
368
wire         node_error_active;
369
wire   [6:0] rx_message_counter;
370
wire         tx_out;
371
wire         tx_oen;
372
 
373
wire         rst;
374
wire         we;
375
wire   [7:0] addr;
376
wire   [7:0] data_in;
377
reg    [7:0] data_out;
378
 
379
 
380
/* Connecting can_registers module */
381
can_registers i_can_registers
382
(
383
  .clk(clk_i),
384
  .rst(rst),
385
  .cs(cs),
386
  .we(we),
387
  .addr(addr),
388
  .data_in(data_in),
389
  .data_out(data_out_regs),
390
  .irq(irq_o),
391
 
392
  .sample_point(sample_point),
393
  .transmitting(transmitting),
394
  .set_reset_mode(set_reset_mode),
395
  .node_bus_off(node_bus_off),
396
  .error_status(error_status),
397
  .rx_err_cnt(rx_err_cnt),
398
  .tx_err_cnt(tx_err_cnt),
399
  .transmit_status(transmit_status),
400
  .receive_status(receive_status),
401
  .tx_successful(tx_successful),
402
  .need_to_tx(need_to_tx),
403
  .overrun(overrun),
404
  .info_empty(info_empty),
405
  .set_bus_error_irq(set_bus_error_irq),
406
  .set_arbitration_lost_irq(set_arbitration_lost_irq),
407
  .arbitration_lost_capture(arbitration_lost_capture),
408
  .node_error_passive(node_error_passive),
409
  .node_error_active(node_error_active),
410
  .rx_message_counter(rx_message_counter),
411
 
412
 
413
  /* Mode register */
414
  .reset_mode(reset_mode),
415
  .listen_only_mode(listen_only_mode),
416
  .acceptance_filter_mode(acceptance_filter_mode),
417
  .self_test_mode(self_test_mode),
418
 
419
  /* Command register */
420
  .clear_data_overrun(),
421
  .release_buffer(release_buffer),
422
  .abort_tx(abort_tx),
423
  .tx_request(tx_request),
424
  .self_rx_request(self_rx_request),
425
  .single_shot_transmission(single_shot_transmission),
426
 
427
  /* Arbitration Lost Capture Register */
428
  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),
429
 
430
  /* Error Code Capture Register */
431
  .read_error_code_capture_reg(read_error_code_capture_reg),
432
  .error_capture_code(error_capture_code),
433
 
434
  /* Bus Timing 0 register */
435
  .baud_r_presc(baud_r_presc),
436
  .sync_jump_width(sync_jump_width),
437
 
438
  /* Bus Timing 1 register */
439
  .time_segment1(time_segment1),
440
  .time_segment2(time_segment2),
441
  .triple_sampling(triple_sampling),
442
 
443
  /* Error Warning Limit register */
444
  .error_warning_limit(error_warning_limit),
445
 
446
  /* Rx Error Counter register */
447
  .we_rx_err_cnt(we_rx_err_cnt),
448
 
449
  /* Tx Error Counter register */
450
  .we_tx_err_cnt(we_tx_err_cnt),
451
 
452
  /* Clock Divider register */
453
  .extended_mode(extended_mode),
454
  .clkout(clkout_o),
455
 
456
  /* This section is for BASIC and EXTENDED mode */
457
  /* Acceptance code register */
458
  .acceptance_code_0(acceptance_code_0),
459
 
460
  /* Acceptance mask register */
461
  .acceptance_mask_0(acceptance_mask_0),
462
  /* End: This section is for BASIC and EXTENDED mode */
463
 
464
  /* This section is for EXTENDED mode */
465
  /* Acceptance code register */
466
  .acceptance_code_1(acceptance_code_1),
467
  .acceptance_code_2(acceptance_code_2),
468
  .acceptance_code_3(acceptance_code_3),
469
 
470
  /* Acceptance mask register */
471
  .acceptance_mask_1(acceptance_mask_1),
472
  .acceptance_mask_2(acceptance_mask_2),
473
  .acceptance_mask_3(acceptance_mask_3),
474
  /* End: This section is for EXTENDED mode */
475
 
476
  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
477
  .tx_data_0(tx_data_0),
478
  .tx_data_1(tx_data_1),
479
  .tx_data_2(tx_data_2),
480
  .tx_data_3(tx_data_3),
481
  .tx_data_4(tx_data_4),
482
  .tx_data_5(tx_data_5),
483
  .tx_data_6(tx_data_6),
484
  .tx_data_7(tx_data_7),
485
  .tx_data_8(tx_data_8),
486
  .tx_data_9(tx_data_9),
487
  .tx_data_10(tx_data_10),
488
  .tx_data_11(tx_data_11),
489
  .tx_data_12(tx_data_12)
490
  /* End: Tx data registers */
491
);
492
 
493
 
494 67 mohor
assign irq_on = ~irq_o;
495 66 mohor
 
496
 
497
/* Connecting can_btl module */
498
can_btl i_can_btl
499
(
500
  .clk(clk_i),
501
  .rst(rst),
502
  .rx(rx_i),
503
 
504
  /* Mode register */
505
  .reset_mode(reset_mode),
506
 
507
  /* Bus Timing 0 register */
508
  .baud_r_presc(baud_r_presc),
509
  .sync_jump_width(sync_jump_width),
510
 
511
  /* Bus Timing 1 register */
512
  .time_segment1(time_segment1),
513
  .time_segment2(time_segment2),
514
  .triple_sampling(triple_sampling),
515
 
516
  /* Output signals from this module */
517
  .clk_en(clk_en),
518
  .sample_point(sample_point),
519
  .sampled_bit(sampled_bit),
520
  .sampled_bit_q(sampled_bit_q),
521
  .tx_point(tx_point),
522
  .hard_sync(hard_sync),
523
  .resync(resync),
524
 
525
 
526
  /* output from can_bsp module */
527
  .rx_idle(rx_idle),
528
  .transmitting(transmitting),
529
  .last_bit_of_inter(last_bit_of_inter)
530
 
531
 
532
 
533
);
534
 
535
 
536
 
537
can_bsp i_can_bsp
538
(
539
  .clk(clk_i),
540
  .rst(rst),
541
 
542
  /* From btl module */
543
  .sample_point(sample_point),
544
  .sampled_bit(sampled_bit),
545
  .sampled_bit_q(sampled_bit_q),
546
  .tx_point(tx_point),
547
  .hard_sync(hard_sync),
548
 
549
  .addr(addr),
550
  .data_in(data_in),
551
  .data_out(data_out_fifo),
552
  .fifo_selected(data_out_fifo_selected),
553
 
554
  /* Mode register */
555
  .reset_mode(reset_mode),
556
  .listen_only_mode(listen_only_mode),
557
  .acceptance_filter_mode(acceptance_filter_mode),
558
  .self_test_mode(self_test_mode),
559
 
560
  /* Command register */
561
  .release_buffer(release_buffer),
562
  .tx_request(tx_request),
563
  .abort_tx(abort_tx),
564
  .self_rx_request(self_rx_request),
565
  .single_shot_transmission(single_shot_transmission),
566
 
567
  /* Arbitration Lost Capture Register */
568
  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),
569
 
570
  /* Error Code Capture Register */
571
  .read_error_code_capture_reg(read_error_code_capture_reg),
572
  .error_capture_code(error_capture_code),
573
 
574
  /* Error Warning Limit register */
575
  .error_warning_limit(error_warning_limit),
576
 
577
  /* Rx Error Counter register */
578
  .we_rx_err_cnt(we_rx_err_cnt),
579
 
580
  /* Tx Error Counter register */
581
  .we_tx_err_cnt(we_tx_err_cnt),
582
 
583
  /* Clock Divider register */
584
  .extended_mode(extended_mode),
585
 
586
  /* output from can_bsp module */
587
  .rx_idle(rx_idle),
588
  .transmitting(transmitting),
589
  .last_bit_of_inter(last_bit_of_inter),
590
  .set_reset_mode(set_reset_mode),
591
  .node_bus_off(node_bus_off),
592
  .error_status(error_status),
593
  .rx_err_cnt({rx_err_cnt_dummy, rx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
594
  .tx_err_cnt({tx_err_cnt_dummy, tx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
595
  .transmit_status(transmit_status),
596
  .receive_status(receive_status),
597
  .tx_successful(tx_successful),
598
  .need_to_tx(need_to_tx),
599
  .overrun(overrun),
600
  .info_empty(info_empty),
601
  .set_bus_error_irq(set_bus_error_irq),
602
  .set_arbitration_lost_irq(set_arbitration_lost_irq),
603
  .arbitration_lost_capture(arbitration_lost_capture),
604
  .node_error_passive(node_error_passive),
605
  .node_error_active(node_error_active),
606
  .rx_message_counter(rx_message_counter),
607
 
608
  /* This section is for BASIC and EXTENDED mode */
609
  /* Acceptance code register */
610
  .acceptance_code_0(acceptance_code_0),
611
 
612
  /* Acceptance mask register */
613
  .acceptance_mask_0(acceptance_mask_0),
614
  /* End: This section is for BASIC and EXTENDED mode */
615
 
616
  /* This section is for EXTENDED mode */
617
  /* Acceptance code register */
618
  .acceptance_code_1(acceptance_code_1),
619
  .acceptance_code_2(acceptance_code_2),
620
  .acceptance_code_3(acceptance_code_3),
621
 
622
  /* Acceptance mask register */
623
  .acceptance_mask_1(acceptance_mask_1),
624
  .acceptance_mask_2(acceptance_mask_2),
625
  .acceptance_mask_3(acceptance_mask_3),
626
  /* End: This section is for EXTENDED mode */
627
 
628
  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
629
  .tx_data_0(tx_data_0),
630
  .tx_data_1(tx_data_1),
631
  .tx_data_2(tx_data_2),
632
  .tx_data_3(tx_data_3),
633
  .tx_data_4(tx_data_4),
634
  .tx_data_5(tx_data_5),
635
  .tx_data_6(tx_data_6),
636
  .tx_data_7(tx_data_7),
637
  .tx_data_8(tx_data_8),
638
  .tx_data_9(tx_data_9),
639
  .tx_data_10(tx_data_10),
640
  .tx_data_11(tx_data_11),
641
  .tx_data_12(tx_data_12),
642
  /* End: Tx data registers */
643
 
644
  /* Tx signal */
645
  .tx(tx_out),
646
  .tx_oen(tx_oen)
647
);
648
 
649
assign tx_o = tx_oen? 1'bz : tx_out;
650
 
651
 
652
// Multiplexing wb_dat_o from registers and rx fifo
653
always @ (extended_mode or addr or reset_mode)
654
begin
655
  if (extended_mode & (~reset_mode) & ((addr >= 8'd16) && (addr <= 8'd28)) | (~extended_mode) & ((addr >= 8'd20) && (addr <= 8'd29)))
656
    data_out_fifo_selected <= 1'b1;
657
  else
658
    data_out_fifo_selected <= 1'b0;
659
end
660
 
661
 
662
always @ (posedge clk_i)
663
begin
664
//  if (wb_cyc_i & (~wb_we_i))
665
  if (cs & (~we))
666
    begin
667
      if (data_out_fifo_selected)
668
        data_out <=#Tp data_out_fifo;
669
      else
670
        data_out <=#Tp data_out_regs;
671
    end
672
end
673
 
674
 
675
 
676
`ifdef CAN_WISHBONE_IF
677
  // Combining wb_cyc_i and wb_stb_i signals to cs signal. Than synchronizing to clk_i clock domain. 
678
  always @ (posedge clk_i or posedge rst)
679
  begin
680
    if (rst)
681
      begin
682
        cs_sync1     <= 1'b0;
683
        cs_sync2     <= 1'b0;
684
        cs_sync3     <= 1'b0;
685
        cs_sync_rst1 <= 1'b0;
686
        cs_sync_rst2 <= 1'b0;
687
      end
688
    else
689
      begin
690
        cs_sync1     <=#Tp wb_cyc_i & wb_stb_i & (~cs_sync_rst2) & cs_can_i;
691
        cs_sync2     <=#Tp cs_sync1            & (~cs_sync_rst2);
692
        cs_sync3     <=#Tp cs_sync2            & (~cs_sync_rst2);
693
        cs_sync_rst1 <=#Tp cs_ack3;
694
        cs_sync_rst2 <=#Tp cs_sync_rst1;
695
      end
696
  end
697
 
698
 
699
  assign cs = cs_sync2 & (~cs_sync3);
700
 
701
 
702
  always @ (posedge wb_clk_i)
703
  begin
704
    cs_ack1 <=#Tp cs_sync3;
705
    cs_ack2 <=#Tp cs_ack1;
706
    cs_ack3 <=#Tp cs_ack2;
707
  end
708
 
709
 
710
 
711
  // Generating acknowledge signal
712
  always @ (posedge wb_clk_i)
713
  begin
714
    wb_ack_o <=#Tp (cs_ack2 & (~cs_ack3));
715
  end
716
 
717
 
718
  assign rst      = wb_rst_i;
719
  assign we       = wb_we_i;
720
  assign addr     = wb_adr_i;
721
  assign data_in  = wb_dat_i;
722
  assign wb_dat_o = data_out;
723
 
724
 
725
`else
726
 
727
  // Latching address
728
  always @ (negedge clk_i or posedge rst)
729
  begin
730
    if (rst)
731
      addr_latched <= 8'h0;
732
    else if (ale_i)
733
      addr_latched <=#Tp port_0_io;
734
  end
735
 
736
 
737
  // Generating delayed wr_i and rd_i signals
738
  always @ (posedge clk_i or posedge rst)
739
  begin
740
    if (rst)
741
      begin
742
        wr_i_q <= 1'b0;
743
        rd_i_q <= 1'b0;
744
      end
745
    else
746
      begin
747
        wr_i_q <=#Tp wr_i;
748
        rd_i_q <=#Tp rd_i;
749
      end
750
  end
751
 
752
 
753
  assign cs = ((wr_i & (~wr_i_q)) | (rd_i & (~rd_i_q))) & cs_can_i;
754
 
755
 
756
  assign rst       = rst_i;
757
  assign we        = wr_i;
758
  assign addr      = addr_latched;
759
  assign data_in   = port_0_io;
760
  assign port_0_io = (cs_can_i & rd_i)? data_out : 8'hz;
761
 
762
`endif
763
 
764
endmodule

powered by: WebSVN 2.1.0

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