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 136

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

powered by: WebSVN 2.1.0

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