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

Subversion Repositories versatile_fifo

[/] [versatile_fifo/] [trunk/] [rtl/] [verilog/] [versatile_fifo_async_cmp.v] - Blame information for rev 25

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

Line No. Rev Author Line
1 21 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Versatile counter                                           ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
7
////  counter                                                     ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   - add LFSR with more taps                                  ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43 5 unneback
module versatile_fifo_async_cmp ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
44
 
45 7 unneback
   parameter ADDR_WIDTH = 4;
46 6 unneback
   parameter N = ADDR_WIDTH-1;
47 5 unneback
 
48
   parameter Q1 = 2'b00;
49
   parameter Q2 = 2'b01;
50
   parameter Q3 = 2'b11;
51
   parameter Q4 = 2'b10;
52
 
53
   parameter going_empty = 1'b0;
54
   parameter going_full  = 1'b1;
55
 
56
   input [N:0]  wptr, rptr;
57 21 unneback
   output reg   fifo_empty;
58
   output       fifo_full;
59 5 unneback
   input        wclk, rclk, rst;
60
 
61 25 unneback
   wire direction;
62
   reg  direction_set, direction_clr;
63 5 unneback
 
64
   wire async_empty, async_full;
65 21 unneback
   wire fifo_full2;
66
   reg  fifo_empty2;
67 5 unneback
 
68
   // direction_set
69
   always @ (wptr[N:N-1] or rptr[N:N-1])
70
     case ({wptr[N:N-1],rptr[N:N-1]})
71
       {Q1,Q2} : direction_set <= 1'b1;
72
       {Q2,Q3} : direction_set <= 1'b1;
73
       {Q3,Q4} : direction_set <= 1'b1;
74
       {Q4,Q1} : direction_set <= 1'b1;
75
       default : direction_set <= 1'b0;
76
     endcase
77
 
78
   // direction_clear
79
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
80
     if (rst)
81
       direction_clr <= 1'b1;
82
     else
83
       case ({wptr[N:N-1],rptr[N:N-1]})
84
         {Q2,Q1} : direction_clr <= 1'b1;
85
         {Q3,Q2} : direction_clr <= 1'b1;
86
         {Q4,Q3} : direction_clr <= 1'b1;
87
         {Q1,Q4} : direction_clr <= 1'b1;
88
         default : direction_clr <= 1'b0;
89
       endcase
90 21 unneback
 
91
`ifndef GENERATE_DIRECTION_AS_LATCH
92
    dff_sr dff_sr_dir( .aclr(direction_clr), .aset(direction_set), .clock(1'b1), .data(1'b1), .q(direction));
93
`endif
94
 
95
`ifdef GENERATE_DIRECTION_AS_LATCH
96 5 unneback
   always @ (posedge direction_set or posedge direction_clr)
97
     if (direction_clr)
98
       direction <= going_empty;
99
     else
100
       direction <= going_full;
101 21 unneback
`endif
102 5 unneback
 
103
   assign async_empty = (wptr == rptr) && (direction==going_empty);
104
   assign async_full  = (wptr == rptr) && (direction==going_full);
105
 
106 21 unneback
    dff_sr dff_sr_empty0( .aclr(rst), .aset(async_full), .clock(wclk), .data(async_full), .q(fifo_full2));
107
    dff_sr dff_sr_empty1( .aclr(rst), .aset(async_full), .clock(wclk), .data(fifo_full2), .q(fifo_full));
108
 
109
/*
110 5 unneback
   always @ (posedge wclk or posedge rst or posedge async_full)
111
     if (rst)
112
       {fifo_full, fifo_full2} <= 2'b00;
113
     else if (async_full)
114
       {fifo_full, fifo_full2} <= 2'b11;
115
     else
116
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
117 21 unneback
*/
118 5 unneback
   always @ (posedge rclk or posedge async_empty)
119
     if (async_empty)
120
       {fifo_empty, fifo_empty2} <= 2'b11;
121
     else
122
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty};
123 21 unneback
 
124 5 unneback
endmodule // async_comp

powered by: WebSVN 2.1.0

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