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

Subversion Repositories can

[/] [can/] [trunk/] [rtl/] [verilog/] [can_bsp.v] - Blame information for rev 126

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  can_bsp.v                                                   ////
4
////                                                              ////
5
////                                                              ////
6 9 mohor
////  This file is part of the CAN Protocol Controller            ////
7 2 mohor
////  http://www.opencores.org/projects/can/                      ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15 9 mohor
////  All additional information is available in the README.txt   ////
16 2 mohor
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20 9 mohor
//// Copyright (C) 2002, 2003 Authors                             ////
21 2 mohor
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43 28 mohor
//// 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 2 mohor
//////////////////////////////////////////////////////////////////////
49
//
50
// CVS Revision History
51
//
52
// $Log: not supported by cvs2svn $
53 126 mohor
// Revision 1.43  2003/09/25 18:55:49  mohor
54
// Synchronization changed, error counters fixed.
55
//
56 125 mohor
// Revision 1.42  2003/08/29 07:01:14  mohor
57
// When detecting bus-free, signal bus_free_cnt_en was cleared to zero
58
// although the last sampled bit was zero instead of one.
59
//
60 121 mohor
// Revision 1.41  2003/07/18 15:23:31  tadejm
61
// Tx and rx length are limited to 8 bytes regardless to the DLC value.
62
//
63 112 tadejm
// Revision 1.40  2003/07/16 15:10:17  mohor
64
// Fixed according to the linter.
65
//
66 110 mohor
// Revision 1.39  2003/07/16 13:12:46  mohor
67
// Fixed according to the linter.
68
//
69 107 mohor
// Revision 1.38  2003/07/10 01:59:04  tadejm
70
// Synchronization fixed. In some strange cases it didn't work according to
71
// the VHDL reference model.
72
//
73 104 tadejm
// Revision 1.37  2003/07/07 11:21:37  mohor
74
// Little fixes (to fix warnings).
75
//
76 102 mohor
// Revision 1.36  2003/07/03 09:32:20  mohor
77
// Synchronization changed.
78
//
79 100 mohor
// Revision 1.35  2003/06/27 20:56:12  simons
80
// Virtual silicon ram instances added.
81
//
82 95 simons
// Revision 1.34  2003/06/22 09:43:03  mohor
83 102 mohor
// synthesi full_case parallel_case fixed.
84 95 simons
//
85 93 mohor
// Revision 1.33  2003/06/21 12:16:30  mohor
86
// paralel_case and full_case compiler directives added to case statements.
87
//
88 90 mohor
// Revision 1.32  2003/06/17 14:28:32  mohor
89
// Form error was detected when stuff bit occured at the end of crc.
90
//
91 80 mohor
// Revision 1.31  2003/06/16 14:31:29  tadejm
92
// Bit stuffing corrected when stuffing comes at the end of the crc.
93
//
94 79 tadejm
// Revision 1.30  2003/06/16 13:57:58  mohor
95
// tx_point generated one clk earlier. rx_i registered. Data corrected when
96
// using extended mode.
97
//
98 78 mohor
// Revision 1.29  2003/06/11 14:21:35  mohor
99
// When switching to tx, sync stage is overjumped.
100
//
101 75 mohor
// Revision 1.28  2003/03/01 22:53:33  mohor
102
// Actel APA ram supported.
103
//
104 48 mohor
// Revision 1.27  2003/02/20 00:26:02  mohor
105
// When a dominant bit was detected at the third bit of the intermission and
106
// node had a message to transmit, bit_stuff error could occur. Fixed.
107
//
108 45 mohor
// Revision 1.26  2003/02/19 23:21:54  mohor
109
// When bit error occured while active error flag was transmitted, counter was
110
// not incremented.
111
//
112 44 mohor
// Revision 1.25  2003/02/19 14:44:03  mohor
113
// CAN core finished. Host interface added. Registers finished.
114
// Synchronization to the wishbone finished.
115
//
116 39 mohor
// Revision 1.24  2003/02/18 00:10:15  mohor
117
// Most of the registers added. Registers "arbitration lost capture", "error code
118
// capture" + few more still need to be added.
119
//
120 36 mohor
// Revision 1.23  2003/02/14 20:17:01  mohor
121
// Several registers added. Not finished, yet.
122
//
123 35 mohor
// Revision 1.22  2003/02/12 14:23:59  mohor
124
// abort_tx added. Bit destuff fixed.
125
//
126 32 mohor
// Revision 1.21  2003/02/11 00:56:06  mohor
127
// Wishbone interface added.
128
//
129 31 mohor
// Revision 1.20  2003/02/10 16:02:11  mohor
130
// CAN is working according to the specification. WB interface and more
131
// registers (status, IRQ, ...) needs to be added.
132
//
133 30 mohor
// Revision 1.19  2003/02/09 18:40:29  mohor
134
// Overload fixed. Hard synchronization also enabled at the last bit of
135
// interframe.
136
//
137 29 mohor
// Revision 1.18  2003/02/09 02:24:33  mohor
138
// Bosch license warning added. Error counters finished. Overload frames
139
// still need to be fixed.
140
//
141 28 mohor
// Revision 1.17  2003/02/04 17:24:41  mohor
142
// Backup.
143
//
144 26 mohor
// Revision 1.16  2003/02/04 14:34:52  mohor
145
// *** empty log message ***
146
//
147 25 mohor
// Revision 1.15  2003/01/31 01:13:37  mohor
148
// backup.
149
//
150 24 mohor
// Revision 1.14  2003/01/16 13:36:19  mohor
151
// Form error supported. When receiving messages, last bit of the end-of-frame
152
// does not generate form error. Receiver goes to the idle mode one bit sooner.
153
// (CAN specification ver 2.0, part B, page 57).
154
//
155 22 mohor
// Revision 1.13  2003/01/15 21:59:45  mohor
156
// Data is stored to fifo at the end of ack stage.
157
//
158 21 mohor
// Revision 1.12  2003/01/15 21:05:11  mohor
159
// CRC checking fixed (when bitstuff occurs at the end of a CRC sequence).
160
//
161 20 mohor
// Revision 1.11  2003/01/15 14:40:23  mohor
162 31 mohor
// RX state machine fixed to receive "remote request" frames correctly.
163
// No data bytes are written to fifo when such frames are received.
164 20 mohor
//
165 19 mohor
// Revision 1.10  2003/01/15 13:16:47  mohor
166 31 mohor
// When a frame with "remote request" is received, no data is stored to
167
// fifo, just the frame information (identifier, ...). Data length that
168
// is stored is the received data length and not the actual data length
169
// that is stored to fifo.
170 19 mohor
//
171 18 mohor
// Revision 1.9  2003/01/14 12:19:35  mohor
172
// rx_fifo is now working.
173
//
174 16 mohor
// Revision 1.8  2003/01/10 17:51:33  mohor
175
// Temporary version (backup).
176
//
177 15 mohor
// Revision 1.7  2003/01/09 21:54:45  mohor
178
// rx fifo added. Not 100 % verified, yet.
179
//
180 14 mohor
// Revision 1.6  2003/01/09 14:46:58  mohor
181
// Temporary files (backup).
182
//
183 13 mohor
// Revision 1.5  2003/01/08 13:30:31  mohor
184
// Temp version.
185
//
186 12 mohor
// Revision 1.4  2003/01/08 02:10:53  mohor
187
// Acceptance filter added.
188
//
189 11 mohor
// Revision 1.3  2002/12/28 04:13:23  mohor
190
// Backup version.
191
//
192 10 mohor
// Revision 1.2  2002/12/27 00:12:52  mohor
193
// Header changed, testbench improved to send a frame (crc still missing).
194
//
195 9 mohor
// Revision 1.1.1.1  2002/12/20 16:39:21  mohor
196
// Initial
197 2 mohor
//
198
//
199 9 mohor
//
200 2 mohor
 
201
// synopsys translate_off
202
`include "timescale.v"
203
// synopsys translate_on
204
`include "can_defines.v"
205
 
206
module can_bsp
207
(
208
  clk,
209 10 mohor
  rst,
210
 
211
  sample_point,
212
  sampled_bit,
213
  sampled_bit_q,
214 24 mohor
  tx_point,
215 11 mohor
  hard_sync,
216
 
217 14 mohor
  addr,
218 35 mohor
  data_in,
219 14 mohor
  data_out,
220 48 mohor
  fifo_selected,
221 35 mohor
 
222 14 mohor
 
223
 
224 11 mohor
  /* Mode register */
225 10 mohor
  reset_mode,
226 36 mohor
  listen_only_mode,
227 11 mohor
  acceptance_filter_mode,
228 36 mohor
  self_test_mode,
229 11 mohor
 
230 15 mohor
  /* Command register */
231
  release_buffer,
232 25 mohor
  tx_request,
233 32 mohor
  abort_tx,
234 36 mohor
  self_rx_request,
235
  single_shot_transmission,
236 104 tadejm
  tx_state,
237
  tx_state_q,
238 125 mohor
  overload_request,
239
  overload_frame,
240 15 mohor
 
241 39 mohor
  /* Arbitration Lost Capture Register */
242
  read_arbitration_lost_capture_reg,
243
 
244
  /* Error Code Capture Register */
245
  read_error_code_capture_reg,
246
  error_capture_code,
247
 
248 35 mohor
  /* Error Warning Limit register */
249
  error_warning_limit,
250
 
251
  /* Rx Error Counter register */
252
  we_rx_err_cnt,
253
 
254
  /* Tx Error Counter register */
255
  we_tx_err_cnt,
256
 
257 15 mohor
  /* Clock Divider register */
258 11 mohor
  extended_mode,
259
 
260
  rx_idle,
261 24 mohor
  transmitting,
262 125 mohor
  transmitter,
263 100 mohor
  go_rx_inter,
264 104 tadejm
  not_first_bit_of_inter,
265 126 mohor
  rx_inter,
266 35 mohor
  set_reset_mode,
267
  node_bus_off,
268
  error_status,
269
  rx_err_cnt,
270
  tx_err_cnt,
271
  transmit_status,
272
  receive_status,
273
  tx_successful,
274
  need_to_tx,
275
  overrun,
276
  info_empty,
277 39 mohor
  set_bus_error_irq,
278
  set_arbitration_lost_irq,
279
  arbitration_lost_capture,
280 36 mohor
  node_error_passive,
281
  node_error_active,
282 39 mohor
  rx_message_counter,
283 11 mohor
 
284 35 mohor
 
285 36 mohor
 
286 11 mohor
  /* This section is for BASIC and EXTENDED mode */
287
  /* Acceptance code register */
288
  acceptance_code_0,
289
 
290
  /* Acceptance mask register */
291
  acceptance_mask_0,
292
  /* End: This section is for BASIC and EXTENDED mode */
293 10 mohor
 
294 11 mohor
  /* This section is for EXTENDED mode */
295
  /* Acceptance code register */
296
  acceptance_code_1,
297
  acceptance_code_2,
298
  acceptance_code_3,
299 10 mohor
 
300 11 mohor
  /* Acceptance mask register */
301
  acceptance_mask_1,
302
  acceptance_mask_2,
303 18 mohor
  acceptance_mask_3,
304 11 mohor
  /* End: This section is for EXTENDED mode */
305 10 mohor
 
306 18 mohor
  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
307
  tx_data_0,
308
  tx_data_1,
309
  tx_data_2,
310
  tx_data_3,
311
  tx_data_4,
312
  tx_data_5,
313
  tx_data_6,
314
  tx_data_7,
315
  tx_data_8,
316
  tx_data_9,
317
  tx_data_10,
318
  tx_data_11,
319 24 mohor
  tx_data_12,
320 18 mohor
  /* End: Tx data registers */
321 24 mohor
 
322
  /* Tx signal */
323 28 mohor
  tx,
324 125 mohor
  tx_next,
325
  tx_oen,
326 18 mohor
 
327 125 mohor
  go_overload_frame,
328
  go_error_frame,
329
  go_tx,
330
  send_ack
331
 
332 95 simons
  /* Bist */
333
`ifdef CAN_BIST
334
  ,
335
  scanb_rst,
336
  scanb_clk,
337
  scanb_si,
338
  scanb_so,
339
  scanb_en
340
`endif
341 2 mohor
);
342
 
343
parameter Tp = 1;
344
 
345 10 mohor
input         clk;
346
input         rst;
347
input         sample_point;
348
input         sampled_bit;
349
input         sampled_bit_q;
350 24 mohor
input         tx_point;
351 11 mohor
input         hard_sync;
352 14 mohor
input   [7:0] addr;
353 35 mohor
input   [7:0] data_in;
354 14 mohor
output  [7:0] data_out;
355 48 mohor
input         fifo_selected;
356 11 mohor
 
