-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.v
More file actions
184 lines (159 loc) · 3.59 KB
/
controller.v
File metadata and controls
184 lines (159 loc) · 3.59 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Project: Bubble Sort
// Module Name:Controller for Sort
//////////////////////////////////////////////////////////////////////////////////
module controller(c_clk,c_rst,c_go,c_c_ld,c_c_clr,c_d_ld,c_d_clr,c_t1_ld,c_t2_ld,c_sel_add,c_sel_data,c_c_lt_n_1,c_d_lt_n_1_c,c_t1_gt_t2, c_re, c_we,c_i_clr,c_i_ld,c_done,c_i_lt_n_1);
input c_clk,c_rst,c_go,c_c_lt_n_1,c_d_lt_n_1_c,c_t1_gt_t2,c_i_lt_n_1;
output reg c_c_ld,c_c_clr,c_d_ld,c_d_clr,c_t1_ld,c_t2_ld,c_sel_add,c_sel_data,c_re,c_we,c_i_clr,c_i_ld,c_done;
//output reg [3:0] c_state;
reg [3:0] state, nstate;
parameter [3:0] s_wait = 0, init_c = 1, check_c = 2, init_d = 3, check_d = 4, read_t1 = 5, read_t2 = 6, check_t1_t2 = 7, write_t1 = 8, write_t2 = 9, inc_d = 10, inc_c = 11, check_i = 12, read_sorted = 13, inc_i = 14;
always@(state, c_go, c_c_lt_n_1, c_d_lt_n_1_c, c_t1_gt_t2, c_i_lt_n_1) begin
c_c_ld <= 0;
c_c_clr <= 0;
c_d_ld <= 0;
c_d_clr <= 0;
c_t1_ld <= 0;
c_t2_ld <= 0;
c_sel_add <= 0;
c_sel_data <= 0;
c_we <= 0;
c_i_clr <= 0;
c_i_ld <= 0;
//c_state <= 0;
case(state)
s_wait: begin
c_done <= 0;
//c_state <= 0;
c_re <= 0;
if (c_go == 0 )
nstate <= s_wait;
else
nstate <= init_c;
end
init_c: begin
//c_state <= 1;
c_c_clr <= 1;
c_c_ld <= 0;
c_d_clr <= 0;
c_d_ld <= 0;
c_i_clr <= 1;
c_i_ld <= 0;
c_re <= 0;
nstate <= check_c;
end
check_c: begin
//c_state <= 2;
c_c_clr <= 0;
c_c_ld <= 0;
if (c_c_lt_n_1 == 1)
nstate <= init_d;
else
nstate <= check_i;
end
init_d: begin
//c_state <= 3;
c_d_clr <= 1;
nstate <= check_d;
end
check_d: begin
//c_state <= 4;
c_d_clr <= 0;
c_d_ld <= 0;
if (c_d_lt_n_1_c == 1)
nstate <= read_t1;
else
nstate <= inc_c;
end
read_t1: begin
//c_state <= 5;
c_t1_ld <= 1;
c_sel_add <= 0;
c_done <= 0;
c_re <= 1;
nstate <= read_t2;
end
read_t2: begin
//c_state <= 6;
c_t1_ld <= 0;
c_t2_ld <= 1;
c_sel_add <= 1;
c_done <= 0;
c_re <= 1;
nstate <= check_t1_t2;
end
check_t1_t2: begin
//c_state <= 7;
c_t2_ld <= 0;
c_re <= 0;
if (c_t1_gt_t2 == 1)
nstate <= write_t1;
else
nstate <= inc_d;
end
write_t1: begin
//c_state <= 8;
c_we <= 1;
c_sel_add <= 1;
c_sel_data <= 0;
c_done <= 0;
nstate <= write_t2;
end
write_t2: begin
//c_state <= 9;
c_we <= 1;
c_sel_add <= 0;
c_sel_data <= 1;
c_done <= 0;
nstate <= inc_d;
end
inc_d: begin
//c_state <= 10;
c_d_ld <= 1;
c_we <= 0;
c_re <= 0;
nstate <= check_d;
end
inc_c: begin
//c_state <= 11;
c_c_ld <= 1;
nstate <= check_c;
end
check_i: begin
//c_state <= 12;
c_i_clr <= 0;
c_i_ld <= 0;
c_done <= 1;
if (c_i_lt_n_1 == 1)
nstate <= read_sorted;
else
nstate <= s_wait;
end
read_sorted: begin
//c_state <= 13;
c_re <= 1;
c_done <= 1;
nstate <= inc_i;
end
inc_i: begin
//c_state <= 14;
c_done <= 1;
c_i_ld <= 1;
nstate <= check_i;
end
default: begin
nstate <= s_wait;
end
endcase
end
// register process
always@(posedge c_clk) begin
if (c_rst==1) begin
state <= s_wait;
end
else begin
state <= nstate;
end
end
endmodule