axi_present_tb.vhd 9.08 KB
Newer Older
tebina nasreddine's avatar
tebina nasreddine committed
1
2

library IEEE;
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
3
4
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
tebina nasreddine's avatar
tebina nasreddine committed
5

tebina nasreddine's avatar
tebina nasreddine committed
6
7
8
9
10
11

entity axi_present_tb is
end axi_present_tb;

architecture Behavioral of axi_present_tb is

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	component axi_present is
		generic (
			ADRWIDTH : integer := 8;
			DATAWIDTH : integer := 32
		);
		port (
			-- AXI SLAVE INTERFACE ----------------------------
			-- Clock and Reset
			S_AXI_ACLK : in std_logic;
			S_AXI_ARESETN : in std_logic;
			-- Write Address Channel
			S_AXI_AWADDR : in std_logic_vector(ADRWIDTH - 1 downto 0);
			S_AXI_AWVALID : in std_logic;
			S_AXI_AWREADY : out std_logic;
			S_AXI_AWPROT : in std_logic_vector(2 downto 0); --addr write protection
			-- Write Data Channel
			S_AXI_WDATA : in std_logic_vector(DATAWIDTH - 1 downto 0);
			S_AXI_WSTRB : in std_logic_vector(3 downto 0);
			S_AXI_WVALID : in std_logic;
			S_AXI_WREADY : out std_logic;
			-- Read Address Channel
			S_AXI_ARADDR : in std_logic_vector(ADRWIDTH - 1 downto 0);
			S_AXI_ARVALID : in std_logic;
			S_AXI_ARREADY : out std_logic;
			S_AXI_ARPROT : in std_logic_vector(2 downto 0); --addr read protection
			-- Read Data Channel
			S_AXI_RDATA : out std_logic_vector(DATAWIDTH - 1 downto 0);
			S_AXI_RRESP : out std_logic_vector(1 downto 0);
			S_AXI_RVALID : out std_logic;
			S_AXI_RREADY : in std_logic;
tebina nasreddine's avatar
tebina nasreddine committed
42
			-- Write Response Channel
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
43
44
45
			S_AXI_BRESP : out std_logic_vector(1 downto 0);
			S_AXI_BVALID : out std_logic;
			S_AXI_BREADY : in std_logic;
tebina nasreddine's avatar
tebina nasreddine committed
46
47
			state_signal : out std_logic_vector (2 downto 0);
			ip_plaintext_signal : out std_logic_vector (63 downto 0);
tebina nasreddine's avatar
tebina nasreddine committed
48
		    ip_ciphertext_buffer : out std_logic_vector (31 downto 0);
tebina nasreddine's avatar
tebina nasreddine committed
49
50
51
52
53
		    counter_signal : out natural;
		    ip_key_signal :  out std_logic_vector (127 downto 0);
		    ip_key_buffer : out std_logic_vector (31 downto 0);
		    ip_ciphertext_signal : out std_logic_vector (63 downto 0)

tebina nasreddine's avatar
tebina nasreddine committed
54
	
tebina nasreddine's avatar
tebina nasreddine committed
55
			
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
56
57
58
59
60
		);
	end component;
	constant ADRWIDTH : integer := 8;
	constant DATAWIDTH : integer := 32;
	constant clk_period : time := 1 ns;
tebina nasreddine's avatar
tebina nasreddine committed
61

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	signal S_AXI_ACLK : std_logic := '0';
	signal S_AXI_ARESETN : std_logic := '0';
	-- Write Address Channel signals
	signal S_AXI_AWADDR : std_logic_vector(ADRWIDTH - 1 downto 0) := (others => '0');
	signal S_AXI_AWVALID : std_logic := '0';
	signal S_AXI_AWREADY : std_logic := '1';
	-- Write Data Channel signals
	signal S_AXI_WDATA : std_logic_vector(31 downto 0) := (others => '0');
	signal S_AXI_WSTRB : std_logic_vector(3 downto 0) := (others => '0');
	signal S_AXI_WVALID : std_logic := '0';
	signal S_AXI_WREADY : std_logic;
	-- Read Address Channel signals
	signal S_AXI_ARADDR : std_logic_vector(ADRWIDTH - 1 downto 0) := (others => '0');
	signal S_AXI_ARVALID : std_logic := '0';
	signal S_AXI_ARREADY : std_logic := '1';
	-- Read Data Channel signals
	signal S_AXI_RRESP : std_logic_vector(1 downto 0);
	signal S_AXI_RVALID : std_logic;
	signal S_AXI_RREADY : std_logic := '0';
	-- Write Response Channel signals
	signal S_AXI_BRESP : std_logic_vector(1 downto 0);
	signal S_AXI_BVALID : std_logic;
	signal S_AXI_BREADY : std_logic := '0';
	signal S_AXI_AWPROT : std_logic_vector (2 downto 0) := "010";
	signal S_AXI_ARPROT : std_logic_vector (2 downto 0) := "010";
	signal S_AXI_RDATA : std_logic_vector(31 downto 0) := (others => '0');
	signal state_signal : std_logic_vector (2 downto 0);
