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

Subversion Repositories uart

[/] [uart/] [trunk/] [UARTtest.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 7 olupas
      variable temp : bit := '0';
161 2 olupas
  begin
162
     if Rising_Edge(Reset) then
163
        counter := "0000";
164
          WR_N <= '1';
165
          RD_N <= '1';
166
          CS_N <= '1';
167
     elsif Rising_Edge(Clk) then
168
        if IntTx_N = '0' then
169 7 olupas
           if temp = '0' then
170
              temp := '1';
171
              case counter is
172
                 when "0000" =>
173
                      Addr <= "00";
174
                      DataIn <= x"AA";
175
                      WR_N <= '0';
176
                      CS_N <= '0';
177
                      counter := counter + cone;
178
                 when "0001" =>
179
                      Addr <= "00";
180
                      DataIn <= x"AF";
181
                      WR_N <= '0';
182
                      CS_N <= '0';
183
                      counter := counter + cone;
184
                 when "0010" =>
185
                      Addr <= "00";
186
                      DataIn <= x"55";
187
                      WR_N <= '0';
188
                      CS_N <= '0';
189
                      counter := counter + cone;
190
                 when "0011" =>
191
                      Addr <= "00";
192
                      DataIn <= x"E8";
193
                      WR_N <= '0';
194
                      CS_N <= '0';
195
                      counter := "0000";
196
                 when others => null;
197
              end case;
198
           elsif temp = '1' then
199
              temp := '0';
200
           end if;
201 2 olupas
        elsif IntRx_N = '0' then
202
           Addr <= "00";
203
           RD_N <= '0';
204
           CS_N <= '0';
205
        else
206
          RD_N <= '1';
207
          CS_N <= '1';
208
          WR_N <= '1';
209
          DataIn <= "ZZZZZZZZ";
210
        end if;
211
     end if;
212
  end process;
213
end stimulus; --================== End of TestBench ==================--

powered by: WebSVN 2.1.0

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