diff --git a/libraries/base/dp/src/vhdl/dp_block_validate_bsn_at_sync.vhd b/libraries/base/dp/src/vhdl/dp_block_validate_bsn_at_sync.vhd index 52843298d1163625c6e04489a017bf6d0555d035..47cb45bade13a28402e6d47080299feca2963957 100644 --- a/libraries/base/dp/src/vhdl/dp_block_validate_bsn_at_sync.vhd +++ b/libraries/base/dp/src/vhdl/dp_block_validate_bsn_at_sync.vhd @@ -190,9 +190,14 @@ BEGIN out_reg => OPEN -- no write ); - p_bsn_check : PROCESS(bs_sosi, in_sosi, bsn_at_sync_reg, bsn_ok_reg) + -- Process to check the bsn at sync. It captures the bsn at the sync of bs_sosi. Then compares that bsn to + -- the bsn at sync of in_sosi. If they are unequal all packets during that sync period with in_sosi.channel + -- equal to g_check_channel are discarded. + p_bsn_check : PROCESS(bs_sosi, in_sosi, bsn_at_sync_reg, bsn_ok_reg, out_valid_reg) + -- v_bsn_ok used for the first in_sosi packet of a sync period as sync and sop are both '1'. VARIABLE v_bsn_ok : STD_LOGIC; - VARIABLE v_bsn_at_sync : STD_LOGIC_VECTOR(g_bsn_w-1 DOWNTO 0); + -- Using v_bsn_at_sync to ensure correct behavior when in_sosi has no latency compared to bs_sosi. + VARIABLE v_bsn_at_sync : STD_LOGIC_VECTOR(g_bsn_w-1 DOWNTO 0); BEGIN v_bsn_at_sync := bsn_at_sync_reg; v_bsn_ok := bsn_ok_reg; @@ -202,30 +207,32 @@ BEGIN v_bsn_at_sync := bs_sosi.bsn; END IF; - IF in_sosi.sync = '1' AND TO_UINT(in_sosi.channel) = g_check_channel THEN - IF in_sosi.bsn = v_bsn_at_sync THEN - v_bsn_ok := '1'; - ELSE - v_bsn_ok := '0'; + IF TO_UINT(in_sosi.channel) = g_check_channel THEN + -- Compare bsn at sync of in_sosi to bsn at sync of bs_sosi. + IF in_sosi.sync = '1' THEN + IF in_sosi.bsn = v_bsn_at_sync THEN + v_bsn_ok := '1'; + ELSE + v_bsn_ok := '0'; + END IF; END IF; - END IF; - IF in_sosi.sop = '1' THEN - IF TO_UINT(in_sosi.channel) = g_check_channel THEN + -- Setting out_valid to control the discarding at packet level. + IF in_sosi.sop = '1' THEN out_valid <= v_bsn_ok; - ELSE - out_valid <= '1'; END IF; - END IF; - - IF TO_UINT(in_sosi.channel) = g_check_channel THEN + + -- set cnt_discarded_en to control u_discarded_counter. cnt_discarded_en <= in_sosi.sync AND NOT v_bsn_ok; ELSE - cnt_discarded_en <= '0'; - END IF; + IF in_sosi.sop = '1' THEN + out_valid <= '1'; -- Packets with channel unequal to g_check_channel are always valid + END IF; - bsn_ok <= v_bsn_ok; - bsn_at_sync <= v_bsn_at_sync; + cnt_discarded_en <= '0'; -- Packets with channel unequal to g_check_channel cannot be discarded. + END IF; + bsn_ok <= v_bsn_ok; -- bsn_ok is used to indicate if the bsn is correct for the entire sync period of g_check_channel. + bsn_at_sync <= v_bsn_at_sync; -- register to store the bsn at sync of bs_sosi. END PROCESS; p_dp_clk : PROCESS(dp_rst, dp_clk) diff --git a/libraries/base/dp/tb/vhdl/tb_dp_block_validate_bsn_at_sync.vhd b/libraries/base/dp/tb/vhdl/tb_dp_block_validate_bsn_at_sync.vhd index 5269a6923cb0b3a05c6b651dd4074591d49a2c04..66b17b21e6b6e30dceac514bc18c57853235de39 100644 --- a/libraries/base/dp/tb/vhdl/tb_dp_block_validate_bsn_at_sync.vhd +++ b/libraries/base/dp/tb/vhdl/tb_dp_block_validate_bsn_at_sync.vhd @@ -63,7 +63,8 @@ ARCHITECTURE tb OF tb_dp_block_validate_bsn_at_sync IS CONSTANT c_gap_size : NATURAL := 4; CONSTANT c_nof_sync : NATURAL := 5; CONSTANT c_nof_blk : NATURAL := g_nof_blocks_per_sync * c_nof_sync; - CONSTANT c_check_channel : NATURAL := g_nof_blocks_per_sync; + -- choosing c_check_channel such that it corresponds with a channel from stimuli on a sync because the channel field is generated by a counter. + CONSTANT c_check_channel : NATURAL := g_nof_blocks_per_sync; -- can be c_check_channel MOD g_nof_blocks_per_sync = 0 but not larger than c_nof_blk. SIGNAL dp_clk : STD_LOGIC := '1'; SIGNAL mm_clk : STD_LOGIC := '1'; @@ -191,7 +192,8 @@ BEGIN VARIABLE v_valid_blk : BOOLEAN := TRUE; BEGIN IF rising_edge(dp_clk) THEN - IF reference_sosi.sop = '1' THEN + IF reference_sosi.sop = '1' THEN --Decide for each block if it should be valid. + -- A block can only be discarded if its channel field corresponds with the check_channel. IF g_bsn_init >= g_nof_blocks_per_sync AND TO_UINT(reference_sosi.channel) = c_check_channel THEN v_valid_blk := FALSE; ELSE