tebina nasreddine's avatar
tebina nasreddine committed
89
	signal ip_plaintext_signal : std_logic_vector ( 63 downto 0 );
tebina nasreddine's avatar
tebina nasreddine committed
90
	signal ip_ciphertext_buffer : std_logic_vector ( 31 downto 0 );
tebina nasreddine's avatar
tebina nasreddine committed
91
92
93
94
    signal counter_signal : natural ;
    signal ip_key_signal : std_logic_vector (127 downto 0);
	signal ip_key_buffer : std_logic_vector (31 downto 0);
	signal ip_ciphertext_signal : std_logic_vector (63 downto 0);
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
95
96
97
98
99
100
	--------------------------------------------------------
	constant ClockPeriod : time := 5 ns;
	constant ClockPeriod2 : time := 10 ns;
	shared variable ClockCount : integer range 0 to 50_000 := 10;
	signal sendIt : std_logic := '0';
	signal readIt : std_logic := '0';
tebina nasreddine's avatar
tebina nasreddine committed
101
102

begin
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	UUT : axi_present
 
	port map(
		S_AXI_ACLK => S_AXI_ACLK, 
		S_AXI_ARESETN => S_AXI_ARESETN, 
		S_AXI_AWADDR => S_AXI_AWADDR, 
		S_AXI_AWVALID => S_AXI_AWVALID, 
		S_AXI_AWREADY => S_AXI_AWREADY, 
		S_AXI_AWPROT => S_AXI_AWPROT, 
		S_AXI_WDATA => S_AXI_WDATA, 
		S_AXI_WSTRB => S_AXI_WSTRB, 
		S_AXI_WVALID => S_AXI_WVALID, 
		S_AXI_WREADY => S_AXI_WREADY, 
		S_AXI_BRESP => S_AXI_BRESP, 
		S_AXI_BVALID => S_AXI_BVALID, 
		S_AXI_BREADY => S_AXI_BREADY, 
		S_AXI_ARADDR => S_AXI_ARADDR, 
		S_AXI_ARVALID => S_AXI_ARVALID, 
		S_AXI_ARREADY => S_AXI_ARREADY, 
		S_AXI_ARPROT => S_AXI_ARPROT, 
		S_AXI_RRESP => S_AXI_RRESP, 
		S_AXI_RVALID => S_AXI_RVALID, 
		S_AXI_RREADY => S_AXI_RREADY, 
		S_AXI_RDATA => S_AXI_RDATA, 
tebina nasreddine's avatar
tebina nasreddine committed
127
128
		state_signal => state_signal,
		ip_plaintext_signal => ip_plaintext_signal,
tebina nasreddine's avatar
tebina nasreddine committed
129
		ip_ciphertext_buffer => ip_ciphertext_buffer,
tebina nasreddine's avatar
tebina nasreddine committed
130
131
132
133
		counter_signal => counter_signal,
		ip_key_signal => ip_key_signal,
		ip_key_buffer => ip_key_buffer,
		ip_ciphertext_signal => ip_ciphertext_signal
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
134
135
136
		--------------------------------------------------------
	);
	--stimulus :process
tebina nasreddine's avatar
tebina nasreddine committed
137

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
138
139
140
	--begin
	--S_AXI_ARESETN <= '1';
	--wait for 200 ns;
tebina nasreddine's avatar
tebina nasreddine committed
141

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	--S_AXI_ARESETN <= '0';
	----write Address
	--S_AXI_AWADDR <= "000000000000010";
	--S_AXI_AWVALID <= '1';
	--S_AXI_WDATA <= (others => '1');
	--S_AXI_WSTRB <= "1111";
	--S_AXI_WVALID <= '1';
	--S_AXI_ARADDR <= "000000000000000";
	--wait for 250 ns;
	--S_AXI_ARVALID <= '1';
	--S_AXI_RREADY <= '1';
	--S_AXI_BREADY <= '1';
	--wait for 500 ns;
	--end process;
	-- Generate S_AXI_ACLK signal
	GENERATE_REFCLOCK : process
	begin
		wait for (ClockPeriod / 2);
		ClockCount := ClockCount + 1;
		S_AXI_ACLK <= '1';
		wait for (ClockPeriod / 2);
		S_AXI_ACLK <= '0';
	end process;
