@@ -34,7 +34,8 @@ entity axi_master is
3434 );
3535 port (
3636 aclk : in std_logic ;
37-
37+ areset_n : in std_logic ;
38+
3839 arvalid : out std_logic := '0' ;
3940 arready : in std_logic ;
4041 arid : out std_logic_vector ;
@@ -128,6 +129,16 @@ begin
128129 end if ;
129130 end procedure ;
130131
132+ procedure drive_idle is
133+ begin
134+ arvalid <= '0' ;
135+ awvalid <= '0' ;
136+ wvalid <= '0' ;
137+ drive_ar_invalid;
138+ drive_aw_invalid;
139+ drive_w_invalid;
140+ end procedure ;
141+
131142 function get_full_read_size return std_logic_vector is
132143 begin
133144 return std_logic_vector (to_unsigned (integer (ceil (log2 (real (rdata'length / 8 )))), arsize'length ));
@@ -154,21 +165,19 @@ begin
154165 begin
155166 -- Initialization
156167 rnd.InitSeed(rnd'instance_name );
157- drive_ar_invalid;
158- drive_aw_invalid;
159- drive_w_invalid;
168+ drive_idle;
160169
161170 loop
162- wait until rising_edge (aclk) and not is_empty(message_queue);
171+ wait until rising_edge (aclk) and not is_empty(message_queue) and areset_n = '1' ;
163172 idle <= false ;
164173 wait for 0 ps ;
165174
166175 request_msg := pop(message_queue);
167176 msg_type := message_type(request_msg);
168177
169178 if is_read(msg_type) then
170- while rnd.Uniform(0.0 , 1.0 ) > axi_master_handle.p_read_high_probability loop
171- wait until rising_edge (aclk);
179+ while rnd.Uniform(0.0 , 1.0 ) > axi_master_handle.p_read_high_probability and areset_n = '1' loop
180+ wait until rising_edge (aclk) or areset_n = '0' ;
172181 end loop ;
173182
174183 addr := pop_std_ulogic_vector(request_msg);
@@ -216,7 +225,7 @@ begin
216225 push(read_reply_queue, request_msg);
217226
218227 arvalid <= '1' ;
219- wait until (arvalid and arready) = '1' and rising_edge (aclk);
228+ wait until (( arvalid and arready) = '1' and rising_edge (aclk)) or areset_n = '0' ;
220229 arvalid <= '0' ;
221230 drive_ar_invalid;
222231
@@ -319,6 +328,14 @@ begin
319328 unexpected_msg_type(msg_type);
320329 end if ;
321330
331+ if areset_n = '0' then
332+ drive_idle;
333+ flush(read_reply_queue);
334+ flush(write_reply_queue);
335+ flush(message_queue);
336+ wait for 0 ps ;
337+ end if ;
338+
322339 idle <= true ;
323340 end loop ;
324341 end process ;
@@ -345,40 +362,47 @@ begin
345362 begin
346363
347364 rready <= '1' ;
348- wait until (rvalid and rready) = '1' and rising_edge (aclk);
365+ wait until (( rvalid and rready) = '1' and rising_edge (aclk) );
349366
350- reply_msg := new_msg;
351- request_msg := pop(read_reply_queue);
352- msg_type := message_type(request_msg);
353-
354- addr := pop_std_ulogic_vector(request_msg);
355- len := pop_integer(request_msg);
356- size := pop_std_ulogic_vector(request_msg);
357- burst := pop_std_ulogic_vector(request_msg);
358- id := pop_std_ulogic_vector(request_msg);
359- resp := pop(request_msg);
367+ if areset_n = '1' then
368+ reply_msg := new_msg;
369+ request_msg := pop(read_reply_queue);
370+ msg_type := message_type(request_msg);
360371
361- if msg_type = bus_burst_read_msg or msg_type = axi_burst_read_msg then
362- push_integer(reply_msg, len + 1 ); -- bring axi burst up to bus one based indexing
363- end if ;
372+ addr := pop_std_ulogic_vector(request_msg);
373+ len := pop_integer(request_msg);
374+ size := pop_std_ulogic_vector(request_msg);
375+ burst := pop_std_ulogic_vector(request_msg);
376+ id := pop_std_ulogic_vector(request_msg);
377+ resp := pop(request_msg);
364378
365- -- first iteration
366- check_axi_id(axi_master_handle.p_bus_handle, rid, id, " rid" );
367- check_axi_resp(axi_master_handle.p_bus_handle, rresp, resp, " rresp" );
368- write_debug;
369- push_std_ulogic_vector(reply_msg, rdata);
379+ if msg_type = bus_burst_read_msg or msg_type = axi_burst_read_msg then
380+ push_integer(reply_msg, len + 1 ); -- bring axi burst up to bus one based indexing
381+ end if ;
370382
371- -- burst iterations
372- for i in 0 to len - 1 loop
373- wait until (rvalid and rready) = '1' and rising_edge (aclk);
383+ -- first iteration
374384 check_axi_id(axi_master_handle.p_bus_handle, rid, id, " rid" );
375385 check_axi_resp(axi_master_handle.p_bus_handle, rresp, resp, " rresp" );
376386 write_debug;
377387 push_std_ulogic_vector(reply_msg, rdata);
378- end loop ;
379388
380- reply(net, request_msg, reply_msg);
381- delete(request_msg);
389+ -- burst iterations
390+ for i in 0 to len - 1 loop
391+ wait until ((rvalid and rready) = '1' and rising_edge (aclk)) or areset_n = '0' ;
392+ if areset_n = '0' then
393+ exit ;
394+ end if ;
395+ check_axi_id(axi_master_handle.p_bus_handle, rid, id, " rid" );
396+ check_axi_resp(axi_master_handle.p_bus_handle, rresp, resp, " rresp" );
397+ write_debug;
398+ push_std_ulogic_vector(reply_msg, rdata);
399+ end loop ;
400+
401+ if areset_n = '1' then
402+ reply(net, request_msg, reply_msg);
403+ delete(request_msg);
404+ end if ;
405+ end if ;
382406 end process ;
383407
384408 -- Reply in separate process do not destroy alignment with the clock
0 commit comments