?? uart_rx_tb.vhd
字號:
-- --------------------------------------------------------------------
-- >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
-- --------------------------------------------------------------------
-- Copyright (c) 2001 by Lattice Semiconductor Corporation
-- --------------------------------------------------------------------
--
-- Permission:
--
-- Lattice Semiconductor grants permission to use this code for use
-- in synthesis for any Lattice programmable logic product. Other
-- use of this code, including the selling or duplication of any
-- portion is strictly prohibited.
--
-- Disclaimer:
--
-- This VHDL or Verilog source code is intended as a design reference
-- which illustrates how these types of functions can be implemented.
-- It is the user's responsibility to verify their design for
-- consistency and functionality through the use of formal
-- verification methods. Lattice Semiconductor provides no warranty
-- regarding the use or functionality of this code.
--
-- --------------------------------------------------------------------
--
-- Lattice Semiconductor Corporation
-- 5555 NE Moore Court
-- Hillsboro, OR 97214
-- U.S.A
--
-- TEL: 1-800-Lattice (USA and Canada)
-- 408-826-6000 (other locations)
--
-- web: http://www.latticesemi.com/
-- email: techsupport@latticesemi.com
--
-- --------------------------------------------------------------------
--
-- Project: Universal Asynchronous Receiver Transmitter
-- File: uart_rx_tb.vhd
-- Title: uart_rx_tb
-- Design Library: IEEE, generics
-- Dependencies: IEEE.std_logic_1164.all
-- IEEE.numeric_std.all
-- generics.components.all
-- Description: VHDL test bench for UART_top receiver testing
-- There are 20 tests in different combinations:
-- Test 1 : 5-bit data receiving test, even parity
-- Test 2 : 5-bit data receiving test, odd parity
-- Test 3 : 5-bit data receiving test, stick even parity
-- Test 4 : 5-bit data receiving test, stick odd parity
-- Test 5 : 5-bit data receiving test, no parity
-- Test 6 : 6-bit data receiving test, even parity
-- Test 7 : 6-bit data receiving test, odd parity
-- Test 8 : 6-bit data receiving test, stick even parity
-- Test 9 : 6-bit data receiving test, stick odd parity
-- Test 10 : 6-bit data receiving test, no parity
-- Test 11 : 7-bit data receiving test, even parity
-- Test 12 : 7-bit data receiving test, odd parity
-- Test 13 : 7-bit data receiving test, stick even parity
-- Test 14 : 7-bit data receiving test, stick odd parity
-- Test 15 : 7-bit data receiving test, no parity
-- Test 16 : 8-bit data receiving test, even parity
-- Test 17 : 8-bit data receiving test, odd parity
-- Test 18 : 8-bit data receiving test, stick even parity
-- Test 19 : 8-bit data receiving test, stick odd parity
-- Test 20 : 8-bit data receiving test, no parity
--
-- --------------------------------------------------------------------
--
-- Revision History :
-- --------------------------------------------------------------------
-- Ver :| Author :| Mod. Date :| Changes Made:
-- V1.1 :| J.H. :| 06/19/01 :| Support ispMACH 5000VG
-- V1.0 :| J.H. :| 06/01/01 :| First Release
-- --------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity uart_rx_tb is
end uart_rx_tb;
architecture behavior of uart_rx_tb is
component Uart_top
port(
MR : in std_logic;
MCLK : in std_logic;
CS : in std_logic;
RDn : in std_logic;
WRn : in std_logic;
ADSn : in std_logic;
A : in std_logic_vector(2 downto 0);
DIN : in std_logic_vector(7 downto 0);
DOUT : out std_logic_vector(7 downto 0);
DDIS : out std_logic;
INTR : out std_logic;
SIN : in std_logic;
RxRDYn : out std_logic;
SOUT : out std_logic;
TxRDYn : out std_logic;
DCDn : in std_logic;
CTSn : in std_logic;
DSRn : in std_logic;
RIn : in std_logic;
DTRn : out std_logic;
RTSn : out std_logic
);
end component;
-- Clock Frequency of Test
-- MCLK_MHZ : frequency of MCLK
-- PLLO_MHZ : frequency of PLL clk_out
-- When the UART design is targeted to devices without
-- PLL feature or the PLL feature is not used, PLLO_MHZ
-- should be set to the same value of MCLK_MHZ.
constant MCLK_MHZ : real := 32.0000;
constant PLLO_MHZ : real := 80.0000;
constant ONE_K_NS : time := 1000 ns;
-- Clock Period Declaration
-- MCLK_CLK_PERIOD : clock period of MCLK
-- CLK_PEROID : clock period of internal clock
constant MCLK_CLK_PERIOD : time := ONE_K_NS / MCLK_MHZ;
constant CLK_PERIOD : time := ONE_K_NS / PLLO_MHZ;
-- UART Registers Address Map
constant RBR : std_logic_vector(2 downto 0) := "000";
constant THR : std_logic_vector(2 downto 0) := "000";
constant IER : std_logic_vector(2 downto 0) := "001";
constant IIR : std_logic_vector(2 downto 0) := "010";
constant LCR : std_logic_vector(2 downto 0) := "011";
constant MCR : std_logic_vector(2 downto 0) := "100";
constant LSR : std_logic_vector(2 downto 0) := "101";
constant MSR : std_logic_vector(2 downto 0) := "110";
-- TimeOut Definition
constant WAIT_TIMEOUT : integer := 1000;
-- This procedure performs a write cycle over the internal register
procedure write_reg (
addr : in std_logic_vector(2 downto 0);
data : in std_logic_vector(7 downto 0);
signal CS : out std_logic;
signal ADSn : out std_logic;
signal WRn : out std_logic;
signal A : out std_logic_vector(2 Downto 0);
signal DIN : out std_logic_vector(7 DownTo 0)) is
begin
wait for CLK_PERIOD;
ADSn <= '0';
wait for CLK_PERIOD;
A <= addr;
CS <= '1';
wait for CLK_PERIOD;
ADSn <= '1';
wait for CLK_PERIOD;
A <= (others => '1');
CS <= '0';
wait for (2*CLK_PERIOD);
WRn <= '0';
wait for CLK_PERIOD;
DIN <= data;
wait for CLK_PERIOD;
WRn <= '1';
wait for CLK_PERIOD;
DIN <= (others => '1');
wait for (2*CLK_PERIOD);
end write_reg;
-- This procedure performs a read cycle over the internal register
procedure read_reg (
addr : in std_logic_vector(2 downto 0);
signal data : out std_logic_vector(7 downto 0);
signal CS : out std_logic;
signal ADSn : out std_logic;
signal RDn : out std_logic;
signal A : out std_logic_vector(2 Downto 0);
signal DOUT : in std_logic_vector(7 Downto 0)) is
begin
wait for CLK_PERIOD;
ADSn <= '0';
wait for CLK_PERIOD;
A <= addr;
CS <= '1';
wait for CLK_PERIOD;
ADSn <= '1';
wait for CLK_PERIOD;
A <= (others => '1');
CS <= '0';
wait for (2*CLK_PERIOD);
RDn <= '0';
wait for (2*CLK_PERIOD);
data <= DOUT;
RDn <= '1';
wait for (3*CLK_PERIOD);
end read_reg;
-- This procedure generates a serial frame for testing
procedure sin_gen (
numDataBits : integer range 5 to 8;
data : in std_logic_vector(7 downto 0);
parity : in std_logic;
stopBitLength : real;
parityBitExist : boolean;
stopBitIsHigh : boolean;
constant cycleTime : in time;
signal SIN : out std_logic) is
begin
-- Start Bit
SIN <= '0';
wait for cycleTime;
-- Data Bits
for dataBit in 0 to numDataBits-1 loop
SIN <= data(dataBit);
wait for cycleTime;
end loop;
-- Parity Bit
if (parityBitExist) then
SIN <= parity;
wait for cycleTime;
end if;
-- Stop Bit(s)
if (stopBitIsHigh) then
SIN <= '1';
else
SIN <= '0'; -- for BREAK & Framing Error generation
end if;
wait for stopBitLength*cycleTime;
SIN <= '1';
end sin_gen;
signal MR : std_logic := '1';
signal MCLK : std_logic := '0';
signal CS : std_logic := '0';
signal RDn : std_logic := '1';
signal WRn : std_logic := '1';
signal ADSn : std_logic := '1';
signal A : std_logic_vector(2 downto 0);
signal DIN : std_logic_vector(7 downto 0);
signal DOUT : std_logic_vector(7 downto 0);
signal DDIS : std_logic;
signal INTR : std_logic;
signal SIN : std_logic;
signal RxRDYn : std_logic;
signal SOUT : std_logic;
signal TxRDYn : std_logic;
signal DCDn : std_logic;
signal CTSn : std_logic;
signal DSRn : std_logic;
signal RIn : std_logic;
signal DTRn : std_logic;
signal RTSn : std_logic;
signal regData_readBack : std_logic_vector(7 downto 0);
signal okToReceiveSIN : std_logic := '0';
signal TestID : integer := 0;
signal PCLK : std_logic := '0';
begin
-----------------------------------------------------------------------
-- UUT Instantiation
-----------------------------------------------------------------------
uut: Uart_top port map(
MR => MR,
MCLK => MCLK,
CS => CS,
RDn => RDn,
WRn => WRn,
ADSn => ADSn,
A => A,
DIN => DIN,
DOUT => DOUT,
DDIS => DDIS,
INTR => INTR,
SIN => SIN,
RxRDYn => RxRDYn,
SOUT => SOUT,
TxRDYn => TxRDYn,
DCDn => DCDn,
CTSn => CTSn,
DSRn => DSRn,
RIn => RIn,
DTRn => DTRn,
RTSn => RTSn
);
-- Master Clock Generator
MCLK <= not MCLK after (MCLK_CLK_PERIOD/2);
-- PLL Clock Generator (for simulation purpose)
PCLK <= not PCLK after (CLK_PERIOD/2);
-----------------------------------------------------------------------
-- SIN Generation for UART Receiver Functions Tests
-----------------------------------------------------------------------
SIN_proc: process
begin
-- SIN Initialization
SIN<= '1';
-- Test 1 ----------------------------------------------------
-- 5-bit data receiving test, even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(5,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(5,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 2 ----------------------------------------------------
-- 5-bit data receiving test, odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(5,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(5,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 3 ----------------------------------------------------
-- 5-bit data receiving test, stick even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(5,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(5,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 4 ----------------------------------------------------
-- 5-bit data receiving test, stick odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(5,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(5,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 5 ----------------------------------------------------
-- 5-bit data receiving test, no parity
wait until rising_edge(okToReceiveSIN);
sin_gen(5,"10101010",'0',1.0,false,true,CLK_PERIOD*16, SIN);
sin_gen(5,"01010110",'0',1.0,false,true,CLK_PERIOD*16, SIN);
-- Test 6 ----------------------------------------------------
-- 6-bit data receiving test, even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(6,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(6,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 7 ----------------------------------------------------
-- 6-bit data receiving test, odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(6,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(6,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 8 ----------------------------------------------------
-- 6-bit data receiving test, stick even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(6,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(6,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 9 ----------------------------------------------------
-- 6-bit data receiving test, stick odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(6,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(6,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 10 ---------------------------------------------------
-- 6-bit data receiving test, no parity
wait until rising_edge(okToReceiveSIN);
sin_gen(6,"10101010",'0',1.0,false,true,CLK_PERIOD*16, SIN);
sin_gen(6,"01010110",'0',1.0,false,true,CLK_PERIOD*16, SIN);
-- Test 11 ---------------------------------------------------
-- 7-bit data receiving test, even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(7,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(7,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 12 ---------------------------------------------------
-- 7-bit data receiving test, odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(7,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(7,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 13 ---------------------------------------------------
-- 7-bit data receiving test, stick even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(7,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(7,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 14 ---------------------------------------------------
-- 7-bit data receiving test, stick odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(7,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(7,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 15 ---------------------------------------------------
-- 7-bit data receiving test, no parity
wait until rising_edge(okToReceiveSIN);
sin_gen(7,"10101010",'0',1.0,false,true,CLK_PERIOD*16, SIN);
sin_gen(7,"01010110",'0',1.0,false,true,CLK_PERIOD*16, SIN);
-- Test 16 ---------------------------------------------------
-- 8-bit data receiving test, even parity
wait until rising_edge(okToReceiveSIN);
sin_gen(8,"10101010",'0',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(8,"01010110",'0',1.0,true,true,CLK_PERIOD*16, SIN);
-- Test 17 ---------------------------------------------------
-- 8-bit data receiving test, odd parity
wait until rising_edge(okToReceiveSIN);
sin_gen(8,"10101010",'1',1.0,true,true,CLK_PERIOD*16, SIN);
sin_gen(8,"01010110",'1',1.0,true,true,CLK_PERIOD*16, SIN);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -