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

Subversion Repositories can

[/] [can/] [tags/] [rel_6/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 75

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

powered by: WebSVN 2.1.0

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