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

Subversion Repositories can

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

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

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

powered by: WebSVN 2.1.0

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