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 106

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

powered by: WebSVN 2.1.0

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