diff --git a/generic_ip/swim/2/doc/swim_2.json b/generic_ip/swim/2/doc/swim_2.json index e8be5a0..5176af4 100644 --- a/generic_ip/swim/2/doc/swim_2.json +++ b/generic_ip/swim/2/doc/swim_2.json @@ -39,13 +39,13 @@ "minor_number" : { "type" : "c", "bit_len" : "8", - "reset" : "0x02", + "reset" : "0x03", "description" : "Minor number" }, "major_number" : { "type" : "c", "bit_len" : "8", - "reset" : "0x00", + "reset" : "0x02", "description" : "Major number" }, diff --git a/generic_ip/swim/2/src/swim_2.vhd b/generic_ip/swim/2/src/swim_2.vhd index bb7d30c..93d63c5 100644 --- a/generic_ip/swim/2/src/swim_2.vhd +++ b/generic_ip/swim/2/src/swim_2.vhd @@ -60,7 +60,8 @@ use ieee.std_logic_misc.all; entity swim_2 is generic ( - CLK_FREQ_MHZ : integer := 100 + CLK_FREQ_MHZ : integer := 100; + TEST_MODE : boolean := false ); port ( clk : in std_logic; @@ -151,7 +152,9 @@ architecture rtl of swim_2 is -- Signals for timing pulse generation signal count_4KHz : std_logic_vector(9 downto 0); -- Counter to count 4MHz pulse for 4KHz timing + signal count_4mhz_for_4khz : std_logic_vector(9 downto 0); signal count_4MHz : std_logic_vector(4 downto 0); -- Counter to count 100MHz clock for 4MHz timing + signal count_4Mhz_thresh : std_logic_vector(4 downto 0); signal bit_count : std_logic_vector(4 downto 0); -- Counter to count 4MHz ticks for TX of return-to zero 0/1 signal tick_4KHz : std_logic; -- Tick at 4KHz (100MHz pulse) signal tick_4MHz : std_logic; -- Tick at 4MHz (100MHz pulse) @@ -204,6 +207,7 @@ architecture rtl of swim_2 is signal rx_rising_edge : std_logic; -- Pulse on input signal rising edge signal swim_in_last : std_logic; -- Cycle delayed version of (synced) swim input signal rx_bit_count : std_logic_vector(9 downto 0); -- Count of received bits + signal rx_bit_count_thresh : std_logic_vector(9 downto 0); signal receiving_bit : std_logic; -- Flag active when receiving a bit signal rx_idx : std_logic_vector(3 downto 0); -- Count of cycles for low period of received bit signal rx_parity : std_logic; -- Parity of the received byte @@ -219,6 +223,19 @@ architecture rtl of swim_2 is constant one : std_logic_vector(31 downto 0) := 32x"00000001"; -- Convenience std_logic_vector value of 1 to save on conversions begin + + GEN_TEST_MODE : if TEST_MODE generate + count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ/100-1, 10)); + rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD/10, 10)); + count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ/10-1, 5)); + end generate; + + GEN_NOT_TEST_MODE : if not TEST_MODE generate + count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ-1, 10)); + rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD, 10)); + count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ-1, 5)); + end generate; + -- Export for debug selected signals (up to 5) dbg_port <= timed_out & status_rx_error & status_rxbusy & status_tx_nak_error & swim_in_sync(0) ; @@ -317,7 +334,7 @@ begin timed_out <= '0'; -- Generate a 4MHz tick - if (count_4MHz = std_logic_vector(to_unsigned(CLK_COUNT_4MHZ-1, 5))) then + if count_4MHz = count_4Mhz_thresh then count_4MHz <= (others => '0'); else count_4MHz <= std_logic_vector(unsigned(count_4MHz) + 1); @@ -332,7 +349,7 @@ begin -- Generate a 4KHz tick if (tick_4MHz = '1') then - if (count_4KHz = std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ-1, 10))) then + if count_4KHz = count_4mhz_for_4khz then count_4KHz <= (others => '0'); else count_4KHz <= std_logic_vector(unsigned(count_4KHz) + 1); @@ -758,7 +775,7 @@ begin -- the rising edge. A long count is a zero, a short count is a 1. if rx_rising_edge = '1' then - if unsigned(rx_bit_count) > RX_BIT_COUNT_THRESHOLD then + if unsigned(rx_bit_count) > unsigned(rx_bit_count_thresh) then rx_bit_var := '0'; else rx_bit_var := '1';