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

Subversion Repositories uart

[/] [uart/] [trunk/] [UARTtest.vhd] - Diff between revs 9 and 10

Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 10
--============================================================================--
--============================================================================--
-- Design units   : TestBench for miniUART device. 
-- Design units   : TestBench for miniUART device. 
--
--
-- File name      : UARTTest.vhd
-- File name      : UARTTest.vhd
--
--
-- Purpose        : Implements the test bench for miniUART device.
-- Purpose        : Implements the test bench for miniUART device.
--
--
-- Library        : uart_Lib.vhd
-- Library        : uart_Lib.vhd
--
--
-- Dependencies   : IEEE.Std_Logic_1164
-- Dependencies   : IEEE.Std_Logic_1164
--
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Revision list
-- Revision list
-- Version   Author             Date          Changes
-- Version   Author             Date          Changes
--
--
-- 0.1      Ovidiu Lupas     December 1999     New model
-- 0.1      Ovidiu Lupas     December 1999     New model
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Clock generator
-- Clock generator
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
library IEEE,work;
library IEEE,work;
use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_1164.all;
--
--
entity ClkGen is
entity ClkGen is
   port (
   port (
      Clk     : out Std_Logic);   -- Oscillator clock
      Clk     : out Std_Logic);   -- Oscillator clock
end ClkGen;--==================== End of entity ==============================--
end ClkGen;--==================== End of entity ==============================--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Architecture for clock and reset signals generator
-- Architecture for clock and reset signals generator
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
architecture Behaviour of ClkGen is
architecture Behaviour of ClkGen is
begin --========================== Architecture ==============================-- 
begin --========================== Architecture ==============================-- 
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Provide the system clock signal
  -- Provide the system clock signal
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  ClkDriver : process
  ClkDriver : process
    variable clktmp : Std_Logic := '1';
    variable clktmp : Std_Logic := '1';
    variable tpw_CI_posedge : Time := 12 ns; -- ~40 MHz
    variable tpw_CI_posedge : Time := 12 ns; -- ~40 MHz
  begin
  begin
     Clk <= clktmp;
     Clk <= clktmp;
     clktmp := not clktmp;
     clktmp := not clktmp;
    wait for tpw_CI_posedge;
    wait for tpw_CI_posedge;
  end process;
  end process;
end Behaviour; --=================== End of architecure =====================--
end Behaviour; --=================== End of architecure =====================--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- LoopBack Device
-- LoopBack Device
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
library IEEE,work;
library IEEE,work;
use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_1164.all;
--
--
entity LoopBack is
entity LoopBack is
   port (
   port (
      Clk     : in  Std_Logic;   -- Oscillator clock
      Clk     : in  Std_Logic;   -- Oscillator clock
      RxWr    : in  Std_Logic;   -- Rx line
      RxWr    : in  Std_Logic;   -- Rx line
      TxWr    : out Std_Logic);  -- Tx line
      TxWr    : out Std_Logic);  -- Tx line
end LoopBack; --==================== End of entity ==========================--
end LoopBack; --==================== End of entity ==========================--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Architecture for clock and reset signals generator
-- Architecture for clock and reset signals generator
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
architecture Behaviour of LoopBack is
architecture Behaviour of LoopBack is
begin --========================== Architecture ==============================-- 
begin --========================== Architecture ==============================-- 
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Provide the external clock signal
  -- Provide the external clock signal
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  ClkTrig : process(Clk)
  ClkTrig : process(Clk)
  begin
  begin
      TxWr <= RxWr;
      TxWr <= RxWr;
  end process;
  end process;
end Behaviour; --=================== End of architecure =====================--
end Behaviour; --=================== End of architecure =====================--
 
 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Testbench for UART device 
