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 130

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

powered by: WebSVN 2.1.0

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