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 12

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

Line No. Rev Author Line
1 5 unneback
module versatile_fifo_async_cmp ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
2
 
3 7 unneback
   parameter ADDR_WIDTH = 4;
4 6 unneback
   parameter N = ADDR_WIDTH-1;
5 5 unneback
 
6
   parameter Q1 = 2'b00;
7
   parameter Q2 = 2'b01;
8
   parameter Q3 = 2'b11;
9
   parameter Q4 = 2'b10;
10
 
11
   parameter going_empty = 1'b0;
12
   parameter going_full  = 1'b1;
13
 
14
   input [N:0]  wptr, rptr;
15
   output reg   fifo_empty, fifo_full;
16
   input        wclk, rclk, rst;
17
 
18
   reg  direction, direction_set, direction_clr;
19
 
20
   wire async_empty, async_full;
21
   reg  fifo_full2, fifo_empty2;
22
 
23
   // direction_set
24
   always @ (wptr[N:N-1] or rptr[N:N-1])
25
     case ({wptr[N:N-1],rptr[N:N-1]})
26
       {Q1,Q2} : direction_set <= 1'b1;
27
       {Q2,Q3} : direction_set <= 1'b1;
28
       {Q3,Q4} : direction_set <= 1'b1;
29
       {Q4,Q1} : direction_set <= 1'b1;
30
       default : direction_set <= 1'b0;
31
     endcase
32
 
33
   // direction_clear
34
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
35
     if (rst)
36
       direction_clr <= 1'b1;
37
     else
38
       case ({wptr[N:N-1],rptr[N:N-1]})
39
         {Q2,Q1} : direction_clr <= 1'b1;
40
         {Q3,Q2} : direction_clr <= 1'b1;
41
         {Q4,Q3} : direction_clr <= 1'b1;
42
         {Q1,Q4} : direction_clr <= 1'b1;
43
         default : direction_clr <= 1'b0;
44
       endcase
45
 
46
   always @ (posedge direction_set or posedge direction_clr)
47
     if (direction_clr)
48
       direction <= going_empty;
49
     else
50
       direction <= going_full;
51
 
52
   assign async_empty = (wptr == rptr) && (direction==going_empty);
53
   assign async_full  = (wptr == rptr) && (direction==going_full);
54
 
55
   always @ (posedge wclk or posedge rst or posedge async_full)
56
     if (rst)
57
       {fifo_full, fifo_full2} <= 2'b00;
58
     else if (async_full)
59
       {fifo_full, fifo_full2} <= 2'b11;
60
     else
61
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
62
 
63
   always @ (posedge rclk or posedge async_empty)
64
     if (async_empty)
65
       {fifo_empty, fifo_empty2} <= 2'b11;
66
     else
67
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty};
68
 
69
endmodule // async_comp

powered by: WebSVN 2.1.0

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