##// END OF EJS Templates
Se saca comando x"08" de la implementación. Este comando estaba indicado en la descripción y dejaba colgado al equipo en el momento de su configuración porque el pulsedesign genera este comando.
Se saca comando x"08" de la implementación. Este comando estaba indicado en la descripción y dejaba colgado al equipo en el momento de su configuración porque el pulsedesign genera este comando.

File last commit:

r45:46
r45:46
Show More
commands_detector.vhd
182 lines | 7.2 KiB | text/x-vhdl | VhdlLexer
/ Trunk / source / vhd / commands_detector.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Entidad de detector de comandos
---Contiene un SIPO (Serial Input Parallel Output) interno proveniente de rs232_module para obtener en un registro los datos seriales.
---Devuelve el comando codificado ("funcion") con una se�al de aviso de comando listo("func_data_sel") muy usada en muchos modulos.
---Asimismo, devuelve el dato recibido ("data_out") con una se�al de aviso de dato listo ("ready_div_clk") que sera recibida por wr_memory_block_module.
---Una vez de dar aviso mediante ambas se�ales de aviso se espera "ACK" para regresar a espera de otro comando � dato.
entity commands_detector is
Port ( clk : in STD_LOGIC;
RST : in STD_LOGIC;
RX : in STD_LOGIC;
ACK : in std_logic;
funcion : out STD_LOGIC_VECTOR (7 downto 0);
func_data_sel : out std_logic;
data_out : out std_LOGIC_VECTOR(7 downto 0);
ready_div_clk : out STD_LOGIC);
end commands_detector;
architecture Behavioral of commands_detector is
component rs232_module
Port ( CLK : in STD_LOGIC;
RST : in STD_LOGIC;
RX : in STD_LOGIC;
ACK : in STD_LOGIC;
READY : out STD_LOGIC;
DATA : out STD_LOGIC_VECTOR (7 downto 0));
end component;
--Definiciones para m�quina de estado
type command_func_fsm is (IDLE, COMMAND_VAL, DATA_VAL,WAIT_ACK);
signal com_func_fsm : command_func_fsm:=IDLE;
attribute com_fsm_attribute : STRING;
attribute com_fsm_attribute of command_func_fsm: TYPE is "00 01 10 11";
--Se�ales internas para enlazar se�ales rs232_module_1
signal READY : std_logic:='0';
signal data : std_logic_vector(7 downto 0):=(others=>'0');
begin
--Instanciaci�n de rs232_module_1 para detectar datos formato RS232 a 9600 baudios
---depositando dato recibido en registro "data".
---Se�al interna "READY" sirve para indicar que se tiene un dato listo en la bandeja "data". Dura 1 ciclo de clk_sys.
rs232_module_1 : rs232_module
Port map ( CLK => CLK,
RST => RST,
RX => RX,
ACK => READY,
READY => READY,
DATA => data);
--Proceso de M�quina de Estado
---IDLE: estado de espera a recepci�n de dato listo en bandeja "data" mediante "ready" que viene de rs232_module_1
--- y de decisi�n entre recepci�n de COMANDO � DATO
---COMMAND_VAL: estado que reconoce comandos estandar y pasa a WAIT_ACK, caso contrario regresa a IDLE.
---DATA_VAL: estado de transicion a WAIT_ACK.
---WAIT_ACK: espera se�al acknowledge externo, que indica recepci�n externa de dato codificado � registro paralelo para regresar a IDLE.
Process(clk)
begin
if rising_edge(clk) then
if RST = '1' then
com_func_fsm <= IDLE;
else
case com_func_fsm is
------------------------------------
when IDLE =>
case ready is
when '1' =>
if data = X"FF" then
com_func_fsm <= COMMAND_VAL;
elsif data = X"FE" then
com_func_fsm <= DATA_VAL;
end if;
when others => null;
end case;
------------------------------------
when DATA_VAL =>
if ready = '1' then
com_func_fsm <= WAIT_ACK;
end if;
------------------------------------
when COMMAND_VAL =>
if ready = '1' then
case data is
when X"78" | X"48" | X"58" | X"68" | X"70" | X"5C"| X"18" | X"00" | X"28" | X"30" | X"40" | X"43" | X"09" | X"16" | X"59" | X"45"=>
com_func_fsm <= WAIT_ACK;
when others => com_func_fsm <= IDLE;
end case;
end if;
------------------------------------
when OTHERS =>
if ACK = '1' then
com_func_fsm <= IDLE;
end if;
------------------------------------
end case;
end if;
end if;
end process;
--Proceso que, dentro del estado COMMAND_VAL, diferencia los comandos recibidos y los codifica en un registro "funcion"
---Al recibir un "ACK" por parte de un m�dulo externo (acknowledge de recepci�n) se resetea.
Process(clk)
variable temp : std_logic_vector(7 downto 0);
begin
if rising_edge(clk) then
if rst = '1' or ACK = '1' then
temp := (others=>'0');
elsif com_func_fsm = COMMAND_VAL and ready = '1' then
--RESET(X"78") RESET por comando
--TX_ON(X"48"), TX_OFF(X"58") Habilitador TX
--SW_ON(X"68"), SW_OFF(X"70") Habilitador SW
--BW_ON(X"09"), BW_OFF(X"5C") Habilitador BW
--DISABLE(X"00"), ENABLE(X"18") [cmds borrados: X"50" | X"20"] Tipo de Funcionamiento de CR (Deshabilitar Salidas X"00" | Free Running X"18")
--WR_DELAY(X"28"),WR_ESTADOS(X"30"), Escritura en MEM. RETARDOS, MEM. ESTADOS y NEXT_SEQ para MULTIPP
--FRECUENCIA SAMPLING(X"40") , ACTIVAR SAMPLING(X"43") SAMPLING Activable y con Frecuencia Programable
--DIVISOR FREC. PROGRAMABLE (X"08"), DIVISOR POR DEFECTO = 60 Divisor de Frecuencia Programable para generaci�n de Pulsos de Salida de CR.
--GENERADOR DE RF VARIABLE (X"45")
case data is
-- when X"09" | X"5C" => temp:="10000000";
when X"45" => temp:="10000000";
when X"78" => temp:="01000000";
when X"48" | X"58" => temp:="00100000";
when X"68" | X"70" => temp:="00010000";
when X"18" | X"00" | X"59" => temp:="00001000";
when X"28" | X"30" => temp:="00000100";
when X"40" | X"43" => temp:="00000010";
when X"16" => temp:="00000001";
when others => temp:=(others=>'0');
end case;
end if;
end if;
funcion <= temp;
end process;
--Proceso que genera "ready_div_clk".
---"ready_div_clk" indica que un dato(no comando) ha sido le�do correctamente y se encuentra disponible en el registro "data_out"
---Al recibir un "ACK" por parte de un m�dulo externo (acknowledge de recepci�n) se resetea.
Process(clk)
begin
if rising_edge(clk) then
if rst = '1' or ACK = '1' then
ready_div_clk <= '0';
elsif ready = '1' then
case com_func_fsm is
when DATA_VAL =>
ready_div_clk <= '1';
when others => null;
end case;
end if;
end if;
end Process;
--Proceso que extrae el dato � comando mostrado por rs232_module_1
---Al recibir un "ACK" por parte de un m�dulo externo (acknowledge de recepci�n) se resetea.
Process(clk)
begin
if rising_edge(clk) then
if rst = '1' or ACK = '1' then
data_out <= (others=>'0');
elsif ready = '1' then
case com_func_fsm is
when DATA_VAL | COMMAND_VAL => data_out <= data;
when others => null;
end case;
end if;
end if;
end process;
--Proceso que genera "func_data_sel".
---Muestra un pulso luego de 2 ciclos de clk_sys de haber entrado al estado COMMAND_VAL.
---Tiene una duraci�n de 1 ciclo de clk_sys.
process(clk)
variable retardo : std_logic_vector(1 downto 0):=(others=>'0');
begin
if rising_edge(clk) then
if rst = '1' or com_func_fsm /= COMMAND_VAL then
func_data_sel <= '0';
retardo:=(others=>'0');
elsif com_func_fsm = COMMAND_VAL then
func_data_sel <= not(retardo(1)) and retardo(0);
retardo(1):=retardo(0);
retardo(0) :='1';
end if;
end if;
end process;
end Behavioral;