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

Subversion Repositories can

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

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

powered by: WebSVN 2.1.0

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