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

Subversion Repositories can

[/] [can/] [tags/] [rel_6/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 67

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

powered by: WebSVN 2.1.0

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