1 |
66 |
mohor |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// can_registers.v ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// This file is part of the CAN Protocol Controller ////
|
7 |
|
|
//// http://www.opencores.org/projects/can/ ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// Author(s): ////
|
11 |
|
|
//// Igor Mohor ////
|
12 |
|
|
//// igorm@opencores.org ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// All additional information is available in the README.txt ////
|
16 |
|
|
//// file. ////
|
17 |
|
|
//// ////
|
18 |
|
|
//////////////////////////////////////////////////////////////////////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Copyright (C) 2002, 2003 Authors ////
|
21 |
|
|
//// ////
|
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 |
|
|
//// 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 |
|
|
//////////////////////////////////////////////////////////////////////
|
49 |
|
|
//
|
50 |
|
|
// CVS Revision History
|
51 |
|
|
//
|
52 |
|
|
// $Log: not supported by cvs2svn $
|
53 |
156 |
igorm |
// Revision 1.35 2004/11/30 15:08:26 igorm
|
54 |
|
|
// irq is cleared after the release_buffer command. This bug was entered with
|
55 |
|
|
// changes for the edge triggered interrupts.
|
56 |
|
|
//
|
57 |
154 |
igorm |
// Revision 1.34 2004/11/18 12:39:43 igorm
|
58 |
|
|
// Fixes for compatibility after the SW reset.
|
59 |
|
|
//
|
60 |
152 |
igorm |
// Revision 1.33 2004/10/25 11:44:38 igorm
|
61 |
|
|
// Interrupt is always cleared for one clock after the irq register is read.
|
62 |
|
|
// This fixes problems when CPU is using IRQs that are edge triggered.
|
63 |
|
|
//
|
64 |
147 |
igorm |
// Revision 1.32 2004/05/12 15:58:41 igorm
|
65 |
|
|
// Core improved to pass all tests with the Bosch VHDL Reference system.
|
66 |
|
|
//
|
67 |
141 |
igorm |
// Revision 1.31 2003/09/25 18:55:49 mohor
|
68 |
|
|
// Synchronization changed, error counters fixed.
|
69 |
|
|
//
|
70 |
125 |
mohor |
// Revision 1.30 2003/07/16 15:19:34 mohor
|
71 |
|
|
// Fixed according to the linter.
|
72 |
|
|
// Case statement for data_out joined.
|
73 |
|
|
//
|
74 |
111 |
mohor |
// Revision 1.29 2003/07/10 01:59:04 tadejm
|
75 |
|
|
// Synchronization fixed. In some strange cases it didn't work according to
|
76 |
|
|
// the VHDL reference model.
|
77 |
|
|
//
|
78 |
104 |
tadejm |
// Revision 1.28 2003/07/07 11:21:37 mohor
|
79 |
|
|
// Little fixes (to fix warnings).
|
80 |
|
|
//
|
81 |
102 |
mohor |
// Revision 1.27 2003/06/22 09:43:03 mohor
|
82 |
|
|
// synthesi full_case parallel_case fixed.
|
83 |
|
|
//
|
84 |
93 |
mohor |
// Revision 1.26 2003/06/22 01:33:14 mohor
|
85 |
|
|
// clkout is clk/2 after the reset.
|
86 |
|
|
//
|
87 |
92 |
mohor |
// Revision 1.25 2003/06/21 12:16:30 mohor
|
88 |
|
|
// paralel_case and full_case compiler directives added to case statements.
|
89 |
|
|
//
|
90 |
90 |
mohor |
// Revision 1.24 2003/06/09 11:22:54 mohor
|
91 |
|
|
// data_out is already registered in the can_top.v file.
|
92 |
|
|
//
|
93 |
70 |
mohor |
// Revision 1.23 2003/04/15 15:31:24 mohor
|
94 |
|
|
// Some features are supported in extended mode only (listen_only_mode...).
|
95 |
|
|
//
|
96 |
69 |
mohor |
// Revision 1.22 2003/03/20 16:58:50 mohor
|
97 |
|
|
// unix.
|
98 |
|
|
//
|
99 |
66 |
mohor |
// Revision 1.20 2003/03/11 16:31:05 mohor
|
100 |
|
|
// Mux used for clkout to avoid "gated clocks warning".
|
101 |
|
|
//
|
102 |
|
|
// Revision 1.19 2003/03/10 17:34:25 mohor
|
103 |
|
|
// Doubled declarations removed.
|
104 |
|
|
//
|
105 |
|
|
// Revision 1.18 2003/03/01 22:52:11 mohor
|
106 |
|
|
// Data is latched on read.
|
107 |
|
|
//
|
108 |
|
|
// Revision 1.17 2003/02/19 15:09:02 mohor
|
109 |
|
|
// Incomplete sensitivity list fixed.
|
110 |
|
|
//
|
111 |
|
|
// Revision 1.16 2003/02/19 14:44:03 mohor
|
112 |
|
|
// CAN core finished. Host interface added. Registers finished.
|
113 |
|
|
// Synchronization to the wishbone finished.
|
114 |
|
|
//
|
115 |
|
|
// Revision 1.15 2003/02/18 00:10:15 mohor
|
116 |
|
|
// Most of the registers added. Registers "arbitration lost capture", "error code
|
117 |
|
|
// capture" + few more still need to be added.
|
118 |
|
|
//
|
119 |
|
|
// Revision 1.14 2003/02/14 20:17:01 mohor
|
120 |
|
|
// Several registers added. Not finished, yet.
|
121 |
|
|
//
|
122 |
|
|
// Revision 1.13 2003/02/12 14:25:30 mohor
|
123 |
|
|
// abort_tx added.
|
124 |
|
|
//
|
125 |
|
|
// Revision 1.12 2003/02/11 00:56:06 mohor
|
126 |
|
|
// Wishbone interface added.
|
127 |
|
|
//
|
128 |
|
|
// Revision 1.11 2003/02/09 02:24:33 mohor
|
129 |
|
|
// Bosch license warning added. Error counters finished. Overload frames
|
130 |
|
|
// still need to be fixed.
|
131 |
|
|
//
|
132 |
|
|
// Revision 1.10 2003/01/31 01:13:38 mohor
|
133 |
|
|
// backup.
|
134 |
|
|
//
|
135 |
|
|
// Revision 1.9 2003/01/15 13:16:48 mohor
|
136 |
|
|
// When a frame with "remote request" is received, no data is stored
|
137 |
|
|
// to fifo, just the frame information (identifier, ...). Data length
|
138 |
|
|
// that is stored is the received data length and not the actual data
|
139 |
|
|
// length that is stored to fifo.
|
140 |
|
|
//
|
141 |
|
|
// Revision 1.8 2003/01/14 17:25:09 mohor
|
142 |
|
|
// Addresses corrected to decimal values (previously hex).
|
143 |
|
|
//
|
144 |
|
|
// Revision 1.7 2003/01/14 12:19:35 mohor
|
145 |
|
|
// rx_fifo is now working.
|
146 |
|
|
//
|
147 |
|
|
// Revision 1.6 2003/01/10 17:51:34 mohor
|
148 |
|
|
// Temporary version (backup).
|
149 |
|
|
//
|
150 |
|
|
// Revision 1.5 2003/01/09 14:46:58 mohor
|
151 |
|
|
// Temporary files (backup).
|
152 |
|
|
//
|
153 |
|
|
// Revision 1.4 2003/01/08 02:10:55 mohor
|
154 |
|
|
// Acceptance filter added.
|
155 |
|
|
//
|
156 |
|
|
// Revision 1.3 2002/12/27 00:12:52 mohor
|
157 |
|
|
// Header changed, testbench improved to send a frame (crc still missing).
|
158 |
|
|
//
|
159 |
|
|
// Revision 1.2 2002/12/26 16:00:34 mohor
|
160 |
|
|
// Testbench define file added. Clock divider register added.
|
161 |
|
|
//
|
162 |
|
|
// Revision 1.1.1.1 2002/12/20 16:39:21 mohor
|
163 |
|
|
// Initial
|
164 |
|
|
//
|
165 |
|
|
//
|
166 |
|
|
//
|
167 |
|
|
|
168 |
|
|
// synopsys translate_off
|
169 |
|
|
`include "timescale.v"
|
170 |
|
|
// synopsys translate_on
|
171 |
|
|
`include "can_defines.v"
|
172 |
|
|
|
173 |
|
|
module can_registers
|
174 |
|
|
(
|
175 |
|
|
clk,
|
176 |
|
|
rst,
|
177 |
|
|
cs,
|
178 |
|
|
we,
|
179 |
|
|
addr,
|
180 |
|
|
data_in,
|
181 |
|
|
data_out,
|
182 |
147 |
igorm |
irq_n,
|
183 |
66 |
mohor |
|
184 |
|
|
sample_point,
|
185 |
|
|
transmitting,
|
186 |
|
|
set_reset_mode,
|
187 |
|
|
node_bus_off,
|
188 |
|
|
error_status,
|
189 |
|
|
rx_err_cnt,
|
190 |
|
|
tx_err_cnt,
|
191 |
|
|
transmit_status,
|
192 |
|
|
receive_status,
|
193 |
|
|
tx_successful,
|
194 |
|
|
need_to_tx,
|
195 |
|
|
overrun,
|
196 |
|
|
info_empty,
|
197 |
|
|
set_bus_error_irq,
|
198 |
|
|
set_arbitration_lost_irq,
|
199 |
|
|
arbitration_lost_capture,
|
200 |
|
|
node_error_passive,
|
201 |
|
|
node_error_active,
|
202 |
|
|
rx_message_counter,
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
/* Mode register */
|
206 |
|
|
reset_mode,
|
207 |
|
|
listen_only_mode,
|
208 |
|
|
acceptance_filter_mode,
|
209 |
|
|
self_test_mode,
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
/* Command register */
|
213 |
|
|
clear_data_overrun,
|
214 |
|
|
release_buffer,
|
215 |
|
|
abort_tx,
|
216 |
|
|
tx_request,
|
217 |
|
|
self_rx_request,
|
218 |
|
|
single_shot_transmission,
|
219 |
104 |
tadejm |
tx_state,
|
220 |
|
|
tx_state_q,
|
221 |
125 |
mohor |
overload_request,
|
222 |
|
|
overload_frame,
|
223 |
66 |
mohor |
|
224 |
|
|
/* Arbitration Lost Capture Register */
|
225 |
|
|
read_arbitration_lost_capture_reg,
|
226 |
|
|
|
227 |
|
|
/* Error Code Capture Register */
|
228 |
|
|
read_error_code_capture_reg,
|
229 |
|
|
error_capture_code,
|
230 |
|
|
|
231 |
|
|
/* Bus Timing 0 register */
|
232 |
|
|
baud_r_presc,
|
233 |
|
|
sync_jump_width,
|
234 |
|
|
|
235 |
|
|
/* Bus Timing 1 register */
|
236 |
|
|
time_segment1,
|
237 |
|
|
time_segment2,
|
238 |
|
|
triple_sampling,
|
239 |
|
|
|
240 |
|
|
/* Error Warning Limit register */
|
241 |
|
|
error_warning_limit,
|
242 |
|
|
|
243 |
|
|
/* Rx Error Counter register */
|
244 |
|
|
we_rx_err_cnt,
|
245 |
|
|
|
246 |
|
|
/* Tx Error Counter register */
|
247 |
|
|
we_tx_err_cnt,
|
248 |
|
|
|
249 |
|
|
/* Clock Divider register */
|
250 |
|
|
extended_mode,
|
251 |
|
|
clkout,
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
/* This section is for BASIC and EXTENDED mode */
|
255 |
|
|
/* Acceptance code register */
|
256 |
|
|
acceptance_code_0,
|
257 |
|
|
|
258 |
|
|
/* Acceptance mask register */
|
259 |
|
|
acceptance_mask_0,
|
260 |
|
|
/* End: This section is for BASIC and EXTENDED mode */
|
261 |
|
|
|
262 |
|
|
/* This section is for EXTENDED mode */
|
263 |
|
|
/* Acceptance code register */
|
264 |
|
|
acceptance_code_1,
|
265 |
|
|
acceptance_code_2,
|
266 |
|
|
acceptance_code_3,
|
267 |
|
|
|
268 |
|
|
/* Acceptance mask register */
|
269 |
|
|
acceptance_mask_1,
|
270 |
|
|
acceptance_mask_2,
|
271 |
|
|
acceptance_mask_3,
|
272 |
|
|
/* End: This section is for EXTENDED mode */
|
273 |
|
|
|
274 |
|
|
/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
|
275 |
|
|
tx_data_0,
|
276 |
|
|
tx_data_1,
|
277 |
|
|
tx_data_2,
|
278 |
|
|
tx_data_3,
|
279 |
|
|
tx_data_4,
|
280 |
|
|
tx_data_5,
|
281 |
|
|
tx_data_6,
|
282 |
|
|
tx_data_7,
|
283 |
|
|
tx_data_8,
|
284 |
|
|
tx_data_9,
|
285 |
|
|
tx_data_10,
|
286 |
|
|
tx_data_11,
|
287 |
|
|
tx_data_12
|
288 |
|
|
/* End: Tx data registers */
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
);
|
294 |
|
|
|
295 |
|
|
parameter Tp = 1;
|
296 |
|
|
|
297 |
|
|
input clk;
|
298 |
|
|
input rst;
|
299 |
|
|
input cs;
|
300 |
|
|
input we;
|
301 |
|
|
input [7:0] addr;
|
302 |
|
|
input [7:0] data_in;
|
303 |
|
|
|
304 |
|
|
output [7:0] data_out;
|
305 |
|
|
reg [7:0] data_out;
|
306 |
|
|
|
307 |
147 |
igorm |
output irq_n;
|
308 |
66 |
mohor |
|
309 |
|
|
input sample_point;
|
310 |
|
|
input transmitting;
|
311 |
|
|
input set_reset_mode;
|
312 |
|
|
input node_bus_off;
|
313 |
|
|
input error_status;
|
314 |
|
|
input [7:0] rx_err_cnt;
|
315 |
|
|
input [7:0] tx_err_cnt;
|
316 |
|
|
input transmit_status;
|
317 |
|
|
input receive_status;
|
318 |
|
|
input tx_successful;
|
319 |
|
|
input need_to_tx;
|
320 |
|
|
input overrun;
|
321 |
|
|
input info_empty;
|
322 |
|
|
input set_bus_error_irq;
|
323 |
|
|
input set_arbitration_lost_irq;
|
324 |
|
|
input [4:0] arbitration_lost_capture;
|
325 |
|
|
input node_error_passive;
|
326 |
|
|
input node_error_active;
|
327 |
|
|
input [6:0] rx_message_counter;
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
/* Mode register */
|
332 |
|
|
output reset_mode;
|
333 |
|
|
output listen_only_mode;
|
334 |
|
|
output acceptance_filter_mode;
|
335 |
|
|
output self_test_mode;
|
336 |
|
|
|
337 |
|
|
/* Command register */
|
338 |
|
|
output clear_data_overrun;
|
339 |
|
|
output release_buffer;
|
340 |
|
|
output abort_tx;
|
341 |
|
|
output tx_request;
|
342 |
|
|
output self_rx_request;
|
343 |
|
|
output single_shot_transmission;
|
344 |
104 |
tadejm |
input tx_state;
|
345 |
|
|
input tx_state_q;
|
346 |
125 |
mohor |
output overload_request;
|
347 |
|
|
input overload_frame;
|
348 |
66 |
mohor |
|
349 |
125 |
mohor |
|
350 |
66 |
mohor |
/* Arbitration Lost Capture Register */
|
351 |
|
|
output read_arbitration_lost_capture_reg;
|
352 |
|
|
|
353 |
|
|
/* Error Code Capture Register */
|
354 |
|
|
output read_error_code_capture_reg;
|
355 |
|
|
input [7:0] error_capture_code;
|
356 |
|
|
|
357 |
|
|
/* Bus Timing 0 register */
|
358 |
|
|
output [5:0] baud_r_presc;
|
359 |
|
|
output [1:0] sync_jump_width;
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
/* Bus Timing 1 register */
|
363 |
|
|
output [3:0] time_segment1;
|
364 |
|
|
output [2:0] time_segment2;
|
365 |
|
|
output triple_sampling;
|
366 |
|
|
|
367 |
|
|
/* Error Warning Limit register */
|
368 |
|
|
output [7:0] error_warning_limit;
|
369 |
|
|
|
370 |
|
|
/* Rx Error Counter register */
|
371 |
|
|
output we_rx_err_cnt;
|
372 |
|
|
|
373 |
|
|
/* Tx Error Counter register */
|
374 |
|
|
output we_tx_err_cnt;
|
375 |
|
|
|
376 |
|
|
/* Clock Divider register */
|
377 |
|
|
output extended_mode;
|
378 |
|
|
output clkout;
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
/* This section is for BASIC and EXTENDED mode */
|
382 |
|
|
/* Acceptance code register */
|
383 |
|
|
output [7:0] acceptance_code_0;
|
384 |
|
|
|
385 |
|
|
/* Acceptance mask register */
|
386 |
|
|
output [7:0] acceptance_mask_0;
|
387 |
|
|
|
388 |
|
|
/* End: This section is for BASIC and EXTENDED mode */
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
/* This section is for EXTENDED mode */
|
392 |
|
|
/* Acceptance code register */
|
393 |
|
|
output [7:0] acceptance_code_1;
|
394 |
|
|
output [7:0] acceptance_code_2;
|
395 |
|
|
output [7:0] acceptance_code_3;
|
396 |
|
|
|
397 |
|
|
/* Acceptance mask register */
|
398 |
|
|
output [7:0] acceptance_mask_1;
|
399 |
|
|
output [7:0] acceptance_mask_2;
|
400 |
|
|
output [7:0] acceptance_mask_3;
|
401 |
|
|
|
402 |
|
|
/* End: This section is for EXTENDED mode */
|
403 |
|
|
|
404 |
|
|
/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
|
405 |
|
|
output [7:0] tx_data_0;
|
406 |
|
|
output [7:0] tx_data_1;
|
407 |
|
|
output [7:0] tx_data_2;
|
408 |
|
|
output [7:0] tx_data_3;
|
409 |
|
|
output [7:0] tx_data_4;
|
410 |
|
|
output [7:0] tx_data_5;
|
411 |
|
|
output [7:0] tx_data_6;
|
412 |
|
|
output [7:0] tx_data_7;
|
413 |
|
|
output [7:0] tx_data_8;
|
414 |
|
|
output [7:0] tx_data_9;
|
415 |
|
|
output [7:0] tx_data_10;
|
416 |
|
|
output [7:0] tx_data_11;
|
417 |
|
|
output [7:0] tx_data_12;
|
418 |
|
|
/* End: Tx data registers */
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
reg tx_successful_q;
|
422 |
|
|
reg overrun_q;
|
423 |
|
|
reg overrun_status;
|
424 |
|
|
reg transmission_complete;
|
425 |
|
|
reg transmit_buffer_status_q;
|
426 |
|
|
reg receive_buffer_status;
|
427 |
|
|
reg error_status_q;
|
428 |
|
|
reg node_bus_off_q;
|
429 |
|
|
reg node_error_passive_q;
|
430 |
|
|
reg transmit_buffer_status;
|
431 |
|
|
reg single_shot_transmission;
|
432 |
104 |
tadejm |
reg self_rx_request;
|
433 |
147 |
igorm |
reg irq_n;
|
434 |
66 |
mohor |
|
435 |
|
|
// Some interrupts exist in basic mode and in extended mode. Since they are in different registers they need to be multiplexed.
|
436 |
|
|
wire data_overrun_irq_en;
|
437 |
|
|
wire error_warning_irq_en;
|
438 |
|
|
wire transmit_irq_en;
|
439 |
|
|
wire receive_irq_en;
|
440 |
|
|
|
441 |
|
|
wire [7:0] irq_reg;
|
442 |
147 |
igorm |
wire irq;
|
443 |
66 |
mohor |
|
444 |
|
|
wire we_mode = cs & we & (addr == 8'd0);
|
445 |
|
|
wire we_command = cs & we & (addr == 8'd1);
|
446 |
|
|
wire we_bus_timing_0 = cs & we & (addr == 8'd6) & reset_mode;
|
447 |
|
|
wire we_bus_timing_1 = cs & we & (addr == 8'd7) & reset_mode;
|
448 |
|
|
wire we_clock_divider_low = cs & we & (addr == 8'd31);
|
449 |
|
|
wire we_clock_divider_hi = we_clock_divider_low & reset_mode;
|
450 |
|
|
|
451 |
|
|
wire read = cs & (~we);
|
452 |
|
|
wire read_irq_reg = read & (addr == 8'd3);
|
453 |
|
|
assign read_arbitration_lost_capture_reg = read & extended_mode & (addr == 8'd11);
|
454 |
|
|
assign read_error_code_capture_reg = read & extended_mode & (addr == 8'd12);
|
455 |
|
|
|
456 |
|
|
/* This section is for BASIC and EXTENDED mode */
|
457 |
|
|
wire we_acceptance_code_0 = cs & we & reset_mode & ((~extended_mode) & (addr == 8'd4) | extended_mode & (addr == 8'd16));
|
458 |
|
|
wire we_acceptance_mask_0 = cs & we & reset_mode & ((~extended_mode) & (addr == 8'd5) | extended_mode & (addr == 8'd20));
|
459 |
|
|
wire we_tx_data_0 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd10) | extended_mode & (addr == 8'd16)) & transmit_buffer_status;
|
460 |
|
|
wire we_tx_data_1 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd11) | extended_mode & (addr == 8'd17)) & transmit_buffer_status;
|
461 |
|
|
wire we_tx_data_2 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd12) | extended_mode & (addr == 8'd18)) & transmit_buffer_status;
|
462 |
|
|
wire we_tx_data_3 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd13) | extended_mode & (addr == 8'd19)) & transmit_buffer_status;
|
463 |
|
|
wire we_tx_data_4 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd14) | extended_mode & (addr == 8'd20)) & transmit_buffer_status;
|
464 |
|
|
wire we_tx_data_5 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd15) | extended_mode & (addr == 8'd21)) & transmit_buffer_status;
|
465 |
|
|
wire we_tx_data_6 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd16) | extended_mode & (addr == 8'd22)) & transmit_buffer_status;
|
466 |
|
|
wire we_tx_data_7 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd17) | extended_mode & (addr == 8'd23)) & transmit_buffer_status;
|
467 |
|
|
wire we_tx_data_8 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd18) | extended_mode & (addr == 8'd24)) & transmit_buffer_status;
|
468 |
|
|
wire we_tx_data_9 = cs & we & (~reset_mode) & ((~extended_mode) & (addr == 8'd19) | extended_mode & (addr == 8'd25)) & transmit_buffer_status;
|
469 |
|
|
wire we_tx_data_10 = cs & we & (~reset_mode) & ( extended_mode & (addr == 8'd26)) & transmit_buffer_status;
|
470 |
|
|
wire we_tx_data_11 = cs & we & (~reset_mode) & ( extended_mode & (addr == 8'd27)) & transmit_buffer_status;
|
471 |
|
|
wire we_tx_data_12 = cs & we & (~reset_mode) & ( extended_mode & (addr == 8'd28)) & transmit_buffer_status;
|
472 |
|
|
/* End: This section is for BASIC and EXTENDED mode */
|
473 |
|
|
|
474 |
|
|
|
475 |
|
|
/* This section is for EXTENDED mode */
|
476 |
|
|
wire we_interrupt_enable = cs & we & (addr == 8'd4) & extended_mode;
|
477 |
|
|
wire we_error_warning_limit = cs & we & (addr == 8'd13) & reset_mode & extended_mode;
|
478 |
|
|
assign we_rx_err_cnt = cs & we & (addr == 8'd14) & reset_mode & extended_mode;
|
479 |
|
|
assign we_tx_err_cnt = cs & we & (addr == 8'd15) & reset_mode & extended_mode;
|
480 |
|
|
wire we_acceptance_code_1 = cs & we & (addr == 8'd17) & reset_mode & extended_mode;
|
481 |
|
|
wire we_acceptance_code_2 = cs & we & (addr == 8'd18) & reset_mode & extended_mode;
|
482 |
|
|
wire we_acceptance_code_3 = cs & we & (addr == 8'd19) & reset_mode & extended_mode;
|
483 |
|
|
wire we_acceptance_mask_1 = cs & we & (addr == 8'd21) & reset_mode & extended_mode;
|
484 |
|
|
wire we_acceptance_mask_2 = cs & we & (addr == 8'd22) & reset_mode & extended_mode;
|
485 |
|
|
wire we_acceptance_mask_3 = cs & we & (addr == 8'd23) & reset_mode & extended_mode;
|
486 |
|
|
/* End: This section is for EXTENDED mode */
|
487 |
|
|
|
488 |
|
|
|
489 |
|
|
|
490 |
|
|
always @ (posedge clk)
|
491 |
|
|
begin
|
492 |
|
|
tx_successful_q <=#Tp tx_successful;
|
493 |
|
|
overrun_q <=#Tp overrun;
|
494 |
|
|
transmit_buffer_status_q <=#Tp transmit_buffer_status;
|
495 |
|
|
error_status_q <=#Tp error_status;
|
496 |
|
|
node_bus_off_q <=#Tp node_bus_off;
|
497 |
|
|
node_error_passive_q <=#Tp node_error_passive;
|
498 |
|
|
end
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
/* Mode register */
|
503 |
|
|
wire [0:0] mode;
|
504 |
|
|
wire [4:1] mode_basic;
|
505 |
|
|
wire [3:1] mode_ext;
|
506 |
|
|
wire receive_irq_en_basic;
|
507 |
|
|
wire transmit_irq_en_basic;
|
508 |
|
|
wire error_irq_en_basic;
|
509 |
|
|
wire overrun_irq_en_basic;
|
510 |
|
|
|
511 |
|
|
can_register_asyn_syn #(1, 1'h1) MODE_REG0
|
512 |
|
|
( .data_in(data_in[0]),
|
513 |
|
|
.data_out(mode[0]),
|
514 |
|
|
.we(we_mode),
|
515 |
|
|
.clk(clk),
|
516 |
|
|
.rst(rst),
|
517 |
|
|
.rst_sync(set_reset_mode)
|
518 |
|
|
);
|
519 |
|
|
|
520 |
|
|
can_register_asyn #(4, 0) MODE_REG_BASIC
|
521 |
|
|
( .data_in(data_in[4:1]),
|
522 |
|
|
.data_out(mode_basic[4:1]),
|
523 |
|
|
.we(we_mode),
|
524 |
|
|
.clk(clk),
|
525 |
|
|
.rst(rst)
|
526 |
|
|
);
|
527 |
|
|
|
528 |
|
|
can_register_asyn #(3, 0) MODE_REG_EXT
|
529 |
|
|
( .data_in(data_in[3:1]),
|
530 |
|
|
.data_out(mode_ext[3:1]),
|
531 |
|
|
.we(we_mode & reset_mode),
|
532 |
|
|
.clk(clk),
|
533 |
|
|
.rst(rst)
|
534 |
|
|
);
|
535 |
|
|
|
536 |
|
|
assign reset_mode = mode[0];
|
537 |
69 |
mohor |
assign listen_only_mode = extended_mode & mode_ext[1];
|
538 |
|
|
assign self_test_mode = extended_mode & mode_ext[2];
|
539 |
|
|
assign acceptance_filter_mode = extended_mode & mode_ext[3];
|
540 |
66 |
mohor |
|
541 |
|
|
assign receive_irq_en_basic = mode_basic[1];
|
542 |
|
|
assign transmit_irq_en_basic = mode_basic[2];
|
543 |
|
|
assign error_irq_en_basic = mode_basic[3];
|
544 |
|
|
assign overrun_irq_en_basic = mode_basic[4];
|
545 |
|
|
/* End Mode register */
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
/* Command register */
|
549 |
|
|
wire [4:0] command;
|
550 |
|
|
can_register_asyn_syn #(1, 1'h0) COMMAND_REG0
|
551 |
|
|
( .data_in(data_in[0]),
|
552 |
|
|
.data_out(command[0]),
|
553 |
|
|
.we(we_command),
|
554 |
|
|
.clk(clk),
|
555 |
|
|
.rst(rst),
|
556 |
152 |
igorm |
.rst_sync(command[0] & sample_point | reset_mode)
|
557 |
66 |
mohor |
);
|
558 |
|
|
|
559 |
|
|
can_register_asyn_syn #(1, 1'h0) COMMAND_REG1
|
560 |
|
|
( .data_in(data_in[1]),
|
561 |
|
|
.data_out(command[1]),
|
562 |
|
|
.we(we_command),
|
563 |
|
|
.clk(clk),
|
564 |
|
|
.rst(rst),
|
565 |
152 |
igorm |
.rst_sync(sample_point & (tx_request | (abort_tx & ~transmitting)) | reset_mode)
|
566 |
66 |
mohor |
);
|
567 |
|
|
|
568 |
|
|
can_register_asyn_syn #(2, 2'h0) COMMAND_REG
|
569 |
|
|
( .data_in(data_in[3:2]),
|
570 |
|
|
.data_out(command[3:2]),
|
571 |
|
|
.we(we_command),
|
572 |
|
|
.clk(clk),
|
573 |
|
|
.rst(rst),
|
574 |
152 |
igorm |
.rst_sync(|command[3:2] | reset_mode)
|
575 |
66 |
mohor |
);
|
576 |
|
|
|
577 |
|
|
can_register_asyn_syn #(1, 1'h0) COMMAND_REG4
|
578 |
|
|
( .data_in(data_in[4]),
|
579 |
|
|
.data_out(command[4]),
|
580 |
|
|
.we(we_command),
|
581 |
|
|
.clk(clk),
|
582 |
|
|
.rst(rst),
|
583 |
152 |
igorm |
.rst_sync(command[4] & sample_point | reset_mode)
|
584 |
66 |
mohor |
);
|
585 |
|
|
|
586 |
104 |
tadejm |
|
587 |
|
|
always @ (posedge clk or posedge rst)
|
588 |
|
|
begin
|
589 |
|
|
if (rst)
|
590 |
|
|
self_rx_request <= 1'b0;
|
591 |
|
|
else if (command[4] & (~command[0]))
|
592 |
|
|
self_rx_request <=#Tp 1'b1;
|
593 |
|
|
else if ((~tx_state) & tx_state_q)
|
594 |
|
|
self_rx_request <=#Tp 1'b0;
|
595 |
|
|
end
|
596 |
|
|
|
597 |
|
|
|
598 |
66 |
mohor |
assign clear_data_overrun = command[3];
|
599 |
|
|
assign release_buffer = command[2];
|
600 |
|
|
assign tx_request = command[0] | command[4];
|
601 |
104 |
tadejm |
assign abort_tx = command[1] & (~tx_request);
|
602 |
66 |
mohor |
|
603 |
|
|
|
604 |
|
|
always @ (posedge clk or posedge rst)
|
605 |
|
|
begin
|
606 |
|
|
if (rst)
|
607 |
|
|
single_shot_transmission <= 1'b0;
|
608 |
104 |
tadejm |
else if (tx_request & command[1] & sample_point)
|
609 |
66 |
mohor |
single_shot_transmission <=#Tp 1'b1;
|
610 |
104 |
tadejm |
else if ((~tx_state) & tx_state_q)
|
611 |
66 |
mohor |
single_shot_transmission <=#Tp 1'b0;
|
612 |
|
|
end
|
613 |
|
|
|
614 |
|
|
|
615 |
125 |
mohor |
/*
|
616 |
|
|
can_register_asyn_syn #(1, 1'h0) COMMAND_REG_OVERLOAD // Uncomment this to enable overload requests !!!
|
617 |
|
|
( .data_in(data_in[5]),
|
618 |
|
|
.data_out(overload_request),
|
619 |
|
|
.we(we_command),
|
620 |
|
|
.clk(clk),
|
621 |
|
|
.rst(rst),
|
622 |
|
|
.rst_sync(overload_frame & ~overload_frame_q)
|
623 |
|
|
);
|
624 |
66 |
mohor |
|
625 |
125 |
mohor |
reg overload_frame_q;
|
626 |
|
|
|
627 |
|
|
always @ (posedge clk or posedge rst)
|
628 |
|
|
begin
|
629 |
|
|
if (rst)
|
630 |
|
|
overload_frame_q <= 1'b0;
|
631 |
|
|
else
|
632 |
|
|
overload_frame_q <=#Tp overload_frame;
|
633 |
|
|
end
|
634 |
|
|
*/
|
635 |
|
|
assign overload_request = 0; // Overload requests are not supported, yet !!!
|
636 |
|
|
|
637 |
|
|
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
|
641 |
66 |
mohor |
/* End Command register */
|
642 |
|
|
|
643 |
|
|
|
644 |
|
|
/* Status register */
|
645 |
|
|
|
646 |
|
|
wire [7:0] status;
|
647 |
|
|
|
648 |
|
|
assign status[7] = node_bus_off;
|
649 |
|
|
assign status[6] = error_status;
|
650 |
|
|
assign status[5] = transmit_status;
|
651 |
|
|
assign status[4] = receive_status;
|
652 |
|
|
assign status[3] = transmission_complete;
|
653 |
|
|
assign status[2] = transmit_buffer_status;
|
654 |
|
|
assign status[1] = overrun_status;
|
655 |
|
|
assign status[0] = receive_buffer_status;
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
|
|
always @ (posedge clk or posedge rst)
|
660 |
|
|
begin
|
661 |
|
|
if (rst)
|
662 |
|
|
transmission_complete <= 1'b1;
|
663 |
|
|
else if (tx_successful & (~tx_successful_q) | abort_tx)
|
664 |
|
|
transmission_complete <=#Tp 1'b1;
|
665 |
|
|
else if (tx_request)
|
666 |
|
|
transmission_complete <=#Tp 1'b0;
|
667 |
|
|
end
|
668 |
|
|
|
669 |
|
|
|
670 |
|
|
always @ (posedge clk or posedge rst)
|
671 |
|
|
begin
|
672 |
|
|
if (rst)
|
673 |
|
|
transmit_buffer_status <= 1'b1;
|
674 |
|
|
else if (tx_request)
|
675 |
|
|
transmit_buffer_status <=#Tp 1'b0;
|
676 |
152 |
igorm |
else if (reset_mode || !need_to_tx)
|
677 |
66 |
mohor |
transmit_buffer_status <=#Tp 1'b1;
|
678 |
|
|
end
|
679 |
|
|
|
680 |
|
|
|
681 |
|
|
always @ (posedge clk or posedge rst)
|
682 |
|
|
begin
|
683 |
|
|
if (rst)
|
684 |
|
|
overrun_status <= 1'b0;
|
685 |
|
|
else if (overrun & (~overrun_q))
|
686 |
|
|
overrun_status <=#Tp 1'b1;
|
687 |
152 |
igorm |
else if (reset_mode || clear_data_overrun)
|
688 |
66 |
mohor |
overrun_status <=#Tp 1'b0;
|
689 |
|
|
end
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
always @ (posedge clk or posedge rst)
|
693 |
|
|
begin
|
694 |
|
|
if (rst)
|
695 |
|
|
receive_buffer_status <= 1'b0;
|
696 |
152 |
igorm |
else if (reset_mode || release_buffer)
|
697 |
66 |
mohor |
receive_buffer_status <=#Tp 1'b0;
|
698 |
|
|
else if (~info_empty)
|
699 |
|
|
receive_buffer_status <=#Tp 1'b1;
|
700 |
|
|
end
|
701 |
|
|
|
702 |
|
|
/* End Status register */
|
703 |
|
|
|
704 |
|
|
|
705 |
|
|
/* Interrupt Enable register (extended mode) */
|
706 |
|
|
wire [7:0] irq_en_ext;
|
707 |
|
|
wire bus_error_irq_en;
|
708 |
|
|
wire arbitration_lost_irq_en;
|
709 |
|
|
wire error_passive_irq_en;
|
710 |
|
|
wire data_overrun_irq_en_ext;
|
711 |
|
|
wire error_warning_irq_en_ext;
|
712 |
|
|
wire transmit_irq_en_ext;
|
713 |
|
|
wire receive_irq_en_ext;
|
714 |
|
|
|
715 |
|
|
can_register #(8) IRQ_EN_REG
|
716 |
|
|
( .data_in(data_in),
|
717 |
|
|
.data_out(irq_en_ext),
|
718 |
|
|
.we(we_interrupt_enable),
|
719 |
|
|
.clk(clk)
|
720 |
|
|
);
|
721 |
|
|
|
722 |
|
|
|
723 |
|
|
assign bus_error_irq_en = irq_en_ext[7];
|
724 |
|
|
assign arbitration_lost_irq_en = irq_en_ext[6];
|
725 |
|
|
assign error_passive_irq_en = irq_en_ext[5];
|
726 |
|
|
assign data_overrun_irq_en_ext = irq_en_ext[3];
|
727 |
|
|
assign error_warning_irq_en_ext = irq_en_ext[2];
|
728 |
|
|
assign transmit_irq_en_ext = irq_en_ext[1];
|
729 |
|
|
assign receive_irq_en_ext = irq_en_ext[0];
|
730 |
|
|
/* End Bus Timing 0 register */
|
731 |
|
|
|
732 |
|
|
|
733 |
|
|
/* Bus Timing 0 register */
|
734 |
|
|
wire [7:0] bus_timing_0;
|
735 |
|
|
can_register #(8) BUS_TIMING_0_REG
|
736 |
|
|
( .data_in(data_in),
|
737 |
|
|
.data_out(bus_timing_0),
|
738 |
|
|
.we(we_bus_timing_0),
|
739 |
|
|
.clk(clk)
|
740 |
|
|
);
|
741 |
|
|
|
742 |
|
|
assign baud_r_presc = bus_timing_0[5:0];
|
743 |
|
|
assign sync_jump_width = bus_timing_0[7:6];
|
744 |
|
|
/* End Bus Timing 0 register */
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
/* Bus Timing 1 register */
|
748 |
|
|
wire [7:0] bus_timing_1;
|
749 |
|
|
can_register #(8) BUS_TIMING_1_REG
|
750 |
|
|
( .data_in(data_in),
|
751 |
|
|
.data_out(bus_timing_1),
|
752 |
|
|
.we(we_bus_timing_1),
|
753 |
|
|
.clk(clk)
|
754 |
|
|
);
|
755 |
|
|
|
756 |
|
|
assign time_segment1 = bus_timing_1[3:0];
|
757 |
|
|
assign time_segment2 = bus_timing_1[6:4];
|
758 |
|
|
assign triple_sampling = bus_timing_1[7];
|
759 |
|
|
/* End Bus Timing 1 register */
|
760 |
|
|
|
761 |
|
|
|
762 |
|
|
/* Error Warning Limit register */
|
763 |
|
|
can_register_asyn #(8, 96) ERROR_WARNING_REG
|
764 |
|
|
( .data_in(data_in),
|
765 |
|
|
.data_out(error_warning_limit),
|
766 |
|
|
.we(we_error_warning_limit),
|
767 |
|
|
.clk(clk),
|
768 |
|
|
.rst(rst)
|
769 |
|
|
);
|
770 |
|
|
/* End Error Warning Limit register */
|
771 |
|
|
|
772 |
|
|
|
773 |
|
|
|
774 |
|
|
/* Clock Divider register */
|
775 |
|
|
wire [7:0] clock_divider;
|
776 |
|
|
wire clock_off;
|
777 |
|
|
wire [2:0] cd;
|
778 |
|
|
reg [2:0] clkout_div;
|
779 |
|
|
reg [2:0] clkout_cnt;
|
780 |
|
|
reg clkout_tmp;
|
781 |
|
|
|
782 |
92 |
mohor |
can_register_asyn #(1, 0) CLOCK_DIVIDER_REG_7
|
783 |
66 |
mohor |
( .data_in(data_in[7]),
|
784 |
|
|
.data_out(clock_divider[7]),
|
785 |
|
|
.we(we_clock_divider_hi),
|
786 |
92 |
mohor |
.clk(clk),
|
787 |
|
|
.rst(rst)
|
788 |
66 |
mohor |
);
|
789 |
|
|
|
790 |
|
|
assign clock_divider[6:4] = 3'h0;
|
791 |
|
|
|
792 |
92 |
mohor |
can_register_asyn #(1, 0) CLOCK_DIVIDER_REG_3
|
793 |
66 |
mohor |
( .data_in(data_in[3]),
|
794 |
|
|
.data_out(clock_divider[3]),
|
795 |
|
|
.we(we_clock_divider_hi),
|
796 |
92 |
mohor |
.clk(clk),
|
797 |
|
|
.rst(rst)
|
798 |
66 |
mohor |
);
|
799 |
|
|
|
800 |
92 |
mohor |
can_register_asyn #(3, 0) CLOCK_DIVIDER_REG_LOW
|
801 |
66 |
mohor |
( .data_in(data_in[2:0]),
|
802 |
|
|
.data_out(clock_divider[2:0]),
|
803 |
|
|
.we(we_clock_divider_low),
|
804 |
92 |
mohor |
.clk(clk),
|
805 |
|
|
.rst(rst)
|
806 |
66 |
mohor |
);
|
807 |
|
|
|
808 |
|
|
assign extended_mode = clock_divider[7];
|
809 |
|
|
assign clock_off = clock_divider[3];
|
810 |
|
|
assign cd[2:0] = clock_divider[2:0];
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
always @ (cd)
|
815 |
|
|
begin
|
816 |
93 |
mohor |
case (cd) /* synthesis full_case parallel_case */
|
817 |
111 |
mohor |
3'b000 : clkout_div = 3'd0;
|
818 |
|
|
3'b001 : clkout_div = 3'd1;
|
819 |
|
|
3'b010 : clkout_div = 3'd2;
|
820 |
|
|
3'b011 : clkout_div = 3'd3;
|
821 |
|
|
3'b100 : clkout_div = 3'd4;
|
822 |
|
|
3'b101 : clkout_div = 3'd5;
|
823 |
|
|
3'b110 : clkout_div = 3'd6;
|
824 |
|
|
3'b111 : clkout_div = 3'd0;
|
825 |
66 |
mohor |
endcase
|
826 |
|
|
end
|
827 |
|
|
|
828 |
|
|
|
829 |
|
|
|
830 |
|
|
always @ (posedge clk or posedge rst)
|
831 |
|
|
begin
|
832 |
|
|
if (rst)
|
833 |
|
|
clkout_cnt <= 3'h0;
|
834 |
|
|
else if (clkout_cnt == clkout_div)
|
835 |
|
|
clkout_cnt <=#Tp 3'h0;
|
836 |
|
|
else
|
837 |
|
|
clkout_cnt <= clkout_cnt + 1'b1;
|
838 |
|
|
end
|
839 |
|
|
|
840 |
|
|
|
841 |
|
|
|
842 |
|
|
always @ (posedge clk or posedge rst)
|
843 |
|
|
begin
|
844 |
|
|
if (rst)
|
845 |
|
|
clkout_tmp <= 1'b0;
|
846 |
|
|
else if (clkout_cnt == clkout_div)
|
847 |
|
|
clkout_tmp <=#Tp ~clkout_tmp;
|
848 |
|
|
end
|
849 |
|
|
|
850 |
|
|
|
851 |
|
|
assign clkout = clock_off ? 1'b1 : ((&cd)? clk : clkout_tmp);
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
|
855 |
|
|
/* End Clock Divider register */
|
856 |
|
|
|
857 |
|
|
|
858 |
|
|
|
859 |
|
|
|
860 |
|
|
/* This section is for BASIC and EXTENDED mode */
|
861 |
|
|
|
862 |
|
|
/* Acceptance code register */
|
863 |
|
|
can_register #(8) ACCEPTANCE_CODE_REG0
|
864 |
|
|
( .data_in(data_in),
|
865 |
|
|
.data_out(acceptance_code_0),
|
866 |
|
|
.we(we_acceptance_code_0),
|
867 |
|
|
.clk(clk)
|
868 |
|
|
);
|
869 |
|
|
/* End: Acceptance code register */
|
870 |
|
|
|
871 |
|
|
|
872 |
|
|
/* Acceptance mask register */
|
873 |
|
|
can_register #(8) ACCEPTANCE_MASK_REG0
|
874 |
|
|
( .data_in(data_in),
|
875 |
|
|
.data_out(acceptance_mask_0),
|
876 |
|
|
.we(we_acceptance_mask_0),
|
877 |
|
|
.clk(clk)
|
878 |
|
|
);
|
879 |
|
|
/* End: Acceptance mask register */
|
880 |
|
|
/* End: This section is for BASIC and EXTENDED mode */
|
881 |
|
|
|
882 |
|
|
|
883 |
|
|
/* Tx data 0 register. */
|
884 |
|
|
can_register #(8) TX_DATA_REG0
|
885 |
|
|
( .data_in(data_in),
|
886 |
|
|
.data_out(tx_data_0),
|
887 |
|
|
.we(we_tx_data_0),
|
888 |
|
|
.clk(clk)
|
889 |
|
|
);
|
890 |
|
|
/* End: Tx data 0 register. */
|
891 |
|
|
|
892 |
|
|
|
893 |
|
|
/* Tx data 1 register. */
|
894 |
|
|
can_register #(8) TX_DATA_REG1
|
895 |
|
|
( .data_in(data_in),
|
896 |
|
|
.data_out(tx_data_1),
|
897 |
|
|
.we(we_tx_data_1),
|
898 |
|
|
.clk(clk)
|
899 |
|
|
);
|
900 |
|
|
/* End: Tx data 1 register. */
|
901 |
|
|
|
902 |
|
|
|
903 |
|
|
/* Tx data 2 register. */
|
904 |
|
|
can_register #(8) TX_DATA_REG2
|
905 |
|
|
( .data_in(data_in),
|
906 |
|
|
.data_out(tx_data_2),
|
907 |
|
|
.we(we_tx_data_2),
|
908 |
|
|
.clk(clk)
|
909 |
|
|
);
|
910 |
|
|
/* End: Tx data 2 register. */
|
911 |
|
|
|
912 |
|
|
|
913 |
|
|
/* Tx data 3 register. */
|
914 |
|
|
can_register #(8) TX_DATA_REG3
|
915 |
|
|
( .data_in(data_in),
|
916 |
|
|
.data_out(tx_data_3),
|
917 |
|
|
.we(we_tx_data_3),
|
918 |
|
|
.clk(clk)
|
919 |
|
|
);
|
920 |
|
|
/* End: Tx data 3 register. */
|
921 |
|
|
|
922 |
|
|
|
923 |
|
|
/* Tx data 4 register. */
|
924 |
|
|
can_register #(8) TX_DATA_REG4
|
925 |
|
|
( .data_in(data_in),
|
926 |
|
|
.data_out(tx_data_4),
|
927 |
|
|
.we(we_tx_data_4),
|
928 |
|
|
.clk(clk)
|
929 |
|
|
);
|
930 |
|
|
/* End: Tx data 4 register. */
|
931 |
|
|
|
932 |
|
|
|
933 |
|
|
/* Tx data 5 register. */
|
934 |
|
|
can_register #(8) TX_DATA_REG5
|
935 |
|
|
( .data_in(data_in),
|
936 |
|
|
.data_out(tx_data_5),
|
937 |
|
|
.we(we_tx_data_5),
|
938 |
|
|
.clk(clk)
|
939 |
|
|
);
|
940 |
|
|
/* End: Tx data 5 register. */
|
941 |
|
|
|
942 |
|
|
|
943 |
|
|
/* Tx data 6 register. */
|
944 |
|
|
can_register #(8) TX_DATA_REG6
|
945 |
|
|
( .data_in(data_in),
|
946 |
|
|
.data_out(tx_data_6),
|
947 |
|
|
.we(we_tx_data_6),
|
948 |
|
|
.clk(clk)
|
949 |
|
|
);
|
950 |
|
|
/* End: Tx data 6 register. */
|
951 |
|
|
|
952 |
|
|
|
953 |
|
|
/* Tx data 7 register. */
|
954 |
|
|
can_register #(8) TX_DATA_REG7
|
955 |
|
|
( .data_in(data_in),
|
956 |
|
|
.data_out(tx_data_7),
|
957 |
|
|
.we(we_tx_data_7),
|
958 |
|
|
.clk(clk)
|
959 |
|
|
);
|
960 |
|
|
/* End: Tx data 7 register. */
|
961 |
|
|
|
962 |
|
|
|
963 |
|
|
/* Tx data 8 register. */
|
964 |
|
|
can_register #(8) TX_DATA_REG8
|
965 |
|
|
( .data_in(data_in),
|
966 |
|
|
.data_out(tx_data_8),
|
967 |
|
|
.we(we_tx_data_8),
|
968 |
|
|
.clk(clk)
|
969 |
|
|
);
|
970 |
|
|
/* End: Tx data 8 register. */
|
971 |
|
|
|
972 |
|
|
|
973 |
|
|
/* Tx data 9 register. */
|
974 |
|
|
can_register #(8) TX_DATA_REG9
|
975 |
|
|
( .data_in(data_in),
|
976 |
|
|
.data_out(tx_data_9),
|
977 |
|
|
.we(we_tx_data_9),
|
978 |
|
|
.clk(clk)
|
979 |
|
|
);
|
980 |
|
|
/* End: Tx data 9 register. */
|
981 |
|
|
|
982 |
|
|
|
983 |
|
|
/* Tx data 10 register. */
|
984 |
|
|
can_register #(8) TX_DATA_REG10
|
985 |
|
|
( .data_in(data_in),
|
986 |
|
|
.data_out(tx_data_10),
|
987 |
|
|
.we(we_tx_data_10),
|
988 |
|
|
.clk(clk)
|
989 |
|
|
);
|
990 |
|
|
/* End: Tx data 10 register. */
|
991 |
|
|
|
992 |
|
|
|
993 |
|
|
/* Tx data 11 register. */
|
994 |
|
|
can_register #(8) TX_DATA_REG11
|
995 |
|
|
( .data_in(data_in),
|
996 |
|
|
.data_out(tx_data_11),
|
997 |
|
|
.we(we_tx_data_11),
|
998 |
|
|
.clk(clk)
|
999 |
|
|
);
|
1000 |
|
|
/* End: Tx data 11 register. */
|
1001 |
|
|
|
1002 |
|
|
|
1003 |
|
|
/* Tx data 12 register. */
|
1004 |
|
|
can_register #(8) TX_DATA_REG12
|
1005 |
|
|
( .data_in(data_in),
|
1006 |
|
|
.data_out(tx_data_12),
|
1007 |
|
|
.we(we_tx_data_12),
|
1008 |
|
|
.clk(clk)
|
1009 |
|
|
);
|
1010 |
|
|
/* End: Tx data 12 register. */
|
1011 |
|
|
|
1012 |
|
|
|
1013 |
|
|
|
1014 |
|
|
|
1015 |
|
|
|
1016 |
|
|
/* This section is for EXTENDED mode */
|
1017 |
|
|
|
1018 |
|
|
/* Acceptance code register 1 */
|
1019 |
|
|
can_register #(8) ACCEPTANCE_CODE_REG1
|
1020 |
|
|
( .data_in(data_in),
|
1021 |
|
|
.data_out(acceptance_code_1),
|
1022 |
|
|
.we(we_acceptance_code_1),
|
1023 |
|
|
.clk(clk)
|
1024 |
|
|
);
|
1025 |
|
|
/* End: Acceptance code register */
|
1026 |
|
|
|
1027 |
|
|
|
1028 |
|
|
/* Acceptance code register 2 */
|
1029 |
|
|
can_register #(8) ACCEPTANCE_CODE_REG2
|
1030 |
|
|
( .data_in(data_in),
|
1031 |
|
|
.data_out(acceptance_code_2),
|
1032 |
|
|
.we(we_acceptance_code_2),
|
1033 |
|
|
.clk(clk)
|
1034 |
|
|
);
|
1035 |
|
|
/* End: Acceptance code register */
|
1036 |
|
|
|
1037 |
|
|
|
1038 |
|
|
/* Acceptance code register 3 */
|
1039 |
|
|
can_register #(8) ACCEPTANCE_CODE_REG3
|
1040 |
|
|
( .data_in(data_in),
|
1041 |
|
|
.data_out(acceptance_code_3),
|
1042 |
|
|
.we(we_acceptance_code_3),
|
1043 |
|
|
.clk(clk)
|
1044 |
|
|
);
|
1045 |
|
|
/* End: Acceptance code register */
|
1046 |
|
|
|
1047 |
|
|
|
1048 |
|
|
/* Acceptance mask register 1 */
|
1049 |
|
|
can_register #(8) ACCEPTANCE_MASK_REG1
|
1050 |
|
|
( .data_in(data_in),
|
1051 |
|
|
.data_out(acceptance_mask_1),
|
1052 |
|
|
.we(we_acceptance_mask_1),
|
1053 |
|
|
.clk(clk)
|
1054 |
|
|
);
|
1055 |
|
|
/* End: Acceptance code register */
|
1056 |
|
|
|
1057 |
|
|
|
1058 |
|
|
/* Acceptance mask register 2 */
|
1059 |
|
|
can_register #(8) ACCEPTANCE_MASK_REG2
|
1060 |
|
|
( .data_in(data_in),
|
1061 |
|
|
.data_out(acceptance_mask_2),
|
1062 |
|
|
.we(we_acceptance_mask_2),
|
1063 |
|
|
.clk(clk)
|
1064 |
|
|
);
|
1065 |
|
|
/* End: Acceptance code register */
|
1066 |
|
|
|
1067 |
|
|
|
1068 |
|
|
/* Acceptance mask register 3 */
|
1069 |
|
|
can_register #(8) ACCEPTANCE_MASK_REG3
|
1070 |
|
|
( .data_in(data_in),
|
1071 |
|
|
.data_out(acceptance_mask_3),
|
1072 |
|
|
.we(we_acceptance_mask_3),
|
1073 |
|
|
.clk(clk)
|
1074 |
|
|
);
|
1075 |
|
|
/* End: Acceptance code register */
|
1076 |
|
|
|
1077 |
|
|
|
1078 |
|
|
/* End: This section is for EXTENDED mode */
|
1079 |
|
|
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
|
|
|
1083 |
|
|
// Reading data from registers
|
1084 |
111 |
mohor |
always @ ( addr or extended_mode or mode or bus_timing_0 or bus_timing_1 or clock_divider or
|
1085 |
66 |
mohor |
acceptance_code_0 or acceptance_code_1 or acceptance_code_2 or acceptance_code_3 or
|
1086 |
|
|
acceptance_mask_0 or acceptance_mask_1 or acceptance_mask_2 or acceptance_mask_3 or
|
1087 |
|
|
reset_mode or tx_data_0 or tx_data_1 or tx_data_2 or tx_data_3 or tx_data_4 or
|
1088 |
|
|
tx_data_5 or tx_data_6 or tx_data_7 or tx_data_8 or tx_data_9 or status or
|
1089 |
|
|
error_warning_limit or rx_err_cnt or tx_err_cnt or irq_en_ext or irq_reg or mode_ext or
|
1090 |
|
|
arbitration_lost_capture or rx_message_counter or mode_basic or error_capture_code
|
1091 |
|
|
)
|
1092 |
|
|
begin
|
1093 |
111 |
mohor |
case({extended_mode, addr[4:0]}) /* synthesis parallel_case */
|
1094 |
|
|
{1'h1, 5'd00} : data_out = {4'b0000, mode_ext[3:1], mode[0]}; // extended mode
|
1095 |
|
|
{1'h1, 5'd01} : data_out = 8'h0; // extended mode
|
1096 |
|
|
{1'h1, 5'd02} : data_out = status; // extended mode
|
1097 |
|
|
{1'h1, 5'd03} : data_out = irq_reg; // extended mode
|
1098 |
|
|
{1'h1, 5'd04} : data_out = irq_en_ext; // extended mode
|
1099 |
|
|
{1'h1, 5'd06} : data_out = bus_timing_0; // extended mode
|
1100 |
|
|
{1'h1, 5'd07} : data_out = bus_timing_1; // extended mode
|
1101 |
|
|
{1'h1, 5'd11} : data_out = {3'h0, arbitration_lost_capture[4:0]}; // extended mode
|
1102 |
|
|
{1'h1, 5'd12} : data_out = error_capture_code; // extended mode
|
1103 |
|
|
{1'h1, 5'd13} : data_out = error_warning_limit; // extended mode
|
1104 |
|
|
{1'h1, 5'd14} : data_out = rx_err_cnt; // extended mode
|
1105 |
|
|
{1'h1, 5'd15} : data_out = tx_err_cnt; // extended mode
|
1106 |
|
|
{1'h1, 5'd16} : data_out = acceptance_code_0; // extended mode
|
1107 |
|
|
{1'h1, 5'd17} : data_out = acceptance_code_1; // extended mode
|
1108 |
|
|
{1'h1, 5'd18} : data_out = acceptance_code_2; // extended mode
|
1109 |
|
|
{1'h1, 5'd19} : data_out = acceptance_code_3; // extended mode
|
1110 |
|
|
{1'h1, 5'd20} : data_out = acceptance_mask_0; // extended mode
|
1111 |
|
|
{1'h1, 5'd21} : data_out = acceptance_mask_1; // extended mode
|
1112 |
|
|
{1'h1, 5'd22} : data_out = acceptance_mask_2; // extended mode
|
1113 |
|
|
{1'h1, 5'd23} : data_out = acceptance_mask_3; // extended mode
|
1114 |
|
|
{1'h1, 5'd24} : data_out = 8'h0; // extended mode
|
1115 |
|
|
{1'h1, 5'd25} : data_out = 8'h0; // extended mode
|
1116 |
|
|
{1'h1, 5'd26} : data_out = 8'h0; // extended mode
|
1117 |
|
|
{1'h1, 5'd27} : data_out = 8'h0; // extended mode
|
1118 |
|
|
{1'h1, 5'd28} : data_out = 8'h0; // extended mode
|
1119 |
|
|
{1'h1, 5'd29} : data_out = {1'b0, rx_message_counter}; // extended mode
|
1120 |
|
|
{1'h1, 5'd31} : data_out = clock_divider; // extended mode
|
1121 |
|
|
{1'h0, 5'd00} : data_out = {3'b001, mode_basic[4:1], mode[0]}; // basic mode
|
1122 |
|
|
{1'h0, 5'd01} : data_out = 8'hff; // basic mode
|
1123 |
|
|
{1'h0, 5'd02} : data_out = status; // basic mode
|
1124 |
156 |
igorm |
{1'h0, 5'd03} : data_out = {4'he, irq_reg[3:0]}; // basic mode
|
1125 |
111 |
mohor |
{1'h0, 5'd04} : data_out = reset_mode? acceptance_code_0 : 8'hff; // basic mode
|
1126 |
|
|
{1'h0, 5'd05} : data_out = reset_mode? acceptance_mask_0 : 8'hff; // basic mode
|
1127 |
|
|
{1'h0, 5'd06} : data_out = reset_mode? bus_timing_0 : 8'hff; // basic mode
|
1128 |
|
|
{1'h0, 5'd07} : data_out = reset_mode? bus_timing_1 : 8'hff; // basic mode
|
1129 |
|
|
{1'h0, 5'd10} : data_out = reset_mode? 8'hff : tx_data_0; // basic mode
|
1130 |
|
|
{1'h0, 5'd11} : data_out = reset_mode? 8'hff : tx_data_1; // basic mode
|
1131 |
|
|
{1'h0, 5'd12} : data_out = reset_mode? 8'hff : tx_data_2; // basic mode
|
1132 |
|
|
{1'h0, 5'd13} : data_out = reset_mode? 8'hff : tx_data_3; // basic mode
|
1133 |
|
|
{1'h0, 5'd14} : data_out = reset_mode? 8'hff : tx_data_4; // basic mode
|
1134 |
|
|
{1'h0, 5'd15} : data_out = reset_mode? 8'hff : tx_data_5; // basic mode
|
1135 |
|
|
{1'h0, 5'd16} : data_out = reset_mode? 8'hff : tx_data_6; // basic mode
|
1136 |
|
|
{1'h0, 5'd17} : data_out = reset_mode? 8'hff : tx_data_7; // basic mode
|
1137 |
|
|
{1'h0, 5'd18} : data_out = reset_mode? 8'hff : tx_data_8; // basic mode
|
1138 |
|
|
{1'h0, 5'd19} : data_out = reset_mode? 8'hff : tx_data_9; // basic mode
|
1139 |
|
|
{1'h0, 5'd31} : data_out = clock_divider; // basic mode
|
1140 |
|
|
default : data_out = 8'h0; // the rest is read as 0
|
1141 |
|
|
endcase
|
1142 |
66 |
mohor |
end
|
1143 |
|
|
|
1144 |
|
|
|
1145 |
|
|
// Some interrupts exist in basic mode and in extended mode. Since they are in different registers they need to be multiplexed.
|
1146 |
|
|
assign data_overrun_irq_en = extended_mode ? data_overrun_irq_en_ext : overrun_irq_en_basic;
|
1147 |
|
|
assign error_warning_irq_en = extended_mode ? error_warning_irq_en_ext : error_irq_en_basic;
|
1148 |
|
|
assign transmit_irq_en = extended_mode ? transmit_irq_en_ext : transmit_irq_en_basic;
|
1149 |
|
|
assign receive_irq_en = extended_mode ? receive_irq_en_ext : receive_irq_en_basic;
|
1150 |
|
|
|
1151 |
|
|
|
1152 |
|
|
reg data_overrun_irq;
|
1153 |
|
|
always @ (posedge clk or posedge rst)
|
1154 |
|
|
begin
|
1155 |
|
|
if (rst)
|
1156 |
|
|
data_overrun_irq <= 1'b0;
|
1157 |
|
|
else if (overrun & (~overrun_q) & data_overrun_irq_en)
|
1158 |
|
|
data_overrun_irq <=#Tp 1'b1;
|
1159 |
152 |
igorm |
else if (reset_mode || read_irq_reg)
|
1160 |
66 |
mohor |
data_overrun_irq <=#Tp 1'b0;
|
1161 |
|
|
end
|
1162 |
|
|
|
1163 |
|
|
|
1164 |
|
|
reg transmit_irq;
|
1165 |
|
|
always @ (posedge clk or posedge rst)
|
1166 |
|
|
begin
|
1167 |
|
|
if (rst)
|
1168 |
|
|
transmit_irq <= 1'b0;
|
1169 |
152 |
igorm |
else if (reset_mode || read_irq_reg)
|
1170 |
|
|
transmit_irq <=#Tp 1'b0;
|
1171 |
66 |
mohor |
else if (transmit_buffer_status & (~transmit_buffer_status_q) & transmit_irq_en)
|
1172 |
|
|
transmit_irq <=#Tp 1'b1;
|
1173 |
|
|
end
|
1174 |
|
|
|
1175 |
|
|
|
1176 |
|
|
reg receive_irq;
|
1177 |
|
|
always @ (posedge clk or posedge rst)
|
1178 |
|
|
begin
|
1179 |
|
|
if (rst)
|
1180 |
|
|
receive_irq <= 1'b0;
|
1181 |
|
|
else if ((~info_empty) & (~receive_irq) & receive_irq_en)
|
1182 |
|
|
receive_irq <=#Tp 1'b1;
|
1183 |
152 |
igorm |
else if (reset_mode || release_buffer)
|
1184 |
|
|
receive_irq <=#Tp 1'b0;
|
1185 |
66 |
mohor |
end
|
1186 |
|
|
|
1187 |
|
|
|
1188 |
|
|
reg error_irq;
|
1189 |
|
|
always @ (posedge clk or posedge rst)
|
1190 |
|
|
begin
|
1191 |
|
|
if (rst)
|
1192 |
|
|
error_irq <= 1'b0;
|
1193 |
|
|
else if (((error_status ^ error_status_q) | (node_bus_off ^ node_bus_off_q)) & error_warning_irq_en)
|
1194 |
|
|
error_irq <=#Tp 1'b1;
|
1195 |
|
|
else if (read_irq_reg)
|
1196 |
|
|
error_irq <=#Tp 1'b0;
|
1197 |
|
|
end
|
1198 |
|
|
|
1199 |
|
|
|
1200 |
|
|
reg bus_error_irq;
|
1201 |
|
|
always @ (posedge clk or posedge rst)
|
1202 |
|
|
begin
|
1203 |
|
|
if (rst)
|
1204 |
|
|
bus_error_irq <= 1'b0;
|
1205 |
|
|
else if (set_bus_error_irq & bus_error_irq_en)
|
1206 |
|
|
bus_error_irq <=#Tp 1'b1;
|
1207 |
152 |
igorm |
else if (reset_mode || read_irq_reg)
|
1208 |
66 |
mohor |
bus_error_irq <=#Tp 1'b0;
|
1209 |
|
|
end
|
1210 |
|
|
|
1211 |
|
|
|
1212 |
|
|
reg arbitration_lost_irq;
|
1213 |
|
|
always @ (posedge clk or posedge rst)
|
1214 |
|
|
begin
|
1215 |
|
|
if (rst)
|
1216 |
|
|
arbitration_lost_irq <= 1'b0;
|
1217 |
|
|
else if (set_arbitration_lost_irq & arbitration_lost_irq_en)
|
1218 |
|
|
arbitration_lost_irq <=#Tp 1'b1;
|
1219 |
152 |
igorm |
else if (reset_mode || read_irq_reg)
|
1220 |
66 |
mohor |
arbitration_lost_irq <=#Tp 1'b0;
|
1221 |
|
|
end
|
1222 |
|
|
|
1223 |
|
|
|
1224 |
|
|
|
1225 |
|
|
reg error_passive_irq;
|
1226 |
|
|
always @ (posedge clk or posedge rst)
|
1227 |
|
|
begin
|
1228 |
|
|
if (rst)
|
1229 |
|
|
error_passive_irq <= 1'b0;
|
1230 |
|
|
else if ((node_error_passive & (~node_error_passive_q) | (~node_error_passive) & node_error_passive_q & node_error_active) & error_passive_irq_en)
|
1231 |
|
|
error_passive_irq <=#Tp 1'b1;
|
1232 |
152 |
igorm |
else if (reset_mode || read_irq_reg)
|
1233 |
66 |
mohor |
error_passive_irq <=#Tp 1'b0;
|
1234 |
|
|
end
|
1235 |
|
|
|
1236 |
|
|
|
1237 |
|
|
|
1238 |
|
|
assign irq_reg = {bus_error_irq, arbitration_lost_irq, error_passive_irq, 1'b0, data_overrun_irq, error_irq, transmit_irq, receive_irq};
|
1239 |
|
|
|
1240 |
|
|
assign irq = data_overrun_irq | transmit_irq | receive_irq | error_irq | bus_error_irq | arbitration_lost_irq | error_passive_irq;
|
1241 |
|
|
|
1242 |
|
|
|
1243 |
147 |
igorm |
always @ (posedge clk or posedge rst)
|
1244 |
|
|
begin
|
1245 |
|
|
if (rst)
|
1246 |
|
|
irq_n <= 1'b1;
|
1247 |
154 |
igorm |
else if (read_irq_reg || release_buffer)
|
1248 |
147 |
igorm |
irq_n <=#Tp 1'b1;
|
1249 |
|
|
else if (irq)
|
1250 |
|
|
irq_n <=#Tp 1'b0;
|
1251 |
|
|
end
|
1252 |
66 |
mohor |
|
1253 |
|
|
|
1254 |
|
|
|
1255 |
|
|
endmodule
|
1256 |
152 |
igorm |
|