357 14 mohor
 
358 10 mohor
input         reset_mode;
359 36 mohor
input         listen_only_mode;
360 11 mohor
input         acceptance_filter_mode;
361
input         extended_mode;
362 36 mohor
input         self_test_mode;
363 2 mohor
 
364 35 mohor
 
365 15 mohor
/* Command register */
366
input         release_buffer;
367 25 mohor
input         tx_request;
368 32 mohor
input         abort_tx;
369 36 mohor
input         self_rx_request;
370
input         single_shot_transmission;
371 104 tadejm
output        tx_state;
372
output        tx_state_q;
373 125 mohor
input         overload_request;
374
output        overload_frame;       // When receiver is busy, it needs to send overload frame. Only 2 overload frames are allowed to
375
                                    // be send in a row. This is not implemented, yet,  because host can not send an overload request.
376 11 mohor
 
377 39 mohor
/* Arbitration Lost Capture Register */
378
input         read_arbitration_lost_capture_reg;
379
 
380
/* Error Code Capture Register */
381
input         read_error_code_capture_reg;
382
output  [7:0] error_capture_code;
383
 
384 35 mohor
/* Error Warning Limit register */
385
input   [7:0] error_warning_limit;
386
 
387
/* Rx Error Counter register */
388
input         we_rx_err_cnt;
389
 
390
/* Tx Error Counter register */
391
input         we_tx_err_cnt;
392
 
393 10 mohor
output        rx_idle;
394 24 mohor
output        transmitting;
395 125 mohor
output        transmitter;
396 100 mohor
output        go_rx_inter;
397 104 tadejm
output        not_first_bit_of_inter;
398 126 mohor
output        rx_inter;
399 35 mohor
output        set_reset_mode;
400
output        node_bus_off;
401
output        error_status;
402
output  [8:0] rx_err_cnt;
403
output  [8:0] tx_err_cnt;
404
output        transmit_status;
405
output        receive_status;
406
output        tx_successful;
407
output        need_to_tx;
408
output        overrun;
409
output        info_empty;
410 39 mohor
output        set_bus_error_irq;
411
output        set_arbitration_lost_irq;
412
output  [4:0] arbitration_lost_capture;
413 36 mohor
output        node_error_passive;
414
output        node_error_active;
415 39 mohor
output  [6:0] rx_message_counter;
416 2 mohor
 
417 29 mohor
 
418 11 mohor
/* This section is for BASIC and EXTENDED mode */
419
/* Acceptance code register */
420
input   [7:0] acceptance_code_0;
421
 
422
/* Acceptance mask register */
423
input   [7:0] acceptance_mask_0;
424
 
425
/* End: This section is for BASIC and EXTENDED mode */
426
 
427
 
428
/* This section is for EXTENDED mode */
429
/* Acceptance code register */
430
input   [7:0] acceptance_code_1;
431
input   [7:0] acceptance_code_2;
432
input   [7:0] acceptance_code_3;
433
 
434
/* Acceptance mask register */
435
input   [7:0] acceptance_mask_1;
436
input   [7:0] acceptance_mask_2;
437
input   [7:0] acceptance_mask_3;
438
/* End: This section is for EXTENDED mode */
439
 
440 24 mohor
/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
441 18 mohor
input   [7:0] tx_data_0;
442
input   [7:0] tx_data_1;
443
input   [7:0] tx_data_2;
444
input   [7:0] tx_data_3;
445
input   [7:0] tx_data_4;
446
input   [7:0] tx_data_5;
447
input   [7:0] tx_data_6;
448
input   [7:0] tx_data_7;
449
input   [7:0] tx_data_8;
450
input   [7:0] tx_data_9;
451
input   [7:0] tx_data_10;
452
input   [7:0] tx_data_11;
453
input   [7:0] tx_data_12;
454 24 mohor
/* End: Tx data registers */
455 11 mohor
 
456 24 mohor
/* Tx signal */
457
output        tx;
458 125 mohor
output        tx_next;
459 28 mohor
output        tx_oen;
460 11 mohor
 
461 125 mohor
output        go_overload_frame;
462
output        go_error_frame;
463
output        go_tx;
464
output        send_ack;
465
 
466 95 simons
/* Bist */
467
`ifdef CAN_BIST
468
input         scanb_rst;
469
input         scanb_clk;
470
input         scanb_si;
471
output        scanb_so;
472
input         scanb_en;
473
`endif
474
 
475 10 mohor
reg           reset_mode_q;
476
reg     [5:0] bit_cnt;
477 2 mohor
 
478 10 mohor
reg     [3:0] data_len;
479
reg    [28:0] id;
480
reg     [2:0] bit_stuff_cnt;
481 25 mohor
reg     [2:0] bit_stuff_cnt_tx;
482
reg           tx_point_q;
483 10 mohor
 
484
reg           rx_idle;
485
reg           rx_id1;
486
reg           rx_rtr1;
487
reg           rx_ide;
488
reg           rx_id2;
489
reg           rx_rtr2;
490
reg           rx_r1;
491
reg           rx_r0;
492
reg           rx_dlc;
493
reg           rx_data;
494
reg           rx_crc;
495 11 mohor
reg           rx_crc_lim;
496 10 mohor
reg           rx_ack;
497 11 mohor
reg           rx_ack_lim;
498 10 mohor
reg           rx_eof;
499 24 mohor
reg           rx_inter;
500 45 mohor
reg           go_early_tx_latched;
501 10 mohor
 
502 19 mohor
reg           rtr1;
503
reg           ide;
504
reg           rtr2;
505
reg    [14:0] crc_in;
506
 
507 24 mohor
reg     [7:0] tmp_data;
508
reg     [7:0] tmp_fifo [0:7];
509
reg           write_data_to_tmp_fifo;
510
reg     [2:0] byte_cnt;
511
reg           bit_stuff_cnt_en;
512 11 mohor
reg           crc_enable;
513
 
514 10 mohor
reg     [2:0] eof_cnt;
515 28 mohor
reg     [2:0] passive_cnt;
516
 
517 24 mohor
reg           transmitting;
518 10 mohor
 
519 24 mohor
reg           error_frame;
520 28 mohor
reg           error_frame_q;
521 24 mohor
reg           enable_error_cnt2;
522
reg     [2:0] error_cnt1;
523
reg     [2:0] error_cnt2;
524 29 mohor
reg     [2:0] delayed_dominant_cnt;
525
reg           enable_overload_cnt2;
526 30 mohor
reg           overload_frame;
527
reg           overload_frame_blocked;
528 125 mohor
reg     [1:0] overload_request_cnt;
529 29 mohor
reg     [2:0] overload_cnt1;
530
reg     [2:0] overload_cnt2;
531 24 mohor
reg           tx;
532 28 mohor
reg           crc_err;
533 24 mohor
 
534 39 mohor
reg           arbitration_lost;
535
reg           arbitration_lost_q;
536
reg     [4:0] arbitration_lost_capture;
537
reg           arbitration_cnt_en;
538
reg           arbitration_blocked;
539 25 mohor
reg           tx_q;
540
 
541 28 mohor
reg           need_to_tx;   // When the CAN core has something to transmit and a dominant bit is sampled at the third bit
542 25 mohor
reg     [3:0] data_cnt;     // Counting the data bytes that are written to FIFO
543
reg     [2:0] header_cnt;   // Counting header length
544
reg           wr_fifo;      // Write data and header to 64-byte fifo
545
reg     [7:0] data_for_fifo;// Multiplexed data that is stored to 64-byte fifo
546
 
547
reg     [5:0] tx_pointer;
548
reg           tx_bit;
549
reg           tx_state;
550 104 tadejm
reg           tx_state_q;
551 28 mohor
reg           transmitter;
552 25 mohor
reg           finish_msg;
553
 
554 35 mohor
reg     [8:0] rx_err_cnt;
555
reg     [8:0] tx_err_cnt;
556 28 mohor
reg           rx_err_cnt_blocked;
557 35 mohor
reg     [3:0] bus_free_cnt;
558
reg           bus_free_cnt_en;
559
reg           bus_free;
560
reg           waiting_for_bus_free;
561 28 mohor
 
562
reg           node_error_passive;
563
reg           node_bus_off;
564 35 mohor
reg           node_bus_off_q;
565 28 mohor
reg           ack_err_latched;
566
reg           bit_err_latched;
567
reg           stuff_err_latched;
568
reg           form_err_latched;
569
reg           rule3_exc1_1;
570
reg           rule3_exc1_2;
571
reg           rule3_exc2;
572
reg           suspend;
573
reg           susp_cnt_en;
574
reg     [2:0] susp_cnt;
575 125 mohor
reg           error_flag_over_latched;
576 28 mohor
 
577 39 mohor
reg     [7:0] error_capture_code;
578
reg     [7:6] error_capture_code_type;
579
reg           error_capture_code_blocked;
580
 
581
wire    [4:0] error_capture_code_segment;
582
wire          error_capture_code_direction;
583
 
584 28 mohor
wire          bit_de_stuff;
585
wire          bit_de_stuff_tx;
586
 
587 44 mohor
wire          rule5;
588 28 mohor
 
589
/* Rx state machine */
590
wire          go_rx_idle;
591
wire          go_rx_id1;
592
wire          go_rx_rtr1;
593
wire          go_rx_ide;
594
wire          go_rx_id2;
595
wire          go_rx_rtr2;
596
wire          go_rx_r1;
597
wire          go_rx_r0;
598
wire          go_rx_dlc;
599
wire          go_rx_data;
600
wire          go_rx_crc;
601
wire          go_rx_crc_lim;
602
wire          go_rx_ack;
603
wire          go_rx_ack_lim;
604
wire          go_rx_eof;
605
wire          go_rx_inter;
606
 
607 104 tadejm
wire          last_bit_of_inter;
608
 
609 28 mohor
wire          go_crc_enable;
610
wire          rst_crc_enable;
611
 
612
wire          bit_de_stuff_set;
613
wire          bit_de_stuff_reset;
614
 
615
wire          go_early_tx;
616
 
617
wire   [14:0] calculated_crc;
618
wire   [15:0] r_calculated_crc;
619
wire          remote_rq;
620
wire    [3:0] limited_data_len;
621
wire          form_err;
622
 
623
wire          error_frame_ended;
624
wire          overload_frame_ended;
625
wire          bit_err;
626
wire          ack_err;
627
wire          stuff_err;
628
 
629 29 mohor
wire          id_ok;                // If received ID matches ID set in registers
630
wire          no_byte0;             // There is no byte 0 (RTR bit set to 1 or DLC field equal to 0). Signal used for acceptance filter.
631
wire          no_byte1;             // There is no byte 1 (RTR bit set to 1 or DLC field equal to 1). Signal used for acceptance filter.
632 28 mohor
 
633 25 mohor
wire    [2:0] header_len;
634
wire          storing_header;
635
wire    [3:0] limited_data_len_minus1;
636
wire          reset_wr_fifo;
637 28 mohor
wire          err;
638 25 mohor
 
639 28 mohor
wire          arbitration_field;
640 25 mohor
 
641 28 mohor
wire   [18:0] basic_chain;
642
wire   [63:0] basic_chain_data;
643
wire   [18:0] extended_chain_std;
644
wire   [38:0] extended_chain_ext;
645 78 mohor
wire   [63:0] extended_chain_data_std;
646
wire   [63:0] extended_chain_data_ext;
647 28 mohor
 
648
wire          rst_tx_pointer;
649
 
650
wire    [7:0] r_tx_data_0;
651
wire    [7:0] r_tx_data_1;
652
wire    [7:0] r_tx_data_2;
653
wire    [7:0] r_tx_data_3;
654
wire    [7:0] r_tx_data_4;
655
wire    [7:0] r_tx_data_5;
656
wire    [7:0] r_tx_data_6;
657
wire    [7:0] r_tx_data_7;
658
wire    [7:0] r_tx_data_8;
659
wire    [7:0] r_tx_data_9;
660
wire    [7:0] r_tx_data_10;
661
wire    [7:0] r_tx_data_11;
662
wire    [7:0] r_tx_data_12;
663
 
664
wire          send_ack;
665
wire          bit_err_exc1;
666
wire          bit_err_exc2;
667
wire          bit_err_exc3;
668
wire          bit_err_exc4;
669 30 mohor
wire          bit_err_exc5;
670 28 mohor
wire          error_flag_over;
671 29 mohor
wire          overload_flag_over;
672 28 mohor
 
