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 161

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

powered by: WebSVN 2.1.0

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