1 |
2 |
danielqg |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : PS/2 interface Testbench
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : ps2.vhd
|
6 |
|
|
-- Author : Daniel Quintero <danielqg@infonegocio.com>
|
7 |
|
|
-- Company : Itoo Software
|
8 |
|
|
-- Created : 2003-04-14
|
9 |
|
|
-- Last update: 2003-10-30
|
10 |
|
|
-- Platform : VHDL'87
|
11 |
|
|
-------------------------------------------------------------------------------
|
12 |
|
|
-- Description: PS/2 generic UART for mice/keyboard, Wishbone Testbench
|
13 |
|
|
-------------------------------------------------------------------------------
|
14 |
|
|
-- This code is distributed under the terms and conditions of the
|
15 |
|
|
-- GNU General Public License
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-- Revisions :
|
18 |
|
|
-- Date Version Author Description
|
19 |
|
|
-- 2003-04-14 1.0 daniel Created
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
library ieee, work;
|
23 |
|
|
use ieee.std_logic_1164.all;
|
24 |
|
|
use work.wb_test.all;
|
25 |
|
|
|
26 |
|
|
entity wb_ps2_tb is
|
27 |
|
|
-- Generic declarations of the tested unit
|
28 |
|
|
generic(
|
29 |
|
|
addr_width : positive := 1;
|
30 |
|
|
bus_width : positive := 8);
|
31 |
|
|
end wb_ps2_tb;
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
architecture sim of wb_ps2_tb is
|
35 |
|
|
-- Component declaration of the tested unit
|
36 |
|
|
component ps2_wb
|
37 |
|
|
port (
|
38 |
|
|
wb_clk_i : in std_logic;
|
39 |
|
|
wb_rst_i : in std_logic;
|
40 |
|
|
wb_dat_i : in std_logic_vector(7 downto 0);
|
41 |
|
|
wb_dat_o : out std_logic_vector(7 downto 0);
|
42 |
|
|
wb_adr_i : in std_logic_vector(0 downto 0);
|
43 |
|
|
wb_stb_i : in std_logic;
|
44 |
|
|
wb_we_i : in std_logic;
|
45 |
|
|
wb_ack_o : out std_logic;
|
46 |
|
|
irq_o : out std_logic;
|
47 |
|
|
ps2_clk : inout std_logic;
|
48 |
|
|
ps2_dat : inout std_logic);
|
49 |
|
|
end component;
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
component ps2mouse
|
53 |
|
|
port (
|
54 |
|
|
PS2_clk : inout std_logic;
|
55 |
|
|
PS2_data : inout std_logic);
|
56 |
|
|
end component;
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
signal adr_i : std_logic_vector (addr_width-1 downto 0) := (others => '0');
|
61 |
|
|
-- Stimulus signals - signals mapped to the input and inout ports of tested entity
|
62 |
|
|
signal clk_i : std_logic := '0';
|
63 |
|
|
signal rst_i : std_logic := '0';
|
64 |
|
|
signal cyc_i : std_logic;
|
65 |
|
|
signal stb_i : std_logic;
|
66 |
|
|
signal we_i : std_logic;
|
67 |
|
|
signal dat_i : std_logic_vector((bus_width-1) downto 0);
|
68 |
|
|
|
69 |
|
|
-- Observed signals - signals mapped to the output ports of tested entity
|
70 |
|
|
signal ack_o : std_logic;
|
71 |
|
|
signal dat_o : std_logic_vector((bus_width-1) downto 0);
|
72 |
|
|
signal irq_o : std_logic;
|
73 |
|
|
signal ps2_clk : std_logic;
|
74 |
|
|
signal ps2_dat : std_logic;
|
75 |
|
|
|
76 |
|
|
signal done : boolean := false;
|
77 |
|
|
|
78 |
|
|
-- Add your code here ...
|
79 |
|
|
|
80 |
|
|
begin
|
81 |
|
|
-- Unit Under Test port map
|
82 |
|
|
ps2_wb_1 : ps2_wb
|
83 |
|
|
port map (
|
84 |
|
|
wb_clk_i => clk_i,
|
85 |
|
|
wb_rst_i => rst_i,
|
86 |
|
|
wb_dat_i => dat_i,
|
87 |
|
|
wb_dat_o => dat_o,
|
88 |
|
|
wb_adr_i => adr_i,
|
89 |
|
|
wb_stb_i => stb_i,
|
90 |
|
|
wb_we_i => we_i,
|
91 |
|
|
wb_ack_o => ack_o,
|
92 |
|
|
irq_o => irq_o,
|
93 |
|
|
ps2_clk => ps2_clk,
|
94 |
|
|
ps2_dat => ps2_dat);
|
95 |
|
|
|
96 |
|
|
ps2mouse_1 : ps2mouse
|
97 |
|
|
port map (
|
98 |
|
|
PS2_clk => ps2_clk,
|
99 |
|
|
PS2_data => ps2_dat);
|
100 |
|
|
|
101 |
|
|
clk : process is
|
102 |
|
|
begin
|
103 |
|
|
while not done loop
|
104 |
|
|
clk_i <= not clk_i;
|
105 |
|
|
wait for 25 ns; -- 20Mhz clock
|
106 |
|
|
end loop;
|
107 |
|
|
wait;
|
108 |
|
|
end process;
|
109 |
|
|
|
110 |
|
|
reset : process is
|
111 |
|
|
begin
|
112 |
|
|
rst_i <= '1';
|
113 |
|
|
wait for 150 ns;
|
114 |
|
|
rst_i <= '0';
|
115 |
|
|
wait;
|
116 |
|
|
end process;
|
117 |
|
|
|
118 |
|
|
master : process is
|
119 |
|
|
variable status : std_logic_vector(7 downto 0);
|
120 |
|
|
begin
|
121 |
|
|
we_i <= '0';
|
122 |
|
|
cyc_i <= '0';
|
123 |
|
|
stb_i <= '0';
|
124 |
|
|
adr_i <= (others => '0');
|
125 |
|
|
dat_i <= (others => '0');
|
126 |
|
|
wait until clk_i'event and clk_i = '1';
|
127 |
|
|
wait until clk_i'event and clk_i = '1';
|
128 |
|
|
wait until clk_i'event and clk_i = '1';
|
129 |
|
|
wait until clk_i'event and clk_i = '1';
|
130 |
|
|
wait until clk_i'event and clk_i = '1';
|
131 |
|
|
wait until clk_i'event and clk_i = '1';
|
132 |
|
|
wait until clk_i'event and clk_i = '1';
|
133 |
|
|
|
134 |
|
|
-- Check control register, interrupt status bits
|
135 |
|
|
wr_chk_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","11000000");
|
136 |
|
|
wr_chk_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","10000000");
|
137 |
|
|
wr_chk_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","01000000");
|
138 |
|
|
wr_chk_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","00000000");
|
139 |
|
|
|
140 |
|
|
-- Check for transmit
|
141 |
|
|
wr_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","11000000");
|
142 |
|
|
wr_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "0","01010101");
|
143 |
|
|
|
144 |
|
|
-- wait for end of transmit
|
145 |
|
|
status := (others => '1');
|
146 |
|
|
while status(0) = '1' loop
|
147 |
|
|
rd_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1",status);
|
148 |
|
|
end loop;
|
149 |
|
|
|
150 |
|
|
-- wait for receive data
|
151 |
|
|
while status(1) = '0' loop
|
152 |
|
|
rd_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1",status);
|
153 |
|
|
end loop;
|
154 |
|
|
|
155 |
|
|
-- Get data
|
156 |
|
|
rd_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1",status);
|
157 |
|
|
|
158 |
|
|
-- Clear flag
|
159 |
|
|
wr_val (clk_i, adr_i, dat_o, dat_i, we_i, cyc_i, stb_i, ack_o, "1","11000000");
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
done <= true;
|
163 |
|
|
end process;
|
164 |
|
|
end sim;
|
165 |
|
|
|