OpenCores
URL https://opencores.org/ocsvn/raytrac/raytrac/trunk

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [sm.vhd] - Blame information for rev 226

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 134 jguarin200
--! @file sm.vhd
2 158 jguarin200
--! @brief Maquina de Estados. Controla la operación interna y genera los mecanismos de sincronización con el exterior (interrupciones). 
3 134 jguarin200
--! @author Julián Andrés Guarín Reyes
4
--------------------------------------------------------------
5
-- RAYTRAC
6
-- Author Julian Andres Guarin
7
-- sm.vhd
8
-- This file is part of raytrac.
9
-- 
10
--     raytrac is free software: you can redistribute it and/or modify
11
--     it under the terms of the GNU General Public License as published by
12
--     the Free Software Foundation, either version 3 of the License, or
13
--     (at your option) any later version.
14
-- 
15
--     raytrac is distributed in the hope that it will be useful,
16
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
17
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
--     GNU General Public License for more details.
19
-- 
20
--     You should have received a copy of the GNU General Public License
21
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26 139 jguarin200
use ieee.std_logic_unsigned.all;
27 134 jguarin200
 
28 151 jguarin200
use work.arithpack.all;
29 134 jguarin200
 
30
entity sm is
31
        port (
32
 
33 145 jguarin200
                --! Se&ntilde;ales normales de secuencia.
34
                clk,rst:                        in std_logic;
35 158 jguarin200
                --! Vector con las instrucci&oacute;n codficada
36 152 jguarin200
                instrQq:in std_logic_vector(floatwidth-1 downto 0);
37 158 jguarin200
                --! Se&ntilde;al de cola vacia.
38 145 jguarin200
                instrQ_empty:in std_logic;
39 142 jguarin200
 
40 145 jguarin200
 
41
                adda,addb:out std_logic_vector (widthadmemblock-1 downto 0);
42
                sync_chain_0,instrRdAckd:out std_logic;
43 142 jguarin200
 
44 147 jguarin200
 
45 145 jguarin200
                full_r:         in std_logic;   --! Indica que la cola de resultados no puede aceptar mas de 32 elementos.
46
 
47 142 jguarin200
 
48 150 jguarin200
                --! End Of Instruction Event
49
                eoi     : out std_logic;
50 142 jguarin200
 
51 151 jguarin200
                --! State Exposed for testbench purposes.
52
                state : out macState;
53
 
54 142 jguarin200
                --! DataPath Control uca code.
55 145 jguarin200
                dpc_uca : out std_logic_vector (2 downto 0)
56 142 jguarin200
 
57
 
58 134 jguarin200
        );
59
end entity;
60 139 jguarin200
 
61
architecture sm_arch of sm is
62
 
63 151 jguarin200
 
64 158 jguarin200
        --! LOAD_INSTRUCTION: Estado en el que se espera que en la cola de instrucciones haya una instrucci&oacute;n para ejecutar.
65 145 jguarin200
        --! EXECUTE_INSTRUCTION: Estado en el que se ejecuta la instrucci&oacute;n de la cola de instrucciones.
66 158 jguarin200
        --! FLUSH_ARITH_PIPELINE: Estado en el que se espera un n&uacute;mero espec&iacute;fico de ciclos de reloj, para que se desocupe el pipeline aritm&eacute;tico.
67 145 jguarin200
 
68 161 jguarin200
        --!TBXSTART:STATE
69 151 jguarin200
        signal s_state : macState;
70 161 jguarin200
        --!TBXEND
71 139 jguarin200
 
72
 
73 161 jguarin200
        --!TBXSTART:INS_BLKS     
74
        signal s_dpc_uca                :       std_logic_vector(2 downto 0);
75
        signal s_instr_uca              :       std_logic_vector(2 downto 0);
76
        signal s_block_start_a  :       std_logic_vector(4 downto 0);
77
        signal s_block_start_b  :       std_logic_vector(4 downto 0);
78
        signal s_block_end_a    :       std_logic_vector(4 downto 0);
79
        signal s_block_end_b    :       std_logic_vector(4 downto 0);
80
        signal s_combinatory    :       std_logic;
81
        signal s_delay_field    :       std_logic_vector(7 downto 0);
82
        --!TBXEND
