OpenCores
URL https://opencores.org/ocsvn/rio/rio/trunk

Subversion Repositories rio

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /rio/trunk/bench
    from Rev 4 to Rev 20
    Reverse comparison

Rev 4 → Rev 20

/vhdl/TestRioPcsUart.vhd
0,0 → 1,674
-------------------------------------------------------------------------------
--
-- RapidIO IP Library Core
--
-- This file is part of the RapidIO IP library project
-- http://www.opencores.org/cores/rio/
--
-- Description
-- This file contains a testbench for RioPcsUart.
--
-- To Do:
-- -
--
-- Author(s):
-- - Magnus Rosenius, magro732@opencores.org
--
-------------------------------------------------------------------------------
--
-- Copyright (C) 2013 Authors and OPENCORES.ORG
--
-- This source file may be used and distributed without
-- restriction provided that this copyright statement is not
-- removed from the file and that any derivative work contains
-- the original copyright notice and the associated disclaimer.
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the GNU Lesser General
-- Public License as published by the Free Software Foundation;
-- either version 2.1 of the License, or (at your option) any
-- later version.
--
-- This source is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU Lesser General Public License for more
-- details.
--
-- You should have received a copy of the GNU Lesser General
-- Public License along with this source; if not, download it
-- from http://www.opencores.org/lgpl.shtml
--
-------------------------------------------------------------------------------
 
-------------------------------------------------------------------------------
-- TestRioPcsUart.
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library std;
use std.textio.all;
use work.test_common.all;
use work.rio_common.all;
 
 
-------------------------------------------------------------------------------
-- Entity for TestRioPcsUart.
-------------------------------------------------------------------------------
entity TestRioPcsUart is
end entity;
 
 
-------------------------------------------------------------------------------
-- Architecture for TestUart.
-------------------------------------------------------------------------------
architecture TestRioPcsUartImpl of TestRioPcsUart is
component RioFifo1 is
generic(
WIDTH : natural);
port(
clk : in std_logic;
areset_n : in std_logic;
 
empty_o : out std_logic;
read_i : in std_logic;
data_o : out std_logic_vector(WIDTH-1 downto 0);
 
full_o : out std_logic;
write_i : in std_logic;
data_i : in std_logic_vector(WIDTH-1 downto 0));
end component;
component RioSymbolConverter is
port(
clk : in std_logic;
areset_n : in std_logic;
 
portInitialized_o : out std_logic;
outboundSymbolEmpty_i : in std_logic;
outboundSymbolRead_o : out std_logic;
outboundSymbol_i : in std_logic_vector(33 downto 0);
inboundSymbolFull_i : in std_logic;
inboundSymbolWrite_o : out std_logic;
inboundSymbol_o : out std_logic_vector(33 downto 0);
 
uartEmpty_i : in std_logic;
uartRead_o : out std_logic;
uartData_i : in std_logic_vector(7 downto 0);
uartFull_i : in std_logic;
uartWrite_o : out std_logic;
uartData_o : out std_logic_vector(7 downto 0));
end component;
 
signal clk : std_logic;
signal areset_n : std_logic;
 
signal portInitialized : std_logic;
 
signal outboundSymbolEmpty : std_logic;
signal outboundSymbolRead : std_logic;
signal outboundSymbolReadData : std_logic_vector(33 downto 0);
signal outboundSymbolFull : std_logic;
signal outboundSymbolWrite : std_logic;
signal outboundSymbolWriteData : std_logic_vector(33 downto 0);
 
signal inboundSymbolFull : std_logic;
signal inboundSymbolWrite : std_logic;
signal inboundSymbolWriteData : std_logic_vector(33 downto 0);
 
signal uartInboundEmpty : std_logic;
signal uartInboundRead : std_logic;
signal uartInboundReadData : std_logic_vector(7 downto 0);
signal uartInboundFull : std_logic;
signal uartInboundWrite : std_logic;
signal uartInboundWriteData : std_logic_vector(7 downto 0);
 
signal uartOutboundFull : std_logic;
signal uartOutboundWrite : std_logic;
signal uartOutboundWriteData : std_logic_vector(7 downto 0);
begin
-----------------------------------------------------------------------------
-- Clock generation.
-----------------------------------------------------------------------------
ClockGenerator: process
begin
clk <= '0';
wait for 20 ns;
clk <= '1';
wait for 20 ns;
end process;
 
 
-----------------------------------------------------------------------------
-- Serial protocol test driver.
-----------------------------------------------------------------------------
TestDriver: process
 
