Commit 78d3f242 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

wrsw_ext_board: fix formatting, no technical change

parent a8d8867f
files = [ "ext_board_check.vhd"];
files = [ "ext_board_check.vhd" ];
......@@ -5,8 +5,6 @@
-- File : ext_board_check.vhd
-- Author : Mattia Rzzi
-- Company : CERN BE-CO-HT
-- Created : 2012-03-07
-- Last update: 2014-03-20
-- Platform : FPGA-generic
-- Standard : VHDL
-------------------------------------------------------------------------------
......@@ -44,84 +42,86 @@ use work.wr_fabric_pkg.all;
use work.endpoint_pkg.all;
use work.wrsw_top_pkg.all;
library UNISIM;
use UNISIM.vcomponents.all;
entity ext_board_check is
generic (
g_pattern : std_logic_vector (63 downto 0) := x"CAFED00DCAFED00D";
g_clk_divider : integer := 16
);
g_pattern : std_logic_vector(63 downto 0) := x"CAFED00DCAFED00D";
g_clk_divider : integer := 16);
port (
clk_sys_i : in std_logic;
rst_n_i : in std_logic;
loopback_i : in std_logic;
loopback_o : out std_logic;
board_detected_o : out std_logic
);
clk_sys_i : in std_logic;
rst_n_i : in std_logic;
loopback_i : in std_logic;
loopback_o : out std_logic;
board_detected_o : out std_logic
);
end ext_board_check;
architecture Behavioral of ext_board_check is
signal clk_divider : integer range 0 to g_clk_divider-1;
signal clk_en : std_logic;
signal bit_position : integer range 0 to g_pattern'length-1;
type fsm_states is (init, write_bit, read_bit, done);
signal fsm_state : fsm_states := init;
signal error_detected : std_logic;
begin
signal clk_divider : integer range 0 to g_clk_divider-1;
signal clk_en : std_logic;
signal bit_position : integer range 0 to g_pattern'length-1;
signal error_detected : std_logic;
clock_divider_inst : process (clk_sys_i)
begin
if rising_edge (clk_sys_i) then
clk_divider <= clk_divider + 1;
if (clk_divider = g_clk_divider - 1) then
clk_divider <= 0;
clk_en <= '1';
else
clk_en <= '0';
end if;
end if;
end process;
type fsm_states is (INIT, WRITE_BIT, READ_BIT, DONE);
signal fsm_state : fsm_states := INIT;
FSM_INST : process (clk_sys_i)
begin
if rst_n_i = '0' then
board_detected_o <= '0';
fsm_state <= init;
elsif rising_edge(clk_sys_i) then
case fsm_state is
when init =>
board_detected_o <= '0';
bit_position <= 0;
fsm_state <= write_bit;
error_detected <= '0';
when write_bit =>
loopback_o <= g_pattern(bit_position);
if (clk_en = '1') then
fsm_state <= read_bit;
end if;
when read_bit =>
if (g_pattern(bit_position) = loopback_i) then
if (bit_position = g_pattern'length-1) then
fsm_state <= done;
else
bit_position <= bit_position + 1;
fsm_state <= write_bit;
end if;
else
error_detected <= '1';
fsm_state <= done;
end if;
when done =>
board_detected_o <= not error_detected;
when others => fsm_state <= init;
end case;
end if;
end process;
clock_divider_inst : process (clk_sys_i)
begin
if rising_edge (clk_sys_i) then
clk_divider <= clk_divider + 1;
if (clk_divider = g_clk_divider - 1) then
clk_divider <= 0;
clk_en <= '1';
else
clk_en <= '0';
end if;
end if;
end process;
FSM_INST : process (clk_sys_i)
begin
if rst_n_i = '0' then
board_detected_o <= '0';
fsm_state <= INIT;
elsif rising_edge(clk_sys_i) then
case fsm_state is
when INIT =>
board_detected_o <= '0';
bit_position <= 0;
fsm_state <= WRITE_BIT;
error_detected <= '0';
when WRITE_BIT =>
loopback_o <= g_pattern(bit_position);
if (clk_en = '1') then
fsm_state <= READ_BIT;
end if;
when READ_BIT =>
if (g_pattern(bit_position) = loopback_i) then
if (bit_position = g_pattern'length-1) then
fsm_state <= DONE;
else
bit_position <= bit_position + 1;
fsm_state <= WRITE_BIT;
end if;
else
error_detected <= '1';
fsm_state <= DONE;
end if;
when DONE =>
board_detected_o <= not error_detected;
when others =>
fsm_state <= INIT;
end case;
end if;
end process;
end Behavioral;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment