-
Notifications
You must be signed in to change notification settings - Fork 0
/
brptr.v
57 lines (55 loc) · 1.61 KB
/
brptr.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10:00:00 03/27/2009
// Design Name:
// Module Name: brptr
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module brptr (rptr,rstate,rclk,empty,rst_n,rinc);
parameter size=4;
output [size-1:0] rptr;
output rstate;
input rclk,rst_n,empty,rinc;
reg [size-1:0] rgray;
reg [size:0] rbin5;
wire [size:0] rbnext5;
wire [size-1:0] rgnext,rbnext;
wire [size-1:0] rptr;
reg rstate;
always @ (posedge rclk or negedge rst_n)
begin
if(!rst_n)
begin
rbin5<=0;
rgray<=0;
rgray[size-1:0] <=0;
rstate <=0;
end
else
begin
rbin5<=rbnext5;
rgray<=rgnext;
rstate <= rbnext5[size]; //use the msb of bin as rstate
end
end
//---------------------------------------------------------------
// increment the binary count if not empty
//---------------------------------------------------------------
assign rbnext5 = !empty ? rbin5 + rinc : rbin5;
assign rbnext = rbnext5[size-1:0];
assign rgnext = (rbnext>>1) ^ rbnext; // binary-to-gray conversion
assign rptr[size-1:0] = rgray[size-1:0];//use gray as the address of read data
endmodule