forked from somhi/jtframe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjtframe_sdram_stats.v
69 lines (59 loc) · 2.13 KB
/
jtframe_sdram_stats.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
57
58
59
60
61
62
63
64
65
66
67
68
69
/* This file is part of JTFRAME.
JTFRAME program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JTFRAME program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JTFRAME. If not, see <http://www.gnu.org/licenses/>.
Author: Jose Tejada Gomez. Twitter: @topapate
Version: 1.0
Date: 20-10-2022 */
// see debug.md for a table describing the st_dout vs st_addr
module jtframe_sdram_stats(
input rst,
input clk,
input [3:0] rdy,
input LVBL,
input [7:0] st_addr,
output reg [7:0] st_dout
);
reg LVBLl;
reg [19:0] acc_blank, acc_active,
req_blank, req_active, req_frame;
reg [ 3:0] rdy_l;
reg count_up;
always @* begin
if( st_addr[5] )
count_up = |(rdy & ~rdy_l);
else
count_up = rdy[ st_addr[1:0]] & ~rdy_l[st_addr[1:0]];
end
always @(posedge clk) begin
LVBLl <= LVBL;
rdy_l <= rdy;
if( count_up && LVBL ) acc_active <= acc_active+1'd1;
if( count_up && !LVBL ) acc_blank <= acc_blank+1'd1;
req_frame <= req_blank + req_active;
if( !LVBL && LVBLl ) begin
req_blank <= (req_blank >>1) + (acc_blank >>1);
req_active <= (req_active>>1) + (acc_active>>1);
acc_blank <= 0;
acc_active <= 0;
end
end
always @(posedge clk) begin
case( { st_addr[4], st_addr[3:2] } )
3'b0_00: st_dout <= req_frame [19:12];
3'b0_01: st_dout <= req_active[19:12];
3'b0_10: st_dout <= req_blank [19:12];
3'b1_00: st_dout <= req_frame [15:8];
3'b1_01: st_dout <= req_active[15:8];
3'b1_10: st_dout <= req_blank [15:8];
default: st_dout <= 0;
endcase
end
endmodule