---------------------------------------------------------------------------
-- Procedure to read a symbol.
---------------------------------------------------------------------------
procedure ReadSymbol(
constant symbolType : in std_logic_vector(1 downto 0);
constant symbolContent : in std_logic_vector(31 downto 0) := x"00000000") is
begin
inboundSymbolFull <= '0';
wait until inboundSymbolWrite = '1' and clk'event and clk = '1';
inboundSymbolFull <= '1';
 
assert symbolType = inboundSymbolWriteData(33 downto 32)
report "Missmatching symbol type:expected=" &
integer'image(to_integer(unsigned(symbolType))) &
" got=" &
integer'image(to_integer(unsigned(outboundSymbolWriteData(33 downto 32))))
severity error;
 
if (symbolType = SYMBOL_CONTROL_SC) or (symbolType = SYMBOL_CONTROL_PD) then
assert symbolContent(31 downto 8) = inboundSymbolWriteData(31 downto 8)
report "Missmatching symbol content:expected=" &
integer'image(to_integer(unsigned(symbolContent(31 downto 8)))) &
" got=" &
integer'image(to_integer(unsigned(inboundSymbolWriteData(31 downto 8))))
severity error;
elsif (symbolType = SYMBOL_DATA) then
assert symbolContent(31 downto 0) = inboundSymbolWriteData(31 downto 0)
report "Missmatching symbol content:expected=" &
integer'image(to_integer(unsigned(symbolContent(31 downto 0)))) &
" got=" &
integer'image(to_integer(unsigned(inboundSymbolWriteData(31 downto 0))))
severity error;
end if;
end procedure;
 
---------------------------------------------------------------------------
-- Procedure to write a symbol.
---------------------------------------------------------------------------
procedure WriteSymbol(
constant symbolType : in std_logic_vector(1 downto 0);
constant symbolContent : in std_logic_vector(31 downto 0) := x"00000000") is
begin
wait until outboundSymbolFull = '0' and clk'event and clk = '1';
outboundSymbolWrite <= '1';
outboundSymbolWriteData <= symbolType & symbolContent;
wait until clk'event and clk = '1';
outboundSymbolWrite <= '0';
end procedure;
 
---------------------------------------------------------------------------
-- Procedure to read an octet.
---------------------------------------------------------------------------
procedure ReadOctet(
constant octet : in std_logic_vector(7 downto 0) := x"00") is
begin
uartOutboundFull <= '0';
wait until uartOutboundWrite = '1' and clk'event and clk = '1';
uartOutboundFull <= '1';
 
assert uartOutboundWriteData = octet
report "Missmatching octet content:expected=" &
integer'image(to_integer(unsigned(octet))) &
" got=" &
integer'image(to_integer(unsigned(uartOutboundWriteData)))
severity error;
end procedure;
 
---------------------------------------------------------------------------
-- Procedure to send a symbol.
---------------------------------------------------------------------------
procedure WriteOctet(
constant octet : in std_logic_vector(7 downto 0) := x"00") is
begin
wait until uartInboundFull = '0' and clk'event and clk = '1';
uartInboundWrite <= '1';
uartInboundWriteData <= octet;
wait until clk'event and clk = '1';
uartInboundWrite <= '0';
end procedure;
 
---------------------------------------------------------------------------
-- Process variables.
---------------------------------------------------------------------------
 
begin
---------------------------------------------------------------------------
-- Test case initialization.
---------------------------------------------------------------------------
uartOutboundFull <= '1';
uartInboundWrite <= '0';
 
inboundSymbolFull <= '1';
outboundSymbolWrite <= '0';
 
-- Generate a startup reset pulse.
areset_n <= '0';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
areset_n <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
---------------------------------------------------------------------------
PrintS("-----------------------------------------------------------------");
PrintS("TG_RioPcsUart");
PrintS("-----------------------------------------------------------------");
PrintS("TG_RioPcsUart-TC1");
PrintS("Description: Check initial silence time.");
PrintS("Requirement: XXXXX");
PrintS("-----------------------------------------------------------------");
PrintS("Step 1:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC1-Step1");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_IDLE);
uartOutboundFull <= '0';
for i in 0 to 4095 loop
wait until clk'event and clk = '1';
assert uartOutboundWrite = '0' report "Sending during silence time."
severity error;
end loop;
 
