Commit a08f2147 authored by Ille, Ondrej, Ing.'s avatar Ille, Ondrej, Ing.

Merge branch '126-extend-bit-stuffing-unit-test' into 'master'

Resolve "Extend bit stuffing unit test"

Closes #126

See merge request illeondr/CAN_FD_IP_Core!76
parents 97e9d740 c7fee8ca
......@@ -59,18 +59,15 @@
-- 2.Added keeping previous value of dst_counter when circuit is
-- disabled instead of erasing! This way ciruit is compatible
-- with bit stuffing!
-- 3.dst_bit_ctr value kept when destuffing error occured for
-- correct behaviour in testbench. This is only a small thing
-- since when stuff error occurs bit stuffing is turned off
-- immediately due to error frame transmittion and dst_ctr is
-- not needed anymore!!!
-- 4.Added warning when bit stuffing rule is set to 0 or 1 which
-- 3.Added warning when bit stuffing rule is set to 0 or 1 which
-- is invalid setting!
-- 12.1.2017 Changed priority of fixed bit-destuffing processing. Fixed bit
-- destuffing should always have higher priority than non-fixed
-- bit-destuffing and thus be before in the If-elsif condition!
-- This is due to possible conflic of normal and fixed bit destu-
-- ffing in the start of FD CRC. Fixed bit-destuff should win!
-- 23.5.2018 Bug-fix of stuff error detection. Stuff error on special
-- stuff-bit in first bit of CRC also must be detected.
--------------------------------------------------------------------------------
library ieee;
......@@ -79,203 +76,209 @@ use IEEE.numeric_std.all;
use WORK.CANconstants.all;
entity bitDestuffing is
port(
-------------------
--Clock And Reset--
-------------------
signal clk_sys : in std_logic; --System clock
signal res_n : in std_logic; --Async Reset
-------------------------
--Bus Sampling Interface-
-------------------------
signal data_in : in std_logic; --Sampled data from busSync.vhd
-----------------------
--Prescaler interface -
-----------------------
--Triggering signal with one clk_sys delay behind the used sampling signal
signal trig_spl_1 : in std_logic;
--Note: signals nbt_trig_spl_1 or dbt_trig_spl_1 can be used
-- depending whenever data bit time or nominal bit tim is used
--------------------
--Error Signalling--
--------------------
signal stuff_Error : out std_logic; --Stuff Error
-----------------------
--CAN Core interface --
-----------------------
--Data output for CAN Core
signal data_out : out std_logic;
--Signal that data on output are not valid but it is a stuff bit
signal destuffed : out std_logic;
--Enable of the circuit
signal enable : in std_logic;
--Enable stuff Error logging
signal stuff_Error_enable : in std_logic;
--Whenever fixed bit Destuffing method is used
signal fixed_stuff : in std_logic;
--Length of bit stuffing rule
signal length : in std_logic_vector(2 downto 0);
--Number of destuffed bits with regular bit stuffing method
signal dst_ctr : out natural range 0 to 7
);
--Note:Bit Destuffing has no driving bus aliases
---------------------------------
--Internal signals and registers
---------------------------------
--Number of equal consecutive bits
signal same_bits : natural range 0 to 15;
signal prev_val : std_logic; --Previous value of the bit
signal destuffed_reg : std_logic; --Registered value of destuffed
signal error_reg : std_logic; --Registred value of destuffed
signal enable_prev : std_logic; --Previous value of enable
signal fixed_prev : std_logic; --Previous value of fixed stuff method
--ISO CAN FD destuff bit counter
signal dst_bit_ctr : natural range 0 to 7;
--Note: Number of stuffed, destuffed bits is transmitted modulo 8. Thus
-- only 3 bits counter is enough!!
port(
------------------------------------------------------------------------
-- Clock And Reset
------------------------------------------------------------------------
signal clk_sys : in std_logic;
signal res_n : in std_logic;
end entity;
------------------------------------------------------------------------
-- Bus Sampling Interface
------------------------------------------------------------------------
signal data_in : in std_logic;
architecture rtl of bitDestuffing is
begin
------------------------------------------------------------------------
-- Prescaler interface
------------------------------------------------------------------------
-- Triggering signal with one clk_sys delay behind the used
-- sampling signal
signal trig_spl_1 : in std_logic;
-----------------------
--Destuffing process
-----------------------
destuf_proc : process(res_n, clk_sys)
begin
if(res_n = ACT_RESET)then
same_bits <= 1;
prev_val <= RECESSIVE;
fixed_prev <= '0';
destuffed_reg <= '0';
error_reg <= '0';
--Bit stuff counter for ISO FD
dst_bit_ctr <= 0;
enable_prev <= '0';
elsif (rising_edge(clk_sys))then
--Edge detection on enable and fixed stuff
enable_prev <= enable;
dst_bit_ctr <= dst_bit_ctr;
if((length = "000" or length = "001")and (enable='1'))then
report "0 and 1 bit stuffing length is invalid" severity warning;
end if;
if(enable = '1')then
--When transition starts prev_val needs to be deleted! Otherwise
--stuff error might occur when first bits of identifier are zero
if(enable_prev = '0')then
prev_val <= RECESSIVE;
dst_bit_ctr <= 0;
fixed_prev <= '0';
same_bits <= 1;
--Destuffing is processed with triggering signal
elsif(trig_spl_1 = '1')then
prev_val <= data_in; --Data is always propagated
--When stuffing method is changed in the beginning of the
--CRC field the stuffing counter needs to be erased!
if(fixed_stuff = '1' and fixed_prev = '0')then
prev_val <= RECESSIVE;
same_bits <= 1; --TODO: think if here shouldnt be zero
-- due to extra inserted stuff bit!!!
destuffed_reg <= '1';
fixed_prev <= fixed_stuff;
--If number of bits was reached then
elsif(same_bits = unsigned(length) and fixed_stuff = '0')or
(same_bits = unsigned(length)+1 and fixed_stuff = '1')then
--Fixed stuff is must be plus one since also the stuffed bit is
--counted! In normal bit stuffing when bit is stuffed same_bits is
--erased and counted from first bit after stuffed bit!
destuffed_reg <= '1';
same_bits <= 1;
------------------------------------------------------------------------
--Error Signalling
------------------------------------------------------------------------
--Stuff bit occured increase the stuffing counter!
--but only in the case of the original stuffing method
if(fixed_stuff = '0')then
dst_bit_ctr <= (dst_bit_ctr+1) mod 8;
else
dst_bit_ctr <= dst_bit_ctr;
end if;
-- Stuff error detected when stuff rule is
signal stuff_Error : out std_logic;
--Stuff Rule violation
if(prev_val = data_in and stuff_Error_enable = '1')then
error_reg <= '1';
dst_bit_ctr <= dst_bit_ctr;
else
error_reg <= '0';
end if;
------------------------------------------------------------------------
--CAN Core interface
------------------------------------------------------------------------
--If number of bits not reached then
--only increase number of same bits
else
-- Data output for CAN Core
signal data_out : out std_logic;
if(data_in = prev_val) or (fixed_stuff = '1')then
same_bits <= (same_bits+1) mod 8;
else
same_bits <= 1;
end if;
-- Signal that data on output are not valid but it is a stuff bit
signal destuffed : out std_logic;
--Trigger not occured keep the value of the
--stuff counter
dst_bit_ctr <= dst_bit_ctr;
-- Enable of the circuit
signal enable : in std_logic;
destuffed_reg <= '0';
error_reg <= '0';
-- Enable stuff Error logging
signal stuff_Error_enable : in std_logic;
end if;
-- Whenever fixed bit Destuffing method is used
signal fixed_stuff : in std_logic;
--Trigger not occured keep the previous values
else
same_bits <= same_bits;
prev_val <= prev_val;
destuffed_reg <= destuffed_reg;
error_reg <= '0';
dst_bit_ctr <= dst_bit_ctr;
-- Length of bit stuffing rule
signal length : in std_logic_vector(2 downto 0);
-- Number of destuffed bits with regular bit stuffing method
signal dst_ctr : out natural range 0 to 7
);
----------------------------------------------------------------------------
--Internal signals and registers
----------------------------------------------------------------------------
--Number of equal consecutive bits
signal same_bits : natural range 0 to 15;
signal prev_val : std_logic; -- Previous value of the bit
signal destuffed_reg : std_logic; -- Registered value of destuffed
signal error_reg : std_logic; -- Registred value of destuffed
signal enable_prev : std_logic; -- Previous value of enable
signal fixed_prev : std_logic; -- Previous value of fixed stuff
-- ISO CAN FD destuff bit counter
signal dst_bit_ctr : natural range 0 to 7;
-- Note: Number of stuffed, destuffed bits is transmitted modulo 8. Thus
-- only 3 bits counter is enough!!
end entity;
architecture rtl of bitDestuffing is
begin
----------------------------------------------------------------------------
-- Destuffing process
---------------------------------------------------------------------------
destuf_proc : process(res_n, clk_sys)
begin
if (res_n = ACT_RESET) then
same_bits <= 1;
prev_val <= RECESSIVE;
fixed_prev <= '0';
destuffed_reg <= '0';
error_reg <= '0';
-- Bit stuff counter for ISO FD
dst_bit_ctr <= 0;
enable_prev <= '0';
elsif (rising_edge(clk_sys)) then
-- Edge detection on enable and fixed stuff
enable_prev <= enable;
dst_bit_ctr <= dst_bit_ctr;
if ((length = "000" or length = "001") and (enable = '1')) then
report "0 and 1 bit stuffing length is invalid" severity warning;
end if;
else
same_bits <= 1;
destuffed_reg <= '0';
error_reg <= '0';
dst_bit_ctr <= dst_bit_ctr;
if (enable = '1') then
-- When transition starts prev_val needs to be deleted! Otherwise
-- stuff error might occur when first bits of identifier are zero
if (enable_prev = '0') then
prev_val <= RECESSIVE;
dst_bit_ctr <= 0;
fixed_prev <= '0';
same_bits <= 1;
-- Destuffing is processed with triggering signal
elsif (trig_spl_1 = '1') then
prev_val <= data_in; --Data is always propagated
fixed_prev <= fixed_stuff;
--When stuffing method is changed in the beginning of the
--CRC field the stuffing counter needs to be erased!
if (fixed_stuff = '1' and fixed_prev = '0') then
prev_val <= RECESSIVE;
same_bits <= 1;
destuffed_reg <= '1';
-- Stuff Rule violation
if (prev_val = data_in and stuff_Error_enable = '1') then
error_reg <= '1';
else
error_reg <= '0';
end if;
--If number of bits was reached then
elsif (same_bits = unsigned(length) and fixed_stuff = '0') or
(same_bits = unsigned(length) + 1 and fixed_stuff = '1')
-- Fixed stuff must be plus one since also the stuffed bit is
-- counted! In normal bit stuffing when bit is stuffed same_bits
-- is erased and counted from first bit after stuffed bit!
then
destuffed_reg <= '1';
same_bits <= 1;
-- Stuff bit occured increase the stuffing counter!
-- but only in the case of the original stuffing method
if (fixed_stuff = '0') then
dst_bit_ctr <= (dst_bit_ctr + 1) mod 8;
else
dst_bit_ctr <= dst_bit_ctr;
end if;
-- Stuff Rule violation
if (prev_val = data_in and stuff_Error_enable = '1') then
error_reg <= '1';
else
error_reg <= '0';
end if;
-- If number of bits not reached then
-- only increase number of same bits
else
if (data_in = prev_val) or (fixed_stuff = '1') then
same_bits <= (same_bits + 1) mod 8;
else
same_bits <= 1;
end if;
-- Trigger not occured keep the value of stuff counter
dst_bit_ctr <= dst_bit_ctr;
destuffed_reg <= '0';
error_reg <= '0';
end if;
--Trigger not occured keep the previous values
else
same_bits <= same_bits;
prev_val <= prev_val;
destuffed_reg <= destuffed_reg;
error_reg <= '0';
dst_bit_ctr <= dst_bit_ctr;
end if;
--Sample the data with trigger even if destuffing
-- is disabled
if(trig_spl_1 = '1')then
prev_val <= data_in;
else
prev_val <= prev_val;
end if;
same_bits <= 1;
destuffed_reg <= '0';
error_reg <= '0';
dst_bit_ctr <= dst_bit_ctr;
end if;
-- Sample the data with trigger even if destuffing
-- is disabled
if (trig_spl_1 = '1') then
prev_val <= data_in;
else
prev_val <= prev_val;
end if;
end if;
end if;
end process;
end process;
--Register propagation on output
-- Register propagation on output
data_out <= data_in;
destuffed <= destuffed_reg;
stuff_Error <= error_reg;
......
......@@ -74,71 +74,71 @@ USE IEEE.numeric_std.ALL;
USE WORK.CANconstants.ALL;
entity bitStuffing_v2 is
port(
-------------------------
--Clock and Async reset--
-------------------------
signal clk_sys :in std_logic;
signal res_n :in std_logic;
---------------------------------
--Prescaler interface - sampling-
---------------------------------
--Trigger signal for propagating the data
--(one clk_sys delayed behind beginning of bit time)
signal tran_trig_1 :in std_logic;
-----------------------
--CAN Core interface --
-----------------------
--Enabling the operation of the circuit
signal enable :in std_logic;
signal data_in :in std_logic; --Data Input sampled
--Whenever fixed bit stuffing should be used (CAN FD Option)
signal fixed_stuff :in std_logic;
--Logic 1 signals stuffed bit for CAN Core. CAN Core has to halt the
--data sending for one bit-time
signal data_halt :out std_logic;
--Length of Bit Stuffing
signal length :in std_logic_vector(2 downto 0);
--Note: "HandShake like" protocol between CAN Core is
-- easier implementation of bitStuffing than Bit-Stuffing with Buffer
signal bst_ctr :out natural range 0 to 7; --Bit stuffing counter
-------------------------
--Bus Synchro interface--
-------------------------
signal data_out :out std_logic --Data output
--Note: Data are sent into bus synchroniser but can be also
-- fed back to CAN Core for CRC calculation in CAN FD Phase!
port(
------------------------------------------------------------------------
-- Clock and Async reset
------------------------------------------------------------------------
signal clk_sys :in std_logic;
signal res_n :in std_logic;
------------------------------------------------------------------------
-- Prescaler interface - sampling
------------------------------------------------------------------------
--Trigger signal for propagating the data
--(one clk_sys delayed behind beginning of bit time)
signal tran_trig_1 :in std_logic;
------------------------------------------------------------------------
--CAN Core interface
------------------------------------------------------------------------
-- Enabling the operation of the circuit
signal enable :in std_logic;
-- Data Input sampled
signal data_in :in std_logic;
-- If fixed bit stuffing should be used (CRC of CAN FD)
signal fixed_stuff :in std_logic;
-- Logic 1 signals stuffed bit for CAN Core. CAN Core has to halt the
-- data sending for one bit-time
signal data_halt :out std_logic;
-- Length of Bit Stuffing
signal length :in std_logic_vector(2 downto 0);
-- Bit stuffing counter
signal bst_ctr :out natural range 0 to 7;
------------------------------------------------------------------------
--Bus Synchroniser interface
------------------------------------------------------------------------
signal data_out :out std_logic --Data output
--Note: Data are sent into bus synchroniser but can be also
-- fed back to CAN Core for CRC calculation in CAN FD Phase!
);
--Note: Bit Stufffing has no driving bus aliases, bit stuffing
--function cant be user controlled
----------------------
--Internal Registers--
----------------------
--Number of equal consequent bits
signal same_bits : natural range 0 to 7;
--Value of previously transcieved bit
signal prev_bit : std_logic;
signal halt_reg : std_logic; --Halt for CAN Core
--Registered value of fixed stuffing
signal fixed_prev : std_logic;
signal stuff_ctr : natural range 0 to 7;
signal enable_prev : std_logic;
);
----------------------------------------------------------------------------
-- Internal Registers
----------------------------------------------------------------------------
-- Number of equal consequent bits
signal same_bits : natural range 0 to 7;
-- Value of previously transcieved bit
signal prev_bit : std_logic;
-- Halt for CAN Core
signal halt_reg : std_logic;
-- Registered value of fixed stuffing
signal fixed_prev : std_logic;
signal stuff_ctr : natural range 0 to 7;
signal enable_prev : std_logic;
end entity;
......@@ -146,100 +146,99 @@ end entity;
architecture rtl of bitStuffing_v2 is
begin
bst_ctr <= stuff_ctr;
stuff_proc:process(res_n,clk_sys)
begin
if(res_n=ACT_RESET)then
same_bits <= 1;
prev_bit <= RECESSIVE;
halt_reg <= '0';
enable_prev <= '0';
stuff_ctr <= 0;
fixed_prev <= '0';
elsif rising_edge(clk_sys)then
--Registering fixed stuff value for edge detection
enable_prev <= enable;
stuff_ctr <= stuff_ctr;
if(enable='1')then
--Start of the bit stuffing
if(enable_prev='0')then
prev_bit <= RECESSIVE;
same_bits <= 1;
stuff_ctr <= 0;
fixed_prev <= '0';
--Trigger signal
elsif(tran_trig_1='1')then
--When stuffing method is changed in the beginning of the
--CRC field the stuffing counter needs to be erased!
if(fixed_stuff='1' and fixed_prev='0')then
prev_bit <= not prev_bit;
halt_reg <= '1';
same_bits <= 1; --TODO: think if here shouldnt be zero
-- due to extra inserted stuff bit!!!
fixed_prev <= fixed_stuff;
--If number of bits was reached
elsif(same_bits=unsigned(length) and fixed_stuff='0') or
(same_bits=unsigned(length)+1 and fixed_stuff='1')
--Fixed stuff is must be plus one since also the stuffed bit is
--counted! In normal bit stuffing when bit is stuffed same_bits is
--erased and counted from first bit after stuffed bit!
then
--Since the inverted bit also counts as bit starting value is not
--zero but one
same_bits <= 1;
prev_bit <= not prev_bit;
halt_reg <= '1';
--Stuff bit occured increase the stuffing counter!
--but only in the case of the original stuffing method
if(fixed_stuff='0')then
stuff_ctr <= (stuff_ctr+1) mod 8;
else
stuff_ctr <= stuff_ctr;
end if;
else --Not reached nuber of bits for stuff bit
--If fixed stuffing selected or incoming bit is equal with last bit
if(data_in=prev_bit or fixed_stuff='1')then
same_bits <= (same_bits+1) mod 8;
else
same_bits <= 1;
end if;
bst_ctr <= stuff_ctr;
stuff_proc : process(res_n, clk_sys)
begin