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

Subversion Repositories can

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

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

powered by: WebSVN 2.1.0

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