Line 39... |
Line 39... |
--
|
--
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
use ieee.std_logic_unsigned.all;
|
|
|
library work;
|
library work;
|
use work.GECKO3COM_defines.all;
|
use work.GECKO3COM_defines.all;
|
|
|
|
|
entity GECKO3COM_simple_test is
|
entity GECKO3COM_simple_test is
|
port (
|
port (
|
i_nReset : in std_logic;
|
i_nReset : in std_logic;
|
i_sysclk : in std_logic; -- FPGA System CLK
|
i_sysclk : in std_logic; -- FPGA System CLK
|
-- Interface signals to the EZ-USB FX2
|
-- Interface signals to the EZ-USB FX2
|
Line 54... |
Line 56... |
i_WRU : in std_logic; -- write from GPIF
|
i_WRU : in std_logic; -- write from GPIF
|
i_RDYU : in std_logic; -- GPIF is ready
|
i_RDYU : in std_logic; -- GPIF is ready
|
o_WRX : out std_logic; -- To write to GPIF
|
o_WRX : out std_logic; -- To write to GPIF
|
o_RDYX : out std_logic; -- IP Core is ready
|
o_RDYX : out std_logic; -- IP Core is ready
|
-- bidirect data bus
|
-- bidirect data bus
|
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0)
|
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
-- simple test "user interface" signals
|
-- simple test "user interface" signals
|
o_LEDrx : out std_logic; -- controll LED receive data
|
o_LEDrx : out std_logic; -- controll LED receive data
|
o_LEDtx : out std_logic; -- controll LED send data
|
o_LEDtx : out std_logic; -- controll LED send data
|
o_LEDrun : out std_logic; -- power LED
|
o_LEDrun : out std_logic; -- power LED
|
i_mode_switch : in std_logic_vector(2 downto 0));
|
i_mode_switch : in std_logic_vector(2 downto 0));
|
Line 72... |
Line 74... |
-- CONSTANTS
|
-- CONSTANTS
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
constant BUSWIDTH : integer := 32; -- you can choose here 32 or 16
|
constant BUSWIDTH : integer := 32; -- you can choose here 32 or 16
|
|
|
-- lenght of the message stored in the response message rom:
|
-- lenght of the message stored in the response message rom:
|
constant c_transfer_size_rom : std_logic_vector(31 downto 0) := x"0000000E";
|
signal c_transfer_size_rom : std_logic_vector(31 downto 0) := x"0000000E";
|
|
|
-- we will transmitt 1 MiB data when the pseude random number generator
|
-- we will transmitt 1 MiB data when the pseude random number generator
|
-- is used:
|
-- is used:
|
constant c_transfer_size_prng : std_logic_vector(31 downto 0) := x"00100000";
|
signal c_transfer_size_prng : std_logic_vector(31 downto 0) := x"00100000";
|
|
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- COMPONENTS
|
-- COMPONENTS
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
Line 141... |
Line 143... |
signal s_send_finished : std_logic;
|
signal s_send_finished : std_logic;
|
|
|
signal s_mode : std_logic_vector(1 downto 0);
|
signal s_mode : std_logic_vector(1 downto 0);
|
signal s_transfer_size_reg_select : std_logic;
|
signal s_transfer_size_reg_select : std_logic;
|
signal s_transfer_size_reg_en : std_logic;
|
signal s_transfer_size_reg_en : std_logic;
|
signal s_have_more_data : std_logic;
|
|
signal s_send_counter_reset : std_logic;
|
signal s_send_counter_reset : std_logic;
|
signal s_send_counter_en : std_logic;
|
signal s_send_counter_en : std_logic;
|
signal s_send_counter_equals_transfer_size : std_logic;
|
signal s_send_counter_equals_transfer_size : std_logic;
|
signal s_prng_en : std_logic;
|
signal s_prng_en : std_logic;
|
signal s_prng_feedback : std_logic;
|
signal s_prng_feedback : std_logic;
|
signal s_receive_data_error : std_logic;
|
signal s_receive_data_error : std_logic;
|
|
|
signal s_receive_data_old : std_logic_vector(31 downto 0);
|
signal s_receive_data_old : std_logic_vector(31 downto 0);
|
signal s_selected_transfer_size : std_logic_vector(31 downto 0);
|
signal s_selected_transfer_size : std_logic_vector(31 downto 0);
|
signal s_remaining_transfer_size : std_logic_vector(31 downto 0);
|
signal s_remaining_transfer_size : std_logic_vector(31 downto 0);
|
|
signal s_subtract_value : std_logic_vector(31 downto 0);
|
signal s_send_counter_value : std_logic_vector(31 downto 0);
|
signal s_send_counter_value : std_logic_vector(31 downto 0);
|
signal s_prng_data : std_logic_vector(31 downto 0);
|
signal s_prng_data : std_logic_vector(31 downto 0);
|
signal s_message_rom_data : std_logic_vector(31 downto 0);
|
signal s_message_rom_data : std_logic_vector(31 downto 0);
|
|
|
|
|
Line 172... |
Line 174... |
st8_reset_send_counter);
|
st8_reset_send_counter);
|
|
|
signal state, next_state : t_fsmState;
|
signal state, next_state : t_fsmState;
|
|
|
-- XST specific synthesize attributes
|
-- XST specific synthesize attributes
|
attribute safe_recovery_state of pr_state : signal is "idle";
|
attribute safe_recovery_state of state : signal is "st1_idle";
|
attribute safe_implementation of pr_state : signal is "yes";
|
attribute safe_implementation of state : signal is "yes";
|
|
|
|
|
|
|
begin -- behavour
|
begin -- behavour
|
|
|
Line 224... |
Line 226... |
-- type : combinational
|
-- type : combinational
|
-- inputs : i_mode_switch
|
-- inputs : i_mode_switch
|
-- outputs: s_mode
|
-- outputs: s_mode
|
mode_switch_decoder: process (i_mode_switch)
|
mode_switch_decoder: process (i_mode_switch)
|
begin -- process mode_switch_decoder
|
begin -- process mode_switch_decoder
|
if i_mode_switch = "xx1" then
|
if i_mode_switch = "001" then
|
s_mode <= "00";
|
s_mode <= "00";
|
elsif i_mode_switch = "x1x" then
|
elsif i_mode_switch = "010" then
|
s_mode <= "01";
|
s_mode <= "01";
|
elsif i_mode_switch = "1xx" then
|
elsif i_mode_switch = "100" then
|
s_mode <= "10";
|
s_mode <= "10";
|
else
|
else
|
s_mode <= "00";
|
s_mode <= "00";
|
end if;
|
end if;
|
end process mode_switch_decoder;
|
end process mode_switch_decoder;
|
Line 246... |
Line 248... |
-- type : combinational
|
-- type : combinational
|
-- inputs : s_mode, s_prng_data, s_message_rom_data
|
-- inputs : s_mode, s_prng_data, s_message_rom_data
|
-- outputs: s_send_fifo_data
|
-- outputs: s_send_fifo_data
|
send_data_mux: process (s_mode, s_prng_data, s_message_rom_data)
|
send_data_mux: process (s_mode, s_prng_data, s_message_rom_data)
|
begin -- process send_data_mux
|
begin -- process send_data_mux
|
case i_send_mux_sel is
|
case s_mode is
|
when "00" => s_send_fifo_data <= s_message_rom_data;
|
when "00" => s_send_fifo_data <= s_message_rom_data;
|
when "01" => s_send_fifo_data <= s_prng_data;
|
when "01" => s_send_fifo_data <= s_prng_data;
|
when others => s_send_fifo_data <= (others => 'x')
|
when others => s_send_fifo_data <= (others => 'X');
|
end case;
|
end case;
|
end process send_data_mux;
|
end process send_data_mux;
|
|
|
|
|
-- purpose: mulitiplexer to select the send transfer size
|
-- purpose: mulitiplexer to select the send transfer size
|
Line 263... |
Line 265... |
send_transfersize_mode_mux: process (s_mode, c_transfer_size_rom, c_transfer_size_prng)
|
send_transfersize_mode_mux: process (s_mode, c_transfer_size_rom, c_transfer_size_prng)
|
begin -- process send_transfersize_mode_mux
|
begin -- process send_transfersize_mode_mux
|
case s_mode is
|
case s_mode is
|
when "00" => s_selected_transfer_size <= c_transfer_size_rom;
|
when "00" => s_selected_transfer_size <= c_transfer_size_rom;
|
when "01" => s_selected_transfer_size <= c_transfer_size_prng;
|
when "01" => s_selected_transfer_size <= c_transfer_size_prng;
|
when others => s_selected_transfer_size <= (others => 'x')
|
when others => s_selected_transfer_size <= (others => 'X');
|
end case;
|
end case;
|
end process send_transfersize_mode_mux;
|
end process send_transfersize_mode_mux;
|
|
|
|
|
-- purpose: stores the initial or remaining transfer size
|
-- purpose: stores the initial or remaining transfer size
|
Line 289... |
Line 291... |
end if;
|
end if;
|
end if;
|
end if;
|
end process remaining_transfer_size_reg;
|
end process remaining_transfer_size_reg;
|
|
|
|
|
-- purpose: mulitiplexer to select the final transfer size for the selected mode
|
|
-- type : combinational
|
|
-- inputs : s_mode, c_transfer_size_rom, c_transfer_size_prng
|
|
-- outputs: s_selected_transfer_size
|
|
send_transfersize_mode_mux: process (s_mode, c_transfer_size_rom, c_transfer_size_prng)
|
|
begin -- process send_transfersize_mode_mux
|
|
case s_mode is
|
|
when "00" => s_selected_transfer_size <= c_transfer_size_rom;
|
|
when "01" => s_selected_transfer_size <= c_transfer_size_prng;
|
|
when others => s_selected_transfer_size <= (others => 'x')
|
|
end case;
|
|
end process send_transfersize_mode_mux;
|
|
|
|
|
|
-- maximum alowed transfer size comparator
|
-- maximum alowed transfer size comparator
|
s_have_more_data <=
|
s_send_have_more_data <=
|
'1' when s_remaining_transfer_size > s_receive_transfersize else
|
'1' when s_remaining_transfer_size > s_receive_transfersize else
|
'0';
|
'0';
|
|
|
|
|
-- purpose: mulitiplexer to select the send transfer size
|
-- purpose: mulitiplexer to select the send transfer size
|
-- type : combinational
|
-- type : combinational
|
-- inputs : s_have_more_data, s_remaining_transfer_size,
|
-- inputs : s_have_more_data, s_remaining_transfer_size,
|
-- s_receive_transfersize
|
-- s_receive_transfersize
|
-- outputs: s_send_transfersize
|
-- outputs: s_send_transfersize
|
send_transfersize_mux: process (s_have_more_data, s_current_transfer_size,
|
send_transfersize_mux: process (s_send_have_more_data, s_receive_transfersize,
|
s_receive_transfersize)
|
s_remaining_transfer_size)
|
|
|
begin -- process send_transfersize_mux
|
begin -- process send_transfersize_mux
|
case i_send_mux_sel is
|
case s_send_have_more_data is
|
when '0' => s_send_transfersize <= s_remaining_transfer_size;
|
when '0' => s_send_transfersize <= s_remaining_transfer_size;
|
when '1' => s_send_transfersize <= s_receive_transfersize
|
when '1' => s_send_transfersize <= s_receive_transfersize;
|
|
when others => s_send_transfersize <= (others => 'X');
|
end case;
|
end case;
|
end process send_transfersize_mux;
|
end process send_transfersize_mux;
|
|
|
|
|
-- purpose: up counter for the send transfer size
|
-- purpose: up counter for the send transfer size
|
Line 334... |
Line 324... |
send_counter : process (i_sysclk, i_nReset)
|
send_counter : process (i_sysclk, i_nReset)
|
begin -- process send_counter
|
begin -- process send_counter
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
s_send_counter_value <= (others => '0');
|
s_send_counter_value <= (others => '0');
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
if i_send_counter_reset = '1' then
|
if s_send_counter_reset = '1' then
|
s_send_counter_value <= (others => '0');
|
s_send_counter_value <= (others => '0');
|
end if;
|
end if;
|
if i_send_counter_en = '1' then
|
if s_send_counter_en = '1' then
|
s_send_counter_value <= s_send_counter_value + 1;
|
s_send_counter_value <= s_send_counter_value + 1;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process send_counter;
|
end process send_counter;
|
|
|
Line 371... |
Line 361... |
-- inputs : i_sysclk, i_nReset, s_receive_fifo_data, s_receive_fifo_rd_en
|
-- inputs : i_sysclk, i_nReset, s_receive_fifo_data, s_receive_fifo_rd_en
|
-- outputs: s_receive_fifo_data_old
|
-- outputs: s_receive_fifo_data_old
|
receive_fifo_data_reg: process (i_sysclk, i_nReset)
|
receive_fifo_data_reg: process (i_sysclk, i_nReset)
|
begin -- process receive_fifo_data_reg
|
begin -- process receive_fifo_data_reg
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
s_receive_fifo_data_old <= (others => '0');
|
s_receive_data_old <= (others => '0');
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
if s_receive_fifo_rd_en = '1' then
|
if s_receive_fifo_rd_en = '1' then
|
s_receive_fifo_data_old <= s_receive_fifo_data;
|
s_receive_data_old <= s_receive_fifo_data;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process receive_fifo_data_reg;
|
end process receive_fifo_data_reg;
|
|
|
|
|
-- receive data comparator
|
-- receive data comparator
|
-- (use together with test data with incrementing values)
|
-- (use together with test data with incrementing values)
|
s_receive_data_error <=
|
s_receive_data_error <=
|
'0' when s_receive_fifo_data_old + 1 = s_receive_fifo_data else
|
'0' when s_receive_data_old + 1 = s_receive_fifo_data else
|
'1';
|
'1';
|
|
|
|
|
-- purpose: linear shift register for the pseude random number
|
-- purpose: linear shift register for the pseude random number
|
-- generator (PRNG)
|
-- generator (PRNG)
|
Line 398... |
Line 388... |
begin -- process prng_shiftregister
|
begin -- process prng_shiftregister
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
if i_nReset = '0' then -- asynchronous reset (active low)
|
s_prng_data <= "01010101 01010101 01010101 01010101";
|
s_prng_data <= "01010101 01010101 01010101 01010101";
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
elsif i_sysclk'event and i_sysclk = '1' then -- rising clock edge
|
if s_prng_en = '1' then
|
if s_prng_en = '1' then
|
s_prng_data <= s_prng_data(30 downto 0) & s_prng_feedback;
|
s_prng_data(31 downto 1) <= s_prng_data(30 downto 0);
|
|
s_prng_data(0) <= s_prng_feedback;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process prng_shiftregister;
|
end process prng_shiftregister;
|
|
|
-- purpose: feedback polynom for the pseudo random number generator (PRNG)
|
-- purpose: feedback polynom for the pseudo random number generator (PRNG)
|
Line 410... |
Line 401... |
-- outputs: s_prng_feedback
|
-- outputs: s_prng_feedback
|
s_prng_feedback <= s_prng_data(15) xor s_prng_data(13) xor s_prng_data(12)
|
s_prng_feedback <= s_prng_data(15) xor s_prng_data(13) xor s_prng_data(12)
|
xor s_prng_data(10);
|
xor s_prng_data(10);
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- finite state machine (moore)
|
-- finite state machine (moore)
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
|
|
-- state reg
|
-- state reg
|
Line 427... |
Line 419... |
end process fsm_state_reg;
|
end process fsm_state_reg;
|
|
|
|
|
-- comb logic
|
-- comb logic
|
next_state_decode: process(state, s_receive_fifo_empty, s_send_fifo_full,
|
next_state_decode: process(state, s_receive_fifo_empty, s_send_fifo_full,
|
s_send_data_request)
|
s_send_data_request, s_send_have_more_data, s_mode,
|
|
s_send_counter_equals_transfer_size)
|
begin -- process next_state_decode
|
begin -- process next_state_decode
|
|
|
--declare default state for next_state to avoid latches
|
--declare default state for next_state to avoid latches
|
next_state <= state; --default is to stay in current state
|
next_state <= state; --default is to stay in current state
|
|
|
Line 480... |
Line 473... |
s_send_counter_en <= '1';
|
s_send_counter_en <= '1';
|
if s_mode = "01" then
|
if s_mode = "01" then
|
s_prng_en <= '1';
|
s_prng_en <= '1';
|
end if;
|
end if;
|
|
|
if s_send_counter_equals_transfer_size = '1' and s_have_more_data = '0' then
|
if s_send_counter_equals_transfer_size = '1' and
|
|
s_send_have_more_data = '0'
|
|
then
|
next_state <= st1_idle;
|
next_state <= st1_idle;
|
elsif s_send_counter_equals_transfer_size = '1' and s_have_more_data = '1' then
|
elsif s_send_counter_equals_transfer_size = '1' and
|
|
s_send_have_more_data = '1'
|
|
then
|
next_state <= st7_subtract_transfered_data;
|
next_state <= st7_subtract_transfered_data;
|
elsif s_send_fifo_full = '1' then
|
elsif s_send_fifo_full = '1' then
|
next_state <= st6_send_wait;
|
next_state <= st6_send_wait;
|
end if;
|
end if;
|
|
|
Line 494... |
Line 491... |
|
|
if s_send_fifo_full = '0' then
|
if s_send_fifo_full = '0' then
|
next_state <= st5_send_data;
|
next_state <= st5_send_data;
|
end if;
|
end if;
|
|
|
when st7_subtract_transfered_data
|
when st7_subtract_transfered_data =>
|
s_transfer_size_reg_select <= '0';
|
s_transfer_size_reg_select <= '0';
|
s_transfer_size_reg_en <= '1';
|
s_transfer_size_reg_en <= '1';
|
|
|
if s_send_data_request = '1' then
|
if s_send_data_request = '1' then
|
st8_reset_send_counter;
|
next_state <= st8_reset_send_counter;
|
end if;
|
end if;
|
|
|
when st8_reset_send_counter =>
|
when st8_reset_send_counter =>
|
s_send_counter_reset <= '1';
|
s_send_counter_reset <= '1';
|
|
|
Line 521... |
Line 518... |
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- RESPONSE MESSAGE ROM
|
-- RESPONSE MESSAGE ROM
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- This file was generated with hex2rom written by Daniel Wallner
|
-- This file was generated with hex2rom written by Daniel Wallner
|
|
|
|
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use IEEE.numeric_std.all;
|
|
|
entity response_message_rom is
|
entity response_message_rom is
|
port(
|
port(
|
A : in std_logic_vector(3 downto 0);
|
A : in std_logic_vector(3 downto 0);
|
D : out std_logic_vector(31 downto 0)
|
D : out std_logic_vector(31 downto 0)
|
);
|
);
|