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

Subversion Repositories can

[/] [can/] [tags/] [rel_22/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 125

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

powered by: WebSVN 2.1.0

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