ReadOctet(x"7e");
---------------------------------------------------------------------------
PrintS("-----------------------------------------------------------------");
PrintS("TG_RioPcsUart-TC2");
PrintS("Description: Check outbound symbol generation.");
PrintS("Requirement: XXXXX");
PrintS("-----------------------------------------------------------------");
PrintS("Step 1:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step1");
---------------------------------------------------------------------------
WriteSymbol(SYMBOL_IDLE);
ReadOctet(x"7e");
WriteSymbol(SYMBOL_IDLE);
ReadOctet(x"7e");
WriteSymbol(SYMBOL_IDLE);
ReadOctet(x"7e");
 
---------------------------------------------------------------------------
PrintS("Step 2:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step2");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_CONTROL_SC, x"123456" & "XXXXXXXX");
ReadOctet(x"12");
ReadOctet(x"34");
ReadOctet(x"56");
ReadOctet(x"7e");
---------------------------------------------------------------------------
PrintS("Step 3:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step3");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_CONTROL_PD, x"7d7d7d" & "XXXXXXXX");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7e");
---------------------------------------------------------------------------
PrintS("Step 4:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step4");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_CONTROL_SC, x"7e7e7e" & "XXXXXXXX");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7e");
---------------------------------------------------------------------------
PrintS("Step 5:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step5");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_CONTROL_PD, x"7d7f7e" & "XXXXXXXX");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7f");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7e");
 
---------------------------------------------------------------------------
PrintS("Step 6:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step6");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_DATA, x"12345678");
ReadOctet(x"12");
ReadOctet(x"34");
ReadOctet(x"56");
ReadOctet(x"78");
---------------------------------------------------------------------------
PrintS("Step 7:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step7");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_DATA, x"7d7d7d7d");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7d");
ReadOctet(x"5d");
 
---------------------------------------------------------------------------
PrintS("Step 8:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step8");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_DATA, x"7e7e7e7e");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7d");
ReadOctet(x"5e");
 
---------------------------------------------------------------------------
PrintS("Step 9:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step9");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_DATA, x"7d7f7e7f");
ReadOctet(x"7d");
ReadOctet(x"5d");
ReadOctet(x"7f");
ReadOctet(x"7d");
ReadOctet(x"5e");
ReadOctet(x"7f");
 
---------------------------------------------------------------------------
PrintS("Step 10:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC2-Step10");
---------------------------------------------------------------------------
 
WriteSymbol(SYMBOL_IDLE);
ReadOctet(x"7e");
WriteSymbol(SYMBOL_CONTROL_SC, x"123456" & "XXXXXXXX");
ReadOctet(x"12");
ReadOctet(x"34");
ReadOctet(x"56");
ReadOctet(x"7e");
WriteSymbol(SYMBOL_DATA, x"789abcde");
ReadOctet(x"78");
ReadOctet(x"9a");
ReadOctet(x"bc");
ReadOctet(x"de");
WriteSymbol(SYMBOL_CONTROL_SC, x"123456" & "XXXXXXXX");
ReadOctet(x"12");
ReadOctet(x"34");
ReadOctet(x"56");
ReadOctet(x"7e");
WriteSymbol(SYMBOL_DATA, x"789abcde");
ReadOctet(x"78");
ReadOctet(x"9a");
ReadOctet(x"bc");
ReadOctet(x"de");
WriteSymbol(SYMBOL_DATA, x"789abcde");
ReadOctet(x"78");
ReadOctet(x"9a");
ReadOctet(x"bc");
ReadOctet(x"de");
 
---------------------------------------------------------------------------
PrintS("-----------------------------------------------------------------");
PrintS("TG_RioPcsUart-TC3");
PrintS("Description: Check inbound symbol generation.");
PrintS("Requirement: XXXXX");
PrintS("-----------------------------------------------------------------");
PrintS("Step 1:");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step1");
---------------------------------------------------------------------------
 
WriteOctet(x"7e");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_IDLE);
 
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"12");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_IDLE);
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"34");
WriteOctet(x"56");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_IDLE);
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"78");
WriteOctet(x"9a");
WriteOctet(x"bc");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_CONTROL_SC, x"789abc" & "XXXXXXXX");
 
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_CONTROL_SC, x"7d7d7d" & "XXXXXXXX");
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7e");
ReadSymbol(SYMBOL_CONTROL_SC, x"7e7e7e" & "XXXXXXXX");
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"f1");
WriteOctet(x"11");
WriteOctet(x"22");
WriteOctet(x"33");
ReadSymbol(SYMBOL_DATA, x"f1112233");
 
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"7e");
ReadSymbol(SYMBOL_IDLE);
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7d");
WriteOctet(x"5d");
WriteOctet(x"7d");
WriteOctet(x"5d");
ReadSymbol(SYMBOL_DATA, x"7d7d7d7d");
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7d");
WriteOctet(x"5e");
WriteOctet(x"7d");
WriteOctet(x"5e");
ReadSymbol(SYMBOL_DATA, x"7e7e7e7e");
---------------------------------------------------------------------------
PrintS("Step :");
PrintS("Action: .");
PrintS("Result: .");
---------------------------------------------------------------------------
PrintR("TG_RioPcsUart-TC3-Step");
---------------------------------------------------------------------------
 