83 151 jguarin200
 
84 162 jguarin200
        --!TBXSTART:CNT_SIGNLS
85
        signal s_set_b                  :       std_logic;                                              --! Se&ntilde;al para colocar un valor arbitrario en el contador B.
86
        signal s_set_a                  :       std_logic;
87
        signal s_set_dly                :       std_logic;
88
        signal s_go_b                   :       std_logic;                                              --! Salida para controlar la pausa(0) o marcha(1) del contador de direcciones del operando B/D.
89
        signal s_go_a                   :       std_logic;                                              --! Salida para controlar la pausa(0) o marcha(1) del contador de direcciones del operando A/C. 
90
        signal s_go_delay               :       std_logic;                                              --! Salida para controlar la pausa(0) o marcha(1) del contador de delay, para el flush del pipeline aritm&eacute;tico.
91
        signal s_zeroFlag_delay :       std_logic;                                              --! Bandera de cero del contador delay. 
92
        signal s_eq_b,s_eq_a    :       std_logic;      --! Indica cuando se est&aacute; leyendo el &uacute;ltimo bloque de memoria con operandos de entrada de a y de b respectivamente. 
93
        signal s_eb_b,s_eb_a    :       std_logic;      --! Indica que se est&aacute; leyendo en memoria el &uacute;ltimo operando del bloque actual, b o a, respectivamente.
94 161 jguarin200
        --!TBXEND               
95 134 jguarin200
begin
96 151 jguarin200
 
97
        state <= s_state;
98
 
99 158 jguarin200
        --! C&oacute;digo UCA, pero en la etapa DPC: La diferencia es que UCA en la etapa DPC, decodifica el datapath dentro del pipeline aritm&eacute;tico.
100 145 jguarin200
        dpc_uca <= s_dpc_uca;
101 142 jguarin200
 
102 145 jguarin200
 
103 161 jguarin200
        --! Bloques asignados en la instrucci&oacute;n
104 152 jguarin200
        s_block_start_a <= instrQq(floatwidth-4 downto floatwidth-8);
105
        s_block_end_a <= instrQq(floatwidth-9 downto floatwidth-13);
106 139 jguarin200
 
107 152 jguarin200
        s_block_start_b <= instrQq(floatwidth-14 downto floatwidth-18);
108
        s_block_end_b <= instrQq(floatwidth-19 downto floatwidth-23);
109 145 jguarin200
 
110 158 jguarin200
        --! Campo que define si la instrucci&oacute;n es combinatoria
111 152 jguarin200
        s_combinatory <= instrQq(floatwidth-24);
112 145 jguarin200
 
113 158 jguarin200
        --! Campo que define cuantos clocks debe esperar el sistema, despues de que se ejecuta una instrucci&oacute;n, para que el pipeline aritm&eacute;tico quede vacio.
114 152 jguarin200
        s_delay_field <= instrQq(floatwidth-25 downto floatwidth-32);
115 145 jguarin200
 
116 158 jguarin200
        --! UCA code, c&oacute;digo con la instrucci&oacute;n a ejecutar. 
117 145 jguarin200
        s_instr_uca <= instrQq(31 downto 29);
118
 
119 142 jguarin200
        --! Address Counters
120 152 jguarin200
        --!TBXINSTANCESTART
121 142 jguarin200
        counterA:customCounter
122 152 jguarin200
        generic map (
123
                EOBFLAG => "YES",
124
                ZEROFLAG => "NO",
125
                BACKWARDS => "NO",
126
                EQUALFLAG => "YES",
127
                subwidth => 4,
128
                width => 9
129
        )
130
        port map (
131
                clk => clk,
132
                rst => rst,
133
                go => s_go_a,
134
                set => s_set_a,
135
                setValue => s_block_start_a,
136
                cmpBlockValue => s_block_end_a,
137
                zero_flag => open,
138
                eob_flag => s_eb_a,
139
                eq_flag => s_eq_a,
140
                count => adda
141
        );
142
        --!TBXINSTANCEEND
143
        --!TBXINSTANCESTART
144 142 jguarin200
        counterB:customCounter
145 152 jguarin200
        generic map (
146
                EOBFLAG => "YES",
147
                ZEROFLAG => "NO",
148
                BACKWARDS => "NO",
149
                EQUALFLAG => "YES",
150
                subwidth => 4,
151
                width => 9
152
        )