673 112 tadejm
wire    [5:0] limited_tx_cnt_ext;
674
wire    [5:0] limited_tx_cnt_std;
675 28 mohor
 
676 35 mohor
assign go_rx_idle     =                   sample_point &  sampled_bit & last_bit_of_inter | bus_free & (~node_bus_off);
677 29 mohor
assign go_rx_id1      =                   sample_point &  (~sampled_bit) & (rx_idle | last_bit_of_inter);
678 107 mohor
assign go_rx_rtr1     = (~bit_de_stuff) & sample_point &  rx_id1  & (bit_cnt[3:0] == 4'd10);
679 11 mohor
assign go_rx_ide      = (~bit_de_stuff) & sample_point &  rx_rtr1;
680
assign go_rx_id2      = (~bit_de_stuff) & sample_point &  rx_ide  &   sampled_bit;
681 107 mohor
assign go_rx_rtr2     = (~bit_de_stuff) & sample_point &  rx_id2  & (bit_cnt[4:0] == 5'd17);
682 11 mohor
assign go_rx_r1       = (~bit_de_stuff) & sample_point &  rx_rtr2;
683
assign go_rx_r0       = (~bit_de_stuff) & sample_point & (rx_ide  & (~sampled_bit) | rx_r1);
684
assign go_rx_dlc      = (~bit_de_stuff) & sample_point &  rx_r0;
685 107 mohor
assign go_rx_data     = (~bit_de_stuff) & sample_point &  rx_dlc  & (bit_cnt[1:0] == 2'd3) &  (sampled_bit   |   (|data_len[2:0])) & (~remote_rq);
686
assign go_rx_crc      = (~bit_de_stuff) & sample_point & (rx_dlc  & (bit_cnt[1:0] == 2'd3) & ((~sampled_bit) & (~(|data_len[2:0])) | remote_rq) |
687
                                                          rx_data & (bit_cnt[5:0] == ((limited_data_len<<3) - 1'b1)));  // overflow works ok at max value (8<<3 = 64 = 0). 0-1 = 6'h3f
688
assign go_rx_crc_lim  = (~bit_de_stuff) & sample_point &  rx_crc  & (bit_cnt[3:0] == 4'd14);
689 79 tadejm
assign go_rx_ack      = (~bit_de_stuff) & sample_point &  rx_crc_lim;
690 11 mohor
assign go_rx_ack_lim  =                   sample_point &  rx_ack;
691 35 mohor
assign go_rx_eof      =                   sample_point &  rx_ack_lim;
692 125 mohor
assign go_rx_inter    =                 ((sample_point &  rx_eof  & (eof_cnt == 3'd6)) | error_frame_ended | overload_frame_ended) & (~overload_request);
693 10 mohor
 
694 28 mohor
assign go_error_frame = (form_err | stuff_err | bit_err | ack_err | (crc_err & go_rx_eof));
695 107 mohor
assign error_frame_ended = (error_cnt2 == 3'd7) & tx_point;
696
assign overload_frame_ended = (overload_cnt2 == 3'd7) & tx_point;
697 24 mohor
 
698 126 mohor
//assign go_overload_frame = (   ((sample_point &  rx_eof  & (eof_cnt == 3'd6)) | error_frame_ended | overload_frame_ended) & overload_request | 
699
assign go_overload_frame = (   ((sample_point &  rx_eof  & (eof_cnt == 3'd6)) | error_frame_ended | overload_frame_ended) & (overload_request | (~sampled_bit)) |
700 125 mohor
                                 sample_point & (~sampled_bit) & rx_inter & (bit_cnt[1:0] < 2'd2)                                            |
701
                                 sample_point & (~sampled_bit) & ((error_cnt2 == 3'd7) | (overload_cnt2 == 3'd7))
702 30 mohor
                           )
703
                           & (~overload_frame_blocked)
704
                           ;
705 24 mohor
 
706 25 mohor
 
707
assign go_crc_enable  = hard_sync | go_tx;
708 11 mohor
assign rst_crc_enable = go_rx_crc;
709 10 mohor
 
710 32 mohor
assign bit_de_stuff_set   = go_rx_id1 & (~go_error_frame);
711 79 tadejm
assign bit_de_stuff_reset = go_rx_ack | reset_mode | go_error_frame | go_overload_frame;
712 11 mohor
 
713 19 mohor
assign remote_rq = ((~ide) & rtr1) | (ide & rtr2);
714 107 mohor
assign limited_data_len = (data_len < 4'h8)? data_len : 4'h8;
715 11 mohor
 
716 36 mohor
assign ack_err = rx_ack & sample_point & sampled_bit & tx_state & (~self_test_mode);
717 39 mohor
assign bit_err = (tx_state | error_frame | overload_frame | rx_ack) & sample_point & (tx != sampled_bit) & (~bit_err_exc1) & (~bit_err_exc2) & (~bit_err_exc3) & (~bit_err_exc4) & (~bit_err_exc5);
718 28 mohor
assign bit_err_exc1 = tx_state & arbitration_field & tx;
719
assign bit_err_exc2 = rx_ack & tx;
720 107 mohor
assign bit_err_exc3 = error_frame & node_error_passive & (error_cnt1 < 3'd7);
721
assign bit_err_exc4 = (error_frame & (error_cnt1 == 3'd7) & (~enable_error_cnt2)) | (overload_frame & (overload_cnt1 == 3'd7) & (~enable_overload_cnt2));
722
assign bit_err_exc5 = (error_frame & (error_cnt2 == 3'd7)) | (overload_frame & (overload_cnt2 == 3'd7));
723 19 mohor
 
724 28 mohor
assign arbitration_field = rx_id1 | rx_rtr1 | rx_ide | rx_id2 | rx_rtr2;
725 25 mohor
 
726 107 mohor
assign last_bit_of_inter = rx_inter & (bit_cnt[1:0] == 2'd2);
727
assign not_first_bit_of_inter = rx_inter & (bit_cnt[1:0] != 2'd0);
728 25 mohor
 
729 26 mohor
 
730 10 mohor
// Rx idle state
731
always @ (posedge clk or posedge rst)
732
begin
733
  if (rst)
734 24 mohor
    rx_idle <= 1'b0;
735 125 mohor
//  else if (reset_mode | go_rx_id1 | error_frame)
736
  else if (reset_mode | go_rx_id1 | go_error_frame)
737 10 mohor
    rx_idle <=#Tp 1'b0;
738
  else if (go_rx_idle)
739
    rx_idle <=#Tp 1'b1;
740
end
741
 
742
 
743
// Rx id1 state
744
always @ (posedge clk or posedge rst)
745
begin
746
  if (rst)
747
    rx_id1 <= 1'b0;
748 125 mohor
//  else if (reset_mode | go_rx_rtr1 | error_frame)
749
  else if (reset_mode | go_rx_rtr1 | go_error_frame)
750 10 mohor
    rx_id1 <=#Tp 1'b0;
751
  else if (go_rx_id1)
752
    rx_id1 <=#Tp 1'b1;
753
end
754
 
755
 
756
// Rx rtr1 state
757
always @ (posedge clk or posedge rst)
758
begin
759
  if (rst)
760
    rx_rtr1 <= 1'b0;
761 125 mohor
//  else if (reset_mode | go_rx_ide | error_frame)
762
  else if (reset_mode | go_rx_ide | go_error_frame)
763 10 mohor
    rx_rtr1 <=#Tp 1'b0;
764
  else if (go_rx_rtr1)
765
    rx_rtr1 <=#Tp 1'b1;
766
end
767
 
768
 
769
// Rx ide state
770
always @ (posedge clk or posedge rst)
771
begin
772
  if (rst)
773
    rx_ide <= 1'b0;
774 125 mohor
//  else if (reset_mode | go_rx_r0 | go_rx_id2 | error_frame)
775
  else if (reset_mode | go_rx_r0 | go_rx_id2 | go_error_frame)
776 10 mohor
    rx_ide <=#Tp 1'b0;
777
  else if (go_rx_ide)
778
    rx_ide <=#Tp 1'b1;
779
end
780
 
781
 
782
// Rx id2 state
783
always @ (posedge clk or posedge rst)
784
begin
785
  if (rst)
786
    rx_id2 <= 1'b0;
787 125 mohor
//  else if (reset_mode | go_rx_rtr2 | error_frame)
788
  else if (reset_mode | go_rx_rtr2 | go_error_frame)
789 10 mohor
    rx_id2 <=#Tp 1'b0;
790
  else if (go_rx_id2)
791
    rx_id2 <=#Tp 1'b1;
792
end
793
 
794
 
795
// Rx rtr2 state
796
always @ (posedge clk or posedge rst)
797
begin
798
  if (rst)
799
    rx_rtr2 <= 1'b0;
800 125 mohor
//  else if (reset_mode | go_rx_r1 | error_frame)
801
  else if (reset_mode | go_rx_r1 | go_error_frame)
802 10 mohor
    rx_rtr2 <=#Tp 1'b0;
803
  else if (go_rx_rtr2)
804
    rx_rtr2 <=#Tp 1'b1;
805
end
806
 
807
 
808
// Rx r0 state
809
always @ (posedge clk or posedge rst)
810
begin
811
  if (rst)
812
    rx_r1 <= 1'b0;
813 125 mohor
//  else if (reset_mode | go_rx_r0 | error_frame)
814
  else if (reset_mode | go_rx_r0 | go_error_frame)
815 10 mohor
    rx_r1 <=#Tp 1'b0;
816
  else if (go_rx_r1)
817
    rx_r1 <=#Tp 1'b1;
818
end
819
 
820
 
821
// Rx r0 state
822
always @ (posedge clk or posedge rst)
823
begin
824
  if (rst)
825
    rx_r0 <= 1'b0;
826 125 mohor
//  else if (reset_mode | go_rx_dlc | error_frame)
827
  else if (reset_mode | go_rx_dlc | go_error_frame)
828 10 mohor
    rx_r0 <=#Tp 1'b0;
829
  else if (go_rx_r0)
830
    rx_r0 <=#Tp 1'b1;
831
end
832
 
833
 
834
// Rx dlc state
835
always @ (posedge clk or posedge rst)
836
begin
837
  if (rst)
838
    rx_dlc <= 1'b0;
839 125 mohor
//  else if (reset_mode | go_rx_data | go_rx_crc | error_frame)
840
  else if (reset_mode | go_rx_data | go_rx_crc | go_error_frame)
841 10 mohor
    rx_dlc <=#Tp 1'b0;
842
  else if (go_rx_dlc)
843
    rx_dlc <=#Tp 1'b1;
844
end
845
 
846
 
847
// Rx data state
848
always @ (posedge clk or posedge rst)
849
begin
850
  if (rst)
851
    rx_data <= 1'b0;
852 125 mohor
//  else if (reset_mode | go_rx_crc | error_frame)
853
  else if (reset_mode | go_rx_crc | go_error_frame)
854 10 mohor
    rx_data <=#Tp 1'b0;
855
  else if (go_rx_data)
856
    rx_data <=#Tp 1'b1;
857
end
858
 
859
 
860
// Rx crc state
861
always @ (posedge clk or posedge rst)
862
begin
863
  if (rst)
864
    rx_crc <= 1'b0;
865 125 mohor
//  else if (reset_mode | go_rx_crc_lim | error_frame)
866
  else if (reset_mode | go_rx_crc_lim | go_error_frame)
867 10 mohor
    rx_crc <=#Tp 1'b0;
868
  else if (go_rx_crc)
869
    rx_crc <=#Tp 1'b1;
870
end
871
 
872
 
873 11 mohor
// Rx crc delimiter state
874
always @ (posedge clk or posedge rst)
875
begin
876
  if (rst)
877
    rx_crc_lim <= 1'b0;
878 125 mohor
//  else if (reset_mode | go_rx_ack | error_frame)
879
  else if (reset_mode | go_rx_ack | go_error_frame)
880 11 mohor
    rx_crc_lim <=#Tp 1'b0;
881
  else if (go_rx_crc_lim)
882
    rx_crc_lim <=#Tp 1'b1;
883
end
884
 
885
 
886 10 mohor
// Rx ack state
887
always @ (posedge clk or posedge rst)
888
begin
889
  if (rst)
890
    rx_ack <= 1'b0;
891 125 mohor
//  else if (reset_mode | go_rx_ack_lim | error_frame)
892
  else if (reset_mode | go_rx_ack_lim | go_error_frame)
893 10 mohor
    rx_ack <=#Tp 1'b0;
894
  else if (go_rx_ack)
895
    rx_ack <=#Tp 1'b1;
896
end
897
 
898
 
899 11 mohor
// Rx ack delimiter state
900
always @ (posedge clk or posedge rst)
901
begin
902
  if (rst)
903
    rx_ack_lim <= 1'b0;
904 125 mohor
//  else if (reset_mode | go_rx_eof | error_frame)
905
  else if (reset_mode | go_rx_eof | go_error_frame)
906 11 mohor
    rx_ack_lim <=#Tp 1'b0;
907
  else if (go_rx_ack_lim)
908
    rx_ack_lim <=#Tp 1'b1;
909
end
910
 
911
 
912 10 mohor
// Rx eof state
913
always @ (posedge clk or posedge rst)
914
begin
915
  if (rst)
916
    rx_eof <= 1'b0;
917 125 mohor
//  else if (go_rx_inter | error_frame | go_overload_frame)
918
  else if (go_rx_inter | go_error_frame | go_overload_frame)
919 10 mohor
    rx_eof <=#Tp 1'b0;
920
  else if (go_rx_eof)
921
    rx_eof <=#Tp 1'b1;
922
end
923
 
924
 
925 24 mohor
 
926
// Interframe space
927
always @ (posedge clk or posedge rst)
928
begin
929
  if (rst)
930
    rx_inter <= 1'b0;
931 35 mohor
  else if (reset_mode | go_rx_idle | go_rx_id1 | go_overload_frame | go_error_frame)
932 24 mohor
    rx_inter <=#Tp 1'b0;
933
  else if (go_rx_inter)
934
    rx_inter <=#Tp 1'b1;
935
end
936
 
937
 
938 10 mohor
// ID register
939
always @ (posedge clk or posedge rst)
940
begin
941
  if (rst)
942 107 mohor
    id <= 29'h0;
943 11 mohor
  else if (sample_point & (rx_id1 | rx_id2) & (~bit_de_stuff))
944 10 mohor
    id <=#Tp {id[27:0], sampled_bit};
945
end
946
 
947 11 mohor
 
948
// rtr1 bit
949
always @ (posedge clk or posedge rst)
950
begin
951
  if (rst)
952 107 mohor
    rtr1 <= 1'b0;
953 11 mohor
  else if (sample_point & rx_rtr1 & (~bit_de_stuff))
954
    rtr1 <=#Tp sampled_bit;
955
end
956
 
957
 
958
// rtr2 bit
959
always @ (posedge clk or posedge rst)
960
begin
961
  if (rst)
962 107 mohor
    rtr2 <= 1'b0;
963 11 mohor
  else if (sample_point & rx_rtr2 & (~bit_de_stuff))
964
    rtr2 <=#Tp sampled_bit;
965
end
966
 
967
 
968
// ide bit
969
always @ (posedge clk or posedge rst)
970
begin
971
  if (rst)
972 107 mohor
    ide <= 1'b0;
973 11 mohor
  else if (sample_point & rx_ide & (~bit_de_stuff))
974
    ide <=#Tp sampled_bit;
975
end
976
 
977
 
978 10 mohor
// Data length
979
always @ (posedge clk or posedge rst)
980
begin
981
  if (rst)
982 107 mohor
    data_len <= 4'b0;
983 10 mohor
  else if (sample_point & rx_dlc & (~bit_de_stuff))
984
    data_len <=#Tp {data_len[2:0], sampled_bit};
985
end
986
 
987
 
988 11 mohor
// Data
989
always @ (posedge clk or posedge rst)
990
begin
991
  if (rst)
992 107 mohor
    tmp_data <= 8'h0;
993 11 mohor
  else if (sample_point & rx_data & (~bit_de_stuff))
994
    tmp_data <=#Tp {tmp_data[6:0], sampled_bit};
995
end
996
 
997
 
998
always @ (posedge clk or posedge rst)
999
begin
1000
  if (rst)
1001 107 mohor
    write_data_to_tmp_fifo <= 1'b0;
1002 11 mohor
  else if (sample_point & rx_data & (~bit_de_stuff) & (&bit_cnt[2:0]))
1003
    write_data_to_tmp_fifo <=#Tp 1'b1;
1004
  else
1005 107 mohor
    write_data_to_tmp_fifo <=#Tp 1'b0;
1006 11 mohor
end
1007
 
1008
 
1009
always @ (posedge clk or posedge rst)
1010
begin
1011
  if (rst)
1012 107 mohor
    byte_cnt <= 3'h0;
1013 36 mohor
  else if (write_data_to_tmp_fifo)
1014 107 mohor
    byte_cnt <=#Tp byte_cnt + 1'b1;
1015 36 mohor
  else if (reset_mode | (sample_point & go_rx_crc_lim))
1016 107 mohor
    byte_cnt <=#Tp 3'h0;
1017 11 mohor
end
1018
 
1019
 
1020 24 mohor
always @ (posedge clk)
1021 11 mohor
begin
1022
  if (write_data_to_tmp_fifo)
1023
    tmp_fifo[byte_cnt] <=#Tp tmp_data;
1024
end
1025
 
1026
 
1027
 
1028
// CRC
1029
always @ (posedge clk or posedge rst)
1030
begin
1031
  if (rst)
1032 107 mohor
    crc_in <= 15'h0;
1033 11 mohor
  else if (sample_point & rx_crc & (~bit_de_stuff))
1034
    crc_in <=#Tp {crc_in[13:0], sampled_bit};
1035
end
1036
 
1037
 
1038 10 mohor
// bit_cnt
1039
always @ (posedge clk or posedge rst)
1040
begin
1041
  if (rst)
1042 107 mohor
    bit_cnt <= 6'd0;
1043 24 mohor
  else if (go_rx_id1 | go_rx_id2 | go_rx_dlc | go_rx_data | go_rx_crc |
1044
           go_rx_ack | go_rx_eof | go_rx_inter | go_error_frame | go_overload_frame)
1045 107 mohor
    bit_cnt <=#Tp 6'd0;
1046 11 mohor
  else if (sample_point & (~bit_de_stuff))
1047 10 mohor
    bit_cnt <=#Tp bit_cnt + 1'b1;
1048
end
1049
 
1050
 
1051
// eof_cnt
1052
always @ (posedge clk or posedge rst)
1053
begin
1054
  if (rst)
1055 107 mohor
    eof_cnt <= 3'd0;
1056 10 mohor
  else if (sample_point)
1057
    begin
1058 35 mohor
      if (reset_mode | go_rx_inter | go_error_frame | go_overload_frame)
1059 107 mohor
        eof_cnt <=#Tp 3'd0;
1060 28 mohor
      else if (rx_eof)
1061 10 mohor
        eof_cnt <=#Tp eof_cnt + 1'b1;
1062
    end
1063
end
1064
 
1065
 
1066 11 mohor
// Enabling bit de-stuffing
1067
always @ (posedge clk or posedge rst)
1068
begin
1069
  if (rst)
1070
    bit_stuff_cnt_en <= 1'b0;
1071
  else if (bit_de_stuff_set)
1072
    bit_stuff_cnt_en <=#Tp 1'b1;
1073
  else if (bit_de_stuff_reset)
1074
    bit_stuff_cnt_en <=#Tp 1'b0;
1075
end
1076 10 mohor
 
1077 24 mohor
 
1078 10 mohor
// bit_stuff_cnt
1079
always @ (posedge clk or posedge rst)
1080
begin
1081
  if (rst)
1082 107 mohor
    bit_stuff_cnt <= 3'h1;
1083 15 mohor
  else if (bit_de_stuff_reset)
1084 107 mohor
    bit_stuff_cnt <=#Tp 3'h1;
1085 11 mohor
  else if (sample_point & bit_stuff_cnt_en)
1086 10 mohor
    begin
1087 107 mohor
      if (bit_stuff_cnt == 3'h5)
1088
        bit_stuff_cnt <=#Tp 3'h1;
1089 10 mohor
      else if (sampled_bit == sampled_bit_q)
1090
        bit_stuff_cnt <=#Tp bit_stuff_cnt + 1'b1;
1091
      else
1092 107 mohor
        bit_stuff_cnt <=#Tp 3'h1;
1093 10 mohor
    end
1094
end
1095
 
1096
 
1097 25 mohor
// bit_stuff_cnt_tx
1098
always @ (posedge clk or posedge rst)
1099
begin
1100
  if (rst)
1101 107 mohor
    bit_stuff_cnt_tx <= 3'h1;
1102 25 mohor
  else if (bit_de_stuff_reset)
1103 107 mohor
    bit_stuff_cnt_tx <=#Tp 3'h1;
1104 25 mohor
  else if (tx_point_q & bit_stuff_cnt_en)
1105
    begin
1106 107 mohor
      if (bit_stuff_cnt_tx == 3'h5)
1107
        bit_stuff_cnt_tx <=#Tp 3'h1;
1108 25 mohor
      else if (tx == tx_q)
1109
        bit_stuff_cnt_tx <=#Tp bit_stuff_cnt_tx + 1'b1;
1110
      else
1111 107 mohor
        bit_stuff_cnt_tx <=#Tp 3'h1;
1112 25 mohor
    end
1113
end
1114
 
1115
 
1116 107 mohor
assign bit_de_stuff = bit_stuff_cnt == 3'h5;
1117
assign bit_de_stuff_tx = bit_stuff_cnt_tx == 3'h5;
1118 10 mohor
 
1119
 
1120 24 mohor
 
1121 28 mohor
// stuff_err
1122
assign stuff_err = sample_point & bit_stuff_cnt_en & bit_de_stuff & (sampled_bit == sampled_bit_q);
1123 10 mohor
 
1124
 
1125 28 mohor
 
1126 35 mohor
// Generating delayed signals
1127 107 mohor
always @ (posedge clk or posedge rst)
1128 10 mohor
begin
1129 107 mohor
  if (rst)
1130
    begin
1131
      reset_mode_q <=#Tp 1'b0;
1132
      node_bus_off_q <=#Tp 1'b0;
1133
    end
1134
  else
1135
    begin
1136
      reset_mode_q <=#Tp reset_mode;
1137
      node_bus_off_q <=#Tp node_bus_off;
1138
    end
1139 10 mohor
end
1140
 
1141
 
1142 11 mohor
 
1143
always @ (posedge clk or posedge rst)
1144
begin
1145
  if (rst)
1146
    crc_enable <= 1'b0;
1147
  else if (go_crc_enable)
1148
    crc_enable <=#Tp 1'b1;
1149
  else if (reset_mode | rst_crc_enable)
1150
    crc_enable <=#Tp 1'b0;
1151
end
1152
 
1153
 
1154
// CRC error generation
1155
always @ (posedge clk or posedge rst)
1156
begin
1157
  if (rst)
1158 28 mohor
    crc_err <= 1'b0;
1159 12 mohor
  else if (go_rx_ack)
1160 28 mohor
    crc_err <=#Tp crc_in != calculated_crc;
1161
  else if (reset_mode | error_frame_ended)
1162
    crc_err <=#Tp 1'b0;
1163 11 mohor
end
1164
 
1165
 
1166 22 mohor
// Conditions for form error
1167 126 mohor
assign form_err = sample_point & ( ((~bit_de_stuff) & rx_crc_lim & (~sampled_bit)               ) |
1168 28 mohor
                                   (                  rx_ack_lim & (~sampled_bit)               ) |
1169 107 mohor
                                   ((eof_cnt < 3'd6)& rx_eof     & (~sampled_bit) & (~tx_state) ) |
1170 28 mohor
                                   (                & rx_eof     & (~sampled_bit) &   tx_state  )
1171
                                 );
1172 11 mohor
 
1173 22 mohor
 
1174 28 mohor
always @ (posedge clk or posedge rst)
1175
begin
1176
  if (rst)
1177
    ack_err_latched <= 1'b0;
1178 30 mohor
  else if (reset_mode | error_frame_ended | go_overload_frame)
1179 28 mohor
    ack_err_latched <=#Tp 1'b0;
1180
  else if (ack_err)
1181
    ack_err_latched <=#Tp 1'b1;
1182
end
1183
 
1184
 
1185
always @ (posedge clk or posedge rst)
1186
begin
1187
  if (rst)
1188
    bit_err_latched <= 1'b0;
1189 30 mohor
  else if (reset_mode | error_frame_ended | go_overload_frame)
1190 28 mohor
    bit_err_latched <=#Tp 1'b0;
1191
  else if (bit_err)
1192
    bit_err_latched <=#Tp 1'b1;
1193
end
1194
 
1195
 
1196 44 mohor
 
1197 28 mohor
// Rule 5 (Fault confinement).
1198 125 mohor
assign rule5 = bit_err &  ( (~node_error_passive) & error_frame    & (error_cnt1    < 3'd7)
1199
                            |
1200
                                                    overload_frame & (overload_cnt1 < 3'd7)
1201
                          );
1202 28 mohor
 
1203
// Rule 3 exception 1 - first part (Fault confinement).
1204
always @ (posedge clk or posedge rst)
1205
begin
1206
  if (rst)
1207
    rule3_exc1_1 <= 1'b0;
1208
  else if (reset_mode | error_flag_over | rule3_exc1_2)
1209
    rule3_exc1_1 <=#Tp 1'b0;
1210
  else if (transmitter & node_error_passive & ack_err)
1211
    rule3_exc1_1 <=#Tp 1'b1;
1212
end
1213
 
1214
 
1215
// Rule 3 exception 1 - second part (Fault confinement).
1216
always @ (posedge clk or posedge rst)
1217
begin
1218
  if (rst)
1219
    rule3_exc1_2 <= 1'b0;
1220 126 mohor
//  else if (reset_mode | error_flag_over)
1221
  else if (reset_mode | go_error_frame | rule3_exc1_2)
1222 28 mohor
    rule3_exc1_2 <=#Tp 1'b0;
1223 126 mohor
  else if (rule3_exc1_1 & (error_cnt1 < 3'd7) & sample_point & (~sampled_bit))
1224 28 mohor
    rule3_exc1_2 <=#Tp 1'b1;
1225
end
1226
 
1227
 
1228
// Rule 3 exception 2 (Fault confinement).
1229
always @ (posedge clk or posedge rst)
1230
begin
1231
  if (rst)
1232
    rule3_exc2 <= 1'b0;
1233
  else if (reset_mode | error_flag_over)
1234
    rule3_exc2 <=#Tp 1'b0;
1235
  else if (transmitter & stuff_err & arbitration_field & sample_point & tx & (~sampled_bit))
1236
    rule3_exc2 <=#Tp 1'b1;
1237
end
1238
 
1239
 
1240
 
1241
always @ (posedge clk or posedge rst)
1242
begin
1243
  if (rst)
1244
    stuff_err_latched <= 1'b0;
1245 30 mohor
  else if (reset_mode | error_frame_ended | go_overload_frame)
1246 28 mohor
    stuff_err_latched <=#Tp 1'b0;
1247
  else if (stuff_err)
1248
    stuff_err_latched <=#Tp 1'b1;
1249
end
1250
 
1251
 
1252
 
1253
always @ (posedge clk or posedge rst)
1254
begin
1255
  if (rst)
1256
    form_err_latched <= 1'b0;
1257 30 mohor
  else if (reset_mode | error_frame_ended | go_overload_frame)
1258 28 mohor
    form_err_latched <=#Tp 1'b0;
1259
  else if (form_err)
1260
    form_err_latched <=#Tp 1'b1;
1261
end
1262
 
1263
 
1264
 
1265 11 mohor
// Instantiation of the RX CRC module
1266
can_crc i_can_crc_rx
1267
(
1268
  .clk(clk),
1269 25 mohor
  .data(sampled_bit),
1270 11 mohor
  .enable(crc_enable & sample_point & (~bit_de_stuff)),
1271 35 mohor
  .initialize(go_crc_enable),
1272 11 mohor
  .crc(calculated_crc)
1273
);
1274
 
1275
 
1276
 
1277
 
1278 107 mohor
assign no_byte0 = rtr1 | (data_len<4'h1);
1279
assign no_byte1 = rtr1 | (data_len<4'h2);
1280 11 mohor
 
1281
can_acf i_can_acf
1282
(
1283
  .clk(clk),
1284
  .rst(rst),
1285
 
1286
  .id(id),
1287
 
1288
  /* Mode register */
1289
  .reset_mode(reset_mode),
1290
  .acceptance_filter_mode(acceptance_filter_mode),
1291
 
1292 12 mohor
  // Clock Divider register
1293 11 mohor
  .extended_mode(extended_mode),
1294
 
1295
  /* This section is for BASIC and EXTENDED mode */
1296
  /* Acceptance code register */
1297
  .acceptance_code_0(acceptance_code_0),
1298
 
1299
  /* Acceptance mask register */
1300
  .acceptance_mask_0(acceptance_mask_0),
1301
  /* End: This section is for BASIC and EXTENDED mode */
1302
 
1303
  /* This section is for EXTENDED mode */
1304
  /* Acceptance code register */
1305
  .acceptance_code_1(acceptance_code_1),
1306
  .acceptance_code_2(acceptance_code_2),
1307
  .acceptance_code_3(acceptance_code_3),
1308
 
1309
  /* Acceptance mask register */
1310
  .acceptance_mask_1(acceptance_mask_1),
1311
  .acceptance_mask_2(acceptance_mask_2),
1312
  .acceptance_mask_3(acceptance_mask_3),
1313
  /* End: This section is for EXTENDED mode */
1314
 
1315
  .go_rx_crc_lim(go_rx_crc_lim),
1316 29 mohor
  .go_rx_inter(go_rx_inter),
1317 30 mohor
  .go_error_frame(go_error_frame),
1318 11 mohor
 
1319
  .data0(tmp_fifo[0]),
1320
  .data1(tmp_fifo[1]),
1321
  .rtr1(rtr1),
1322
  .rtr2(rtr2),
1323
  .ide(ide),
1324 16 mohor
  .no_byte0(no_byte0),
1325
  .no_byte1(no_byte1),
1326 11 mohor
 
1327
  .id_ok(id_ok)
1328
 
1329
);
1330
 
1331
 
1332
 
1333
 
1334 16 mohor
assign header_len[2:0] = extended_mode ? (ide? (3'h5) : (3'h3)) : 3'h2;
1335 13 mohor
assign storing_header = header_cnt < header_len;
1336 107 mohor
assign limited_data_len_minus1[3:0] = remote_rq? 4'hf : ((data_len < 4'h8)? (data_len -1'b1) : 4'h7);   // - 1 because counter counts from 0
1337
assign reset_wr_fifo = (data_cnt == (limited_data_len_minus1 + {1'b0, header_len})) | reset_mode;
1338 12 mohor
 
1339 28 mohor
assign err = form_err | stuff_err | bit_err | ack_err | form_err_latched | stuff_err_latched | bit_err_latched | ack_err_latched | crc_err;
1340 24 mohor
 
1341
 
1342 28 mohor
 
1343 13 mohor
// Write enable signal for 64-byte rx fifo
1344
always @ (posedge clk or posedge rst)
1345
begin
1346
  if (rst)
1347
    wr_fifo <= 1'b0;
1348 16 mohor
  else if (reset_wr_fifo)
1349
    wr_fifo <=#Tp 1'b0;
1350 36 mohor
  else if (go_rx_inter & id_ok & (~error_frame_ended) & ((~tx_state) | self_rx_request))
1351 13 mohor
    wr_fifo <=#Tp 1'b1;
1352
end
1353 12 mohor
 
1354
 
1355 13 mohor
// Header counter. Header length depends on the mode of operation and frame format.
1356 12 mohor
always @ (posedge clk or posedge rst)
1357
begin
1358
  if (rst)
1359 107 mohor
    header_cnt <= 3'h0;
1360 16 mohor
  else if (reset_wr_fifo)
1361 107 mohor
    header_cnt <=#Tp 3'h0;
1362 16 mohor
  else if (wr_fifo & storing_header)
1363 107 mohor
    header_cnt <=#Tp header_cnt + 1'h1;
1364 12 mohor
end
1365
 
1366
 
1367 13 mohor
// Data counter. Length of the data is limited to 8 bytes.
1368 12 mohor
always @ (posedge clk or posedge rst)
1369
begin
1370
  if (rst)
1371 107 mohor
    data_cnt <= 4'h0;
1372 16 mohor
  else if (reset_wr_fifo)
1373 107 mohor
    data_cnt <=#Tp 4'h0;
1374 16 mohor
  else if (wr_fifo)
1375 107 mohor
    data_cnt <=#Tp data_cnt + 4'h1;
1376 12 mohor
end
1377
 
1378
 
1379 13 mohor
// Multiplexing data that is stored to 64-byte fifo depends on the mode of operation and frame format
1380 24 mohor
always @ (extended_mode or ide or data_cnt or header_cnt or  header_len or
1381
          storing_header or id or rtr1 or rtr2 or data_len or
1382 13 mohor
          tmp_fifo[0] or tmp_fifo[2] or tmp_fifo[4] or tmp_fifo[6] or
1383
          tmp_fifo[1] or tmp_fifo[3] or tmp_fifo[5] or tmp_fifo[7])
1384 12 mohor
begin
1385 107 mohor
  casex ({storing_header, extended_mode, ide, header_cnt}) /* synthesis parallel_case */
1386
    6'b1_1_1_000  : data_for_fifo = {1'b1, rtr2, 2'h0, data_len};  // extended mode, extended format header
1387
    6'b1_1_1_001  : data_for_fifo = id[28:21];                     // extended mode, extended format header
1388
    6'b1_1_1_010  : data_for_fifo = id[20:13];                     // extended mode, extended format header
1389
    6'b1_1_1_011  : data_for_fifo = id[12:5];                      // extended mode, extended format header
1390
    6'b1_1_1_100  : data_for_fifo = {id[4:0], 3'h0};               // extended mode, extended format header
1391
    6'b1_1_0_000  : data_for_fifo = {1'b0, rtr1, 2'h0, data_len};  // extended mode, standard format header
1392
    6'b1_1_0_001  : data_for_fifo = id[10:3];                      // extended mode, standard format header
1393
    6'b1_1_0_010  : data_for_fifo = {id[2:0], 5'h0};               // extended mode, standard format header
1394
    6'b1_0_x_000  : data_for_fifo = id[10:3];                      // normal mode                    header
1395
    6'b1_0_x_001  : data_for_fifo = {id[2:0], rtr1, data_len};     // normal mode                    header
1396
    default       : data_for_fifo = tmp_fifo[data_cnt - {1'b0, header_len}]; // data 
1397
  endcase
1398 12 mohor
end
1399
 
1400
 
1401
 
1402
 
1403
// Instantiation of the RX fifo module
1404 13 mohor
can_fifo i_can_fifo
1405 12 mohor
(
1406
  .clk(clk),
1407
  .rst(rst),
1408
 
1409 13 mohor
  .wr(wr_fifo),
1410 12 mohor
 
1411 13 mohor
  .data_in(data_for_fifo),
1412 110 mohor
  .addr(addr[5:0]),
1413 14 mohor
  .data_out(data_out),
1414 48 mohor
  .fifo_selected(fifo_selected),
1415 12 mohor
 
1416
  .reset_mode(reset_mode),
1417 15 mohor
  .release_buffer(release_buffer),
1418 35 mohor
  .extended_mode(extended_mode),
1419
  .overrun(overrun),
1420 39 mohor
  .info_empty(info_empty),
1421
  .info_cnt(rx_message_counter)
1422 95 simons
 
1423
`ifdef CAN_BIST
1424
  ,
1425
  .scanb_rst(scanb_rst),
1426
  .scanb_clk(scanb_clk),
1427
  .scanb_si(scanb_si),
1428
  .scanb_so(scanb_so),
1429
  .scanb_en(scanb_en)
1430
`endif
1431 12 mohor
);
1432
 
1433
 
1434 29 mohor
// Transmitting error frame.
1435 24 mohor
always @ (posedge clk or posedge rst)
1436
begin
1437
  if (rst)
1438
    error_frame <= 1'b0;
1439 30 mohor
  else if (reset_mode | error_frame_ended | go_overload_frame)
1440 24 mohor
    error_frame <=#Tp 1'b0;
1441 28 mohor
  else if (go_error_frame)
1442 24 mohor
    error_frame <=#Tp 1'b1;
1443
end
1444 12 mohor
 
1445 13 mohor
 
1446 107 mohor
always @ (posedge clk or posedge rst)
1447 28 mohor
begin
1448 107 mohor
  if (rst)
1449
    error_frame_q <=#Tp 1'b0;
1450
  else if (sample_point)
1451 28 mohor
    error_frame_q <=#Tp error_frame;
1452
end
1453
 
1454
 
1455 24 mohor
always @ (posedge clk or posedge rst)
1456
begin
1457
  if (rst)
1458 107 mohor
    error_cnt1 <= 3'd0;
1459 30 mohor
  else if (reset_mode | error_frame_ended | go_error_frame | go_overload_frame)
1460 107 mohor
    error_cnt1 <=#Tp 3'd0;
1461
  else if (error_frame & tx_point & (error_cnt1 < 3'd7))
1462 24 mohor
    error_cnt1 <=#Tp error_cnt1 + 1'b1;
1463
end
1464
 
1465
 
1466 28 mohor
 
1467 107 mohor
assign error_flag_over = ((~node_error_passive) & sample_point & (error_cnt1 == 3'd7) | node_error_passive  & sample_point & (passive_cnt == 3'h5)) & (~enable_error_cnt2);
1468 28 mohor
 
1469
 
1470 24 mohor
always @ (posedge clk or posedge rst)
1471
begin
1472
  if (rst)
1473 125 mohor
    error_flag_over_latched <= 1'b0;
1474 30 mohor
  else if (reset_mode | error_frame_ended | go_error_frame | go_overload_frame)
1475 125 mohor
    error_flag_over_latched <=#Tp 1'b0;
1476 28 mohor
  else if (error_flag_over)
1477 125 mohor
    error_flag_over_latched <=#Tp 1'b1;
1478 28 mohor
end
1479
 
1480
 
1481
always @ (posedge clk or posedge rst)
1482
begin
1483
  if (rst)
1484 24 mohor
    enable_error_cnt2 <= 1'b0;
1485 30 mohor
  else if (reset_mode | error_frame_ended | go_error_frame | go_overload_frame)
1486 24 mohor
    enable_error_cnt2 <=#Tp 1'b0;
1487 30 mohor
  else if (error_frame & (error_flag_over & sampled_bit))
1488 24 mohor
    enable_error_cnt2 <=#Tp 1'b1;
1489
end
1490
 
1491
 
1492
always @ (posedge clk or posedge rst)
1493
begin
1494
  if (rst)
1495 107 mohor
    error_cnt2 <= 3'd0;
1496 30 mohor
  else if (reset_mode | error_frame_ended | go_error_frame | go_overload_frame)
1497 107 mohor
    error_cnt2 <=#Tp 3'd0;
1498 24 mohor
  else if (enable_error_cnt2 & tx_point)
1499
    error_cnt2 <=#Tp error_cnt2 + 1'b1;
1500
end
1501
 
1502
 
1503 28 mohor
always @ (posedge clk or posedge rst)
1504
begin
1505
  if (rst)
1506 107 mohor
    delayed_dominant_cnt <= 3'h0;
1507 29 mohor
  else if (reset_mode | enable_error_cnt2 | go_error_frame | enable_overload_cnt2 | go_overload_frame)
1508 107 mohor
    delayed_dominant_cnt <=#Tp 3'h0;
1509
  else if (sample_point & (~sampled_bit) & ((error_cnt1 == 3'd7) | (overload_cnt1 == 3'd7)))
1510 29 mohor
    delayed_dominant_cnt <=#Tp delayed_dominant_cnt + 1'b1;
1511 28 mohor
end
1512 24 mohor
 
1513 25 mohor
 
1514 28 mohor
// passive_cnt
1515
always @ (posedge clk or posedge rst)
1516
begin
1517
  if (rst)
1518 107 mohor
    passive_cnt <= 3'h0;
1519 30 mohor
  else if (reset_mode | error_frame_ended | go_error_frame | go_overload_frame)
1520 107 mohor
    passive_cnt <=#Tp 3'h0;
1521
  else if (sample_point & (passive_cnt < 3'h5))
1522 28 mohor
    begin
1523
      if (error_frame_q & (~enable_error_cnt2) & (sampled_bit == sampled_bit_q))
1524
        passive_cnt <=#Tp passive_cnt + 1'b1;
1525
      else
1526 107 mohor
        passive_cnt <=#Tp 3'h0;
1527 28 mohor
    end
1528
end
1529 25 mohor
 
1530
 
1531 29 mohor
 
1532
// Transmitting overload frame.
1533
always @ (posedge clk or posedge rst)
1534
begin
1535
  if (rst)
1536
    overload_frame <= 1'b0;
1537
  else if (reset_mode | overload_frame_ended | go_error_frame)
1538
    overload_frame <=#Tp 1'b0;
1539
  else if (go_overload_frame)
1540
    overload_frame <=#Tp 1'b1;
1541
end
1542
 
1543
 
1544
always @ (posedge clk or posedge rst)
1545
begin
1546
  if (rst)
1547 107 mohor
    overload_cnt1 <= 3'd0;
1548 30 mohor
  else if (reset_mode | overload_frame_ended | go_error_frame | go_overload_frame)
1549 107 mohor
    overload_cnt1 <=#Tp 3'd0;
1550
  else if (overload_frame & tx_point & (overload_cnt1 < 3'd7))
1551 29 mohor
    overload_cnt1 <=#Tp overload_cnt1 + 1'b1;
1552
end
1553
 
1554
 
1555 107 mohor
assign overload_flag_over = sample_point & (overload_cnt1 == 3'd7) & (~enable_overload_cnt2);
1556 29 mohor
 
1557
 
1558
always @ (posedge clk or posedge rst)
1559
begin
1560
  if (rst)
1561
    enable_overload_cnt2 <= 1'b0;
1562 30 mohor
  else if (reset_mode | overload_frame_ended | go_error_frame | go_overload_frame)
1563 29 mohor
    enable_overload_cnt2 <=#Tp 1'b0;
1564 30 mohor
  else if (overload_frame & (overload_flag_over & sampled_bit))
1565 29 mohor
    enable_overload_cnt2 <=#Tp 1'b1;
1566
end
1567
 
1568
 
1569
always @ (posedge clk or posedge rst)
1570
begin
1571
  if (rst)
1572 107 mohor
    overload_cnt2 <= 3'd0;
1573 30 mohor
  else if (reset_mode | overload_frame_ended | go_error_frame | go_overload_frame)
1574 107 mohor
    overload_cnt2 <=#Tp 3'd0;
1575 29 mohor
  else if (enable_overload_cnt2 & tx_point)
1576
    overload_cnt2 <=#Tp overload_cnt2 + 1'b1;
1577
end
1578
 
1579
 
1580 30 mohor
always @ (posedge clk or posedge rst)
1581
begin
1582
  if (rst)
1583 125 mohor
    overload_request_cnt <= 2'b0;
1584
  else if (reset_mode | go_error_frame | go_rx_id1)
1585
    overload_request_cnt <=#Tp 2'b0;
1586
  else if (overload_request & overload_frame)
1587
    overload_request_cnt <=#Tp overload_request_cnt + 1'b1;
1588
end
1589
 
1590
 
1591
always @ (posedge clk or posedge rst)
1592
begin
1593
  if (rst)
1594 107 mohor
    overload_frame_blocked <= 1'b0;
1595 30 mohor
  else if (reset_mode | go_error_frame | go_rx_id1)
1596 107 mohor
    overload_frame_blocked <=#Tp 1'b0;
1597 125 mohor
  else if (overload_request & overload_frame & overload_request_cnt == 2'h2)   // This is a second sequential overload_request
1598 30 mohor
    overload_frame_blocked <=#Tp 1'b1;
1599
end
1600
 
1601
 
1602 36 mohor
assign send_ack = (~tx_state) & rx_ack & (~err) & (~listen_only_mode);
1603 25 mohor
 
1604
 
1605 125 mohor
reg tx_next;
1606
always @ (reset_mode or tx_state or bit_de_stuff_tx or tx_bit or tx_q or
1607 126 mohor
//always @ (reset_mode or go_tx or tx_state or bit_de_stuff_tx or tx_bit or tx_q or
1608
          send_ack or go_overload_frame or overload_frame or overload_cnt1 or
1609
          go_error_frame or error_frame or error_cnt1 or node_error_passive)
1610 24 mohor
begin
1611 125 mohor
  if (reset_mode)                                                               // Reset
1612
    tx_next = 1'b1;
1613
  else
1614 24 mohor
    begin
1615 126 mohor
      if (go_error_frame | error_frame)                                         // Transmitting error frame
1616 30 mohor
        begin
1617 107 mohor
          if (error_cnt1 < 3'd6)
1618 25 mohor
            begin
1619 29 mohor
              if (node_error_passive)
1620 125 mohor
                tx_next = 1'b1;
1621 25 mohor
              else
1622 125 mohor
                tx_next = 1'b0;
1623 25 mohor
            end
1624 29 mohor
          else
1625 125 mohor
            tx_next = 1'b1;
1626 24 mohor
        end
1627 126 mohor
      else if (go_overload_frame | overload_frame)                              // Transmitting overload frame
1628
        begin
1629
          if (overload_cnt1 < 3'd6)
1630
            tx_next = 1'b0;
1631
          else
1632
            tx_next = 1'b1;
1633
        end
1634
      else if (tx_state)                                                        // Transmitting message
1635
//      else if (go_tx | tx_state)                                                // Transmitting message
1636
        tx_next = ((~bit_de_stuff_tx) & tx_bit) | (bit_de_stuff_tx & (~tx_q));
1637
      else if (send_ack)                                                        // Acknowledge
1638
        tx_next = 1'b0;
1639 25 mohor
      else
1640 125 mohor
        tx_next = 1'b1;
1641 24 mohor
    end
1642
end
1643
 
1644
 
1645 125 mohor
always @ (posedge clk or posedge rst)
1646
begin
1647
  if (rst)
1648
    tx <= 1'b1;
1649
  else if (tx_point)
1650
    tx <=#Tp tx_next;
1651
end
1652 45 mohor
 
1653 125 mohor
 
1654 107 mohor
always @ (posedge clk or posedge rst)
1655 25 mohor
begin
1656 107 mohor
  if (rst)
1657
    tx_q <=#Tp 1'b0;
1658
  else if (tx_point)
1659 45 mohor
    tx_q <=#Tp tx & (~go_early_tx_latched);
1660 25 mohor
end
1661 24 mohor
 
1662
 
1663 25 mohor
/* Delayed tx point */
1664 107 mohor
always @ (posedge clk or posedge rst)
1665 25 mohor
begin
1666 107 mohor
  if (rst)
1667
    tx_point_q <=#Tp 1'b0;
1668
  else
1669
    tx_point_q <=#Tp tx_point;
1670 25 mohor
end
1671 24 mohor
 
1672
 
1673 25 mohor
/* Changing bit order from [7:0] to [0:7] */
1674
can_ibo i_ibo_tx_data_0  (.di(tx_data_0),  .do(r_tx_data_0));
1675
can_ibo i_ibo_tx_data_1  (.di(tx_data_1),  .do(r_tx_data_1));
1676
can_ibo i_ibo_tx_data_2  (.di(tx_data_2),  .do(r_tx_data_2));
1677
can_ibo i_ibo_tx_data_3  (.di(tx_data_3),  .do(r_tx_data_3));
1678
can_ibo i_ibo_tx_data_4  (.di(tx_data_4),  .do(r_tx_data_4));
1679
can_ibo i_ibo_tx_data_5  (.di(tx_data_5),  .do(r_tx_data_5));
1680
can_ibo i_ibo_tx_data_6  (.di(tx_data_6),  .do(r_tx_data_6));
1681
can_ibo i_ibo_tx_data_7  (.di(tx_data_7),  .do(r_tx_data_7));
1682
can_ibo i_ibo_tx_data_8  (.di(tx_data_8),  .do(r_tx_data_8));
1683
can_ibo i_ibo_tx_data_9  (.di(tx_data_9),  .do(r_tx_data_9));
1684
can_ibo i_ibo_tx_data_10 (.di(tx_data_10), .do(r_tx_data_10));
1685
can_ibo i_ibo_tx_data_11 (.di(tx_data_11), .do(r_tx_data_11));
1686
can_ibo i_ibo_tx_data_12 (.di(tx_data_12), .do(r_tx_data_12));
1687 24 mohor
 
1688 25 mohor
/* Changing bit order from [14:0] to [0:14] */
1689
can_ibo i_calculated_crc0 (.di(calculated_crc[14:7]), .do(r_calculated_crc[7:0]));
1690
can_ibo i_calculated_crc1 (.di({calculated_crc[6:0], 1'b0}), .do(r_calculated_crc[15:8]));
1691 24 mohor
 
1692
 
1693 25 mohor
assign basic_chain = {r_tx_data_1[7:4], 2'h0, r_tx_data_1[3:0], r_tx_data_0[7:0], 1'b0};
1694
assign basic_chain_data = {r_tx_data_9, r_tx_data_8, r_tx_data_7, r_tx_data_6, r_tx_data_5, r_tx_data_4, r_tx_data_3, r_tx_data_2};
1695
assign extended_chain_std = {r_tx_data_0[7:4], 2'h0, r_tx_data_0[1], r_tx_data_2[2:0], r_tx_data_1[7:0], 1'b0};
1696
assign extended_chain_ext = {r_tx_data_0[7:4], 2'h0, r_tx_data_0[1], r_tx_data_4[4:0], r_tx_data_3[7:0], r_tx_data_2[7:3], 1'b1, 1'b1, r_tx_data_2[2:0], r_tx_data_1[7:0], 1'b0};
1697 78 mohor
assign extended_chain_data_std = {r_tx_data_10, r_tx_data_9, r_tx_data_8, r_tx_data_7, r_tx_data_6, r_tx_data_5, r_tx_data_4, r_tx_data_3};
1698
assign extended_chain_data_ext = {r_tx_data_12, r_tx_data_11, r_tx_data_10, r_tx_data_9, r_tx_data_8, r_tx_data_7, r_tx_data_6, r_tx_data_5};
1699 25 mohor
 
1700 78 mohor
always @ (extended_mode or rx_data or tx_pointer or extended_chain_data_std or extended_chain_data_ext or rx_crc or r_calculated_crc or
1701 25 mohor
          r_tx_data_0   or extended_chain_ext or extended_chain_std or basic_chain_data or basic_chain or
1702
          finish_msg)
1703
begin
1704
  if (extended_mode)
1705
    begin
1706
      if (rx_data)  // data stage
1707 78 mohor
        if (r_tx_data_0[0])    // Extended frame
1708
          tx_bit = extended_chain_data_ext[tx_pointer];
1709
        else
1710
          tx_bit = extended_chain_data_std[tx_pointer];
1711 25 mohor
      else if (rx_crc)
1712
        tx_bit = r_calculated_crc[tx_pointer];
1713
      else if (finish_msg)
1714
        tx_bit = 1'b1;
1715
      else
1716
        begin
1717
          if (r_tx_data_0[0])    // Extended frame
1718
            tx_bit = extended_chain_ext[tx_pointer];
1719
          else
1720
            tx_bit = extended_chain_std[tx_pointer];
1721
        end
1722
    end
1723
  else  // Basic mode
1724
    begin
1725
      if (rx_data)  // data stage
1726
        tx_bit = basic_chain_data[tx_pointer];
1727
      else if (rx_crc)
1728
        tx_bit = r_calculated_crc[tx_pointer];
1729
      else if (finish_msg)
1730
        tx_bit = 1'b1;
1731
      else
1732
        tx_bit = basic_chain[tx_pointer];
1733
    end
1734
end
1735
 
1736
 
1737 112 tadejm
assign limited_tx_cnt_ext = tx_data_0[3] ? 6'h3f : ((tx_data_0[2:0] <<3) - 1'b1);
1738
assign limited_tx_cnt_std = tx_data_1[3] ? 6'h3f : ((tx_data_1[2:0] <<3) - 1'b1);
1739
 
1740
assign rst_tx_pointer = ((~bit_de_stuff_tx) & tx_point & (~rx_data) &   extended_mode  &   r_tx_data_0[0]   & tx_pointer == 6'd38             ) |   // arbitration + control for extended format
1741
                        ((~bit_de_stuff_tx) & tx_point & (~rx_data) &   extended_mode  & (~r_tx_data_0[0])  & tx_pointer == 6'd18             ) |   // arbitration + control for extended format
1742
                        ((~bit_de_stuff_tx) & tx_point & (~rx_data) & (~extended_mode)                      & tx_pointer == 6'd18             ) |   // arbitration + control for standard format
1743
                        ((~bit_de_stuff_tx) & tx_point &   rx_data  &   extended_mode                       & tx_pointer == limited_tx_cnt_ext) |   // data       (overflow is OK here)
1744
                        ((~bit_de_stuff_tx) & tx_point &   rx_data  & (~extended_mode)                      & tx_pointer == limited_tx_cnt_std) |   // data       (overflow is OK here)
1745
                        (                     tx_point &   rx_crc_lim                                                                         ) |   // crc
1746
                        (go_rx_idle                                                                                                           ) |   // at the end
1747
                        (reset_mode                                                                                                           ) |
1748
                        (overload_frame                                                                                                       ) |
1749
                        (error_frame                                                                                                          ) ;
1750
 
1751 25 mohor
always @ (posedge clk or posedge rst)
1752
begin
1753
  if (rst)
1754 107 mohor
    tx_pointer <= 6'h0;
1755 25 mohor
  else if (rst_tx_pointer)
1756 107 mohor
    tx_pointer <=#Tp 6'h0;
1757 25 mohor
  else if (go_early_tx | (tx_point & tx_state & (~bit_de_stuff_tx)))
1758
    tx_pointer <=#Tp tx_pointer + 1'b1;
1759
end
1760
 
1761
 
1762 104 tadejm
//assign tx_successful = transmitter & go_rx_inter & ((~error_frame_ended) & (~overload_frame_ended) & (~arbitration_lost) | single_shot_transmission);
1763
assign tx_successful = transmitter & go_rx_inter & (~error_frame_ended) & (~overload_frame_ended) & (~arbitration_lost);
1764 28 mohor
 
1765
 
1766 25 mohor
always @ (posedge clk or posedge rst)
1767
begin
1768
  if (rst)
1769
    need_to_tx <= 1'b0;
1770 104 tadejm
  else if (tx_successful | reset_mode | (abort_tx & (~transmitting)) | ((~tx_state) & tx_state_q & single_shot_transmission))
1771 28 mohor
    need_to_tx <=#Tp 1'h0;
1772 32 mohor
  else if (tx_request & sample_point)
1773 25 mohor
    need_to_tx <=#Tp 1'b1;
1774
end
1775
 
1776
 
1777
 
1778 36 mohor
assign go_early_tx = (~listen_only_mode) & need_to_tx & (~tx_state) & (~suspend) & sample_point & (~sampled_bit) & (rx_idle | last_bit_of_inter);
1779
assign go_tx       = (~listen_only_mode) & need_to_tx & (~tx_state) & (~suspend) & (go_early_tx | rx_idle);
1780 25 mohor
 
1781
 
1782 45 mohor
// go_early_tx latched (for proper bit_de_stuff generation)
1783
always @ (posedge clk or posedge rst)
1784
begin
1785
  if (rst)
1786
    go_early_tx_latched <= 1'b0;
1787 126 mohor
//  else if (tx_point_q)
1788
  else if (tx_point)
1789 45 mohor
    go_early_tx_latched <=#Tp 1'b0;
1790
  else if (go_early_tx)
1791
    go_early_tx_latched <=#Tp 1'b1;
1792
end
1793
 
1794
 
1795
 
1796 25 mohor
// Tx state
1797
always @ (posedge clk or posedge rst)
1798
begin
1799
  if (rst)
1800
    tx_state <= 1'b0;
1801 39 mohor
  else if (reset_mode | go_rx_inter | error_frame | arbitration_lost)
1802 25 mohor
    tx_state <=#Tp 1'b0;
1803
  else if (go_tx)
1804
    tx_state <=#Tp 1'b1;
1805
end
1806
 
1807 107 mohor
always @ (posedge clk or posedge rst)
1808 104 tadejm
begin
1809 107 mohor
  if (rst)
1810
    tx_state_q <=#Tp 1'b0;
1811
  else
1812
    tx_state_q <=#Tp tx_state;
1813 104 tadejm
end
1814 25 mohor
 
1815
 
1816 104 tadejm
 
1817 28 mohor
// Node is a transmitter
1818 25 mohor
always @ (posedge clk or posedge rst)
1819
begin
1820
  if (rst)
1821 28 mohor
    transmitter <= 1'b0;
1822
  else if (go_tx)
1823
    transmitter <=#Tp 1'b1;
1824 125 mohor
//  else if ((reset_mode | go_rx_inter ) | ((~tx_state) & tx_state_q))
1825
  else if (reset_mode | go_rx_idle)
1826 28 mohor
    transmitter <=#Tp 1'b0;
1827
end
1828 125 mohor
 
1829 28 mohor
 
1830
 
1831
// Signal "transmitting" signals that the core is a transmitting (message, error frame or overload frame). No synchronization is done meanwhile.
1832
// Node might be both transmitter or receiver (sending error or overload frame)
1833
always @ (posedge clk or posedge rst)
1834
begin
1835
  if (rst)
1836 26 mohor
    transmitting <= 1'b0;
1837 125 mohor
//  else if (go_error_frame | go_overload_frame | go_tx)
1838
  else if (go_error_frame | go_overload_frame | go_tx | send_ack)
1839 28 mohor
    transmitting <=#Tp 1'b1;
1840 125 mohor
  else if (reset_mode | go_rx_idle | (go_rx_id1 & (~tx_state)) | (arbitration_lost & tx_state) | rx_ack_lim)
1841 26 mohor
    transmitting <=#Tp 1'b0;
1842
end
1843
 
1844
 
1845 28 mohor
always @ (posedge clk or posedge rst)
1846
begin
1847
  if (rst)
1848 107 mohor
    suspend <= 1'b0;
1849
  else if (reset_mode | (sample_point & (susp_cnt == 3'h7)))
1850
    suspend <=#Tp 1'b0;
1851 125 mohor
//  else if (go_rx_inter & transmitter & node_error_passive)
1852 126 mohor
  else if (not_first_bit_of_inter & transmitter & node_error_passive)
1853 28 mohor
    suspend <=#Tp 1'b1;
1854
end
1855 26 mohor
 
1856 28 mohor
 
1857 26 mohor
always @ (posedge clk or posedge rst)
1858
begin
1859
  if (rst)
1860 107 mohor
    susp_cnt_en <= 1'b0;
1861
  else if (reset_mode | (sample_point & (susp_cnt == 3'h7)))
1862
    susp_cnt_en <=#Tp 1'b0;
1863 29 mohor
  else if (suspend & sample_point & last_bit_of_inter)
1864 28 mohor
    susp_cnt_en <=#Tp 1'b1;
1865
end
1866
 
1867
 
1868
always @ (posedge clk or posedge rst)
1869
begin
1870
  if (rst)
1871 107 mohor
    susp_cnt <= 3'h0;
1872
  else if (reset_mode | (sample_point & (susp_cnt == 3'h7)))
1873
    susp_cnt <=#Tp 3'h0;
1874 28 mohor
  else if (susp_cnt_en & sample_point)
1875
    susp_cnt <=#Tp susp_cnt + 1'b1;
1876
end
1877
 
1878
 
1879
 
1880
 
1881
always @ (posedge clk or posedge rst)
1882
begin
1883
  if (rst)
1884 25 mohor
    finish_msg <= 1'b0;
1885 28 mohor
  else if (go_rx_idle | go_rx_id1 | error_frame | reset_mode)
1886 25 mohor
    finish_msg <=#Tp 1'b0;
1887
  else if (go_rx_crc_lim)
1888
    finish_msg <=#Tp 1'b1;
1889
end
1890
 
1891
 
1892
always @ (posedge clk or posedge rst)
1893
begin
1894
  if (rst)
1895 39 mohor
    arbitration_lost <= 1'b0;
1896 25 mohor
  else if (go_rx_idle | error_frame | reset_mode)
1897 39 mohor
    arbitration_lost <=#Tp 1'b0;
1898 28 mohor
  else if (tx_state & sample_point & tx & arbitration_field)
1899 39 mohor
    arbitration_lost <=#Tp (~sampled_bit);
1900 25 mohor
end
1901
 
1902
 
1903 107 mohor
always @ (posedge clk or posedge rst)
1904 39 mohor
begin
1905 107 mohor
  if (rst)
1906
    arbitration_lost_q <=#Tp 1'b0;
1907
  else
1908
    arbitration_lost_q <=#Tp arbitration_lost;
1909 39 mohor
end
1910 25 mohor
 
1911 39 mohor
 
1912
assign set_arbitration_lost_irq = arbitration_lost & (~arbitration_lost_q) & (~arbitration_blocked);
1913
 
1914
 
1915 28 mohor
always @ (posedge clk or posedge rst)
1916
begin
1917
  if (rst)
1918 39 mohor
    arbitration_cnt_en <= 1'b0;
1919
  else if (arbitration_blocked)
1920
    arbitration_cnt_en <=#Tp 1'b0;
1921
  else if (rx_id1 & sample_point & (~arbitration_blocked))
1922
    arbitration_cnt_en <=#Tp 1'b1;
1923
end
1924
 
1925
 
1926
 
1927
always @ (posedge clk or posedge rst)
1928
begin
1929
  if (rst)
1930
    arbitration_blocked <= 1'b0;
1931
  else if (read_arbitration_lost_capture_reg)
1932
    arbitration_blocked <=#Tp 1'b0;
1933
  else if (set_arbitration_lost_irq)
1934
    arbitration_blocked <=#Tp 1'b1;
1935
end
1936
 
1937
 
1938
always @ (posedge clk or posedge rst)
1939
begin
1940
  if (rst)
1941
    arbitration_lost_capture <= 5'h0;
1942
  else if (read_arbitration_lost_capture_reg)
1943
    arbitration_lost_capture <=#Tp 5'h0;
1944
  else if (sample_point & (~arbitration_blocked) & arbitration_cnt_en & (~bit_de_stuff))
1945
    arbitration_lost_capture <=#Tp arbitration_lost_capture + 1'b1;
1946
end
1947
 
1948
 
1949
 
1950
always @ (posedge clk or posedge rst)
1951
begin
1952
  if (rst)
1953 107 mohor
    rx_err_cnt <= 9'h0;
1954 35 mohor
  else if (we_rx_err_cnt & (~node_bus_off))
1955
    rx_err_cnt <=#Tp {1'b0, data_in};
1956
  else if (set_reset_mode)
1957 107 mohor
    rx_err_cnt <=#Tp 9'h0;
1958 28 mohor
  else
1959
    begin
1960 126 mohor
      if ((~listen_only_mode) & (~transmitter | arbitration_lost))
1961 28 mohor
        begin
1962 126 mohor
          if (go_rx_ack_lim & (~go_error_frame) & (~crc_err) & (rx_err_cnt > 9'h0))
1963 36 mohor
            begin
1964 107 mohor
              if (rx_err_cnt > 9'd127)
1965
                rx_err_cnt <=#Tp 9'd127;
1966 36 mohor
              else
1967
                rx_err_cnt <=#Tp rx_err_cnt - 1'b1;
1968
            end
1969 126 mohor
          else if (rx_err_cnt < 9'd248)   // 248 + 8 = 256
1970 36 mohor
            begin
1971 44 mohor
              if (go_error_frame & (~rule5))                                                                            // 1  (rule 5 is just the opposite then rule 1 exception
1972 36 mohor
                rx_err_cnt <=#Tp rx_err_cnt + 1'b1;
1973 126 mohor
              else if ( (error_flag_over & (~error_flag_over_latched) & sample_point & (~sampled_bit) & (error_cnt1 == 3'd7) & (~rx_err_cnt_blocked)  ) |   // 2
1974 125 mohor
                        (go_error_frame & rule5                                                                                  ) |   // 5
1975 126 mohor
//                        (error_frame & sample_point & (~sampled_bit) & (delayed_dominant_cnt == 3'h7)                            )     // 6
1976
                        (sample_point & (~sampled_bit) & (delayed_dominant_cnt == 3'h7)                            )     // 6
1977 36 mohor
                      )
1978
                rx_err_cnt <=#Tp rx_err_cnt + 4'h8;
1979
            end
1980 30 mohor
        end
1981 28 mohor
    end
1982
end
1983
 
1984
 
1985
always @ (posedge clk or posedge rst)
1986
begin
1987
  if (rst)
1988 107 mohor
    tx_err_cnt <= 9'h0;
1989 35 mohor
  else if (we_tx_err_cnt)
1990
    tx_err_cnt <=#Tp {1'b0, data_in};
1991 28 mohor
  else
1992
    begin
1993 35 mohor
      if (set_reset_mode)
1994 107 mohor
        tx_err_cnt <=#Tp 9'd127;
1995
      else if ((tx_err_cnt > 9'd0) & (tx_successful | bus_free))
1996 30 mohor
        tx_err_cnt <=#Tp tx_err_cnt - 1'h1;
1997 126 mohor
      else if (transmitter & (~arbitration_lost))
1998 28 mohor
        begin
1999 107 mohor
          if ( (sample_point & (~sampled_bit) & (delayed_dominant_cnt == 3'h7)                  ) |       // 6
2000 44 mohor
               (go_error_frame & rule5                                                          ) |       // 4  (rule 5 is the same as rule 4)
2001 125 mohor
//               (error_flag_over & (~error_flag_over_latched) & (~rule3_exc1_2) & (~rule3_exc2)  )         // 3
2002 126 mohor
//               (go_error_frame & (~(transmitter & node_error_passive & ack_err))                ) // 3 ?
2003
               (go_error_frame & (~(transmitter & node_error_passive & ack_err))                ) |       // 3 
2004
               (error_frame & rule3_exc1_2)                                                               // 3
2005 28 mohor
             )
2006
            tx_err_cnt <=#Tp tx_err_cnt + 4'h8;
2007
        end
2008
    end
2009
end
2010
 
2011
 
2012
always @ (posedge clk or posedge rst)
2013
begin
2014
  if (rst)
2015
    rx_err_cnt_blocked <= 1'b0;
2016
  else if (reset_mode | error_frame_ended)
2017
    rx_err_cnt_blocked <=#Tp 1'b0;
2018 107 mohor
  else if (sample_point & (error_cnt1 == 3'd7))
2019 28 mohor
    rx_err_cnt_blocked <=#Tp 1'b1;
2020
end
2021
 
2022
 
2023
 
2024
always @ (posedge clk or posedge rst)
2025
begin
2026
  if (rst)
2027
    node_error_passive <= 1'b0;
2028 126 mohor
//  else if ((rx_err_cnt < 128) & (tx_err_cnt < 9'd128) & error_frame_ended)
2029
  else if ((rx_err_cnt < 128) & (tx_err_cnt < 9'd128))
2030 28 mohor
    node_error_passive <=#Tp 1'b0;
2031 107 mohor
  else if (((rx_err_cnt >= 128) | (tx_err_cnt >= 9'd128)) & (error_frame_ended | go_error_frame | (~reset_mode) & reset_mode_q) & (~node_bus_off))
2032 28 mohor
    node_error_passive <=#Tp 1'b1;
2033
end
2034
 
2035
 
2036 36 mohor
assign node_error_active = ~(node_error_passive | node_bus_off);
2037
 
2038
 
2039 28 mohor
always @ (posedge clk or posedge rst)
2040
begin
2041
  if (rst)
2042
    node_bus_off <= 1'b0;
2043 107 mohor
  else if ((rx_err_cnt == 9'h0) & (tx_err_cnt == 9'd0) & (~reset_mode) | (we_tx_err_cnt & (data_in < 8'd255)))
2044 28 mohor
    node_bus_off <=#Tp 1'b0;
2045 107 mohor
  else if ((tx_err_cnt >= 9'd256) | (we_tx_err_cnt & (data_in == 8'd255)))
2046 28 mohor
    node_bus_off <=#Tp 1'b1;
2047
end
2048
 
2049
 
2050 35 mohor
 
2051 28 mohor
always @ (posedge clk or posedge rst)
2052
begin
2053
  if (rst)
2054 107 mohor
    bus_free_cnt <= 4'h0;
2055 35 mohor
  else if (reset_mode)
2056 107 mohor
    bus_free_cnt <=#Tp 4'h0;
2057 30 mohor
  else if (sample_point)
2058
    begin
2059 107 mohor
      if (sampled_bit & bus_free_cnt_en & (bus_free_cnt < 4'd10))
2060 35 mohor
        bus_free_cnt <=#Tp bus_free_cnt + 1'b1;
2061 30 mohor
      else
2062 107 mohor
        bus_free_cnt <=#Tp 4'h0;
2063 30 mohor
    end
2064 28 mohor
end
2065
 
2066
 
2067 35 mohor
always @ (posedge clk or posedge rst)
2068
begin
2069
  if (rst)
2070
    bus_free_cnt_en <= 1'b0;
2071
  else if ((~reset_mode) & reset_mode_q | node_bus_off_q & (~reset_mode))
2072
    bus_free_cnt_en <=#Tp 1'b1;
2073 121 mohor
  else if (sample_point & sampled_bit & (bus_free_cnt==4'd10) & (~node_bus_off))
2074 35 mohor
    bus_free_cnt_en <=#Tp 1'b0;
2075
end
2076 28 mohor
 
2077
 
2078 35 mohor
always @ (posedge clk or posedge rst)
2079
begin
2080
  if (rst)
2081
    bus_free <= 1'b0;
2082 107 mohor
  else if (sample_point & sampled_bit & (bus_free_cnt==4'd10))
2083 35 mohor
    bus_free <=#Tp 1'b1;
2084
  else
2085
    bus_free <=#Tp 1'b0;
2086
end
2087
 
2088
 
2089
always @ (posedge clk or posedge rst)
2090
begin
2091
  if (rst)
2092
    waiting_for_bus_free <= 1'b1;
2093
  else if (bus_free & (~node_bus_off))
2094
    waiting_for_bus_free <=#Tp 1'b0;
2095
  else if ((~reset_mode) & reset_mode_q | node_bus_off_q & (~reset_mode))
2096
    waiting_for_bus_free <=#Tp 1'b1;
2097
end
2098
 
2099
 
2100 28 mohor
assign tx_oen = node_bus_off;
2101
 
2102 35 mohor
assign set_reset_mode = node_bus_off & (~node_bus_off_q);
2103
assign error_status = (~reset_mode) & extended_mode? ((rx_err_cnt >= error_warning_limit) | (tx_err_cnt >= error_warning_limit))    :
2104 107 mohor
                                                     ((rx_err_cnt >= 9'd96) | (tx_err_cnt >= 9'd96))                                      ;
2105 28 mohor
 
2106 35 mohor
assign transmit_status = transmitting                 | (extended_mode & waiting_for_bus_free);
2107
assign receive_status  = (~rx_idle) & (~transmitting) | (extended_mode & waiting_for_bus_free);
2108
 
2109 39 mohor
 
2110
/* Error code capture register */
2111
always @ (posedge clk or posedge rst)
2112
begin
2113
  if (rst)
2114
    error_capture_code <= 8'h0;
2115
  else if (read_error_code_capture_reg)
2116
    error_capture_code <=#Tp 8'h0;
2117
  else if (set_bus_error_irq)
2118
    error_capture_code <=#Tp {error_capture_code_type[7:6], error_capture_code_direction, error_capture_code_segment[4:0]};
2119
end
2120
 
2121
 
2122
 
2123 107 mohor
assign error_capture_code_segment[0] = rx_idle | rx_ide | (rx_id2 & (bit_cnt<6'd13)) | rx_r1 | rx_r0 | rx_dlc | rx_ack | rx_ack_lim | error_frame & node_error_active;
2124 39 mohor
assign error_capture_code_segment[1] = rx_idle | rx_id1 | rx_id2 | rx_dlc | rx_data | rx_ack_lim | rx_eof | rx_inter | error_frame & node_error_passive;
2125 107 mohor
assign error_capture_code_segment[2] = (rx_id1 & (bit_cnt>6'd7)) | rx_rtr1 | rx_ide | rx_id2 | rx_rtr2 | rx_r1 | error_frame & node_error_passive | overload_frame;
2126
assign error_capture_code_segment[3] = (rx_id2 & (bit_cnt>6'd4)) | rx_rtr2 | rx_r1 | rx_r0 | rx_dlc | rx_data | rx_crc | rx_crc_lim | rx_ack | rx_ack_lim | rx_eof | overload_frame;
2127 39 mohor
assign error_capture_code_segment[4] = rx_crc_lim | rx_ack | rx_ack_lim | rx_eof | rx_inter | error_frame | overload_frame;
2128
assign error_capture_code_direction  = ~transmitting;
2129
 
2130
 
2131
always @ (bit_err or form_err or stuff_err)
2132
begin
2133
  if (bit_err)
2134 107 mohor
    error_capture_code_type[7:6] = 2'b00;
2135 39 mohor
  else if (form_err)
2136 107 mohor
    error_capture_code_type[7:6] = 2'b01;
2137 39 mohor
  else if (stuff_err)
2138 107 mohor
    error_capture_code_type[7:6] = 2'b10;
2139 39 mohor
  else
2140 107 mohor
    error_capture_code_type[7:6] = 2'b11;
2141 39 mohor
end
2142
 
2143
 
2144
assign set_bus_error_irq = go_error_frame & (~error_capture_code_blocked);
2145
 
2146
 
2147
always @ (posedge clk or posedge rst)
2148
begin
2149
  if (rst)
2150
    error_capture_code_blocked <= 1'b0;
2151
  else if (read_error_code_capture_reg)
2152
    error_capture_code_blocked <=#Tp 1'b0;
2153
  else if (set_bus_error_irq)
2154
    error_capture_code_blocked <=#Tp 1'b1;
2155
end
2156
 
2157
 
2158 2 mohor
endmodule

powered by: WebSVN 2.1.0

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