-- Testbench for UART device 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std.all;
library work;
library work;
use work.Uart_Def.all;
use work.Uart_Def.all;
 
 
entity UARTTEST is
entity UARTTEST is
end UARTTEST;
end UARTTEST;
 
 
architecture stimulus of UARTTEST is
architecture stimulus of UARTTEST is
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  -- Signals
  -- Signals
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  signal Reset   : Std_Logic;  -- Synchro signal
  signal Reset   : Std_Logic;  -- Synchro signal
  signal Clk     : Std_Logic;  -- Clock signal
  signal Clk     : Std_Logic;  -- Clock signal
  signal DataIn  : Std_Logic_Vector(7 downto 0);
  signal DataIn  : Std_Logic_Vector(7 downto 0);
  signal DataOut : Std_Logic_Vector(7 downto 0);
  signal DataOut : Std_Logic_Vector(7 downto 0);
  signal RxD     : Std_Logic;  -- RS-232 data input
  signal RxD     : Std_Logic;  -- RS-232 data input
  signal TxD     : Std_Logic;  -- RS-232 data output
  signal TxD     : Std_Logic;  -- RS-232 data output
  signal CS_N    : Std_Logic;
  signal CS_N    : Std_Logic;
  signal RD_N    : Std_Logic;
  signal RD_N    : Std_Logic;
  signal WR_N    : Std_Logic;
  signal WR_N    : Std_Logic;
  signal IntRx_N : Std_Logic;  -- Receive interrupt
  signal IntRx_N : Std_Logic;  -- Receive interrupt
  signal IntTx_N : Std_Logic;  -- Transmit interrupt
  signal IntTx_N : Std_Logic;  -- Transmit interrupt
  signal Addr    : Std_Logic_Vector(1 downto 0); -- 
  signal Addr    : Std_Logic_Vector(1 downto 0); -- 
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  -- Clock Divider
  -- Clock Divider
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  component ClkGen is
  component ClkGen is
   port (
   port (
      Clk     : out Std_Logic);   -- Oscillator clock
      Clk     : out Std_Logic);   -- Oscillator clock
  end component;
  end component;
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  -- LoopBack Device
  -- LoopBack Device
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  component LoopBack is
  component LoopBack is
   port (
   port (
      Clk     : in  Std_Logic;   -- Oscillator clock
      Clk     : in  Std_Logic;   -- Oscillator clock
      RxWr    : in  Std_Logic;   -- Rx line
      RxWr    : in  Std_Logic;   -- Rx line
      TxWr    : out Std_Logic);  -- Tx line
      TxWr    : out Std_Logic);  -- Tx line
  end component;
  end component;
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  -- UART Device
  -- UART Device
  -------------------------------------------------------------------
  -------------------------------------------------------------------
  component miniUART is
  component miniUART is
  port (
  port (
     SysClk   : in  Std_Logic;  -- System Clock
     SysClk   : in  Std_Logic;  -- System Clock
     Reset    : in  Std_Logic;  -- Reset input
     Reset    : in  Std_Logic;  -- Reset input
     CS_N     : in  Std_Logic;
     CS_N     : in  Std_Logic;
     RD_N     : in  Std_Logic;
     RD_N     : in  Std_Logic;
     WR_N     : in  Std_Logic;
     WR_N     : in  Std_Logic;
     RxD      : in  Std_Logic;
     RxD      : in  Std_Logic;
     TxD      : out Std_Logic;
     TxD      : out Std_Logic;
     IntRx_N  : out Std_Logic;  -- Receive interrupt
     IntRx_N  : out Std_Logic;  -- Receive interrupt
     IntTx_N  : out Std_Logic;  -- Transmit interrupt
     IntTx_N  : out Std_Logic;  -- Transmit interrupt
     Addr     : in  Std_Logic_Vector(1 downto 0); -- 
     Addr     : in  Std_Logic_Vector(1 downto 0); -- 
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- 
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- 
     DataOut  : out Std_Logic_Vector(7 downto 0)); -- 
     DataOut  : out Std_Logic_Vector(7 downto 0)); -- 
  end component;
  end component;
