-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_manager.v
268 lines (253 loc) · 6.52 KB
/
memory_manager.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
`timescale 1ns / 1ps
module memory_manager(
input clk,
input reset,
input [1:0] Floor, //Piso de Solicitud
input [1:0] Request, //Solicitud MSB: Si(1) No(0) LSB: Sube(1) Baja(0)
input [1:0] CurrentFloor, //Piso Actual
input UDIn, //Subiendo o Bajando
input [2:0] FloorRequest, //Solicitud de Piso
input FRDelay, //Se presiono un boton de ir a un piso
input Delay, //Llego a un piso
input NextStageDelay,
input Stop, //Termino ejecucion y se detuvo en el piso
output OCRequest, //Open or Closed Request
output UDRequest, //Up or Down Request
output NoStopRequest,
output DoneDelay,
output DoneFRDelay,
output DoneNextStageDelay,
output [3:0]TestStopsUP,
output [3:0]TestStopsDW
);
localparam NCola = 4;
reg reg_DoneNextStageDelay;
reg reg_DoneDelay;
reg reg_DoneFRDelay;
reg reg_OCRequest;
reg reg_UDRequest;
reg reg_NoStopRequest;
reg [3:0] index;
reg [3:0] Counter; //Contador de Posicion de Memoria
reg [3:0] Stops[1:0]; //Pisos en los que hay que parar subiendo
initial begin
Stops[0] = 0;
Stops[1] = 0;
reg_OCRequest = 0;
reg_UDRequest = 0;
reg_NoStopRequest = 0;
reg_DoneDelay = 0;
reg_DoneFRDelay = 0;
reg_DoneNextStageDelay = 0;
end
always@(posedge clk or posedge reset)begin
if(reset == 1)begin
Stops[0] = 0;
Stops[1] = 0;
reg_OCRequest = 0;
reg_UDRequest = 0;
reg_NoStopRequest = 0;
reg_DoneDelay = 0;
reg_DoneFRDelay = 0;
reg_DoneNextStageDelay = 0;
end
else begin
begin
if(NextStageDelay == 1)//Verifica que ya no está presionando un boton de ir a Piso
reg_DoneNextStageDelay = 0;
end
begin
if(Request[1] == 1)begin//Interrupción Request en Algun Piso
reg_NoStopRequest = 0; //Detiene la maquina
if(Floor == CurrentFloor)begin
reg_OCRequest = 1;
reg_UDRequest = UDIn;
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquin
end
else begin
if(Floor == 0) begin
Stops[0][0] = 1;
if(Stop == 1 && CurrentFloor > 0)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor > 0)
reg_UDRequest = 0;
end
else if(Floor == 1) begin
if(Request[0] == 1)
Stops[1][1] = 1;
else if(Request[0] == 0)
Stops[0][1] = 1;
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquin
if(CurrentFloor > 1)
reg_UDRequest = 0;
else if(CurrentFloor < 1)
reg_UDRequest = 1;
end
else if(Floor == 2)begin
if(Request[0] == 1)
Stops[1][2] = 1;
else if(Request[0] == 0)
Stops[0][2] = 1;
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor > 2)
reg_UDRequest = 0;
else if(CurrentFloor < 2)
reg_UDRequest = 1;
end
else if(Floor == 3)begin
Stops[1][3] = 1;
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor < 3)
reg_UDRequest = 1;
end
end
end//end bloque ifs
end
/*if(Stops[0] == 0 && Stops[1] == 0)begin//No hay mas instrucciones que verificar
reg_NoStopRequest = 0;
end*/
begin
if(Stop == 1)begin//Interrupcion de fin de ejecucion y esta en espera
reg_OCRequest = 0;
if(Stops[1] != 0)begin
reg_UDRequest = 1;
reg_NoStopRequest = 1; //Reunicia la maquina
end
else if(Stops[0] != 0)begin
reg_UDRequest = 0;
reg_NoStopRequest = 1; //Reunicia la maquina
end
end
else
reg_NoStopRequest = 0;
if(Delay == 1)begin//Interrupcion de Abrir o Cerrar Puertas
if(CurrentFloor == 0)begin //Piso 1
if(Stops[0][0] == 1)begin //Hay que parar en este piso
reg_OCRequest = 1;
Stops[0][0] = 0;
reg_DoneDelay = 1;
end
//else
//reg_UDRequest = UDIn;
end
else if(CurrentFloor == 1)begin //Piso 2
if(Stops[reg_UDRequest][1] == 1)begin //Hay que parar en este piso
reg_OCRequest = 1;
Stops[reg_UDRequest][1] = 0;
reg_DoneDelay = 1;
end
else if(Stops[0][1] && Stops[1][2] == 0 && Stops[1][3] == 0)begin
reg_OCRequest = 1;
//Stops[1][1] = 0;
Stops[1][1] = 1;
reg_DoneDelay = 1;
end
else if(Stops[1][1] && Stops[0][0] == 0)begin
reg_OCRequest = 1;
//Stops[0][1] = 0;
Stops[1][1] = 0;
reg_DoneDelay = 1;
end
//else
//reg_UDRequest = UDIn;
end
else if(CurrentFloor == 2)begin //Piso 3
if(Stops[reg_UDRequest][2] == 1)begin//Hay que parar en este piso
reg_OCRequest = 1;
Stops[reg_UDRequest][2] = 0;
reg_DoneDelay = 1;
end
else if(Stops[1][2] == 1 && Stops[1][3] == 0)begin
reg_OCRequest = 1;
//Stops[0][2] = 0;
Stops[1][2] = 0;
reg_DoneDelay = 1;
end
else if(Stops[0][2] == 1 && Stops[0][0] == 0 && Stops[0][1] == 0)begin
reg_OCRequest = 1;
//Stops[1][2] = 0;
Stops[0][2] = 0;
reg_DoneDelay = 1;
end
//else
//reg_UDRequest = UDIn;
end
else if(CurrentFloor == 3)begin //Piso 4
if(Stops[1][3] == 1)begin //Hay que parar en este piso
reg_OCRequest = 1;
Stops[1][3] = 0;
reg_DoneDelay = 1;
end
//else
//reg_UDRequest = UDIn;
end
end//end current floor ifs
end
begin
if(FRDelay == 1)begin//Nuevo Request de Destino de Piso
if(FloorRequest-4'd4 == CurrentFloor)begin
reg_DoneNextStageDelay = 1;
reg_DoneFRDelay = 1;
end
else begin
if(FloorRequest == 4)begin
if(Stop == 1 && CurrentFloor >= 0)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor > 0)begin
Stops[0][0] = 1;
reg_UDRequest = 0;
end
end
else if(FloorRequest == 5)begin
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquin
if(CurrentFloor > 1)begin
Stops[0][1] = 1;
reg_UDRequest = 0;
end
else if(CurrentFloor < 1)begin
Stops[1][1] = 1;
reg_UDRequest = 1;
end
end
else if(FloorRequest == 6)begin
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor > 2)begin
Stops[0][2] = 1;
reg_UDRequest = 0;
end
else if(CurrentFloor < 2)begin
Stops[1][2] = 1;
reg_UDRequest = 1;
end
end
else if(FloorRequest == 7)begin
if(Stop == 1)
reg_NoStopRequest = 1; //Reunicia la maquina
if(CurrentFloor < 3)begin
Stops[1][3] = 1;
reg_UDRequest = 1;
end
end
reg_OCRequest = 0;
reg_DoneNextStageDelay = 1;
reg_DoneFRDelay = 1;
end
end//end bloque ifs
end
end//end else
end//end always
assign DoneNextStageDelay = reg_DoneNextStageDelay;
assign DoneFRDelay = reg_DoneFRDelay;
assign DoneDelay = reg_DoneDelay;
assign UDRequest = reg_UDRequest;
assign OCRequest = reg_OCRequest;
assign NoStopRequest = reg_NoStopRequest;
assign TestStopsUP = Stops[1];
assign TestStopsDW = Stops[0];
endmodule