-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_controller.v
119 lines (98 loc) · 2 KB
/
main_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module main_control( input clock, en_com,
input end_receive,
input end_process,
input end_transmit,
input begin_process,
input begin_transmit,
output reg [1:0] status,
output reg g1, g2, g3,
output reg s0, s1, s2, s3);
reg [1:0] p_stat ;
reg [1:0] n_stat ;
parameter
receive = 2'b00,
process = 2'b01,
transmit = 2'b10,
finish = 2'b11;
initial begin
p_stat <= receive;
n_stat <= receive;
end
always @(posedge clock)
begin
if (begin_process)
g1 <= 1'b1;
if (begin_transmit)
g2 <= 1'b1;
if (end_receive)
g3 <= 1'b1;
end
initial begin
g1 <= 1'b0;
g2 <= 1'b0;
g3 <= 1'b0;
s0 <= 1'b0;
s1 <= 1'b0;
s2 <= 1'b0;
s3 <= 1'b0;
//tx_en <= 1'b0;
end
always @(posedge clock)
p_stat <= n_stat;
always @(end_receive or end_process or end_transmit or begin_process or begin_transmit or p_stat or en_com)
case (p_stat)
receive: begin
status <= 2'b00;
s0 <= 1'b1;
s1 <= 1'b0;
s2 <= 1'b0;
s3 <= 1'b0;
if (!end_process && !end_transmit && begin_process)
n_stat <= process; //testing
else
n_stat <= receive;
end
process: begin
status <= 2'b01;
s0 <= 1'b1;
s1 <= 1'b1;
s2 <= 1'b0;
s3 <= 1'b0;
//tx_en <= 1'b0;
if (end_receive && end_process && !end_transmit)
n_stat <= finish;
else
n_stat <= process;
end
transmit: begin
status <= 2'b10;
s0 <= 1'b1;
s1 <= 1'b1;
s2 <= 1'b1;
s3 <= 1'b0;
//tx_en <= 1'b1;
if (end_receive && end_transmit) //&& end_process
n_stat <= finish;
else
n_stat <= transmit;
end
finish: begin
status <= 2'b11;
s0 <= 1'b1;
s1 <= 1'b1;
s2 <= 1'b1;
s3 <= 1'b1;
//tx_en <= 1'b0;
n_stat <= finish;
end
default: begin
status <= 2'b00;
s0 <= 1'b1;
s1 <= 1'b0;
s2 <= 1'b0;
s3 <= 1'b0;
//tx_en <= 1'b0;
n_stat <= receive;
end
endcase
endmodule