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

Subversion Repositories can

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

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

powered by: WebSVN 2.1.0

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