1 |
2 |
lal87 |
----------------------------------------------------------------------------
|
2 |
|
|
---- Create Date: 19:12:45 10/24/2010 ----
|
3 |
|
|
---- Design Name: pic_tb ----
|
4 |
|
|
---- Project Name: PIC ----
|
5 |
|
|
---- Description: ----
|
6 |
|
|
---- A testbench code for the pic.vhd code ----
|
7 |
|
|
---- ----
|
8 |
|
|
----------------------------------------------------------------------------
|
9 |
|
|
---- ----
|
10 |
|
|
---- This file is a part of the pic project at ----
|
11 |
|
|
---- http://www.opencores.org/ ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- Author(s): ----
|
14 |
|
|
---- Vipin Lal, lalnitt@gmail.com ----
|
15 |
|
|
---- ----
|
16 |
|
|
----------------------------------------------------------------------------
|
17 |
|
|
---- ----
|
18 |
|
|
---- Copyright (C) 2010 Authors and OPENCORES.ORG ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- This source file may be used and distributed without ----
|
21 |
|
|
---- restriction provided that this copyright statement is not ----
|
22 |
|
|
---- removed from the file and that any derivative work contains ----
|
23 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
24 |
|
|
---- ----
|
25 |
|
|
---- This source file is free software; you can redistribute it ----
|
26 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
27 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
28 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
29 |
|
|
---- later version. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- This source is distributed in the hope that it will be ----
|
32 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
33 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
34 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
35 |
|
|
---- details. ----
|
36 |
|
|
---- ----
|
37 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
38 |
|
|
---- Public License along with this source; if not, download it ----
|
39 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
40 |
|
|
---- ----
|
41 |
|
|
----------------------------------------------------------------------------
|
42 |
|
|
LIBRARY ieee;
|
43 |
|
|
USE ieee.std_logic_1164.ALL;
|
44 |
|
|
USE ieee.numeric_std.ALL;
|
45 |
|
|
|
46 |
|
|
ENTITY pic_tb IS
|
47 |
|
|
END pic_tb;
|
48 |
|
|
|
49 |
|
|
ARCHITECTURE behavior OF pic_tb IS
|
50 |
|
|
|
51 |
|
|
-- Component Declaration for the Unit Under Test (UUT)
|
52 |
|
|
|
53 |
|
|
COMPONENT PIC
|
54 |
|
|
PORT(
|
55 |
|
|
CLK_I : IN std_logic;
|
56 |
|
|
RST_I : IN std_logic;
|
57 |
|
|
IR : IN unsigned(7 downto 0);
|
58 |
|
|
DataBus : INOUT unsigned(7 downto 0);
|
59 |
|
|
INTR_O : OUT std_logic;
|
60 |
|
|
INTA_I : IN std_logic
|
61 |
|
|
);
|
62 |
|
|
END COMPONENT;
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
--Inputs
|
66 |
|
|
signal CLK_I : std_logic := '0';
|
67 |
|
|
signal RST_I : std_logic := '0';
|
68 |
|
|
signal IR : unsigned(7 downto 0) := (others => '0');
|
69 |
|
|
signal INTA_I : std_logic := '1';
|
70 |
|
|
|
71 |
|
|
--BiDirs
|
72 |
|
|
signal DataBus : unsigned(7 downto 0);
|
73 |
|
|
|
74 |
|
|
--Outputs
|
75 |
|
|
signal INTR_O : std_logic;
|
76 |
|
|
|
77 |
|
|
-- Clock period definitions
|
78 |
|
|
constant CLK_period : time := 10 ns;
|
79 |
|
|
|
80 |
|
|
BEGIN
|
81 |
|
|
|
82 |
|
|
-- Instantiate the Unit Under Test (UUT)
|
83 |
|
|
uut: PIC PORT MAP (
|
84 |
|
|
CLK_I => CLK_I,
|
85 |
|
|
RST_I => RST_I,
|
86 |
|
|
IR => IR,
|
87 |
|
|
DataBus => DataBus,
|
88 |
|
|
INTR_O => INTR_O,
|
89 |
|
|
INTA_I => INTA_I
|
90 |
|
|
);
|
91 |
|
|
|
92 |
|
|
-- Clock process definitions
|
93 |
|
|
CLK_I_process :process
|
94 |
|
|
begin
|
95 |
|
|
CLK_I <= '0';
|
96 |
|
|
wait for CLK_period/2;
|
97 |
|
|
CLK_I <= '1';
|
98 |
|
|
wait for CLK_period/2;
|
99 |
|
|
end process;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
-- Stimulus process.
|
103 |
|
|
stim_proc: process
|
104 |
|
|
begin
|
105 |
|
|
DataBus <= (others => 'Z');
|
106 |
|
|
RST_I <= '1';
|
107 |
|
|
wait for clk_period;
|
108 |
|
|
RST_I <= '0';
|
109 |
|
|
wait for clk_period*3;
|
110 |
|
|
DataBus(1 downto 0) <= "01"; --set polling method.
|
111 |
|
|
wait for clk_period;
|
112 |
|
|
DataBus <= (others => 'Z'); --make databus as high impedance.
|
113 |
|
|
wait until INTR_O = '1'; --wait for an interrupt.
|
114 |
|
|
wait for clk_period;
|
115 |
|
|
INTA_I <= '0'; --send ack in the next clk cycle.
|
116 |
|
|
wait for clk_period;
|
117 |
|
|
INTA_I <= '1'; --reset ack.
|
118 |
|
|
wait until DataBus = "01011011"; --wait till info abt interrupt is received.
|
119 |
|
|
wait for clk_period;
|
120 |
|
|
INTA_I <= '0'; --send ack in the next clk cycle.
|
121 |
|
|
wait for clk_period;
|
122 |
|
|
INTA_I <= '1'; --reset ack.
|
123 |
|
|
wait for clk_period*20; --ISR takes 20 clk cycles for execution.
|
124 |
|
|
DataBus <= "10100011"; --tell pic that ISR is completed.
|
125 |
|
|
INTA_I <= '0';
|
126 |
|
|
wait for clk_period;
|
127 |
|
|
INTA_I <= '1';
|
128 |
|
|
DataBus <= (others => 'Z');
|
129 |
|
|
--First interrupt executed successfully.
|
130 |
|
|
|
131 |
|
|
wait for clk_period*10;
|
132 |
|
|
RST_I <= '1';
|
133 |
|
|
wait for clk_period;
|
134 |
|
|
RST_I <= '0';
|
135 |
|
|
wait for clk_period;
|
136 |
|
|
--set polling method and priority of interrupts.
|
137 |
|
|
--descending order of priority: 7,3,4,5,6,1,2,0;
|
138 |
|
|
DataBus <= "11101110";
|
139 |
|
|
wait for clk_period;
|
140 |
|
|
DataBus <= "10010110";
|
141 |
|
|
wait for clk_period;
|
142 |
|
|
DataBus <= "11000110";
|
143 |
|
|
wait for clk_period;
|
144 |
|
|
DataBus <= "01000010";
|
145 |
|
|
wait for clk_period;
|
146 |
|
|
DataBus <= (others => 'Z'); --make databus as high impedance.
|
147 |
|
|
wait until INTR_O = '1'; --wait for an interrupt.
|
148 |
|
|
wait for clk_period;
|
149 |
|
|
INTA_I <= '0'; --send ack in the next clk cycle.
|
150 |
|
|
wait for clk_period;
|
151 |
|
|
INTA_I <= '1'; --reset ack.
|
152 |
|
|
wait until DataBus = "10011011"; --wait till info abt interrupt is received.
|
153 |
|
|
wait for clk_period;
|
154 |
|
|
INTA_I <= '0'; --send ack in the next clk cycle.
|
155 |
|
|
wait for clk_period;
|
156 |
|
|
INTA_I <= '1'; --reset ack.
|
157 |
|
|
wait for clk_period*20; --ISR takes 20 clk cycles for execution.
|
158 |
|
|
DataBus <= "01100011"; --tell pic that ISR is completed.
|
159 |
|
|
INTA_I <= '0';
|
160 |
|
|
wait for clk_period;
|
161 |
|
|
INTA_I <= '1';
|
162 |
|
|
DataBus <= (others => 'Z');
|
163 |
|
|
wait;
|
164 |
|
|
end process;
|
165 |
|
|
|
166 |
|
|
--External interrupts.
|
167 |
|
|
external_ints : process
|
168 |
|
|
begin
|
169 |
|
|
wait for clk_period*15;
|
170 |
|
|
IR(3) <= '1';
|
171 |
|
|
wait until INTA_I='1';
|
172 |
|
|
wait until INTA_I='1';
|
173 |
|
|
IR(3) <= '0';
|
174 |
|
|
wait for clk_period*60;
|
175 |
|
|
IR <= "00101001"; --Interrupts 0,3 and 5.
|
176 |
|
|
wait until INTA_I='1';
|
177 |
|
|
wait until INTA_I='1';
|
178 |
|
|
IR <= (others => '0');
|
179 |
|
|
wait;
|
180 |
|
|
end process;
|
181 |
|
|
|
182 |
|
|
END;
|