WriteOctet(x"44");
WriteOctet(x"55");
WriteOctet(x"66");
WriteOctet(x"77");
ReadSymbol(SYMBOL_DATA, x"44556677");
WriteOctet(x"88");
WriteOctet(x"99");
WriteOctet(x"aa");
WriteOctet(x"bb");
ReadSymbol(SYMBOL_DATA, x"8899aabb");
---------------------------------------------------------------------------
-- Test completed.
---------------------------------------------------------------------------
 
TestEnd;
end process;
 
 
-----------------------------------------------------------------------------
--
-----------------------------------------------------------------------------
OutboundSymbolFifo: RioFifo1
generic map(WIDTH=>34)
port map(
clk=>clk, areset_n=>areset_n,
empty_o=>outboundSymbolEmpty, read_i=>outboundSymbolRead, data_o=>outboundSymbolReadData,
full_o=>outboundSymbolFull, write_i=>outboundSymbolWrite, data_i=>outboundSymbolWriteData);
 
InboundOctetFifo: RioFifo1
generic map(WIDTH=>8)
port map(
clk=>clk, areset_n=>areset_n,
empty_o=>uartInboundEmpty, read_i=>uartInboundRead, data_o=>uartInboundReadData,
full_o=>uartInboundFull, write_i=>uartInboundWrite, data_i=>uartInboundWriteData);
 
