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

Subversion Repositories can

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

powered by: WebSVN 2.1.0

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