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

Subversion Repositories can

[/] [can/] [tags/] [rel_7/] [rtl/] [verilog/] [can_top.v] - Blame information for rev 66

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

powered by: WebSVN 2.1.0

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