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 21

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