diff --git a/generic_ip/fire_pulse_manager/2/build/fire_pulse_manager_2_hw.tcl b/generic_ip/fire_pulse_manager/2/build/fire_pulse_manager_2_hw.tcl index 9d315d7..17bfddc 100644 --- a/generic_ip/fire_pulse_manager/2/build/fire_pulse_manager_2_hw.tcl +++ b/generic_ip/fire_pulse_manager/2/build/fire_pulse_manager_2_hw.tcl @@ -62,9 +62,9 @@ add_fileset_file queue_and_delay.vhd VHDL PATH ../../../common/0/src/queue_and_d add_fileset_file simple_frac_div_2.vhd VHDL PATH ../../../pulse_generator/2/src/simple_frac_div_2.vhd add_fileset_file pulse_generator_2_pkg.vhd VHDL PATH ../../../pulse_generator/2/src/pulse_generator_2_pkg.vhd add_fileset_file pulse_generator_2.vhd VHDL PATH ../../../pulse_generator/2/src/pulse_generator_2.vhd -add_fileset_file uart_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/uart_rx_1.vhd +add_fileset_file pof_uart_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_uart_rx_1.vhd add_fileset_file pof_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_rx_1.vhd -add_fileset_file uart_regen_1.vhd VHDL PATH ../../../pof_protocol/1/src/uart_regen_1.vhd +add_fileset_file pof_uart_regen_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_uart_regen_1.vhd add_fileset_file smb_diagnostics_2.vhd VHDL PATH ../src/smb_diagnostics_2.vhd add_fileset_file fire_pulse_2_pkg.vhd VHDL PATH ../src/fire_pulse_2_pkg.vhd add_fileset_file simple_enc_vel_detect.vhd VHDL PATH ../src/simple_enc_vel_detect.vhd @@ -96,9 +96,9 @@ add_fileset_file queue_and_delay.vhd VHDL PATH ../../../common/0/src/queue_and_d add_fileset_file simple_frac_div_2.vhd VHDL PATH ../../../pulse_generator/2/src/simple_frac_div_2.vhd add_fileset_file pulse_generator_2_pkg.vhd VHDL PATH ../../../pulse_generator/2/src/pulse_generator_2_pkg.vhd add_fileset_file pulse_generator_2.vhd VHDL PATH ../../../pulse_generator/2/src/pulse_generator_2.vhd -add_fileset_file uart_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/uart_rx_1.vhd +add_fileset_file pof_uart_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_uart_rx_1.vhd add_fileset_file pof_rx_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_rx_1.vhd -add_fileset_file uart_regen_1.vhd VHDL PATH ../../../pof_protocol/1/src/uart_regen_1.vhd +add_fileset_file pof_uart_regen_1.vhd VHDL PATH ../../../pof_protocol/1/src/pof_uart_regen_1.vhd add_fileset_file smb_diagnostics_2.vhd VHDL PATH ../src/smb_diagnostics_2.vhd add_fileset_file fire_pulse_2_pkg.vhd VHDL PATH ../src/fire_pulse_2_pkg.vhd add_fileset_file simple_enc_vel_detect.vhd VHDL PATH ../src/simple_enc_vel_detect.vhd diff --git a/generic_ip/fire_pulse_manager/2/sim/com_fpm.do b/generic_ip/fire_pulse_manager/2/sim/com_fpm.do index e340393..00cdaa1 100644 --- a/generic_ip/fire_pulse_manager/2/sim/com_fpm.do +++ b/generic_ip/fire_pulse_manager/2/sim/com_fpm.do @@ -53,9 +53,9 @@ vcom -2008 -work $WORKLIB $LOG_PATH/event_logger_0.vhd # Fire-Pulse-Manager vcom -2008 -work $WORKLIB $COMMON_PATH/cs_bus_itf.vhd -vcom -2008 -work $WORKLIB $POF_PATH/uart_rx_1.vhd +vcom -2008 -work $WORKLIB $POF_PATH/pof_uart_rx_1.vhd vcom -2008 -work $WORKLIB $POF_PATH/pof_rx_1.vhd -vcom -2008 -work $WORKLIB $POF_PATH/uart_regen_1.vhd +vcom -2008 -work $WORKLIB $POF_PATH/pof_uart_regen_1.vhd vcom -2008 -work $WORKLIB $SRC_PATH/smb_diagnostics_2.vhd vcom -2008 -work $WORKLIB $SRC_PATH/simple_enc_vel_detect.vhd vcom -2008 -work $WORKLIB $SRC_PATH/fire_pulse_2_pkg.vhd diff --git a/generic_ip/fire_pulse_manager/2/src/fire_pulse_ctrl_2.vhd b/generic_ip/fire_pulse_manager/2/src/fire_pulse_ctrl_2.vhd index 79d90cc..59107c9 100644 --- a/generic_ip/fire_pulse_manager/2/src/fire_pulse_ctrl_2.vhd +++ b/generic_ip/fire_pulse_manager/2/src/fire_pulse_ctrl_2.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2017-09-06 --- Last update: 2019-09-24 +-- Last update: 2019-09-25 -- SVN ID : Git -- Standard : VHDL'08 ------------------------------------------------------------------------------- @@ -159,12 +159,15 @@ begin uart_regen_bypass <= uart_regen_bypass_i; -- latch src_sel to improve timing + /* pSRC_SEL_L : process(clk) begin if(clk = '1' and clk'event) then src_sel <= src_sel_i; end if; end process pSRC_SEL_L; + */ + src_sel <= src_sel_i; uart_bit_div <= bit_div; upd_max_pos <= upd_max_pos_i; diff --git a/generic_ip/fire_pulse_manager/2/src/fire_pulse_manager_2.vhd b/generic_ip/fire_pulse_manager/2/src/fire_pulse_manager_2.vhd index 3f9d600..faceb24 100644 --- a/generic_ip/fire_pulse_manager/2/src/fire_pulse_manager_2.vhd +++ b/generic_ip/fire_pulse_manager/2/src/fire_pulse_manager_2.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2017-09-06 --- Last update: 2019-09-24 +-- Last update: 2019-09-27 -- SVN ID : Git -- Standard : VHDL'08 ------------------------------------------------------------------------------- @@ -58,7 +58,10 @@ architecture rtl of fire_pulse_manager_2 is constant PD_QUEUE_SIZE : natural := 512; -- Period used for Time-of-Flight compensation velocity measurememnt - constant VEL_MEAS_PERIOD : natural := 10000; + constant VEL_MEAS_PERIOD : natural := 10000; + + constant POF_UART_BIT_BIV : integer := 6; -- POF-Rx UART sampling clock vs + -- baudrate ratio signal reset_n_i : std_logic; -- @@ -105,7 +108,7 @@ architecture rtl of fire_pulse_manager_2 is signal rx_watchdog : std_logic; signal rx_watchdog_en : std_logic; signal rx_watchdog_clr : std_logic; - signal bit_div : std_logic_vector( 3 downto 0); + signal print_start_i : std_logic; signal error_rate_thres : std_logic_vector( 7 downto 0); signal parity_err_cnt : std_logic_vector(15 downto 0); signal skip_pos_cnt : std_logic_vector(15 downto 0); @@ -218,7 +221,7 @@ begin upd_max_pos => open, upd_min_pos => open, enable_rx => enable_rx, - uart_bit_div => bit_div, + uart_bit_div => open, error_rate_thres => error_rate_thres, max_error_flag => max_error_flag, rx_watchdog => rx_watchdog, @@ -271,8 +274,9 @@ begin mon_point_src(9) <= fire_pulse_i; mon_point_src(10) <= inc_pos; mon_point_src(11) <= dec_pos; + mon_point_src(12) <= print_start_i; -- - mon_point_src(15 downto 12) <= (others => '0'); + mon_point_src(15 downto 13) <= (others => '0'); pof_iso_en <= enable_rx; @@ -326,6 +330,8 @@ begin -- POF Receiver iPOF_RX : entity work.pof_rx_1 + generic map( + GEN_BIT_DIV => POF_UART_BIT_BIV) port map( reset_n => reset_n_i, clk => clk, @@ -334,12 +340,11 @@ begin rx_data => pof_rx, init_out => remote_init, pd_out => pd_pulse_pof, - print_start => print_start, + print_start => print_start_i, inc_pos => inc_pos_pof, dec_pos => dec_pos_pof, abs_pos => abs_pos_pof, enable => enable_rx, - bit_div => bit_div, error_rate_thres => error_rate_thres, one_pps => one_pps, max_error_flag => max_error_flag, @@ -349,14 +354,16 @@ begin parity_err_cnt => parity_err_cnt, skip_pos_cnt => skip_pos_cnt); + print_start <= print_start_i; + -- UART signal regeneration - iUART_REGEN : entity work.uart_regen_1 + iUART_REGEN : entity work.pof_uart_regen_1 generic map( - data_width => 8) + GEN_BIT_DIV => POF_UART_BIT_BIV, + data_width => 9) port map( reset_n => reset_n, clk => rx_clk, - bit_div => bit_div, enable => enable_rx, bypass_en => uart_regen_bypass, uart_rx => pof_rx, diff --git a/generic_ip/pof_protocol/1/doc/pof_tx_1.json b/generic_ip/pof_protocol/1/doc/pof_tx_1.json index 2876fa3..669893f 100644 --- a/generic_ip/pof_protocol/1/doc/pof_tx_1.json +++ b/generic_ip/pof_protocol/1/doc/pof_tx_1.json @@ -41,7 +41,7 @@ "type" : "w", "bit_len" : "1", "reset" : "0x0", - "description" : "Enables queueing up events in the POF-Tx FIFO, each time there is a change in Print-Start value" + "description" : "Enables queuing up events in the POF-Tx FIFO, each time there is a change in Print-Start value" }, "print_start_src" : { "type" : "w", diff --git a/generic_ip/pof_protocol/1/sim/sim_pof_txrx.do b/generic_ip/pof_protocol/1/sim/sim_pof_txrx.do index 0150aab..281417a 100644 --- a/generic_ip/pof_protocol/1/sim/sim_pof_txrx.do +++ b/generic_ip/pof_protocol/1/sim/sim_pof_txrx.do @@ -39,7 +39,7 @@ vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire_redge.vhd --vcom -2008 -work $WORKLIB ../src/altera/fifo_16x8.vhd vcom -2008 -work $WORKLIB $COMMON_PATH/altera/sync_fifo.vhd vcom -2008 -work $WORKLIB ../src/uart_tx_1.vhd -vcom -2008 -work $WORKLIB ../src/uart_rx_1.vhd +vcom -2008 -work $WORKLIB ../src/pof_uart_rx_1.vhd vcom -2008 -work $WORKLIB ../src/pof_tx_1.vhd vcom -2008 -work $WORKLIB ../src//pof_rx_1.vhd diff --git a/generic_ip/pof_protocol/1/sim/wave_pof_txrx.do b/generic_ip/pof_protocol/1/sim/wave_pof_txrx.do index b7a1a4b..bcb8472 100644 --- a/generic_ip/pof_protocol/1/sim/wave_pof_txrx.do +++ b/generic_ip/pof_protocol/1/sim/wave_pof_txrx.do @@ -28,6 +28,9 @@ add wave -noupdate /pof_tx_rx_1_tb/pd_out add wave -noupdate /pof_tx_rx_1_tb/inc_pos_out add wave -noupdate /pof_tx_rx_1_tb/dec_pos_out add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_pos_out +add wave -noupdate /pof_tx_rx_1_tb/print_start_in +add wave -noupdate /pof_tx_rx_1_tb/print_start_out +add wave -noupdate /pof_tx_rx_1_tb/ps_flip_cnt add wave -noupdate /pof_tx_rx_1_tb/test_completed add wave -noupdate /pof_tx_rx_1_tb/running add wave -noupdate /pof_tx_rx_1_tb/configuring @@ -58,6 +61,7 @@ add wave -noupdate /pof_tx_rx_1_tb/pd_err add wave -noupdate /pof_tx_rx_1_tb/pos_err add wave -noupdate /pof_tx_rx_1_tb/enc_err add wave -noupdate /pof_tx_rx_1_tb/ovfl_err +add wave -noupdate /pof_tx_rx_1_tb/ps_err add wave -noupdate /pof_tx_rx_1_tb/injected_errors add wave -noupdate /pof_tx_rx_1_tb/max_pos add wave -noupdate /pof_tx_rx_1_tb/min_pos @@ -135,6 +139,7 @@ add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_out add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/inc_pos add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dec_pos add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/abs_pos +add wave -noupdate /pof_tx_rx_1_tb/print_start_out add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/error_rate_thres add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/one_pps add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/max_error_flag @@ -165,6 +170,16 @@ add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/toggle_pd add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_confirmed add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_toggle_test add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd +add wave -noupdate /pof_tx_rx_1_tb/print_start_in +add wave -noupdate /pof_tx_rx_1_tb/print_start_out +add wave -noupdate /pof_tx_rx_1_tb/ps_flip_cnt +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/ps_gen +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/ps_new +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/ps_confirmed +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/ps_test +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_error +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_error_i +add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/print_start_i add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/valid_pos add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/upd_pos add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/corr_done @@ -190,26 +205,14 @@ add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dec_pos_ii add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_width add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/reset_n add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/clk -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/bit_div add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/init add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_out add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_out_valid add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rx_data -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/fsm_state_curr -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/fsm_state_next add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rx_data_i -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/shf_data -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rst_bit_cnt -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/inc_bit_cnt -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rst_clk_cnt -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/end_of_bit -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/end_of_rx -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_valid -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/stop_bit add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data -add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/bit_cnt TreeUpdate [SetDefaultTree] -WaveRestoreCursors {{Cursor 1} {18949975000 ps} 0} +WaveRestoreCursors {{Cursor 1} {1338555000 ps} 0} quietly wave cursor active 1 configure wave -namecolwidth 305 configure wave -valuecolwidth 100 @@ -225,4 +228,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ps update -WaveRestoreZoom {16743248207 ps} {29628150095 ps} +WaveRestoreZoom {0 ps} {3221225472 ps} diff --git a/generic_ip/pof_protocol/1/src/pof_rx_1.vhd b/generic_ip/pof_protocol/1/src/pof_rx_1.vhd index 80b156e..af20423 100644 --- a/generic_ip/pof_protocol/1/src/pof_rx_1.vhd +++ b/generic_ip/pof_protocol/1/src/pof_rx_1.vhd @@ -6,7 +6,7 @@ -- Author : Gianmarco Girau -- Company : Global Inkjet Systems -- Created : 2017-08-23 --- Last update: 2019-09-24 +-- Last update: 2019-09-27 -- SVN ID : Git -- Standard : VHDL'08 ------------------------------------------------------------------------------- @@ -20,6 +20,8 @@ use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity pof_rx_1 is + generic( + GEN_BIT_DIV : integer := 6); port( reset_n : in std_logic; clk : in std_logic; @@ -35,7 +37,6 @@ entity pof_rx_1 is abs_pos : out std_logic_vector(31 downto 0); -- C&S enable : in std_logic; - bit_div : in std_logic_vector(3 downto 0); error_rate_thres : in std_logic_vector(7 downto 0); one_pps : in std_logic; max_error_flag : out std_logic; @@ -100,13 +101,13 @@ begin -- De-serialize symbols (Serial clock at 300 MHz - typical) ----------------------------------------------------------------------------- - iRX_SYMBOL : entity work.uart_rx_1 + iRX_SYMBOL : entity work.pof_uart_rx_1 generic map( - data_width => 9) + GEN_BIT_DIV => GEN_BIT_DIV, + data_width => 9) port map( reset_n => reset_n, clk => rx_clk, - bit_div => bit_div, init => clear_i, data_out => rx_symbol, data_out_valid => rx_symbol_val, @@ -187,7 +188,9 @@ begin elsif (ps_gen = '1') then ps_test <= '1'; end if; - if(ps_confirmed = '1') then + if(init = '1' or enable = '0') then + print_start_i <= '0'; + elsif(ps_confirmed = '1') then print_start_i <= ps_new; end if; -- diff --git a/generic_ip/pof_protocol/1/src/pof_uart_regen_1.vhd b/generic_ip/pof_protocol/1/src/pof_uart_regen_1.vhd new file mode 100644 index 0000000..d98093a --- /dev/null +++ b/generic_ip/pof_protocol/1/src/pof_uart_regen_1.vhd @@ -0,0 +1,100 @@ +------------------------------------------------------------------------------- +-- Title : uart_regen +-- Project : EMB-1 +------------------------------------------------------------------------------- +-- File : uart_regen.vhd +-- Author : Gianmarco Girau/Simon Southwell +-- Company : Global Inkjet Systems +-- Created : 2017-10-31 +-- Last update: 2019-09-27 +-- SVN ID : Git +-- Standard : VHDL'08 +------------------------------------------------------------------------------- +-- Description: +-- Regenerate the UART signal +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity pof_uart_regen_1 is + generic( + GEN_BIT_DIV : integer := 6; + data_width : natural range 1 to 31 := 8 + ); + port( + reset_n : in std_logic; + clk : in std_logic; + enable : in std_logic; + bypass_en : in std_logic; + uart_rx : in std_logic; + uart_tx : out std_logic); +end entity pof_uart_regen_1; + +architecture rtl of pof_uart_regen_1 is + + signal uart_rx_i : std_logic; + signal uart_regen : std_logic; + signal receiving : std_logic; + signal sample_cnt_unary : std_logic_vector(GEN_BIT_DIV-1 downto 0); + signal bit_cnt_unary : std_logic_vector(data_width + 1 downto 0); + +begin + + -- output mux (maybe register?) + uart_tx <= uart_rx when bypass_en = '1' else uart_regen; + + ----------------------------------------------------------------------------- + -- Input Synchronization + ----------------------------------------------------------------------------- + + iSYNC_IN : entity work.sync_wire + generic map( + rst_val => '1', + sync_stages => 3) + port map( + rstN => reset_n, + clk => clk, + async_in => uart_rx, + sync_out => uart_rx_i); + + pREGEN : process(clk) + begin + if clk = '1' and clk'event then + if enable = '0' or bypass_en = '1' then + receiving <= '0'; + bit_cnt_unary <= std_logic_vector(to_unsigned(1, bit_cnt_unary'length)); + sample_cnt_unary <= std_logic_vector(to_unsigned(1, sample_cnt_unary'length)); + uart_regen <= '1'; + else + -- If start bit seen when not receiving, start receiving and start unary sample count shifting (with rotation). + -- Keep rotating whilst receiving. + if (receiving = '0' and uart_rx_i = '0') or receiving = '1' then + receiving <= '1'; + sample_cnt_unary <= sample_cnt_unary(sample_cnt_unary'high-1 downto 0) & sample_cnt_unary(sample_cnt_unary'high); + end if; + + end if; + + -- At half way regenerate the input + if sample_cnt_unary(GEN_BIT_DIV/2 - 1) = '1' then + uart_regen <= uart_rx_i; + end if; + + -- After half way, up the bit count + if sample_cnt_unary(GEN_BIT_DIV/2) = '1' then + bit_cnt_unary <= bit_cnt_unary(bit_cnt_unary'high-1 downto 0) & bit_cnt_unary(bit_cnt_unary'high); + end if; + + -- If at the end of the last (stop) bit clear the receiving state. + if sample_cnt_unary(GEN_BIT_DIV-1) = '1' and bit_cnt_unary(0) = '1' then + receiving <= '0'; + end if; + + end if; + + end process pREGEN; + +end architecture rtl; diff --git a/generic_ip/pof_protocol/1/src/pof_uart_rx_1.vhd b/generic_ip/pof_protocol/1/src/pof_uart_rx_1.vhd new file mode 100644 index 0000000..7f25f41 --- /dev/null +++ b/generic_ip/pof_protocol/1/src/pof_uart_rx_1.vhd @@ -0,0 +1,126 @@ +------------------------------------------------------------------------------- +-- Title : pof_uart_rx +-- Project : EMB-1 +------------------------------------------------------------------------------- +-- File : pof_uart_rx.vhd +-- Author : Gianmarco Girau/Simon Southwell +-- Company : Global Inkjet Systems +-- Created : 2016-10-24 +-- Last update: 2019-09-27 +-- SVN ID : Git +-- Standard : VHDL'08 +------------------------------------------------------------------------------- +-- Description: +-- Simple UART receiver, used to receive data over the POF, 1 start, 1 stop +-- bit, no parity +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity pof_uart_rx_1 is + generic( + GEN_BIT_DIV : integer := 6; + data_width : natural range 1 to 31 := 8 + ); + port( + reset_n : in std_logic; + clk : in std_logic; + init : in std_logic; + data_out : out std_logic_vector(data_width - 1 downto 0); + data_out_valid : out std_logic; + rx_error : out std_logic; + rx_data : in std_logic); +end entity pof_uart_rx_1; + +architecture rtl of pof_uart_rx_1 is + + signal rx_data_i : std_logic; + signal data : std_logic_vector(data_width + 1 downto 0); + + signal bit_cnt_unary : std_logic_vector(data_width + 1 downto 0); + signal sample_cnt_unary : std_logic_vector(GEN_BIT_DIV-1 downto 0); + signal receiving : std_logic; + signal init_int : std_logic := '0'; + +begin + + ----------------------------------------------------------------------------- + -- Input Synchronization + ----------------------------------------------------------------------------- + + iSYNC_IN : entity work.sync_wire + generic map( + rst_val => '1', + sync_stages => 3) + port map( + rstN => reset_n, + clk => clk, + async_in => rx_data, + sync_out => rx_data_i); + + ----------------------------------------------------------------------------- + -- UART registers and sequential logic + ----------------------------------------------------------------------------- + + pRX : process(clk) + begin + if clk = '1' and clk'event then + + init_int <= init; + + -- Data out valid will pulse + data_out_valid <= '0'; + rx_error <= '0'; + + -- If initialising, only clear control state + if init_int = '1' then + + receiving <= '0'; + bit_cnt_unary <= std_logic_vector(to_unsigned(1, bit_cnt_unary'length)); + sample_cnt_unary <= std_logic_vector(to_unsigned(1, sample_cnt_unary'length)); + + else + + -- If start bit seen when not receiving, start receiving and start unary sample count shifting (with rotation). + -- Keep rotating whilst receiving. + if (receiving = '0' and rx_data_i = '0') or receiving = '1' then + receiving <= '1'; + sample_cnt_unary <= sample_cnt_unary(sample_cnt_unary'high-1 downto 0) & sample_cnt_unary(sample_cnt_unary'high); + end if; + + end if; + + -- At half way shift in the data (LSB first) and shift (with rotation) the unary bit count + if sample_cnt_unary(GEN_BIT_DIV/2 - 1) = '1' then + data <= rx_data_i & data(data'high downto 1); + end if; + + -- After half way, up the bit count + if sample_cnt_unary(GEN_BIT_DIV/2) = '1' then + bit_cnt_unary <= bit_cnt_unary(bit_cnt_unary'high-1 downto 0) & bit_cnt_unary(bit_cnt_unary'high); + end if; + + -- Extract the payload bits from the input shift register + data_out <= data(data_width downto 1); + + -- If at the end of the last (stop) bit, update data out and set valid. + -- Clear the receiving state. + if sample_cnt_unary(GEN_BIT_DIV-1) = '1' and bit_cnt_unary(0) = '1' then + + -- Data is valid if stop bit a 1 + data_out_valid <= data(data_width+1); + + -- It is an error if the stop bit is 0 + rx_error <= not data(data_width+1); + + -- Clear receiving flag + receiving <= '0'; + end if; + + end if; + end process pRX; + +end architecture rtl; diff --git a/generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd b/generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd index 9b32c09..2dac5e2 100644 --- a/generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd +++ b/generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd @@ -6,7 +6,7 @@ -- Author : GMG -- Company : Global Inkjet Systems -- Created : 2017-08-29 --- Last update: 2019-09-23 +-- Last update: 2019-09-26 -- SVN ID : Git -- Standard : VHDL'2008 ------------------------------------------------------------------------------- @@ -44,11 +44,14 @@ architecture behav of pof_tx_rx_1_tb is constant DISCR_THRES : natural := 1000; constant TIME_INT : time := 800 ns; - constant UART_BIT_DIV : std_logic_vector(3 downto 0) := "0110"; -- divide by 6 + constant UART_BIT_DIV : integer := 6; -- divide by 6 constant SYMBOL_LEN : natural := 8; -- UART symbol length, excluding -- start/stop and parity bits + -- Print-Start toggling period + constant PS_SWITCH_PER : natural := 5000; + -- Logging Verbosity Level constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM; @@ -59,7 +62,8 @@ architecture behav of pof_tx_rx_1_tb is signal init_tx, init_rx, dir_in, pd_in, inc_pos, dec_pos : std_logic; signal tx_data, rx_data, init_out, dir_out : std_logic; signal pd_out, inc_pos_out, dec_pos_out, end_of_swathe : std_logic; - signal print_start, print_start_out : std_logic; + signal print_start_in, print_start_out : std_logic; + signal ps_flip_cnt : natural := 0; -- signal test_completed, running, configuring : boolean; signal passed, failed, stimuli_completed : boolean; @@ -76,7 +80,7 @@ architecture behav of pof_tx_rx_1_tb is signal pos_discr_cnt : integer; signal pd_in_cnt, pd_out_cnt : integer; signal enc_pulse_cnt : integer; - signal dir_err, pd_err, ovfl_err : std_logic; + signal dir_err, pd_err, ovfl_err, ps_err : std_logic; signal pos_err, enc_err, dir_in_d : std_logic; signal injected_errors : integer; signal max_pos, min_pos : integer; @@ -116,7 +120,7 @@ begin -- architecture behav clk => clk, init => init_tx, pd_in => pd_in, - print_start => '0', + print_start => print_start_in, inc_pos => inc_pos, dec_pos => dec_pos, abs_position => abs_position, @@ -129,6 +133,8 @@ begin -- architecture behav avs_readdata => avs_readdata_sl0); iPOF_RX : entity work.pof_rx_1 + generic map( + GEN_BIT_DIV => UART_BIT_DIV) port map( reset_n => reset_n, clk => clk, @@ -142,7 +148,6 @@ begin -- architecture behav dec_pos => dec_pos_out, abs_pos => abs_pos_out, enable => enable_rx, - bit_div => UART_BIT_DIV, error_rate_thres => error_rate_thres, one_pps => one_pps, max_error_flag => max_error_flag, @@ -255,8 +260,20 @@ begin -- architecture behav pSTIMULI_REGs : process(clk) begin - if (clk = '1' and clk'event) then + if(reset_n = '0') then + abs_position_d <= (others => '0'); + print_start_in <= '0'; + ps_flip_cnt <= 0; + elsif(clk = '1' and clk'event) then abs_position_d <= abs_position; + if(running = true) then + if(ps_flip_cnt = PS_SWITCH_PER-1) then + ps_flip_cnt <= 0; + print_start_in <= not print_start_in; + else + ps_flip_cnt <= ps_flip_cnt + 1; + end if; + end if; end if; end process pSTIMULI_REGs; @@ -520,6 +537,11 @@ begin -- architecture behav elsif (end_of_swathe = '1' and enc_pulse_cnt /= SWATHE_LEN) then enc_err <= '1'; end if; + if(reset_n = '0') then + ps_err <= '0'; + elsif(running = true and ps_flip_cnt = integer(0.9*real(PS_SWITCH_PER)) and print_start_out /= print_start_in) then + ps_err <= '1'; + end if; max_pos_d <= max_pos; min_pos_d <= min_pos; if ((dir_in = '0' and max_pos /= max_pos_d) or (dir_in = '1' and min_pos /= min_pos_d)) then @@ -556,8 +578,7 @@ begin -- architecture behav if (reset_n = '0') then detected_error <= false; elsif (clk = '1' and clk'event) then - --if(ovfl_err = '1' or dir_err = '1' or pd_err = '1' or pos_err = '1' or enc_err = '1') then - if (ovfl_err = '1' or dir_err = '1' or pd_err = '1' or pos_err = '1') then + if (ovfl_err = '1' or dir_err = '1' or pd_err = '1' or pos_err = '1' or ps_err = '1') then detected_error <= true; end if; end if; diff --git a/generic_ip/pof_protocol/1/src/uart_regen_1.vhd b/generic_ip/pof_protocol/1/src/uart_regen_1.vhd deleted file mode 100644 index 11fd454..0000000 --- a/generic_ip/pof_protocol/1/src/uart_regen_1.vhd +++ /dev/null @@ -1,160 +0,0 @@ -------------------------------------------------------------------------------- --- Title : uart_regen --- Project : EMB-1 -------------------------------------------------------------------------------- --- File : uart_regen.vhd --- Author : Gianmarco Girau --- Company : Global Inkjet Systems --- Created : 2017-10-31 --- Last update: 2019-09-24 --- SVN ID : Git --- Standard : VHDL'08 -------------------------------------------------------------------------------- --- Description: --- Regenerate the UART signal -------------------------------------------------------------------------------- --- altera vhdl_input_version vhdl_2008 - -library ieee; -use ieee.std_logic_1164.all; -use ieee.numeric_std.all; - -entity uart_regen_1 is - generic( - data_width : natural range 1 to 31); - port( - reset_n : in std_logic; - clk : in std_logic; - bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit - enable : in std_logic; - bypass_en : in std_logic; - uart_rx : in std_logic; - uart_tx : out std_logic); -end entity uart_regen_1; - -architecture rtl of uart_regen_1 is - - type fsm_state_t is (s_init, s_idle, s_regen); - - signal fsm_state_curr, fsm_state_next : fsm_state_t; - -- - signal uart_rx_i, ld_data, rst_bit_cnt, inc_bit_cnt : std_logic; - signal rst_clk_cnt, end_of_bit, end_of_rx : std_logic; - signal uart_regen, uart_regen_i : std_logic; - -- - signal clk_cnt : std_logic_vector(3 downto 0); - signal bit_cnt : std_logic_vector(5 downto 0); - -begin - - ----------------------------------------------------------------------------- - -- Input Synchronization - ----------------------------------------------------------------------------- - - iSYNC_IN : entity work.sync_wire - generic map( - rst_val => '1', - sync_stages => 3) - port map( - rstN => reset_n, - clk => clk, - async_in => uart_rx, - sync_out => uart_rx_i); - - -- NOTE : No NEED TO SYNCHRONIZE TO THE LOCAL CLOCK inputs enable, bypass_en - -- and bit_biv BECAUSE THOSE SIGNALS ARE PREDOMINANTLY STATIC - - ----------------------------------------------------------------------------- - -- UART registers and sequential logic - ----------------------------------------------------------------------------- - - pREGs : process(clk) - begin - if (clk = '1' and clk'event) then - if (rst_bit_cnt = '1') then - bit_cnt <= (others => '0'); - elsif (inc_bit_cnt = '1') then - bit_cnt <= std_logic_vector(unsigned(bit_cnt) + 1); - end if; - ld_data <= '0'; - if clk_cnt = ('0' & std_logic_vector(unsigned(bit_div(bit_div'high downto 1)) + 1)) then - ld_data <= '1'; - end if; - - if (rst_clk_cnt = '1' or end_of_bit = '1') then - clk_cnt <= std_logic_vector(unsigned(bit_div) - 1); - else - clk_cnt <= std_logic_vector(unsigned(clk_cnt) - 1); - end if; - if (enable = '0') then - uart_regen_i <= '1'; - elsif (ld_data = '1') then - uart_regen_i <= uart_rx_i; - end if; - uart_regen <= uart_regen_i; - end if; - end process pREGs; - - end_of_bit <= '1' when unsigned(clk_cnt) = 0 else '0'; - end_of_rx <= '1' when unsigned(bit_cnt) = data_width + 1 else '0'; - - -- output mux - uart_tx <= uart_rx when bypass_en = '1' else uart_regen; - - ----------------------------------------------------------------------------- - -- FSM - ----------------------------------------------------------------------------- - - -- FSM state register - pFSM_SR : process(clk) - begin - if (clk = '1' and clk'event) then - if (enable = '0' or bypass_en = '1') then - fsm_state_curr <= s_init; - else - fsm_state_curr <= fsm_state_next; - end if; - end if; - end process pFSM_SR; - - -- FSM Combinational Logic - pFSM_CL : process(fsm_state_curr, uart_rx_i, end_of_bit, end_of_rx, clk_cnt, bit_div) - begin - --default assignments - rst_clk_cnt <= '0'; - rst_bit_cnt <= '0'; - inc_bit_cnt <= '0'; - -- - fsm_state_next <= fsm_state_curr; - - case fsm_state_curr is - when s_init => - if (uart_rx_i = '1') then - fsm_state_next <= s_idle; - end if; - - when s_idle => - if (uart_rx_i = '0') then - rst_clk_cnt <= '1'; - rst_bit_cnt <= '1'; - fsm_state_next <= s_regen; - end if; - - when s_regen => - - if (end_of_bit = '1') then - inc_bit_cnt <= '1'; - if (end_of_rx = '1') then - if (uart_rx_i = '1') then - fsm_state_next <= s_idle; - else - fsm_state_next <= s_init; - end if; - end if; - end if; - - end case; - end process pFSM_CL; - - -end architecture rtl; diff --git a/generic_ip/pof_protocol/1/src/uart_rx_1.vhd b/generic_ip/pof_protocol/1/src/uart_rx_1.vhd deleted file mode 100644 index 57ca45b..0000000 --- a/generic_ip/pof_protocol/1/src/uart_rx_1.vhd +++ /dev/null @@ -1,186 +0,0 @@ -------------------------------------------------------------------------------- --- Title : uart_rx --- Project : EMB-1 -------------------------------------------------------------------------------- --- File : uart_rx.vhd --- Author : Gianmarco Girau --- Company : Global Inkjet Systems --- Created : 2016-10-24 --- Last update: 2019-09-20 --- SVN ID : Git --- Standard : VHDL'08 -------------------------------------------------------------------------------- --- Description: --- Simple UART receiver, used to receive data over the POF, 1 start, 1 stop --- bit, no parity -------------------------------------------------------------------------------- --- altera vhdl_input_version vhdl_2008 - -library ieee; -use ieee.std_logic_1164.all; -use ieee.numeric_std.all; - -entity uart_rx_1 is - generic( - data_width : natural range 1 to 31); - port( - reset_n : in std_logic; - clk : in std_logic; - bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit - init : in std_logic; - data_out : out std_logic_vector(data_width - 1 downto 0); - data_out_valid : out std_logic; - rx_error : out std_logic; - rx_data : in std_logic); -end entity uart_rx_1; - -architecture rtl of uart_rx_1 is - - type fsm_state_t is (s_init, s_idle, s_get_start_bit, s_get_data, s_get_stop_bit); - - signal fsm_state_curr, fsm_state_next : fsm_state_t; - -- - signal rx_data_i, rst_bit_cnt, inc_bit_cnt : std_logic; - signal rst_clk_cnt, end_of_rx, data_valid : std_logic; - signal stop_bit, rx_error_i : std_logic; - -- - signal data : std_logic_vector(data_width - 1 downto 0); - signal bit_cnt : std_logic_vector(5 downto 0); - - -- avoid maths with loadable shift registers - -- bit_div will be used to set an indexed bit of the timer shift register - -- the timers will shift down towards zeroth bit which will indicate timer has completed. - -- this should be faster than using a decrementer and comparators - signal uart_bit_timer, uart_bit_sample_timer : std_logic_vector(2**bit_div'length - 1 downto 0); - signal uart_bit_timer_load_value, uart_bit_sample_timer_load_value : std_logic_vector(2**bit_div'length - 1 downto 0); - - signal end_of_bit : std_logic; - signal shf_data : std_logic; - -begin - - ----------------------------------------------------------------------------- - -- Input Synchronization - ----------------------------------------------------------------------------- - - iSYNC_IN : entity work.sync_wire - generic map( - rst_val => '1', - sync_stages => 3) - port map( - rstN => reset_n, - clk => clk, - async_in => rx_data, - sync_out => rx_data_i); - - ----------------------------------------------------------------------------- - -- UART registers and sequential logic - ----------------------------------------------------------------------------- - - pREGs : process(clk) - begin - if (clk = '1' and clk'event) then - if (rst_bit_cnt = '1') then - bit_cnt <= (others => '0'); - elsif (inc_bit_cnt = '1') then - bit_cnt <= std_logic_vector(unsigned(bit_cnt) + 1); - end if; - if (rst_clk_cnt = '1' or end_of_bit = '1') then - uart_bit_timer <= uart_bit_timer_load_value; - uart_bit_sample_timer <= uart_bit_sample_timer_load_value; - else - uart_bit_timer <= '0' & uart_bit_timer(uart_bit_timer'high downto 1); - uart_bit_sample_timer <= '0' & uart_bit_sample_timer(uart_bit_sample_timer'high downto 1); - end if; - if (shf_data = '1') then - data <= rx_data_i & data(data'high downto 1); - end if; - data_out_valid <= data_valid; - if (data_valid = '1') then - data_out <= data; - end if; - rx_error <= rx_error_i; - uart_bit_timer_load_value <= (others => '0'); - uart_bit_timer_load_value(to_integer(unsigned(bit_div) -1 )) <= '1'; - uart_bit_sample_timer_load_value <= (others => '0'); - uart_bit_sample_timer_load_value(to_integer( unsigned(bit_div(bit_div'high downto 1)) -1)) <= '1'; - end if; - end process pREGs; - - shf_data <= uart_bit_sample_timer(0) and not stop_bit; - end_of_bit <= uart_bit_timer(0); - end_of_rx <= '1' when unsigned(bit_cnt) = data_width else '0'; - - ----------------------------------------------------------------------------- - -- FSM - ----------------------------------------------------------------------------- - - -- FSM state register - pFSM_SR : process(clk) - begin - if (clk = '1' and clk'event) then - if (init = '1') then - fsm_state_curr <= s_init; - else - fsm_state_curr <= fsm_state_next; - end if; - end if; - end process pFSM_SR; - - -- FSM Combinational Logic - pFSM_CL : process(all) - begin - --default assignments - rst_clk_cnt <= '0'; - rst_bit_cnt <= '0'; - inc_bit_cnt <= '0'; - data_valid <= '0'; - stop_bit <= '0'; - rx_error_i <= '0'; - -- - fsm_state_next <= fsm_state_curr; - - case fsm_state_curr is - when s_init => - if (rx_data_i = '1') then - fsm_state_next <= s_idle; - end if; - - when s_idle => - if (rx_data_i = '0') then - rst_clk_cnt <= '1'; - rst_bit_cnt <= '1'; - fsm_state_next <= s_get_start_bit; - end if; - - when s_get_start_bit => - if (end_of_bit = '1') then - inc_bit_cnt <= '1'; - fsm_state_next <= s_get_data; - end if; - - when s_get_data => - if (end_of_bit = '1') then - inc_bit_cnt <= '1'; - if (end_of_rx = '1') then - fsm_state_next <= s_get_stop_bit; - end if; - end if; - - when s_get_stop_bit => - stop_bit <= '1'; - if (end_of_bit = '1') then - if (rx_data_i = '1') then - data_valid <= '1'; - fsm_state_next <= s_idle; - else - rx_error_i <= '1'; - fsm_state_next <= s_init; - end if; - end if; - - end case; - end process pFSM_CL; - - -end architecture rtl;