1 |
2 |
olupas |
--============================================================================--
|
2 |
|
|
-- Design units : TestBench for miniUART device.
|
3 |
|
|
--
|
4 |
|
|
-- File name : UARTTest.vhd
|
5 |
|
|
--
|
6 |
|
|
-- Purpose : Implements the test bench for miniUART device.
|
7 |
|
|
--
|
8 |
|
|
-- Library : uart_Lib.vhd
|
9 |
|
|
--
|
10 |
|
|
-- Dependencies : IEEE.Std_Logic_1164
|
11 |
|
|
--
|
12 |
|
|
--------------------------------------------------------------------------------
|
13 |
|
|
--------------------------------------------------------------------------------
|
14 |
|
|
-- Revision list
|
15 |
|
|
-- Version Author Date Changes
|
16 |
|
|
--
|
17 |
|
|
-- 0.1 Ovidiu Lupas December 1999 New model
|
18 |
|
|
--------------------------------------------------------------------------------
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
-- Clock generator
|
21 |
|
|
-------------------------------------------------------------------------------
|
22 |
|
|
library IEEE,work;
|
23 |
|
|
use IEEE.Std_Logic_1164.all;
|
24 |
|
|
--
|
25 |
|
|
entity ClkGen is
|
26 |
|
|
port (
|
27 |
|
|
Clk : out Std_Logic); -- Oscillator clock
|
28 |
|
|
end ClkGen;--==================== End of entity ==============================--
|
29 |
|
|
--------------------------------------------------------------------------------
|
30 |
|
|
-- Architecture for clock and reset signals generator
|
31 |
|
|
--------------------------------------------------------------------------------
|
32 |
|
|
architecture Behaviour of ClkGen is
|
33 |
|
|
begin --========================== Architecture ==============================--
|
34 |
|
|
------------------------------------------------------------------------------
|
35 |
|
|
-- Provide the system clock signal
|
36 |
|
|
------------------------------------------------------------------------------
|
37 |
|
|
ClkDriver : process
|
38 |
|
|
variable clktmp : Std_Logic := '1';
|
39 |
|
|
variable tpw_CI_posedge : Time := 12 ns; -- ~40 MHz
|
40 |
|
|
begin
|
41 |
|
|
Clk <= clktmp;
|
42 |
|
|
clktmp := not clktmp;
|
43 |
|
|
wait for tpw_CI_posedge;
|
44 |
|
|
end process;
|
45 |
|
|
end Behaviour; --=================== End of architecure =====================--
|
46 |
|
|
-------------------------------------------------------------------------------
|
47 |
|
|
-- LoopBack Device
|
48 |
|
|
-------------------------------------------------------------------------------
|
49 |
|
|
library IEEE,work;
|
50 |
|
|
use IEEE.Std_Logic_1164.all;
|
51 |
|
|
--
|
52 |
|
|
entity LoopBack is
|
53 |
|
|
port (
|
54 |
|
|
Clk : in Std_Logic; -- Oscillator clock
|
55 |
|
|
RxWr : in Std_Logic; -- Rx line
|
56 |
|
|
TxWr : out Std_Logic); -- Tx line
|
57 |
|
|
end LoopBack; --==================== End of entity ==========================--
|
58 |
|
|
--------------------------------------------------------------------------------
|
59 |
|
|
-- Architecture for clock and reset signals generator
|
60 |
|
|
--------------------------------------------------------------------------------
|
61 |
|
|
architecture Behaviour of LoopBack is
|
62 |
|
|
begin --========================== Architecture ==============================--
|
63 |
|
|
------------------------------------------------------------------------------
|
64 |
|
|
-- Provide the external clock signal
|
65 |
|
|
------------------------------------------------------------------------------
|
66 |
|
|
ClkTrig : process(Clk)
|
67 |
|
|
begin
|
68 |
|
|
TxWr <= RxWr;
|
69 |
|
|
end process;
|
70 |
|
|
end Behaviour; --=================== End of architecure =====================--
|
71 |
|
|
|
72 |
|
|
--------------------------------------------------------------------------------
|
73 |
|
|
-- Testbench for UART device
|
74 |
|
|
--------------------------------------------------------------------------------
|
75 |
|
|
library ieee;
|
76 |
|
|
use ieee.std_logic_1164.all;
|
77 |
|
|
use ieee.numeric_std.all;
|
78 |
|
|
library work;
|
79 |
|
|
use work.Uart_Def.all;
|
80 |
|
|
|
81 |
|
|
entity UARTTEST is
|
82 |
|
|
end UARTTEST;
|
83 |
|
|
|
84 |
|
|
architecture stimulus of UARTTEST is
|
85 |
|
|
-------------------------------------------------------------------
|
86 |
|
|
-- Signals
|
87 |
|
|
-------------------------------------------------------------------
|
88 |
|
|
signal Reset : Std_Logic; -- Synchro signal
|
89 |
|
|
signal Clk : Std_Logic; -- Clock signal
|
90 |
|
|
signal DataIn : Std_Logic_Vector(7 downto 0);
|
91 |
|
|
signal DataOut : Std_Logic_Vector(7 downto 0);
|
92 |
|
|
signal RxD : Std_Logic; -- RS-232 data input
|
93 |
|
|
signal TxD : Std_Logic; -- RS-232 data output
|
94 |
|
|
signal CS_N : Std_Logic;
|
95 |
|
|
signal RD_N : Std_Logic;
|
96 |
|
|
signal WR_N : Std_Logic;
|
97 |
|
|
signal IntRx_N : Std_Logic; -- Receive interrupt
|
98 |
|
|
signal IntTx_N : Std_Logic; -- Transmit interrupt
|
99 |
|
|
signal Addr : Std_Logic_Vector(1 downto 0); --
|
100 |
|
|
-------------------------------------------------------------------
|
101 |
|
|
-- Clock Divider
|
102 |
|
|
-------------------------------------------------------------------
|
103 |
|
|
component ClkGen is
|
104 |
|
|
port (
|
105 |
|
|
Clk : out Std_Logic); -- Oscillator clock
|
106 |
|
|
end component;
|
107 |
|
|
-------------------------------------------------------------------
|
108 |
|
|
-- LoopBack Device
|
109 |
|
|
-------------------------------------------------------------------
|
110 |
|
|
component LoopBack is
|
111 |
|
|
port (
|
112 |
|
|
Clk : in Std_Logic; -- Oscillator clock
|
113 |
|
|
RxWr : in Std_Logic; -- Rx line
|
114 |
|
|
TxWr : out Std_Logic); -- Tx line
|
115 |
|
|
end component;
|
116 |
|
|
-------------------------------------------------------------------
|
117 |
|
|
-- UART Device
|
118 |
|
|
-------------------------------------------------------------------
|
119 |
|
|
component miniUART is
|
120 |
|
|
port (
|
121 |
|
|
SysClk : in Std_Logic; -- System Clock
|
122 |
|
|
Reset : in Std_Logic; -- Reset input
|
123 |
|
|
CS_N : in Std_Logic;
|
124 |
|
|
RD_N : in Std_Logic;
|
125 |
|
|
WR_N : in Std_Logic;
|
126 |
|
|
RxD : in Std_Logic;
|
127 |
|
|
TxD : out Std_Logic;
|
128 |
|
|
IntRx_N : out Std_Logic; -- Receive interrupt
|
129 |
|
|
IntTx_N : out Std_Logic; -- Transmit interrupt
|
130 |
|
|
Addr : in Std_Logic_Vector(1 downto 0); --
|
131 |
|
|
DataIn : in Std_Logic_Vector(7 downto 0); --
|
132 |
|
|
DataOut : out Std_Logic_Vector(7 downto 0)); --
|
133 |
|
|
end component;
|
134 |
|
|
begin --======================== Architecture ========================--
|
135 |
|
|
---------------------------------------------------------------------
|
136 |
|
|
-- Instantiation of components
|
137 |
|
|
---------------------------------------------------------------------
|
138 |
|
|
Clock : ClkGen port map (Clk);
|
139 |
|
|
LoopDev : LoopBack port map (Clk,TxD,RxD);
|
140 |
|
|
miniUARTDev : miniUART port map (Clk,Reset,CS_N,RD_N,WR_N,RxD,TxD,
|
141 |
|
|
IntRx_N,IntTx_N,Addr,DataIn,DataOut);
|
142 |
|
|
---------------------------------------------------------------------
|
143 |
|
|
-- Reset cycle
|
144 |
|
|
---------------------------------------------------------------------
|
145 |
|
|
RstCyc : process
|
146 |
|
|
begin
|
147 |
|
|
Reset <= '1';
|
148 |
|
|
wait for 5 ns;
|
149 |
|
|
Reset <= '0';
|
150 |
|
|
wait for 250 ns;
|
151 |
|
|
Reset <= '1';
|
152 |
|
|
wait;
|
153 |
|
|
end process;
|
154 |
|
|
---------------------------------------------------------------------
|
155 |
|
|
--
|
156 |
|
|
---------------------------------------------------------------------
|
157 |
|
|
ProcCyc : process(Clk,IntRx_N,IntTx_N,Reset)
|
158 |
|
|
variable counter : unsigned(3 downto 0);
|
159 |
|
|
constant cone : unsigned(3 downto 0):= "0001";
|
160 |
|
|
begin
|
161 |
|
|
if Rising_Edge(Reset) then
|
162 |
|
|
counter := "0000";
|
163 |
|
|
WR_N <= '1';
|
164 |
|
|
RD_N <= '1';
|
165 |
|
|
CS_N <= '1';
|
166 |
|
|
elsif Rising_Edge(Clk) then
|
167 |
|
|
if IntTx_N = '0' then
|
168 |
|
|
case counter is
|
169 |
|
|
when "0000" =>
|
170 |
|
|
Addr <= "00";
|
171 |
|
|
DataIn <= x"AA";
|
172 |
|
|
WR_N <= '0';
|
173 |
|
|
CS_N <= '0';
|
174 |
|
|
counter := counter + cone;
|
175 |
|
|
when "0001" =>
|
176 |
|
|
Addr <= "00";
|
177 |
|
|
DataIn <= x"55";
|
178 |
|
|
WR_N <= '0';
|
179 |
|
|
CS_N <= '0';
|
180 |
|
|
counter := "0000";
|
181 |
|
|
when others => null;
|
182 |
|
|
end case;
|
183 |
|
|
elsif IntRx_N = '0' then
|
184 |
|
|
Addr <= "00";
|
185 |
|
|
RD_N <= '0';
|
186 |
|
|
CS_N <= '0';
|
187 |
|
|
else
|
188 |
|
|
RD_N <= '1';
|
189 |
|
|
CS_N <= '1';
|
190 |
|
|
WR_N <= '1';
|
191 |
|
|
DataIn <= "ZZZZZZZZ";
|
192 |
|
|
end if;
|
193 |
|
|
end if;
|
194 |
|
|
end process;
|
195 |
|
|
end stimulus; --================== End of TestBench ==================--
|