-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacheControl.sv.bak
108 lines (104 loc) · 2.34 KB
/
cacheControl.sv.bak
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module cacheControl(clk, rst_n, rdy, dCache_or_iCache, write_or_read, Ihit, Dhit, Ddirty, dataSetDirty, Irdy, Drdy, currState);
input clk, rst_n;
input dCache_or_iCache, write_or_read, rdy; // read and write enable
input Ihit, Dhit, Ddirty; //specify if hit/miss in instruction and data cache respectively
output reg dataSetDirty; //only write to data cache so only need a dirty signal from data cache
output reg Irdy, Drdy; //I cach and D cache ready signal.
output reg [1:0] currState;
typedef enum reg [1:0] {CACHEACCESS, WRITEBACK, READ_MISS, WRITE_MISS} state_t;
state_t state, nxt_state;
always_ff @(posedge clk, negedge rst_n) begin
if(!rst_n)
state <= CACHEACCESS;
else
state <= nxt_state;
end
always_comb begin
Irdy = 0;
Drdy = 0;
dataSetDirty = 0;
//nxt_state = CACHEACCESS;
currState = nxt_state;
case(state)
CACHEACCESS: begin
if(dCache_or_iCache) begin
if(Dhit) begin
dataSetDirty = 1;
nxt_state = CACHEACCESS;
end
else if (!Dhit && Ddirty) begin
nxt_state = WRITEBACK;
Drdy = 1;
Irdy = 1;
end
else if(write_or_read && !Dhit && !Ddirty) begin
nxt_state = WRITE_MISS;
Drdy = 1;
Irdy = 1;
end
else if (!write_or_read && !Dhit && !Ddirty) begin
nxt_state = READ_MISS;
Drdy = 1;
Irdy = 1;
end
else
nxt_state = CACHEACCESS;
end
else begin
if(Ihit) begin
nxt_state = CACHEACCESS;
end
else begin
nxt_state = READ_MISS;
Drdy = 1;
Irdy = 1;
end
end
end
WRITE_MISS: begin
Irdy = 1;
Drdy = 1;
if(rdy) begin
dataSetDirty = 1;
nxt_state = CACHEACCESS;
end
else
nxt_state = WRITE_MISS;
end
WRITEBACK: begin
Drdy = 1;
Irdy = 1;
if(rdy) begin
if(write_or_read)
nxt_state = WRITE_MISS;
else
nxt_state = READ_MISS;
end
else
nxt_state = WRITEBACK;
end
READ_MISS: begin
Drdy = 1;
Irdy = 1;
if(rdy) begin
if(dCache_or_iCache) begin
dataSetDirty = 1;
nxt_state = CACHEACCESS;
end
else begin
nxt_state = CACHEACCESS;
end
end
else
nxt_state = READ_MISS;
end
default: begin
Drdy = 0;
Irdy = 0;
dataSetDirty = 0;
nxt_state = CACHEACCESS;
currState = state;
end
endcase
end
endmodule