--! @file sm.vhd
|
--! @file sm.vhd
|
--! @brief Maquina de Estados. Controla la operación interna y genera los mecanismos de sincronización con el exterior (interrupciones).
|
--! @brief Maquina de Estados. Controla la operación interna y genera los mecanismos de sincronización con el exterior (interrupciones).
|
--! @author Julián Andrés Guarín Reyes
|
--! @author Julián Andrés Guarín Reyes
|
--------------------------------------------------------------
|
--------------------------------------------------------------
|
-- RAYTRAC
|
-- RAYTRAC
|
-- Author Julian Andres Guarin
|
-- Author Julian Andres Guarin
|
-- sm.vhd
|
-- sm.vhd
|
-- This file is part of raytrac.
|
-- This file is part of raytrac.
|
--
|
--
|
-- raytrac is free software: you can redistribute it and/or modify
|
-- raytrac is free software: you can redistribute it and/or modify
|
-- it under the terms of the GNU General Public License as published by
|
-- it under the terms of the GNU General Public License as published by
|
-- the Free Software Foundation, either version 3 of the License, or
|
-- the Free Software Foundation, either version 3 of the License, or
|
-- (at your option) any later version.
|
-- (at your option) any later version.
|
--
|
--
|
-- raytrac is distributed in the hope that it will be useful,
|
-- raytrac is distributed in the hope that it will be useful,
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
-- GNU General Public License for more details.
|
-- GNU General Public License for more details.
|
--
|
--
|
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
-- along with raytrac. If not, see <http://www.gnu.org/licenses/>.
|
-- along with raytrac. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use work.arithpack.all;
|
use work.arithpack.all;
|
|
|
entity customCounter is
|
entity customCounter is
|
generic (
|
generic (
|
EOBFLAG : string := "NO";
|
EOBFLAG : string := "NO";
|
ZEROFLAG : string := "YES";
|
ZEROFLAG : string := "YES";
|
BACKWARDS : string := "YES";
|
BACKWARDS : string := "YES";
|
EQUALFLAG : string := "NO";
|
EQUALFLAG : string := "NO";
|
width : integer := 5;
|
width : integer := 5;
|
subwidth : integer := 0
|
subwidth : integer := 0
|
);
|
);
|
port (
|
port (
|
clk,rst,go,set : in std_logic;
|
clk,rst,go,set : in std_logic;
|
setValue, cmpBlockValue : in std_logic_vector (width-1 downto subwidth); --! Los 5 bits de arriba.
|
setValue, cmpBlockValue : in std_logic_vector (width-1 downto subwidth); --! Los 5 bits de arriba.
|
zero_flag,eob_flag, eq_flag : out std_logic;
|
zero_flag,eob_flag, eq_flag : out std_logic;
|
count : out std_logic_vector (width - 1 downto 0)
|
count : out std_logic_vector (width - 1 downto 0)
|
);
|
);
|
end entity;
|
end entity;
|
|
|
|
|
|
|
architecture customCounter_arch of customCounter is
|
architecture customCounter_arch of customCounter is
|
|
|
--!TBXSTART:COUNTING_REGISTERS
|
--!TBXSTART:COUNTING_REGISTERS
|
signal scount_d, scount_q, sgo : std_logic_vector(width-1 downto 0);
|
signal scount_d, scount_q, sgo : std_logic_vector(width-1 downto 0);
|
--!TBXEND
|
--!TBXEND
|
--!TBXSTART:END_OF_BLOCK_FLAG
|
--!TBXSTART:END_OF_BLOCK_FLAG
|
signal seob_flag : std_logic;
|
signal seob_flag : std_logic;
|
--!TBXEND
|
--!TBXEND
|
|
|
|
|
begin
|
begin
|
|
|
--!Compara los bits superiores solamente, si subwidth es 4 y width es 9 comparara los 9-4=5 bits superiores.
|
--!Compara los bits superiores solamente, si subwidth es 4 y width es 9 comparara los 9-4=5 bits superiores.
|
steadyEqualFlag:
|
steadyEqualFlag:
|
if EQUALFLAG/="YES" generate
|
if EQUALFLAG/="YES" generate
|
eq_flag <= '0';
|
eq_flag <= '0';
|
end generate steadyEqualFlag;
|
end generate steadyEqualFlag;
|
equalFlagsProcess:
|
equalFlagsProcess:
|
if EQUALFLAG="YES" generate
|
if EQUALFLAG="YES" generate
|
process (scount_d(width-1 downto subwidth),cmpBlockValue,clk,rst)
|
process (scount_d(width-1 downto subwidth),cmpBlockValue,clk,rst)
|
begin
|
begin
|
if rst=rstMasterValue then
|
if rst=rstMasterValue then
|
eq_flag <= '0';
|
eq_flag <= '0';
|
elsif clk'event and clk='1' then
|
elsif clk'event and clk='1' then
|
if scount_d(width-1 downto subwidth)=cmpBlockValue then
|
if scount_d(width-1 downto subwidth)=cmpBlockValue then
|
eq_flag <= '1';
|
eq_flag <= '1';
|
else
|
else
|
eq_flag <= '0';
|
eq_flag <= '0';
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
end generate equalFlagsProcess;
|
end generate equalFlagsProcess;
|
|
|
--Backwards or Forwards.
|
--Backwards or Forwards.
|
forwardGenerator:
|
forwardGenerator:
|
if BACKWARDS="NO" generate
|
if BACKWARDS="NO" generate
|
sgo(width-1 downto 1) <= (others => '0');
|
sgo(width-1 downto 1) <= (others => '0');
|
sgo(0) <= go;
|
sgo(0) <= go;
|
end generate forwardGenerator;
|
end generate forwardGenerator;
|
|
|
backwardGenerator:
|
backwardGenerator:
|
if BACKWARDS="YES" generate
|
if BACKWARDS="YES" generate
|
sgo(width-1 downto 0) <= (others => go);
|
sgo(width-1 downto 0) <= (others => go);
|
end generate backwardGenerator;
|
end generate backwardGenerator;
|
|
|
|
|
--! Si en los parámetros no se encuentra especificado que detecte el zero entonces la salida zero_flag estará en cero siempre.
|
--! Si en los parámetros no se encuentra especificado que detecte el zero entonces la salida zero_flag estará en cero siempre.
|
steadyZeroFlag:
|
steadyZeroFlag:
|
if ZEROFLAG/="YES" generate
|
if ZEROFLAG/="YES" generate
|
zero_flag <= '0';
|
zero_flag <= '0';
|
end generate steadyZeroFlag;
|
end generate steadyZeroFlag;
|
|
|
--! Si el parámetro para la bandera de cero se especifica, entonces se instancia un proceso que depende del valor del conteo.
|
--! Si el parámetro para la bandera de cero se especifica, entonces se instancia un proceso que depende del valor del conteo.
|
zeroFlagProcess:
|
zeroFlagProcess:
|
if ZEROFLAG="YES" generate
|
if ZEROFLAG="YES" generate
|
--! Proceso para calcular la bandera de cero, en el conteo.
|
--! Proceso para calcular la bandera de cero, en el conteo.
|
process (scount_d,clk,rst)
|
process (scount_d,clk,rst)
|
begin
|
begin
|
if rst=rstMasterValue then
|
if rst=rstMasterValue then
|
zero_flag <= '0';
|
zero_flag <= '0';
|
elsif clk'event and clk='1' then
|
elsif clk'event and clk='1' then
|
zero_flag <= '1';
|
zero_flag <= '1';
|
for i in width-1 downto 0 loop
|
for i in width-1 downto 0 loop
|
if scount_d(i) = '1' then
|
if scount_d(i) = '1' then
|
zero_flag <= '0';
|
zero_flag <= '0';
|
exit;--the loop;
|
exit;--the loop;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end process;
|
end process;
|
end generate zeroFlagProcess;
|
end generate zeroFlagProcess;
|
|
|
|
|
--! Proceso para controlar la salida de la bandera de fin de bloque. Se colocará en uno lógico cuando el conteo vaya en multiplo de 32 menos 1.
|
--! Proceso para controlar la salida de la bandera de fin de bloque. Se colocará en uno lógico cuando el conteo vaya en multiplo de 32 menos 1.
|
steadyEobFlag:
|
steadyEobFlag:
|
if EOBFLAG/="YES" generate
|
if EOBFLAG/="YES" generate
|
eob_flag <= '0';
|
eob_flag <= '0';
|
end generate steadyEobFlag;
|
end generate steadyEobFlag;
|
eobFlagProcess:
|
eobFlagProcess:
|
if EOBFLAG="YES" generate
|
if EOBFLAG="YES" generate
|
process (scount_d(subwidth-1 downto 0),clk,rst)
|
process (scount_d(subwidth-1 downto 0),clk,rst)
|
begin
|
begin
|
if rst=rstMasterValue then
|
if rst=rstMasterValue then
|
eob_flag <= '0';
|
eob_flag <= '0';
|
elsif clk'event and clk='1' then
|
elsif clk'event and clk='1' then
|
eob_flag <= '1';
|
eob_flag <= '1';
|
for i in subwidth-1 downto 0 loop
|
for i in subwidth-1 downto 0 loop
|
if scount_d(i) /= '1' then
|
if scount_d(i) /= '1' then
|
eob_flag <= '0';
|
eob_flag <= '0';
|
exit;--the loop
|
exit;--the loop
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end process;
|
end process;
|
end generate eobFlagProcess;
|
end generate eobFlagProcess;
|
|
|
--! Salida combinatoria del contador.
|
--! Salida combinatoria del contador.
|
count <= scount_d;
|
count <= scount_d;
|
|
|
--! Proceso de control del conteo.
|
--! Proceso de control del conteo.
|
add_proc:
|
add_proc:
|
process (scount_q,sgo,set,setValue)
|
process (scount_q,sgo,set,setValue)
|
begin
|
begin
|
case set is
|
case set is
|
--! Si subwidth es cero, p.ej. cuando se quiere hacer un contador simple y no detectar el final de bloques de 4 bits de ancho, el compilador ignora el statement con la expresión por fuera del rango.
|
--! Si subwidth es cero, p.ej. cuando se quiere hacer un contador simple y no detectar el final de bloques de 4 bits de ancho, el compilador ignora el statement con la expresión por fuera del rango.
|
when '1' => scount_d(subwidth-1 downto 0) <= (others => '0');scount_d(width-1 downto subwidth) <= setValue;
|
when '1' =>
|
when others => scount_d <= scount_q+sgo;
|
scount_d(subwidth-1 downto 0) <= (others => '0');
|
|
scount_d(width-1 downto subwidth) <= setValue;
|
|
when others =>
|
|
scount_d <= scount_q+sgo;
|
end case;
|
end case;
|
end process;
|
end process;
|
|
|
count_proc:
|
count_proc:
|
process (clk,rst)
|
process (clk,rst)
|
begin
|
begin
|
if rst=rstMasterValue then
|
if rst=rstMasterValue then
|
scount_q <= (others => '0');
|
scount_q <= (others => '0');
|
elsif clk='1' and clk'event then
|
elsif clk='1' and clk'event then
|
scount_q <= scount_d;
|
scount_q <= scount_d;
|
end if;
|
end if;
|
end process;
|
end process;
|
end architecture;
|
end architecture;
|
|
|
|
|