tebina nasreddine's avatar
tebina nasreddine committed
165

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
166
167
168
169
170
171
172
173
174
175
176
177
178
	send : process
	begin
		S_AXI_AWVALID <= '0';
		S_AXI_WVALID <= '0';
		S_AXI_BREADY <= '0';
		loop
		wait until sendIt = '1';
		wait until S_AXI_ACLK = '0';
		S_AXI_AWVALID <= '1';
		S_AXI_WVALID <= '1';
		wait until (S_AXI_AWREADY and S_AXI_WREADY) = '1'; --Client ready to read address/data 
		S_AXI_BREADY <= '1';
		wait until S_AXI_BVALID = '1'; -- Write result valid
tebina nasreddine's avatar
tebina nasreddine committed
179
		assert S_AXI_BRESP = "00" report "AXI data NOT written" severity failure;
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
180
181
182
		S_AXI_AWVALID <= '0';
		S_AXI_WVALID <= '0';
		S_AXI_BREADY <= '1';
tebina nasreddine's avatar
tebina nasreddine committed
183
		
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
184
185
186
187
		wait until S_AXI_BVALID = '0'; -- All finished
		S_AXI_BREADY <= '0';
	end loop;
	end process send;
tebina nasreddine's avatar
tebina nasreddine committed
188

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
	read : process
	begin
		S_AXI_ARVALID <= '0';
		S_AXI_RREADY <= '0';
		loop
		wait until readIt = '1';
		wait until S_AXI_ACLK = '0';
		S_AXI_ARVALID <= '1';
		S_AXI_RREADY <= '1';
		wait until (S_AXI_RVALID and S_AXI_ARREADY) = '1'; --Client provided data
		assert S_AXI_RRESP = "00" report "AXI data NOT written" severity failure;
		S_AXI_ARVALID <= '0';
		S_AXI_RREADY <= '0';
	end loop;
	end process read;
	--
	tb : process
	begin
		S_AXI_ARESETN <= '0';
		sendIt <= '0';
		wait for 15 ns;
		S_AXI_ARESETN <= '1';
tebina nasreddine's avatar
tebina nasreddine committed
211

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
212
		S_AXI_AWADDR <= x"01";
tebina nasreddine's avatar
tebina nasreddine committed
213
		S_AXI_WDATA <= x"deadbeef";
tebina nasreddine's avatar
tebina nasreddine committed
214
		S_AXI_WSTRB <= b"0000";
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
215
216
217
218
219
220
221
222
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"01";
tebina nasreddine's avatar
tebina nasreddine committed
223
		S_AXI_WDATA <= x"deaddead";
tebina nasreddine's avatar
tebina nasreddine committed
224
		S_AXI_WSTRB <= b"0000";
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
225
226
227
228
229
230
231
232
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"01";
tebina nasreddine's avatar
tebina nasreddine committed
233
		S_AXI_WDATA <= x"beafbeaf";
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
234
235
236
237
238
239
240
241
242
		S_AXI_WSTRB <= b"1111";
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"01";
tebina nasreddine's avatar
tebina nasreddine committed
243
		S_AXI_WDATA <= x"B16B00B5";
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
244
245
246
247
248
249
250
251
252
		S_AXI_WSTRB <= b"1111";
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"01";
tebina nasreddine's avatar
tebina nasreddine committed
253
		S_AXI_WDATA <= x"00000000";
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
		S_AXI_WSTRB <= b"1111";
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"04";
		S_AXI_WDATA <= x"A5A5A5A5";
		S_AXI_WSTRB <= b"1111";
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
		S_AXI_AWADDR <= x"04";
		S_AXI_WDATA <= x"A5A5A5A5";
		S_AXI_WSTRB <= b"1111";
		sendIt <= '1'; --Start AXI Write to Slave
		wait for 1 ns;
		sendIt <= '0'; --Clear Start Send Flag
		wait until S_AXI_BVALID = '1';
		wait until S_AXI_BVALID = '0'; --AXI Write finished
		S_AXI_WSTRB <= b"0000";
 
tebina nasreddine's avatar
?    
tebina nasreddine committed
282
 
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
283
284
		S_AXI_ARADDR <= "00000000";
		readIt <= '1'; --Start AXI Read from Slave
tebina nasreddine's avatar
?    
tebina nasreddine committed
285
		wait for 5 ns;
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
286
287
288
289
290
		readIt <= '0'; --Clear "Start Read" Flag
		wait until S_AXI_RVALID = '1';
		wait until S_AXI_RVALID = '0';
		S_AXI_ARADDR <= "00000010";
		readIt <= '1'; --Start AXI Read from Slave
tebina nasreddine's avatar
?    
tebina nasreddine committed
291
		wait for 5 ns;
tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
292
293
294
295
296
297
		readIt <= '0'; --Clear "Start Read" Flag
		wait until S_AXI_RVALID = '1';
		wait until S_AXI_RVALID = '0';
 
		wait; -- will wait forever
	end process tb;
tebina nasreddine's avatar
tebina nasreddine committed
298

tebina nasreddine's avatar
cleanup    
tebina nasreddine committed
299
end Behavioral;