-
Notifications
You must be signed in to change notification settings - Fork 1
/
FSM_MSI_CPU_requests_controller.v
97 lines (94 loc) · 2.58 KB
/
FSM_MSI_CPU_requests_controller.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
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
module FSM_MSI_CPU_requests_controller(
input [1:0] state_in,
input cpu_write_hit, cpu_read_hit,
input cpu_write_miss, cpu_read_miss,
output reg write_back_block_next,//used in implementation
output reg [1:0] state_next,bus_next
);
//States parameters, for state_in and state_out, simplificam a vida:
parameter INVALID=2'b00, MODIFIED=2'b01, SHARED=2'b10;
//Bus parameters, to go out for bus:
parameter BUS_INVALIDATE=2'b00, BUS_WRITE_MISS=2'b01, BUS_READ_MISS=2'b10;
wire cpu_write = cpu_write_hit | cpu_write_miss;//whenever a write
wire cpu_read = cpu_read_hit | cpu_read_miss;
initial begin
state_next <= INVALID;
bus_next <= 2'b0;
write_back_block_next <= 0;
end
always@(*)begin
case(state_in)
INVALID:begin
case({cpu_write,cpu_read})
2'b01: begin
state_next <= SHARED;
bus_next <= BUS_READ_MISS;
write_back_block_next <= 0;
end
2'b10: begin
state_next <= MODIFIED;
bus_next <= BUS_WRITE_MISS;
write_back_block_next <= 0;
end
default:begin
state_next <= 2'b11;//error code
bus_next <= 2'b11;
write_back_block_next <= 0;
$display("Error: no cpu should write and read at the once");
end
endcase
end
MODIFIED:begin
case({cpu_write_hit,cpu_read_hit,cpu_write_miss,cpu_read_miss})
4'b0001:begin
state_next <= SHARED;
bus_next <= BUS_READ_MISS;
write_back_block_next <= 1;
end
4'b0010:begin
state_next <= MODIFIED;
bus_next <= BUS_WRITE_MISS;
write_back_block_next <=1;
end
4'b0100,4'b1000:begin
state_next <= MODIFIED;
write_back_block_next <= 0;
end
default:begin
state_next <= 2'b11;//error code
bus_next <= 2'b11;
write_back_block_next <= 0;
end
endcase
end
SHARED:begin
case({cpu_write_hit,cpu_read_hit,cpu_write_miss,cpu_read_miss})
4'b0001:begin
state_next <= SHARED;
bus_next <= BUS_READ_MISS;
write_back_block_next <= 0;
end
4'b0010:begin
state_next <= MODIFIED;
bus_next <= BUS_WRITE_MISS;
write_back_block_next <= 0;
end
4'b0100:begin
state_next <= SHARED;
write_back_block_next <= 0;
end
4'b1000:begin
state_next <= MODIFIED;
bus_next <= BUS_INVALIDATE;
write_back_block_next <= 0;
end
default:begin
state_next <= 2'b11;//error code
bus_next <= 2'b11;
write_back_block_next <= 0;
end
endcase
end
endcase
end
endmodule