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 130

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

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

powered by: WebSVN 2.1.0

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