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 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 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
module versatile_fifo_async_cmp ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
44
 
45
   parameter ADDR_WIDTH = 4;
46
   parameter N = ADDR_WIDTH-1;
47
 
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
   output reg   fifo_empty;
58
   output       fifo_full;
59
   input        wclk, rclk, rst;
60
 
61
`ifndef GENERATE_DIRECTION_AS_LATCH
62
   wire direction;
63
`endif
64
`ifdef GENERATE_DIRECTION_AS_LATCH
65
   reg direction;
66
`endif
67
   reg  direction_set, direction_clr;
68
 
69
   wire async_empty, async_full;
70
   wire fifo_full2;
71
   reg  fifo_empty2;
72
 
73
   // direction_set
74
   always @ (wptr[N:N-1] or rptr[N:N-1])
75
     case ({wptr[N:N-1],rptr[N:N-1]})
76
       {Q1,Q2} : direction_set <= 1'b1;
77
       {Q2,Q3} : direction_set <= 1'b1;
78
       {Q3,Q4} : direction_set <= 1'b1;
79
       {Q4,Q1} : direction_set <= 1'b1;
80
       default : direction_set <= 1'b0;
81
     endcase
82
 
83
   // direction_clear
84
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
85
     if (rst)
86
       direction_clr <= 1'b1;
87
     else
88
       case ({wptr[N:N-1],rptr[N:N-1]})
89
         {Q2,Q1} : direction_clr <= 1'b1;
90
         {Q3,Q2} : direction_clr <= 1'b1;
91
         {Q4,Q3} : direction_clr <= 1'b1;
92
         {Q1,Q4} : direction_clr <= 1'b1;
93
         default : direction_clr <= 1'b0;
94
       endcase
95
 
96
`ifndef GENERATE_DIRECTION_AS_LATCH
97
    dff_sr dff_sr_dir( .aclr(direction_clr), .aset(direction_set), .clock(1'b1), .data(1'b1), .q(direction));
98
`endif
99
 
100
`ifdef GENERATE_DIRECTION_AS_LATCH
101
   always @ (posedge direction_set or posedge direction_clr)
102
     if (direction_clr)
103
       direction <= going_empty;
104
     else
105
       direction <= going_full;
106
`endif
107
 
108
   assign async_empty = (wptr == rptr) && (direction==going_empty);
109
   assign async_full  = (wptr == rptr) && (direction==going_full);
110
 
111
    dff_sr dff_sr_empty0( .aclr(rst), .aset(async_full), .clock(wclk), .data(async_full), .q(fifo_full2));
112
    dff_sr dff_sr_empty1( .aclr(rst), .aset(async_full), .clock(wclk), .data(fifo_full2), .q(fifo_full));
113
 
114
/*
115
   always @ (posedge wclk or posedge rst or posedge async_full)
116
     if (rst)
117
       {fifo_full, fifo_full2} <= 2'b00;
118
     else if (async_full)
119
       {fifo_full, fifo_full2} <= 2'b11;
120
     else
121
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
122
*/
123
   always @ (posedge rclk or posedge async_empty)
124
     if (async_empty)
125
       {fifo_empty, fifo_empty2} <= 2'b11;
126
     else
127
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty};
128
 
129
endmodule // async_comp

powered by: WebSVN 2.1.0

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