TestSymbolConverter: RioSymbolConverter
port map(
clk=>clk, areset_n=>areset_n,
portInitialized_o=>portInitialized,
outboundSymbolEmpty_i=>outboundSymbolEmpty,
outboundSymbolRead_o=>outboundSymbolRead, outboundSymbol_i=>outboundSymbolReadData,
inboundSymbolFull_i=>inboundSymbolFull,
inboundSymbolWrite_o=>inboundSymbolWrite, inboundSymbol_o=>inboundSymbolWriteData,
uartEmpty_i=>uartInboundEmpty, uartRead_o=>uartInboundRead, uartData_i=>uartInboundReadData,
uartFull_i=>uartOutboundFull, uartWrite_o=>uartOutboundWrite, uartData_o=>uartOutboundWriteData);
end architecture;
vhdl/TestRioPcsUart.vhd Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: vhdl/TestUart.vhd =================================================================== --- vhdl/TestUart.vhd (nonexistent) +++ vhdl/TestUart.vhd (revision 20) @@ -0,0 +1,228 @@ +------------------------------------------------------------------------------- +-- +-- RapidIO IP Library Core +-- +-- This file is part of the RapidIO IP library project +-- http://www.opencores.org/cores/rio/ +-- +-- Description +-- Contains a testbench for the generic UART entity. +-- +-- To Do: +-- - +-- +-- Author(s): +-- - Magnus Rosenius, magro732@opencores.org +-- +------------------------------------------------------------------------------- +-- +-- Copyright (C) 2013 Authors and OPENCORES.ORG +-- +-- This source file may be used and distributed without +-- restriction provided that this copyright statement is not +-- removed from the file and that any derivative work contains +-- the original copyright notice and the associated disclaimer. +-- +-- This source file is free software; you can redistribute it +-- and/or modify it under the terms of the GNU Lesser General +-- Public License as published by the Free Software Foundation; +-- either version 2.1 of the License, or (at your option) any +-- later version. +-- +-- This source is distributed in the hope that it will be +-- useful, but WITHOUT ANY WARRANTY; without even the implied +-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +-- PURPOSE. See the GNU Lesser General Public License for more +-- details. +-- +-- You should have received a copy of the GNU Lesser General +-- Public License along with this source; if not, download it +-- from http://www.opencores.org/lgpl.shtml +-- +------------------------------------------------------------------------------- + + +------------------------------------------------------------------------------- +-- TestUart. +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +library std; +use std.textio.all; +use work.test_common.all; + + +------------------------------------------------------------------------------- +-- Entity for TestUart. +------------------------------------------------------------------------------- +entity TestUart is +end entity; + + +------------------------------------------------------------------------------- +-- Architecture for TestUart. +------------------------------------------------------------------------------- +architecture TestUartImpl of TestUart is + + component Uart is + generic( + DIVISOR_WIDTH : natural; + DATA_WIDTH : natural); + port( + clk : in std_logic; + areset_n : in std_logic; + + divisor_i : in std_logic_vector(DIVISOR_WIDTH-1 downto 0); + + serial_i : in std_logic; + serial_o : out std_logic; + + empty_o : out std_logic; + read_i : in std_logic; + data_o : out std_logic_vector(DATA_WIDTH-1 downto 0); + + full_o : out std_logic; + write_i : in std_logic; + data_i : in std_logic_vector(DATA_WIDTH-1 downto 0)); + end component; + + signal clk : std_logic; + signal areset_n : std_logic; + + signal rxSerial : std_logic; + signal txSerial : std_logic; + + signal rxEmpty : std_logic; + signal rxRead : std_logic; + signal rxData : std_logic_vector(7 downto 0); + + signal txFull : std_logic; + signal txWrite : std_logic; + signal txData : std_logic_vector(7 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- Clock generation. + ----------------------------------------------------------------------------- + ClockGenerator: process + begin + clk <= '0'; + wait for 20 ns; + clk <= '1'; + wait for 20 ns; + end process; + + + ----------------------------------------------------------------------------- + -- Serial port emulator. + ----------------------------------------------------------------------------- + TestDriver: process + + procedure SerialSend( + constant data : in std_logic_vector(7 downto 0)) is + variable outgoing : std_logic_vector(9 downto 0); + begin + -- Create the complete transmission character. + outgoing(0) := '0'; + for i in 0 to 7 loop + outgoing(i+1) := data(i); + end loop; + outgoing(9) := '1'; + + -- Send the character. + for i in 0 to 9 loop + txSerial <= outgoing(i); + wait for 500 ns; + end loop; + end procedure; + + procedure SerialReceive( + constant data : in std_logic_vector(7 downto 0)) is + variable incomming : std_logic_vector(9 downto 0); + begin + -- Receive the character. + wait until rxSerial = '0'; + incomming(0) := '0'; + for i in 1 to 9 loop + wait for 500 ns; + incomming(i) := rxSerial; + end loop; + + -- Check if the received character is expected. + assert (incomming(0) = '0') report "Start bit." severity error; + assert (incomming(8 downto 1) = data) report "Data bit" severity error; + assert (incomming(9) = '1') report "Stop bit." severity error; + end procedure; + + begin + txSerial <= '1'; + txWrite <= '0'; + rxRead <= '0'; + areset_n <= '0'; + + wait until clk'event and clk = '1'; + wait until clk'event and clk = '1'; + areset_n <= '1'; + wait until clk'event and clk = '1'; + wait until clk'event and clk = '1'; + + --------------------------------------------------------------------------- + -- Send byte to uart. + --------------------------------------------------------------------------- + SerialSend(x"55"); + wait until rxEmpty = '0' and clk'event and clk = '1'; + rxRead <= '1'; + wait until clk'event and clk = '1'; + rxRead <= '0'; + wait until clk'event and clk = '1'; + assert rxData = x"55" report "rxData" severity error; + + SerialSend(x"62"); + wait until rxEmpty = '0' and clk'event and clk = '1'; + rxRead <= '1'; + wait until clk'event and clk = '1'; + rxRead <= '0'; + wait until clk'event and clk = '1'; + assert rxData = x"62" report "rxData" severity error; + + wait until txFull = '0' and clk'event and clk = '1'; + txWrite <= '1'; + txData <= x"55"; + wait until clk'event and clk = '1'; + txWrite <= '0'; + SerialReceive(x"55"); + + wait until txFull = '0' and clk'event and clk = '1'; + txWrite <= '1'; + txData <= x"62"; + wait until clk'event and clk = '1'; + txWrite <= '0'; + SerialReceive(x"62"); + + -- REMARK: Formalize the tests and write more testcases... + + --------------------------------------------------------------------------- + -- Test completed. + --------------------------------------------------------------------------- + + TestEnd; + end process; + + + ----------------------------------------------------------------------------- + -- Instantiate the uart. + ----------------------------------------------------------------------------- + + UartInst: Uart + generic map(DIVISOR_WIDTH=>4, DATA_WIDTH=>8) + port map( + clk=>clk, areset_n=>areset_n, + divisor_i=>"1011", + serial_i=>txSerial, serial_o=>rxSerial, + empty_o=>rxEmpty, read_i=>rxRead, data_o=>rxData, + full_o=>txFull, write_i=>txWrite, data_i=>txData); + +end architecture;
vhdl/TestUart.vhd Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.