1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00
myhdl/example/manual/FramerCtrl.vhd

90 lines
2.1 KiB
VHDL
Raw Normal View History

2008-11-22 22:40:25 +01:00
-- File: FramerCtrl.vhd
2010-07-02 13:24:04 +02:00
-- Generated by MyHDL 0.7dev
-- Date: Sun Oct 10 21:39:53 2010
2008-11-22 22:40:25 +01:00
package pck_FramerCtrl is
type t_enum_t_State_1 is (
SEARCH,
CONFIRM,
SYNC
);
attribute enum_encoding of t_enum_t_State_1: type is "001 010 100";
end package pck_FramerCtrl;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use std.textio.all;
2010-07-02 13:24:04 +02:00
use work.pck_myhdl_07dev.all;
2008-11-22 22:40:25 +01:00
use work.pck_FramerCtrl.all;
entity FramerCtrl is
port (
SOF: out std_logic;
state: inout t_enum_t_State_1;
syncFlag: in std_logic;
clk: in std_logic;
reset_n: in std_logic
);
end entity FramerCtrl;
2010-07-02 13:24:04 +02:00
-- Framing control FSM.
--
-- SOF -- start-of-frame output bit
-- state -- FramerState output
-- syncFlag -- sync pattern found indication input
-- clk -- clock input
-- reset_n -- active low reset
2008-11-22 22:40:25 +01:00
architecture MyHDL of FramerCtrl is
signal index: unsigned(7 downto 0);
begin
2010-07-02 13:24:04 +02:00
2008-11-22 22:40:25 +01:00
FRAMERCTRL_FSM: process (clk, reset_n) is
begin
if (reset_n = '0') then
SOF <= '0';
index <= "00000000";
state <= SEARCH;
elsif rising_edge(clk) then
index <= ((index + 1) mod 8);
SOF <= '0';
case state is
when SEARCH =>
index <= "00000001";
if to_boolean(syncFlag) then
state <= CONFIRM;
end if;
when CONFIRM =>
if (index = 0) then
if to_boolean(syncFlag) then
state <= SYNC;
else
state <= SEARCH;
end if;
end if;
when SYNC =>
if (index = 0) then
if (not to_boolean(syncFlag)) then
state <= SEARCH;
end if;
end if;
SOF <= to_std_logic(signed(resize(index, 9)) = (8 - 1));
when others =>
assert False report "End of Simulation" severity Failure;
end case;
end if;
end process FRAMERCTRL_FSM;
end architecture MyHDL;