From: hadaq Date: Thu, 15 Nov 2012 19:33:05 +0000 (+0000) Subject: timestamp sync basically works X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=7e3465025003f5d3b56353d8b4e0c25de1e0d477;p=trb3.git timestamp sync basically works --- diff --git a/nxyter/source/nx_i2c_master.vhd b/nxyter/source/nx_i2c_master.vhd index 2c74b9d..8f1b799 100644 --- a/nxyter/source/nx_i2c_master.vhd +++ b/nxyter/source/nx_i2c_master.vhd @@ -118,7 +118,10 @@ architecture Behavioral of nx_i2c_master is begin -- Timer - nx_i2c_timer_1: nx_i2c_timer + nx_timer_1: nx_timer + generic map ( + CTR_WIDTH => 12 + ) port map ( CLK_IN => CLK_IN, RESET_IN => RESET_IN, diff --git a/nxyter/source/nx_i2c_readbyte.vhd b/nxyter/source/nx_i2c_readbyte.vhd index 58a3197..42857f9 100644 --- a/nxyter/source/nx_i2c_readbyte.vhd +++ b/nxyter/source/nx_i2c_readbyte.vhd @@ -68,7 +68,10 @@ architecture Behavioral of nx_i2c_readbyte is begin -- Timer - nx_i2c_timer_1: nx_i2c_timer + nx_timer_1: nx_timer + generic map( + CTR_WIDTH => 12 + ) port map ( CLK_IN => CLK_IN, RESET_IN => RESET_IN, diff --git a/nxyter/source/nx_i2c_sendbyte.vhd b/nxyter/source/nx_i2c_sendbyte.vhd index 2044e31..88d0be9 100644 --- a/nxyter/source/nx_i2c_sendbyte.vhd +++ b/nxyter/source/nx_i2c_sendbyte.vhd @@ -68,7 +68,10 @@ architecture Behavioral of nx_i2c_sendbyte is begin -- Timer - nx_i2c_timer_1: nx_i2c_timer + nx_timer_1: nx_timer + generic map ( + CTR_WIDTH => 12 + ) port map ( CLK_IN => CLK_IN, RESET_IN => RESET_IN, diff --git a/nxyter/source/nx_i2c_startstop.vhd b/nxyter/source/nx_i2c_startstop.vhd index 7b9c0fe..82d612a 100644 --- a/nxyter/source/nx_i2c_startstop.vhd +++ b/nxyter/source/nx_i2c_startstop.vhd @@ -54,7 +54,10 @@ architecture Behavioral of nx_i2c_startstop is begin -- Timer - nx_i2c_timer_1: nx_i2c_timer + nx_timer_1: nx_timer + generic map ( + CTR_WIDTH => 12 + ) port map ( CLK_IN => CLK_IN, RESET_IN => RESET_IN, diff --git a/nxyter/source/nx_i2c_timer.vhd b/nxyter/source/nx_timer.vhd similarity index 82% rename from nxyter/source/nx_i2c_timer.vhd rename to nxyter/source/nx_timer.vhd index 15d5ab9..6381d98 100644 --- a/nxyter/source/nx_i2c_timer.vhd +++ b/nxyter/source/nx_timer.vhd @@ -2,23 +2,26 @@ library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -entity nx_i2c_timer is +entity nx_timer is + generic ( + CTR_WIDTH : integer := 12 + ); port( CLK_IN : in std_logic; RESET_IN : in std_logic; - TIMER_START_IN : in unsigned(11 downto 0); + TIMER_START_IN : in unsigned(CTR_WIDTH - 1 downto 0); TIMER_DONE_OUT : out std_logic ); end entity; -architecture Behavioral of nx_i2c_timer is +architecture Behavioral of nx_timer is -- Timer - signal timer_ctr : unsigned(11 downto 0); + signal timer_ctr : unsigned(CTR_WIDTH - 1 downto 0); signal timer_done_o : std_logic; - signal timer_ctr_x : unsigned(11 downto 0); + signal timer_ctr_x : unsigned(CTR_WIDTH - 1 downto 0); signal timer_done_o_x : std_logic; type STATES is (S_IDLE, diff --git a/nxyter/source/nx_timestamp_fifo_read.vhd b/nxyter/source/nx_timestamp_fifo_read.vhd index 250b819..62bdf63 100644 --- a/nxyter/source/nx_timestamp_fifo_read.vhd +++ b/nxyter/source/nx_timestamp_fifo_read.vhd @@ -28,38 +28,41 @@ entity nx_timestamp_fifo_read is SLV_NO_MORE_DATA_OUT : out std_logic; SLV_UNKNOWN_ADDR_OUT : out std_logic; - DEBUG_OUT : out std_logic_vector(7 downto 0) + DEBUG_OUT : out std_logic_vector(15 downto 0) ); end entity; architecture Behavioral of nx_timestamp_fifo_read is - -- FIFO Input Handler - signal nx_timestamp_n : std_logic_vector(7 downto 0); - signal fifo_skip_write_x : std_logic; - signal fifo_skip_write_l : std_logic; - signal fifo_skip_write : std_logic; - signal fifo_full_i : std_logic; - signal fifo_write_enable_o : std_logic; - signal fifo_write_skip_ctr : unsigned(7 downto 0); - signal nx_frame_clock_o : std_logic; - signal frame_clock_ctr : unsigned(1 downto 0); + signal fifo_full : std_logic; + signal fifo_write_enable : std_logic; + signal frame_tag_o : std_logic; + + -- FRAME_CLOCK_GENERATOR + signal frame_clock_ctr : unsigned(1 downto 0); + signal nx_frame_clock_o : std_logic; + + signal frame_clock_ctr_inc_x : std_logic; + signal frame_clock_ctr_inc_l : std_logic; + signal frame_clock_ctr_inc : std_logic; -- FIFO Output Handler - signal fifo_empty_i : std_logic; - signal fifo_empty_x : std_logic; - signal fifo_empty : std_logic; - signal fifo_full_x : std_logic; - signal fifo_full : std_logic; - signal fifo_out : std_logic_vector(31 downto 0); - signal fifo_read_enable_o : std_logic; - signal fifo_skip_write_o : std_logic; - signal fifo_skip_write_r : std_logic; - signal fifo_skip_write_s : std_logic; - - -- SYNC NX Frame Process + signal fifo_out : std_logic_vector(35 downto 0); + signal fifo_empty : std_logic; + signal fifo_read_enable_x : std_logic; + signal fifo_read_enable : std_logic; + signal register_fifo_data_x : std_logic_vector(31 downto 0); + signal register_fifo_data : std_logic_vector(31 downto 0); + signal fifo_new_data_x : std_logic; + signal fifo_new_data : std_logic; + + signal frame_clock_ctr_inc_r : std_logic; + signal frame_clock_ctr_inc_s : std_logic; + signal frame_clock_ctr_inc_o : std_logic; + -- Sync NX Frame Process + -- RS Sync FlipFlop signal nx_frame_synced_o : std_logic; signal rs_sync_set : std_logic; @@ -70,74 +73,67 @@ architecture Behavioral of nx_timestamp_fifo_read is signal frame_sync_wait_ctr : unsigned (7 downto 0); -- Slave Bus - signal register_fifo_data : std_logic_vector(31 downto 0); - signal register_fifo_status : std_logic_vector(31 downto 0); signal slv_data_out_o : std_logic_vector(31 downto 0); signal slv_no_more_data_o : std_logic; signal slv_unknown_addr_o : std_logic; signal slv_ack_o : std_logic; - signal fifo_write_enable_x : std_logic; - signal fifo_write_enable : std_logic; - signal fifo_read_enable_x : std_logic; - signal fifo_read_enable : std_logic; - signal fifo_write_skip_ctr_x : std_logic_vector(7 downto 0); - signal fifo_write_skip_ctr_o : std_logic_vector(7 downto 0); - - type STATES is (IDLE, - READ_FIFO + signal register_fifo_status : std_logic_vector(31 downto 0); + + type STATES is (S_IDLE, + S_READ_FIFO ); - signal STATE : STATES; + signal STATE, NEXT_STATE : STATES; - type STATES_SYNC is (SYNC_CHECK, - SYNC_RESYNC, - SYNC_WAIT + type STATES_SYNC is (S_SYNC_CHECK, + S_SYNC_RESYNC, + S_SYNC_WAIT ); signal STATE_SYNC : STATES_SYNC; - -begin - DEBUG_OUT(0) <= fifo_write_enable_o; - DEBUG_OUT(1) <= fifo_full; - DEBUG_OUT(2) <= fifo_read_enable_o; - DEBUG_OUT(3) <= fifo_empty; - DEBUG_OUT(4) <= nx_frame_synced_o; - DEBUG_OUT(5) <= fifo_skip_write_o; - DEBUG_OUT(6) <= nx_frame_clock_o; - DEBUG_OUT(7) <= CLK_IN; +begin + + DEBUG_OUT(0) <= CLK_IN; + + DEBUG_OUT(1) <= NX_TIMESTAMP_CLK_IN; -- fifo_write_enable; +-- DEBUG_OUT(2) <= fifo_full; +-- DEBUG_OUT(3) <= fifo_write_enable; +-- DEBUG_OUT(4) <= fifo_empty; +-- DEBUG_OUT(5) <= fifo_read_enable; + + -- DEBUG_OUT(2) <= NX_FRAME_CLOCK_OUT; + -- DEBUG_OUT(3) <= ; + -- DEBUG_OUT(5) <= ; + -- DEBUG_OUT(6) <= ; + -- DEBUG_OUT(7) <= '0'; + DEBUG_OUT(6) <= NX_FRAME_CLOCK_OUT; + DEBUG_OUT(7) <= frame_clock_ctr_inc; +-- DEBUG_OUT(15 downto 8) <= NX_TIMESTAMP_OUT(7 downto 0); + --DEBUG_OUT(15 downto 8) <= NX_TIMESTAMP_IN(7 downto 0); + DEBUG_OUT(9 downto 8) <= frame_clock_ctr; ----------------------------------------------------------------------------- -- Dual Clock FIFO 8bit to 32bit ----------------------------------------------------------------------------- - -- First Decode - -- Gray_Decoder_1: Gray_Decoder - -- generic map ( - -- WIDTH => 8) - -- port map ( - -- CLK_IN => NX_TIMESTAMP_CLK_IN, - -- RESET_IN => RESET_IN, - -- GRAY_IN => NX_TIMESTAMP_IN, - -- BINARY_OUT => nx_timestamp_n - -- ); - nx_timestamp_n <= NX_TIMESTAMP_IN; - - - -- Second send data to FIFO - fifo_dc_8to32_1: fifo_dc_8to32 + -- Send data to FIFO + fifo_dc_9to36_1: fifo_dc_9to36 port map ( - Data => nx_timestamp_n, - WrClock => NX_TIMESTAMP_CLK_IN, - RdClock => CLK_IN, - WrEn => fifo_write_enable_o, - RdEn => fifo_read_enable_o, - Reset => RESET_IN, - RPReset => RESET_IN, - Q => fifo_out, - Empty => fifo_empty_i, - Full => fifo_full_i + Data(7 downto 0) => NX_TIMESTAMP_IN, + Data(8) => frame_tag_o, + WrClock => NX_TIMESTAMP_CLK_IN, + RdClock => CLK_IN, + WrEn => fifo_write_enable, + RdEn => fifo_read_enable, + Reset => RESET_IN, + RPReset => RESET_IN, + Q => fifo_out, + Empty => fifo_empty, + Full => fifo_full ); + -- Write only in case FIFO is not full + fifo_write_enable <= '0' when fifo_full = '1' else '1'; ----------------------------------------------------------------------------- -- FIFO Input Handler @@ -149,93 +145,137 @@ begin begin if( rising_edge(NX_TIMESTAMP_CLK_IN) ) then if( RESET_IN = '1' ) then - fifo_skip_write_x <= '0'; - fifo_skip_write_l <= '0'; + frame_clock_ctr_inc_x <= '0'; + frame_clock_ctr_inc_l <= '0'; else - fifo_skip_write_x <= fifo_skip_write_o; - fifo_skip_write_l <= fifo_skip_write_x; + frame_clock_ctr_inc_x <= frame_clock_ctr_inc_o; + frame_clock_ctr_inc_l <= frame_clock_ctr_inc_x; end if; end if; end process PROC_FIFO_IN_HANDLER_SYNC; - -- Signal fifo_skip_write might 2 clocks long --> I need 1 + -- Signal frame_tag_ctr_inc_l might be 2 clocks long --> I need 1 level_to_pulse_1: level_to_pulse port map ( CLK_IN => NX_TIMESTAMP_CLK_IN, RESET_IN => RESET_IN, - LEVEL_IN => fifo_skip_write_l, - PULSE_OUT => fifo_skip_write + LEVEL_IN => frame_clock_ctr_inc_l, + PULSE_OUT => frame_clock_ctr_inc ); - - -- Write only in case FIFO is not full, skip one write cycle in case - -- fifo_skip_write is true (needed by the synchronization process - -- to genrate the NX Frame Clock which I don't have, grrrr) - PROC_FIFO_IN_HANDLER: process(NX_TIMESTAMP_CLK_IN) + + PROC_FRAME_CLOCK_GENERATOR: process(NX_TIMESTAMP_CLK_IN) begin if( rising_edge(NX_TIMESTAMP_CLK_IN) ) then if( RESET_IN = '1' ) then - fifo_write_enable_o <= '0'; - frame_clock_ctr <= (others => '0'); - fifo_write_skip_ctr <= (others => '0'); + frame_clock_ctr <= (others => '0'); + nx_frame_clock_o <= '0'; + frame_tag_o <= '1'; else - fifo_write_enable_o <= '1'; - - if (fifo_full_i = '1') then - fifo_write_enable_o <= '0'; - elsif (fifo_skip_write = '1') then - fifo_write_skip_ctr <= fifo_write_skip_ctr + 1; - fifo_write_enable_o <= '0'; - end if; + case frame_clock_ctr is + + when "00" => + nx_frame_clock_o <= '1'; + frame_tag_o <= '1'; + when "01" => + nx_frame_clock_o <= '1'; + frame_tag_o <= '0'; + when "10" => + nx_frame_clock_o <= '0'; + frame_tag_o <= '0'; + when "11" => + nx_frame_clock_o <= '0'; + frame_tag_o <= '0'; + when others => null; - if (frame_clock_ctr < 2) then - nx_frame_clock_o <= '1'; - else - nx_frame_clock_o <= '0'; - end if; + end case; - if (fifo_skip_write = '1') then - frame_clock_ctr <= (others => '0'); + if (frame_clock_ctr_inc = '1') then + frame_clock_ctr <= frame_clock_ctr + 2; else frame_clock_ctr <= frame_clock_ctr + 1; end if; - + end if; end if; - end process PROC_FIFO_IN_HANDLER; - - NX_FRAME_CLOCK_OUT <= nx_frame_clock_o; + end process PROC_FRAME_CLOCK_GENERATOR; ----------------------------------------------------------------------------- -- FIFO Output Handler and Sync FIFO ----------------------------------------------------------------------------- - -- Read only in case FIFO is not empty - PROC_FIFO_READ: process(CLK_IN) - begin + PROC_FIFO_READ_TRANSFER: process (CLK_IN) + begin if( rising_edge(CLK_IN) ) then - if( RESET_IN = '1' ) then - fifo_read_enable_o <= '0'; - STATE <= IDLE; + if (RESET_IN = '1') then + fifo_read_enable <= '0'; + fifo_new_data <= '0'; + register_fifo_data <= (others => '0'); + STATE <= S_IDLE; + register_fifo_data <= (others => '0'); else - fifo_read_enable_o <= '0'; - case STATE is - - when IDLE => - if (fifo_empty_i = '1') then - STATE <= IDLE; - else - fifo_read_enable_o <= '1'; - STATE <= READ_FIFO; - end if; - - when READ_FIFO => - register_fifo_data <= fifo_out; - STATE <= IDLE; - - when others => null; - end case; + fifo_read_enable <= fifo_read_enable_x; + fifo_new_data <= fifo_new_data_x; + register_fifo_data <= register_fifo_data_x; + STATE <= NEXT_STATE; end if; end if; + end process PROC_FIFO_READ_TRANSFER; + + -- Read only in case FIFO is not empty + PROC_FIFO_READ: process(STATE) + + variable frame_tag : std_logic_vector(3 downto 0); + + begin + fifo_read_enable_x <= '0'; + fifo_new_data_x <= '0'; + register_fifo_data_x <= register_fifo_data; + + frame_tag := fifo_out(35) & fifo_out(26) & + fifo_out(17) & fifo_out(8); + + case STATE is + + when S_IDLE => + if (fifo_empty = '1') then + NEXT_STATE <= S_IDLE; + else + fifo_read_enable_x <= '1'; + NEXT_STATE <= S_READ_FIFO; + end if; + + when S_READ_FIFO => + fifo_new_data_x <= '1'; + case frame_tag is + when "1000" => + register_fifo_data_x(31 downto 24) <= fifo_out(34 downto 27); + register_fifo_data_x(23 downto 16) <= fifo_out(25 downto 18); + register_fifo_data_x(15 downto 8) <= fifo_out(16 downto 9); + register_fifo_data_x(7 downto 0) <= fifo_out(7 downto 0); + when "0100" => + register_fifo_data_x(31 downto 24) <= fifo_out( 7 downto 0); + register_fifo_data_x(23 downto 16) <= fifo_out(34 downto 27); + register_fifo_data_x(15 downto 8) <= fifo_out(25 downto 18); + register_fifo_data_x(7 downto 0) <= fifo_out(16 downto 9); + when "0010" => + register_fifo_data_x(31 downto 24) <= fifo_out(16 downto 9); + register_fifo_data_x(23 downto 16) <= fifo_out(7 downto 0); + register_fifo_data_x(15 downto 8) <= fifo_out(34 downto 27); + register_fifo_data_x(7 downto 0) <= fifo_out(25 downto 18); + when "0001" => + register_fifo_data_x(31 downto 24) <= fifo_out(25 downto 18); + register_fifo_data_x(23 downto 16) <= fifo_out(16 downto 9); + register_fifo_data_x(15 downto 8) <= fifo_out(7 downto 0); + register_fifo_data_x(7 downto 0) <= fifo_out(34 downto 27); + + when others => + register_fifo_data_x <= (others => '1'); + fifo_new_data_x <= '0'; + end case; + NEXT_STATE <= S_IDLE; + + when others => null; + end case; end process PROC_FIFO_READ; @@ -251,57 +291,65 @@ begin end if; end process PROC_RS_FRAME_SYNCED; - -- Sync to NX NO_DATA FRAME + -- Sync to NX_DATA FRAME PROC_SYNC_TO_NO_DATA: process(CLK_IN) + + variable fifo_tag_given : std_logic_vector(3 downto 0); + begin + fifo_tag_given := fifo_out(35) & fifo_out(26) & + fifo_out(17) & fifo_out(8); + if( rising_edge(CLK_IN) ) then if( RESET_IN = '1' ) then - rs_sync_set <= '0'; - rs_sync_reset <= '1'; - nx_frame_resync_ctr <= (others => '0'); - frame_sync_wait_ctr <= (others => '0'); - fifo_skip_write_s <= '0'; - STATE_SYNC <= SYNC_CHECK; + rs_sync_set <= '0'; + rs_sync_reset <= '1'; + nx_frame_resync_ctr <= (others => '0'); + frame_sync_wait_ctr <= (others => '0'); + frame_clock_ctr_inc_s <= '0'; + STATE_SYNC <= S_SYNC_CHECK; else - rs_sync_set <= '0'; - rs_sync_reset <= '0'; - fifo_skip_write_s <= '0'; + rs_sync_set <= '0'; + rs_sync_reset <= '0'; + frame_clock_ctr_inc_s <= '0'; + + DEBUG_OUT(5 downto 2) <= fifo_tag_given; case STATE_SYNC is - when SYNC_CHECK => - case fifo_out is + when S_SYNC_CHECK => + case register_fifo_data is when x"7f7f7f06" => rs_sync_set <= '1'; - STATE_SYNC <= SYNC_CHECK; + STATE_SYNC <= S_SYNC_CHECK; when x"067f7f7f" => - STATE_SYNC <= SYNC_RESYNC; + STATE_SYNC <= S_SYNC_RESYNC; when x"7f067f7f" => - STATE_SYNC <= SYNC_RESYNC; + STATE_SYNC <= S_SYNC_RESYNC; when x"7f7f067f" => - STATE_SYNC <= SYNC_RESYNC; + STATE_SYNC <= S_SYNC_RESYNC; when others => - STATE_SYNC <= SYNC_CHECK; + STATE_SYNC <= S_SYNC_CHECK; end case; - when SYNC_RESYNC => - rs_sync_reset <= '1'; - fifo_skip_write_s <= '1'; - nx_frame_resync_ctr <= nx_frame_resync_ctr + 1; - frame_sync_wait_ctr <= x"ff"; - STATE_SYNC <= SYNC_WAIT; + when S_SYNC_RESYNC => + rs_sync_reset <= '1'; + frame_clock_ctr_inc_s <= '1'; + nx_frame_resync_ctr <= nx_frame_resync_ctr + 1; + frame_sync_wait_ctr <= x"ff"; + STATE_SYNC <= S_SYNC_WAIT; - when SYNC_WAIT => + when S_SYNC_WAIT => if (frame_sync_wait_ctr > 0) then frame_sync_wait_ctr <= frame_sync_wait_ctr -1; - STATE_SYNC <= SYNC_WAIT; + STATE_SYNC <= S_SYNC_WAIT; else - STATE_SYNC <= SYNC_CHECK; + STATE_SYNC <= S_SYNC_CHECK; end if; end case; @@ -311,50 +359,51 @@ begin end process PROC_SYNC_TO_NO_DATA; NX_FRAME_SYNC_OUT <= nx_frame_synced_o; - NX_TIMESTAMP_OUT <= register_fifo_data; - -------------------------------------------------------------------------------- --- TRBNet Slave Bus -------------------------------------------------------------------------------- - - -- Cross ClockDomain NX_TIMESTAMP_CLK_IN --> CLK_IN, for simplicity just - -- cross all signals, even the CLK_IN ones - PROC_SYNC_FIFO_SIGNALS: process(CLK_IN) - begin - if( rising_edge(CLK_IN) ) then - if( RESET_IN = '1' ) then - fifo_empty_x <= '0'; - fifo_empty <= '0'; - - fifo_full_x <= '0'; - fifo_full <= '0'; - - fifo_write_enable_x <= '0'; - fifo_write_enable <= '0'; - - fifo_read_enable_x <= '0'; - fifo_read_enable <= '0'; - fifo_write_skip_ctr_x <= (others => '0'); - fifo_write_skip_ctr_o <= (others => '0'); - else - fifo_empty_x <= fifo_empty_i; - fifo_empty <= fifo_empty_x; - - fifo_full_x <= fifo_full_i; - fifo_full <= fifo_full_x; - - fifo_write_enable_x <= fifo_write_enable_o; - fifo_write_enable <= fifo_write_enable_x; - - fifo_read_enable_x <= fifo_read_enable_o; - fifo_read_enable <= fifo_read_enable_x; - - fifo_write_skip_ctr_x <= fifo_write_skip_ctr; - fifo_write_skip_ctr_o <= fifo_write_skip_ctr_x; - end if; - end if; - end process PROC_SYNC_FIFO_SIGNALS; +-- +-- ------------------------------------------------------------------------------- +-- -- TRBNet Slave Bus +-- ------------------------------------------------------------------------------- +-- +-- -- Cross ClockDomain NX_TIMESTAMP_CLK_IN --> CLK_IN, for simplicity just +-- -- cross all signals, even the CLK_IN ones +-- -- PROC_SYNC_FIFO_SIGNALS: process(CLK_IN) +-- -- begin +-- -- if( rising_edge(CLK_IN) ) then +-- -- if( RESET_IN = '1' ) then +-- -- fifo_empty_x <= '0'; +-- -- fifo_empty <= '0'; +-- -- +-- -- fifo_full_x <= '0'; +-- -- fifo_full <= '0'; +-- -- +-- -- fifo_write_enable_x <= '0'; +-- -- fifo_write_enable <= '0'; +-- -- +-- -- fifo_read_enable_x <= '0'; +-- -- fifo_read_enable <= '0'; +-- -- +-- -- fifo_write_skip_ctr_x <= (others => '0'); +-- -- fifo_write_skip_ctr_o <= (others => '0'); +-- -- else +-- -- fifo_empty_x <= fifo_empty_i; +-- -- fifo_empty <= fifo_empty_x; +-- -- +-- -- fifo_full_x <= fifo_full_i; +-- -- fifo_full <= fifo_full_x; +-- -- +-- -- fifo_write_enable_x <= fifo_write_enable; +-- -- fifo_write_enable <= fifo_write_enable_x; +-- -- +-- -- fifo_read_enable_x <= fifo_read_enable_o; +-- -- fifo_read_enable <= fifo_read_enable_x; +-- -- +-- -- fifo_write_skip_ctr_x <= fifo_write_skip_ctr; +-- -- fifo_write_skip_ctr_o <= fifo_write_skip_ctr_x; +-- -- end if; +-- -- end if; +-- -- end process PROC_SYNC_FIFO_SIGNALS; +-- register_fifo_status(0) <= fifo_write_enable; register_fifo_status(1) <= fifo_full; @@ -362,7 +411,7 @@ begin register_fifo_status(4) <= fifo_read_enable; register_fifo_status(5) <= fifo_empty; register_fifo_status(7 downto 6) <= (others => '0'); - register_fifo_status(15 downto 8) <= fifo_write_skip_ctr_o; + register_fifo_status(15 downto 8) <= (others => '0');-- fifo_write_skip_ctr; register_fifo_status(23 downto 16) <= nx_frame_resync_ctr; register_fifo_status(30 downto 24) <= (others => '0'); register_fifo_status(31) <= nx_frame_synced_o; @@ -373,31 +422,31 @@ begin begin if( rising_edge(CLK_IN) ) then if( RESET_IN = '1' ) then - slv_data_out_o <= (others => '0'); - slv_ack_o <= '0'; - slv_unknown_addr_o <= '0'; - slv_no_more_data_o <= '0'; - fifo_skip_write_r <= '0'; + slv_data_out_o <= (others => '0'); + slv_ack_o <= '0'; + slv_unknown_addr_o <= '0'; + slv_no_more_data_o <= '0'; + frame_clock_ctr_inc_r <= '0'; else - slv_data_out_o <= (others => '0'); - slv_ack_o <= '1'; - slv_unknown_addr_o <= '0'; - slv_no_more_data_o <= '0'; - fifo_skip_write_r <= '0'; + slv_data_out_o <= (others => '0'); + slv_ack_o <= '1'; + slv_unknown_addr_o <= '0'; + slv_no_more_data_o <= '0'; + frame_clock_ctr_inc_r <= '0'; if (SLV_READ_IN = '1') then case SLV_ADDR_IN is - when x"0000" => slv_data_out_o <= register_fifo_data; - when x"0001" => slv_data_out_o <= register_fifo_status; + when x"0000" => slv_data_out_o <= register_fifo_data; + when x"0001" => slv_data_out_o <= register_fifo_status; when others => slv_unknown_addr_o <= '1'; - slv_ack_o <= '0'; + slv_ack_o <= '0'; end case; elsif (SLV_WRITE_IN = '1') then case SLV_ADDR_IN is - when x"0001" => fifo_skip_write_r <= '1'; - when others => slv_unknown_addr_o <= '1'; - slv_ack_o <= '0'; + when x"0001" => frame_clock_ctr_inc_r <= '1'; + when others => slv_unknown_addr_o <= '1'; + slv_ack_o <= '0'; end case; else slv_ack_o <= '0'; @@ -406,13 +455,15 @@ begin end if; end process PROC_FIFO_REGISTERS; - fifo_skip_write_o <= fifo_skip_write_r or fifo_skip_write_s; + frame_clock_ctr_inc_o <= frame_clock_ctr_inc_r or frame_clock_ctr_inc_s; --- Output Signals + -- Output Signals SLV_DATA_OUT <= slv_data_out_o; SLV_NO_MORE_DATA_OUT <= slv_no_more_data_o; SLV_UNKNOWN_ADDR_OUT <= slv_unknown_addr_o; SLV_ACK_OUT <= slv_ack_o; + NX_FRAME_CLOCK_OUT <= nx_frame_clock_o; + NX_TIMESTAMP_OUT <= register_fifo_data; end Behavioral; diff --git a/nxyter/source/nxyter.vhd b/nxyter/source/nxyter.vhd index 60f07c2..f87402a 100644 --- a/nxyter/source/nxyter.vhd +++ b/nxyter/source/nxyter.vhd @@ -97,6 +97,7 @@ architecture Behavioral of nXyter_FEE_board is signal spi_sdo : std_logic; -- FIFO Read + signal nx_ts_reset_o : std_logic; signal nx_frame_clock_o : std_logic; signal nx_frame_sync_o : std_logic; @@ -110,12 +111,15 @@ begin ------------------------------------------------------------------------------- -- DEBUG ------------------------------------------------------------------------------- --- DEBUG_LINE_OUT(0) <= CLK_IN; --- DEBUG_LINE_OUT(1) <= clk_256_o; --- DEBUG_LINE_OUT(2) <= NX_CLK128_IN; +-- DEBUG_LINE_OUT(2) <= CLK_IN; +-- DEBUG_LINE_OUT(1) <= NX_CLK256A_OUT; +-- DEBUG_LINE_OUT(0) <= NX_CLK128_IN; -- DEBUG_LINE_OUT(3) <= nx_frame_clock_o; -- DEBUG_LINE_OUT(4) <= nx_frame_sync_o; --- DEBUG_LINE_OUT(7 downto 5) <= (others => '0'); +-- DEBUG_LINE_OUT(5) <= NX_RESET_OUT; +-- DEBUG_LINE_OUT(7 downto 6) <= (others => '0'); +-- +-- DEBUG_LINE_OUT(15 downto 8) <= NX_TIMESTAMP_IN; -- DEBUG_LINE_OUT(15 downto 8) <= NX_TIMESTAMP_IN; -- DEBUG_LINE_OUT(8) <= i2c_sda_o; -- DEBUG_LINE_OUT(9) <= i2c_sda_i; @@ -144,6 +148,9 @@ begin LOCK => open ); + NX_CLK256A_OUT <= clk_256_o; + NX_TESTPULSE_OUT <= '0'; + -- pll_25_1: pll_25 -- port map ( -- CLK => CLK_IN, @@ -152,10 +159,6 @@ begin -- ); -- clk_256_o <= CLK_128_IN; - NX_RESET_OUT <= '0'; - NX_CLK256A_OUT <= clk_256_o; - NX_TESTPULSE_OUT <= '0'; - -- TRBNet Bus Handler THE_BUS_HANDLER: trb_net16_regio_bus_handler generic map( @@ -274,20 +277,22 @@ begin ------------------------------------------------------------------------------- nxyter_registers_1: nxyter_registers port map ( - CLK_IN => CLK_IN, - RESET_IN => RESET_IN, - - SLV_READ_IN => slv_read(0), - SLV_WRITE_IN => slv_write(0), - SLV_DATA_OUT => slv_data_rd(0*32+31 downto 0*32), - SLV_DATA_IN => slv_data_wr(0*32+31 downto 0*32), - SLV_ADDR_IN => slv_addr(0*16+15 downto 0*16), - SLV_ACK_OUT => slv_ack(0), - SLV_NO_MORE_DATA_OUT => slv_no_more_data(0), - SLV_UNKNOWN_ADDR_OUT => slv_unknown_addr(0), - I2C_SM_RESET_OUT => i2c_sm_reset_o, - I2C_REG_RESET_OUT => i2c_reg_reset_o, - DEBUG_OUT => open + CLK_IN => CLK_IN, + RESET_IN => RESET_IN, + + SLV_READ_IN => slv_read(0), + SLV_WRITE_IN => slv_write(0), + SLV_DATA_OUT => slv_data_rd(0*32+31 downto 0*32), + SLV_DATA_IN => slv_data_wr(0*32+31 downto 0*32), + SLV_ADDR_IN => slv_addr(0*16+15 downto 0*16), + SLV_ACK_OUT => slv_ack(0), + SLV_NO_MORE_DATA_OUT => slv_no_more_data(0), + SLV_UNKNOWN_ADDR_OUT => slv_unknown_addr(0), + I2C_SM_RESET_OUT => i2c_sm_reset_o, + I2C_REG_RESET_OUT => i2c_reg_reset_o, + NX_TS_RESET_OUT => nx_ts_reset_o, + -- DEBUG_OUT(7 downto 0) => DEBUG_LINE_OUT(15 downto 8) + DEBUG_OUT => open ); ------------------------------------------------------------------------------- @@ -310,11 +315,8 @@ begin SLV_ACK_OUT => slv_ack(1), SLV_NO_MORE_DATA_OUT => slv_no_more_data(1), SLV_UNKNOWN_ADDR_OUT => slv_unknown_addr(1), - DEBUG_OUT(13 downto 0) => DEBUG_LINE_OUT(13 downto 0) - --DEBUG_OUT => open + DEBUG_OUT => open ); - DEBUG_LINE_OUT(14) <= I2C_SDA_INOUT; - DEBUG_LINE_OUT(15) <= I2C_SCL_INOUT; ------------------------------------------------------------------------------- -- nXyter TimeStamp Read @@ -340,10 +342,10 @@ begin SLV_NO_MORE_DATA_OUT => slv_no_more_data(2), SLV_UNKNOWN_ADDR_OUT => slv_unknown_addr(2), --- DEBUG_OUT => DEBUG_LINE_OUT(7 downto 0) - DEBUG_OUT => open + DEBUG_OUT => DEBUG_LINE_OUT + -- DEBUG_OUT => open ); - + ------------------------------------------------------------------------------- -- Data Buffer FIFO ------------------------------------------------------------------------------- @@ -370,6 +372,7 @@ begin ------------------------------------------------------------------------------- -- nXyter Signals ------------------------------------------------------------------------------- + NX_RESET_OUT <= not nx_ts_reset_o; ------------------------------------------------------------------------------- -- I2C Signals @@ -377,7 +380,7 @@ begin I2C_SM_RESET_OUT <= not i2c_sm_reset_o; I2C_REG_RESET_OUT <= not i2c_reg_reset_o; - + ------------------------------------------------------------------------------- -- END ------------------------------------------------------------------------------- diff --git a/nxyter/source/nxyter_components.vhd b/nxyter/source/nxyter_components.vhd index 5a56b94..e06c824 100644 --- a/nxyter/source/nxyter_components.vhd +++ b/nxyter/source/nxyter_components.vhd @@ -78,7 +78,10 @@ component nx_i2c_master ); end component; -component nx_i2c_timer +component nx_timer + generic ( + CTR_WIDTH : integer + ); port ( CLK_IN : in std_logic; RESET_IN : in std_logic; @@ -153,10 +156,26 @@ component nxyter_registers SLV_UNKNOWN_ADDR_OUT : out std_logic; I2C_SM_RESET_OUT : out std_logic; I2C_REG_RESET_OUT : out std_logic; + NX_TS_RESET_OUT : out std_logic; DEBUG_OUT : out std_logic_vector(15 downto 0) ); end component; +component fifo_dc_9to36 + port ( + Data : in std_logic_vector(8 downto 0); + WrClock : in std_logic; + RdClock : in std_logic; + WrEn : in std_logic; + RdEn : in std_logic; + Reset : in std_logic; + RPReset : in std_logic; + Q : out std_logic_vector(35 downto 0); + Empty : out std_logic; + Full : out std_logic + ); +end component; + component fifo_dc_8to32 port ( Data : in std_logic_vector(7 downto 0); @@ -168,7 +187,8 @@ component fifo_dc_8to32 RPReset : in std_logic; Q : out std_logic_vector(31 downto 0); Empty : out std_logic; - Full : out std_logic); + Full : out std_logic + ); end component; component nx_timestamp_fifo_read @@ -191,7 +211,7 @@ component nx_timestamp_fifo_read SLV_NO_MORE_DATA_OUT : out std_logic; SLV_UNKNOWN_ADDR_OUT : out std_logic; - DEBUG_OUT : out std_logic_vector(7 downto 0) + DEBUG_OUT : out std_logic_vector(15 downto 0) ); end component; diff --git a/nxyter/source/nxyter_registers.vhd b/nxyter/source/nxyter_registers.vhd index c287f7c..5460142 100644 --- a/nxyter/source/nxyter_registers.vhd +++ b/nxyter/source/nxyter_registers.vhd @@ -24,7 +24,8 @@ entity nxyter_registers is -- Signals I2C_SM_RESET_OUT : out std_logic; I2C_REG_RESET_OUT : out std_logic; - + NX_TS_RESET_OUT : out std_logic; + DEBUG_OUT : out std_logic_vector(15 downto 0) ); end entity; @@ -40,15 +41,20 @@ architecture Behavioral of nxyter_registers is -- I2C Reset signal i2c_sm_reset_start : std_logic; signal i2c_reg_reset_start : std_logic; - signal wait_timer_init_x : unsigned(7 downto 0); + signal nx_ts_reset_start : std_logic; + signal i2c_sm_reset_o : std_logic; signal i2c_reg_reset_o : std_logic; - + signal nx_ts_reset_o : std_logic; + signal wait_timer_init_x : unsigned(7 downto 0); + type STATES is (S_IDLE, S_I2C_SM_RESET, S_I2C_SM_RESET_WAIT, S_I2C_REG_RESET, - S_I2C_REG_RESET_WAIT + S_I2C_REG_RESET_WAIT, + S_NX_TS_RESET, + S_NX_TS_RESET_WAIT ); signal STATE, NEXT_STATE : STATES; @@ -62,16 +68,23 @@ architecture Behavioral of nxyter_registers is begin - DEBUG_OUT <= reg_data(0)(15 downto 0); + DEBUG_OUT(0) <= I2C_SM_RESET_OUT ; + DEBUG_OUT(1) <= I2C_REG_RESET_OUT; + DEBUG_OUT(2) <= NX_TS_RESET_OUT; - nx_i2c_timer_1: nx_i2c_timer + DEBUG_OUT(15 downto 3) <= (others => '0'); + + nx_timer_1: nx_timer + generic map ( + CTR_WIDTH => 8 + ) port map ( - CLK_IN => CLK_IN, - RESET_IN => RESET_IN, - TIMER_START_IN(7 downto 0) => wait_timer_init, - TIMER_START_IN(11 downto 8) => open, - TIMER_DONE_OUT => wait_timer_done + CLK_IN => CLK_IN, + RESET_IN => RESET_IN, + TIMER_START_IN => wait_timer_init, + TIMER_DONE_OUT => wait_timer_done ); + ----------------------------------------------------------------------------- -- I2C SM Reset ----------------------------------------------------------------------------- @@ -93,6 +106,7 @@ begin begin i2c_sm_reset_o <= '0'; i2c_reg_reset_o <= '0'; + nx_ts_reset_o <= '0'; wait_timer_init_x <= (others => '0'); case STATE is @@ -101,6 +115,8 @@ begin NEXT_STATE <= S_I2C_SM_RESET; elsif (i2c_reg_reset_start = '1') then NEXT_STATE <= S_I2C_REG_RESET; + elsif (nx_ts_reset_start = '1') then + NEXT_STATE <= S_NX_TS_RESET; else NEXT_STATE <= S_IDLE; end if; @@ -131,6 +147,20 @@ begin NEXT_STATE <= S_IDLE; end if; + when S_NX_TS_RESET => + nx_ts_reset_o <= '1'; + wait_timer_init_x <= x"8f"; + NEXT_STATE <= S_NX_TS_RESET_WAIT; + + when S_NX_TS_RESET_WAIT => + nx_ts_reset_o <= '1'; + if (wait_timer_done = '0') then + NEXT_STATE <= S_NX_TS_RESET_WAIT; + else + NEXT_STATE <= S_IDLE; + end if; + + end case; end process PROC_I2C_SM_RESET; @@ -158,6 +188,7 @@ begin i2c_sm_reset_start <= '0'; i2c_reg_reset_start <= '0'; + nx_ts_reset_start <= '0'; else slv_ack_o <= '1'; slv_unknown_addr_o <= '0'; @@ -165,12 +196,13 @@ begin slv_data_out_o <= (others => '0'); i2c_sm_reset_start <= '0'; i2c_reg_reset_start <= '0'; + nx_ts_reset_start <= '0'; if (SLV_WRITE_IN = '1') then case SLV_ADDR_IN is - when x"0000" => i2c_sm_reset_start <= '1'; + when x"0000" => i2c_sm_reset_start <= '1'; when x"0001" => i2c_reg_reset_start <= '1'; - when x"0002" => reg_data(2) <= SLV_DATA_IN; + when x"0002" => nx_ts_reset_start <= '1'; when x"0003" => reg_data(3) <= SLV_DATA_IN; when x"0004" => reg_data(4) <= SLV_DATA_IN; when x"0005" => reg_data(5) <= SLV_DATA_IN; @@ -209,5 +241,6 @@ begin I2C_SM_RESET_OUT <= i2c_sm_reset_o; I2C_REG_RESET_OUT <= i2c_reg_reset_o; + NX_TS_RESET_OUT <= nx_ts_reset_o; end Behavioral;