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

Subversion Repositories can

[/] [can/] [tags/] [asyst_3/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 110

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

powered by: WebSVN 2.1.0

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