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

Subversion Repositories can

[/] [can/] [trunk/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 77

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

Line No. Rev Author Line
1 66 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  can_top.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 77 mohor
// Revision 1.33  2003/06/11 14:21:35  mohor
54
// When switching to tx, sync stage is overjumped.
55
//
56 75 mohor
// Revision 1.32  2003/06/09 11:32:36  mohor
57
// Ports added for the CAN_BIST.
58
//
59 71 mohor
// Revision 1.31  2003/03/26 11:19:46  mohor
60
// CAN interrupt is active low.
61
//
62 67 mohor
// Revision 1.30  2003/03/20 17:01:17  mohor
63
// unix.
64
//
65 66 mohor
// Revision 1.28  2003/03/14 19:36:48  mohor
66
// can_cs signal used for generation of the cs.
67
//
68
// Revision 1.27  2003/03/12 05:56:33  mohor
69
// Bidirectional port_0_i changed to port_0_io.
70
// input cs_can changed to cs_can_i.
71
//
72
// Revision 1.26  2003/03/12 04:39:40  mohor
73
// rd_i and wr_i are active high signals. If 8051 is connected, these two signals
74
// need to be negated one level higher.
75
//
76
// Revision 1.25  2003/03/12 04:17:36  mohor
77
// 8051 interface added (besides WISHBONE interface). Selection is made in
78
// can_defines.v file.
79
//
80
// Revision 1.24  2003/03/10 17:24:40  mohor
81
// wire declaration added.
82
//
83
// Revision 1.23  2003/03/05 15:33:13  mohor
84
// tx_o is now tristated signal. tx_oen and tx_o combined together.
85
//
86
// Revision 1.22  2003/03/05 15:01:56  mohor
87
// Top level signal names changed.
88
//
89
// Revision 1.21  2003/03/01 22:53:33  mohor
90
// Actel APA ram supported.
91
//
92
// Revision 1.20  2003/02/19 15:09:02  mohor
93
// Incomplete sensitivity list fixed.
94
//
95
// Revision 1.19  2003/02/19 15:04:14  mohor
96
// Typo fixed.
97
//
98
// Revision 1.18  2003/02/19 14:44:03  mohor
99
// CAN core finished. Host interface added. Registers finished.
100
// Synchronization to the wishbone finished.
101
//
102
// Revision 1.17  2003/02/18 00:10:15  mohor
103
// Most of the registers added. Registers "arbitration lost capture", "error code
104
// capture" + few more still need to be added.
105
//
106
// Revision 1.16  2003/02/14 20:17:01  mohor
107
// Several registers added. Not finished, yet.
108
//
109
// Revision 1.15  2003/02/12 14:25:30  mohor
110
// abort_tx added.
111
//
112
// Revision 1.14  2003/02/11 00:56:06  mohor
113
// Wishbone interface added.
114
//
115
// Revision 1.13  2003/02/09 18:40:29  mohor
116
// Overload fixed. Hard synchronization also enabled at the last bit of
117
// interframe.
118
//
119
// Revision 1.12  2003/02/09 02:24:33  mohor
120
// Bosch license warning added. Error counters finished. Overload frames
121
// still need to be fixed.
122
//
123
// Revision 1.11  2003/02/04 14:34:52  mohor
124
// *** empty log message ***
125
//
126
// Revision 1.10  2003/01/31 01:13:38  mohor
127
// backup.
128
//
129
// Revision 1.9  2003/01/15 13:16:48  mohor
130
// When a frame with "remote request" is received, no data is stored to
131
// fifo, just the frame information (identifier, ...). Data length that
132
// is stored is the received data length and not the actual data length
133
// that is stored to fifo.
134
//
135
// Revision 1.8  2003/01/14 17:25:09  mohor
136
// Addresses corrected to decimal values (previously hex).
137
//
138
// Revision 1.7  2003/01/10 17:51:34  mohor
139
// Temporary version (backup).
140
//
141
// Revision 1.6  2003/01/09 21:54:45  mohor
142
// rx fifo added. Not 100 % verified, yet.
143
//
144
// Revision 1.5  2003/01/08 02:10:56  mohor
145
// Acceptance filter added.
146
//
147
// Revision 1.4  2002/12/28 04:13:23  mohor
148
// Backup version.
149
//
150
// Revision 1.3  2002/12/27 00:12:52  mohor
151
// Header changed, testbench improved to send a frame (crc still missing).
152
//
153
// Revision 1.2  2002/12/26 16:00:34  mohor
154
// Testbench define file added. Clock divider register added.
155
//
156
// Revision 1.1.1.1  2002/12/20 16:39:21  mohor
157
// Initial
158
//
159
//
160
//
161
 
162
// synopsys translate_off
163
`include "timescale.v"
164
// synopsys translate_on
165
`include "can_defines.v"
166
 
167
module can_top
168
(
169
  `ifdef CAN_WISHBONE_IF
170
    wb_clk_i,
171
    wb_rst_i,
172
    wb_dat_i,
173
    wb_dat_o,
174
    wb_cyc_i,
175
    wb_stb_i,
176
    wb_we_i,
177
    wb_adr_i,
178
    wb_ack_o,
179
  `else
180
    rst_i,
181
    ale_i,
182
    rd_i,
183
    wr_i,
184
    port_0_io,
185
  `endif
186
  cs_can_i,
187
  clk_i,
188
  rx_i,
189
  tx_o,
190 67 mohor
  irq_on,
191 66 mohor
  clkout_o
192 71 mohor
  // Bist
193
`ifdef CAN_BIST
194
  ,
195
  // debug chain signals
196
  scanb_rst,      // bist scan reset
197
  scanb_clk,      // bist scan clock
198
  scanb_si,       // bist scan serial in
199
  scanb_so,       // bist scan serial out
200
  scanb_en        // bist scan shift enable
201
`endif
202 66 mohor
);
203
 
204
parameter Tp = 1;
205
 
206
`ifdef CAN_WISHBONE_IF
207
  input        wb_clk_i;
208
  input        wb_rst_i;
209
  input  [7:0] wb_dat_i;
210
  output [7:0] wb_dat_o;
211
  input        wb_cyc_i;
212
  input        wb_stb_i;
213
  input        wb_we_i;
214
  input  [7:0] wb_adr_i;
215
  output       wb_ack_o;
216
 
217
  reg          wb_ack_o;
218
  reg          cs_sync1;
219
  reg          cs_sync2;
220
  reg          cs_sync3;
221
 
222
  reg          cs_ack1;
223
  reg          cs_ack2;
224
  reg          cs_ack3;
225
  reg          cs_sync_rst1;
226
  reg          cs_sync_rst2;
227
`else
228
  input        rst_i;
229
  input        ale_i;
230
  input        rd_i;
231
  input        wr_i;
232
  inout  [7:0] port_0_io;
233
 
234
  reg    [7:0] addr_latched;
235
  reg          wr_i_q;
236
  reg          rd_i_q;
237
`endif
238
 
239
input        cs_can_i;
240
input        clk_i;
241
input        rx_i;
242
output       tx_o;
243 67 mohor
output       irq_on;
244 66 mohor
output       clkout_o;
245
 
246 71 mohor
// Bist
247
`ifdef CAN_BIST
248
input   scanb_rst;      // bist scan reset
249
input   scanb_clk;      // bist scan clock
250
input   scanb_si;       // bist scan serial in
251
output  scanb_so;       // bist scan serial out
252
input   scanb_en;       // bist scan shift enable
253
`endif
254
 
255 66 mohor
reg          data_out_fifo_selected;
256
 
257
 
258 67 mohor
wire         irq_o;
259 66 mohor
wire   [7:0] data_out_fifo;
260
wire   [7:0] data_out_regs;
261
 
262
 
263
/* Mode register */
264
wire         reset_mode;
265
wire         listen_only_mode;
266
wire         acceptance_filter_mode;
267
wire         self_test_mode;
268
 
269
/* Command register */
270
wire         release_buffer;
271
wire         tx_request;
272
wire         abort_tx;
273
wire         self_rx_request;
274
wire         single_shot_transmission;
275
 
276
/* Arbitration Lost Capture Register */
277
wire         read_arbitration_lost_capture_reg;
278
 
279
/* Error Code Capture Register */
280
wire         read_error_code_capture_reg;
281
wire   [7:0] error_capture_code;
282
 
283
/* Bus Timing 0 register */
284
wire   [5:0] baud_r_presc;
285
wire   [1:0] sync_jump_width;
286
 
287
/* Bus Timing 1 register */
288
wire   [3:0] time_segment1;
289
wire   [2:0] time_segment2;
290
wire         triple_sampling;
291
 
292
/* Error Warning Limit register */
293
wire   [7:0] error_warning_limit;
294
 
295
/* Rx Error Counter register */
296
wire         we_rx_err_cnt;
297
 
298
/* Tx Error Counter register */
299
wire         we_tx_err_cnt;
300
 
301
/* Clock Divider register */
302
wire         extended_mode;
303
 
304
/* This section is for BASIC and EXTENDED mode */
305
/* Acceptance code register */
306
wire   [7:0] acceptance_code_0;
307
 
308
/* Acceptance mask register */
309
wire   [7:0] acceptance_mask_0;
310
/* End: This section is for BASIC and EXTENDED mode */
311
 
312
 
313
/* This section is for EXTENDED mode */
314
/* Acceptance code register */
315
wire   [7:0] acceptance_code_1;
316
wire   [7:0] acceptance_code_2;
317
wire   [7:0] acceptance_code_3;
318
 
319
/* Acceptance mask register */
320
wire   [7:0] acceptance_mask_1;
321
wire   [7:0] acceptance_mask_2;
322
wire   [7:0] acceptance_mask_3;
323
/* End: This section is for EXTENDED mode */
324
 
325
/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
326
wire   [7:0] tx_data_0;
327
wire   [7:0] tx_data_1;
328
wire   [7:0] tx_data_2;
329
wire   [7:0] tx_data_3;
330
wire   [7:0] tx_data_4;
331
wire   [7:0] tx_data_5;
332
wire   [7:0] tx_data_6;
333
wire   [7:0] tx_data_7;
334
wire   [7:0] tx_data_8;
335
wire   [7:0] tx_data_9;
336
wire   [7:0] tx_data_10;
337
wire   [7:0] tx_data_11;
338
wire   [7:0] tx_data_12;
339
/* End: Tx data registers */
340
 
341
wire         cs;
342
 
343
/* Output signals from can_btl module */
344
wire         clk_en;
345
wire         sample_point;
346
wire         sampled_bit;
347
wire         sampled_bit_q;
348
wire         tx_point;
349
wire         hard_sync;
350 75 mohor
wire         go_seg1;
351 66 mohor
 
352
/* output from can_bsp module */
353
wire         rx_idle;
354
wire         transmitting;
355 75 mohor
wire         overjump_sync_seg;
356 66 mohor
wire         last_bit_of_inter;
357
wire         set_reset_mode;
358
wire         node_bus_off;
359
wire         error_status;
360
wire   [7:0] rx_err_cnt;
361
wire   [7:0] tx_err_cnt;
362
wire         rx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
363
wire         tx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
364
wire         transmit_status;
365
wire         receive_status;
366
wire         tx_successful;
367
wire         need_to_tx;
368
wire         overrun;
369
wire         info_empty;
370
wire         set_bus_error_irq;
371
wire         set_arbitration_lost_irq;
372
wire   [4:0] arbitration_lost_capture;
373
wire         node_error_passive;
374
wire         node_error_active;
375
wire   [6:0] rx_message_counter;
376
wire         tx_out;
377
wire         tx_oen;
378
 
379
wire         rst;
380
wire         we;
381
wire   [7:0] addr;
382
wire   [7:0] data_in;
383
reg    [7:0] data_out;
384
 
385
 
386
/* Connecting can_registers module */
387
can_registers i_can_registers
388
(
389
  .clk(clk_i),
390
  .rst(rst),
391
  .cs(cs),
392
  .we(we),
393
  .addr(addr),
394
  .data_in(data_in),
395
  .data_out(data_out_regs),
396
  .irq(irq_o),
397
 
398
  .sample_point(sample_point),
399
  .transmitting(transmitting),
400
  .set_reset_mode(set_reset_mode),
401
  .node_bus_off(node_bus_off),
402
  .error_status(error_status),
403
  .rx_err_cnt(rx_err_cnt),
404
  .tx_err_cnt(tx_err_cnt),
405
  .transmit_status(transmit_status),
406
  .receive_status(receive_status),
407
  .tx_successful(tx_successful),
408
  .need_to_tx(need_to_tx),
409
  .overrun(overrun),
410
  .info_empty(info_empty),
411
  .set_bus_error_irq(set_bus_error_irq),
412
  .set_arbitration_lost_irq(set_arbitration_lost_irq),
413
  .arbitration_lost_capture(arbitration_lost_capture),
414
  .node_error_passive(node_error_passive),
415
  .node_error_active(node_error_active),
416
  .rx_message_counter(rx_message_counter),
417
 
418
 
419
  /* Mode register */
420
  .reset_mode(reset_mode),
421
  .listen_only_mode(listen_only_mode),
422
  .acceptance_filter_mode(acceptance_filter_mode),
423
  .self_test_mode(self_test_mode),
424
 
425
  /* Command register */
426
  .clear_data_overrun(),
427
  .release_buffer(release_buffer),
428
  .abort_tx(abort_tx),
429
  .tx_request(tx_request),
430
  .self_rx_request(self_rx_request),
431
  .single_shot_transmission(single_shot_transmission),
432
 
433
  /* Arbitration Lost Capture Register */
434
  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),
435
 
436
  /* Error Code Capture Register */
437
  .read_error_code_capture_reg(read_error_code_capture_reg),
438
  .error_capture_code(error_capture_code),
439
 
440
  /* Bus Timing 0 register */
441
  .baud_r_presc(baud_r_presc),
442
  .sync_jump_width(sync_jump_width),
443
 
444
  /* Bus Timing 1 register */
445
  .time_segment1(time_segment1),
446
  .time_segment2(time_segment2),
447
  .triple_sampling(triple_sampling),
448
 
449
  /* Error Warning Limit register */
450
  .error_warning_limit(error_warning_limit),
451
 
452
  /* Rx Error Counter register */
453
  .we_rx_err_cnt(we_rx_err_cnt),
454
 
455
  /* Tx Error Counter register */
456
  .we_tx_err_cnt(we_tx_err_cnt),
457
 
458
  /* Clock Divider register */
459
  .extended_mode(extended_mode),
460
  .clkout(clkout_o),
461
 
462
  /* This section is for BASIC and EXTENDED mode */
463
  /* Acceptance code register */
464
  .acceptance_code_0(acceptance_code_0),
465
 
466
  /* Acceptance mask register */
467
  .acceptance_mask_0(acceptance_mask_0),
468
  /* End: This section is for BASIC and EXTENDED mode */
469
 
470
  /* This section is for EXTENDED mode */
471
  /* Acceptance code register */
472
  .acceptance_code_1(acceptance_code_1),
473
  .acceptance_code_2(acceptance_code_2),
474
  .acceptance_code_3(acceptance_code_3),
475
 
476
  /* Acceptance mask register */
477
  .acceptance_mask_1(acceptance_mask_1),
478
  .acceptance_mask_2(acceptance_mask_2),
479
  .acceptance_mask_3(acceptance_mask_3),
480
  /* End: This section is for EXTENDED mode */
481
 
482
  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
483
  .tx_data_0(tx_data_0),
484
  .tx_data_1(tx_data_1),
485
  .tx_data_2(tx_data_2),
486
  .tx_data_3(tx_data_3),
487
  .tx_data_4(tx_data_4),
488
  .tx_data_5(tx_data_5),
489
  .tx_data_6(tx_data_6),
490
  .tx_data_7(tx_data_7),
491
  .tx_data_8(tx_data_8),
492
  .tx_data_9(tx_data_9),
493
  .tx_data_10(tx_data_10),
494
  .tx_data_11(tx_data_11),
495
  .tx_data_12(tx_data_12)
496
  /* End: Tx data registers */
497
);
498
 
499
 
500 67 mohor
assign irq_on = ~irq_o;
501 66 mohor
 
502
 
503
/* Connecting can_btl module */
504
can_btl i_can_btl
505
(
506
  .clk(clk_i),
507
  .rst(rst),
508
  .rx(rx_i),
509
 
510
  /* Mode register */
511
  .reset_mode(reset_mode),
512
 
513
  /* Bus Timing 0 register */
514
  .baud_r_presc(baud_r_presc),
515
  .sync_jump_width(sync_jump_width),
516
 
517
  /* Bus Timing 1 register */
518
  .time_segment1(time_segment1),
519
  .time_segment2(time_segment2),
520
  .triple_sampling(triple_sampling),
521
 
522
  /* Output signals from this module */
523
  .clk_en(clk_en),
524
  .sample_point(sample_point),
525
  .sampled_bit(sampled_bit),
526
  .sampled_bit_q(sampled_bit_q),
527
  .tx_point(tx_point),
528
  .hard_sync(hard_sync),
529 75 mohor
  .go_seg1(go_seg1),
530 66 mohor
 
531
 
532
  /* output from can_bsp module */
533
  .rx_idle(rx_idle),
534 75 mohor
  .overjump_sync_seg(overjump_sync_seg),
535 66 mohor
  .last_bit_of_inter(last_bit_of_inter)
536
 
537
 
538
 
539
);
540
 
541
 
542
 
543
can_bsp i_can_bsp
544
(
545
  .clk(clk_i),
546
  .rst(rst),
547
 
548
  /* From btl module */
549
  .sample_point(sample_point),
550
  .sampled_bit(sampled_bit),
551
  .sampled_bit_q(sampled_bit_q),
552
  .tx_point(tx_point),
553
  .hard_sync(hard_sync),
554 75 mohor
  .go_seg1(go_seg1),
555 66 mohor
 
556
  .addr(addr),
557
  .data_in(data_in),
558
  .data_out(data_out_fifo),
559
  .fifo_selected(data_out_fifo_selected),
560
 
561
  /* Mode register */
562
  .reset_mode(reset_mode),
563
  .listen_only_mode(listen_only_mode),
564
  .acceptance_filter_mode(acceptance_filter_mode),
565
  .self_test_mode(self_test_mode),
566
 
567
  /* Command register */
568
  .release_buffer(release_buffer),
569
  .tx_request(tx_request),
570
  .abort_tx(abort_tx),
571
  .self_rx_request(self_rx_request),
572
  .single_shot_transmission(single_shot_transmission),
573
 
574
  /* Arbitration Lost Capture Register */
575
  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),
576
 
577
  /* Error Code Capture Register */
578
  .read_error_code_capture_reg(read_error_code_capture_reg),
579
  .error_capture_code(error_capture_code),
580
 
581
  /* Error Warning Limit register */
582
  .error_warning_limit(error_warning_limit),
583
 
584
  /* Rx Error Counter register */
585
  .we_rx_err_cnt(we_rx_err_cnt),
586
 
587
  /* Tx Error Counter register */
588
  .we_tx_err_cnt(we_tx_err_cnt),
589
 
590
  /* Clock Divider register */
591
  .extended_mode(extended_mode),
592
 
593
  /* output from can_bsp module */
594
  .rx_idle(rx_idle),
595
  .transmitting(transmitting),
596 75 mohor
  .overjump_sync_seg(overjump_sync_seg),
597 66 mohor
  .last_bit_of_inter(last_bit_of_inter),
598
  .set_reset_mode(set_reset_mode),
599
  .node_bus_off(node_bus_off),
600
  .error_status(error_status),
601
  .rx_err_cnt({rx_err_cnt_dummy, rx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
602
  .tx_err_cnt({tx_err_cnt_dummy, tx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).
603
  .transmit_status(transmit_status),
604
  .receive_status(receive_status),
605
  .tx_successful(tx_successful),
606
  .need_to_tx(need_to_tx),
607
  .overrun(overrun),
608
  .info_empty(info_empty),
609
  .set_bus_error_irq(set_bus_error_irq),
610
  .set_arbitration_lost_irq(set_arbitration_lost_irq),
611
  .arbitration_lost_capture(arbitration_lost_capture),
612
  .node_error_passive(node_error_passive),
613
  .node_error_active(node_error_active),
614
  .rx_message_counter(rx_message_counter),
615
 
616
  /* This section is for BASIC and EXTENDED mode */
617
  /* Acceptance code register */
618
  .acceptance_code_0(acceptance_code_0),
619
 
620
  /* Acceptance mask register */
621
  .acceptance_mask_0(acceptance_mask_0),
622
  /* End: This section is for BASIC and EXTENDED mode */
623
 
624
  /* This section is for EXTENDED mode */
625
  /* Acceptance code register */
626
  .acceptance_code_1(acceptance_code_1),
627
  .acceptance_code_2(acceptance_code_2),
628
  .acceptance_code_3(acceptance_code_3),
629
 
630
  /* Acceptance mask register */
631
  .acceptance_mask_1(acceptance_mask_1),
632
  .acceptance_mask_2(acceptance_mask_2),
633
  .acceptance_mask_3(acceptance_mask_3),
634
  /* End: This section is for EXTENDED mode */
635
 
636
  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */
637
  .tx_data_0(tx_data_0),
638
  .tx_data_1(tx_data_1),
639
  .tx_data_2(tx_data_2),
640
  .tx_data_3(tx_data_3),
641
  .tx_data_4(tx_data_4),
642
  .tx_data_5(tx_data_5),
643
  .tx_data_6(tx_data_6),
644
  .tx_data_7(tx_data_7),
645
  .tx_data_8(tx_data_8),
646
  .tx_data_9(tx_data_9),
647
  .tx_data_10(tx_data_10),
648
  .tx_data_11(tx_data_11),
649
  .tx_data_12(tx_data_12),
650
  /* End: Tx data registers */
651
 
652
  /* Tx signal */
653
  .tx(tx_out),
654
  .tx_oen(tx_oen)
655
);
656
 
657
assign tx_o = tx_oen? 1'bz : tx_out;
658
 
659
 
660
// Multiplexing wb_dat_o from registers and rx fifo
661
always @ (extended_mode or addr or reset_mode)
662
begin
663
  if (extended_mode & (~reset_mode) & ((addr >= 8'd16) && (addr <= 8'd28)) | (~extended_mode) & ((addr >= 8'd20) && (addr <= 8'd29)))
664
    data_out_fifo_selected <= 1'b1;
665
  else
666
    data_out_fifo_selected <= 1'b0;
667
end
668
 
669
 
670
always @ (posedge clk_i)
671
begin
672
//  if (wb_cyc_i & (~wb_we_i))
673
  if (cs & (~we))
674
    begin
675
      if (data_out_fifo_selected)
676
        data_out <=#Tp data_out_fifo;
677
      else
678
        data_out <=#Tp data_out_regs;
679
    end
680
end
681
 
682
 
683
 
684
`ifdef CAN_WISHBONE_IF
685
  // Combining wb_cyc_i and wb_stb_i signals to cs signal. Than synchronizing to clk_i clock domain. 
686
  always @ (posedge clk_i or posedge rst)
687
  begin
688
    if (rst)
689
      begin
690
        cs_sync1     <= 1'b0;
691
        cs_sync2     <= 1'b0;
692
        cs_sync3     <= 1'b0;
693
        cs_sync_rst1 <= 1'b0;
694
        cs_sync_rst2 <= 1'b0;
695
      end
696
    else
697
      begin
698
        cs_sync1     <=#Tp wb_cyc_i & wb_stb_i & (~cs_sync_rst2) & cs_can_i;
699
        cs_sync2     <=#Tp cs_sync1            & (~cs_sync_rst2);
700
        cs_sync3     <=#Tp cs_sync2            & (~cs_sync_rst2);
701
        cs_sync_rst1 <=#Tp cs_ack3;
702
        cs_sync_rst2 <=#Tp cs_sync_rst1;
703
      end
704
  end
705
 
706
 
707
  assign cs = cs_sync2 & (~cs_sync3);
708
 
709
 
710
  always @ (posedge wb_clk_i)
711
  begin
712
    cs_ack1 <=#Tp cs_sync3;
713
    cs_ack2 <=#Tp cs_ack1;
714
    cs_ack3 <=#Tp cs_ack2;
715
  end
716
 
717
 
718
 
719
  // Generating acknowledge signal
720
  always @ (posedge wb_clk_i)
721
  begin
722
    wb_ack_o <=#Tp (cs_ack2 & (~cs_ack3));
723
  end
724
 
725
 
726
  assign rst      = wb_rst_i;
727
  assign we       = wb_we_i;
728
  assign addr     = wb_adr_i;
729
  assign data_in  = wb_dat_i;
730
  assign wb_dat_o = data_out;
731
 
732
 
733
`else
734
 
735
  // Latching address
736
  always @ (negedge clk_i or posedge rst)
737
  begin
738
    if (rst)
739
      addr_latched <= 8'h0;
740
    else if (ale_i)
741
      addr_latched <=#Tp port_0_io;
742
  end
743
 
744
 
745
  // Generating delayed wr_i and rd_i signals
746
  always @ (posedge clk_i or posedge rst)
747
  begin
748
    if (rst)
749
      begin
750
        wr_i_q <= 1'b0;
751
        rd_i_q <= 1'b0;
752
      end
753
    else
754
      begin
755
        wr_i_q <=#Tp wr_i;
756
        rd_i_q <=#Tp rd_i;
757
      end
758
  end
759
 
760
 
761
  assign cs = ((wr_i & (~wr_i_q)) | (rd_i & (~rd_i_q))) & cs_can_i;
762
 
763
 
764
  assign rst       = rst_i;
765
  assign we        = wr_i;
766
  assign addr      = addr_latched;
767
  assign data_in   = port_0_io;
768
  assign port_0_io = (cs_can_i & rd_i)? data_out : 8'hz;
769
 
770
`endif
771
 
772
endmodule

powered by: WebSVN 2.1.0

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