begin --======================== Architecture ========================--
begin --======================== Architecture ========================--
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  -- Instantiation of components
  -- Instantiation of components
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  Clock       : ClkGen port map (Clk);
  Clock       : ClkGen port map (Clk);
  LoopDev     : LoopBack port map (Clk,TxD,RxD);
  LoopDev     : LoopBack port map (Clk,TxD,RxD);
  miniUARTDev : miniUART port map (Clk,Reset,CS_N,RD_N,WR_N,RxD,TxD,
  miniUARTDev : miniUART port map (Clk,Reset,CS_N,RD_N,WR_N,RxD,TxD,
                                   IntRx_N,IntTx_N,Addr,DataIn,DataOut);
                                   IntRx_N,IntTx_N,Addr,DataIn,DataOut);
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  -- Reset cycle
  -- Reset cycle
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  RstCyc : process
  RstCyc : process
  begin
  begin
     Reset <= '1';
     Reset <= '1';
     wait for 5 ns;
     wait for 5 ns;
     Reset <= '0';
     Reset <= '0';
     wait for 250 ns;
     wait for 250 ns;
     Reset <= '1';
     Reset <= '1';
     wait;
     wait;
  end process;
  end process;
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  -- 
  -- 
  ---------------------------------------------------------------------
  ---------------------------------------------------------------------
  ProcCyc : process(Clk,IntRx_N,IntTx_N,Reset)
  ProcCyc : process(Clk,IntRx_N,IntTx_N,Reset)
      variable counter : unsigned(3 downto 0);
      variable counter : unsigned(3 downto 0);
      constant cone : unsigned(3 downto 0):= "0001";
      constant cone : unsigned(3 downto 0):= "0001";
      variable temp : bit := '0';
      variable temp : bit := '0';
  begin
  begin
     if Rising_Edge(Reset) then
     if Rising_Edge(Reset) then
        counter := "0000";
        counter := "0000";
          WR_N <= '1';
          WR_N <= '1';
          RD_N <= '1';
          RD_N <= '1';
          CS_N <= '1';
          CS_N <= '1';
     elsif Rising_Edge(Clk) then
     elsif Rising_Edge(Clk) then
        if IntTx_N = '0' then
        if IntTx_N = '0' then
           if temp = '0' then
           if temp = '0' then
              temp := '1';
              temp := '1';
              case counter is
              case counter is
                 when "0000" =>
                 when "0000" =>
                      Addr <= "00";
                      Addr <= "00";
                      DataIn <= x"AA";
                      DataIn <= x"AA";
                      WR_N <= '0';
                      WR_N <= '0';
                      CS_N <= '0';
                      CS_N <= '0';
                      counter := counter + cone;
                      counter := counter + cone;
                 when "0001" =>
                 when "0001" =>
                      Addr <= "00";
                      Addr <= "00";
                      DataIn <= x"AF";
                      DataIn <= x"AF";
                      WR_N <= '0';
                      WR_N <= '0';
                      CS_N <= '0';
                      CS_N <= '0';
                      counter := counter + cone;
                      counter := counter + cone;
                 when "0010" =>
                 when "0010" =>
                      Addr <= "00";
                      Addr <= "00";
                      DataIn <= x"55";
                      DataIn <= x"55";
                      WR_N <= '0';
                      WR_N <= '0';
                      CS_N <= '0';
                      CS_N <= '0';
                      counter := counter + cone;
                      counter := counter + cone;
                 when "0011" =>
                 when "0011" =>
                      Addr <= "00";
                      Addr <= "00";
                      DataIn <= x"E8";
                      DataIn <= x"E8";
                      WR_N <= '0';
                      WR_N <= '0';
                      CS_N <= '0';
                      CS_N <= '0';
                      counter := "0000";
                      counter := "0000";
                 when others => null;
                 when others => null;
              end case;
              end case;
           elsif temp = '1' then
           elsif temp = '1' then
              temp := '0';
              temp := '0';
           end if;
           end if;
        elsif IntRx_N = '0' then
        elsif IntRx_N = '0' then
           Addr <= "00";
           Addr <= "00";
           RD_N <= '0';
           RD_N <= '0';
           CS_N <= '0';
           CS_N <= '0';
        else
        else
          RD_N <= '1';
          RD_N <= '1';
          CS_N <= '1';
          CS_N <= '1';
          WR_N <= '1';
          WR_N <= '1';
          DataIn <= "ZZZZZZZZ";
          DataIn <= "ZZZZZZZZ";
        end if;
        end if;
     end if;
     end if;
  end process;
  end process;
 
 

powered by: WebSVN 2.1.0

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