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

Subversion Repositories can

[/] [can/] [tags/] [rel_22/] [rtl/] [verilog/] [can_bsp.v] - Blame information for rev 146

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

powered by: WebSVN 2.1.0

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