153
        port map (
154
                clk => clk,
155
                rst => rst,
156
                go => s_go_b,
157
                set => s_set_b,
158
                setValue => s_block_start_b,
159
                cmpBlockValue => s_block_end_b,
160
                zero_flag => open,
161
                eob_flag => s_eb_b,
162
                eq_flag => s_eq_b,
163
                count => addb
164
        );
165
        --!TBXINSTANCEEND
166
        --!TBXINSTANCESTART
167 145 jguarin200
        counterDly:customCounter
168 152 jguarin200
        generic map(
169
                EOBFLAG => "NO",
170
                ZEROFLAG => "YES",
171 153 jguarin200
                BACKWARDS => "YES",
172 152 jguarin200
                EQUALFLAG => "NO",
173
                width =>   5,
174
                subwidth => 0
175
 
176
        )
177
        port map (
178
                clk => clk,
179
                rst => rst,
180
                go => s_go_delay,
181
                set => s_set_dly,
182
                setValue => s_delay_field(4 downto 0),
183
                cmpBlockValue => "00000",
184
                zero_flag => s_zeroFlag_delay,
185
                eob_flag => open,
186
                eq_flag => open,
187
                count => open
188
        );
189
        --!TBXINSTANCEEND
190 139 jguarin200
 
191 145 jguarin200
        sm_comb:
192 151 jguarin200
        process (s_state, full_r,s_eb_b,s_combinatory,s_zeroFlag_delay,s_eq_b,s_eb_a,s_eq_a,instrQ_empty)
193 145 jguarin200
        begin
194
                --!Se&ntilde;al de play/pause del contador de direcciones para el par&aacute;metro B/D.
195
                s_go_b <= not(full_r and s_eb_b);
196 139 jguarin200
 
197 145 jguarin200
                --!Se&ntilde;al de play/pause del contador de direcciones para el par&aacute;metro A/C.
198
                if s_combinatory='0' then
199
                        s_go_a <= not(full_r and s_eb_b);
200
 
201
                else
202
                        s_go_a <= not(full_r) and s_eb_b and s_eq_b;
203
                end if;
204
 
205
                --!Se&ntilde;al de play/pause del contador del arithmetic pipeline flush counter.
206
                s_go_delay  <= not(s_zeroFlag_delay);
207
 
208 158 jguarin200
                --! Si estamos en el final de la instrucci&oacute;n, "descargamos" esta de la m&aacute;quina de estados con acknowledge read.
209 151 jguarin200
                if s_eb_b='1' and s_eq_b='1' and s_eb_a='1' and s_eq_a='1' and s_state=EXECUTE_INSTRUCTION then
210 145 jguarin200
                        instrRdAckd <= '1';
211
                else
212
                        instrRdAckd <= '0';
213
                end if;
214
 
215 151 jguarin200
                if (s_eb_a='1' and s_eq_a='1') or s_state=LOAD_INSTRUCTION or s_state=FLUSH_ARITH_PIPELINE then
216 145 jguarin200
                        s_set_a <= '1';
217
                else
218
                        s_set_a <= '0';
219
                end if;
220
 
221
 
222
 
223 151 jguarin200
                if (s_eb_b='1' and s_eq_b='1') or s_state=LOAD_INSTRUCTION or s_state=FLUSH_ARITH_PIPELINE then
224 145 jguarin200
                        s_set_b <= '1';
225
                else
226
                        s_set_b <= '0';
227
                end if;
228
 
229
        end process;
230
 
231 139 jguarin200
        sm_proc:
232 151 jguarin200
        process (clk,rst,s_state, full_r,s_eb_b,s_combinatory,s_zeroFlag_delay,s_eq_b,s_eb_a,s_eq_a,instrQ_empty)
233 139 jguarin200
        begin
234 145 jguarin200
 
235 139 jguarin200
                if rst=rstMasterValue then
236 145 jguarin200
 
237 151 jguarin200
                        s_state <= LOAD_INSTRUCTION;
238 145 jguarin200
                        s_set_dly <= '1';
239
                        sync_chain_0 <= '0';
240 150 jguarin200
                        eoi<='0';
