Below is my code for NUMLINES=4. If pkt_send_req comes on any of the requests, pkt_send_ack[i] must be asserted for once cycle within a delay of 1-32 cycles. I am not seeing the expected behavious. Total number of acks are not matching total number of reqs. Can you please correct this?
task foo_driver::drive_ack();
int req_pos;
int ack_pos;
int pos;
int delay_ack;
int req_pos_q[$];
int ack_q[$];
semaphore mutex = new(1); // Create a semaphore with 1 token
forever begin
@(posedge intf.clock);
fork
begin: requests
if(|intf.pkt_send_req ==1) begin
val = intf.o_val;
for (int i = 0; i < `NUM_LINES; i++) begin
if (intf.pkt_send_req[i] == 1) begin
mutex.get(); // Acquire the mutex
req_pos_q.push_back(i);
mutex.put(); // Release the mutex
end
end
end
else begin
val = 0;
end
end
begin: acks
while (req_pos_q.size() != 0) begin
mutex.get(); // Acquire the mutex
ack_pos = req_pos_q.pop_front();
ack_q.push_back(ack_pos);
mutex.put(); // Release the mutex
delay_ack = $urandom_range(32, 1);
repeat (delay_ack) @(posedge intf.clock);
pos=ack_q.pop_front();
intf.pkt_send_ack[pos] <= 1'b1;
@(posedge intf.clock);
intf.pkt_send_ack[pos] <= 1'b0;
@(posedge intf.clock);
end
end
join_none
end
endtask