-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
---- ----
|
---- ----
|
---- Present - a lightweight block cipher project ----
|
---- Present - a lightweight block cipher project ----
|
---- ----
|
---- ----
|
---- This file is part of the Present - a lightweight block ----
|
---- This file is part of the Present - a lightweight block ----
|
---- cipher project ----
|
---- cipher project ----
|
---- http://www.http://opencores.org/project,present ----
|
---- http://www.http://opencores.org/project,present ----
|
---- ----
|
---- ----
|
---- Description: ----
|
---- Description: ----
|
---- This test bench simulate data transfer between PC and ----
|
---- This test bench simulate data transfer between PC and ----
|
---- PresentDecodeComm core. All test data were generated in ----
|
---- PresentDecodeComm core. All test data were generated in ----
|
---- another program and textio was used for processing. Test bench----
|
---- another program and textio was used for processing. Test bench----
|
---- is for to distinct data sets. ----
|
---- is for to distinct data sets. ----
|
---- To Do: ----
|
---- To Do: ----
|
---- ----
|
---- ----
|
---- Author(s): ----
|
---- Author(s): ----
|
---- - Krzysztof Gajewski, gajos@opencores.org ----
|
---- - Krzysztof Gajewski, gajos@opencores.org ----
|
---- k.gajewski@gmail.com ----
|
---- k.gajewski@gmail.com ----
|
---- ----
|
---- ----
|
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
---- ----
|
---- ----
|
---- Copyright (C) 2013 Authors and OPENCORES.ORG ----
|
---- Copyright (C) 2013 Authors and OPENCORES.ORG ----
|
---- ----
|
---- ----
|
---- This source file may be used and distributed without ----
|
---- This source file may be used and distributed without ----
|
---- restriction provided that this copyright statement is not ----
|
---- restriction provided that this copyright statement is not ----
|
---- removed from the file and that any derivative work contains ----
|
---- removed from the file and that any derivative work contains ----
|
---- the original copyright notice and the associated disclaimer. ----
|
---- the original copyright notice and the associated disclaimer. ----
|
---- ----
|
---- ----
|
---- This source file is free software; you can redistribute it ----
|
---- This source file is free software; you can redistribute it ----
|
---- and-or modify it under the terms of the GNU Lesser General ----
|
---- and-or modify it under the terms of the GNU Lesser General ----
|
---- Public License as published by the Free Software Foundation; ----
|
---- Public License as published by the Free Software Foundation; ----
|
---- either version 2.1 of the License, or (at your option) any ----
|
---- either version 2.1 of the License, or (at your option) any ----
|
---- later version. ----
|
---- later version. ----
|
---- ----
|
---- ----
|
---- This source is distributed in the hope that it will be ----
|
---- This source is distributed in the hope that it will be ----
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
---- details. ----
|
---- details. ----
|
---- ----
|
---- ----
|
---- You should have received a copy of the GNU Lesser General ----
|
---- You should have received a copy of the GNU Lesser General ----
|
---- Public License along with this source; if not, download it ----
|
---- Public License along with this source; if not, download it ----
|
---- from http://www.opencores.org/lgpl.shtml ----
|
---- from http://www.opencores.org/lgpl.shtml ----
|
---- ----
|
---- ----
|
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
LIBRARY ieee;
|
LIBRARY ieee;
|
USE ieee.std_logic_1164.ALL;
|
USE ieee.std_logic_1164.ALL;
|
USE std.textio.all;
|
USE std.textio.all;
|
USE work.txt_util.all;
|
USE work.txt_util.all;
|
USE ieee.std_logic_textio.all;
|
USE ieee.std_logic_textio.all;
|
|
|
-- Uncomment the following library declaration if using
|
-- Uncomment the following library declaration if using
|
-- arithmetic functions with Signed or Unsigned values
|
-- arithmetic functions with Signed or Unsigned values
|
--USE ieee.numeric_std.ALL;
|
--USE ieee.numeric_std.ALL;
|
|
|
ENTITY PresentDecodeCommTB IS
|
ENTITY PresentDecodeCommTB IS
|
END PresentDecodeCommTB;
|
END PresentDecodeCommTB;
|
|
|
ARCHITECTURE behavior OF PresentDecodeCommTB IS
|
ARCHITECTURE behavior OF PresentDecodeCommTB IS
|
|
|
-- Component Declaration for the Unit Under Test (UUT)
|
-- Component Declaration for the Unit Under Test (UUT)
|
|
|
COMPONENT PresentDecodeComm
|
COMPONENT PresentDecodeComm
|
PORT(
|
PORT(
|
DATA_RXD : IN std_logic;
|
DATA_RXD : IN std_logic;
|
CLK : IN std_logic;
|
CLK : IN std_logic;
|
RESET : IN std_logic;
|
RESET : IN std_logic;
|
DATA_TXD : OUT std_logic
|
DATA_TXD : OUT std_logic
|
);
|
);
|
END COMPONENT;
|
END COMPONENT;
|
|
|
|
|
--Inputs
|
--Inputs
|
signal DATA_RXD : std_logic := '0';
|
signal DATA_RXD : std_logic := '0';
|
signal CLK : std_logic := '0';
|
signal CLK : std_logic := '0';
|
signal RESET : std_logic := '0';
|
signal RESET : std_logic := '0';
|
|
|
--Outputs
|
--Outputs
|
signal DATA_TXD : std_logic;
|
signal DATA_TXD : std_logic;
|
|
|
-- Clock period definitions
|
-- Clock period definitions
|
-- speed of DIGILENT board and RS-232 core
|
-- speed of DIGILENT board and RS-232 core
|
constant CLK_period : time := 20 ns;
|
constant CLK_period : time := 20 ns;
|
|
|
BEGIN
|
BEGIN
|
|
|
-- Instantiate the Unit Under Test (UUT)
|
-- Instantiate the Unit Under Test (UUT)
|
uut: PresentDecodeComm PORT MAP (
|
uut: PresentDecodeComm PORT MAP (
|
DATA_RXD => DATA_RXD,
|
DATA_RXD => DATA_RXD,
|
CLK => CLK,
|
CLK => CLK,
|
RESET => RESET,
|
RESET => RESET,
|
DATA_TXD => DATA_TXD
|
DATA_TXD => DATA_TXD
|
);
|
);
|
|
|
-- Clock process definitions
|
-- Clock process definitions
|
CLK_process :process
|
CLK_process :process
|
begin
|
begin
|
CLK <= '0';
|
CLK <= '0';
|
wait for CLK_period/2;
|
wait for CLK_period/2;
|
CLK <= '1';
|
CLK <= '1';
|
wait for CLK_period/2;
|
wait for CLK_period/2;
|
end process;
|
end process;
|
|
|
|
|
-- Stimulus process
|
-- Stimulus process
|
stim_proc: process
|
stim_proc: process
|
|
|
-- Variables
|
-- Variables
|
file txt :text is in "test/data.txt";
|
file txt :text is in "test/data.txt";
|
file key :text is in "test/key.txt";
|
file key :text is in "test/key.txt";
|
file txt2 :text is in "test/data2.txt";
|
file txt2 :text is in "test/data2.txt";
|
file key2 :text is in "test/key2.txt";
|
file key2 :text is in "test/key2.txt";
|
|
|
variable line_in : line;
|
variable line_in : line;
|
variable line_content : string(1 to 8);
|
variable line_content : string(1 to 8);
|
variable data : STD_LOGIC;
|
variable data : STD_LOGIC;
|
|
|
begin
|
begin
|
|
|
DATA_RXD <= '1';
|
DATA_RXD <= '1';
|
RESET <= '1';
|
RESET <= '1';
|
wait for 1000 ns;
|
wait for 1000 ns;
|
RESET <= '0';
|
RESET <= '0';
|
|
|
wait for CLK_period*10;
|
wait for CLK_period*10;
|
|
|
|
-- All data are sent in direction from LSB to MSB
|
|
|
-- Reading first 'data' file each "segment" is one bit of serial data
|
-- Reading first 'data' file each "segment" is one bit of serial data
|
while not (endfile(txt)) loop
|
while not (endfile(txt)) loop
|
readline(txt, line_in); -- info line
|
readline(txt, line_in); -- info line
|
read(line_in, line_content);
|
read(line_in, line_content);
|
report line_content;
|
report line_content;
|
|
|
DATA_RXD <= '0'; -- start bit
|
DATA_RXD <= '0'; -- start bit
|
-- this amount is due to estimation of period of time needed for sending
|
-- this amount is due to estimation of period of time needed for sending
|
-- one bit in RS-232 with 115 200 bps bandwith
|
-- one bit in RS-232 with 115 200 bps bandwith
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt, line_in);
|
readline(txt, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data; -- parity bit
|
DATA_RXD <= data; -- parity bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
report "Koniec bajtu";
|
report "End of byte";
|
DATA_RXD <= '1'; -- stop bit
|
DATA_RXD <= '1'; -- stop bit
|
wait for 100 us;
|
wait for 100 us;
|
end loop;
|
end loop;
|
|
|
-- Reading first 'key' file each "segment" is one bit of serial data
|
-- Reading first 'key' file each "segment" is one bit of serial data
|
while not (endfile(key)) loop
|
while not (endfile(key)) loop
|
readline(key, line_in); -- info line
|
readline(key, line_in); -- info line
|
read(line_in, line_content);
|
read(line_in, line_content);
|
report line_content;
|
report line_content;
|
|
|
DATA_RXD <= '0'; -- start bit
|
DATA_RXD <= '0'; -- start bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key, line_in);
|
readline(key, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data; -- parity bit
|
DATA_RXD <= data; -- parity bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
report "Koniec bajtu";
|
report "End of byte";
|
DATA_RXD <= '1'; -- stop bit
|
DATA_RXD <= '1'; -- stop bit
|
wait for 100 us;
|
wait for 100 us;
|
end loop;
|
end loop;
|
|
|
-- Cipher counting and sending result
|
-- Cipher counting and sending result
|
wait for 2000 us;
|
wait for 2000 us;
|
|
|
-- Reading second 'data2' file each "segment" is one bit of serial data
|
-- Reading second 'data2' file each "segment" is one bit of serial data
|
while not (endfile(txt2)) loop
|
while not (endfile(txt2)) loop
|
readline(txt2, line_in); -- info line
|
readline(txt2, line_in); -- info line
|
read(line_in, line_content);
|
read(line_in, line_content);
|
report line_content;
|
report line_content;
|
|
|
DATA_RXD <= '0'; -- start bit
|
DATA_RXD <= '0'; -- start bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(txt2, line_in);
|
readline(txt2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data; -- parity bit
|
DATA_RXD <= data; -- parity bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
report "Koniec bajtu";
|
report "End of byte";
|
DATA_RXD <= '1'; -- stop bit
|
DATA_RXD <= '1'; -- stop bit
|
wait for 100 us;
|
wait for 100 us;
|
end loop;
|
end loop;
|
|
|
-- Reading second 'key2' file each "segment" is one bit of serial data
|
-- Reading second 'key2' file each "segment" is one bit of serial data
|
while not (endfile(key2)) loop
|
while not (endfile(key2)) loop
|
readline(key2, line_in); -- info line
|
readline(key2, line_in); -- info line
|
read(line_in, line_content);
|
read(line_in, line_content);
|
report line_content;
|
report line_content;
|
|
|
DATA_RXD <= '0'; -- start bit
|
DATA_RXD <= '0'; -- start bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data;
|
DATA_RXD <= data;
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
readline(key2, line_in);
|
readline(key2, line_in);
|
read(line_in, data);
|
read(line_in, data);
|
DATA_RXD <= data; -- parity bit
|
DATA_RXD <= data; -- parity bit
|
wait for 8.75 us;
|
wait for 8.75 us;
|
|
|
report "Koniec bajtu";
|
report "End of byte";
|
DATA_RXD <= '1'; -- stop bit
|
DATA_RXD <= '1'; -- stop bit
|
wait for 100 us;
|
wait for 100 us;
|
end loop;
|
end loop;
|
|
|
-- Cipher counting and sending result
|
-- Cipher counting and sending result
|
wait for 2000 us;
|
wait for 2000 us;
|
|
|
assert false severity failure;
|
assert false severity failure;
|
end process;
|
end process;
|
|
|
END;
|
END;
|
|
|