241 145 jguarin200
                        s_dpc_uca <= (others => '0');
242
 
243
 
244 142 jguarin200
                elsif clk='1' and clk'event then
245 139 jguarin200
 
246 151 jguarin200
                        case s_state is
247 142 jguarin200
 
248 158 jguarin200
                                --! Cargar la siguiente instrucci&oacute;n. 
249 145 jguarin200
                                when LOAD_INSTRUCTION =>
250
 
251 150 jguarin200
                                        eoi <= '0';
252
 
253 145 jguarin200
                                        if instrQ_empty='0' and full_r='0' then
254 139 jguarin200
 
255 158 jguarin200
                                                --! Siguiente estado: Ejecutar la instrucci&oacute;n.  
256 151 jguarin200
                                                s_state <= EXECUTE_INSTRUCTION;
257 145 jguarin200
 
258 158 jguarin200
                                                --! Asignar el c&oacute;digo UCA para que comience la decodificaci&oacute;n.
259 145 jguarin200
                                                s_dpc_uca <= s_instr_uca;
260
 
261 158 jguarin200
                                                --! Validar el siguiente dato dentro del pipeline aritm&eacute;tico.
262 145 jguarin200
                                                sync_chain_0 <= '1';
263
 
264
                                                --! En el estado EXECUTE, el valor del contador de delay se debe mantener fijo, y puesto en el valor de delay que contiene la instruccion.
265
                                                s_set_dly <= '1';
266
 
267
 
268
 
269
                                        end if;
270
 
271 158 jguarin200
                                --! Ejecuci&oacute;n de la instruccion          
272 145 jguarin200
                                when EXECUTE_INSTRUCTION =>
273
 
274
 
275
                                        if s_eb_b='1'and s_eq_b='1' and s_eb_a='1' and s_eq_a='1' then  --! Revisar si es el fin de la instruccion
276
 
277 150 jguarin200
 
278 158 jguarin200
                                                --!Ya no ingresaran mas datos al pipeline aritm&eacute;tico, invalidar.
279 145 jguarin200
                                                sync_chain_0 <= '0';
280
 
281
                                                if s_zeroFlag_delay='1' then
282
 
283 150 jguarin200
                                                        --! Notificar fin de procesamiento de la instruccion (End Of Instruction)
284
                                                        eoi <= '1';
285 151 jguarin200
                                                        s_state <= LOAD_INSTRUCTION;
286 145 jguarin200
                                                        s_set_dly <= '1';
287 142 jguarin200
 
288 145 jguarin200
 
289
                                                else
290 150 jguarin200
 
291 151 jguarin200
                                                        s_state <= FLUSH_ARITH_PIPELINE;
292 145 jguarin200
                                                        s_set_dly <= '0';
293 142 jguarin200
 
294 145 jguarin200
                                                end if;
295
 
296 158 jguarin200
                                        --! Invalidar/validar datos dentro del pipeline aritm&eacute;tico.
297 145 jguarin200
                                        elsif s_eb_b='1' and full_r='1' then
298 158 jguarin200
                                                --! Invalidar el siguiente dato dentro del pipeline aritm&eacute;tico.
299 145 jguarin200
                                                sync_chain_0 <= '0';
300 142 jguarin200
                                        else
301 145 jguarin200
                                                sync_chain_0 <= '1';
302
                                        end if;
303
 
304 158 jguarin200
                                --! Ejecuci&oacute;n de la instrucci&oacute;n           
305 145 jguarin200
                                when FLUSH_ARITH_PIPELINE =>
306 158 jguarin200
                                        --! Este estado permanece as&iacute; hasta que, haya una instrucci&oacute;n 
307 145 jguarin200
                                        if s_zeroFlag_delay='1' then
308 142 jguarin200
 
309 150 jguarin200
                                                --! Notificar fin de procesamiento de la instruccion (End Of Instruction)
310
                                                eoi <= '1';
311 151 jguarin200
                                                s_state <= LOAD_INSTRUCTION;
312 145 jguarin200
                                                s_set_dly <= '1';
313
 
314
                                        end if;
315
 
316
                                when others => null;
317
 
318 139 jguarin200
                        end case;
319
                end if;
320
        end process;
321 142 jguarin200
 
322 134 jguarin200
end architecture;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.